From d75072362a77952d391e72f24c75247f2736518f Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sat, 18 Sep 2021 18:08:52 +0200 Subject: [PATCH] vk oit: work around adreno 600 driver regression Android 11 adreno 600 driver v502: PixelBuffer.pixels.length() is returning 0 in some cases. Issue #361 --- core/rend/vulkan/oit/oit_drawer.cpp | 2 ++ core/rend/vulkan/oit/oit_pipeline.h | 1 + core/rend/vulkan/oit/oit_shaders.cpp | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) 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;