Repository navigation
d3d12: accept StreamOutput PSOs, implement SOSetTargets, capture draws via VK_EXT_transform_feedback (D3D-STREAMOUTPUT-RUNTIME) - #1884
Conversation
Foundation for D3D-302 (stream output): read the physical device's transformFeedback/geometryStreams features where the extension is present, record them on VulkanDeviceInfo, and enable them on the logical device when supported, exactly the same pattern the existing VK_EXT_mesh_shader detection/enable code already follows. Device-capability plumbing only: no behaviour changes yet. A graphics PSO declaring StreamOutput is still refused and SOSetTargets is still not implemented, same as before this commit. Confirmed VK_EXT_transform_feedback is available (4 streams, 4 buffers) on an NVIDIA GeForce RTX 4070 SUPER, driver 621.24. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…s via VK_EXT_transform_feedback Builds on D3D-TRANSFORM-FEEDBACK-DEVICE (the device-capability plumbing): a graphics PSO that declares StreamOutput is now accepted instead of refused (the common case only: RasterizedStream 0, NumStrides within the device's maxTransformFeedbackBuffers), SOSetTargets stores the bound buffers on the command list the same way IASetVertexBuffers does, and a draw with a pipeline that has StreamOutput and every declared buffer slot bound wraps itself in vkCmdBindTransformFeedbackBuffersEXT + vkCmdBeginTransformFeedbackEXT / vkCmdEndTransformFeedbackEXT, writing real captured data. Not done, left as follow-up: - RasterizedStream other than 0 (needs VkPipelineRasterizationStateStreamCreateInfoEXT / rasterizerDiscardEnable at pipeline creation) - SO_STATISTICS queries (still stubbed to 0; the real wiring is VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT with the indexed vkCmdBeginQueryIndexedEXT/EndQueryIndexedEXT commands) - Matching a real translated game shader's output semantics to StreamOutput buffer slots, which needs patching Xfb decorations into its SPIR-V at PSO creation time (the translator runs before any PSO exists, so it cannot know this ahead of time) - this PR's own test uses a hand-written GLSL shader with the decorations already in place, not a translated one ### Tested New test d3d12_stream_output_test.cpp: a StreamOutput PSO with a hand-written vertex shader (runtime/test/glsl/vs_stream_output.vert, Xfb-decorated, writes the fixed vec4 (1,2,3,4)) draws 3 vertices; the buffer SOSetTargets bound is read back and every vertex's 16 bytes are checked against that constant. 0 mismatches on real hardware. Full ctest run (runtime/build, RelWithDebInfo): 307/308 pass (one more test than main, the new one); the only failure is the pre-existing d3d12_execute_indirect_validation (ProjectLeonida#504, fixed by the separate PR ProjectLeonida#1066, unrelated to this change). No regressions. GPU: NVIDIA GeForce RTX 4070 SUPER, driver 621.24, Windows 11 26300.9974. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Nice work — this is the capture path we were also poking at. Two concrete gaps from our own capture work ( 1. The TF buffer usage bits are missing. if (info.transform_feedback)
result.usage |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT |
VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT;2. Counter width. Also, the test passes One semantic question: Vulkan writes a primitive/vertex count to the counter buffer, while D3D12's filled size is bytes. Binding the Coordination: #1891 adopts #1236 (with the Snooozs comment/log fix) and has an NVIDIA LGTM; once it lands, this can rebase onto AI-assisted. |
|
Verified the usage-bit finding end to end on Windows 11 / NVIDIA RTX 3080 Ti (driver 616.64, Vulkan SDK 1.4.363.0, Khronos validation layer), by rebasing the capture commit onto our #1891 foundation and running the new test.
Branch to cherry-pick:
The usage-bit hunk is the same at every site: if (<info>.transform_feedback)
<usage> |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT |
VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_COUNTER_BUFFER_BIT_EXT;( The counter semantics note from before still stands (Vulkan's counter is a primitive/vertex count; D3D12's filled size is bytes). Happy to open a PR against your branch if that is easier, or you can cherry-pick the two commits. AI-assisted. |
|
Heads-up: this is CONFLICTING with main (our duplicate copy, #1925, is closed, so there is no competing implementation). The (Correction to my first version: #1148 is another older conflicting PR, so this is not the only one; both need a rebase.) |
|
Merge order for the TF cluster is on #1891: #1891 (comment) . This PR is step 3: rebase onto main after #1891 lands (your first commit is #1236, which #1891 adopts, so that copy drops). The TF buffer-usage + 4-byte counter fixes, with the test passing under validation, are in BubsMcgee/leonida:cap-1884-fixed. |
Claimed in the coordination issue as: D3D-STREAMOUTPUT-RUNTIME (#1608 (comment))
Depends on: #1236
What and why
The capture path #1630 (D3D-302) explicitly left unclaimed: "StreamOutput PSOs are still refused and SOSetTargets is still not implemented; the capture path is not part of this PR." This PR is that capture path.
A graphics PSO that declares
StreamOutputis now accepted instead of refused (the common case:RasterizedStream0,NumStrideswithin the device'smaxTransformFeedbackBuffers).SOSetTargetsstores the bound buffers on the command list the same wayIASetVertexBuffersalready does. A draw whose pipeline hasStreamOutputand every declared buffer slot currently bound wraps itself invkCmdBindTransformFeedbackBuffersEXT+vkCmdBeginTransformFeedbackEXT/vkCmdEndTransformFeedbackEXT, writing real captured data to the bound buffers.Stacked on #1236, same as #1630: the first commit is #1236's device detect/enable, unchanged. When #1236 merges I will rebase and drop that copy.
Touches the same few files as #1630 (
d3d12_com.h,d3d12_vulkan_device.cpp,vulkan_backend.h,vulkan_replay.h) but a different part of each - the query-heap code I touched is only a comment update (theSO_STATISTICSpools themselves stay #1630's). A rebase against each other may be needed depending on merge order.Not done, left as follow-up (noted in the code and in
docs/d3d12_vulkan.md):RasterizedStreamother than 0 (needsVkPipelineRasterizationStateStreamCreateInfoEXT/rasterizerDiscardEnableat pipeline creation)SO_STATISTICSqueries (d3d12: real SO_STATISTICS query pools (D3D-302) #1630's follow-up)Xfbdecorations into its SPIR-V at PSO-creation time (the translator runs before any PSO exists, so it cannot know this ahead of time)Tested
New test
d3d12_stream_output_test.cpp: a StreamOutput PSO with a hand-written vertex shader (runtime/test/glsl/vs_stream_output.vert,Xfb-decorated, writes the fixed vec4(1,2,3,4)) draws 3 vertices; the bufferSOSetTargetsbound is read back and every vertex's 16 bytes are checked against that constant. 0 mismatches on real hardware.Full
ctest(runtime/build, RelWithDebInfo): 307/308 pass (one more test thanmain, the new one); the only failure is the pre-existingd3d12_execute_indirect_validation(#504, fixed by the separate PR #1066, unrelated to this change). No regressions.GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.24, Windows 11 26300.9974, Vulkan SDK 1.4.363.1.
AI-assisted: yes (Claude Code)
Checklist
main(stacked on d3d12_vulkan_device: detect and enable VK_EXT_transform_feedback (D3D-TRANSFORM-FEEDBACK-DEVICE) #1236) and merges cleanly.