Skip to content

Commit

Permalink
gpu: Fix enabled_features
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jun 20, 2024
1 parent d51a369 commit c90ae28
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 38 deletions.
8 changes: 4 additions & 4 deletions layers/gpu/core/gpuav_record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void Validator::PostCallRecordGetPhysicalDeviceProperties(VkPhysicalDevice physi
if (device_props->limits.maxBoundDescriptorSets > 1) {
device_props->limits.maxBoundDescriptorSets -= 1;
} else {
LogWarning("WARNING-GPU-Assisted-Validation-Setup", physicalDevice, record_obj.location,
"Unable to reserve descriptor binding slot on a device with only one slot.");
InternalWarning(physicalDevice, record_obj.location,
"Unable to reserve descriptor binding slot on a device with only one slot.");
}
}

Expand All @@ -84,8 +84,8 @@ void Validator::PostCallRecordGetPhysicalDeviceProperties2(VkPhysicalDevice phys
if (device_props2->properties.limits.maxBoundDescriptorSets > 1) {
device_props2->properties.limits.maxBoundDescriptorSets -= 1;
} else {
LogWarning("WARNING-GPU-Assisted-Validation-Setup", physicalDevice, record_obj.location,
"Unable to reserve descriptor binding slot on a device with only one slot.");
InternalWarning(physicalDevice, record_obj.location,
"Unable to reserve descriptor binding slot on a device with only one slot.");
}
}
// override all possible places maxUpdateAfterBindDescriptorsInAllPools can be set
Expand Down
54 changes: 32 additions & 22 deletions layers/gpu/core/gpuav_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,18 @@ void Validator::PreCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const
const RecordObject &record_obj, vku::safe_VkDeviceCreateInfo *modified_create_info) {
BaseClass::PreCallRecordCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice, record_obj, modified_create_info);

