From 9b609469edab80cb3b3778c4f57786950e6630ca Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 2 Dec 2022 12:46:45 +0900 Subject: [PATCH] [vulkan] Prevent particle update buffers escaping the staging buffer The escape was actually harmless as the buffers would not be read due to the particle count being 0 (thus why the buffers were at the end of the staging buffer: no space was allocated for them, only for the system buffer, but their offsets were just past the system buffer). However, the validation layers quite rightly did not like that. Thus, the two buffers are pointed to the system buffer so all three descriptors are always valid. --- libs/video/renderer/vulkan/vulkan_particles.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/video/renderer/vulkan/vulkan_particles.c b/libs/video/renderer/vulkan/vulkan_particles.c index e624577cb..5ccdcfe3d 100644 --- a/libs/video/renderer/vulkan/vulkan_particles.c +++ b/libs/video/renderer/vulkan/vulkan_particles.c @@ -406,8 +406,17 @@ particles_update (qfv_renderframe_t *rFrame) qfv_parameters_t *params = (qfv_parameters_t *)((byte *)system + paramoffs); memcpy (params, pctx->psystem->partparams, paramsize); - partsize = max (1, partsize); - paramsize = max (1, paramsize); + if (!numParticles) { + // if there are no particles, then no space for the particle states or + // parameters has been allocated in the staging buffer, so map the + // two buffers over the system buffer. This avoids either buffer being + // just past the end of the staging buffer (which the validation layers + // (correctly) do not like). + // This is fine because the two buffers are only read by the the + // compute shader. + partsize = paramsize = syssize; + partoffs = paramoffs = 0; + } size_t sysoffs = packet->offset; VkDescriptorBufferInfo bufferInfo[] = {