Skip to content

Commit

Permalink
Add support for KHR_ray_{query,tracing} extensions (#3235)
Browse files Browse the repository at this point in the history
Update validator for SPV_KHR_ray_tracing.

* Added handling for new enum types
* Add SpvScopeShaderCallKHR as a valid scope
* update spirv-headers

Co-authored-by: alelenv <[email protected]>
Co-authored-by: Torosdagli <[email protected]>
Co-authored-by: Tobias Hector <[email protected]>
Co-authored-by: Steven Perron <[email protected]>
  • Loading branch information
5 people committed Mar 17, 2020
1 parent 25ede1c commit 5a97e3a
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 20 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ vars = {
'effcee_revision': 'cd25ec17e9382f99a895b9ef53ff3c277464d07d',
'googletest_revision': 'f2fb48c3b3d79a75a88a99fba6576b25d42ec528',
're2_revision': '5bd613749fd530b576b890283bfb6bc6ea6246cb',
'spirv_headers_revision': 'a17e17e36da44d2cd1740132ecd7a8cb078f1d15',
'spirv_headers_revision': 'f8bf11a0253a32375c32cad92c841237b96696c0',
}

deps = {
Expand Down
10 changes: 9 additions & 1 deletion include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2015-2016 The Khronos Group Inc.
// Copyright (c) 2015-2020 The Khronos Group Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -165,6 +167,12 @@ typedef enum spv_operand_type_t {
SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS, // SPIR-V Sec 3.29
SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO, // SPIR-V Sec 3.30
SPV_OPERAND_TYPE_CAPABILITY, // SPIR-V Sec 3.31
SPV_OPERAND_TYPE_RAY_FLAGS, // SPIR-V Sec 3.RF
SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION, // SPIR-V Sec 3.RQIntersection
SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE, // SPIR-V Sec
// 3.RQCommitted
SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE, // SPIR-V Sec
// 3.RQCandidate

// Set 5: Operands that are a single word bitmask.
// Sometimes a set bit indicates the instruction requires still more operands.
Expand Down
8 changes: 7 additions & 1 deletion source/binary.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2015-2016 The Khronos Group Inc.
// Copyright (c) 2015-2020 The Khronos Group Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -633,6 +635,10 @@ spv_result_t Parser::parseOperand(size_t inst_offset,
case SPV_OPERAND_TYPE_GROUP_OPERATION:
case SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS:
case SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO:
case SPV_OPERAND_TYPE_RAY_FLAGS:
case SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION:
case SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE:
case SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE:
case SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING:
case SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE:
case SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER:
Expand Down
8 changes: 7 additions & 1 deletion source/disassemble.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2015-2016 The Khronos Group Inc.
// Copyright (c) 2015-2020 The Khronos Group Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -277,6 +279,10 @@ void Disassembler::EmitOperand(const spv_parsed_instruction_t& inst,
case SPV_OPERAND_TYPE_GROUP_OPERATION:
case SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS:
case SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO:
case SPV_OPERAND_TYPE_RAY_FLAGS:
case SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION:
case SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE:
case SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE:
case SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING:
case SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE:
case SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER:
Expand Down
7 changes: 6 additions & 1 deletion source/opcode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2015-2016 The Khronos Group Inc.
// Copyright (c) 2015-2020 The Khronos Group Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -333,6 +335,9 @@ int32_t spvOpcodeGeneratesType(SpvOp op) {
case SpvOpTypeNamedBarrier:
case SpvOpTypeAccelerationStructureNV:
case SpvOpTypeCooperativeMatrixNV:
// case SpvOpTypeAccelerationStructureKHR: covered by
// SpvOpTypeAccelerationStructureNV
case SpvOpTypeRayQueryProvisionalKHR:
return true;
default:
// In particular, OpTypeForwardPointer does not generate a type,
Expand Down
16 changes: 15 additions & 1 deletion source/operand.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2015-2016 The Khronos Group Inc.
// Copyright (c) 2015-2020 The Khronos Group Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -216,6 +218,14 @@ const char* spvOperandTypeStr(spv_operand_type_t type) {
return "kernel profiling info";
case SPV_OPERAND_TYPE_CAPABILITY:
return "capability";
case SPV_OPERAND_TYPE_RAY_FLAGS:
return "ray flags";
case SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION:
return "ray query intersection";
case SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE:
return "ray query committed intersection type";
case SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE:
return "ray query candidate intersection type";
case SPV_OPERAND_TYPE_IMAGE:
case SPV_OPERAND_TYPE_OPTIONAL_IMAGE:
return "image";
Expand Down Expand Up @@ -323,6 +333,10 @@ bool spvOperandIsConcrete(spv_operand_type_t type) {
case SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS:
case SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO:
case SPV_OPERAND_TYPE_CAPABILITY:
case SPV_OPERAND_TYPE_RAY_FLAGS:
case SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION:
case SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE:
case SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE:
case SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING:
case SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE:
case SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER:
Expand Down
2 changes: 2 additions & 0 deletions source/opt/ir_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ void IRContext::AddCombinatorsForCapability(uint32_t capability) {
SpvOpTypeSampler,
SpvOpTypeSampledImage,
SpvOpTypeAccelerationStructureNV,
SpvOpTypeAccelerationStructureKHR,
SpvOpTypeRayQueryProvisionalKHR,
SpvOpTypeArray,
SpvOpTypeRuntimeArray,
SpvOpTypeStruct,
Expand Down
1 change: 1 addition & 0 deletions source/opt/local_access_chain_convert_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ void LocalAccessChainConvertPass::InitExtensions() {
"SPV_NV_shading_rate",
"SPV_NV_mesh_shader",
"SPV_NV_ray_tracing",
"SPV_KHR_ray_query",
"SPV_EXT_fragment_invocation_density",
});
}
Expand Down
1 change: 1 addition & 0 deletions source/opt/local_single_block_elim_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
"SPV_NV_shading_rate",
"SPV_NV_mesh_shader",
"SPV_NV_ray_tracing",
"SPV_KHR_ray_query",
"SPV_EXT_fragment_invocation_density",
"SPV_EXT_physical_storage_buffer",
});
Expand Down
1 change: 1 addition & 0 deletions source/opt/local_single_store_elim_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void LocalSingleStoreElimPass::InitExtensionWhiteList() {
"SPV_NV_shading_rate",
"SPV_NV_mesh_shader",
"SPV_NV_ray_tracing",
"SPV_KHR_ray_query",
"SPV_EXT_fragment_invocation_density",
"SPV_EXT_physical_storage_buffer",
});
Expand Down
2 changes: 2 additions & 0 deletions source/opt/reflect.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ inline bool IsTypeInst(SpvOp opcode) {
return (opcode >= SpvOpTypeVoid && opcode <= SpvOpTypeForwardPointer) ||
opcode == SpvOpTypePipeStorage || opcode == SpvOpTypeNamedBarrier ||
opcode == SpvOpTypeAccelerationStructureNV ||
opcode == SpvOpTypeAccelerationStructureKHR ||
opcode == SpvOpTypeRayQueryProvisionalKHR ||
opcode == SpvOpTypeCooperativeMatrixNV;
}
inline bool IsConstantInst(SpvOp opcode) {
Expand Down
10 changes: 7 additions & 3 deletions source/val/validate_builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,8 +2263,11 @@ spv_result_t BuiltInsValidator::ValidateVertexIndexAtDefinition(
spv_result_t BuiltInsValidator::ValidateVertexIdOrInstanceIdAtDefinition(
const Decoration& decoration, const Instruction& inst) {
const SpvBuiltIn label = SpvBuiltIn(decoration.params()[0]);
bool allow_instance_id = _.HasCapability(SpvCapabilityRayTracingNV) &&
label == SpvBuiltInInstanceId;
bool allow_instance_id =
(_.HasCapability(SpvCapabilityRayTracingNV) ||
_.HasCapability(SpvCapabilityRayTracingProvisionalKHR)) &&
label == SpvBuiltInInstanceId;

if (spvIsVulkanEnv(_.context()->target_env) && !allow_instance_id) {
return _.diag(SPV_ERROR_INVALID_DATA, &inst)
<< "Vulkan spec doesn't allow BuiltIn VertexId/InstanceId "
Expand Down Expand Up @@ -3085,7 +3088,8 @@ spv_result_t BuiltInsValidator::ValidateSingleBuiltInAtDefinition(
case SpvBuiltInWorldToObjectNV:
case SpvBuiltInHitTNV:
case SpvBuiltInHitKindNV:
case SpvBuiltInIncomingRayFlagsNV: {
case SpvBuiltInIncomingRayFlagsNV:
case SpvBuiltInRayGeometryIndexKHR: {
// No validation rules (for the moment).
break;
}
Expand Down
8 changes: 7 additions & 1 deletion source/val/validate_memory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) 2018 Google LLC.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
// reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -533,7 +535,9 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
if (!IsAllowedTypeOrArrayOfSame(
_, pointee,
{SpvOpTypeImage, SpvOpTypeSampler, SpvOpTypeSampledImage,
SpvOpTypeAccelerationStructureNV})) {
SpvOpTypeAccelerationStructureNV,
SpvOpTypeAccelerationStructureKHR,
SpvOpTypeRayQueryProvisionalKHR})) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "UniformConstant OpVariable <id> '" << _.getIdName(inst->id())
<< "' has illegal type.\n"
Expand All @@ -542,6 +546,8 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
<< "are used only as handles to refer to opaque resources. Such "
<< "variables must be typed as OpTypeImage, OpTypeSampler, "
<< "OpTypeSampledImage, OpTypeAccelerationStructureNV, "
"OpTypeAccelerationStructureKHR, "
"OpTypeRayQueryProvisionalKHR, "
<< "or an array of one of these types.";
}
}
Expand Down
1 change: 1 addition & 0 deletions source/val/validate_scopes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bool IsValidScope(uint32_t scope) {
case SpvScopeSubgroup:
case SpvScopeInvocation:
case SpvScopeQueueFamilyKHR:
case SpvScopeShaderCallKHR:
return true;
case SpvScopeMax:
break;
Expand Down
11 changes: 9 additions & 2 deletions test/operand_capabilities_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ TEST_P(EnumCapabilityTest, Sample) {
SpvCapability##CAP1, SpvCapability##CAP2, SpvCapability##CAP3 \
} \
}
#define CASE4(TYPE, VALUE, CAP1, CAP2, CAP3, CAP4) \
{ \
SPV_OPERAND_TYPE_##TYPE, uint32_t(Spv##VALUE), CapabilitySet { \
SpvCapability##CAP1, SpvCapability##CAP2, SpvCapability##CAP3, \
SpvCapability##CAP4 \
} \
}
#define CASE5(TYPE, VALUE, CAP1, CAP2, CAP3, CAP4, CAP5) \
{ \
SPV_OPERAND_TYPE_##TYPE, uint32_t(Spv##VALUE), CapabilitySet { \
Expand Down Expand Up @@ -491,8 +498,8 @@ INSTANTIATE_TEST_SUITE_P(
CASE1(BUILT_IN, BuiltInCullDistance, CullDistance), // Bug 1407, 15234
CASE1(BUILT_IN, BuiltInVertexId, Shader),
CASE1(BUILT_IN, BuiltInInstanceId, Shader),
CASE3(BUILT_IN, BuiltInPrimitiveId, Geometry, Tessellation,
RayTracingNV),
CASE4(BUILT_IN, BuiltInPrimitiveId, Geometry, Tessellation,
RayTracingNV, RayTracingProvisionalKHR),
CASE2(BUILT_IN, BuiltInInvocationId, Geometry, Tessellation),
CASE2(BUILT_IN, BuiltInLayer, Geometry, ShaderViewportIndexLayerEXT),
CASE2(BUILT_IN, BuiltInViewportIndex, MultiViewport, ShaderViewportIndexLayerEXT), // Bug 15234
Expand Down
2 changes: 1 addition & 1 deletion test/opt/ir_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ OpFunctionEnd

TEST_F(IRBuilderTest, AccelerationStructureNV) {
const std::string text = R"(
; CHECK: OpTypeAccelerationStructureNV
; CHECK: OpTypeAccelerationStructureKHR
OpCapability Shader
OpCapability RayTracingNV
OpExtension "SPV_NV_ray_tracing"
Expand Down
2 changes: 1 addition & 1 deletion test/opt/type_manager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ TEST(TypeManager, GetTypeInstructionAllTypes) {
; CHECK: OpTypeForwardPointer [[uniform_ptr]] Uniform
; CHECK: OpTypePipeStorage
; CHECK: OpTypeNamedBarrier
; CHECK: OpTypeAccelerationStructureNV
; CHECK: OpTypeAccelerationStructureKHR
; CHECK: OpTypeCooperativeMatrixNV [[f32]] [[uint24]] [[uint24]] [[uint24]]
OpCapability Shader
OpCapability Int64
Expand Down
10 changes: 6 additions & 4 deletions test/val/val_memory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ OpFunctionEnd
"Variables identified with the UniformConstant storage class "
"are used only as handles to refer to opaque resources. Such "
"variables must be typed as OpTypeImage, OpTypeSampler, "
"OpTypeSampledImage, OpTypeAccelerationStructureNV, or an "
"array of one of these types."));
"OpTypeSampledImage, OpTypeAccelerationStructureNV, "
"OpTypeAccelerationStructureKHR, OpTypeRayQueryProvisionalKHR, "
"or an array of one of these types."));
}

