Skip to content

Commit

Permalink
Fix validation layer errors
Browse files Browse the repository at this point in the history
We now let glslangValidator generate code for vulkan1.1
so we get the StorageBuffer storage class instead of uniform
for storage buffers.
And we enable 8-/16- bit storage types since we use them
for indirect vertex copying.
  • Loading branch information
nyorain committed Dec 16, 2024
1 parent 637899c commit 2edacb4
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/commandHook/hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <vk/vulkan.h>
#include <vector>
#include <memory>
#include <variant>
#include <optional>
#include <string>

Expand Down
1 change: 1 addition & 0 deletions src/commandHook/record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <command/record.hpp>
#include <commandHook/state.hpp>
#include <vkutil/dynds.hpp>
#include <variant>

namespace vil {

Expand Down
4 changes: 2 additions & 2 deletions src/data/histogram.vert
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ layout(location = 1) out float outHeight;

#include "histogram.glsl"

layout(set = 0, binding = 0) buffer HistData {
layout(set = 0, binding = 0) readonly buffer HistData {
HistMetadata meta;
uvec4 data[];
} hist;

void main() {
vec4 lhist = vec4(0.0);
vec4 lhist = vec4(0.0);
float maxHist = hist.meta.maxHist;
for(uint i = 0u; i < 3; ++i) {
lhist[i] = hist.data[gl_InstanceIndex][i] / maxHist;
Expand Down
5 changes: 4 additions & 1 deletion src/data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ if glslang.found()
# TODO: should compile with optimization but default glslang
# on arch does not come with optimizer linked in :(

args = [glslang, '-V', '--vn', varname, config, '-o', '@OUTPUT@', '@INPUT@']
args = [glslang, '-V', '--vn', varname, config, '@INPUT@']

args += ['-o', '@OUTPUT@']
args += ['--target-env', 'vulkan1.1']

if glslang_version.version_compare('>=11.0.0')
args += '--quiet'
Expand Down
76 changes: 64 additions & 12 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,14 @@ VkResult doCreateDevice(
auto hasTransformFeedbackApi = enableTransformFeedback &&
fpPhdevFeatures2 && fpPhdevProps2 &&
hasExt(supportedExts, VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
auto has16BitStorageApi =
fpPhdevFeatures2 && fpPhdevProps2 &&
((ini.vulkan11 && phdevProps.apiVersion >= VK_API_VERSION_1_1) ||
hasExt(supportedExts, VK_KHR_16BIT_STORAGE_EXTENSION_NAME));
auto has8BitStorageApi =
fpPhdevFeatures2 && fpPhdevProps2 &&
((ini.vulkan12 && phdevProps.apiVersion >= VK_API_VERSION_1_2) ||
hasExt(supportedExts, VK_KHR_8BIT_STORAGE_EXTENSION_NAME));
auto hasDeviceFaultApi = enableDeviceFault &&
fpPhdevFeatures2 && fpPhdevProps2 &&
hasExt(supportedExts, VK_EXT_DEVICE_FAULT_EXTENSION_NAME);
Expand All @@ -573,23 +581,29 @@ VkResult doCreateDevice(
auto hasTransformFeedback = false;
auto hasDeviceFault = false;
auto hasAddressBindingReport = false;
bool hasStorage8 = false;
bool hasStorage16 = false;

// find generally relevant feature structs in chain
VkPhysicalDeviceVulkan11Features features11 {};
VkPhysicalDeviceVulkan12Features features12 {};
VkPhysicalDeviceVulkan13Features features13 {};

VkPhysicalDeviceVulkan11Features* inVulkan11 = nullptr;
VkPhysicalDeviceVulkan12Features* inVulkan12 = nullptr;
VkPhysicalDeviceTimelineSemaphoreFeatures* inTS = nullptr;
VkPhysicalDeviceTransformFeedbackFeaturesEXT* inXFB = nullptr;
VkPhysicalDeviceBufferDeviceAddressFeatures* inBufAddr = nullptr;
VkPhysicalDeviceFaultFeaturesEXT* inDF = nullptr;
VkPhysicalDeviceAddressBindingReportFeaturesEXT* inABR = nullptr;
VkPhysicalDevice16BitStorageFeatures* inStorage16 {};
VkPhysicalDevice8BitStorageFeatures* inStorage8 {};

auto* link = static_cast<VkBaseOutStructure*>(pNext);
while(link) {
if(link->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES) {
dlg_assert(phdevProps.apiVersion >= VK_API_VERSION_1_1);
inVulkan11 = reinterpret_cast<VkPhysicalDeviceVulkan11Features*>(link);
features11 = *reinterpret_cast<VkPhysicalDeviceVulkan11Features*>(link);
} else if(link->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES) {
dlg_assert(phdevProps.apiVersion >= VK_API_VERSION_1_2);
Expand All @@ -608,6 +622,10 @@ VkResult doCreateDevice(
inDF = reinterpret_cast<VkPhysicalDeviceFaultFeaturesEXT*>(link);
} else if(link->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ADDRESS_BINDING_REPORT_FEATURES_EXT) {
inABR = reinterpret_cast<VkPhysicalDeviceAddressBindingReportFeaturesEXT*>(link);
} else if(link->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES) {
inStorage8 = reinterpret_cast<VkPhysicalDevice8BitStorageFeatures*>(link);
} else if(link->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES) {
inStorage16 = reinterpret_cast<VkPhysicalDevice16BitStorageFeatures*>(link);
}

link = (static_cast<VkBaseOutStructure*>(link->pNext));
Expand All @@ -617,7 +635,10 @@ VkResult doCreateDevice(
VkPhysicalDeviceTransformFeedbackFeaturesEXT tfFeatures {};
VkPhysicalDeviceFaultFeaturesEXT dfFeatures {};
VkPhysicalDeviceAddressBindingReportFeaturesEXT abrFeatures {};
if(hasTimelineSemaphoresApi || hasTransformFeedbackApi || hasDeviceFaultApi) {
VkPhysicalDevice16BitStorageFeatures storage16Features {};
VkPhysicalDevice8BitStorageFeatures storage8Features {};
if(hasTimelineSemaphoresApi || hasTransformFeedbackApi || hasDeviceFaultApi ||
has16BitStorageApi || has8BitStorageApi) {
dlg_assert(fpPhdevFeatures2);
dlg_assert(fpPhdevProps2);

Expand All @@ -636,6 +657,18 @@ VkResult doCreateDevice(
features2.pNext = &tfFeatures;
}

if(has8BitStorageApi) {
storage8Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES;
storage8Features.pNext = features2.pNext;
features2.pNext = &storage8Features;
}

if(has16BitStorageApi) {
storage16Features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES;
storage16Features.pNext = features2.pNext;
features2.pNext = &storage16Features;
}

if(hasDeviceFaultApi) {
dfFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FAULT_FEATURES_EXT;
dfFeatures.pNext = features2.pNext;
Expand All @@ -654,16 +687,11 @@ VkResult doCreateDevice(
hasTimelineSemaphores = true;

// check if application already has a feature struct holding it
auto addLink = true;
if(inVulkan12) {
addLink = false;
inVulkan12->timelineSemaphore = true;
} else if(inTS) {
addLink = false;
inTS->timelineSemaphore = true;
}

if(addLink) {
} else {
tsFeatures.pNext = const_cast<void*>(nci.pNext);
nci.pNext = &tsFeatures;
}
Expand All @@ -681,13 +709,9 @@ VkResult doCreateDevice(
hasTransformFeedback = true;

// check if application already has a feature struct holding it
auto addLink = true;
if(inXFB) {
addLink = false;
inXFB->transformFeedback = true;
}

if(addLink) {
} else {
tfFeatures.geometryStreams = false;
tfFeatures.pNext = const_cast<void*>(nci.pNext);
nci.pNext = &tfFeatures;
Expand All @@ -699,6 +723,32 @@ VkResult doCreateDevice(
}
}

if(storage8Features.storageBuffer8BitAccess) {
hasStorage8 = true;

if(inStorage8) {
inStorage8->storageBuffer8BitAccess = true;
} else if(inVulkan12) {
inVulkan12->storageBuffer8BitAccess = true;
} else {
storage8Features.pNext = const_cast<void*>(nci.pNext);
nci.pNext = &storage8Features;
}
}

if(storage16Features.storageBuffer16BitAccess) {
hasStorage16 = true;

if(inStorage16) {
inStorage16->storageBuffer16BitAccess = true;
} else if(inVulkan11) {
inVulkan11->storageBuffer16BitAccess = true;
} else {
storage16Features.pNext = const_cast<void*>(nci.pNext);
nci.pNext = &storage16Features;
}
}

if(dfFeatures.deviceFault) {
hasDeviceFault = true;

Expand Down Expand Up @@ -793,6 +843,8 @@ VkResult doCreateDevice(
dev.nonSolidFill = pEnabledFeatures10->fillModeNonSolid;
dev.shaderStorageImageWriteWithoutFormat = pEnabledFeatures10->shaderStorageImageWriteWithoutFormat;
dev.extDeviceFault = hasDeviceFault;
dev.storage8Bit = hasStorage8;
dev.storage16Bit = hasStorage16;

if(hasAddressBindingReport) {
dev.addressMap = std::make_unique<DeviceAddressMap>();
Expand Down
2 changes: 2 additions & 0 deletions src/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct Device {
bool transformFeedback {}; // whether we have transformFeedback
bool nonSolidFill {}; // whether we have nonSolidFill mode
bool bufferDeviceAddress {}; // whether we have bufferDeviceAddress
bool storage8Bit {};
bool storage16Bit {};
bool shaderStorageImageWriteWithoutFormat {};
bool extDeviceFault {}; // whether EXT_device_fault was enabled

Expand Down

0 comments on commit 2edacb4

Please sign in to comment.