auto add_missing_features = [this, modified_create_info]() {
auto add_missing_features = [this, record_obj, modified_create_info]() {
if (force_buffer_device_address_) {
// Add buffer device address feature
if (auto *bda_features = const_cast<VkPhysicalDeviceBufferDeviceAddressFeatures *>(
vku::FindStructInPNextChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(modified_create_info))) {
InternalWarning(device, record_obj.location,
"Forcing VkPhysicalDeviceBufferDeviceAddressFeatures::bufferDeviceAddress to VK_TRUE");
bda_features->bufferDeviceAddress = VK_TRUE;
} else {
InternalWarning(
device, record_obj.location,
"Adding a VkPhysicalDeviceBufferDeviceAddressFeatures to pNext with bufferDeviceAddress set to VK_TRUE");
VkPhysicalDeviceBufferDeviceAddressFeatures new_bda_features = vku::InitStructHelper();
new_bda_features.bufferDeviceAddress = VK_TRUE;
vku::AddToPnext(*modified_create_info, new_bda_features);
Expand All @@ -97,7 +102,9 @@ void Validator::PreCallRecordCreateDevice(VkPhysicalDevice physicalDevice, const
if (api_version > VK_API_VERSION_1_1) {
if (auto *features12 = const_cast<VkPhysicalDeviceVulkan12Features *>(
vku::FindStructInPNextChain<VkPhysicalDeviceVulkan12Features>(modified_create_info->pNext))) {
if (force_buffer_device_address_) {
if (force_buffer_device_address_ && !features12->bufferDeviceAddress) {
InternalWarning(device, record_obj.location,
"Forcing VkPhysicalDeviceVulkan12Features::bufferDeviceAddress to VK_TRUE");
features12->bufferDeviceAddress = VK_TRUE;
}
} else {
Expand Down Expand Up @@ -168,13 +175,14 @@ void Validator::PostCreateDevice(const VkDeviceCreateInfo *pCreateInfo, const Lo
if (!bda_validation_possible) {
if (gpuav_settings.validate_bda) {
if (!supported_features.shaderInt64) {
LogWarning("WARNING-GPU-Assisted-Validation", device, loc,
"Buffer device address validation option was enabled, but required features shaderInt64 is not enabled. "
"Disabling option.");
InternalWarning(
device, loc,
"Buffer device address validation option was enabled, but required features shaderInt64 is not enabled. "
"Disabling option.");
} else {
LogWarning("WARNING-GPU-Assisted-Validation", device, loc,
"Buffer device address validation option was enabled, but required buffer device address extension "
"and/or features are not enabled. Disabling option.");
InternalWarning(device, loc,
"Buffer device address validation option was enabled, but required buffer device address extension "
"and/or features are not enabled. Disabling option.");
}
}
gpuav_settings.validate_bda = false;
Expand All @@ -183,41 +191,43 @@ void Validator::PostCreateDevice(const VkDeviceCreateInfo *pCreateInfo, const Lo
if (gpuav_settings.validate_ray_query) {
if (!enabled_features.rayQuery) {
gpuav_settings.validate_ray_query = false;
LogWarning("WARNING-GPU-Assisted-Validation", device, loc,
"Ray query validation option was enabled, but required feature rayQuery is not enabled. "
"Disabling option.");
InternalWarning(device, loc,
"Ray query validation option was enabled, but required feature rayQuery is not enabled. "
"Disabling option.");
}
}

// copy_buffer_to_image.comp relies on uint8_t buffers to perform validation
if (gpuav_settings.validate_buffer_copies) {
if (!enabled_features.uniformAndStorageBuffer8BitAccess) {
gpuav_settings.validate_buffer_copies = false;
LogWarning("WARNING-GPU-Assisted-Validation", device, loc,
"gpuav_validate_copies option was enabled, but uniformAndStorageBuffer8BitAccess feature is not available. "
"Disabling option.");
InternalWarning(
device, loc,
"gpuav_validate_copies option was enabled, but uniformAndStorageBuffer8BitAccess feature is not available. "
"Disabling option.");
}
}

if (IsExtEnabled(device_extensions.vk_ext_descriptor_buffer)) {
LogWarning("WARNING-GPU-Assisted-Validation", device, loc,
"VK_EXT_descriptor_buffer is enabled, but GPU-AV does not currently support validation of descriptor buffers. "
"Use of descriptor buffers will result in no descriptor checking");
InternalWarning(
device, loc,
"VK_EXT_descriptor_buffer is enabled, but GPU-AV does not currently support validation of descriptor buffers. "
"Use of descriptor buffers will result in no descriptor checking");
}

output_buffer_byte_size_ = glsl::kErrorBufferByteSize;

if (gpuav_settings.validate_descriptors && !force_buffer_device_address_) {
gpuav_settings.validate_descriptors = false;
LogWarning("WARNING-GPU-Assisted-Validation", device, loc,
"Buffer Device Address + feature is not available. No descriptor checking will be attempted");
InternalWarning(device, loc, "Buffer Device Address + feature is not available. No descriptor checking will be attempted");
}

if (gpuav_settings.IsBufferValidationEnabled() && (phys_dev_props.limits.maxPushConstantsSize < 4 * sizeof(uint32_t))) {
gpuav_settings.SetBufferValidationEnabled(false);
LogWarning("WARNING-GPU-Assisted-Validation", device, loc,
"Device does not support the minimum range of push constants (32 bytes). No indirect buffer checking will be "
"attempted");
InternalWarning(
device, loc,
"Device does not support the minimum range of push constants (32 bytes). No indirect buffer checking will be "
"attempted");
}

if (gpuav_settings.validate_descriptors) {
Expand Down
7 changes: 3 additions & 4 deletions layers/gpu/debug_printf/debug_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ void Validator::PostCreateDevice(const VkDeviceCreateInfo *pCreateInfo, const Lo
// This option was published when Debug PrintF came out, leave to not break people's flow
// Deprecated right after the 1.3.280 SDK release
if (!GetEnvironment("DEBUG_PRINTF_TO_STDOUT").empty()) {
LogWarning("WARNING-DEBUG-PRINTF", device, loc,
"DEBUG_PRINTF_TO_STDOUT was set, this is deprecated, please use VK_LAYER_PRINTF_TO_STDOUT");
InternalWarning(device, loc, "DEBUG_PRINTF_TO_STDOUT was set, this is deprecated, please use VK_LAYER_PRINTF_TO_STDOUT");
use_stdout = true;
}

Expand Down Expand Up @@ -404,8 +403,8 @@ void Validator::AnalyzeAndGenerateMessage(VkCommandBuffer command_buffer, VkQueu
index += debug_record->size;
}
if ((index - spvtools::kDebugOutputDataOffset) != expect) {
LogWarning("WARNING-DEBUG-PRINTF", queue, loc,
"WARNING - Debug Printf message was truncated, likely due to a buffer size that was too small for the message");
InternalWarning(queue, loc,
"Debug Printf message was truncated, likely due to a buffer size that was too small for the message");
}
memset(debug_output_buffer, 0, 4 * (debug_output_buffer[spvtools::kDebugOutputSizeOffset] + spvtools::kDebugOutputDataOffset));
}
Expand Down
20 changes: 16 additions & 4 deletions layers/gpu/instrumentation/gpu_shader_instrumentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,28 @@ void GpuShaderInstrumentor::PreCallRecordCreateDevice(VkPhysicalDevice physicalD
DispatchGetPhysicalDeviceFeatures(physicalDevice, &supported_features);

if (auto enabled_features = const_cast<VkPhysicalDeviceFeatures *>(modified_create_info->pEnabledFeatures)) {
if (supported_features.fragmentStoresAndAtomics) {
if (supported_features.fragmentStoresAndAtomics && !enabled_features->fragmentStoresAndAtomics) {
InternalWarning(device, record_obj.location, "Forcing VkPhysicalDeviceFeatures::fragmentStoresAndAtomics to VK_TRUE");
enabled_features->fragmentStoresAndAtomics = VK_TRUE;
}
if (supported_features.vertexPipelineStoresAndAtomics) {
if (supported_features.vertexPipelineStoresAndAtomics && !enabled_features->vertexPipelineStoresAndAtomics) {
InternalWarning(device, record_obj.location,
"Forcing VkPhysicalDeviceFeatures::vertexPipelineStoresAndAtomics to VK_TRUE");
enabled_features->vertexPipelineStoresAndAtomics = VK_TRUE;
}
}

auto add_missing_features = [modified_create_info]() {
auto add_missing_features = [this, record_obj, modified_create_info]() {
// Add timeline semaphore feature - This is required as we use it to manage when command buffers are submitted at queue
// submit time
if (auto *ts_features = const_cast<VkPhysicalDeviceTimelineSemaphoreFeatures *>(
vku::FindStructInPNextChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(modified_create_info))) {
InternalWarning(device, record_obj.location,
"Forcing VkPhysicalDeviceTimelineSemaphoreFeatures::timelineSemaphore to VK_TRUE");
ts_features->timelineSemaphore = VK_TRUE;
} else {
InternalWarning(device, record_obj.location,
"Adding a VkPhysicalDeviceTimelineSemaphoreFeatures to pNext with timelineSemaphore set to VK_TRUE");
VkPhysicalDeviceTimelineSemaphoreFeatures new_ts_features = vku::InitStructHelper();
new_ts_features.timelineSemaphore = VK_TRUE;
vku::AddToPnext(*modified_create_info, new_ts_features);
Expand All @@ -219,6 +226,7 @@ void GpuShaderInstrumentor::PreCallRecordCreateDevice(VkPhysicalDevice physicalD
if (api_version > VK_API_VERSION_1_1) {
if (auto *features12 = const_cast<VkPhysicalDeviceVulkan12Features *>(
vku::FindStructInPNextChain<VkPhysicalDeviceVulkan12Features>(modified_create_info->pNext))) {
InternalWarning(device, record_obj.location, "Forcing VkPhysicalDeviceVulkan12Features::timelineSemaphore to VK_TRUE");
features12->timelineSemaphore = VK_TRUE;
} else {
add_missing_features();
Expand All @@ -227,7 +235,6 @@ void GpuShaderInstrumentor::PreCallRecordCreateDevice(VkPhysicalDevice physicalD
// Add our new extensions (will only add if found)
const std::string_view ts_ext{"VK_KHR_timeline_semaphore"};
vku::AddExtension(*modified_create_info, ts_ext.data());

add_missing_features();
}
}
Expand Down Expand Up @@ -831,4 +838,9 @@ void GpuShaderInstrumentor::InternalError(LogObjectList objlist, const Location
ReleaseDeviceDispatchObject(this->container_type);
}

void GpuShaderInstrumentor::InternalWarning(LogObjectList objlist, const Location &loc, const char *const specific_message) const {
char const *vuid = container_type == LayerObjectTypeDebugPrintf ? "WARNING-DEBUG-PRINTF" : "WARNING-GPU-Assisted-Validation";
LogWarning(vuid, objlist, loc, "Internal Warning: %s", specific_message);
}

} // namespace gpu
1 change: 1 addition & 0 deletions layers/gpu/instrumentation/gpu_shader_instrumentor.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class GpuShaderInstrumentor : public ValidationStateTracker {
const RecordObject &record_obj) override;

void InternalError(LogObjectList objlist, const Location &loc, const char *const specific_message, bool vma_fail = false) const;
void InternalWarning(LogObjectList objlist, const Location &loc, const char *const specific_message) const;
bool CheckForGpuAvEnabled(const void *pNext);

protected:
Expand Down
7 changes: 5 additions & 2 deletions layers/vulkan/generated/chassis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDevice

// Save local info in device object
device_interceptor->api_version = device_interceptor->device_extensions.InitFromDeviceCreateInfo(
&instance_interceptor->instance_extensions, effective_api_version, pCreateInfo);
&instance_interceptor->instance_extensions, effective_api_version,
reinterpret_cast<VkDeviceCreateInfo*>(&modified_create_info));
device_interceptor->device_extensions = device_extensions;

layer_init_device_dispatch_table(*pDevice, &device_interceptor->device_dispatch_table, fpGetDeviceProcAddr);
Expand Down Expand Up @@ -655,7 +656,9 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice gpu, const VkDevice

for (ValidationObject* intercept : instance_interceptor->object_dispatch) {
auto lock = intercept->WriteLock();
intercept->PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, record_obj);
// Send down modified create info as we want to mark enabled features that we sent down on behalf of the app
intercept->PostCallRecordCreateDevice(gpu, reinterpret_cast<VkDeviceCreateInfo*>(&modified_create_info), pAllocator,
pDevice, record_obj);
}

device_interceptor->InitObjectDispatchVectors();
Expand Down
5 changes: 3 additions & 2 deletions scripts/generators/layer_chassis_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ def generateSource(self):
// Save local info in device object
device_interceptor->api_version = device_interceptor->device_extensions.InitFromDeviceCreateInfo(
&instance_interceptor->instance_extensions, effective_api_version, pCreateInfo);
&instance_interceptor->instance_extensions, effective_api_version, reinterpret_cast<VkDeviceCreateInfo*>(&modified_create_info));
device_interceptor->device_extensions = device_extensions;
layer_init_device_dispatch_table(*pDevice, &device_interceptor->device_dispatch_table, fpGetDeviceProcAddr);
Expand Down Expand Up @@ -1331,7 +1331,8 @@ def generateSource(self):
for (ValidationObject* intercept : instance_interceptor->object_dispatch) {
auto lock = intercept->WriteLock();
intercept->PostCallRecordCreateDevice(gpu, pCreateInfo, pAllocator, pDevice, record_obj);
// Send down modified create info as we want to mark enabled features that we sent down on behalf of the app
intercept->PostCallRecordCreateDevice(gpu, reinterpret_cast<VkDeviceCreateInfo*>(&modified_create_info), pAllocator, pDevice, record_obj);
}
device_interceptor->InitObjectDispatchVectors();
Expand Down

0 comments on commit c90ae28

Please sign in to comment.