Skip to content

Commit

Permalink
layers: Add VK_KHR_compute_shader_derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Sep 27, 2024
1 parent 699302d commit 869ddc9
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 0 deletions.
15 changes: 15 additions & 0 deletions layers/core_checks/cc_spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,21 @@ bool CoreChecks::ValidateExecutionModes(const spirv::Module &module_state, const
}
}

if ((stage == VK_SHADER_STAGE_MESH_BIT_EXT || stage == VK_SHADER_STAGE_TASK_BIT_EXT) &&
!phys_dev_ext_props.compute_shader_derivatives_props.meshAndTaskShaderDerivatives) {
if (entrypoint.execution_mode.Has(spirv::ExecutionModeSet::derivative_group_linear)) {
skip |=
LogError("VUID-RuntimeSpirv-meshAndTaskShaderDerivatives-10153", module_state.handle(), loc,
"SPIR-V uses DerivativeGroupLinearKHR in a %s shader, but meshAndTaskShaderDerivatives is not supported.",
string_VkShaderStageFlagBits(stage));
} else if (entrypoint.execution_mode.Has(spirv::ExecutionModeSet::derivative_group_quads)) {
skip |=
LogError("VUID-RuntimeSpirv-meshAndTaskShaderDerivatives-10153", module_state.handle(), loc,
"SPIR-V uses DerivativeGroupQuadsKHR in a %s shader, but meshAndTaskShaderDerivatives is not supported.",
string_VkShaderStageFlagBits(stage));
}
}

return skip;
}

