diff options
| author | Dennis Schöneberg <schoenebergde@gmail.com> | 2026-11-23 19:36:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-23 12:36:37 -0600 |
| commit | dfe4e4ad3acfc7fe804e299e643ab06a88f1c8a7 (patch) | |
| tree | 5c5c3b46bbb64dffc54af9a5c5e97b5050e272fa /runtime | |
| parent | 6dda0630bd6fc0514baadb94fb98e36bd7d64c0b (diff) | |
d3d12: guard null pInputElementDescs and validate graphics/compute PSO descriptors (#6689)
Squash-merged after diff review of PR #6689
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/CMakeLists.txt | 13 | ||||
| -rw-r--r-- | runtime/shims/d3d12_vulkan_device.cpp | 49 | ||||
| -rw-r--r-- | runtime/test/d3d12_pso_validation_test.cpp | 480 |
3 files changed, 539 insertions, 3 deletions
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 719b37069..7080d87bf 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt | |||
| @@ -2503,6 +2503,19 @@ if(TARGET Vulkan::Headers) | |||
| 2503 | target_compile_options(d3d12_draw_test PRIVATE /W4 /permissive- /utf-8) | 2503 | target_compile_options(d3d12_draw_test PRIVATE /W4 /permissive- /utf-8) |
| 2504 | add_test(NAME d3d12_draw COMMAND d3d12_draw_test) | 2504 | add_test(NAME d3d12_draw COMMAND d3d12_draw_test) |
| 2505 | set_tests_properties(d3d12_draw PROPERTIES SKIP_RETURN_CODE 77) | 2505 | set_tests_properties(d3d12_draw PROPERTIES SKIP_RETURN_CODE 77) |
| 2506 | # Graphics & compute PSO descriptor validation parity against live Windows D3D12 (WARP and HW). | ||
| 2507 | add_executable(d3d12_pso_validation_test test/d3d12_pso_validation_test.cpp ${LEONIDA_TEST_VS} | ||
| 2508 | ${LEONIDA_TEST_PS} ${LEONIDA_TEST_PS_UINT} ${LEONIDA_TEST_VS_FULLSCREEN} ${LEONIDA_TEST_CS}) | ||
| 2509 | target_link_libraries(d3d12_pso_validation_test PRIVATE gta6rt_d3d12_com d3d12 dxgi) | ||
| 2510 | target_compile_definitions(d3d12_pso_validation_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX | ||
| 2511 | LEONIDA_TEST_VS_SPV="${LEONIDA_TEST_VS}" LEONIDA_TEST_PS_SPV="${LEONIDA_TEST_PS}" | ||
| 2512 | LEONIDA_TEST_PS_UINT_SPV="${LEONIDA_TEST_PS_UINT}" | ||
| 2513 | LEONIDA_TEST_VS_FULLSCREEN_SPV="${LEONIDA_TEST_VS_FULLSCREEN}" | ||
| 2514 | LEONIDA_TEST_CS_SPV="${LEONIDA_TEST_CS}") | ||
| 2515 | target_compile_options(d3d12_pso_validation_test PRIVATE /W4 /permissive- /utf-8) | ||
| 2516 | add_test(NAME d3d12_pso_validation COMMAND d3d12_pso_validation_test) | ||
| 2517 | set_tests_properties(d3d12_pso_validation PROPERTIES SKIP_RETURN_CODE 77 | ||
| 2518 | FAIL_REGULAR_EXPRESSION "Validation Error;VUID-") | ||
| 2506 | # Conservative raster Tier 1, with geometric coverage bounds and host D3D12 references. | 2519 | # Conservative raster Tier 1, with geometric coverage bounds and host D3D12 references. |
| 2507 | set(LEONIDA_CONSERVATIVE_VS ${CMAKE_CURRENT_BINARY_DIR}/generated/vs_conservative.spv) | 2520 | set(LEONIDA_CONSERVATIVE_VS ${CMAKE_CURRENT_BINARY_DIR}/generated/vs_conservative.spv) |
| 2508 | set(LEONIDA_CONSERVATIVE_PS ${CMAKE_CURRENT_BINARY_DIR}/generated/ps_conservative.spv) | 2521 | set(LEONIDA_CONSERVATIVE_PS ${CMAKE_CURRENT_BINARY_DIR}/generated/ps_conservative.spv) |
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index ad94a062f..831875702 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp | |||
| @@ -2700,10 +2700,11 @@ const leonida::ShaderEntry* pick_entry(const std::vector<const leonida::ShaderEn | |||
| 2700 | 2700 | ||
| 2701 | // Whether the input layout has an element for every ordinary (non-system-value) input of the vertex shader. | 2701 | // Whether the input layout has an element for every ordinary (non-system-value) input of the vertex shader. |
| 2702 | bool layout_feeds(const leonida::ShaderEntry& vs, const D3D12_INPUT_LAYOUT_DESC& layout) { | 2702 | bool layout_feeds(const leonida::ShaderEntry& vs, const D3D12_INPUT_LAYOUT_DESC& layout) { |
| 2703 | const UINT count = layout.pInputElementDescs ? layout.NumElements : 0; | ||
| 2703 | for (const auto& input : vs.input_signature) { | 2704 | for (const auto& input : vs.input_signature) { |
| 2704 | if (input.system_value) continue; | 2705 | if (input.system_value) continue; |
| 2705 | bool fed = false; | 2706 | bool fed = false; |
| 2706 | for (UINT i = 0; i < layout.NumElements && !fed; ++i) | 2707 | for (UINT i = 0; i < count && !fed; ++i) |
| 2707 | fed = layout.pInputElementDescs[i].SemanticIndex == input.semantic_index && | 2708 | fed = layout.pInputElementDescs[i].SemanticIndex == input.semantic_index && |
| 2708 | equal_semantic(input.semantic, layout.pInputElementDescs[i].SemanticName); | 2709 | equal_semantic(input.semantic, layout.pInputElementDescs[i].SemanticName); |
| 2709 | if (!fed) return false; | 2710 | if (!fed) return false; |
| @@ -2711,6 +2712,11 @@ bool layout_feeds(const leonida::ShaderEntry& vs, const D3D12_INPUT_LAYOUT_DESC& | |||
| 2711 | return true; | 2712 | return true; |
| 2712 | } | 2713 | } |
| 2713 | 2714 | ||
| 2715 | // Known D3D12_PIPELINE_STATE_FLAGS bits: TOOL_DEBUG (0x1, kept for cached-PSO parity), bit 0x2, | ||
| 2716 | // DYNAMIC_DEPTH_BIAS (0x4), and DYNAMIC_INDEX_BUFFER_STRIP_CUT (0x8). Higher bits fail with E_INVALIDARG | ||
| 2717 | // on both Windows hardware D3D12 and WARP. | ||
| 2718 | constexpr UINT kKnownPipelineStateFlags = 0xFu; | ||
| 2719 | |||
| 2714 | class RootSignature final | 2720 | class RootSignature final |
| 2715 | : public Child<RootSignature, ID3D12RootSignatureStubs, ID3D12Object, ID3D12DeviceChild, ID3D12RootSignature> { | 2721 | : public Child<RootSignature, ID3D12RootSignatureStubs, ID3D12Object, ID3D12DeviceChild, ID3D12RootSignature> { |
| 2716 | public: | 2722 | public: |
| @@ -2822,8 +2828,10 @@ leonida::cached_pso::Key pipeline_key(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& | |||
| 2822 | for (const D3D12_DEPTH_STENCILOP_DESC& face : {d.FrontFace, d.BackFace}) | 2828 | for (const D3D12_DEPTH_STENCILOP_DESC& face : {d.FrontFace, d.BackFace}) |
| 2823 | key.u32(face.StencilFailOp).u32(face.StencilDepthFailOp).u32(face.StencilPassOp).u32(face.StencilFunc); | 2829 | key.u32(face.StencilFailOp).u32(face.StencilDepthFailOp).u32(face.StencilPassOp).u32(face.StencilFunc); |
| 2824 | const D3D12_INPUT_LAYOUT_DESC& input = desc.InputLayout; | 2830 | const D3D12_INPUT_LAYOUT_DESC& input = desc.InputLayout; |
| 2825 | key.u32(input.pInputElementDescs ? input.NumElements : 0); | 2831 | const UINT input_count = |
| 2826 | for (UINT i = 0; input.pInputElementDescs && i < input.NumElements; ++i) { | 2832 | input.pInputElementDescs ? std::min<UINT>(input.NumElements, D3D12_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT) : 0; |
| 2833 | key.u32(input_count); | ||
| 2834 | for (UINT i = 0; i < input_count; ++i) { | ||
| 2827 | const D3D12_INPUT_ELEMENT_DESC& e = input.pInputElementDescs[i]; | 2835 | const D3D12_INPUT_ELEMENT_DESC& e = input.pInputElementDescs[i]; |
| 2828 | key.text(e.SemanticName).u32(e.SemanticIndex).u32(e.Format).u32(e.InputSlot).u32(e.AlignedByteOffset); | 2836 | key.text(e.SemanticName).u32(e.SemanticIndex).u32(e.Format).u32(e.InputSlot).u32(e.AlignedByteOffset); |
| 2829 | key.u32(e.InputSlotClass).u32(e.InstanceDataStepRate); | 2837 | key.u32(e.InputSlotClass).u32(e.InstanceDataStepRate); |
| @@ -3170,6 +3178,8 @@ public: | |||
| 3170 | log_once("mesh-shader PSOs need VK_EXT_mesh_shader, which the device has not enabled; stage", 1); | 3178 | log_once("mesh-shader PSOs need VK_EXT_mesh_shader, which the device has not enabled; stage", 1); |
| 3171 | return E_NOTIMPL; | 3179 | return E_NOTIMPL; |
| 3172 | } | 3180 | } |
| 3181 | if (desc.NodeMask & ~1u) return E_INVALIDARG; | ||
| 3182 | if (static_cast<UINT>(desc.Flags) & ~kKnownPipelineStateFlags) return E_INVALIDARG; | ||
| 3173 | if (!device_.arena.mapped) { | 3183 | if (!device_.arena.mapped) { |
| 3174 | log_once("pipelines need the GPU address arena (bufferDeviceAddress); stage", 1); | 3184 | log_once("pipelines need the GPU address arena (bufferDeviceAddress); stage", 1); |
| 3175 | return E_NOTIMPL; | 3185 | return E_NOTIMPL; |
| @@ -3180,6 +3190,37 @@ public: | |||
| 3180 | return E_NOTIMPL; | 3190 | return E_NOTIMPL; |
| 3181 | } | 3191 | } |
| 3182 | if (desc.NumRenderTargets > D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT) return E_INVALIDARG; | 3192 | if (desc.NumRenderTargets > D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT) return E_INVALIDARG; |
| 3193 | for (UINT i = desc.NumRenderTargets; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i) | ||
| 3194 | if (desc.RTVFormats[i] != DXGI_FORMAT_UNKNOWN) return E_INVALIDARG; | ||
| 3195 | if (desc.DSVFormat != DXGI_FORMAT_UNKNOWN) { | ||
| 3196 | const Format dsv_fmt = vulkan_format(desc.DSVFormat, true); | ||
| 3197 | if (dsv_fmt.format == VK_FORMAT_UNDEFINED || dsv_fmt.typeless || | ||
| 3198 | !(dsv_fmt.aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT))) { | ||
| 3199 | log_once("depth-stencil format not supported:", desc.DSVFormat); | ||
| 3200 | return E_INVALIDARG; | ||
| 3201 | } | ||
| 3202 | } | ||
| 3203 | if (desc.InputLayout.NumElements > D3D12_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT) return E_INVALIDARG; | ||
| 3204 | if (desc.InputLayout.NumElements > 0 && !desc.InputLayout.pInputElementDescs) return E_INVALIDARG; | ||
| 3205 | for (UINT i = 0; i < desc.InputLayout.NumElements; ++i) { | ||
| 3206 | const D3D12_INPUT_ELEMENT_DESC& element = desc.InputLayout.pInputElementDescs[i]; | ||
| 3207 | if (!element.SemanticName) return E_INVALIDARG; | ||
| 3208 | if (element.InputSlot >= D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT) return E_INVALIDARG; | ||
| 3209 | if (element.InputSlotClass != D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA && | ||
| 3210 | element.InputSlotClass != D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA) | ||
| 3211 | return E_INVALIDARG; | ||
| 3212 | if (element.InputSlotClass == D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA && | ||
| 3213 | element.InstanceDataStepRate != 0) | ||
| 3214 | return E_INVALIDARG; | ||
| 3215 | } | ||
| 3216 | if (desc.BlendState.IndependentBlendEnable) { | ||
| 3217 | for (const D3D12_RENDER_TARGET_BLEND_DESC& rt : desc.BlendState.RenderTarget) | ||
| 3218 | if (rt.LogicOpEnable) return E_INVALIDARG; | ||
| 3219 | } else { | ||
| 3220 | const D3D12_RENDER_TARGET_BLEND_DESC& rt0 = desc.BlendState.RenderTarget[0]; | ||
| 3221 | if (rt0.BlendEnable && rt0.LogicOpEnable) return E_INVALIDARG; | ||
| 3222 | if (rt0.LogicOpEnable && unsigned(rt0.LogicOp) > D3D12_LOGIC_OP_OR_INVERTED) return E_INVALIDARG; | ||
| 3223 | } | ||
| 3183 | if (desc.HS.BytecodeLength || desc.DS.BytecodeLength || desc.StreamOutput.NumEntries) { | 3224 | if (desc.HS.BytecodeLength || desc.DS.BytecodeLength || desc.StreamOutput.NumEntries) { |
| 3184 | log_once("graphics pipeline stage not supported yet (hull/domain/stream output):", 0); | 3225 | log_once("graphics pipeline stage not supported yet (hull/domain/stream output):", 0); |
| 3185 | return E_NOTIMPL; | 3226 | return E_NOTIMPL; |
| @@ -3713,6 +3754,8 @@ public: | |||
| 3713 | auto& vk = device_.context->vk; | 3754 | auto& vk = device_.context->vk; |
| 3714 | const VkDevice dev = device_.info.device; | 3755 | const VkDevice dev = device_.info.device; |
| 3715 | if (!desc.CS.pShaderBytecode || !desc.CS.BytecodeLength) return E_INVALIDARG; | 3756 | if (!desc.CS.pShaderBytecode || !desc.CS.BytecodeLength) return E_INVALIDARG; |
| 3757 | if (desc.NodeMask & ~1u) return E_INVALIDARG; | ||
| 3758 | if (static_cast<UINT>(desc.Flags) & ~kKnownPipelineStateFlags) return E_INVALIDARG; | ||
| 3716 | if (!device_.arena.mapped) { | 3759 | if (!device_.arena.mapped) { |
| 3717 | log_once("pipelines need the GPU address arena (bufferDeviceAddress); stage", 0); | 3760 | log_once("pipelines need the GPU address arena (bufferDeviceAddress); stage", 0); |
| 3718 | return E_NOTIMPL; | 3761 | return E_NOTIMPL; |
diff --git a/runtime/test/d3d12_pso_validation_test.cpp b/runtime/test/d3d12_pso_validation_test.cpp new file mode 100644 index 000000000..89bee7bd2 --- /dev/null +++ b/runtime/test/d3d12_pso_validation_test.cpp | |||
| @@ -0,0 +1,480 @@ | |||
| 1 | // Graphics and compute pipeline state descriptor validation parity against live Windows D3D12 (WARP and HW). | ||
| 2 | // Covers null InputLayout.pInputElementDescs crash prevention, InputLayout bounds/semantics/step-rate/slot-class, | ||
| 3 | // BlendState LogicOp/IndependentBlend rules, trailing RTVFormats, DSVFormat validation, NodeMask, and Flags. | ||
| 4 | // No game data. Set LEONIDA_VK_VALIDATION=1 to check Vulkan usage under VK_LAYER_KHRONOS_validation. | ||
| 5 | #include "d3d12_test_shaders.h" | ||
| 6 | #include "host_adapter.h" | ||
| 7 | #include "host_wine.h" | ||
| 8 | #include "shader_fixture_path.h" | ||
| 9 | #include "test_temp_dir.h" | ||
| 10 | #include "vk_test_device.h" | ||
| 11 | #include "../shims/d3d12_com.h" | ||
| 12 | #include "../src/shader_library.h" | ||
| 13 | |||
| 14 | #include <d3dcompiler.h> | ||
| 15 | #include <dxgi1_4.h> | ||
| 16 | #include <cstdio> | ||
| 17 | #include <cstring> | ||
| 18 | #include <fstream> | ||
| 19 | #include <memory> | ||
| 20 | #include <vector> | ||
| 21 | |||
| 22 | #if !defined(LEONIDA_TEST_VS_SPV) || !defined(LEONIDA_TEST_PS_SPV) || !defined(LEONIDA_TEST_PS_UINT_SPV) || \ | ||
| 23 | !defined(LEONIDA_TEST_VS_FULLSCREEN_SPV) || !defined(LEONIDA_TEST_CS_SPV) | ||
| 24 | #error "Test shader SPIR-V paths must be defined" | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #define EXPECT(condition) do { \ | ||
| 28 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ | ||
| 29 | } while (0) | ||
| 30 | |||
| 31 | using namespace d3d12test; | ||
| 32 | |||
| 33 | namespace { | ||
| 34 | |||
| 35 | struct HostContext { | ||
| 36 | std::string name; | ||
| 37 | Ref<ID3D12Device> device; | ||
| 38 | Ref<ID3D12RootSignature> root; | ||
| 39 | D3D12_SHADER_BYTECODE vs_fullscreen{}; | ||
| 40 | D3D12_SHADER_BYTECODE vs_pos{}; | ||
| 41 | D3D12_SHADER_BYTECODE ps_unorm{}; | ||
| 42 | D3D12_SHADER_BYTECODE ps_uint{}; | ||
| 43 | D3D12_SHADER_BYTECODE cs{}; | ||
| 44 | }; | ||
| 45 | |||
| 46 | bool compile_hlsl(pD3DCompile compile, const char* src, const char* profile, Ref<ID3DBlob>& out) { | ||
| 47 | Ref<ID3DBlob> err; | ||
| 48 | const HRESULT hr = compile(src, std::strlen(src), nullptr, nullptr, nullptr, "main", profile, 0, 0, &out.p, &err.p); | ||
| 49 | if (SUCCEEDED(hr) && out.p) return true; | ||
| 50 | std::fprintf(stderr, "D3DCompile (%s) failed: 0x%08lx\n", profile, static_cast<unsigned long>(hr)); | ||
| 51 | return false; | ||
| 52 | } | ||
| 53 | |||
| 54 | HRESULT create_graphics(ID3D12Device* dev, const D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc) { | ||
| 55 | Ref<ID3D12PipelineState> pso; | ||
| 56 | return dev->CreateGraphicsPipelineState(&desc, IID_PPV_ARGS(&pso.p)); | ||
| 57 | } | ||
| 58 | |||
| 59 | HRESULT create_compute(ID3D12Device* dev, const D3D12_COMPUTE_PIPELINE_STATE_DESC& desc) { | ||
| 60 | Ref<ID3D12PipelineState> pso; | ||
| 61 | return dev->CreateComputePipelineState(&desc, IID_PPV_ARGS(&pso.p)); | ||
| 62 | } | ||
| 63 | |||
| 64 | } // namespace | ||
| 65 | |||
| 66 | int main() { | ||
| 67 | vktest::Device vk_dev; | ||
| 68 | const auto status = vk_dev.initialize(); | ||
| 69 | if (status == vktest::DeviceStatus::unavailable) { | ||
| 70 | std::fprintf(stderr, "SKIP: no usable Vulkan 1.3 device\n"); | ||
| 71 | return 77; | ||
| 72 | } | ||
| 73 | EXPECT(status == vktest::DeviceStatus::ready); | ||
| 74 | |||
| 75 | // Prepare translated shader library for our Vulkan-backed D3D12 device. | ||
| 76 | const auto vs_pos_prog = fssm_program({0x56531001, 0xbf810000}); | ||
| 77 | const auto vs_fs_prog = fssm_program({0x56531002, 0xbf810000}); | ||
| 78 | const auto ps_unorm_prog = fssm_program({0x50531001, 0xbf810000}); | ||
| 79 | const auto ps_uint_prog = fssm_program({0x50531002, 0xbf810000}); | ||
| 80 | const auto cs_prog = fssm_program({0x43531001, 0xbf810000}); | ||
| 81 | |||
| 82 | const auto vs_pos_container = shader_container(vs_pos_prog); | ||
| 83 | const auto vs_fs_container = shader_container(vs_fs_prog); | ||
| 84 | const auto ps_unorm_container = shader_container(ps_unorm_prog); | ||
| 85 | const auto ps_uint_container = shader_container(ps_uint_prog); | ||
| 86 | const auto cs_container = shader_container(cs_prog); | ||
| 87 | |||
| 88 | const testfiles::ScratchDir scratch("leonida_pso_validation_test"); | ||
| 89 | const auto& lib_dir = scratch.path(); | ||
| 90 | EXPECT(testfiles::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_VS_SPV), lib_dir / "vs_draw.spv")); | ||
| 91 | EXPECT(testfiles::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_VS_FULLSCREEN_SPV), | ||
| 92 | lib_dir / "vs_fullscreen.spv")); | ||
| 93 | EXPECT(testfiles::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_PS_SPV), lib_dir / "ps_draw.spv")); | ||
| 94 | EXPECT(testfiles::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_PS_UINT_SPV), lib_dir / "ps_draw_uint.spv")); | ||
| 95 | EXPECT(testfiles::copy_file(vktest::shader_fixture_path(LEONIDA_TEST_CS_SPV), lib_dir / "cs_user_data.spv")); | ||
| 96 | { | ||
| 97 | std::ofstream index(lib_dir / "index.json", std::ios::binary); | ||
| 98 | index << "{\"vs_draw\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_pos_prog) | ||
| 99 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": [" | ||
| 100 | "{\"semantic\": \"COLOR\", \"semantic_index\": 0, \"register\": 0, \"mask\": 15, \"rw_mask\": 15, " | ||
| 101 | "\"system_value\": 0, \"component_type\": \"float\"}, " | ||
| 102 | "{\"semantic\": \"POSITION\", \"semantic_index\": 0, \"register\": 1, \"mask\": 3, \"rw_mask\": 3, " | ||
| 103 | "\"system_value\": 0, \"component_type\": \"float\"}]},\n" | ||
| 104 | " \"vs_fullscreen\": {\"stage\": \"vs\", \"fssm_sha256\": \"" << leonida::sha256_hex(vs_fs_prog) | ||
| 105 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"input_signature\": []},\n" | ||
| 106 | " \"ps_draw\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << leonida::sha256_hex(ps_unorm_prog) | ||
| 107 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0]},\n" | ||
| 108 | " \"ps_draw_uint\": {\"stage\": \"ps\", \"fssm_sha256\": \"" << leonida::sha256_hex(ps_uint_prog) | ||
| 109 | << "\", \"bindings\": [], \"push_constant_bytes\": 144, \"outputs\": [0]},\n" | ||
| 110 | " \"cs_user_data\": {\"stage\": \"cs\", \"fssm_sha256\": \"" << leonida::sha256_hex(cs_prog) | ||
| 111 | << "\", \"bindings\": [], \"push_constant_bytes\": 144}}"; | ||
| 112 | } | ||
| 113 | |||
| 114 | rt::d3d12::VulkanDeviceInfo info{}; | ||
| 115 | info.get_instance_proc = vk_dev.instance_proc; | ||
| 116 | info.instance = vk_dev.instance; | ||
| 117 | info.physical = vk_dev.physical; | ||
| 118 | info.device = vk_dev.device; | ||
| 119 | info.queue = vk_dev.queue; | ||
| 120 | info.queue_family = vk_dev.family; | ||
| 121 | info.buffer_device_address = true; | ||
| 122 | info.subgroup = vk_dev.subgroup; | ||
| 123 | info.shader_dir = lib_dir.string(); | ||
| 124 | info.features.logicOp = vk_dev.enabled.logicOp; | ||
| 125 | info.vertex_attribute_divisor = vk_dev.vertex_attribute_divisor; | ||
| 126 | |||
| 127 | Ref<ID3D12Device> layer_dev; | ||
| 128 | EXPECT(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&layer_dev.p)))); | ||
| 129 | |||
| 130 | D3D12_VERSIONED_ROOT_SIGNATURE_DESC root_desc{}; | ||
| 131 | root_desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0; | ||
| 132 | root_desc.Desc_1_0.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT; | ||
| 133 | const auto root_blob = serialize_root_signature(root_desc); | ||
| 134 | EXPECT(!root_blob.empty()); | ||
| 135 | Ref<ID3D12RootSignature> layer_root; | ||
| 136 | EXPECT(SUCCEEDED(layer_dev->CreateRootSignature(0, root_blob.data(), root_blob.size(), IID_PPV_ARGS(&layer_root.p)))); | ||
| 137 | |||
| 138 | // Optional live host D3D12 devices (WARP and HW) on native Windows for exact HRESULT parity. | ||
| 139 | Ref<ID3DBlob> hlsl_vs_fs, hlsl_vs_pos, hlsl_ps_unorm, hlsl_ps_uint, hlsl_cs; | ||
| 140 | std::vector<std::unique_ptr<HostContext>> hosts; | ||
| 141 | HMODULE compiler_dll = nullptr; | ||
| 142 | if (!hostwine::host_is_wine()) { | ||
| 143 | compiler_dll = LoadLibraryA("d3dcompiler_47.dll"); | ||
| 144 | auto compile = compiler_dll ? reinterpret_cast<pD3DCompile>(GetProcAddress(compiler_dll, "D3DCompile")) : nullptr; | ||
| 145 | if (compile) { | ||
| 146 | const char* kVsFs = "float4 main(uint id : SV_VertexID) : SV_Position { return float4(0,0,0,1); }"; | ||
| 147 | const char* kVsPos = | ||
| 148 | "float4 main(float2 p : POSITION, float4 c : COLOR) : SV_Position { return float4(p, c.x, 1); }"; | ||
| 149 | const char* kPsUnorm = "float4 main() : SV_Target { return float4(1,0,0,1); }"; | ||
| 150 | const char* kPsUint = "uint4 main() : SV_Target { return uint4(1,0,0,1); }"; | ||
| 151 | const char* kCs = "[numthreads(1,1,1)] void main() {}"; | ||
| 152 | if (compile_hlsl(compile, kVsFs, "vs_5_0", hlsl_vs_fs) && | ||
| 153 | compile_hlsl(compile, kVsPos, "vs_5_0", hlsl_vs_pos) && | ||
| 154 | compile_hlsl(compile, kPsUnorm, "ps_5_0", hlsl_ps_unorm) && | ||
| 155 | compile_hlsl(compile, kPsUint, "ps_5_0", hlsl_ps_uint) && | ||
| 156 | compile_hlsl(compile, kCs, "cs_5_0", hlsl_cs)) { | ||
| 157 | Ref<IDXGIFactory4> factory; | ||
| 158 | if (SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p)))) { | ||
| 159 | for (const bool warp : {false, true}) { | ||
| 160 | Ref<IDXGIAdapter> adapter; | ||
| 161 | std::string name; | ||
| 162 | if (!hostadapter::reference(factory.p, vk_dev, warp, &adapter.p, name)) continue; | ||
| 163 | auto hc = std::make_unique<HostContext>(); | ||
| 164 | hc->name = name; | ||
| 165 | if (FAILED(D3D12CreateDevice(adapter.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&hc->device.p)))) | ||
| 166 | continue; | ||
| 167 | if (FAILED(hc->device->CreateRootSignature(0, root_blob.data(), root_blob.size(), | ||
| 168 | IID_PPV_ARGS(&hc->root.p)))) | ||
| 169 | continue; | ||
| 170 | hc->vs_fullscreen = {hlsl_vs_fs->GetBufferPointer(), hlsl_vs_fs->GetBufferSize()}; | ||
| 171 | hc->vs_pos = {hlsl_vs_pos->GetBufferPointer(), hlsl_vs_pos->GetBufferSize()}; | ||
| 172 | hc->ps_unorm = {hlsl_ps_unorm->GetBufferPointer(), hlsl_ps_unorm->GetBufferSize()}; | ||
| 173 | hc->ps_uint = {hlsl_ps_uint->GetBufferPointer(), hlsl_ps_uint->GetBufferSize()}; | ||
| 174 | hc->cs = {hlsl_cs->GetBufferPointer(), hlsl_cs->GetBufferSize()}; | ||
| 175 | hosts.push_back(std::move(hc)); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | auto make_gfx = [&](ID3D12RootSignature* rs, D3D12_SHADER_BYTECODE vs, D3D12_SHADER_BYTECODE ps) { | ||
| 183 | D3D12_GRAPHICS_PIPELINE_STATE_DESC d{}; | ||
| 184 | d.pRootSignature = rs; | ||
| 185 | d.VS = vs; | ||
| 186 | d.PS = ps; | ||
| 187 | d.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; | ||
| 188 | d.SampleMask = 0xffffffffu; | ||
| 189 | d.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID; | ||
| 190 | d.RasterizerState.CullMode = D3D12_CULL_MODE_NONE; | ||
| 191 | d.RasterizerState.DepthClipEnable = TRUE; | ||
| 192 | d.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; | ||
| 193 | d.NumRenderTargets = 1; | ||
| 194 | d.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 195 | d.SampleDesc.Count = 1; | ||
| 196 | return d; | ||
| 197 | }; | ||
| 198 | |||
| 199 | const D3D12_SHADER_BYTECODE layer_vs_fs{vs_fs_container.data(), vs_fs_container.size()}; | ||
| 200 | const D3D12_SHADER_BYTECODE layer_vs_pos{vs_pos_container.data(), vs_pos_container.size()}; | ||
| 201 | const D3D12_SHADER_BYTECODE layer_ps_unorm{ps_unorm_container.data(), ps_unorm_container.size()}; | ||
| 202 | const D3D12_SHADER_BYTECODE layer_ps_uint{ps_uint_container.data(), ps_uint_container.size()}; | ||
| 203 | const D3D12_SHADER_BYTECODE layer_cs{cs_container.data(), cs_container.size()}; | ||
| 204 | |||
| 205 | unsigned checked = 0, host_compared = 0; | ||
| 206 | |||
| 207 | auto check_gfx_parity = [&](const char* label, HRESULT expected, bool use_pos_vs, bool use_uint_ps, | ||
| 208 | auto mutator) -> bool { | ||
| 209 | auto desc = make_gfx(layer_root.p, use_pos_vs ? layer_vs_pos : layer_vs_fs, | ||
| 210 | use_uint_ps ? layer_ps_uint : layer_ps_unorm); | ||
| 211 | if (use_uint_ps) desc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UINT; | ||
| 212 | mutator(desc); | ||
| 213 | const HRESULT actual = create_graphics(layer_dev.p, desc); | ||
| 214 | if (actual != expected) { | ||
| 215 | std::fprintf(stderr, "FAIL [%s]: layer returned 0x%08lx, expected 0x%08lx\n", label, | ||
| 216 | static_cast<unsigned long>(actual), static_cast<unsigned long>(expected)); | ||
| 217 | return false; | ||
| 218 | } | ||
| 219 | ++checked; | ||
| 220 | for (const auto& hcp : hosts) { | ||
| 221 | const HostContext& hc = *hcp; | ||
| 222 | auto hdesc = make_gfx(hc.root.p, use_pos_vs ? hc.vs_pos : hc.vs_fullscreen, | ||
| 223 | use_uint_ps ? hc.ps_uint : hc.ps_unorm); | ||
| 224 | if (use_uint_ps) hdesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UINT; | ||
| 225 | mutator(hdesc); | ||
| 226 | const HRESULT hhr = create_graphics(hc.device.p, hdesc); | ||
| 227 | if (hhr != actual) { | ||
| 228 | std::fprintf(stderr, "FAIL [%s]: layer 0x%08lx != host %s 0x%08lx\n", label, | ||
| 229 | static_cast<unsigned long>(actual), hc.name.c_str(), static_cast<unsigned long>(hhr)); | ||
| 230 | return false; | ||
| 231 | } | ||
| 232 | ++host_compared; | ||
| 233 | } | ||
| 234 | return true; | ||
| 235 | }; | ||
| 236 | |||
| 237 | auto check_gfx_layer_only = [&](const char* label, HRESULT expected, auto mutator) -> bool { | ||
| 238 | auto desc = make_gfx(layer_root.p, layer_vs_fs, layer_ps_unorm); | ||
| 239 | mutator(desc); | ||
| 240 | const HRESULT actual = create_graphics(layer_dev.p, desc); | ||
| 241 | if (actual != expected) { | ||
| 242 | std::fprintf(stderr, "FAIL [%s]: layer returned 0x%08lx, expected 0x%08lx\n", label, | ||
| 243 | static_cast<unsigned long>(actual), static_cast<unsigned long>(expected)); | ||
| 244 | return false; | ||
| 245 | } | ||
| 246 | ++checked; | ||
| 247 | return true; | ||
| 248 | }; | ||
| 249 | |||
| 250 | auto check_cs_parity = [&](const char* label, HRESULT expected, auto mutator) -> bool { | ||
| 251 | D3D12_COMPUTE_PIPELINE_STATE_DESC desc{}; | ||
| 252 | desc.pRootSignature = layer_root.p; | ||
| 253 | desc.CS = layer_cs; | ||
| 254 | mutator(desc); | ||
| 255 | const HRESULT actual = create_compute(layer_dev.p, desc); | ||
| 256 | if (actual != expected) { | ||
| 257 | std::fprintf(stderr, "FAIL [%s]: layer returned 0x%08lx, expected 0x%08lx\n", label, | ||
| 258 | static_cast<unsigned long>(actual), static_cast<unsigned long>(expected)); | ||
| 259 | return false; | ||
| 260 | } | ||
| 261 | ++checked; | ||
| 262 | for (const auto& hcp : hosts) { | ||
| 263 | const HostContext& hc = *hcp; | ||
| 264 | D3D12_COMPUTE_PIPELINE_STATE_DESC hdesc{}; | ||
| 265 | hdesc.pRootSignature = hc.root.p; | ||
| 266 | hdesc.CS = hc.cs; | ||
| 267 | mutator(hdesc); | ||
| 268 | const HRESULT hhr = create_compute(hc.device.p, hdesc); | ||
| 269 | if (hhr != actual) { | ||
| 270 | std::fprintf(stderr, "FAIL [%s]: layer 0x%08lx != host %s 0x%08lx\n", label, | ||
| 271 | static_cast<unsigned long>(actual), hc.name.c_str(), static_cast<unsigned long>(hhr)); | ||
| 272 | return false; | ||
| 273 | } | ||
| 274 | ++host_compared; | ||
| 275 | } | ||
| 276 | return true; | ||
| 277 | }; | ||
| 278 | |||
| 279 | // 1. Baseline & null pInputElementDescs crash guards. | ||
| 280 | EXPECT(check_gfx_parity("gfx: baseline", S_OK, false, false, [](auto&) {})); | ||
| 281 | EXPECT(check_gfx_parity("gfx: InputLayout null ptr, N=1, VS requires inputs", E_INVALIDARG, true, false, | ||
| 282 | [](auto& d) { d.InputLayout = {nullptr, 1}; })); | ||
| 283 | EXPECT(check_gfx_layer_only("gfx: InputLayout null ptr, N=1, VS has no inputs", E_INVALIDARG, | ||
| 284 | [](auto& d) { d.InputLayout = {nullptr, 1}; })); | ||
| 285 | EXPECT(check_gfx_layer_only("gfx: InputLayout null ptr, N=33", E_INVALIDARG, | ||
| 286 | [](auto& d) { d.InputLayout = {nullptr, 33}; })); | ||
| 287 | |||
| 288 | // 2. InputLayout validation (bounds, SemanticName, InputSlot, InputSlotClass, InstanceDataStepRate). | ||
| 289 | std::vector<D3D12_INPUT_ELEMENT_DESC> elems32(32), elems33(33); | ||
| 290 | for (UINT i = 0; i < 32; ++i) | ||
| 291 | elems32[i] = {"TEXCOORD", i, DXGI_FORMAT_R32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, | ||
| 292 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}; | ||
| 293 | for (UINT i = 0; i < 33; ++i) | ||
| 294 | elems33[i] = {"TEXCOORD", i, DXGI_FORMAT_R32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, | ||
| 295 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}; | ||
| 296 | |||
| 297 | EXPECT(check_gfx_parity("gfx: InputLayout NumElements=32", S_OK, false, false, | ||
| 298 | [&](auto& d) { d.InputLayout = {elems32.data(), 32}; })); | ||
| 299 | EXPECT(check_gfx_parity("gfx: InputLayout NumElements=33", E_INVALIDARG, false, false, | ||
| 300 | [&](auto& d) { d.InputLayout = {elems33.data(), 33}; })); | ||
| 301 | |||
| 302 | const D3D12_INPUT_ELEMENT_DESC e_null_sem{nullptr, 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, | ||
| 303 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}; | ||
| 304 | const D3D12_INPUT_ELEMENT_DESC e_empty_sem{"", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, | ||
| 305 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}; | ||
| 306 | const D3D12_INPUT_ELEMENT_DESC e_slot31{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 31, 0, | ||
| 307 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}; | ||
| 308 | const D3D12_INPUT_ELEMENT_DESC e_slot32{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 32, 0, | ||
| 309 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}; | ||
| 310 | const D3D12_INPUT_ELEMENT_DESC e_pv_step1{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, | ||
| 311 | D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 1}; | ||
| 312 | const D3D12_INPUT_ELEMENT_DESC e_pi_step0{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, | ||
| 313 | D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA, 0}; | ||
| 314 | const D3D12_INPUT_ELEMENT_DESC e_pi_step1{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, | ||
| 315 | D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA, 1}; | ||
| 316 | const D3D12_INPUT_ELEMENT_DESC e_bad_cls{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, | ||
| 317 | static_cast<D3D12_INPUT_CLASSIFICATION>(2), 0}; | ||
| 318 | |||
| 319 | EXPECT(check_gfx_parity("gfx: InputLayout SemanticName=nullptr", E_INVALIDARG, false, false, | ||
| 320 | [&](auto& d) { d.InputLayout = {&e_null_sem, 1}; })); | ||
| 321 | EXPECT(check_gfx_parity("gfx: InputLayout SemanticName empty string", S_OK, false, false, | ||
| 322 | [&](auto& d) { d.InputLayout = {&e_empty_sem, 1}; })); | ||
| 323 | EXPECT(check_gfx_parity("gfx: InputLayout InputSlot=31", S_OK, false, false, | ||
| 324 | [&](auto& d) { d.InputLayout = {&e_slot31, 1}; })); | ||
| 325 | EXPECT(check_gfx_parity("gfx: InputLayout InputSlot=32", E_INVALIDARG, false, false, | ||
| 326 | [&](auto& d) { d.InputLayout = {&e_slot32, 1}; })); | ||
| 327 | EXPECT(check_gfx_parity("gfx: InputLayout PER_VERTEX + stepRate=1", E_INVALIDARG, false, false, | ||
| 328 | [&](auto& d) { d.InputLayout = {&e_pv_step1, 1}; })); | ||
| 329 | EXPECT(check_gfx_parity("gfx: InputLayout PER_INSTANCE + stepRate=0", S_OK, false, false, | ||
| 330 | [&](auto& d) { d.InputLayout = {&e_pi_step0, 1}; })); | ||
| 331 | EXPECT(check_gfx_parity("gfx: InputLayout PER_INSTANCE + stepRate=1", S_OK, false, false, | ||
| 332 | [&](auto& d) { d.InputLayout = {&e_pi_step1, 1}; })); | ||
| 333 | EXPECT(check_gfx_parity("gfx: InputLayout invalid InputSlotClass=2", E_INVALIDARG, false, false, | ||
| 334 | [&](auto& d) { d.InputLayout = {&e_bad_cls, 1}; })); | ||
| 335 | |||
| 336 | // 3. BlendState validation (BlendEnable && LogicOpEnable, IndependentBlendEnable && LogicOpEnable, LogicOp range). | ||
| 337 | EXPECT(check_gfx_parity("gfx: BlendEnable && LogicOpEnable (N=1)", E_INVALIDARG, false, true, [](auto& d) { | ||
| 338 | d.BlendState.RenderTarget[0].BlendEnable = TRUE; | ||
| 339 | d.BlendState.RenderTarget[0].LogicOpEnable = TRUE; | ||
| 340 | })); | ||
| 341 | EXPECT(check_gfx_parity("gfx: BlendEnable && LogicOpEnable (N=0)", E_INVALIDARG, false, false, [](auto& d) { | ||
| 342 | d.NumRenderTargets = 0; | ||
| 343 | d.RTVFormats[0] = DXGI_FORMAT_UNKNOWN; | ||
| 344 | d.BlendState.RenderTarget[0].BlendEnable = TRUE; | ||
| 345 | d.BlendState.RenderTarget[0].LogicOpEnable = TRUE; | ||
| 346 | })); | ||
| 347 | EXPECT(check_gfx_parity("gfx: IndependentBlend && RT0.LogicOp (N=1)", E_INVALIDARG, false, true, [](auto& d) { | ||
| 348 | d.BlendState.IndependentBlendEnable = TRUE; | ||
| 349 | d.BlendState.RenderTarget[0].LogicOpEnable = TRUE; | ||
| 350 | })); | ||
| 351 | EXPECT(check_gfx_parity("gfx: IndependentBlend && RT0.LogicOp (N=0)", E_INVALIDARG, false, false, [](auto& d) { | ||
| 352 | d.NumRenderTargets = 0; | ||
| 353 | d.RTVFormats[0] = DXGI_FORMAT_UNKNOWN; | ||
| 354 | d.BlendState.IndependentBlendEnable = TRUE; | ||
| 355 | d.BlendState.RenderTarget[0].LogicOpEnable = TRUE; | ||
| 356 | })); | ||
| 357 | EXPECT(check_gfx_parity("gfx: IndependentBlend && RT1.LogicOp (N=2)", E_INVALIDARG, false, true, [](auto& d) { | ||
| 358 | d.NumRenderTargets = 2; | ||
| 359 | d.RTVFormats[1] = DXGI_FORMAT_R8G8B8A8_UINT; | ||
| 360 | d.BlendState.IndependentBlendEnable = TRUE; | ||
| 361 | d.BlendState.RenderTarget[1].LogicOpEnable = TRUE; | ||
| 362 | })); | ||
| 363 | EXPECT(check_gfx_parity("gfx: IndependentBlend=0 ignores RT1 Blend+LogicOp", S_OK, false, false, [](auto& d) { | ||
| 364 | d.BlendState.IndependentBlendEnable = FALSE; | ||
| 365 | d.BlendState.RenderTarget[1].BlendEnable = TRUE; | ||
| 366 | d.BlendState.RenderTarget[1].LogicOpEnable = TRUE; | ||
| 367 | })); | ||
| 368 | EXPECT(check_gfx_parity("gfx: IndependentBlend=1 checks RT1 even when N=1", E_INVALIDARG, false, false, | ||
| 369 | [](auto& d) { | ||
| 370 | d.BlendState.IndependentBlendEnable = TRUE; | ||
| 371 | d.BlendState.RenderTarget[1].BlendEnable = TRUE; | ||
| 372 | d.BlendState.RenderTarget[1].LogicOpEnable = TRUE; | ||
| 373 | })); | ||
| 374 | EXPECT(check_gfx_parity("gfx: LogicOp out of range (N=1)", E_INVALIDARG, false, true, [](auto& d) { | ||
| 375 | d.BlendState.RenderTarget[0].LogicOpEnable = TRUE; | ||
| 376 | d.BlendState.RenderTarget[0].LogicOp = static_cast<D3D12_LOGIC_OP>(16); | ||
| 377 | })); | ||
| 378 | EXPECT(check_gfx_parity("gfx: LogicOp out of range (N=0)", E_INVALIDARG, false, false, [](auto& d) { | ||
| 379 | d.NumRenderTargets = 0; | ||
| 380 | d.RTVFormats[0] = DXGI_FORMAT_UNKNOWN; | ||
| 381 | d.BlendState.RenderTarget[0].LogicOpEnable = TRUE; | ||
| 382 | d.BlendState.RenderTarget[0].LogicOp = static_cast<D3D12_LOGIC_OP>(16); | ||
| 383 | })); | ||
| 384 | if (vk_dev.enabled.logicOp == VK_TRUE) { | ||
| 385 | EXPECT(check_gfx_parity("gfx: valid LogicOp XOR on R8G8B8A8_UINT", S_OK, false, true, [](auto& d) { | ||
| 386 | d.BlendState.RenderTarget[0].LogicOpEnable = TRUE; | ||
| 387 | d.BlendState.RenderTarget[0].LogicOp = D3D12_LOGIC_OP_XOR; | ||
| 388 | })); | ||
| 389 | } | ||
| 390 | |||
| 391 | // 4. RTVFormats validation. | ||
| 392 | EXPECT(check_gfx_parity("gfx: RTVFormats[1]!=UNKNOWN with N=1", E_INVALIDARG, false, false, | ||
| 393 | [](auto& d) { d.RTVFormats[1] = DXGI_FORMAT_R8G8B8A8_UNORM; })); | ||
| 394 | EXPECT(check_gfx_parity("gfx: RTVFormats[0]!=UNKNOWN with N=0", E_INVALIDARG, false, false, [](auto& d) { | ||
| 395 | d.NumRenderTargets = 0; | ||
| 396 | d.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 397 | })); | ||
| 398 | EXPECT(check_gfx_parity("gfx: RTVFormats[0]==UNKNOWN with N=1", S_OK, false, false, | ||
| 399 | [](auto& d) { d.RTVFormats[0] = DXGI_FORMAT_UNKNOWN; })); | ||
| 400 | EXPECT(check_gfx_parity("gfx: NumRenderTargets=9", E_INVALIDARG, false, false, | ||
| 401 | [](auto& d) { d.NumRenderTargets = 9; })); | ||
| 402 | |||
| 403 | // 5. DSVFormat validation. | ||
| 404 | EXPECT(check_gfx_parity("gfx: DSVFormat=D32_FLOAT", S_OK, false, false, | ||
| 405 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_D32_FLOAT; })); | ||
| 406 | EXPECT(check_gfx_parity("gfx: DSVFormat=D16_UNORM", S_OK, false, false, | ||
| 407 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_D16_UNORM; })); | ||
| 408 | EXPECT(check_gfx_parity("gfx: DSVFormat=D24_UNORM_S8_UINT", S_OK, false, false, | ||
| 409 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT; })); | ||
| 410 | EXPECT(check_gfx_parity("gfx: DSVFormat=D32_FLOAT_S8X24_UINT", S_OK, false, false, | ||
| 411 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_D32_FLOAT_S8X24_UINT; })); | ||
| 412 | EXPECT(check_gfx_parity("gfx: DSVFormat=9999 (unknown)", E_INVALIDARG, false, false, | ||
| 413 | [](auto& d) { d.DSVFormat = static_cast<DXGI_FORMAT>(9999); })); | ||
| 414 | // Layer-strict DSVFormat checks: reject typeless and non-depth formats to avoid invalid Vulkan depthAttachmentFormat. | ||
| 415 | EXPECT(check_gfx_layer_only("gfx: DSVFormat=R32_TYPELESS", E_INVALIDARG, | ||
| 416 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_R32_TYPELESS; })); | ||
| 417 | EXPECT(check_gfx_layer_only("gfx: DSVFormat=R16_TYPELESS", E_INVALIDARG, | ||
| 418 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_R16_TYPELESS; })); | ||
| 419 | EXPECT(check_gfx_layer_only("gfx: DSVFormat=R24G8_TYPELESS", E_INVALIDARG, | ||
| 420 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_R24G8_TYPELESS; })); | ||
| 421 | EXPECT(check_gfx_layer_only("gfx: DSVFormat=R32G8X24_TYPELESS", E_INVALIDARG, | ||
| 422 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_R32G8X24_TYPELESS; })); | ||
| 423 | EXPECT(check_gfx_layer_only("gfx: DSVFormat=R8G8B8A8_UNORM (color)", E_INVALIDARG, | ||
| 424 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_R8G8B8A8_UNORM; })); | ||
| 425 | EXPECT(check_gfx_layer_only("gfx: DSVFormat=R32_FLOAT (color)", E_INVALIDARG, | ||
| 426 | [](auto& d) { d.DSVFormat = DXGI_FORMAT_R32_FLOAT; })); | ||
| 427 | |||
| 428 | // 6. NodeMask and Flags validation (Graphics & Compute). | ||
| 429 | EXPECT(check_gfx_parity("gfx: NodeMask=0", S_OK, false, false, [](auto& d) { d.NodeMask = 0; })); | ||
| 430 | EXPECT(check_gfx_parity("gfx: NodeMask=1", S_OK, false, false, [](auto& d) { d.NodeMask = 1; })); | ||
| 431 | EXPECT(check_gfx_parity("gfx: NodeMask=2", E_INVALIDARG, false, false, [](auto& d) { d.NodeMask = 2; })); | ||
| 432 | EXPECT(check_gfx_parity("gfx: NodeMask=3", E_INVALIDARG, false, false, [](auto& d) { d.NodeMask = 3; })); | ||
| 433 | EXPECT(check_gfx_parity("gfx: NodeMask=0x80000000", E_INVALIDARG, false, false, | ||
| 434 | [](auto& d) { d.NodeMask = 0x80000000u; })); | ||
| 435 | EXPECT(check_gfx_parity("gfx: Flags=DYNAMIC_DEPTH_BIAS", S_OK, false, false, | ||
| 436 | [](auto& d) { d.Flags = D3D12_PIPELINE_STATE_FLAG_DYNAMIC_DEPTH_BIAS; })); | ||
| 437 | EXPECT(check_gfx_parity("gfx: Flags=DYNAMIC_INDEX_BUFFER_STRIP_CUT", S_OK, false, false, | ||
| 438 | [](auto& d) { d.Flags = D3D12_PIPELINE_STATE_FLAG_DYNAMIC_INDEX_BUFFER_STRIP_CUT; })); | ||
| 439 | EXPECT(check_gfx_parity("gfx: Flags=0x10 (unknown bit)", E_INVALIDARG, false, false, | ||
| 440 | [](auto& d) { d.Flags = static_cast<D3D12_PIPELINE_STATE_FLAGS>(0x10); })); | ||
| 441 | EXPECT(check_gfx_parity("gfx: Flags=0x80000000 (unknown bit)", E_INVALIDARG, false, false, | ||
| 442 | [](auto& d) { d.Flags = static_cast<D3D12_PIPELINE_STATE_FLAGS>(0x80000000u); })); | ||
| 443 | EXPECT(check_gfx_layer_only("gfx: Flags=TOOL_DEBUG (cached-PSO parity)", S_OK, | ||
| 444 | [](auto& d) { d.Flags = D3D12_PIPELINE_STATE_FLAG_TOOL_DEBUG; })); | ||
| 445 | |||
| 446 | EXPECT(check_cs_parity("cs: baseline", S_OK, [](auto&) {})); | ||
| 447 | EXPECT(check_cs_parity("cs: NodeMask=0", S_OK, [](auto& d) { d.NodeMask = 0; })); | ||
| 448 | EXPECT(check_cs_parity("cs: NodeMask=1", S_OK, [](auto& d) { d.NodeMask = 1; })); | ||
| 449 | EXPECT(check_cs_parity("cs: NodeMask=2", E_INVALIDARG, [](auto& d) { d.NodeMask = 2; })); | ||
| 450 | EXPECT(check_cs_parity("cs: NodeMask=3", E_INVALIDARG, [](auto& d) { d.NodeMask = 3; })); | ||
| 451 | EXPECT(check_cs_parity("cs: NodeMask=0x80000000", E_INVALIDARG, [](auto& d) { d.NodeMask = 0x80000000u; })); | ||
| 452 | EXPECT(check_cs_parity("cs: Flags=DYNAMIC_DEPTH_BIAS", S_OK, | ||
| 453 | [](auto& d) { d.Flags = D3D12_PIPELINE_STATE_FLAG_DYNAMIC_DEPTH_BIAS; })); | ||
| 454 | EXPECT(check_cs_parity("cs: Flags=DYNAMIC_INDEX_BUFFER_STRIP_CUT", S_OK, | ||
| 455 | [](auto& d) { d.Flags = D3D12_PIPELINE_STATE_FLAG_DYNAMIC_INDEX_BUFFER_STRIP_CUT; })); | ||
| 456 | EXPECT(check_cs_parity("cs: Flags=0x10 (unknown bit)", E_INVALIDARG, | ||
| 457 | [](auto& d) { d.Flags = static_cast<D3D12_PIPELINE_STATE_FLAGS>(0x10); })); | ||
| 458 | EXPECT(check_cs_parity("cs: Flags=0x80000000 (unknown bit)", E_INVALIDARG, | ||
| 459 | [](auto& d) { d.Flags = static_cast<D3D12_PIPELINE_STATE_FLAGS>(0x80000000u); })); | ||
| 460 | { | ||
| 461 | D3D12_COMPUTE_PIPELINE_STATE_DESC cs_debug{}; | ||
| 462 | cs_debug.pRootSignature = layer_root.p; | ||
| 463 | cs_debug.CS = layer_cs; | ||
| 464 | cs_debug.Flags = D3D12_PIPELINE_STATE_FLAG_TOOL_DEBUG; | ||
| 465 | EXPECT(create_compute(layer_dev.p, cs_debug) == S_OK); | ||
| 466 | ++checked; | ||
| 467 | } | ||
| 468 | |||
| 469 | const std::size_t host_count = hosts.size(); | ||
| 470 | hosts.clear(); | ||
| 471 | hlsl_vs_fs.reset(); | ||
| 472 | hlsl_vs_pos.reset(); | ||
| 473 | hlsl_ps_unorm.reset(); | ||
| 474 | hlsl_ps_uint.reset(); | ||
| 475 | hlsl_cs.reset(); | ||
| 476 | if (compiler_dll) FreeLibrary(compiler_dll); | ||
| 477 | std::printf("d3d12_pso_validation_test: PASS (%u layer checks, %u host comparisons across %zu host device(s))\n", | ||
| 478 | checked, host_compared, host_count); | ||
| 479 | return 0; | ||
| 480 | } | ||