TEST_F(ValidateMemory, VulkanUniformConstantOnOpaqueResourceGood) {
Expand Down Expand Up @@ -110,8 +111,9 @@ OpFunctionEnd
"Variables identified with the UniformConstant storage class "
"are used only as handles to refer to opaque resources. Such "
"variables must be typed as OpTypeImage, OpTypeSampler, "
"OpTypeSampledImage, OpTypeAccelerationStructureNV, or an "
"array of one of these types."));
"OpTypeSampledImage, OpTypeAccelerationStructureNV, "
"OpTypeAccelerationStructureKHR, OpTypeRayQueryProvisionalKHR, "
"or an array of one of these types."));
}

TEST_F(ValidateMemory, VulkanUniformConstantOnOpaqueResourceArrayGood) {
Expand Down
5 changes: 3 additions & 2 deletions utils/check_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
'Pierre Moreau',
'Samsung Inc',
'André Perez Maselco',
'Vasyl Teliman']
'Vasyl Teliman',
'Advanced Micro Devices, Inc.']
CURRENT_YEAR='2020'

YEARS = '(2014-2016|2015-2016|2016|2016-2017|2017|2017-2019|2018|2019|2020)'
YEARS = '(2014-2016|2015-2016|2015-2020|2016|2016-2017|2017|2017-2019|2018|2019|2020)'
COPYRIGHT_RE = re.compile(
'Copyright \(c\) {} ({})'.format(YEARS, '|'.join(AUTHORS)))

Expand Down

0 comments on commit 5a97e3a

Please sign in to comment.