Skip to content

Commit fafd375

Browse files
Nullpoint56claude
andcommitted
Patch 0039: Vulkan stage masks drop the shader stages the device lacks
NRI v191 turns a mask naming every shader stage (ALL_SHADERS in a barrier or fence wait, a layout whose stages are ALL) into every Vulkan stage bit, whatever the device has. MoltenVK (no geometry, mesh or ray tracing) refused every such barrier (VUID-VkImageMemoryBarrier2-dstStageMask-03929, 03934, 03935, 07946) and layout (VUID-VkPushConstantRange-stageFlags-parameter, VUID-VkPushConstantsInfo-stageFlags-parameter): CrossQueueCopyTests, D3D12DebugLayerTests and DescriptorTests failed there. The patch records the lacking stages in DeviceVK from the features it enabled and drops them in barriers, fence waits and the layout's resolved stages. StageMaskTests (NVIDIA with DisableVkRayTracing, the ray tracing half): red on v191 with VUID-VkMemoryBarrier2-src/dstStageMask-07946 and both push-constant VUIDs, green with the patch. 0039 applies in order, alone onto bare v191, and passes the -C0 reverse check. Not filed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NvXTk6Roe4sQLHFx9Zykv8
1 parent 6556160 commit fafd375

3 files changed

Lines changed: 265 additions & 23 deletions

