[vulkan] Switch to full screen triangle instead of quad

While I have trouble imagining it making that much performance
difference going from 4 verts to 3 for a whopping 2 polygons, or even
from 2 triangles to 1 for each poly, using only indices for the vertices
does remove a lot of code, and better yet, some memory and buffer
allocations... always a good thing.

That said, I guess freeing up a GPU thread for something else could make
a difference.
This commit is contained in:
Bill Currie 2022-04-01 19:50:41 +09:00
parent 03c403610d
commit 11e30583cf
9 changed files with 34 additions and 67 deletions

View file

@ -40,8 +40,8 @@ typedef enum {
QFV_passDepth, // geometry
QFV_passTranslucent, // geometry
QFV_passGBuffer, // geometry
QFV_passLighting, // single quad
QFV_passCompose, // single quad
QFV_passLighting, // single triangle
QFV_passCompose, // single triangle
QFV_NumPasses
} QFV_Subpass;

View file

@ -66,9 +66,6 @@ typedef struct vulkan_ctx_s {
struct lightingctx_s *lighting_context;
struct composectx_s *compose_context;
VkBuffer quad_buffer;
VkDeviceMemory quad_memory;
VkCommandPool cmdpool;
VkCommandBuffer cmdbuffer;
VkFence fence; // for ctx->cmdbuffer only

View file

@ -301,6 +301,8 @@ alias_shadow_src = $(vkshaderpath)/alias_shadow.vert
alias_shadow_c = $(vkshaderpath)/alias_shadow.vert.spvc
passthrough_src = $(vkshaderpath)/passthrough.vert
passthrough_c = $(vkshaderpath)/passthrough.vert.spvc
fstriangle_src = $(vkshaderpath)/fstriangle.vert
fstriangle_c = $(vkshaderpath)/fstriangle.vert.spvc
pushcolor_src = $(vkshaderpath)/pushcolor.frag
pushcolor_c = $(vkshaderpath)/pushcolor.frag.spvc
shadow_src = $(vkshaderpath)/shadow.geom
@ -358,6 +360,8 @@ $(alias_shadow_c): $(alias_shadow_src)
$(passthrough_c): $(passthrough_src)
$(fstriangle_c): $(fstriangle_src)
$(pushcolor_c): $(pushcolor_src)
$(shadow_c): $(shadow_src)
@ -391,6 +395,7 @@ vkshader_c = \
$(alias_gbuf_c) \
$(alias_shadow_c) \
$(passthrough_c) \
$(fstriangle_c) \
$(pushcolor_c) \
$(shadow_c)
@ -443,6 +448,7 @@ EXTRA_DIST += \
libs/video/renderer/vulkan/shader/compose.frag \
libs/video/renderer/vulkan/shader/lighting.frag \
libs/video/renderer/vulkan/shader/passthrough.vert \
libs/video/renderer/vulkan/shader/fstriangle.vert \
libs/video/renderer/vulkan/shader/partphysics.comp \
libs/video/renderer/vulkan/shader/partupdate.comp \
libs/video/renderer/vulkan/shader/particle.vert \

View file

@ -559,17 +559,13 @@
};
};
fsquad = {
fstriangle = {
vertexInput = {
bindings = (
{ binding = 0; stride = "4 * 4"; inputRate = vertex; },
);
attributes = (
{ location = 0; binding = 0; format = r32g32b32a32_sfloat; offset = 0; },
);
bindings = ();
attributes = ();
};
inputAssembly = {
topology = triangle_strip;
topology = triangle_list;
primitiveRestartEnable = false;
};
colorBlend = {
@ -1008,7 +1004,7 @@
{
stage = vertex;
name = main;
module = $builtin/passthrough.vert;
module = $builtin/fstriangle.vert;
},
{
stage = fragment;
@ -1022,13 +1018,13 @@
};
},
);
vertexInput = $properties.fsquad.vertexInput;
inputAssembly = $properties.fsquad.inputAssembly;
vertexInput = $properties.fstriangle.vertexInput;
inputAssembly = $properties.fstriangle.inputAssembly;
viewport = $properties.viewport;
rasterization = $properties.rasterization.counter_cw_cull_back;
multisample = $properties.multisample;
depthStencil = $properties.depthStencil.disable;
colorBlend = $properties.fsquad.colorBlend;
colorBlend = $properties.fstriangle.colorBlend;
dynamic = {
dynamicState = ( viewport, scissor );
};
@ -1041,7 +1037,7 @@
{
stage = vertex;
name = main;
module = $builtin/passthrough.vert;
module = $builtin/fstriangle.vert;
},
{
stage = fragment;
@ -1049,13 +1045,13 @@
module = $builtin/compose.frag;
},
);
vertexInput = $properties.fsquad.vertexInput;
inputAssembly = $properties.fsquad.inputAssembly;
vertexInput = $properties.fstriangle.vertexInput;
inputAssembly = $properties.fstriangle.inputAssembly;
viewport = $properties.viewport;
rasterization = $properties.rasterization.counter_cw_cull_back;
multisample = $properties.multisample;
depthStencil = $properties.depthStencil.disable;
colorBlend = $properties.fsquad.colorBlend;
colorBlend = $properties.fstriangle.colorBlend;
dynamic = {
dynamicState = ( viewport, scissor );
};

