From c41cfa30dc0495f00b2a05038698d4e483b6f3ec Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Wed, 28 Oct 2026 06:54:34 +0100 Subject: [PATCH] Vulkan: write the translucent polygon parameters straight into the buffer The per-pixel renderer writes each translucent polygon's two words where the shaders read them, instead of into a vector made each render and copied after. --- core/rend/vulkan/oit/oit_drawer.cpp | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/core/rend/vulkan/oit/oit_drawer.cpp b/core/rend/vulkan/oit/oit_drawer.cpp index ca087a2b..45c149d1 100644 --- a/core/rend/vulkan/oit/oit_drawer.cpp +++ b/core/rend/vulkan/oit/oit_drawer.cpp @@ -334,26 +334,28 @@ void OITDrawer::UploadMainBuffer(const OITDescriptorSets::FragmentShaderUniforms chunks.push_back(nullptr); chunkSizes.push_back(padding); - std::vector trPolyParams(pvrrc.gpu ? 0 : pvrrc.global_param_tr.used() * 2); - if (pvrrc.gpu || pvrrc.global_param_tr.used() == 0) - trPolyParams.push_back(0); // makes the validation layers happy - else - { - const PolyParam *pp_end = pvrrc.global_param_tr.LastPtr(0); - const PolyParam *pp = pvrrc.global_param_tr.head(); - for (int i = 0; pp != pp_end; i += 2, pp++) - { - trPolyParams[i] = (pp->tsp.full & 0xffff00c0) | ((pp->isp.full >> 16) & 0xe400) | ((pp->pcw.full >> 7) & 1); - trPolyParams[i + 1] = pp->tsp1.full; - } - } - offsets.polyParamsSize = trPolyParams.size() * 4; - chunks.push_back(trPolyParams.data()); + /* (written below, straight into the buffer: two words a translucent + * polygon, or the one the validation layers want when there is none) */ + const u32 trPolys = pvrrc.gpu ? 0 : (u32)pvrrc.global_param_tr.used(); + offsets.polyParamsSize = (trPolys != 0 ? trPolys * 2 : 1) * 4; + chunks.push_back(nullptr); chunkSizes.push_back(offsets.polyParamsSize); u32 totalSize = offsets.polyParamsOffset + offsets.polyParamsSize; BufferData *buffer = GetMainBuffer(totalSize); buffer->upload(chunks.size(), &chunkSizes[0], &chunks[0]); + u32 *trPolyParams = (u32 *)((u8 *)buffer->MapMemory() + offsets.polyParamsOffset); + if (trPolys == 0) + trPolyParams[0] = 0; + else + { + const PolyParam *pp = pvrrc.global_param_tr.head(); + for (u32 i = 0; i < trPolys; i++, pp++) + { + trPolyParams[i * 2] = (pp->tsp.full & 0xffff00c0) | ((pp->isp.full >> 16) & 0xe400) | ((pp->pcw.full >> 7) & 1); + trPolyParams[i * 2 + 1] = pp->tsp1.full; + } + } } bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)