[vulkan] Use a swizzle view for coverage-alpha

And thus a single pipeline for either colored glyphs or coverage-alpha
glyphs, making for better batching when I get to that.
This commit is contained in:
Bill Currie 2022-11-20 15:46:16 +09:00
parent 40b319bf42
commit 2828a4ce0c
6 changed files with 25 additions and 54 deletions

View File

@ -277,12 +277,10 @@ vkshaderpath = libs/video/renderer/vulkan/shader
slice_src = $(vkshaderpath)/slice.vert
slice_c = $(vkshaderpath)/slice.vert.spvc
glyph_src = $(vkshaderpath)/glyph.vert
glyph_c = $(vkshaderpath)/glyph.vert.spvc
glyph_color_src = $(vkshaderpath)/glyph_color.frag
glyph_color_c = $(vkshaderpath)/glyph_color.frag.spvc
glyph_coverage_src = $(vkshaderpath)/glyph_coverage.frag
glyph_coverage_c = $(vkshaderpath)/glyph_coverage.frag.spvc
glyphv_src = $(vkshaderpath)/glyph.vert
glyphv_c = $(vkshaderpath)/glyph.vert.spvc
glyphf_src = $(vkshaderpath)/glyph.frag
glyphf_c = $(vkshaderpath)/glyph.frag.spvc
linev_src = $(vkshaderpath)/line.vert
linev_c = $(vkshaderpath)/line.vert.spvc
linef_src = $(vkshaderpath)/line.frag
@ -355,9 +353,8 @@ pushcolor_c = $(vkshaderpath)/pushcolor.frag.spvc
$(slice_vert_c): $(slice_vert_src)
$(glyph_vert_c): $(glyph_vert_src)
$(glyph_color_c): $(glyph_color_src)
$(glyph_coverage_c): $(glyph_coverage_src)
$(glyphv_c): $(glyphv_src)
$(glyphf_c): $(glyphf_src)
$(linev_c): $(linev_src)
$(linef_c): $(linef_src)
@ -424,9 +421,8 @@ $(pushcolor_c): $(pushcolor_src)
vkshader_c = \
$(slice_c) \
$(glyph_c) \
$(glyph_color_c) \
$(glyph_coverage_c) \
$(glyphv_c) \
$(glyphf_c) \
$(linev_c) \
$(linef_c) \
$(partphysicsc_c) \

View File

