gpu: Require Vulkan 1.2 shaders for dynamic indexing

Shader compilers struggle with compiling code that indexes texture
arrays by indexes, so keep the fallback shaders simple and don't do that
there.

There's not much of a performance difference anyway between those two
methods.
This commit is contained in:
Benjamin Otte
2023-11-06 02:50:25 +01:00
parent d50e235753
commit 719ff9eca9
3 changed files with 35 additions and 18 deletions

View File

@@ -499,7 +499,8 @@ gsk_vulkan_device_setup (GskVulkanDevice *self,
/* These numbers can be improved in the shader sources by adding more
* entries to the big switch() statements */
self->max_immutable_samplers = 8;
if (!gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_DYNAMIC_INDEXING))
if (!gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_DYNAMIC_INDEXING) ||
!gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_NONUNIFORM_INDEXING))
{
self->max_buffers = 8;
self->max_samplers = 8;
@@ -869,7 +870,8 @@ gsk_vulkan_device_get_vk_pipeline (GskVulkanDevice *self,
return pipeline;
display = gsk_gpu_device_get_display (GSK_GPU_DEVICE (self));
if (gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_NONUNIFORM_INDEXING))
if (gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_DYNAMIC_INDEXING) &&
gsk_vulkan_device_has_feature (self, GDK_VULKAN_FEATURE_NONUNIFORM_INDEXING))
version_string = ".1.2";
else
version_string = ".1.0";

View File

@@ -1,4 +1,4 @@
#ifdef HAVE_NONUNIFORM
#ifdef HAVE_VULKAN_1_2
#extension GL_EXT_nonuniform_qualifier : enable
#endif
@@ -68,7 +68,7 @@ gsk_texture (uint id,
else
{
id >>= 1;
#ifdef HAVE_NONUNIFORM
#ifdef HAVE_VULKAN_1_2
return texture (textures[nonuniformEXT (id)], pos);
#else
if (id == 0)
@@ -87,8 +87,6 @@ gsk_texture (uint id,
return texture (textures[6], pos);
else if (GSK_N_SAMPLERS > 7 && id == 7)
return texture (textures[7], pos);
else if (GSK_N_SAMPLERS > 8)
return texture (textures[id], pos);
#endif
}
return vec4 (1.0, 0.0, 0.8, 1.0);
@@ -121,7 +119,7 @@ gsk_texture_size (uint id,
else
{
id >>= 1;
#ifdef HAVE_NONUNIFORM
#ifdef HAVE_VULKAN_1_2
return textureSize (textures[nonuniformEXT (id)], lod);
#else
if (id == 0)
@@ -140,8 +138,6 @@ gsk_texture_size (uint id,
return textureSize (textures[6], lod);
else if (GSK_N_SAMPLERS > 7 && id == 7)
return textureSize (textures[7], lod);
else if (GSK_N_SAMPLERS > 8)
return textureSize (textures[id], lod);
#endif
}
return ivec2 (1, 1);
@@ -175,7 +171,7 @@ gsk_texel_fetch (uint id,
else
{
id >>= 1;
#ifdef HAVE_NONUNIFORM
#ifdef HAVE_VULKAN_1_2
return texelFetch (textures[nonuniformEXT (id)], pos, lod);
#else
if (id == 0)
@@ -194,19 +190,38 @@ gsk_texel_fetch (uint id,
return texelFetch (textures[6], pos, lod);
else if (GSK_N_SAMPLERS > 7 && id == 7)
return texelFetch (textures[7], pos, lod);
else if (GSK_N_SAMPLERS > 8)
return texelFetch (textures[id], pos, lod);
#endif
}
return vec4 (1.0, 0.0, 0.8, 1.0);
}
#ifdef HAVE_NONUNIFORM
#ifdef HAVE_VULKAN_1_2
#define gsk_get_buffer(id) buffers[nonuniformEXT (id)]
#else
#define gsk_get_buffer(id) buffers[id]
#endif
#define gsk_get_float(id) gsk_get_buffer(id >> 22).floats[id & 0x3FFFFF]
#else
float
gsk_get_float (uint id)
{
uint buffer_id = id >> 22;
uint float_id = id & 0x3FFFFF;
if (buffer_id == 0)
return buffers[0].floats[float_id];
else if (GSK_N_BUFFERS > 1 && buffer_id == 1)
return buffers[1].floats[float_id];
else if (GSK_N_BUFFERS > 2 && buffer_id == 2)
return buffers[2].floats[float_id];
else if (GSK_N_BUFFERS > 3 && buffer_id == 3)
return buffers[3].floats[float_id];
else if (GSK_N_BUFFERS > 4 && buffer_id == 4)
return buffers[4].floats[float_id];
else if (GSK_N_BUFFERS > 5 && buffer_id == 5)
return buffers[5].floats[float_id];
else if (GSK_N_BUFFERS > 6 && buffer_id == 6)
return buffers[6].floats[float_id];
else if (GSK_N_BUFFERS > 7 && buffer_id == 7)
return buffers[7].floats[float_id];
}
#endif
#define gsk_get_int(id) (floatBitsToInt(gsk_get_float(id)))
#define gsk_get_uint(id) (floatBitsToUint(gsk_get_float(id)))

View File

@@ -60,14 +60,14 @@ foreach shader: gsk_private_gpu_shaders
[ '--target-env=vulkan1.2',
'-fshader-stage=vertex',
'-DGSK_VERTEX_SHADER=1',
'-DHAVE_NONUNIFORM=1'
'-DHAVE_VULKAN_1_2=1'
]
],
[ fs.name (fs.replace_suffix (shader, '')) + '.1.2.frag.spv',
[ '--target-env=vulkan1.2',
'-fshader-stage=fragment',
'-DGSK_FRAGMENT_SHADER=1',
'-DHAVE_NONUNIFORM=1'
'-DHAVE_VULKAN_1_2=1'
]
],
[ fs.name (fs.replace_suffix (shader, '')) + '.1.0.vert.spv',