diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 5dd6b42e47..b28471468b 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -7346,6 +7346,13 @@ class PipelineState final log_once("shader bytecode holds no FSSM or FSPX program; bytes", int(stage.code.BytecodeLength)); 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", @@ -7937,6 +7944,11 @@ class PipelineState final return stream_unsupported("compute shader requires a bindless descriptor set"); } 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 a359287cb1..a37beba3e4 100644 --- a/runtime/src/shader_library.h +++ b/runtime/src/shader_library.h @@ -853,6 +853,9 @@ struct ShaderEntry { std::uint32_t lds_bytes = 0; bool uses_code_base = false; bool code_base_known = 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. @@ -1175,6 +1178,8 @@ class ShaderLibrary { e.uses_code_base = c->boolean; e.code_base_known = true; } + 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 2d9bc5212e..a002414726 100644 --- a/runtime/test/d3d12_mesh_test.cpp +++ b/runtime/test/d3d12_mesh_test.cpp @@ -116,6 +116,7 @@ int main(int argc, char** argv) { // The same mesh shader listed without "root_window": one translated before the graphics root window (D3D-448). const auto ms_old_program = fssm_program({0x4d530002, 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}); auto ms_container = shader_container(ms_program); auto ms_old_container = shader_container(ms_old_program); @@ -129,6 +130,7 @@ int main(int argc, char** argv) { std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_draw.spv", std::filesystem::copy_options::overwrite_existing); std::filesystem::copy_file(LEONIDA_TEST_MS_SPV, library / "ms_old.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); { @@ -142,7 +144,9 @@ int main(int argc, char** argv) { " \"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) { @@ -222,6 +226,22 @@ int main(int argc, char** argv) { const D3D12_COMMAND_SIGNATURE_DESC mesh_sig{12, 1, &mesh_arg, 0}; Ref sig; EXPECT(device->CreateCommandSignature(&mesh_sig, nullptr, IID_PPV_ARGS(&sig.p)) == E_NOTIMPL && !sig.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 2448ab7b82..6f17868a1c 100644 --- a/runtime/test/shader_library_test.cpp +++ b/runtime/test/shader_library_test.cpp @@ -675,7 +675,7 @@ int main() { " \"ps_out\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << hash << "\", \"inputs\": [0, 1, 28, 29], " "\"outputs\": [0, 2], \"f16_halves\": {\"0\": [28, 29], \"bad\": [1], \"-1\": [1, 2], " "\"+2\": [3, 4], \" 3\": [5, 6], \"4294967296\": [9, 10], \"99999999999999999999\": [11, 12], " - "\"7\": [20, 21]}},\n" + "\"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, " @@ -704,6 +704,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);