Repository navigation
Runtime: geometry shaders in graphics PSOs (VS + GS + PS) - #2109
Conversation
|
Tested
|
|
Tested a580e16 on an RTX 3060 12 GB, NVIDIA 621.14, Vulkan 1.4.357, Windows 11 26H2: pass. I built and ran the unmodified d3d12_geometry_test.exe twice. All 4,096 pixels matched in both runs. The geometry shader drew the expected copy of the quad, and the pipeline with the incompatible line topology was rejected as expected. The repeat run exited with code 0. Build: clang-cl 23.1.6, Windows SDK 10.0.26100 via xwin, CMake 4.5.1, Ninja 1.13.2, and glslang 16.6.0. Vulkan validation layers were disabled. Synthetic inputs only. AI-assisted setup and verification; tests ran locally. |
0xTehuti
left a comment
There was a problem hiding this comment.
GPU Verification & Code Review Findings (NVIDIA Turing / RTX 2070 SUPER)
Tested on Windows 11 with MSVC 2022, Ninja, CMake, and Vulkan SDK 1.4:
- GPU: NVIDIA GeForce RTX 2070 SUPER (Driver 595.79, 8192 MB VRAM, Vulkan 1.4.363)
- Validation Layers: Khronos Validation Layer active (
LEONIDA_VK_VALIDATION=1)
1. Hardware Test Results
d3d12_geometry_test: PASSED (0.33s, 4,096 / 4,096 pixels matched exactly, 0 validation errors).d3d12_vulkan_device_test: PASSED (9.32s, 0 validation errors).
2. Critical Defect Detected: Heap Corruption in Recipe::required_sizes
While the synthetic test in d3d12_geometry_test passed (because its test shaders do not specify subgroup sizes), there is an out-of-bounds write in runtime/shims/d3d12_vulkan_device.cpp that will corrupt memory when processing real translated geometry and pixel shaders:
In line 2532:
struct Recipe {
std::vector<VkPipelineShaderStageCreateInfo> stages;
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo required_sizes[2]{}; // <-- declared size 2
std::vector<VkVertexInputAttributeDescription> attributes;
...
};Lines 2134–2184 iterate over Stage stages[3] (VS, GS, PS). When line 2182 is reached for the fragment stage (stage_infos.size() == 2):
subgroup_size_for(*stage.entry, required_sizes[stage_infos.size()], info);It accesses required_sizes[2], which is beyond the 2-element array bounds. This writes 24 bytes directly into the adjacent recipe_.attributes (std::vector control block). Furthermore, info.pNext points to this out-of-bounds address, resulting in dangling / overwritten pointers during variant compilation.
Required Fix
Update required_sizes array bound from 2 to 3 in runtime/shims/d3d12_vulkan_device.cpp:
--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -2532,1 +2532,1 @@
- VkPipelineShaderStageRequiredSubgroupSizeCreateInfo required_sizes[2]{}; // what `stages` chain
+ VkPipelineShaderStageRequiredSubgroupSizeCreateInfo required_sizes[3]{}; // what `stages` chainOnce this patch is applied, this PR is clean and ready for merge on NVIDIA Turing.
AI-assisted verification (Orca / Antigravity). No game data used.
…, PS) The recipe kept two VkPipelineShaderStageRequiredSubgroupSizeCreateInfo, one per stage of the old VS+PS table; with a GS the PS's subgroup request wrote a third one past the array, into the recipe's attribute vector (found by @0xTehuti on ItsNotRexed#2109). The array now has three entries and a static_assert ties it to the stage table. d3d12_geometry_test's PS asks for a 32-wide subgroup, so a VS+GS+PS pipeline fills the third struct: without the fix the test crashes (3 of 3 runs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@0xTehuti, thanks, that was a real overflow:
@JavierBlanco23 and @umnitus, thanks for the RTX 5080 and RTX 3060 runs. They were on |
|
Independent verification of
All modules used passed |
CreateGraphicsPipelineState refused any desc.GS, although all 195 geometry shaders translate (triangles in, a triangle strip out; docs/design.md "Geometry shaders"). The stage table now holds VS, GS and PS; a GS needs the geometryShader feature (enabled on the standalone and test devices where the GPU has it, E_NOTIMPL otherwise), and the PSO's topology type must be TRIANGLE, the GS's input (E_INVALIDARG otherwise). The push-constant range names the geometry stage only where the device has it. Hull, domain and stream output stay refused. d3d12_geometry_test (in ctest): a GS that emits each triangle twice, against a pipeline without one, and a line topology refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, PS) The recipe kept two VkPipelineShaderStageRequiredSubgroupSizeCreateInfo, one per stage of the old VS+PS table; with a GS the PS's subgroup request wrote a third one past the array, into the recipe's attribute vector (found by @0xTehuti on ItsNotRexed#2109). The array now has three entries and a static_assert ties it to the stage table. d3d12_geometry_test's PS asks for a 32-wide subgroup, so a VS+GS+PS pipeline fills the third struct: without the fix the test crashes (3 of 3 runs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b82b769 to
9b50f17
Compare
|
@whattheflop, thanks for the RTX 3080 and iGPU runs, including the translator-generated |
…since #2109 #2109 made the PSO stages {vs, gs, ps}; the --f16-interp-fallback link (SHADER-378, #2389) still read the PS from stages[1], found the empty GS slot and never ran, so d3d12_f16_halves drew nothing. With a GS the PS reads the GS's outputs, so the VS/PS link is skipped there (logged once). Also: xgameruntime_test re-reads the package id after clearing the LEONIDA_PACKAGE_ID override. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed#2402's user_data_layout call took {stages[0], stages[1]}, written when a graphics PSO's stages were {vs, ps}. Since ItsNotRexed#2109 they are {vs, gs, ps}, so on main stages[1] is the (usually empty) GS slot: the PS's pc_tail never reached the pipeline layout, set 1 was left out, and a --pc-tail-ubo PS failed VUID-VkGraphicsPipelineCreateInfo-layout-07988 and drew nothing (d3d12_draw_test line 358, d3d12_bundle's twin run). All three stages are passed now; user_data_layout skips the absent ones. This is the same slip 81ec7f7 fixed for the f16 halves link. Found rebasing ItsNotRexed#3106 onto main f847748. With it, d3d12_draw_test, d3d12_bundle, d3d12_typeless_families, d3d12_ia_bounds and d3d12_compute pass with LEONIDA_VK_VALIDATION=1 and no validation error on an RTX 5090 (NVIDIA 621.35) and an AMD Radeon iGPU (AMD 26.5.2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed#2402's user_data_layout call took {stages[0], stages[1]}, written when a graphics PSO's stages were {vs, ps}. Since ItsNotRexed#2109 they are {vs, gs, ps}, so on main stages[1] is the (usually empty) GS slot: the PS's pc_tail never reached the pipeline layout, set 1 was left out, and a --pc-tail-ubo PS failed VUID-VkGraphicsPipelineCreateInfo-layout-07988 and drew nothing (d3d12_draw_test line 358, d3d12_bundle's twin run). All three stages are passed now; user_data_layout skips the absent ones. This is the same slip 81ec7f7 fixed for the f16 halves link. Found rebasing ItsNotRexed#3106 onto main f847748. With it, d3d12_draw_test, d3d12_bundle, d3d12_typeless_families, d3d12_ia_bounds and d3d12_compute pass with LEONIDA_VK_VALIDATION=1 and no validation error on an RTX 5090 (NVIDIA 621.35) and an AMD Radeon iGPU (AMD 26.5.2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in #1902 (new D3D item).
What and why
CreateGraphicsPipelineStaterefused any PSO with aGS("graphics pipeline stage not supported yet (hull/domain/geometry/stream output)"), and nothing enabledgeometryShader. The translator already handles all 195 geometry shaders in the corpus ($GS_VoxelizeGeneric, triangles in, a triangle strip out; docs/design.md, "Geometry shaders", GPU-checked withgs_tri.asm). Without this PR, every PSO that uses one fails.d3d12_vulkan_device.cpp): VS, GS, PS. The GS goes through the same path as the other stages: lookup by FSSM hash in the index (stage: "gs"), set-0 bindings, code base, and subgroup size.geometryShader; without it the PSO isE_NOTIMPLwith a log.PrimitiveTopologyTypemust beTRIANGLE, the translated GS's input primitive, as D3D12 requires the topology to match the GS input; otherwiseE_INVALIDARG.VK_SHADER_STAGE_GEOMETRY_BITonly on a device that has the stage. The loop over the stage table would otherwise name a stage the device can't run.geometryShaderwhere the GPU has it and reports it inVulkanDeviceInfo::features.vk_test_device.henables it too.docs/d3d12_vulkan.md, and geometry removed from the "refused" list.Tested
AMD Radeon RX 7800 XT (RDNA3), driver 26.10.1 (32.0.32015.7029), Windows 11 Pro (26300), MSVC 14.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0,
LEONIDA_VK_VALIDATION=1:d3d12_geometry_test(new, in ctest withSKIP_RETURN_CODE 77):test/glsl/gs_double.geomhas a translated GS's interface and emits every triangle twice, the copy one clip-space unit to the right.LINEtopology type isE_INVALIDARG.ctest -j4110/111. The one failure isd3d12_draw(bundle blend), which also fails on cleanmainand which fix(test): use monotonic fence value (31) for bundle blend pass in d3d12_draw_test #1807 addresses.Not covered: the test GS is GLSL with the translator's interface, not a translated
$GS_VoxelizeGeneric. A real one through this path needs its VS's outputs to line up with the GS inputs, which #1694's interface check covers on the translator side. Stream output (SOSetTargets) is still open.Checklist
docs/design.md, with how it was confirmed. (N/A: runtime only.)AI-assisted (Claude Code).
🤖 Generated with Claude Code