mirror of
https://github.com/libretro/tyrquake.git
synced 2026-11-07 04:35:58 -10:00
Vulkan: the SW renderer draws into staging, uploads ride the frame
The CPU no longer copies the frame, widens the Z buffer, re-copies skins, or waits for an overlay upload: - Each ring slot's staging is the SW renderer's frame buffer for that frame (vid.buffer, pointed at it in begin_frame), so the 8bpp frame reaches the GPU's copy with no host memcpy. Every pixel is drawn again each frame, so what the slot held two frames ago never shows. Staging prefers HOST_CACHED memory, since the renderer reads back what it draws. - Z likewise: the renderer's 16-bit Z is drawn into the slot's Z staging (D_SetZBuffer re-points d_pzbuffer and its row table), and a small compute pass (zwiden.comp) widens it into the R32 vk_zbuffer on the GPU, in place of the host loop that read 2 and wrote 4 bytes a pixel (12 MiB a frame at 1080p) and the copy after it. - Alias skins stay in a slot's skin pool across frames, as long as their cache block lives (dropped by the cache-invalidate hook), and the pool replaces the least recently drawn skin when full instead of failing; host_colormap stays too. A translated player colormap is still copied each frame it is drawn. - Overlay pic uploads made during a frame are recorded into the slot's own upload command buffer and staging, and submitted ahead of the frame in its submit: no QueueSubmit and fence wait in the middle of Host_Frame, which also drained the frame in flight. The Setup menu's player preview is translated straight into staging, and only when the pic or the colours change, not every frame. Output is unchanged: screenshots of the demos, menus, console and view sizes match the previous build at 320x200 and 1024x768, with compute rendering on and off, and the synchronization validation layer reports nothing. On lavapipe, where the GPU is the CPU, the widen pass costs about 1.5 ms a frame at 1024x768; on a GPU it is a fraction of the host loop it replaces.
This commit is contained in:
1 parent
8141003cdc
commit
cb2a244ef0
6 files changed
+741
-193
No files matched your search
+588
-193
File diff suppressed because it is too large.
Load diff
@@ -137,6 +137,8 @@ void D_DrawSurfaces(void);
|
||||
void D_EndParticles(void);
|
||||
void D_Init(void);
|
||||
void D_ViewChanged(void);
|
||||
/* The Z buffer the span drawers use, and the row table into it */
|
||||
void D_SetZBuffer(short *zbuf);
|
||||
void D_SetupFrame(void);
|
||||
void D_StartParticles(void);
|
||||
void D_TurnZOn(void);
|
||||
|
||||
@@ -47,6 +47,18 @@ D_Patch(void)
|
||||
D_ViewChanged
|
||||
================
|
||||
*/
|
||||
void D_SetZBuffer(short *zbuf)
|
||||
{
|
||||
int i;
|
||||
int rows = vid.height;
|
||||
|
||||
if (rows > MAXHEIGHT)
|
||||
rows = MAXHEIGHT;
|
||||
d_pzbuffer = zbuf;
|
||||
for (i = 0; i < rows; i++)
|
||||
zspantable[i] = d_pzbuffer + i * vid.width;
|
||||
}
|
||||
|
||||
void D_ViewChanged(void)
|
||||
{
|
||||
int rowbytes = vid.rowbytes;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Auto-generated SPIR-V bytecode for the tyrquake Vulkan
|
||||
* backend. Do not edit by hand -- run
|
||||
* tools/shaders_regen.sh to regenerate from the GLSL
|
||||
* source under common/shaders/src/.
|
||||
*
|
||||
* Symbol: spv_zwiden_cs
|
||||
* Word count: 504 (2016 bytes)
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint32_t spv_zwiden_cs[] = {
|
||||
0x07230203, 0x00010000, 0x0008000b, 0x00000070, 0x00000000, 0x00020011, 0x00000001, 0x0006000b,
|
||||
0x00000001, 0x4c534c47, 0x6474732e, 0x3035342e, 0x00000000, 0x0003000e, 0x00000000, 0x00000001,
|
||||
0x0006000f, 0x00000005, 0x00000004, 0x6e69616d, 0x00000000, 0x0000000b, 0x00060010, 0x00000004,
|
||||
0x00000011, 0x00000040, 0x00000001, 0x00000001, 0x00030003, 0x00000002, 0x000001c2, 0x00040005,
|
||||
0x00000004, 0x6e69616d, 0x00000000, 0x00080005, 0x0000000b, 0x475f6c67, 0x61626f6c, 0x766e496c,
|
||||
0x7461636f, 0x496e6f69, 0x00000044, 0x00030005, 0x00000013, 0x00004350, 0x00050006, 0x00000013,
|
||||
0x00000000, 0x74646977, 0x00000068, 0x00050006, 0x00000013, 0x00000001, 0x67696568, 0x00007468,
|
||||
0x00030005, 0x00000015, 0x00006370, 0x00030005, 0x00000032, 0x0036315a, 0x00050006, 0x00000032,
|
||||
0x00000000, 0x64726f77, 0x00000073, 0x00040005, 0x00000034, 0x317a5f75, 0x00000036, 0x00040005,
|
||||
0x0000003c, 0x337a5f75, 0x00000032, 0x00040047, 0x0000000b, 0x0000000b, 0x0000001c, 0x00030047,
|
||||
0x00000013, 0x00000002, 0x00050048, 0x00000013, 0x00000000, 0x00000023, 0x00000000, 0x00050048,
|
||||
0x00000013, 0x00000001, 0x00000023, 0x00000004, 0x00040047, 0x00000031, 0x00000006, 0x00000004,
|
||||
0x00030047, 0x00000032, 0x00000003, 0x00040048, 0x00000032, 0x00000000, 0x00000018, 0x00050048,
|
||||
0x00000032, 0x00000000, 0x00000023, 0x00000000, 0x00030047, 0x00000034, 0x00000018, 0x00040047,
|
||||
0x00000034, 0x00000021, 0x00000000, 0x00040047, 0x00000034, 0x00000022, 0x00000000, 0x00030047,
|
||||
0x0000003c, 0x00000019, 0x00040047, 0x0000003c, 0x00000021, 0x00000001, 0x00040047, 0x0000003c,
|
||||
0x00000022, 0x00000000, 0x00040047, 0x0000006d, 0x0000000b, 0x00000019, 0x00020013, 0x00000002,
|
||||
0x00030021, 0x00000003, 0x00000002, 0x00040015, 0x00000006, 0x00000020, 0x00000000, 0x00040017,
|
||||
0x00000009, 0x00000006, 0x00000003, 0x00040020, 0x0000000a, 0x00000001, 0x00000009, 0x0004003b,
|
||||
0x0000000a, 0x0000000b, 0x00000001, 0x0004002b, 0x00000006, 0x0000000c, 0x00000000, 0x00040020,
|
||||
0x0000000d, 0x00000001, 0x00000006, 0x0004002b, 0x00000006, 0x00000010, 0x00000002, 0x0004001e,
|
||||
0x00000013, 0x00000006, 0x00000006, 0x00040020, 0x00000014, 0x00000009, 0x00000013, 0x0004003b,
|
||||
0x00000014, 0x00000015, 0x00000009, 0x00040015, 0x00000016, 0x00000020, 0x00000001, 0x0004002b,
|
||||
0x00000016, 0x00000017, 0x00000000, 0x00040020, 0x00000018, 0x00000009, 0x00000006, 0x0004002b,
|
||||
0x00000016, 0x0000001b, 0x00000001, 0x00020014, 0x0000001f, 0x0003001d, 0x00000031, 0x00000006,
|
||||
0x0003001e, 0x00000032, 0x00000031, 0x00040020, 0x00000033, 0x00000002, 0x00000032, 0x0004003b,
|
||||
0x00000033, 0x00000034, 0x00000002, 0x00040020, 0x00000037, 0x00000002, 0x00000006, 0x00090019,
|
||||
0x0000003a, 0x00000006, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000021,
|
||||
0x00040020, 0x0000003b, 0x00000000, 0x0000003a, 0x0004003b, 0x0000003b, 0x0000003c, 0x00000000,
|
||||
0x00040017, 0x00000042, 0x00000016, 0x00000002, 0x0004002b, 0x00000006, 0x00000045, 0x0000ffff,
|
||||
0x00040017, 0x00000047, 0x00000006, 0x00000004, 0x0004002b, 0x00000006, 0x0000004a, 0x00000001,
|
||||
0x0004002b, 0x00000016, 0x00000059, 0x00000010, 0x0004002b, 0x00000006, 0x0000006c, 0x00000040,
|
||||
0x0006002c, 0x00000009, 0x0000006d, 0x0000006c, 0x0000004a, 0x0000004a, 0x00050036, 0x00000002,
|
||||
0x00000004, 0x00000000, 0x00000003, 0x000200f8, 0x00000005, 0x000300f7, 0x0000006e, 0x00000000,
|
||||
0x000300fb, 0x0000000c, 0x0000006f, 0x000200f8, 0x0000006f, 0x00050041, 0x0000000d, 0x0000000e,
|
||||
0x0000000b, 0x0000000c, 0x0004003d, 0x00000006, 0x0000000f, 0x0000000e, 0x00050084, 0x00000006,
|
||||
0x00000011, 0x0000000f, 0x00000010, 0x00050041, 0x00000018, 0x00000019, 0x00000015, 0x00000017,
|
||||
0x0004003d, 0x00000006, 0x0000001a, 0x00000019, 0x00050041, 0x00000018, 0x0000001c, 0x00000015,
|
||||
0x0000001b, 0x0004003d, 0x00000006, 0x0000001d, 0x0000001c, 0x00050084, 0x00000006, 0x0000001e,
|
||||
0x0000001a, 0x0000001d, 0x000500ae, 0x0000001f, 0x00000020, 0x00000011, 0x0000001e, 0x000300f7,
|
||||
0x00000022, 0x00000000, 0x000400fa, 0x00000020, 0x00000021, 0x00000022, 0x000200f8, 0x00000021,
|
||||
0x000200f9, 0x0000006e, 0x000200f8, 0x00000022, 0x00050086, 0x00000006, 0x00000028, 0x00000011,
|
||||
0x0000001a, 0x00050084, 0x00000006, 0x0000002e, 0x00000028, 0x0000001a, 0x00050082, 0x00000006,
|
||||
0x0000002f, 0x00000011, 0x0000002e, 0x00060041, 0x00000037, 0x00000038, 0x00000034, 0x00000017,
|
||||
0x0000000f, 0x0004003d, 0x00000006, 0x00000039, 0x00000038, 0x0004003d, 0x0000003a, 0x0000003d,
|
||||
0x0000003c, 0x0004007c, 0x00000016, 0x0000003f, 0x0000002f, 0x0004007c, 0x00000016, 0x00000041,
|
||||
0x00000028, 0x00050050, 0x00000042, 0x00000043, 0x0000003f, 0x00000041, 0x000500c7, 0x00000006,
|
||||
0x00000046, 0x00000039, 0x00000045, 0x00070050, 0x00000047, 0x00000048, 0x00000046, 0x0000000c,
|
||||
0x0000000c, 0x0000000c, 0x00040063, 0x0000003d, 0x00000043, 0x00000048, 0x00050080, 0x00000006,
|
||||
0x0000004b, 0x0000002f, 0x0000004a, 0x000500b0, 0x0000001f, 0x0000004e, 0x0000004b, 0x0000001a,
|
||||
0x000300f7, 0x00000050, 0x00000000, 0x000400fa, 0x0000004e, 0x0000004f, 0x0000005c, 0x000200f8,
|
||||
0x0000004f, 0x0004003d, 0x0000003a, 0x00000051, 0x0000003c, 0x0004007c, 0x00000016, 0x00000054,
|
||||
0x0000004b, 0x00050050, 0x00000042, 0x00000057, 0x00000054, 0x00000041, 0x000500c2, 0x00000006,
|
||||
0x0000005a, 0x00000039, 0x00000059, 0x00070050, 0x00000047, 0x0000005b, 0x0000005a, 0x0000000c,
|
||||
0x0000000c, 0x0000000c, 0x00040063, 0x00000051, 0x00000057, 0x0000005b, 0x000200f9, 0x00000050,
|
||||
0x000200f8, 0x0000005c, 0x00050080, 0x00000006, 0x0000005e, 0x00000028, 0x0000004a, 0x000500b0,
|
||||
0x0000001f, 0x00000061, 0x0000005e, 0x0000001d, 0x000300f7, 0x00000063, 0x00000000, 0x000400fa,
|
||||
0x00000061, 0x00000062, 0x00000063, 0x000200f8, 0x00000062, 0x0004003d, 0x0000003a, 0x00000064,
|
||||
0x0000003c, 0x0004007c, 0x00000016, 0x00000067, 0x0000005e, 0x00050050, 0x00000042, 0x00000068,
|
||||
0x00000017, 0x00000067, 0x000500c2, 0x00000006, 0x0000006a, 0x00000039, 0x00000059, 0x00070050,
|
||||
0x00000047, 0x0000006b, 0x0000006a, 0x0000000c, 0x0000000c, 0x0000000c, 0x00040063, 0x00000064,
|
||||
0x00000068, 0x0000006b, 0x000200f9, 0x00000063, 0x000200f8, 0x00000063, 0x000200f9, 0x00000050,
|
||||
0x000200f8, 0x00000050, 0x000200f9, 0x0000006e, 0x000200f8, 0x0000006e, 0x000100fd, 0x00010038,
|
||||
};
|
||||
|
||||
static const size_t spv_zwiden_cs_size = sizeof(spv_zwiden_cs);
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Widens the SW renderer's 16-bit Z buffer into the R32_UINT
|
||||
* vk_zbuffer the GPU 3D passes test and atomically update.
|
||||
*
|
||||
* The SW renderer draws its Z straight into a host-visible
|
||||
* buffer (the frame ring slot's vk_particles_zstaging), so the
|
||||
* host never copies or widens it: this pass reads it a word -
|
||||
* two pixels, low half first (little-endian shorts) - per
|
||||
* invocation and stores each as a zero-extended uint. izi is
|
||||
* never negative, so zero extension keeps the value. Two
|
||||
* pixels to an invocation, as the buffer holds them: half the
|
||||
* invocations of one per pixel, which software Vulkan
|
||||
* (lavapipe) runs measurably faster.
|
||||
*
|
||||
* set 0, binding 0: readonly buffer u_z16 (width*height shorts)
|
||||
* set 0, binding 1: writeonly uimage2D u_z32 (r32ui, width x height)
|
||||
* push constants: width, height
|
||||
*
|
||||
* Dispatch: ceil(width * height / 2 / 64) x 1 x 1.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
* Copyright (C) 2026 The libretro team
|
||||
*/
|
||||
|
||||
#version 450
|
||||
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
layout(set = 0, binding = 0, std430) readonly buffer Z16 {
|
||||
uint words[];
|
||||
} u_z16;
|
||||
|
||||
layout(set = 0, binding = 1, r32ui) uniform writeonly uimage2D u_z32;
|
||||
|
||||
layout(push_constant) uniform PC {
|
||||
uint width;
|
||||
uint height;
|
||||
} pc;
|
||||
|
||||
void main()
|
||||
{
|
||||
uint i = gl_GlobalInvocationID.x * 2u; /* the word's first pixel */
|
||||
uint x, y, w;
|
||||
|
||||
if (i >= pc.width * pc.height)
|
||||
return;
|
||||
|
||||
y = i / pc.width;
|
||||
x = i - y * pc.width;
|
||||
w = u_z16.words[gl_GlobalInvocationID.x];
|
||||
imageStore(u_z32, ivec2(x, y), uvec4(w & 0xffffu, 0u, 0u, 0u));
|
||||
/* The second pixel: next in the row, or the next row's first
|
||||
* when the width is odd */
|
||||
if (x + 1u < pc.width)
|
||||
imageStore(u_z32, ivec2(x + 1u, y), uvec4(w >> 16, 0u, 0u, 0u));
|
||||
else if (y + 1u < pc.height)
|
||||
imageStore(u_z32, ivec2(0, y + 1u), uvec4(w >> 16, 0u, 0u, 0u));
|
||||
}
|
||||
@@ -106,5 +106,6 @@ regen_shader comp sprite cs
|
||||
regen_shader comp alias cs
|
||||
regen_shader comp sky cs
|
||||
regen_shader comp turb cs
|
||||
regen_shader comp zwiden cs
|
||||
|
||||
echo "done."
|
||||
Reference in new issue
Block a user