From 5a97e3a391677ff9baae8ccdf5c03c4d403d848b Mon Sep 17 00:00:00 2001 From: Daniel Koch Date: Tue, 17 Mar 2020 15:30:19 -0400 Subject: [PATCH] Add support for KHR_ray_{query,tracing} extensions (#3235) 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 Co-authored-by: Torosdagli Co-authored-by: Tobias Hector Co-authored-by: Steven Perron --- DEPS | 2 +- include/spirv-tools/libspirv.h | 10 +++++++++- source/binary.cpp | 8 +++++++- source/disassemble.cpp | 8 +++++++- source/opcode.cpp | 7 ++++++- source/operand.cpp | 16 +++++++++++++++- source/opt/ir_context.cpp | 2 ++ source/opt/local_access_chain_convert_pass.cpp | 1 + source/opt/local_single_block_elim_pass.cpp | 1 + source/opt/local_single_store_elim_pass.cpp | 1 + source/opt/reflect.h | 2 ++ source/val/validate_builtins.cpp | 10 +++++++--- source/val/validate_memory.cpp | 8 +++++++- source/val/validate_scopes.cpp | 1 + test/operand_capabilities_test.cpp | 11 +++++++++-- test/opt/ir_builder.cpp | 2 +- test/opt/type_manager_test.cpp | 2 +- test/val/val_memory_test.cpp | 10 ++++++---- utils/check_copyright.py | 5 +++-- 19 files changed, 87 insertions(+), 20 deletions(-) diff --git a/DEPS b/DEPS index e13ca0da90..c3e78a2647 100644 --- a/DEPS +++ b/DEPS @@ -6,7 +6,7 @@ vars = { 'effcee_revision': 'cd25ec17e9382f99a895b9ef53ff3c277464d07d', 'googletest_revision': 'f2fb48c3b3d79a75a88a99fba6576b25d42ec528', 're2_revision': '5bd613749fd530b576b890283bfb6bc6ea6246cb', - 'spirv_headers_revision': 'a17e17e36da44d2cd1740132ecd7a8cb078f1d15', + 'spirv_headers_revision': 'f8bf11a0253a32375c32cad92c841237b96696c0', } deps = { diff --git a/include/spirv-tools/libspirv.h b/include/spirv-tools/libspirv.h index 21a9608f8c..03c7d1bf30 100644 --- a/include/spirv-tools/libspirv.h +++ b/include/spirv-tools/libspirv.h @@ -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. @@ -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. diff --git a/source/binary.cpp b/source/binary.cpp index 0463061850..f16bf52275 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -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. @@ -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: diff --git a/source/disassemble.cpp b/source/disassemble.cpp index 4b3972b51d..af30ce0be2 100644 --- a/source/disassemble.cpp +++ b/source/disassemble.cpp @@ -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. @@ -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: diff --git a/source/opcode.cpp b/source/opcode.cpp index b38b5d4a02..80fe3b3a9f 100644 --- a/source/opcode.cpp +++ b/source/opcode.cpp @@ -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. @@ -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, diff --git a/source/operand.cpp b/source/operand.cpp index 304260668d..755ad6ac78 100644 --- a/source/operand.cpp +++ b/source/operand.cpp @@ -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. @@ -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"; @@ -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: diff --git a/source/opt/ir_context.cpp b/source/opt/ir_context.cpp index 7bca29b201..72993fd647 100644 --- a/source/opt/ir_context.cpp +++ b/source/opt/ir_context.cpp @@ -385,6 +385,8 @@ void IRContext::AddCombinatorsForCapability(uint32_t capability) { SpvOpTypeSampler, SpvOpTypeSampledImage, SpvOpTypeAccelerationStructureNV, + SpvOpTypeAccelerationStructureKHR, + SpvOpTypeRayQueryProvisionalKHR, SpvOpTypeArray, SpvOpTypeRuntimeArray, SpvOpTypeStruct, diff --git a/source/opt/local_access_chain_convert_pass.cpp b/source/opt/local_access_chain_convert_pass.cpp index 19215967ae..e5cdc24538 100644 --- a/source/opt/local_access_chain_convert_pass.cpp +++ b/source/opt/local_access_chain_convert_pass.cpp @@ -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", }); } diff --git a/source/opt/local_single_block_elim_pass.cpp b/source/opt/local_single_block_elim_pass.cpp index aebbd000fc..a465483c65 100644 --- a/source/opt/local_single_block_elim_pass.cpp +++ b/source/opt/local_single_block_elim_pass.cpp @@ -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", }); diff --git a/source/opt/local_single_store_elim_pass.cpp b/source/opt/local_single_store_elim_pass.cpp index d6beeab296..4c71ce1ca8 100644 --- a/source/opt/local_single_store_elim_pass.cpp +++ b/source/opt/local_single_store_elim_pass.cpp @@ -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", }); diff --git a/source/opt/reflect.h b/source/opt/reflect.h index 8106442881..51d23a7406 100644 --- a/source/opt/reflect.h +++ b/source/opt/reflect.h @@ -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) { diff --git a/source/val/validate_builtins.cpp b/source/val/validate_builtins.cpp index 7623d49c29..d86c91e4ea 100644 --- a/source/val/validate_builtins.cpp +++ b/source/val/validate_builtins.cpp @@ -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 " @@ -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; } diff --git a/source/val/validate_memory.cpp b/source/val/validate_memory.cpp index bff8b20ee5..1e1a38dd22 100644 --- a/source/val/validate_memory.cpp +++ b/source/val/validate_memory.cpp @@ -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. @@ -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 '" << _.getIdName(inst->id()) << "' has illegal type.\n" @@ -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."; } } diff --git a/source/val/validate_scopes.cpp b/source/val/validate_scopes.cpp index 473d6e840c..ea3ebcb66e 100644 --- a/source/val/validate_scopes.cpp +++ b/source/val/validate_scopes.cpp @@ -32,6 +32,7 @@ bool IsValidScope(uint32_t scope) { case SpvScopeSubgroup: case SpvScopeInvocation: case SpvScopeQueueFamilyKHR: + case SpvScopeShaderCallKHR: return true; case SpvScopeMax: break; diff --git a/test/operand_capabilities_test.cpp b/test/operand_capabilities_test.cpp index 11955970ea..addb08a793 100644 --- a/test/operand_capabilities_test.cpp +++ b/test/operand_capabilities_test.cpp @@ -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 { \ @@ -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 diff --git a/test/opt/ir_builder.cpp b/test/opt/ir_builder.cpp index f800ca437e..cb234e0045 100644 --- a/test/opt/ir_builder.cpp +++ b/test/opt/ir_builder.cpp @@ -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" diff --git a/test/opt/type_manager_test.cpp b/test/opt/type_manager_test.cpp index 743d0b616a..fdae2efc40 100644 --- a/test/opt/type_manager_test.cpp +++ b/test/opt/type_manager_test.cpp @@ -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 diff --git a/test/val/val_memory_test.cpp b/test/val/val_memory_test.cpp index 22761cc1e1..b32867b16c 100644 --- a/test/val/val_memory_test.cpp +++ b/test/val/val_memory_test.cpp @@ -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) { @@ -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) { diff --git a/utils/check_copyright.py b/utils/check_copyright.py index b2283009de..4467a32519 100755 --- a/utils/check_copyright.py +++ b/utils/check_copyright.py @@ -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)))