Skip to content

Commit 653e15f

Browse files
committed
gpuav: Add 10774
1 parent 0f6964a commit 653e15f

File tree

15 files changed

+946
-360
lines changed

15 files changed

+946
-360
lines changed

layers/gpuav/core/gpuav_features.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ void Instance::AddFeatures(VkPhysicalDevice physical_device, vku::safe_VkDeviceC
6060
VkPhysicalDeviceCooperativeMatrixFeaturesKHR supported_coop_mat_feature = vku::InitStructHelper();
6161
VkPhysicalDeviceRobustness2FeaturesKHR supported_robustness2_feature = vku::InitStructHelper(&supported_coop_mat_feature);
6262
VkPhysicalDevice8BitStorageFeatures supported_8bit_feature = vku::InitStructHelper(&supported_robustness2_feature);
63-
VkPhysicalDeviceBufferDeviceAddressFeatures supported_bda_feature = vku::InitStructHelper(&supported_8bit_feature);
63+
VkPhysicalDevice16BitStorageFeatures supported_16bit_feature = vku::InitStructHelper(&supported_8bit_feature);
64+
VkPhysicalDeviceBufferDeviceAddressFeatures supported_bda_feature = vku::InitStructHelper(&supported_16bit_feature);
6465
VkPhysicalDeviceScalarBlockLayoutFeatures supported_scalar_feature = vku::InitStructHelper(&supported_bda_feature);
6566
VkPhysicalDeviceVulkanMemoryModelFeatures supported_memory_model_feature = vku::InitStructHelper(&supported_scalar_feature);
6667
VkPhysicalDeviceTimelineSemaphoreFeatures supported_timeline_feature = vku::InitStructHelper(&supported_memory_model_feature);
@@ -297,6 +298,42 @@ void Instance::AddFeatures(VkPhysicalDevice physical_device, vku::safe_VkDeviceC
297298
}
298299
}
299300