Expand Down
6 changes: 6 additions & 0 deletions layers/state_tracker/shader_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ void ExecutionModeSet::Add(const Instruction& insn) {
case spv::ExecutionModeStencilRefReplacingEXT:
flags |= stencil_ref_replacing_bit;
break;
case spv::ExecutionModeDerivativeGroupLinearKHR:
flags |= derivative_group_linear;
break;
case spv::ExecutionModeDerivativeGroupQuadsKHR:
flags |= derivative_group_quads;
break;
default:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions layers/state_tracker/shader_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ struct ExecutionModeSet {
stencil_ref_replacing_bit = 1 << 25,

fp_fast_math_default = 1 << 26,

derivative_group_linear = 1 << 27,
derivative_group_quads = 1 << 28,
};

// bits to know if things have been set or not by a Decoration
Expand Down
2 changes: 2 additions & 0 deletions layers/state_tracker/state_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,8 @@ void ValidationStateTracker::PostCreateDevice(const VkDeviceCreateInfo *pCreateI
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_host_image_copy, &phys_dev_props->host_image_copy_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_map_memory_placed, &phys_dev_props->map_memory_placed_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_pipeline_binary, &phys_dev_props->pipeline_binary_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_compute_shader_derivatives,
&phys_dev_props->compute_shader_derivatives_props);
if ((phys_dev_props->host_image_copy_props.copySrcLayoutCount > 0) ||
(phys_dev_props->host_image_copy_props.copyDstLayoutCount > 0)) {
// Have to allocate memory for the layout lists
Expand Down
1 change: 1 addition & 0 deletions layers/state_tracker/state_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,7 @@ class ValidationStateTracker : public ValidationObject {
VkPhysicalDeviceHostImageCopyPropertiesEXT host_image_copy_props;
VkPhysicalDevicePipelineBinaryPropertiesKHR pipeline_binary_props;
VkPhysicalDeviceMapMemoryPlacedPropertiesEXT map_memory_placed_props;
VkPhysicalDeviceComputeShaderDerivativesPropertiesKHR compute_shader_derivatives_props;
};
DeviceExtensionProperties phys_dev_ext_props = {};
std::vector<VkCooperativeMatrixPropertiesNV> cooperative_matrix_properties_nv;
Expand Down
8 changes: 8 additions & 0 deletions tests/device_profiles/max_profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"VkPhysicalDevicePresentIdFeaturesKHR": {
"presentId": true
},
"VkPhysicalDeviceComputeShaderDerivativesFeaturesKHR": {
"computeDerivativeGroupQuads": true,
"computeDerivativeGroupLinear": true
},
"VkPhysicalDevicePresentWaitFeaturesKHR": {
"presentWait": true
},
Expand Down Expand Up @@ -1339,6 +1343,9 @@
"VkPhysicalDeviceMapMemoryPlacedPropertiesEXT": {
"minPlacedMemoryMapAlignment": 4096
},
"VkPhysicalDeviceComputeShaderDerivativesPropertiesKHR": {
"meshAndTaskShaderDerivatives": false
},
"VkPhysicalDeviceConservativeRasterizationPropertiesEXT": {
"primitiveUnderestimation": true,
"conservativePointAndLineRasterization": true,
Expand Down Expand Up @@ -2087,6 +2094,7 @@
"VK_KHR_buffer_device_address": 1,
"VK_KHR_cooperative_matrix": 1,
"VK_KHR_copy_commands2": 1,
"VK_KHR_compute_shader_derivatives": 1,
"VK_KHR_create_renderpass2": 1,
"VK_KHR_dedicated_allocation": 1,
"VK_KHR_deferred_host_operations": 1,
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/mesh_positive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,58 @@ TEST_F(PositiveMesh, DrawIndexTask) {
pipe.shader_stages_ = {ts.GetStageCreateInfo(), ms.GetStageCreateInfo(), fs.GetStageCreateInfo()};
pipe.CreateGraphicsPipeline();
}

TEST_F(PositiveMesh, MeshAndTaskShaderDerivatives) {
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_EXT_MESH_SHADER_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_COMPUTE_SHADER_DERIVATIVES_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::computeDerivativeGroupQuads);
AddRequiredFeature(vkt::Feature::meshShader);
AddDisabledFeature(vkt::Feature::multiviewMeshShader);
AddDisabledFeature(vkt::Feature::primitiveFragmentShadingRateMeshShader);
RETURN_IF_SKIP(Init());
InitRenderTarget();

VkPhysicalDeviceComputeShaderDerivativesPropertiesKHR derivatives_properties = vku::InitStructHelper();
GetPhysicalDeviceProperties2(derivatives_properties);
if (!derivatives_properties.meshAndTaskShaderDerivatives) {
GTEST_SKIP() << "meshAndTaskShaderDerivatives is not supported";
}

const char *ms_source = R"(
OpCapability ComputeDerivativeGroupQuadsKHR
OpCapability MeshShadingEXT
OpExtension "SPV_EXT_mesh_shader"
OpExtension "SPV_KHR_compute_shader_derivatives"
OpMemoryModel Logical GLSL450
OpEntryPoint MeshEXT %main "main" %gl_Position %3
OpExecutionMode %main LocalSize 4 4 1
OpExecutionMode %main DerivativeGroupQuadsKHR
OpExecutionMode %main OutputTrianglesEXT
OpExecutionMode %main OutputVertices 3
OpExecutionMode %main OutputPrimitivesEXT 1
OpSource HLSL 660
OpName %main "main"
OpDecorate %gl_Position BuiltIn Position
OpDecorate %3 BuiltIn PrimitiveTriangleIndicesEXT
%uint = OpTypeInt 32 0
%v3uint = OpTypeVector %uint 3
%uint_3 = OpConstant %uint 3
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
%_ptr_Output__arr_v4float_uint_3 = OpTypePointer Output %_arr_v4float_uint_3
%uint_1 = OpConstant %uint 1
%_arr_v3uint_uint_1 = OpTypeArray %v3uint %uint_1
%_ptr_Output__arr_v3uint_uint_1 = OpTypePointer Output %_arr_v3uint_uint_1
%void = OpTypeVoid
%15 = OpTypeFunction %void
%gl_Position = OpVariable %_ptr_Output__arr_v4float_uint_3 Output
%3 = OpVariable %_ptr_Output__arr_v3uint_uint_1 Output
%main = OpFunction %void None %15
%16 = OpLabel
OpReturn
OpFunctionEnd
)";
VkShaderObj ms(this, ms_source, VK_SHADER_STAGE_MESH_BIT_EXT, SPV_ENV_VULKAN_1_2, SPV_SOURCE_ASM);
}
58 changes: 58 additions & 0 deletions tests/unit/shader_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,61 @@ TEST_F(NegativeShaderMesh, TaskSharedMemoryOverLimit) {
};
CreatePipelineHelper::OneshotTest(*this, set_info, kErrorBit, "VUID-RuntimeSpirv-maxTaskSharedMemorySize-08759");
}

