Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ jobs:
tests/startup_gfx2hlsl_mask_overwrite_check.py \
tests/startup_gfx2hlsl_mask_data_check.py \
tests/startup_gfx2hlsl_image_get_lod_check.py \
tests/startup_gfx2hlsl_image_desc_word_check.py \
tests/startup_gfx2hlsl_add_sub_co_check.py \
tests/startup_gfx2hlsl_add_sub_co_ci_check.py \
tests/startup_gfx2hlsl_saveexec_same_reg_check.py \
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ python3 -m venv out/pe-env
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_bfm_b64_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_mask_data_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_image_get_lod_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_image_desc_word_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_add_sub_co_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_add_sub_co_ci_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_saveexec_same_reg_check.py
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3977,6 +3977,9 @@ if(EXISTS "${INTAKE_PYTHON}")
# Startup shader translator: image_get_lod on 2D and 2D-array textures.
add_test(NAME startup_gfx2hlsl_image_get_lod_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_image_get_lod_check.py")
# Pixel image descriptor words used as numbers: exact width, height and 3D depth fields only.
add_test(NAME startup_gfx2hlsl_image_desc_word_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_image_desc_word_check.py")
foreach(adapter IN ITEMS warp hardware)
add_test(NAME startup_image_get_lod_view_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/startup_image_get_lod_view_check.py" "${DXC_EXECUTABLE}"
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"displayName": "Windows pull request smoke tests",
"filter": {
"include": {
"name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package)$"
"name": "^(bcpack_all_formats(_golden_control)?|startup_bcpack_storage|desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_(cvt_off_f32_i4|image_desc_word|sad_hi_msad)_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package)$"
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16924,6 +16924,14 @@ The pixel translator lowers `quad_perm:[k,k,k,k]` (k = 0 to 3) with full `row_ma

Reproduce: `ctest --preset dev --no-tests=error -R "^startup_gfx2hlsl_dpp_quad_broadcast" -V`. The controls cover the translation, every refusal, the missing `s_wqm`, the loop fixture and the divergent-EXEC control; the WARP and hardware draws compare all 256 pixels of the integer, float and loop fixtures with a CPU reference, with wrong-lane and own-lane translations as failing controls. This does not establish full-game startup.

### Pixel image descriptor size fields

A pixel stage can read the GFX10 size fields of an 8-dword image descriptor that an image instruction uses. `s_bfe_u32`, `s_and_b32` and `s_lshr_b32` lower only when the control or mask is exactly the field. WIDTH is word 1 bits 31:30 and word 2 bits 11:0, stored as width minus one. HEIGHT is word 2 bits 27:14, stored as height minus one. DEPTH is word 4 bits 12:0 and is lowered only for a 3D image. The HLSL reads that component from `GetDimensions(0)` on the texture the image instruction binds. The dimension is taken from the descriptor load that instruction reads, not from the register: a later or earlier load of a different descriptor into the same SGPRs does not borrow it. A copy of the sampled words keeps the load. `s_lshr_b32` lowers only when the descriptor word is the value being shifted. The manifest marks each such SRV with `imagedim <index>`. The draw path refuses that view when the recorded descriptor's `MostDetailedMip` is not 0, because `GetDimensions(0)` is the view's first mip and the descriptor fields are resource mip 0. A sample that does not read a size field is not marked, so a shifted view can still be sampled. A whole word, any other word or field, a shift of word 2 that keeps the resource-level bit, depth of a 1D, 2D or 2D-array image, height of a 1D image, a modified word and `m0` stay refused. A 4-dword buffer descriptor and the compute and vertex stages are unchanged.

```powershell
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_image_desc_word' -V
```

## Startup root signature changes

`tests/startup_root_reset.cpp` and `tests/startup_root_reset_check.py` bind a 1D texture through a descriptor table
Expand Down
64 changes: 63 additions & 1 deletion src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,49 @@

#include "startup_stubs/typed_uav_load.h"

// 'imagedim <index>': the pixel stage reads a GFX10 size field of SRV <index> through GetDimensions(0).
// That is the view's first mip. It matches the descriptor only when the view starts at resource mip 0.
struct ImageSizeSrvs {
std::uint32_t mask = 0;

bool read_manifest_line(const std::string& line)
{
int index = -1, used = 0;
if (std::sscanf(line.c_str(), "imagedim %d%n", &index, &used) != 1 || used != static_cast<int>(line.size()))
return false;
if (index < 0 || index >= 32) return false;
const char* digits = line.c_str() + 9;
if (digits[0] == '0' && digits[1] != '\0') return false;
const auto bit = std::uint32_t{1} << index;
if (mask & bit) return false;
mask |= bit;
return true;
}

bool requires(unsigned index) const
{
return index < 32 && (mask & (std::uint32_t{1} << index)) != 0;
}

template <class SrvVec>
bool valid_for_srvs(const SrvVec& srvs) const
{
if (!mask) return true;
if (srvs.size() < 32 && (mask >> srvs.size()) != 0) return false;
for (std::size_t i = 0; i < srvs.size() && i < 32; ++i) {
if (requires(static_cast<unsigned>(i)) && (srvs[i].kind < 1 || srvs[i].kind > 5))
return false;
}
return true;
}
};

// MostDetailedMip is the first field of every texture SRV in the union.
bool image_size_view_starts_at_resource_mip0(const D3D12_SHADER_RESOURCE_VIEW_DESC& desc)
{
return desc.Texture2D.MostDetailedMip == 0;
}

// A pixel-stage image store (#1996 item F, #2742): tools/startup/gfx2hlsl.py writes 'uav N tex2d|tex2da table P O'
// for the RWTexture2D<float4> or RWTexture2DArray<float4> at u<N>, whose descriptor is at byte O of the title's
// root table P. The native compiler also emits raw table views; a view qualifier or a 'channels' field, as in the compute line, is refused.
Expand Down Expand Up @@ -167,6 +210,7 @@ struct Translation {
x2w_startup::TranslatedSamplers samplers;
x2w_startup::ExportWriteMasks write_masks; // manifest 'wmask': channels each export leaves unwritten (#1674)
x2w_startup::D16ImageSrvs d16_srvs; // manifest 'd16srv': texture views that must match proven D16 formats (#2023)
ImageSizeSrvs image_size_srvs; // manifest 'imagedim': size-field reads that need resource mip 0
ID3DBlob* vs = nullptr;
ID3DBlob* ps = nullptr;
ID3D12RootSignature* root = nullptr;
Expand Down Expand Up @@ -496,6 +540,11 @@ void load_translation(Translation& tr, const std::string& rtv_request = {}, std:
log("x2w-draw invalid write mask manifest line for %016llx: %s", tr.key, line.c_str());
return;
}
} else if (line.compare(0, 9, "imagedim ") == 0) {
if (!tr.image_size_srvs.read_manifest_line(line)) {
log("x2w-draw invalid imagedim manifest line for %016llx: %s", tr.key, line.c_str());
return;
}
} else if (line.compare(0, 7, "d16srv ") == 0) {
if (!tr.d16_srvs.read_manifest_line(line)) {
log("x2w-draw invalid d16srv manifest line for %016llx: %s", tr.key, line.c_str());
Expand All @@ -522,7 +571,8 @@ void load_translation(Translation& tr, const std::string& rtv_request = {}, std:
log("x2w-draw RTV manifest missing for %016llx", tr.key);
return;
}
if (tr.uds.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || !tr.d16_srvs.valid_for_srvs(tr.srvs)) return;
if (tr.uds.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || !tr.d16_srvs.valid_for_srvs(tr.srvs) ||
!tr.image_size_srvs.valid_for_srvs(tr.srvs)) return;
for (const Translation::Ud& ud : tr.uds) {
if (ud.kind == Translation::d16_unorm16 &&
(ud.a < 0 || static_cast<std::size_t>(ud.a) >= tr.srvs.size() || !tr.d16_srvs.requires_exact(static_cast<unsigned>(ud.a))))
Expand Down Expand Up @@ -2181,6 +2231,7 @@ constexpr const char* indexed_rect_unavailable = "indexed_rect_unavailable";
constexpr const char* pipeline_unavailable = "pipeline_unavailable";
constexpr const char* sampler_heap_unavailable = "sampler_heap_unavailable";
constexpr const char* sampled_texture_mismatch = "sampled_texture_mismatch";
constexpr const char* image_size_mip = "image_size_mip";
constexpr const char* sampled_texture_unbindable = "sampled_texture_unbindable";
constexpr const char* incomplete_vertex_stream = "incomplete_vertex_stream";
constexpr const char* incomplete_table_buffer = "incomplete_table_buffer";
Expand Down Expand Up @@ -2886,6 +2937,17 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI
if (texture && record.desc_bytes >= 40) {
std::memcpy(&desc, record.desc, 40);
desc.Format = desktop_format(desc.Format);
if (tr->image_size_srvs.requires(i) && !image_size_view_starts_at_resource_mip0(desc)) {
static LONG refused;
if (first_calls(refused, 6))
log("x2w-draw %016llx srv %u: image size field refused (view starts at mip %u)",
tr->key, i, desc.Texture2D.MostDetailedMip);
if (indirect)
indirect->set_refusal("translated draw reads an image size from a view that does not start at resource mip 0",
indirect_refusal_code::image_size_mip);
ReleaseSRWLockExclusive(&draw_lock);
return false;
}
}
if (texture && x2w_startup::packed_target_format(desc.Format)) {
// The view recorded from the title names a packed format: follow a stand-in texture,
Expand Down
Loading
Loading