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
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,16 @@ target_compile_features(startup_d16_image_format_check PRIVATE cxx_std_17)
add_test(NAME startup_d16_image_format COMMAND startup_d16_image_format_check)
add_test(NAME startup_d16_image_format_accept_uint_control COMMAND startup_d16_image_format_check --mutate accept-uint)
set_tests_properties(startup_d16_image_format_accept_uint_control PROPERTIES WILL_FAIL TRUE)
# Image size-field manifest lines and the mip-0 / null-texture bind decision, without a device.
add_executable(startup_image_size_mip_check tests/startup_image_size_mip_check.cpp)
target_include_directories(startup_image_size_mip_check PRIVATE src)
target_compile_features(startup_image_size_mip_check PRIVATE cxx_std_17)
add_test(NAME startup_image_size_mip COMMAND startup_image_size_mip_check)
add_test(NAME startup_image_size_mip_drop_mip_control COMMAND startup_image_size_mip_check --mutate drop-mip)
add_test(NAME startup_image_size_mip_drop_null_control COMMAND startup_image_size_mip_check --mutate drop-null)
add_test(NAME startup_image_size_mip_reject_lines_control COMMAND startup_image_size_mip_check --mutate reject-lines)
set_tests_properties(startup_image_size_mip_drop_mip_control startup_image_size_mip_drop_null_control
startup_image_size_mip_reject_lines_control PROPERTIES WILL_FAIL TRUE)
# Composite provenance (#1628): one VS and two pixel shaders from one HLSL file.
set(startup_composite_provenance_headers "")
foreach(stage IN ITEMS "vs_6_0;vs_main;vs" "ps_6_0;ps_fill;fill" "ps_6_0;ps_composite;composite")
Expand Down Expand Up @@ -4063,6 +4073,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
5 changes: 3 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"xmem_run_break_readers_check", "xmem_run_break_readers_control", "xmem_cross_call_merge_check",
"xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check",
"xmem_page_runs_device_check", "linear_buffer_backing_check",
"bcpack_formats_check", "startup_stub_consumer", "startup_inline_retire", "startup_resource_retire_title", "startup_table_lock"
"bcpack_formats_check", "startup_stub_consumer", "startup_inline_retire", "startup_resource_retire_title", "startup_table_lock",
"startup_image_size_mip_check"
]
},
{ "name": "release", "configurePreset": "release" },
Expand All @@ -48,7 +49,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_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(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|startup_compute_packed_d16_x_uav_reference)$"
"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_(dispatch|constants|count)_inline_warp|startup_inline_retire_(on|control)_warp|startup_resource_retire_title_inline_warp_debug0|startup_table_lock_(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|startup_compute_packed_d16_x_uav_reference|startup_gfx2hlsl_image_desc_word_controls|startup_image_size_mip(_[a-z_]+)?)$"
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16938,6 +16938,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. It also refuses a marked SRV that has no texture, including on a direct draw, so the size is not taken from a null view. A sample that does not read a size field is not marked, so a shifted view can still be sampled and a null sample binding is unchanged. 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
38 changes: 37 additions & 1 deletion src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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)
x2w_startup::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 @@ -563,6 +564,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 Down Expand Up @@ -590,7 +596,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 @@ -2354,6 +2361,8 @@ 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* image_size_null = "image_size_null";
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 @@ -3391,6 +3400,33 @@ bool draw_translated(Wrapper* self, bool indexed, UINT count, UINT instances, UI
x2w_startup::report_token_entry(line, sizeof(line), tr->key, i, entry, words);
log("%s", line);
}
// GetDimensions(0) is the view's first mip. A marked SRV is refused when that is not
// resource mip 0, and when there is no texture to read (a direct draw would otherwise
// bind null). An unmarked sample is unchanged.
const auto size_bind = x2w_startup::image_size_bind(
tr->image_size_srvs.marks(i), texture != nullptr, record.desc_bytes >= 40,
desc.Texture2D.MostDetailedMip);
if (size_bind != x2w_startup::ImageSizeBind::proceed) {
static LONG refused;
if (first_calls(refused, 6)) {
if (size_bind == x2w_startup::ImageSizeBind::refuse_null)
log("x2w-draw %016llx srv %u: image size field refused (no texture)", tr->key, i);
else
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(
size_bind == x2w_startup::ImageSizeBind::refuse_null
? "translated draw reads an image size from a view with no texture"
: "translated draw reads an image size from a view that does not start at resource mip 0",
size_bind == x2w_startup::ImageSizeBind::refuse_null
? indirect_refusal_code::image_size_null
: indirect_refusal_code::image_size_mip);
}
ReleaseSRWLockExclusive(&draw_lock);
return false;
}
device_of(the_device)->CreateShaderResourceView(texture, texture && record.desc_bytes < 40 ? nullptr : &desc, dest);
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "startup_stubs/pso_recipe.h"
#include "startup_stubs/depth_state_apply.h"
#include "startup_stubs/d16_image_format.h"
#include "startup_stubs/image_size_mip.h"
#include "startup_stubs/formatted_buffer.h"
#include "startup_stubs/view_content_token.h"
#include "startup_stubs/heap_indexed_root.h"
Expand Down
69 changes: 69 additions & 0 deletions src/startup_stubs/image_size_mip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Pixel image-descriptor size fields. gfx2hlsl writes 'imagedim <index>' when SRV <index> is read
// through GetDimensions(0). That call is the view's first mip, so it matches the descriptor only when
// a texture is bound and the view starts at resource mip 0. An unmarked SRV is left alone.
#pragma once

#include <cstdint>
#include <string_view>

namespace x2w_startup {

enum class ImageSizeBind : std::uint8_t {
proceed = 0,
refuse_null = 1,
refuse_mip = 2,
};

struct ImageSizeSrvs {
std::uint32_t mask = 0;

// Parses 'imagedim <index>' for 0 <= index < 32 without leading zeroes or duplicates.
bool read_manifest_line(std::string_view line)
{
constexpr std::string_view prefix = "imagedim ";
if (line.size() <= prefix.size() || line.substr(0, prefix.size()) != prefix)
return false;
const std::string_view digits = line.substr(prefix.size());
if (digits.empty() || digits.size() > 2 || (digits.size() == 2 && digits[0] == '0'))
return false;
unsigned index = 0;
for (char c : digits) {
if (c < '0' || c > '9') return false;
index = index * 10u + static_cast<unsigned>(c - '0');
}
if (index >= 32 || (mask & (std::uint32_t{1} << index)) != 0) return false;
mask |= std::uint32_t{1} << index;
return true;
}

bool marks(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 (marks(static_cast<unsigned>(i)) && (srvs[i].kind < 1 || srvs[i].kind > 5))
return false;
}
return true;
}
};

// marked: the SRV is named by imagedim. have_texture: a resource will be bound.
// have_recorded_desc: a 40-byte view descriptor was copied, so most_detailed_mip is MostDetailedMip.
// MostDetailedMip is the first field of every texture SRV in the union.
inline ImageSizeBind image_size_bind(bool marked, bool have_texture, bool have_recorded_desc,
std::uint32_t most_detailed_mip)
{
if (!marked) return ImageSizeBind::proceed;
if (!have_texture) return ImageSizeBind::refuse_null;
if (have_recorded_desc && most_detailed_mip != 0) return ImageSizeBind::refuse_mip;
return ImageSizeBind::proceed;
}

} // namespace x2w_startup
Loading
Loading