Upgrade SPV and GLSL version if using Vulkan 1.2

This commit is contained in:
Magnus Norddahl 2022-06-06 00:18:24 +02:00 committed by Christoph Oelckers
parent 5e9906e3d3
commit 0c90a72c66
3 changed files with 119 additions and 106 deletions

View file

@ -119,6 +119,7 @@ static const TBuiltInResource DefaultTBuiltInResource = {
/* .maxTaskWorkGroupSizeY_NV = */ 1,
/* .maxTaskWorkGroupSizeZ_NV = */ 1,
/* .maxMeshViewCountNV = */ 4,
/* .maxDualSourceDrawBuffersEXT = */ 1,
/* .limits = */ {
/* .nonInductiveForLoops = */ 1,
@ -159,8 +160,16 @@ std::unique_ptr<VulkanShader> ShaderBuilder::create(const char *shadername, Vulk
glslang::TShader shader(stage);
shader.setStrings(sources, 1);
shader.setEnvInput(glslang::EShSourceGlsl, stage, glslang::EShClientVulkan, 100);
if (device->ApiVersion == VK_API_VERSION_1_2)
{
shader.setEnvClient(glslang::EShClientVulkan, glslang::EShTargetVulkan_1_2);
shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_4);
}
else
{
shader.setEnvClient(glslang::EShClientVulkan, glslang::EShTargetVulkan_1_0);
shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_0);
}
bool compileSuccess = shader.parse(&resources, 110, false, EShMsgVulkanRules);
if (!compileSuccess)
{

View file

@ -343,7 +343,7 @@ void VulkanDevice::CreateInstance()
// Try get the highest vulkan version we can get
VkResult result = VK_ERROR_INITIALIZATION_FAILED;
for (int apiVersion : { VK_API_VERSION_1_2, VK_API_VERSION_1_1, VK_API_VERSION_1_0 })
for (uint32_t apiVersion : { VK_API_VERSION_1_2, VK_API_VERSION_1_1, VK_API_VERSION_1_0 })
{
VkApplicationInfo appInfo = {};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
@ -363,8 +363,11 @@ void VulkanDevice::CreateInstance()
result = vkCreateInstance(&createInfo, nullptr, &instance);
if (result >= VK_SUCCESS)
{
ApiVersion = apiVersion;
break;
}
}
CheckVulkanError(result, "Could not create vulkan instance");
volkLoadInstance(instance);

View file

@ -60,6 +60,7 @@ public:
std::vector<const char *> EnabledExtensions;
std::vector<const char *> OptionalExtensions = { VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME };
std::vector<const char*> EnabledValidationLayers;
uint32_t ApiVersion = {};
// Device setup
VkPhysicalDeviceFeatures UsedDeviceFeatures = {};