diff --git a/core/rend/vulkan/oit/oit_drawer.cpp b/core/rend/vulkan/oit/oit_drawer.cpp index 63f0626d2..29cd5754b 100644 --- a/core/rend/vulkan/oit/oit_drawer.cpp +++ b/core/rend/vulkan/oit/oit_drawer.cpp @@ -262,6 +262,8 @@ bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture) OITDescriptorSets::FragmentShaderUniforms fragUniforms = MakeFragmentUniforms(); fragUniforms.shade_scale_factor = FPU_SHAD_SCALE.scale_factor / 256.f; + // sizeof(Pixel) == 16 + fragUniforms.pixelBufferSize = std::min(config::PixelBufferSize, GetContext()->GetMaxMemoryAllocationSize()) / 16; currentScissor = vk::Rect2D(); diff --git a/core/rend/vulkan/oit/oit_pipeline.h b/core/rend/vulkan/oit/oit_pipeline.h index 92b607ef8..390e53bb3 100644 --- a/core/rend/vulkan/oit/oit_pipeline.h +++ b/core/rend/vulkan/oit/oit_pipeline.h @@ -53,6 +53,7 @@ public: float cp_AlphaTestValue; float sp_FOG_DENSITY; float shade_scale_factor; // new for OIT + u32 pixelBufferSize; }; struct PushConstants diff --git a/core/rend/vulkan/oit/oit_shaders.cpp b/core/rend/vulkan/oit/oit_shaders.cpp index a85eeb2f2..ab69791f7 100644 --- a/core/rend/vulkan/oit/oit_shaders.cpp +++ b/core/rend/vulkan/oit/oit_shaders.cpp @@ -69,6 +69,7 @@ layout (std140, set = 0, binding = 1) uniform FragmentShaderUniforms float cp_AlphaTestValue; float sp_FOG_DENSITY; float shade_scale_factor; + uint pixelBufferSize; } uniformBuffer; layout(set = 3, binding = 2, r32ui) uniform coherent restrict uimage2D abufferPointerImg; @@ -87,7 +88,10 @@ layout (set = 3, binding = 0, std430) coherent restrict buffer PixelBuffer_ { uint getNextPixelIndex() { uint index = atomicAdd(PixelCounter.buffer_index, 1); - if (index >= PixelBuffer.pixels.length()) + // we should be able to simply use PixelBuffer.pixels.length() + // but a regression in the adreno 600 driver (v502) forces us + // to use a uniform. + if (index >= uniformBuffer.pixelBufferSize) // Buffer overflow discard;