File tree

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
VK: drop the stages of shader features the device lacks from stage masks.
2+
3+
GetPipelineStageFlags and GetShaderStageFlags (ConversionVK.h) turn a mask naming every shader
4+
stage ("StageBits::ALL_SHADERS" in a barrier or a fence wait, a pipeline layout whose stages are
5+
"ALL") into every Vulkan stage bit, whatever the device has. On a device without tessellation,
6+
geometry, task, mesh or ray tracing shaders the validation layer then refuses the barrier
7+
(VUID-VkMemoryBarrier2-srcStageMask-07946 / -dstStageMask-07946 for the ray tracing stage, 03929,
8+
03934 and 03935 for geometry, mesh and task), the push constant range and the push
9+
(VUID-VkPushConstantRange-stageFlags-parameter, VUID-VkPushConstantsInfo-stageFlags-parameter: ray
10+
tracing, task and mesh shader stage bits without their extension). Measured on v191: MoltenVK
11+
(no geometry, mesh or ray tracing) and NVIDIA with "disableVKRayTracing". CmdSetDescriptorSet
12+
already adds the mesh stages only with "features.meshShader".
13+
14+
DeviceVK records the shader stages it lacks once, from the features it enabled; barriers and
15+
fence waits drop their pipeline stages, and a pipeline layout drops them from its stages, which
16+
"ALL" and "ALL_SHADERS" resolve to.
17+
18+
diff --git a/Source/VK/CommandBufferVK.hpp b/Source/VK/CommandBufferVK.hpp
19+
index 8dcb4c25..0bacce0b 100644
20+
--- a/Source/VK/CommandBufferVK.hpp
21+
+++ b/Source/VK/CommandBufferVK.hpp
22+
@@ -2638,6 +2638,8 @@ NRI_INLINE void CommandBufferVK::DispatchIndirect(const Buffer& buffer, uint64_t
23+
}
24+
25+
NRI_INLINE void CommandBufferVK::Barrier(const BarrierDesc& barrierDesc) {
26+
+ const VkPipelineStageFlags2 unsupportedStages = m_Device.GetUnsupportedPipelineStages();
27+
+
28+
// Global
29+
Scratch<VkMemoryBarrier2> memoryBarriers = NRI_ALLOCATE_SCRATCH(m_Device, VkMemoryBarrier2, barrierDesc.globalNum);
30+
for (uint32_t i = 0; i < barrierDesc.globalNum; i++) {
31+
@@ -2645,9 +2647,9 @@ NRI_INLINE void CommandBufferVK::Barrier(const BarrierDesc& barrierDesc) {
32+
33+
VkMemoryBarrier2& out = memoryBarriers[i];
34+
out = {VK_STRUCTURE_TYPE_MEMORY_BARRIER_2};
35+
- out.srcStageMask = GetPipelineStageFlags(in.before.stages);
36+
+ out.srcStageMask = GetPipelineStageFlags(in.before.stages) & ~unsupportedStages;
37+
out.srcAccessMask = GetAccessFlags(in.before.access);
38+
- out.dstStageMask = GetPipelineStageFlags(in.after.stages);
39+
+ out.dstStageMask = GetPipelineStageFlags(in.after.stages) & ~unsupportedStages;
40+
out.dstAccessMask = GetAccessFlags(in.after.access);
41+
}
42+
43+
@@ -2660,9 +2662,9 @@ NRI_INLINE void CommandBufferVK::Barrier(const BarrierDesc& barrierDesc) {
44+
45+
VkBufferMemoryBarrier2& out = bufferBarriers[i];
46+
out = {VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2};
47+
- out.srcStageMask = GetPipelineStageFlags(in.before.stages);
48+
+ out.srcStageMask = GetPipelineStageFlags(in.before.stages) & ~unsupportedStages;
49+
out.srcAccessMask = GetAccessFlags(in.before.access);
50+
- out.dstStageMask = GetPipelineStageFlags(in.after.stages);
51+
+ out.dstStageMask = GetPipelineStageFlags(in.after.stages) & ~unsupportedStages;
52+
out.dstAccessMask = GetAccessFlags(in.after.access);
53+
out.srcQueueFamilyIndex = GetQueueFamilyIndex(in.srcQueue, isConcurrent);
54+
out.dstQueueFamilyIndex = GetQueueFamilyIndex(in.dstQueue, isConcurrent);
55+
@@ -2683,9 +2685,9 @@ NRI_INLINE void CommandBufferVK::Barrier(const BarrierDesc& barrierDesc) {
56+
57+
VkImageMemoryBarrier2& out = textureBarriers[i];
58+
out = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2};
59+
- out.srcStageMask = GetPipelineStageFlags(in.before.stages);
60+
+ out.srcStageMask = GetPipelineStageFlags(in.before.stages) & ~unsupportedStages;
61+
out.srcAccessMask = GetAccessFlags(in.before.access);
62+
- out.dstStageMask = GetPipelineStageFlags(in.after.stages);
63+
+ out.dstStageMask = GetPipelineStageFlags(in.after.stages) & ~unsupportedStages;
64+
out.dstAccessMask = GetAccessFlags(in.after.access);
65+
out.oldLayout = GetImageLayout(in.before.layout);
66+
out.newLayout = GetImageLayout(in.after.layout);
67+
diff --git a/Source/VK/DeviceVK.h b/Source/VK/DeviceVK.h
68+
index 741c61fa..5848dd8c 100644
69+
--- a/Source/VK/DeviceVK.h
70+
+++ b/Source/VK/DeviceVK.h
71+
@@ -199,6 +199,14 @@ struct DeviceVK final : public DeviceBase {
72+
return m_Vma;
73+
}
74+
75+
+ inline StageBits GetSupportedShaderStages() const {
76+
+ return m_SupportedShaderStages;
77+
+ }
78+
+
79+
+ inline VkPipelineStageFlags2 GetUnsupportedPipelineStages() const {
80+
+ return m_UnsupportedPipelineStages;
81+
+ }
82+
+
83+
template <typename Implementation, typename Interface, typename... Args>
84+
[[nodiscard]] inline Result CreateImplementation(Interface*& entity, Args&&... args) {
85+
return nri::CreateImplementation(GetAllocationCallbacks(), entity, Allocate<Implementation>(GetAllocationCallbacks(), *this), std::forward<Args>(args)...);
86+
@@ -333,6 +341,8 @@ private:
87+
uint32_t m_MinorVersion = 0;
88+
VkTimeDomainKHR m_CalibratedTimestampCPUTimeDomain = VK_TIME_DOMAIN_DEVICE_KHR;
89+
uint64_t m_NonCoherentAtomSize = 1;
90+
+ VkPipelineStageFlags2 m_UnsupportedPipelineStages = 0;
91+
+ StageBits m_SupportedShaderStages = StageBits::ALL_SHADERS;
92+
DeviceLostDump m_DeviceLostDump = {};
93+
bool m_OwnsNativeObjects = true;
94+
bool m_IsMemoryZeroInitializationEnabled = false;
95+
diff --git a/Source/VK/DeviceVK.hpp b/Source/VK/DeviceVK.hpp
96+
index f0d801bc..d3359ded 100644
97+
--- a/Source/VK/DeviceVK.hpp
98+
+++ b/Source/VK/DeviceVK.hpp
99+
@@ -1663,6 +1663,33 @@ Result DeviceVK::Create(const DeviceCreationDesc& desc, const DeviceCreationVKDe
100+
m_Desc.features.tessellationShader = features.features.tessellationShader != 0;
101+
m_Desc.features.geometryShader = features.features.geometryShader != 0;
102+
m_Desc.features.meshShader = MeshShaderFeatures.meshShader != 0 && MeshShaderFeatures.taskShader != 0;
103+
+
104+
+ // Shader stages the device lacks, dropped from stage masks naming them (like "ALL_SHADERS")
105+
+ if (!m_Desc.features.tessellationShader) {
106+
+ m_SupportedShaderStages &= ~StageBits::TESSELLATION_SHADERS;
107+
+ m_UnsupportedPipelineStages |= VK_PIPELINE_STAGE_2_TESSELLATION_CONTROL_SHADER_BIT | VK_PIPELINE_STAGE_2_TESSELLATION_EVALUATION_SHADER_BIT;
108+
+ }
109+
+
110+
+ if (!m_Desc.features.geometryShader) {
111+
+ m_SupportedShaderStages &= ~StageBits::GEOMETRY_SHADER;
112+
+ m_UnsupportedPipelineStages |= VK_PIPELINE_STAGE_2_GEOMETRY_SHADER_BIT;
113+
+ }
114+
+
115+
+ if (!MeshShaderFeatures.taskShader) {
116+
+ m_SupportedShaderStages &= ~StageBits::TASK_SHADER;
117+
+ m_UnsupportedPipelineStages |= VK_PIPELINE_STAGE_2_TASK_SHADER_BIT_EXT;
118+
+ }
119+
+
120+
+ if (!MeshShaderFeatures.meshShader) {
121+
+ m_SupportedShaderStages &= ~StageBits::MESH_SHADER;
122+
+ m_UnsupportedPipelineStages |= VK_PIPELINE_STAGE_2_MESH_SHADER_BIT_EXT;
123+
+ }
124+
+
125+
+ if (!RayTracingPipelineFeatures.rayTracingPipeline) {
126+
+ m_SupportedShaderStages &= ~StageBits::RAY_TRACING_SHADERS;
127+
+ m_UnsupportedPipelineStages |= VK_PIPELINE_STAGE_2_RAY_TRACING_SHADER_BIT_KHR;
128+
+ }
129+
+
130+
m_Desc.features.lowLatency = m_IsSupported.presentId != 0 && IsExtensionSupported(VK_NV_LOW_LATENCY_2_EXTENSION_NAME, desiredDeviceExts);
131+
m_Desc.features.componentSwizzle = true;
132+
m_Desc.features.independentFrontAndBackStencilReferenceAndMasks = true;
133+
diff --git a/Source/VK/PipelineLayoutVK.hpp b/Source/VK/PipelineLayoutVK.hpp
134+
index cfb15cb9..2d6d1046 100644
135+
--- a/Source/VK/PipelineLayoutVK.hpp
136+
+++ b/Source/VK/PipelineLayoutVK.hpp
137+
@@ -32,6 +32,7 @@ PipelineLayoutVK::~PipelineLayoutVK() {
138+
139+
Result PipelineLayoutVK::Create(const PipelineLayoutDesc& pipelineLayoutDesc) {
140+
m_ShaderStages = GetEffectiveShaderStages(pipelineLayoutDesc.shaderStages);
141+
+ m_ShaderStages &= m_Device.GetSupportedShaderStages();
142+
143+
// Binding offsets
144+
bool ignoreGlobalSPIRVOffsets = (pipelineLayoutDesc.flags & PipelineLayoutBits::IGNORE_GLOBAL_SPIRV_OFFSETS) != 0;
145+
diff --git a/Source/VK/QueueVK.hpp b/Source/VK/QueueVK.hpp
146+
index 0e6f33ee..e53d448e 100644
147+
--- a/Source/VK/QueueVK.hpp
148+
+++ b/Source/VK/QueueVK.hpp
149+
@@ -81,13 +81,14 @@ NRI_INLINE void QueueVK::GetCalibratedTimestamps(uint64_t& timestampGPU, uint64_
150+
151+
NRI_INLINE Result QueueVK::Submit(const QueueSubmitDesc& queueSubmitDesc) {
152+
ExclusiveScope lock(*m_Lock);
153+
+ const VkPipelineStageFlags2 unsupportedStages = m_Device.GetUnsupportedPipelineStages();
154+
155+
Scratch<VkSemaphoreSubmitInfo> waitSemaphores = NRI_ALLOCATE_SCRATCH(m_Device, VkSemaphoreSubmitInfo, queueSubmitDesc.waitFenceNum);
156+
for (uint32_t i = 0; i < queueSubmitDesc.waitFenceNum; i++) {
157+
waitSemaphores[i] = {VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO};
158+
waitSemaphores[i].semaphore = *(FenceVK*)queueSubmitDesc.waitFences[i].fence;
159+
waitSemaphores[i].value = queueSubmitDesc.waitFences[i].value;
160+
- waitSemaphores[i].stageMask = GetPipelineStageFlags(queueSubmitDesc.waitFences[i].stages);
161+
+ waitSemaphores[i].stageMask = GetPipelineStageFlags(queueSubmitDesc.waitFences[i].stages) & ~unsupportedStages;
162+
}
163+
164+
Scratch<VkCommandBufferSubmitInfo> commandBuffers = NRI_ALLOCATE_SCRATCH(m_Device, VkCommandBufferSubmitInfo, queueSubmitDesc.commandBufferNum);
165+
@@ -101,7 +102,7 @@ NRI_INLINE Result QueueVK::Submit(const QueueSubmitDesc& queueSubmitDesc) {
166+
signalSemaphores[i] = {VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO};
167+
signalSemaphores[i].semaphore = *(FenceVK*)queueSubmitDesc.signalFences[i].fence;
168+
signalSemaphores[i].value = queueSubmitDesc.signalFences[i].value;
169+
- signalSemaphores[i].stageMask = GetPipelineStageFlags(queueSubmitDesc.signalFences[i].stages);
170+
+ signalSemaphores[i].stageMask = GetPipelineStageFlags(queueSubmitDesc.signalFences[i].stages) & ~unsupportedStages;
171+
}
172+
173+
VkSubmitInfo2 submitInfo = {VK_STRUCTURE_TYPE_SUBMIT_INFO_2};

0 commit comments

Comments
 (0)