|
| 1 | +// Copyright (c) 2022-2026 The Khronos Group Inc. |
| 2 | +// Copyright (c) 2022-2026 Valve Corporation |
| 3 | +// Copyright (c) 2022-2026 LunarG, Inc. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +#version 460 |
| 18 | +#extension GL_GOOGLE_include_directive : enable |
| 19 | +#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require |
| 20 | +#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require |
| 21 | + |
| 22 | +#include "common.h" |
| 23 | +#include "build_acceleration_structures.h" |
| 24 | + |
| 25 | +layout(push_constant, scalar) |
| 26 | +uniform PushConstants { |
| 27 | + BLASValidationShaderPushData pc; |
| 28 | +}; |
| 29 | + |
| 30 | +// CPU will try to dispatch `primitive_count` threads |
| 31 | +layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; |
| 32 | + |
| 33 | +layout(buffer_reference, scalar) buffer ArrayU8 { uint8_t array[]; }; |
| 34 | +layout(buffer_reference, scalar) buffer ArrayU16 { uint16_t array[]; }; |
| 35 | +layout(buffer_reference, scalar) buffer ArrayU32 { uint array[]; }; |
| 36 | + |
| 37 | +uint LoadIndex(uint i) { |
| 38 | + if (pc.index_type == INDEX_TYPE_UINT16) { |
| 39 | + ArrayU16 array_u16 = ArrayU16(pc.index_data + pc.primitive_offset); |
| 40 | + return uint(array_u16.array[i]); |
| 41 | + } else if (pc.index_type == INDEX_TYPE_UINT32) { |
| 42 | + ArrayU32 array_u32 = ArrayU32(pc.index_data + pc.primitive_offset); |
| 43 | + return array_u32.array[i]; |
| 44 | + } else if (pc.index_type == INDEX_TYPE_UINT8) { |
| 45 | + ArrayU8 array_u8 = ArrayU8(pc.index_data + pc.primitive_offset); |
| 46 | + return uint(array_u8.array[i]); |
| 47 | + } else { |
| 48 | + return 0; |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +void StoreIndex(uint i, uint value) { |
| 53 | + if (pc.index_type == INDEX_TYPE_UINT16) { |
| 54 | + ArrayU16 array_u16 = ArrayU16(pc.index_data + pc.primitive_offset); |
| 55 | + array_u16.array[i] = uint16_t(value); |
| 56 | + } else if (pc.index_type == INDEX_TYPE_UINT32) { |
| 57 | + ArrayU32 array_u32 = ArrayU32(pc.index_data + pc.primitive_offset); |
| 58 | + array_u32.array[i] = value; |
| 59 | + } else if (pc.index_type == INDEX_TYPE_UINT8) { |
| 60 | + ArrayU8 array_u8 = ArrayU8(pc.index_data + pc.primitive_offset); |
| 61 | + array_u8.array[i] = uint8_t(value); |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +void main() { |
| 67 | + const uint gid = gl_GlobalInvocationID.x; |
| 68 | + |
| 69 | + if (gid >= (3 * pc.primitive_count)) { |
| 70 | + return; |
| 71 | + } |
| 72 | + const uint fetched_index = LoadIndex(gid); |
| 73 | + if (pc.max_vertex < (pc.first_vertex + fetched_index)) { |
| 74 | + // In practice an invalid index does not cause a device loss, so don't bother changing its value. |
| 75 | + // Should someone add this back, a write barrier needs to be added on the CPU side. |
| 76 | + // StoreIndex(gid, 0); |
| 77 | + GpuavLogError4(kErrorGroupGpuPreBuildAccelerationStructures, kErrorSubCode_PreBuildAccelerationStructures_MaxFetchedIndex, fetched_index, gid, pc.error_info_i, 0); |
| 78 | + } |
| 79 | +} |
0 commit comments