Skip to content

Commit 79bf6f3

Browse files
gpuav: Nit cleanup of RayHitObject
1 parent 8b58d64 commit 79bf6f3

File tree

11 files changed

+277
-333
lines changed

11 files changed

+277
-333
lines changed

BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ vvl_sources = [
212212
"layers/gpuav/instrumentation/mesh_shading.cpp",
213213
"layers/gpuav/instrumentation/post_process_descriptor_indexing.cpp",
214214
"layers/gpuav/instrumentation/ray_query.cpp",
215+
"layers/gpuav/instrumentation/ray_hit_object.cpp",
215216
"layers/gpuav/instrumentation/register_validation.h",
216217
"layers/gpuav/instrumentation/sanitizer.cpp",
217218
"layers/gpuav/instrumentation/vertex_attribute_fetch_oob.cpp",
@@ -250,6 +251,8 @@ vvl_sources = [
250251
"layers/gpuav/spirv/module.h",
251252
"layers/gpuav/spirv/pass.cpp",
252253
"layers/gpuav/spirv/pass.h",
254+
"layers/gpuav/spirv/ray_hit_object_pass.cpp",
255+
"layers/gpuav/spirv/ray_hit_object_pass.h",
253256
"layers/gpuav/spirv/ray_query_pass.cpp",
254257
"layers/gpuav/spirv/ray_query_pass.h",
255258
"layers/gpuav/spirv/sanitizer_pass.cpp",

layers/gpuav/instrumentation/ray_hit_object.cpp

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
#include "generated/spirv_grammar_helper.h"
1617
#include "gpuav/core/gpuav.h"
1718
#include "gpuav/resources/gpuav_state_trackers.h"
1819
#include "gpuav/shaders/gpuav_error_codes.h"
@@ -41,95 +42,87 @@ void RegisterRayHitObjectValidation(Validator &gpuav, CommandBufferSubState &cb)
4142
std::ostringstream strm;
4243

4344
const uint32_t error_sub_code = GetSubError(error_record);
44-
// opcode_type: 0 = OpHitObjectTraceRayEXT, 1 = OpHitObjectTraceReorderExecuteEXT,
45-
// 2 = OpHitObjectTraceRayMotionEXT, 3 = OpHitObjectTraceMotionReorderExecuteEXT
46-
const uint32_t opcode_type = error_record[kInstRayHitObjectOpcodeType];
47-
const char* opcode_name = "OpHitObjectTraceRayEXT";
48-
if (opcode_type == 1) {
49-
opcode_name = "OpHitObjectTraceReorderExecuteEXT";
50-
} else if (opcode_type == 2) {
51-
opcode_name = "OpHitObjectTraceRayMotionEXT";
52-
} else if (opcode_type == 3) {
53-
opcode_name = "OpHitObjectTraceMotionReorderExecuteEXT";
54-
}
45+
const uint32_t opcode = error_record[kInstLogErrorParameterOffset_1];
5546

5647
switch (error_sub_code) {
5748
case kErrorSubCodeRayHitObjectNegativeMin: {
5849
// TODO - Figure a way to properly use GLSL floatBitsToUint and print the float values
59-
strm << opcode_name << " operand Ray Tmin value is negative. ";
50+
strm << string_SpvOpcode(opcode) << " operand Ray Tmin value is negative. ";
6051
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11879";
6152
} break;
6253
case kErrorSubCodeRayHitObjectNegativeMax: {
63-
strm << opcode_name << " operand Ray Tmax value is negative. ";
54+
strm << string_SpvOpcode(opcode) << " operand Ray Tmax value is negative. ";
6455
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11879";
6556
} break;
6657
case kErrorSubCodeRayHitObjectMinMax: {
67-
strm << opcode_name << " operand Ray Tmax is less than RayTmin. ";
58+
strm << string_SpvOpcode(opcode) << " operand Ray Tmax is less than RayTmin. ";
6859
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11880";
6960
} break;
7061
case kErrorSubCodeRayHitObjectMinNaN: {
71-
strm << opcode_name << " operand Ray Tmin is NaN. ";
62+
strm << string_SpvOpcode(opcode) << " operand Ray Tmin is NaN. ";
7263
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881";
7364
} break;
7465
case kErrorSubCodeRayHitObjectMaxNaN: {
75-
strm << opcode_name << " operand Ray Tmax is NaN. ";
66+
strm << string_SpvOpcode(opcode) << " operand Ray Tmax is NaN. ";
7667
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881";
7768
} break;
7869
case kErrorSubCodeRayHitObjectOriginNaN: {
79-
strm << opcode_name << " operand Ray Origin contains a NaN. ";
70+
strm << string_SpvOpcode(opcode) << " operand Ray Origin contains a NaN. ";
8071
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881";
8172
} break;
8273
case kErrorSubCodeRayHitObjectDirectionNaN: {
83-
strm << opcode_name << " operand Ray Direction contains a NaN. ";
74+
strm << string_SpvOpcode(opcode) << " operand Ray Direction contains a NaN. ";
8475
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881";
8576
} break;
8677
case kErrorSubCodeRayHitObjectOriginFinite: {
87-
strm << opcode_name << " operand Ray Origin contains a non-finite value. ";
78+
strm << string_SpvOpcode(opcode) << " operand Ray Origin contains a non-finite value. ";
8879
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11878";
8980
} break;
9081
case kErrorSubCodeRayHitObjectDirectionFinite: {
91-
strm << opcode_name << " operand Ray Direction contains a non-finite value. ";
82+
strm << string_SpvOpcode(opcode) << " operand Ray Direction contains a non-finite value. ";
9283
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11878";
9384
} break;
9485
case kErrorSubCodeRayHitObjectBothSkip: {
95-
const uint32_t value = error_record[kInstRayHitObjectParamOffset_0];
96-
strm << opcode_name << " operand Ray Flags is 0x" << std::hex << value << ". ";
86+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
87+
strm << string_SpvOpcode(opcode) << " operand Ray Flags is 0x" << std::hex << value << ". ";
9788
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11883";
9889
} break;
9990
case kErrorSubCodeRayHitObjectSkipCull: {
100-
const uint32_t value = error_record[kInstRayHitObjectParamOffset_0];
101-
strm << opcode_name << " operand Ray Flags is 0x" << std::hex << value << ". ";
91+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
92+
strm << string_SpvOpcode(opcode) << " operand Ray Flags is 0x" << std::hex << value << ". ";
10293
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11884";
10394
} break;
10495
case kErrorSubCodeRayHitObjectOpaque: {
105-
const uint32_t value = error_record[kInstRayHitObjectParamOffset_0];
106-
strm << opcode_name << " operand Ray Flags is 0x" << std::hex << value << ". ";
96+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
97+
strm << string_SpvOpcode(opcode) << " operand Ray Flags is 0x" << std::hex << value << ". ";
10798
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11885";
10899
} break;
109100
case kErrorSubCodeRayHitObjectSkipTrianglesWithPipelineSkipAABBs: {
110-
const uint32_t value = error_record[kInstRayHitObjectParamOffset_0];
111-
strm << opcode_name << " operand Ray Flags (0x" << std::hex << value
112-
<< ") contains SkipTrianglesKHR, but pipeline was created with VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR. ";
101+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
102+
strm << string_SpvOpcode(opcode) << " operand Ray Flags (0x" << std::hex << value
103+
<< ") contains SkipTrianglesKHR, but pipeline was created with "
104+
"VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR. ";
113105
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11886";
114106
} break;
115107
case kErrorSubCodeRayHitObjectSkipAABBsWithPipelineSkipTriangles: {
116-
const uint32_t value = error_record[kInstRayHitObjectParamOffset_0];
117-
strm << opcode_name << " operand Ray Flags (0x" << std::hex << value
118-
<< ") contains SkipAABBsKHR, but pipeline was created with VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR. ";
108+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
109+
strm << string_SpvOpcode(opcode) << " operand Ray Flags (0x" << std::hex << value
110+
<< ") contains SkipAABBsKHR, but pipeline was created with "
111+
"VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR. ";
119112
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11887";
120113
} break;
114+
case kErrorSubCodeRayHitObjectTimeOutOfRange: {
115+
strm << string_SpvOpcode(opcode) << " operand time is not between 0.0 and 1.0. ";
116+
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11882";
117+
} break;
121118
case kErrorSubCodeRayHitObjectSBTIndexExceedsLimit: {
122119
// For this case, param_0 contains the SBT index and opcode_type slot contains the max SBT index
123-
const uint32_t sbt_index = error_record[kInstRayHitObjectParamOffset_0];
124-
const uint32_t max_sbt_index = error_record[kInstRayHitObjectOpcodeType];
120+
const uint32_t sbt_index = error_record[kInstLogErrorParameterOffset_0];
121+
const uint32_t max_sbt_index = error_record[kInstLogErrorParameterOffset_1];
125122
strm << "OpHitObjectSetShaderBindingTableRecordIndexEXT SBT index (" << std::dec << sbt_index
126123
<< ") exceeds VkPhysicalDeviceRayTracingInvocationReorderPropertiesEXT::maxShaderBindingTableRecordIndex (" << max_sbt_index << "). ";
127124
out_vuid_msg = "VUID-RuntimeSpirv-maxShaderBindingTableRecordIndex-11888";
128125
} break;
129-
case kErrorSubCodeRayHitObjectTimeOutOfRange: {
130-
strm << opcode_name << " operand time is not between 0.0 and 1.0. ";
131-
out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11882";
132-
} break;
133126
default:
134127
error_found = false;
135128
break;

layers/gpuav/instrumentation/ray_query.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2024-2025 LunarG, Inc.
1+
/* Copyright (c) 2024-2026 LunarG, Inc.
22
*
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
@@ -81,17 +81,17 @@ void RegisterRayQueryValidation(Validator &gpuav, CommandBufferSubState &cb) {
8181
out_vuid_msg = "VUID-RuntimeSpirv-OpRayQueryInitializeKHR-06348";
8282
} break;
8383
case kErrorSubCodeRayQueryBothSkip: {
84-
const uint32_t value = error_record[kInstRayQueryParamOffset_0];
84+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
8585
strm << "OpRayQueryInitializeKHR operand Ray Flags is 0x" << std::hex << value << ". ";
8686
out_vuid_msg = "VUID-RuntimeSpirv-OpRayQueryInitializeKHR-06889";
8787
} break;
8888
case kErrorSubCodeRayQuerySkipCull: {
89-
const uint32_t value = error_record[kInstRayQueryParamOffset_0];
89+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
9090
strm << "OpRayQueryInitializeKHR operand Ray Flags is 0x" << std::hex << value << ". ";
9191
out_vuid_msg = "VUID-RuntimeSpirv-OpRayQueryInitializeKHR-06890";
9292
} break;
9393
case kErrorSubCodeRayQueryOpaque: {
94-
const uint32_t value = error_record[kInstRayQueryParamOffset_0];
94+
const uint32_t value = error_record[kInstLogErrorParameterOffset_0];
9595
strm << "OpRayQueryInitializeKHR operand Ray Flags is 0x" << std::hex << value << ". ";
9696
out_vuid_msg = "VUID-RuntimeSpirv-OpRayQueryInitializeKHR-06891";
9797
} break;

layers/gpuav/shaders/gpuav_error_codes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ const int kErrorSubCodeRayHitObjectOriginFinite = 11;
117117
const int kErrorSubCodeRayHitObjectDirectionFinite = 12;
118118
const int kErrorSubCodeRayHitObjectSkipTrianglesWithPipelineSkipAABBs = 13;
119119
const int kErrorSubCodeRayHitObjectSkipAABBsWithPipelineSkipTriangles = 14;
120-
const int kErrorSubCodeRayHitObjectSBTIndexExceedsLimit = 15;
121-
const int kErrorSubCodeRayHitObjectTimeOutOfRange = 16;
120+
const int kErrorSubCodeRayHitObjectTimeOutOfRange = 15;
121+
const int kErrorSubCodeRayHitObjectSBTIndexExceedsLimit = 16;
122122

123123
// MeshShading
124124
//

layers/gpuav/shaders/gpuav_error_header.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (c) 2021-2025 The Khronos Group Inc.
2-
// Copyright (c) 2021-2025 Valve Corporation
3-
// Copyright (c) 2021-2025 LunarG, Inc.
1+
// Copyright (c) 2021-2026 The Khronos Group Inc.
2+
// Copyright (c) 2021-2026 Valve Corporation
3+
// Copyright (c) 2021-2026 LunarG, Inc.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.
@@ -156,19 +156,6 @@ const uint kInstBuffAddrAccessPayloadMaskAccessInfo = 0x3FFFFFFF;
156156
const int kMeshShadingOutputVerticesShift = 16;
157157
const int kMeshShadingOutputPrimitivesMask = 0xFFFF;
158158

159-
// Ray query
160-
// ---
161-
const int kInstRayQueryParamOffset_0 = kHeaderSize;
162-
163-
// Ray hit object (VK_EXT_ray_tracing_invocation_reorder)
164-
// OpHitObjectTraceRayEXT, OpHitObjectTraceReorderExecuteEXT, OpHitObjectTraceRayMotionEXT,
165-
// OpHitObjectTraceMotionReorderExecuteEXT, OpHitObjectSetShaderBindingTableRecordIndexEXT
166-
// ---
167-
const int kInstRayHitObjectParamOffset_0 = kHeaderSize;
168-
// 0 = OpHitObjectTraceRayEXT, 1 = OpHitObjectTraceReorderExecuteEXT,
169-
// 2 = OpHitObjectTraceRayMotionEXT, 3 = OpHitObjectTraceMotionReorderExecuteEXT
170-
const int kInstRayHitObjectOpcodeType = kHeaderSize + 1;
171-
172159
// Validation commands shaders
173160
// ---
174161
const int kValCmdErrorPayloadDword_0 = kHeaderSize;

layers/gpuav/shaders/instrumentation/ray_hit_object.comp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,26 @@
2121
#include "common_descriptor_sets.h"
2222
#include "error_payload.h"
2323

24+
// From SPIRV-Headers
25+
const uint OpHitObjectTraceReorderExecuteEXT = 5311;
26+
const uint OpHitObjectTraceMotionReorderExecuteEXT = 5312;
27+
const uint OpHitObjectTraceRayEXT = 5316;
28+
const uint OpHitObjectTraceRayMotionEXT = 5317;
29+
2430
// Validation for VK_EXT_ray_tracing_invocation_reorder hit object operations:
25-
// OpHitObjectTraceRayEXT, OpHitObjectTraceReorderExecuteEXT,
26-
// OpHitObjectTraceRayMotionEXT, OpHitObjectTraceMotionReorderExecuteEXT
2731
//
28-
// opcode_type: 0 = OpHitObjectTraceRayEXT, 1 = OpHitObjectTraceReorderExecuteEXT,
29-
// 2 = OpHitObjectTraceRayMotionEXT, 3 = OpHitObjectTraceMotionReorderExecuteEXT
30-
// pipeline_flags: bit 0 = pipeline has SKIP_AABBS, bit 1 = pipeline has SKIP_TRIANGLES
31-
// time: motion time parameter (only valid for opcode_type 2 and 3, pass 0.0 for others)
32+
// pipeline_flags:
33+
// bit 0 = pipeline has SKIP_AABBS
34+
// bit 1 = pipeline has SKIP_TRIANGLES
35+
// time:
36+
// motion time parameter (only valid for opcode_type "Motion" opcodes, pass 0.0 for others)
3237
bool inst_ray_hit_object(const uint inst_offset, const uint opcode_type, const uint ray_flags, const vec3 ray_origin, const float ray_tmin, const vec3 ray_direction, const float ray_tmax, const uint pipeline_flags, const float time)
3338
{
3439
uint error = 0u;
3540
uint param_0 = 0u;
3641

37-
// VUID 11882: time must be between 0.0 and 1.0 (only for motion opcodes)
38-
const bool is_motion_opcode = (opcode_type == 2 || opcode_type == 3);
42+
const bool is_motion_opcode = (opcode_type == OpHitObjectTraceRayMotionEXT || opcode_type == OpHitObjectTraceMotionReorderExecuteEXT);
43+
3944
if (is_motion_opcode && (time < 0.0f || time > 1.0f)) {
4045
error = kErrorSubCodeRayHitObjectTimeOutOfRange;
4146
} else if (isnan(ray_tmin)) {
@@ -85,11 +90,11 @@ bool inst_ray_hit_object(const uint inst_offset, const uint opcode_type, const u
8590
error = kErrorSubCodeRayHitObjectOpaque;
8691
param_0 = ray_flags;
8792
} else if ((ray_flags & SkipTrianglesKHR) != 0 && (pipeline_flags & kPipelineHasSkipAABBs) != 0) {
88-
// VUID 11886: SkipTriangles ray flag with pipeline SKIP_AABBS flag
93+
// SkipTriangles ray flag with pipeline SKIP_AABBS flag
8994
error = kErrorSubCodeRayHitObjectSkipTrianglesWithPipelineSkipAABBs;
9095
param_0 = ray_flags;
9196
} else if ((ray_flags & SkipAABBsKHR) != 0 && (pipeline_flags & kPipelineHasSkipTriangles) != 0) {
92-
// VUID 11887: SkipAABBs ray flag with pipeline SKIP_TRIANGLES flag
97+
// SkipAABBs ray flag with pipeline SKIP_TRIANGLES flag
9398
error = kErrorSubCodeRayHitObjectSkipAABBsWithPipelineSkipTriangles;
9499
param_0 = ray_flags;
95100
}
@@ -109,7 +114,6 @@ bool inst_ray_hit_object(const uint inst_offset, const uint opcode_type, const u
109114
return true;
110115
}
111116

112-
// Check for VUID 11888: SBT index must be <= maxShaderBindingTableRecordIndex
113117
bool inst_ray_hit_object_sbt_index_check(const uint inst_offset, const uint sbt_index, const uint max_sbt_index)
114118
{
115119
if (sbt_index > max_sbt_index) {

0 commit comments

Comments
 (0)