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