View file

@ -95,6 +95,8 @@ static
static
#include "libs/video/renderer/vulkan/shader/passthrough.vert.spvc"
static
#include "libs/video/renderer/vulkan/shader/fstriangle.vert.spvc"
static
#include "libs/video/renderer/vulkan/shader/pushcolor.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/shadow.geom.spvc"
@ -134,6 +136,7 @@ static shaderdata_t builtin_shaders[] = {
{ "alias_gbuf.frag", alias_gbuf_frag, sizeof (alias_gbuf_frag) },
{ "alias_shadow.vert", alias_shadow_vert, sizeof (alias_shadow_vert) },
{ "passthrough.vert", passthrough_vert, sizeof (passthrough_vert) },
{ "fstriangle.vert", fstriangle_vert, sizeof (fstriangle_vert) },
{ "pushcolor.frag", pushcolor_frag, sizeof (pushcolor_frag) },
{ "shadow.geom", shadow_geom, sizeof (shadow_geom) },
{}

View file

@ -0,0 +1,9 @@
#version 450
void
main ()
{
float x = (gl_VertexIndex & 2);
float y = (gl_VertexIndex & 1);
gl_Position = vec4 (2, 4, 0, 1) * vec4 (x, y, 0, 1) - vec4 (1, 1, 0, 0);
}

View file

@ -105,9 +105,7 @@ Vulkan_Compose_Draw (qfv_renderframe_t *rFrame)
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
VkDeviceSize offset = 0;
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &ctx->quad_buffer, &offset);
dfunc->vkCmdDraw (cmd, 4, 1, 0, 0);
dfunc->vkCmdDraw (cmd, 3, 1, 0, 0);
QFV_duCmdEndLabel (device, cmd);
dfunc->vkEndCommandBuffer (cmd);

View file

@ -260,9 +260,7 @@ Vulkan_Lighting_Draw (qfv_renderframe_t *rFrame)
dfunc->vkCmdSetViewport (cmd, 0, 1, &ctx->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &ctx->scissor);
VkDeviceSize offset = 0;
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &ctx->quad_buffer, &offset);
dfunc->vkCmdDraw (cmd, 4, 1, 0, 0);
dfunc->vkCmdDraw (cmd, 3, 1, 0, 0);
QFV_duCmdEndLabel (device, cmd);
dfunc->vkEndCommandBuffer (cmd);

View file

@ -446,43 +446,6 @@ Vulkan_CreateRenderPass (vulkan_ctx_t *ctx)
rp->draw = renderpass_draw;
DARRAY_APPEND (&ctx->renderPasses, rp);
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
static float quad_vertices[] = {
-1, -1, 0, 1,
-1, 1, 0, 1,
1, -1, 0, 1,
1, 1, 0, 1,
};
ctx->quad_buffer = QFV_CreateBuffer (device, sizeof (quad_vertices),
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
| VK_BUFFER_USAGE_TRANSFER_DST_BIT);
ctx->quad_memory = QFV_AllocBufferMemory (device, ctx->quad_buffer,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
0, 0);
QFV_BindBufferMemory (device, ctx->quad_buffer, ctx->quad_memory, 0);
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
float *verts = QFV_PacketExtend (packet, sizeof (quad_vertices));
memcpy (verts, quad_vertices, sizeof (quad_vertices));
qfv_bufferbarrier_t bb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
bb.barrier.buffer = ctx->quad_buffer;
bb.barrier.size = sizeof (quad_vertices);
dfunc->vkCmdPipelineBarrier (packet->cmd, bb.srcStages, bb.dstStages,
0, 0, 0, 1, &bb.barrier, 0, 0);
VkBufferCopy copy_region[] = {
{ packet->offset, 0, sizeof (quad_vertices) },
};
dfunc->vkCmdCopyBuffer (packet->cmd, ctx->staging->buffer,
ctx->quad_buffer, 1, &copy_region[0]);
bb = bufferBarriers[qfv_BB_TransferWrite_to_VertexAttrRead];
bb.barrier.buffer = ctx->quad_buffer;
bb.barrier.size = sizeof (quad_vertices);
dfunc->vkCmdPipelineBarrier (packet->cmd, bb.srcStages, bb.dstStages,
0, 0, 0, 1, &bb.barrier, 0, 0);
QFV_PacketSubmit (packet);
}
static void
@ -542,9 +505,6 @@ Vulkan_DestroyRenderPasses (vulkan_ctx_t *ctx)
free (rp);
}
dfunc->vkFreeMemory (device->dev, ctx->quad_memory, 0);
dfunc->vkDestroyBuffer (device->dev, ctx->quad_buffer, 0);
}
VkPipeline