From 35b3f9749b9d63a7d24977aeea0e9e2fcbe85292 Mon Sep 17 00:00:00 2001 From: Luuk Motz Date: Tue, 1 Dec 2026 23:23:17 +0100 Subject: [PATCH 1/2] shader: treat a mesh buffer load at a uniform address as uniform A buffer_load_dword, or a buffer_load_format_x from a descriptor-table V#, without OFFEN, with a uniform IDXEN index if any and a constant or uniform SOFFSET, reads the same address in every lane. Until the shader stores to memory it returns the same dwords in every lane, so mark them uniform under the same conditions as the heap typed load and let a following v_readfirstlane read them. The address is checked before the load, whose destination may be its own index register. Co-Authored-By: Claude Opus 5.5 --- src/gfx1013_direct_mesh.inl | 28 ++++++++++++++++++++++++++++ tests/native_direct_mesh_check.py | 23 +++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index ad89aaad5..36bd3b67e 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -876,6 +876,30 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout return full_exec || (exec_skip && !exec_skip->per_lane && exec_skip->guard==lane_active && !wave_active.empty()); }; + // A MUBUF load without OFFEN, with a uniform IDXEN index if any and a constant or uniform SOFFSET, reads + // the same address in every lane. Read before the load: its destination may be its own index register. + auto uniform_buffer_address=[&](const Inst &i) { + if ((i.a&0x1000) || memory_stored) return false; + if (i.a&0x2000) { + const auto index=alu.read(256+(i.b&255)); + if (index.empty() || uniform(index)!=index) return false; + } + const unsigned soffset=(i.b>>24)&255; + if (constant32(i,soffset)) return true; + if (soffset>=106) return false; + const auto value=alu.read(soffset); + return !value.empty() && uniform(value)==value; + }; + // Until the shader stores to memory, such a load returns the same dwords in every lane. Mark them uniform + // under the same conditions as the heap typed load, so v_readfirstlane can read them. + auto mark_uniform_buffer_load=[&](const Inst &i,unsigned count) { + for (unsigned j=0;j>16)&31)*4].type==Symbol::Type::descriptor) { // A V# read whole from a bound descriptor table: the shared typed-buffer SRV path checks the // table binding and all four descriptor words, as it does for vertex and pixel shaders. + const bool uniform_address=uniform_buffer_address(i); alu.memory(i,state); if (!full_exec) partial_writes.insert(256+i.dst); + if (uniform_address) mark_uniform_buffer_load(i,1); } else if (i.name=="buffer_load_format" && i.op==0 && vector_exec && ((i.a&0x3ffff)==0x2000 || (i.a&0x3ffff)==0)) { const auto base=((i.b>>16)&31)*4; @@ -1930,6 +1956,7 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout alu.formatted_byte_load(i,state,window); if (!full_exec) for (unsigned j=0;j<=i.op;++j) partial_writes.insert(256+i.dst+j); } else if (i.name=="buffer_load_dword" && vector_exec) { + const bool uniform_address=uniform_buffer_address(i); constexpr unsigned counts[]{1,2,4,3}; const unsigned count=counts[i.op&3]; if ((i.a&0x3000)==0x1000) @@ -1938,6 +1965,7 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout alu.memory(i,state); if (!full_exec) for (unsigned j=0;j Date: Wed, 2 Dec 2026 08:39:46 +0100 Subject: [PATCH 2/2] tests: expect the lane-0 broadcast for a non-uniform mesh READFIRSTLANE Since #3793, a v_readfirstlane_b32 of a value that is not uniform under full EXEC broadcasts lane 0 through groupshared memory instead of being refused. The uniform buffer load cases now check that READFIRSTLANE reads the load directly with no broadcast slot, and the OFFEN and per-lane index cases check that the broadcast is used. Part of #3703. Co-Authored-By: Claude Opus 5.5 --- tests/native_direct_mesh_check.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index fe2a32e83..3a27785c1 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -1061,17 +1061,19 @@ def run_offen(name, words, error=None): text, re.DOTALL), text text = run('scalar-buffer-vcc-branch', words[:3]+words[7:]+compare_root+choose_output+controlled) assert 'rawBufferLoad' in text and 'br i1' in text - # A buffer load whose address is the same in every lane is uniform, so READFIRSTLANE may read it. + # A buffer load whose address is the same in every lane is uniform, so READFIRSTLANE reads it + # directly instead of broadcasting lane 0 through groupshared memory. uniform_read = [0x7e280506] # v_readfirstlane_b32 s20, v6 for name, load in (('uniform-load-off', [0xe0300014, 0x80060600]), # buffer_load_dword v6, off, s[24:27], 0 offset:20 ('uniform-load-root-soffset', [0xe0300014, 0x15060600])): # ... s[24:27], s21 offset:20 text = run(name, words[:3] + load + uniform_read + controlled) loaded = re.search(r'(%[\w.]+) = extractvalue %dx\.types\.ResRet\.i32 %[\w.]+, 0\n', text) - assert 'rawBufferLoad' in text and loaded, text + assert 'rawBufferLoad' in text and loaded and '@meshReadFirstLane' not in text, text assert re.search(r'uitofp i32 ' + re.escape(loaded[1]) + r' to float', text), text - # A per-lane offset keeps it refused, even from a uniform VGPR. - run('uniform-load-offen', words[:3] + [0x7e020215, 0xe0301014, 0x80060601] + # v1 = s21; ... v1 offen - uniform_read + controlled, 'unsupported mesh instruction or EXEC state: v_readfirstlane_b32') + # A per-lane offset is not uniform, even from a uniform VGPR, so lane 0 is broadcast. + text = run('uniform-load-offen', words[:3] + [0x7e020215, 0xe0301014, 0x80060601] + # v1 = s21; ... v1 offen + uniform_read + controlled) + assert '@meshReadFirstLane' in text, text # Convert a whole-wave scalar through a VGPR before READFIRSTLANE. wave_body = words[7:] + [0x7e340e14, 0x7e30051a] + compare_root + choose_output wave_range = [0xb0140003, 0xbe8c047e, 0x7da80014, 0xbf880000 | len(wave_body)] @@ -1203,11 +1205,11 @@ def table_load(body, seed=True): 0x7e240501])): # v_readfirstlane_b32 s18, v1 text = run(name, table_setup + load + readfirst_exported) loaded = re.search(r'(%[\w.]+) = extractvalue %dx\.types\.ResRet\.i32 %[\w.]+, 0\n', text) - assert 'bufferLoad.i32' in text and loaded, text + assert 'bufferLoad.i32' in text and loaded and '@meshReadFirstLane' not in text, text assert re.search(r'uitofp i32 ' + re.escape(loaded[1]) + r' to float', text), text - run('typed-table-lane-index-readfirstlane', table_setup + readfirst_exported[:7] + - [0xe0002000, 0x80060a00, 0x7e24050a] + readfirst_exported[7:], # index v0, the lane's thread - 'unsupported mesh instruction or EXEC state: v_readfirstlane_b32') + text = run('typed-table-lane-index-readfirstlane', table_setup + readfirst_exported[:7] + + [0xe0002000, 0x80060a00, 0x7e24050a] + readfirst_exported[7:]) # index v0, the lane's thread + assert '@meshReadFirstLane' in text, text layout.write_text(heap_layout) run('typed-heap-offset-skip', skip_load([0xe0002004, 0x80080a01]), 'formatted load requires zero or a single linear index')