|
| 1 | +/* Copyright (c) 2024-2026 LunarG, Inc. |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +#include "gpuav/core/gpuav.h" |
| 17 | +#include "gpuav/resources/gpuav_state_trackers.h" |
| 18 | +#include "gpuav/shaders/gpuav_error_codes.h" |
| 19 | +#include "gpuav/shaders/gpuav_error_header.h" |
| 20 | + |
| 21 | +namespace gpuav { |
| 22 | + |
| 23 | +void RegisterRayHitObjectValidation(Validator &gpuav, CommandBufferSubState &cb) { |
| 24 | + if (!gpuav.gpuav_settings.shader_instrumentation.ray_hit_object) { |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + cb.on_instrumentation_error_logger_register_functions.emplace_back([](Validator &gpuav, CommandBufferSubState &cb, |
| 29 | + const LastBound &last_bound) { |
| 30 | + CommandBufferSubState::InstrumentationErrorLogger inst_error_logger = [](Validator &gpuav, const Location &loc, |
| 31 | + const uint32_t *error_record, |
| 32 | + std::string &out_error_msg, |
| 33 | + std::string &out_vuid_msg) { |
| 34 | + using namespace glsl; |
| 35 | + bool error_found = false; |
| 36 | + if (GetErrorGroup(error_record) != kErrorGroupInstRayHitObject) { |
| 37 | + return error_found; |
| 38 | + } |
| 39 | + error_found = true; |
| 40 | + |
| 41 | + std::ostringstream strm; |
| 42 | + |
| 43 | + 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 | + } |
| 55 | + |
| 56 | + switch (error_sub_code) { |
| 57 | + case kErrorSubCodeRayHitObjectNegativeMin: { |
| 58 | + // TODO - Figure a way to properly use GLSL floatBitsToUint and print the float values |
| 59 | + strm << opcode_name << " operand Ray Tmin value is negative. "; |
| 60 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11879"; |
| 61 | + } break; |
| 62 | + case kErrorSubCodeRayHitObjectNegativeMax: { |
| 63 | + strm << opcode_name << " operand Ray Tmax value is negative. "; |
| 64 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11879"; |
| 65 | + } break; |
| 66 | + case kErrorSubCodeRayHitObjectMinMax: { |
| 67 | + strm << opcode_name << " operand Ray Tmax is less than RayTmin. "; |
| 68 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11880"; |
| 69 | + } break; |
| 70 | + case kErrorSubCodeRayHitObjectMinNaN: { |
| 71 | + strm << opcode_name << " operand Ray Tmin is NaN. "; |
| 72 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881"; |
| 73 | + } break; |
| 74 | + case kErrorSubCodeRayHitObjectMaxNaN: { |
| 75 | + strm << opcode_name << " operand Ray Tmax is NaN. "; |
| 76 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881"; |
| 77 | + } break; |
| 78 | + case kErrorSubCodeRayHitObjectOriginNaN: { |
| 79 | + strm << opcode_name << " operand Ray Origin contains a NaN. "; |
| 80 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881"; |
| 81 | + } break; |
| 82 | + case kErrorSubCodeRayHitObjectDirectionNaN: { |
| 83 | + strm << opcode_name << " operand Ray Direction contains a NaN. "; |
| 84 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11881"; |
| 85 | + } break; |
| 86 | + case kErrorSubCodeRayHitObjectOriginFinite: { |
| 87 | + strm << opcode_name << " operand Ray Origin contains a non-finite value. "; |
| 88 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11878"; |
| 89 | + } break; |
| 90 | + case kErrorSubCodeRayHitObjectDirectionFinite: { |
| 91 | + strm << opcode_name << " operand Ray Direction contains a non-finite value. "; |
| 92 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11878"; |
| 93 | + } break; |
| 94 | + case kErrorSubCodeRayHitObjectBothSkip: { |
| 95 | + const uint32_t value = error_record[kInstRayHitObjectParamOffset_0]; |
| 96 | + strm << opcode_name << " operand Ray Flags is 0x" << std::hex << value << ". "; |
| 97 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11883"; |
| 98 | + } break; |
| 99 | + case kErrorSubCodeRayHitObjectSkipCull: { |
| 100 | + const uint32_t value = error_record[kInstRayHitObjectParamOffset_0]; |
| 101 | + strm << opcode_name << " operand Ray Flags is 0x" << std::hex << value << ". "; |
| 102 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11884"; |
| 103 | + } break; |
| 104 | + case kErrorSubCodeRayHitObjectOpaque: { |
| 105 | + const uint32_t value = error_record[kInstRayHitObjectParamOffset_0]; |
| 106 | + strm << opcode_name << " operand Ray Flags is 0x" << std::hex << value << ". "; |
| 107 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11885"; |
| 108 | + } break; |
| 109 | + 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. "; |
| 113 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11886"; |
| 114 | + } break; |
| 115 | + 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. "; |
| 119 | + out_vuid_msg = "VUID-RuntimeSpirv-OpHitObjectTraceRayEXT-11887"; |
| 120 | + } break; |
| 121 | + case kErrorSubCodeRayHitObjectSBTIndexExceedsLimit: { |
| 122 | + // 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]; |
| 125 | + strm << "OpHitObjectSetShaderBindingTableRecordIndexEXT SBT index (" << std::dec << sbt_index |
| 126 | + << ") exceeds VkPhysicalDeviceRayTracingInvocationReorderPropertiesEXT::maxShaderBindingTableRecordIndex (" << max_sbt_index << "). "; |
| 127 | + out_vuid_msg = "VUID-RuntimeSpirv-maxShaderBindingTableRecordIndex-11888"; |
| 128 | + } 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; |
| 133 | + default: |
| 134 | + error_found = false; |
| 135 | + break; |
| 136 | + } |
| 137 | + out_error_msg += strm.str(); |
| 138 | + return error_found; |
| 139 | + }; |
| 140 | + |
| 141 | + return inst_error_logger; |
| 142 | + }); |
| 143 | +} |
| 144 | + |
| 145 | +} // namespace gpuav |
0 commit comments