Preserve shared scalar loads during embedded vertex fetch replacement

This commit is contained in:
nmzik
2026-09-15 08:54:16 +04:00
parent 5702cfc935
commit a1fbc41146
4 changed files with 49 additions and 39 deletions
+49
View File
@@ -9561,6 +9561,54 @@ void TestMergedShaderUserDataSnapshot() {
}
}
void TestEmbeddedFetchPreservesSharedScalarLoad() {
using namespace ShaderRecompiler;
const uint32_t code[] = {
EncodeSMovB32(5, 255), 0x47f,
EncodeSmem0(0x03, 0, 11), (125u << 25u) | 4u, // s_load_dwordx8 s[0:7], s[22:23], 4
EncodeSop2(0x1e, 9, 0, 132), // s_lshl_b32 s9, s0, 4
EncodeSop2(0x0e, 9, 9, 255), 0x1f0,
EncodeSmem0(0x02, 24, 10), 9u << 25u,
EncodeVop2(0x01, 0, 256 + 8, 5), // vertex/instance index selection
EncodeMubuf0(0x02), EncodeMubuf1(9, 6, 0), // replaced vertex fetch
EncodeSop2(0x1e, 9, 5, 132), // another component of the same scalar load
EncodeSop2(0x0e, 9, 9, 255), 0x1f0,
EncodeSmem0(0x02, 28, 10), 9u << 25u,
EncodeMubuf0(0x0c), EncodeMubuf1(12, 7, 1),
EncodeExp0(0x0c, 0xf), EncodeExp1(9, 10, 11, 12), EncodeSopp(0x01),
};
std::array<std::array<uint32_t, 4>, 32> buffers{};
buffers[2] = {0x12340000, 0, 64, 0x00027000};
buffers[31] = {0x56780000, 0, 64, 0x00027000};
const std::array<uint32_t, 9> attributes = {0, 0, 0, 0, 0, 0, 2, 0, 0};
std::array<uint32_t, 16> user_data{};
const uint64_t tables[] = {reinterpret_cast<uint64_t>(buffers.data()),
reinterpret_cast<uint64_t>(attributes.data())};
std::memcpy(user_data.data() + 12, tables, sizeof(tables));
ShaderVertexInputInfo input{};
input.fetch_embedded = true;
input.fetch_buffer_reg = 12;
input.fetch_attrib_reg = 14;
input.resources_num = 1;
input.resources_dst[0].attr_id = 1;
input.resources[0].fields[1] = 12u << 16u;
input.resources[0].fields[2] = 1;
input.resources[0].fields[3] =
(static_cast<uint32_t>(Prospero::BufferFormat::k32_32_32Float) << 12u) |
DstSel(4, 5, 6, 7);
auto options = MakeCompileOptions(ShaderType::Vertex);
options.user_data_base = 8;
options.user_data = user_data;
options.input_info.vertex = &input;
auto result = RecompileForTest(code, options);
Check(result.program.info.vertex_fetch_components[0] == 3 &&
result.resources.buffers.size() == 1 &&
std::equal(buffers[2].begin(), buffers[2].end(),
result.resources.buffers[0].dwords.begin()),
"embedded fetch discarded a scalar-load component used by another buffer read");
CheckSpirvBinaryValidates(result.spirv);
}
void TestEmbeddedVertexFormatSwizzle() {
using namespace ShaderRecompiler;
using namespace ShaderRecompiler::IR;
@@ -13346,6 +13394,7 @@ int main() {
TestMeshExportStorage();
TestMergedShaderUserDataSnapshot();
TestMeshInputAssembly();
TestEmbeddedFetchPreservesSharedScalarLoad();
TestEmbeddedVertexFormatSwizzle();
TestNewShaderRecompilerSetpcJumpTable();
TestNewShaderRecompilerPrunesUnreachableSetpcMetadata();