301+
if (supported_16bit_feature.storageBuffer16BitAccess) {
302+
auto add_16bit_access = [modified_create_info, &adjustment_warnings]() {
303+
// Add storageBuffer16BitAccess feature
304+
if (auto *sixteen_bit_access_feature = const_cast<VkPhysicalDevice16BitStorageFeatures *>(
305+
vku::FindStructInPNextChain<VkPhysicalDevice16BitStorageFeatures>(modified_create_info))) {
306+
if (!sixteen_bit_access_feature->storageBuffer16BitAccess) {
307+
adjustment_warnings += "\tForcing VkPhysicalDevice16BitStorageFeatures::storageBuffer16BitAccess to VK_TRUE\n";
308+
sixteen_bit_access_feature->storageBuffer16BitAccess = VK_TRUE;
309+
}
310+
} else {
311+
adjustment_warnings +=
312+
"\tAdding a VkPhysicalDevice16BitStorageFeatures to pNext with storageBuffer16BitAccess "
313+
"set to VK_TRUE\n";
314+
VkPhysicalDevice16BitStorageFeatures new_16bit_features = vku::InitStructHelper();
315+
new_16bit_features.storageBuffer16BitAccess = VK_TRUE;
316+
vku::AddToPnext(*modified_create_info, new_16bit_features);
317+
}
318+
};
319+
320+
if (api_version >= VK_API_VERSION_1_2) {
321+
if (auto *features12 = const_cast<VkPhysicalDeviceVulkan11Features *>(
322+
vku::FindStructInPNextChain<VkPhysicalDeviceVulkan11Features>(modified_create_info->pNext))) {
323+
if (!features12->storageBuffer16BitAccess) {
324+
adjustment_warnings += "\tForcing VkPhysicalDeviceVulkan11Features::storageBuffer16BitAccess to VK_TRUE\n";
325+
features12->storageBuffer16BitAccess = VK_TRUE;
326+
}
327+
} else {
328+
add_16bit_access();
329+
}
330+
} else if (IsExtensionAvailable(VK_KHR_16BIT_STORAGE_EXTENSION_NAME, available_extensions)) {
331+
// Only adds if not found already
332+
vku::AddExtension(*modified_create_info, VK_KHR_16BIT_STORAGE_EXTENSION_NAME);
333+
add_16bit_access();
334+
}
335+
}
336+
300337
if (gpuav_settings.debug_printf_enabled) {
301338
if (!IsExtensionAvailable(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, available_extensions)) {
302339
adjustment_warnings +=

layers/gpuav/core/gpuav_record.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ void Validator::PreCallRecordCmdBuildAccelerationStructuresKHR(
616616
}
617617
auto &cb_sub_state = SubState(*cb_state);
618618
const LastBound &last_bound = cb_state->GetLastBoundRayTracing();
619-
valcmd::BuildAccelerationStructures(*this, record_obj.location, cb_sub_state, last_bound, infoCount, pInfos, ppBuildRangeInfos);
619+
valcmd::TLAS(*this, record_obj.location, cb_sub_state, last_bound, infoCount, pInfos, ppBuildRangeInfos);
620+
valcmd::BLAS(*this, record_obj.location, cb_sub_state, last_bound, infoCount, pInfos, ppBuildRangeInfos);
620621
}
621622

622623
void Validator::PreCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,

layers/gpuav/core/gpuav_setup.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,13 @@ struct BufferContent : public Setting {
388388
struct AccelerationStructuresBuild : public Setting {
389389
bool IsEnabled(const GpuAVSettings &settings) { return settings.validate_acceleration_structures_builds; }
390390
// Validation shader branches on a push constant value to fetch different descriptors
391-
bool HasRequiredFeatures(const DeviceFeatures &features) { return features.shaderInt64; }
391+
bool HasRequiredFeatures(const DeviceFeatures &features) {
392+
return features.shaderInt64 && features.storageBuffer8BitAccess && features.storageBuffer16BitAccess;
393+
}
392394
void Disable(GpuAVSettings &settings) { settings.validate_acceleration_structures_builds = false; }
393395
std::string DisableMessage() {
394-
return "\t structure builds validation option was enabled, but the shaderInt64 feature is not "
396+
return "\t structure builds validation option was enabled, but the shaderInt64 or storageBuffer8BitAccess or "
397+
"storageBuffer16BitAccess features are not "
395398
"supported. [Disabling "
396399
"gpuav_acceleration_structures_builds]\n";
397400
}

layers/gpuav/shaders/gpuav_error_codes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ const int kErrorSubCode_PreBuildAccelerationStructures_DestroyedASBuffer = 3;
193193
const int kErrorSubCode_PreBuildAccelerationStructures_InvalidASType = 4;
194194
const int kErrorSubCode_PreBuildAccelerationStructures_DestroyedASMemory = 5;
195195
const int kErrorSubCode_PreBuildAccelerationStructures_BlasMemoryOverlap = 6;
196+
const int kErrorSubCode_PreBuildAccelerationStructures_MaxFetchedIndex = 7;
196197

197198
#ifdef __cplusplus
198199
} // namespace glsl
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}

layers/gpuav/shaders/validation_cmd/build_acceleration_structures.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ layout(buffer_reference, scalar) buffer PtrToBlasBuiltInCmd { Range buffer_range
106106
const uint kBuildASValidationMode_invalid_AS = 0;
107107
const uint kBuildASValidationMode_memory_overlaps = 1;
108108

109-
// Case where arrayOfPointers is false
110-
struct AccelerationStructureReferencePushData {
109+
struct TLASValidationShaderPushData {
111110
PtrtoPtrToAccelerationStructureArrays ptr_to_ptr_to_accel_structs_arrays;
112111
uint64_t valid_dummy_blas_addr;
113112

@@ -125,6 +124,22 @@ struct AccelerationStructureReferencePushData {
125124
uint blas_built_in_cmd_array_size;
126125
};
127126

127+
// From VkIndexType
128+
const uint INDEX_TYPE_UINT16 = 0;
129+
const uint INDEX_TYPE_UINT32 = 1;
130+
const uint INDEX_TYPE_UINT8 = 1000265000;
131+
const uint INDEX_TYPE_NONE_KHR = 1000165000;
132+
133+
struct BLASValidationShaderPushData {
134+
uint64_t index_data; // Cast it appropriately according to index_type
135+
uint index_type;
136+
uint max_vertex;
137+
uint first_vertex;
138+
uint primitive_offset;
139+
uint primitive_count;
140+
uint error_info_i;
141+
};
142+
128143
#ifdef __cplusplus
129144
} // namespace glsl
130145
} // namespace gpuav

layers/gpuav/shaders/validation_cmd/build_acceleration_structures.comp renamed to layers/gpuav/shaders/validation_cmd/tlas.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
layout(push_constant, scalar)
2525
uniform PushConstants {
26-
AccelerationStructureReferencePushData pc;
26+
TLASValidationShaderPushData pc;
2727
};
2828

2929
bool RangesInclude(Range r1, Range r2) {

0 commit comments

Comments
 (0)