diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 3b9958b35c..f7c219cb86 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -3320,6 +3320,13 @@ class PipelineState final std::fprintf(stderr, "[rt] d3d12: no translated %s for FSSM sha256 %s\n", stage.name, hash.c_str()); return E_INVALIDARG; } + if (stage.entry->needs_maintenance8 && !device_.info.maintenance8) { + // A texel offset outside a gather is invalid SPIR-V for Vulkan without VK_KHR_maintenance8; refuse + // it here, with the reason, instead of handing the driver a module it may reject or miscompile. + std::fprintf(stderr, "[rt] d3d12: %s samples with a texel offset; the device has no VK_KHR_maintenance8\n", + stage.entry->name.c_str()); + return E_NOTIMPL; + } if (stage.entry->binding_count) { if (!device_.bindless) { std::fprintf(stderr, "[rt] d3d12: %s uses set-0 bindings; the device has no bindless set 0\n", @@ -3803,6 +3810,11 @@ class PipelineState final return E_NOTIMPL; } if (entry->binding_count) register_literal_samplers(device_, *entry); + if (entry->needs_maintenance8 && !device_.info.maintenance8) { + std::fprintf(stderr, "[rt] d3d12: %s samples with a texel offset; the device has no VK_KHR_maintenance8\n", + entry->name.c_str()); + return E_NOTIMPL; + } // SHADER-309: a module over the device's maxComputeSharedMemorySize is invalid usage that spirv-val accepts // and RADV dies on (#1721); some drivers report 32768. Refuse it here instead of creating the pipeline. if (entry->lds_bytes) { diff --git a/runtime/src/shader_library.h b/runtime/src/shader_library.h index 8eb76f3c44..9e95e63d73 100644 --- a/runtime/src/shader_library.h +++ b/runtime/src/shader_library.h @@ -698,6 +698,9 @@ struct ShaderEntry { // pipeline needs it at or under the device's maxComputeSharedMemorySize (32768 on some drivers). std::uint32_t lds_bytes = 0; bool uses_code_base = false; + // The index's needs_maintenance8: an image sample takes a texel offset outside a gather (the SPIR-V Offset image + // operand), valid only with VK_KHR_maintenance8; a pipeline on a device without it is refused. + bool needs_maintenance8 = false; bool wave64 = false; // The subgroup size the translator assumed (64 for a wave64 shader, 32 otherwise); 0 when the entry says null, // as one translated with --wave64-emulate does, or has none. @@ -884,6 +887,8 @@ class ShaderLibrary { if (const Json* l = meta.find("local_size"); l && l->kind == Json::Kind::array) for (std::size_t i = 0; i < l->array.size() && i < 3; ++i) e.local_size[i] = u32(&l->array[i]); if (const Json* c = meta.find("uses_code_base"); c && c->kind == Json::Kind::boolean) e.uses_code_base = c->boolean; + if (const Json* m = meta.find("needs_maintenance8"); m && m->kind == Json::Kind::boolean) + e.needs_maintenance8 = m->boolean; if (const Json* w = meta.find("wave64"); w && w->kind == Json::Kind::boolean) e.wave64 = w->boolean; if (const Json* g = meta.find("subgroup_size"); g && g->kind == Json::Kind::number) e.subgroup_size = u32(g); diff --git a/runtime/test/d3d12_mesh_test.cpp b/runtime/test/d3d12_mesh_test.cpp index df430c11a6..418af645fb 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp @@ -107,6 +107,7 @@ int main() { const auto ms_program = fssm_program({0x4d530001, 0xbf810000}); const auto ps_program = fssm_program({0x50530001, 0xbf810000}); + const auto ps_offset_program = fssm_program({0x50530002, 0xbf810000}); // index entry with needs_maintenance8 const auto vs_program = fssm_program({0x56530002, 0xbf810000}); const auto ms_container = shader_container(ms_program), ps_container = shader_container(ps_program); const auto vs_container = shader_container(vs_program); @@ -114,6 +115,7 @@ int main() { std::filesystem::create_directories(library); std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_draw.spv", std::filesystem::copy_options::overwrite_existing); std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_draw.spv", std::filesystem::copy_options::overwrite_existing); + std::filesystem::copy_file(LEONIDA_TEST_PS_SPV, library / "ps_offset.spv", std::filesystem::copy_options::overwrite_existing); std::filesystem::copy_file(LEONIDA_TEST_VS_FULLSCREEN_SPV, library / "vs_fullscreen.spv", std::filesystem::copy_options::overwrite_existing); { @@ -124,7 +126,9 @@ int main() { " \"vs_fullscreen\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_program) << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": []},\n" " \"ps_draw\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << leonida::sha256_hex(ps_program) - << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0]}}"; + << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0]},\n" + " \"ps_offset\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << leonida::sha256_hex(ps_offset_program) + << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0], \"needs_maintenance8\": true}}"; } const auto device_info = [&](bool mesh) { @@ -180,6 +184,22 @@ int main() { stream.add(TargetsSubobject{.inner = one_target()}); Ref pso; EXPECT(create(device.p, stream, pso) == E_NOTIMPL && !pso.p); + // A pixel shader whose index entry says needs_maintenance8 (a texel offset outside a gather) is refused on a + // device that did not enable VK_KHR_maintenance8 (this one: device_info() leaves it off); the same VS + PS + // pipeline with an entry without the flag is created. + const auto ps_offset_container = shader_container(ps_offset_program); + const D3D12_SHADER_BYTECODE ps_offset{ps_offset_container.data(), ps_offset_container.size()}; + Stream needs8, plain; + needs8.add(RootSubobject{.inner = root.p}).add(VsSubobject{.inner = vs}).add(PsSubobject{.inner = ps_offset}); + needs8.add(TopologySubobject{.inner = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE}); + needs8.add(TargetsSubobject{.inner = one_target()}); + plain.add(RootSubobject{.inner = root.p}).add(VsSubobject{.inner = vs}).add(PsSubobject{.inner = ps}); + plain.add(TopologySubobject{.inner = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE}); + plain.add(TargetsSubobject{.inner = one_target()}); + Ref refused, created; + EXPECT(create(device.p, needs8, refused) == E_NOTIMPL && !refused.p); + EXPECT(SUCCEEDED(create(device.p, plain, created)) && created.p); + created.reset(); root.reset(); EXPECT(rt::d3d12_xs::device_proxy_ref_count(device.p) == 1); } diff --git a/runtime/test/shader_library_test.cpp b/runtime/test/shader_library_test.cpp index e2d19f340b..74290d8de1 100644 --- a/runtime/test/shader_library_test.cpp +++ b/runtime/test/shader_library_test.cpp @@ -363,7 +363,8 @@ int main() { "{\"semantic\": \"TEXCOORD\", \"semantic_index\": 3, \"register\": -1, \"system_value\": 0, " "\"component_type\": \"float\"}]},\n" " \"ps_out\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << hash << "\", \"inputs\": [0, 1, 28, 29], " - "\"outputs\": [0, 2], \"f16_halves\": {\"0\": [28, 29], \"bad\": [1], \"7\": [20, 21]}},\n" + "\"outputs\": [0, 2], \"f16_halves\": {\"0\": [28, 29], \"bad\": [1], \"7\": [20, 21]}, " + "\"needs_maintenance8\": true},\n" " \"ps_native\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << hash2 << "\", \"wave64\": true, " "\"subgroup_size\": 64},\n" " \"cs_emulated\": {\"stage\": \"cs\", \"fssm_sha256\": \"" << hash2 << "\", \"wave64\": true, " @@ -392,6 +393,7 @@ int main() { vs_all[1]->input_signature[0].register_index == 0); const ShaderEntry* ps = library.find("ps", hash); CHECK(ps && ps->outputs.size() == 2 && ps->outputs[1] == 2); + CHECK(ps->needs_maintenance8 && !vs->needs_maintenance8); // read from the index; absent means false CHECK(ps->inputs.size() == 4 && ps->inputs[0] == 0 && ps->inputs[3] == 29); CHECK(ps->f16_halves.size() == 2 && ps->f16_halves.at(0)[0] == 28 && ps->f16_halves.at(0)[1] == 29 && ps->f16_halves.at(7)[0] == 20 && ps->f16_halves.at(7)[1] == 21);