1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
// Copyright (c) 2024-2025 The Khronos Group Inc.
// Copyright (c) 2024-2025 Valve Corporation
// Copyright (c) 2024-2025 LunarG, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// NOTE: This file doesn't contain any entrypoints and should be compiled with the--no-link option for glslang
#version 450
#extension GL_GOOGLE_include_directive : enable
#include "common_descriptor_sets.h"
#include "error_payload.h"
layout(buffer_reference, buffer_reference_align = 8, scalar) buffer DescriptorSetType {
// struct glsl::DescriptorState {
// x: id
// y: extra data depending on the descriptor type
// }
uvec2 data[];
};
layout(buffer_reference, buffer_reference_align = 8, scalar) buffer InitializedStatus {
// Maps to DescriptorHeap and used to detect if descriptor is still valid on CPU
uint data[];
};
layout(set = kInstDefaultDescriptorSet, binding = kBindingInstDescriptorIndexingOOB, scalar) buffer BoundDescriptorSetsStateSSBO {
InitializedStatus descriptor_init_status;
DescriptorSetType descriptor_set_types[kDebugInputBindlessMaxDescSets];
} gpuav;
// Unlike the bindless version, we don't need to check for Uninitialized and Destroyed descriptors.
// At draw time on the CPU we can verify that information.
bool inst_descriptor_indexing_oob_non_bindless(const uint inst_offset, const uint desc_set, const uint binding,
const uint desc_index, const uint binding_layout_size, const uint binding_layout_offset) {
// For non-array this should hopefully optimized out as "if (0 > 1)"
// Have seen with Mesa, that the final NIR will optimize out all of inst_descriptor_indexing_oob_non_bindless if this is false.
if (desc_index >= binding_layout_size) {
error_payload = ErrorPayload(
inst_offset,
SpecConstantLinkShaderId | (kErrorGroupInstDescriptorIndexingOOB << kErrorGroupShift) | (kErrorSubCodeDescriptorIndexingBounds << kErrorSubCodeShift),
(desc_set << kInstDescriptorIndexingSetShift) | desc_index,
binding_layout_size,
binding
);
return false;
}
return true;
}
// Unlike the non-bindless version, bindless needs to check for Uninitialized and Destroyed descriptors.
bool inst_descriptor_indexing_oob_bindless(const uint inst_offset, const uint desc_set, const uint binding,
const uint desc_index, const uint binding_layout_size, const uint binding_layout_offset) {
uint error = 0u;
// First make sure the index is not OOB
if (desc_index >= binding_layout_size) {
error = kErrorSubCodeDescriptorIndexingBounds;
} else {
DescriptorSetType descriptor_set_type = gpuav.descriptor_set_types[desc_set];
// check if the descriptor was ever initialized
const uint global_descriptor_index = binding_layout_offset + desc_index;
uint desc_id = descriptor_set_type.data[global_descriptor_index].x & kNullDescriptor;
if (desc_id == 0u) {
error = kErrorSubCodeDescriptorIndexingUninitialized;
} else if (desc_id != kNullDescriptor) {
// check that the resource is still valid (and not using nullDescriptor)
uint desc_index = desc_id / 32;
uint desc_bit = 1 << (desc_id & 31);
if ((gpuav.descriptor_init_status.data[desc_index] & desc_bit) == 0) {
error = kErrorSubCodeDescriptorIndexingDestroyed;
}
}
}
if (0u != error) {
error_payload = ErrorPayload(
inst_offset,
SpecConstantLinkShaderId | (kErrorGroupInstDescriptorIndexingOOB << kErrorGroupShift) | (error << kErrorSubCodeShift),
(desc_set << kInstDescriptorIndexingSetShift) | desc_index,
binding_layout_size,
binding
);
return false;
}
return true;
}
// This version includes an extra check for Combined Image Samplers
bool inst_descriptor_indexing_oob_bindless_combined_image_sampler(const uint inst_offset, const uint desc_set, const uint binding,
const uint desc_index, const uint binding_layout_size, const uint binding_layout_offset) {
uint error = 0u;
// First make sure the index is not OOB
if (desc_index >= binding_layout_size) {
error = kErrorSubCodeDescriptorIndexingBounds;
} else {
DescriptorSetType descriptor_set_type = gpuav.descriptor_set_types[desc_set];
// check if the descriptor was ever initialized
const uint global_descriptor_index = binding_layout_offset + desc_index;
uvec2 descriptor_state = descriptor_set_type.data[global_descriptor_index];
uint desc_id = descriptor_state.x & kNullDescriptor;
if (desc_id == 0u) {
error = kErrorSubCodeDescriptorIndexingUninitialized;
} else if (desc_id != kNullDescriptor) {
// check that the resource is still valid (and not using nullDescriptor)
uint desc_index = desc_id / 32;
uint desc_bit = 1 << (desc_id & 31);
if ((gpuav.descriptor_init_status.data[desc_index] & desc_bit) == 0) {
error = kErrorSubCodeDescriptorIndexingDestroyed;
}
}
// If dealing with a combined image sampler, need to check the sampler as well
uint desc_type = (descriptor_state.x & ~kNullDescriptor) >> kDescBitShift;
if (desc_type == kImageSamplerDesc && error == 0) {
// check sampler
desc_id = descriptor_state.y;
if (desc_id == 0u) {
error = kErrorSubCodeDescriptorIndexingUninitialized;
} else if (desc_id != kNullDescriptor) {
// check that the resource is still valid
uint desc_index = desc_id / 32;
uint desc_bit = 1 << (desc_id & 31);
if ((gpuav.descriptor_init_status.data[desc_index] & desc_bit) == 0) {
error = kErrorSubCodeDescriptorIndexingDestroyed;
}
}
}
}
if (0u != error) {
error_payload = ErrorPayload(
inst_offset,
SpecConstantLinkShaderId | (kErrorGroupInstDescriptorIndexingOOB << kErrorGroupShift) | (error << kErrorSubCodeShift),
(desc_set << kInstDescriptorIndexingSetShift) | desc_index,
binding_layout_size,
binding
);
return false;
}
return true;
}
|