Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3788,15 +3788,20 @@ Implemented (`QueryHeap` in `runtime/shims/d3d12_vulkan_device.cpp`, the query c
(`compare_invalid_arguments`, "query heap:", RTX 5070 / 621.14): `E_INVALIDARG` for no queries, a node other than
node 0, or a type past `PIPELINE_STATISTICS1` (7), checked before the output; a valid description with a null
output is then `E_UNEXPECTED`, not `S_FALSE`.
- **Stream-output statistics** (D3D-302). The layer has no stream output: a graphics PSO with `StreamOutput`
entries is refused and `SOSetTargets` is not implemented, so no primitive reaches a stream and every
`SO_STATISTICS_STREAM0..3` query counts 0 written and 0 needed. An `SO_STATISTICS` heap is therefore made without
a `VkQueryPool`: `BeginQuery`/`EndQuery` record nothing in Vulkan (D3D12's call rules are still kept, and the
- **Stream-output statistics** (D3D-302). The layer still refuses `StreamOutput` PSOs and does not implement
`SOSetTargets`, so no primitive reaches a stream yet. With `VK_EXT_transform_feedback` enabled on the device
(`D3D-TRANSFORM-FEEDBACK-DEVICE`) and its `transformFeedbackQueries` property set, an `SO_STATISTICS` heap is a
real `VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT` pool begun and ended indexed on the stream
(`vkCmdBeginQueryIndexedEXT` / `vkCmdEndQueryIndexedEXT`), and `ResolveQueryData` copies the two 64-bit results per
query (16 bytes: `NumPrimitivesWritten`, `PrimitivesStorageNeeded`), in the same order; with no stream output they
are 0. A stream at or above the device's `maxTransformFeedbackStreams` runs nothing and resolves zero, as if the
heap had no pool. Without the feature, the property, or a nonzero `maxTransformFeedbackStreams`, the heap is made
without a `VkQueryPool`: `BeginQuery`/`EndQuery` run nothing in Vulkan (D3D12's call rules are still kept, and the
heap's queries track ended or not as the others do), they overlap no other query, and `ResolveQueryData` writes
zeros (`vkCmdFillBuffer`, 16 bytes per query: `NumPrimitivesWritten`, `PrimitivesStorageNeeded`), with no
statistics split since nothing is dispatched. When stream output lands, the heap becomes a
`VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT` pool begun with `vkCmdBeginQueryIndexedEXT` on the stream, whose two
results are in the same order.
zeros (`vkCmdFillBuffer`, 16 bytes per query), with no statistics split since nothing is dispatched. Two
overlapping `SO_STATISTICS` queries on one stream would be two active indexed queries in one pool
(`VUID-vkCmdBeginQueryIndexedEXT-queryPool-04753`), so `prepare()` refuses such a list
(`ReplayResult::invalid_query`); queries on different streams are fine.
- **Recording.** The list keeps D3D12's rules for the calls: timestamps only have `EndQuery`; every other query is
begun and ended in the same list with the same type, is not begun again while it runs, and is not resolved while
it runs; resolve offsets are multiples of 8. A list closed with a query still running reports `E_INVALIDARG` and
Expand Down
17 changes: 12 additions & 5 deletions runtime/shims/d3d12_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,20 @@ struct VulkanDeviceInfo {
// VK_EXT_mesh_shader's meshShaderQueries feature is enabled on `device`, so the clipping invocations of a mesh
// segment come from a mesh-primitives query (D3D-MESH-CLIPPING-COUNTER). Without it they read 0.
bool mesh_shader_queries = false;
// VK_EXT_transform_feedback with its transformFeedback feature is detected and enabled on `device` (D3D-302).
// Nothing uses it yet: a graphics PSO that declares StreamOutput is still refused and SOSetTargets is still not
// implemented. (#1630 adds the SO_STATISTICS query pools, which use it.)
// VK_EXT_transform_feedback with its transformFeedback feature is enabled on `device` (D3D-302): an
// SO_STATISTICS heap is a real VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool, begun and ended indexed on the
// stream. StreamOutput PSOs are still refused and SOSetTargets is still not implemented.
bool transform_feedback = false;
// VK_EXT_transform_feedback's geometryStreams feature is enabled when the device offers it. Nothing rasterizes a
// StreamOutput RasterizedStream yet; it is here for the capture implementation that follows.
// VK_EXT_transform_feedback's geometryStreams feature is offered by the device. The device-enable chain requests
// it when present so the pipeline cache key matches vk_pipeline_check; nothing rasterizes a stream other than 0.
bool transform_feedback_geometry_streams = false;
// VK_EXT_transform_feedback's transformFeedbackQueries property (D3D-302): the device can begin/end a
// VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT query. Without it an SO_STATISTICS heap is made without a pool and
// every SO_STATISTICS query resolves zero, even when the transformFeedback feature is enabled.
bool transform_feedback_queries = false;
// The device's maxTransformFeedbackStreams property: an SO_STATISTICS_STREAMn query runs only for n below it.
// Streams from this count up (to the D3D12 maximum of four) run nothing and resolve zero.
std::uint32_t max_transform_feedback_streams = 0;
// The core features enabled on `device`. Graphics PSOs that need independentBlend, fillModeNonSolid,
// depthBiasClamp or dualSrcBlend are refused unless it is set here.
VkPhysicalDeviceFeatures features{};
Expand Down
37 changes: 28 additions & 9 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10759,11 +10759,17 @@ class QueryHeap final
break;
}
case h::so_statistics:
// The layer has no stream output: a graphics PSO with StreamOutput entries is refused (E_NOTIMPL) and
// SOSetTargets is not implemented, so no primitive ever reaches a stream and every query of this heap
// counts 0 written and 0 needed. That needs no Vulkan pool: Begin/EndQuery run nothing and a resolve fills zeros. When stream
// output lands, this becomes a VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT pool (D3D-302).
return register_pool(desc);
// D3D-302: with VK_EXT_transform_feedback enabled, an SO_STATISTICS heap is a real transform-feedback
// pool whose queries begin/end on a stream (vkCmdBeginQueryIndexedEXT); a resolve copies 16 bytes per
// query (NumPrimitivesWritten, PrimitivesStorageNeeded), in the same order. StreamOutput PSOs are still
// refused and SOSetTargets is still not implemented, so no primitive reaches a stream yet and every
// query counts 0. The pool needs the transformFeedbackQueries property and at least one stream; without
// them (or without the feature) the heap is made without a pool and every query resolves to zero.
if (!device_.info.transform_feedback || !device_.info.transform_feedback_queries ||
!device_.info.max_transform_feedback_streams)
return register_pool(desc);
info.queryType = VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT;
break;
case h::pipeline_statistics:
if (!device_.info.pipeline_statistics_query) {
log_once("pipeline-statistics query heap: pipelineStatisticsQuery not enabled; type", desc.Type);
Expand Down Expand Up @@ -10792,6 +10798,9 @@ class QueryHeap final
pool.count = desc.Count;
pool.precise = device_.info.occlusion_query_precise;
pool.ended.assign(desc.Count, false);
// D3D-302: a real transform-feedback pool queries streams below maxTransformFeedbackStreams; D3D12 has four.
if (pool_ && desc.Type == leonida::d3d12_query_heap::so_statistics)
pool.streams = std::min<std::uint32_t>(4, device_.info.max_transform_feedback_streams);
device_.context->add_query_pool(id(), pool);
registered_ = true;
return S_OK;
Expand Down Expand Up @@ -17985,6 +17994,8 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
VkPhysicalDeviceMeshShaderFeaturesEXT mesh_features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_EXT};
VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback_features{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT};
VkPhysicalDeviceTransformFeedbackPropertiesEXT transform_feedback_properties{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT};
{
std::uint32_t extension_count = 0;
vkEnumerateDeviceExtensionProperties(info.physical, nullptr, &extension_count, nullptr);
Expand Down Expand Up @@ -18015,14 +18026,22 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
vkGetPhysicalDeviceFeatures2(info.physical, &features);
info.transform_feedback = transform_feedback_features.transformFeedback == VK_TRUE;
info.transform_feedback_geometry_streams = transform_feedback_features.geometryStreams == VK_TRUE;
// D3D-302: the queries and the stream count are properties, not features.
VkPhysicalDeviceProperties2 properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
&transform_feedback_properties};
vkGetPhysicalDeviceProperties2(info.physical, &properties);
info.transform_feedback_queries = transform_feedback_properties.transformFeedbackQueries == VK_TRUE;
info.max_transform_feedback_streams = transform_feedback_properties.maxTransformFeedbackStreams;
}
}
if (!info.mesh_shader)
std::fprintf(stderr, "[rt] d3d12: the GPU has no VK_EXT_mesh_shader: mesh-shader PSOs are unsupported\n");
if (!info.transform_feedback)
std::fprintf(stderr,
"[rt] d3d12: the GPU has no VK_EXT_transform_feedback: stream output is unsupported and "
"SO_STATISTICS pools read zero\n");
"[rt] d3d12: the GPU has no VK_EXT_transform_feedback: SO_STATISTICS query pools read zero\n");
else if (!info.transform_feedback_queries || !info.max_transform_feedback_streams)
std::fprintf(stderr, "[rt] d3d12: the GPU has no transform-feedback queries (transformFeedbackQueries, "
"maxTransformFeedbackStreams): SO_STATISTICS query pools read zero\n");
if (has_as && has_dho && has_rq && chosen12.bufferDeviceAddress) {
as_features.pNext = &rq_features;
VkPhysicalDeviceFeatures2 features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &as_features};
Expand Down Expand Up @@ -18058,8 +18077,8 @@ HRESULT create_vulkan_device_standalone(REFIID riid, void** out, QueueTestSettin
// The mesh-primitives query, which counts the primitives a mesh shader emits (D3D-MESH-CLIPPING-COUNTER).
enable_mesh.meshShaderQueries = info.mesh_shader_queries ? VK_TRUE : VK_FALSE;

// D3D-302: StreamOutput PSOs, SOSetTargets and real SO_STATISTICS queries need transformFeedback; geometryStreams
// is only requested when the device already offers it (RasterizedStream != 0 is the one thing it gates).
// D3D-302: real SO_STATISTICS queries need transformFeedback; geometryStreams is only requested when the device
// already offers it, so the enable chain matches vk_pipeline_check's (a driver keys the pipeline cache on it).
VkPhysicalDeviceTransformFeedbackFeaturesEXT enable_transform_feedback{
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT};
enable_transform_feedback.transformFeedback = VK_TRUE;
Expand Down
13 changes: 12 additions & 1 deletion runtime/src/vulkan_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ struct VulkanDeviceFunctions {
X(vkCreatePipelineCache) X(vkDestroyPipelineCache) X(vkGetPipelineCacheData) X(vkMergePipelineCaches) \
X(vkCreateEvent) X(vkDestroyEvent) X(vkResetEvent) X(vkCmdSetEvent) X(vkCmdWaitEvents) X(vkCmdDrawMeshTasksEXT) \
X(vkCreateRenderPass2) X(vkDestroyRenderPass) X(vkCreateFramebuffer) X(vkDestroyFramebuffer) \
X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass)
X(vkCmdBeginRenderPass) X(vkCmdEndRenderPass) \
X(vkCmdBeginQueryIndexedEXT) X(vkCmdEndQueryIndexedEXT)
#define LEONIDA_VK_MEMBER(name) PFN_##name name = nullptr;
LEONIDA_VK_DEVICE_FUNCTIONS(LEONIDA_VK_MEMBER)
#undef LEONIDA_VK_MEMBER
Expand Down Expand Up @@ -165,6 +166,9 @@ struct VulkanDeviceFunctions {
return vkCmdBeginRendering && vkCmdEndRendering && vkCmdBindVertexBuffers2 && vkCmdSetPrimitiveTopology &&
vkCmdSetPrimitiveRestartEnable;
}
// VK_EXT_transform_feedback is enabled on the device: the indexed-query entry points are loaded, so an
// SO_STATISTICS heap can be a real transform-feedback pool (D3D-302).
bool transform_feedback = false;
};

