From a0c935e8bc4d85b6a4a3e4dcf2a2d22bab95f5dd Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 6 Dec 2021 14:21:10 +0900 Subject: [PATCH] [vulkan] Make lighting samplers configurable My VersaPro doesn't support more than 32 per-stage samplers (lavapipe). This is a small part of getting Vulkan to run on lavapipe and even in itself is rather incomplete. --- libs/video/renderer/vulkan/qfpipeline.plist | 16 ++++++++++++++-- libs/video/renderer/vulkan/shader/lighting.frag | 4 ++-- libs/video/renderer/vulkan/vulkan_lighting.c | 4 +++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libs/video/renderer/vulkan/qfpipeline.plist b/libs/video/renderer/vulkan/qfpipeline.plist index 3bbbb7b46..c4b8433b2 100644 --- a/libs/video/renderer/vulkan/qfpipeline.plist +++ b/libs/video/renderer/vulkan/qfpipeline.plist @@ -1,4 +1,10 @@ { + limits = { + //FIXME this really needs to be an external variable as the C code + //needs to agree on the size, so it might as well set maxSamplers + //directly (and any other such variable) + maxSamplers = "min (256u, $physDevLimits.maxPerStageDescriptorSamplers)"; + }; samplers = { quakepic = { magFilter = nearest; @@ -120,7 +126,7 @@ bindings = ( { type = combined_image_sampler; - descriptorCount = "$frames.size * 256z"; + descriptorCount = "$frames.size * size_t($properties.limits.maxSamplers)"; }, ); }; @@ -308,7 +314,7 @@ { binding = 0; descriptorType = combined_image_sampler; - descriptorCount = 256; + descriptorCount = $properties.limits.maxSamplers; stageFlags = fragment; }, ); @@ -903,6 +909,12 @@ stage = fragment; name = main; module = $builtin/lighting.frag; + specializationInfo = { + mapEntries = ( + { size = 4; offset = 0; constantID = 0; }, + ); + data = "array($properties.limits.maxSamplers)"; + }; }, ); vertexInput = $properties.fsquad.vertexInput; diff --git a/libs/video/renderer/vulkan/shader/lighting.frag b/libs/video/renderer/vulkan/shader/lighting.frag index 4f53c412c..9c8009d43 100644 --- a/libs/video/renderer/vulkan/shader/lighting.frag +++ b/libs/video/renderer/vulkan/shader/lighting.frag @@ -14,8 +14,6 @@ struct LightData { vec3 direction; float cone; }; -//XXX can't include :( be sure to keep up to date with qf_lighting.h -#define MaxLights 256 #define StyleMask 0x07f #define ModelMask 0x380 @@ -33,6 +31,8 @@ struct LightData { #define ST_CASCADE (2 << 10) // cascaded shadow maps #define ST_CUBE (3 << 10) // cubemap (omni, large spotlight) +layout (constant_id = 0) const int MaxLights = 256; + layout (set = 2, binding = 0) uniform sampler2DArrayShadow shadowCascade[MaxLights]; layout (set = 2, binding = 0) uniform sampler2DShadow shadowPlane[MaxLights]; layout (set = 2, binding = 0) uniform samplerCubeShadow shadowCube[MaxLights]; diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index 754ba242a..b3edfb640 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -416,7 +416,9 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx) lframe->shadowWrite = base_image_write; lframe->shadowWrite.dstSet = shadow_set->a[i]; lframe->shadowWrite.dstBinding = 0; - lframe->shadowWrite.descriptorCount = MaxLights; + lframe->shadowWrite.descriptorCount + = min (MaxLights, + device->physDev->properties.limits.maxPerStageDescriptorSamplers); lframe->shadowWrite.pImageInfo = lframe->shadowInfo; } free (attach_set);