@ -1151,7 +1151,7 @@
@inherit = $properties.pipelines.trans_base;//FIXME should be sparate
stages = (
{ stage = vertex; name = main; module = $builtin/slice.vert; },
{ stage = fragment; name = main; module = $builtin/glyph_color.frag; },
{ stage = fragment; name = main; module = $builtin/glyph.frag; },
);
vertexInput = $properties.vertexInput.slice;
inputAssembly = {
@ -1168,6 +1168,10 @@
};
glyph = {
@inherit = $properties.pipelines.trans_base;//FIXME should be sparate
stages = (
{ stage = vertex; name = main; module = $builtin/glyph.vert; },
{ stage = fragment; name = main; module = $builtin/glyph.frag; },
);
vertexInput = $properties.vertexInput.glyph;
inputAssembly = {
// glyphs are drawn using instanced quads, so primitive restart
@ -1182,20 +1186,6 @@
};
layout = glyph_layout;
};
glyph_color = {
@inherit = $properties.pipelines.glyph;
stages = (
{ stage = vertex; name = main; module = $builtin/glyph.vert; },
{ stage = fragment; name = main; module = $builtin/glyph_color.frag; },
);
};
glyph_coverage = {
@inherit = $properties.pipelines.glyph;
stages = (
{ stage = vertex; name = main; module = $builtin/glyph.vert; },
{ stage = fragment; name = main; module = $builtin/glyph_coverage.frag; },
);
};
lines = {
@inherit = $properties.pipelines.twod;
stages = (

View File

@ -43,9 +43,7 @@ static
static
#include "libs/video/renderer/vulkan/shader/glyph.vert.spvc"
static
#include "libs/video/renderer/vulkan/shader/glyph_color.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/glyph_coverage.frag.spvc"
#include "libs/video/renderer/vulkan/shader/glyph.frag.spvc"
static
#include "libs/video/renderer/vulkan/shader/line.vert.spvc"
static
@ -124,8 +122,7 @@ typedef struct shaderdata_s {
static shaderdata_t builtin_shaders[] = {
{ "slice.vert", slice_vert, sizeof (slice_vert) },
{ "glyph.vert", glyph_vert, sizeof (glyph_vert) },
{ "glyph_color.frag", glyph_color_frag, sizeof (glyph_color_frag) },
{ "glyph_coverage.frag", glyph_coverage_frag, sizeof (glyph_coverage_frag) },
{ "glyph.frag", glyph_frag, sizeof (glyph_frag) },
{ "line.vert", line_vert, sizeof (line_vert) },
{ "line.frag", line_frag, sizeof (line_frag) },
{ "particle.vert", particle_vert, sizeof (particle_vert) },

View File

@ -1,17 +0,0 @@
#version 450
layout (set = 1, binding = 1) uniform sampler2D Texture;
layout (location = 0) in vec2 uv;
layout (location = 1) in vec4 color;
layout (location = 0) out vec4 frag_color;
void
main (void)
{
vec4 pix;
pix = texture (Texture, uv).rrrr;
frag_color = pix * color;
}

View File

@ -191,7 +191,7 @@ typedef struct drawctx_s {
qfv_resobj_t *line_objects;
VkPipeline quad_pipeline;
VkPipeline slice_pipeline;
VkPipeline glyph_coverage_pipeline;
VkPipeline glyph_pipeline;
VkPipeline line_pipeline;
VkPipelineLayout layout;
VkPipelineLayout glyph_layout;//slice pipeline uses same layout
@ -538,7 +538,7 @@ Vulkan_Draw_Shutdown (vulkan_ctx_t *ctx)
dfunc->vkDestroyPipeline (device->dev, dctx->quad_pipeline, 0);
dfunc->vkDestroyPipeline (device->dev, dctx->slice_pipeline, 0);
dfunc->vkDestroyPipeline (device->dev, dctx->glyph_coverage_pipeline, 0);
dfunc->vkDestroyPipeline (device->dev, dctx->glyph_pipeline, 0);
dfunc->vkDestroyPipeline (device->dev, dctx->line_pipeline, 0);
Hash_DelTable (dctx->pic_cache);
delete_memsuper (dctx->pic_memsuper);
@ -613,8 +613,7 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
dctx->quad_pipeline = Vulkan_CreateGraphicsPipeline (ctx, "twod");
dctx->slice_pipeline = Vulkan_CreateGraphicsPipeline (ctx, "slice");
dctx->glyph_coverage_pipeline
= Vulkan_CreateGraphicsPipeline (ctx, "glyph_coverage");
dctx->glyph_pipeline = Vulkan_CreateGraphicsPipeline (ctx, "glyph");
dctx->line_pipeline = Vulkan_CreateGraphicsPipeline (ctx, "lines");
dctx->layout = Vulkan_CreatePipelineLayout (ctx, "twod_layout");
@ -1226,7 +1225,7 @@ Vulkan_FlushText (qfv_renderframe_t *rFrame)
VkDeviceSize offsets[] = {0};
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &glyph_buffer, offsets);
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
dctx->glyph_coverage_pipeline);
dctx->glyph_pipeline);
dfunc->vkCmdSetViewport (cmd, 0, 1, &rFrame->renderpass->viewport);
dfunc->vkCmdSetScissor (cmd, 0, 1, &rFrame->renderpass->scissor);
@ -1352,6 +1351,12 @@ Vulkan_Draw_AddFont (rfont_t *rfont, vulkan_ctx_t *ctx)
.type = VK_IMAGE_VIEW_TYPE_2D,
.format = font->resource->glyph_image.image.format,
.aspect = VK_IMAGE_ASPECT_COLOR_BIT,
.components = {
.r = VK_COMPONENT_SWIZZLE_R,
.g = VK_COMPONENT_SWIZZLE_R,
.b = VK_COMPONENT_SWIZZLE_R,
.a = VK_COMPONENT_SWIZZLE_R,
},
},
};
__auto_type glyph_iview = &font->resource->glyph_iview;