// Both kinds of compute resolve use the same storage buffer, descriptor set and pipeline layout.
Expand Down Expand Up @@ -1090,6 +1094,8 @@ class VulkanContext {
GraphicsIndirectCapabilities indirect = {})
: device_(device), tracker_(separate_depth_stencil_layouts), ray_tracing_(ray_tracing) {
loaded_ = vk.load(get, device);
// VK_EXT_transform_feedback: enabled on the device when its indexed-query entry points resolved (D3D-302).
vk.transform_feedback = vk.vkCmdBeginQueryIndexedEXT && vk.vkCmdEndQueryIndexedEXT;
if (loaded_ && gpu_labels_.initialize(device, get)) {
replay_.gpu_label = [this](VkCommandBuffer cb, const label::Write& write) { gpu_labels_.record(cb, write); };
}
Expand Down Expand Up @@ -1125,6 +1131,11 @@ class VulkanContext {
replay_.reset_query_pool = vk.vkCmdResetQueryPool;
replay_.begin_query = vk.vkCmdBeginQuery;
replay_.end_query = vk.vkCmdEndQuery;
// VK_EXT_transform_feedback (D3D-302), loaded when the device enabled it: indexed SO_STATISTICS queries.
if (vk.transform_feedback) {
replay_.begin_query_indexed = vk.vkCmdBeginQueryIndexedEXT;
replay_.end_query_indexed = vk.vkCmdEndQueryIndexedEXT;
}
replay_.write_timestamp = vk.vkCmdWriteTimestamp;
replay_.copy_query_pool_results = vk.vkCmdCopyQueryPoolResults;
replay_.bind_pipeline = vk.vkCmdBindPipeline;
Expand Down
Loading
Loading