TEST_F(NegativeShaderMesh, MeshAndTaskShaderDerivatives) {
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_EXT_MESH_SHADER_EXTENSION_NAME);
AddRequiredExtensions(VK_KHR_COMPUTE_SHADER_DERIVATIVES_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::computeDerivativeGroupQuads);
AddRequiredFeature(vkt::Feature::meshShader);
AddDisabledFeature(vkt::Feature::multiviewMeshShader);
AddDisabledFeature(vkt::Feature::primitiveFragmentShadingRateMeshShader);
RETURN_IF_SKIP(Init());
InitRenderTarget();

VkPhysicalDeviceComputeShaderDerivativesPropertiesKHR derivatives_properties = vku::InitStructHelper();
GetPhysicalDeviceProperties2(derivatives_properties);
if (derivatives_properties.meshAndTaskShaderDerivatives) {
GTEST_SKIP() << "meshAndTaskShaderDerivatives is supported";
}

const char *ms_source = R"(
OpCapability ComputeDerivativeGroupQuadsKHR
OpCapability MeshShadingEXT
OpExtension "SPV_EXT_mesh_shader"
OpExtension "SPV_KHR_compute_shader_derivatives"
OpMemoryModel Logical GLSL450
OpEntryPoint MeshEXT %main "main" %gl_Position %3
OpExecutionMode %main LocalSize 4 4 1
OpExecutionMode %main DerivativeGroupQuadsKHR
OpExecutionMode %main OutputTrianglesEXT
OpExecutionMode %main OutputVertices 3
OpExecutionMode %main OutputPrimitivesEXT 1
OpSource HLSL 660
OpName %main "main"
OpDecorate %gl_Position BuiltIn Position
OpDecorate %3 BuiltIn PrimitiveTriangleIndicesEXT
%uint = OpTypeInt 32 0
%v3uint = OpTypeVector %uint 3
%uint_3 = OpConstant %uint 3
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
%_ptr_Output__arr_v4float_uint_3 = OpTypePointer Output %_arr_v4float_uint_3
%uint_1 = OpConstant %uint 1
%_arr_v3uint_uint_1 = OpTypeArray %v3uint %uint_1
%_ptr_Output__arr_v3uint_uint_1 = OpTypePointer Output %_arr_v3uint_uint_1
%void = OpTypeVoid
%15 = OpTypeFunction %void
%gl_Position = OpVariable %_ptr_Output__arr_v4float_uint_3 Output
%3 = OpVariable %_ptr_Output__arr_v3uint_uint_1 Output
%main = OpFunction %void None %15
%16 = OpLabel
OpReturn
OpFunctionEnd
)";

m_errorMonitor->SetDesiredError("VUID-RuntimeSpirv-meshAndTaskShaderDerivatives-10153");
VkShaderObj ms(this, ms_source, VK_SHADER_STAGE_MESH_BIT_EXT, SPV_ENV_VULKAN_1_2, SPV_SOURCE_ASM);
m_errorMonitor->VerifyFound();
}

0 comments on commit 869ddc9

Please sign in to comment.