mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-29 15:41:59 +00:00
[vulkan] Get line rendering working again
Rather important for debugging 2d stuff (draw's lines are 2d-only). Other than translucent console, this gets the vulkan draw api back to full operation.
This commit is contained in:
parent
b91a76cbcc
commit
cdc5f8a912
3 changed files with 36 additions and 42 deletions
|
@ -566,10 +566,6 @@
|
||||||
topology = line_list;
|
topology = line_list;
|
||||||
primitiveRestartEnable = false;
|
primitiveRestartEnable = false;
|
||||||
};
|
};
|
||||||
twod = {
|
|
||||||
topology = triangle_strip;
|
|
||||||
primitiveRestartEnable = true;
|
|
||||||
};
|
|
||||||
sprite = {
|
sprite = {
|
||||||
topology = triangle_strip;
|
topology = triangle_strip;
|
||||||
primitiveRestartEnable = true;
|
primitiveRestartEnable = true;
|
||||||
|
@ -666,14 +662,13 @@
|
||||||
{ location = 3; binding = 0; format = r32g32b32a32_sfloat; offset = 48; },
|
{ location = 3; binding = 0; format = r32g32b32a32_sfloat; offset = 48; },
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
twod = {
|
lines = {
|
||||||
bindings = (
|
bindings = (
|
||||||
{ binding = 0; stride = "2 * 4 * 4"; inputRate = vertex; },
|
{ binding = 0; stride = "2 * 4 + 4"; inputRate = vertex; },
|
||||||
);
|
);
|
||||||
attributes = (
|
attributes = (
|
||||||
{ location = 0; binding = 0; format = r32g32_sfloat; offset = 0; },
|
{ location = 0; binding = 0; format = r32g32_sfloat; offset = 0; },
|
||||||
{ location = 1; binding = 0; format = r32g32_sfloat; offset = 8; },
|
{ location = 1; binding = 0; format = r8g8b8a8_unorm; offset = 8; },
|
||||||
{ location = 2; binding = 0; format = r32g32b32a32_sfloat; offset = 16; },
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -1135,8 +1130,6 @@
|
||||||
inputAssembly = $properties.inputAssembly.sprite;
|
inputAssembly = $properties.inputAssembly.sprite;
|
||||||
layout = sprite_layout;
|
layout = sprite_layout;
|
||||||
};
|
};
|
||||||
twod = {
|
|
||||||
};
|
|
||||||
slice = {
|
slice = {
|
||||||
@inherit = $properties.pipelines.trans_base;
|
@inherit = $properties.pipelines.trans_base;
|
||||||
renderPass = output;
|
renderPass = output;
|
||||||
|
@ -1166,7 +1159,7 @@
|
||||||
{ stage = vertex; name = main; module = $builtin/line.vert; },
|
{ stage = vertex; name = main; module = $builtin/line.vert; },
|
||||||
{ stage = fragment; name = main; module = $builtin/line.frag; },
|
{ stage = fragment; name = main; module = $builtin/line.frag; },
|
||||||
);
|
);
|
||||||
vertexInput = $properties.vertexInput.twod;
|
vertexInput = $properties.vertexInput.lines;
|
||||||
rasterization = $properties.rasterization.counter_cw_cull_back;
|
rasterization = $properties.rasterization.counter_cw_cull_back;
|
||||||
depthStencil = $properties.depthStencil.disable;
|
depthStencil = $properties.depthStencil.disable;
|
||||||
colorBlend = {
|
colorBlend = {
|
||||||
|
|
|
@ -5,8 +5,7 @@ layout (set = 0, binding = 0) uniform
|
||||||
#include "matrices.h"
|
#include "matrices.h"
|
||||||
;
|
;
|
||||||
layout (location = 0) in vec2 vertex;
|
layout (location = 0) in vec2 vertex;
|
||||||
layout (location = 1) in vec2 uv;
|
layout (location = 1) in vec4 vcolor;
|
||||||
layout (location = 2) in vec4 vcolor;
|
|
||||||
|
|
||||||
layout (location = 0) out vec4 color;
|
layout (location = 0) out vec4 color;
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,6 @@ typedef struct descbatchset_s
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float xy[2];
|
float xy[2];
|
||||||
float st[2];
|
|
||||||
byte color[4];
|
byte color[4];
|
||||||
} linevert_t;
|
} linevert_t;
|
||||||
|
|
||||||
|
@ -113,11 +112,11 @@ typedef struct {
|
||||||
float uv[2];
|
float uv[2];
|
||||||
} quadvert_t;
|
} quadvert_t;
|
||||||
|
|
||||||
typedef struct vertqueue_s {
|
typedef struct linequeue_s {
|
||||||
linevert_t *verts;
|
linevert_t *verts;
|
||||||
int count;
|
int count;
|
||||||
int size;
|
int size;
|
||||||
} vertqueue_t;
|
} linequeue_t;
|
||||||
|
|
||||||
typedef struct quadqueue_s {
|
typedef struct quadqueue_s {
|
||||||
quadinst_t *quads;
|
quadinst_t *quads;
|
||||||
|
@ -146,16 +145,18 @@ typedef struct descpool_s {
|
||||||
|
|
||||||
typedef struct drawframe_s {
|
typedef struct drawframe_s {
|
||||||
size_t instance_offset;
|
size_t instance_offset;
|
||||||
|
size_t dvert_offset;
|
||||||
size_t line_offset;
|
size_t line_offset;
|
||||||
VkBuffer instance_buffer;
|
VkBuffer instance_buffer;
|
||||||
VkBuffer dvert_buffer;
|
VkBuffer dvert_buffer;
|
||||||
|
VkBuffer line_buffer;
|
||||||
VkBufferView dvert_view;
|
VkBufferView dvert_view;
|
||||||
|
|
||||||
uint32_t dvertex_index;
|
uint32_t dvertex_index;
|
||||||
uint32_t dvertex_max;
|
uint32_t dvertex_max;
|
||||||
descbatchset_t quad_batch;
|
descbatchset_t quad_batch;
|
||||||
quadqueue_t quad_insts;
|
quadqueue_t quad_insts;
|
||||||
vertqueue_t line_verts;
|
linequeue_t line_verts;
|
||||||
qfv_cmdbufferset_t cmdSet;
|
qfv_cmdbufferset_t cmdSet;
|
||||||
descpool_t dyn_descs;
|
descpool_t dyn_descs;
|
||||||
} drawframe_t;
|
} drawframe_t;
|
||||||
|
@ -202,6 +203,7 @@ typedef struct drawctx_s {
|
||||||
qfv_resobj_t *svertex_objects;
|
qfv_resobj_t *svertex_objects;
|
||||||
qfv_resobj_t *instance_objects;
|
qfv_resobj_t *instance_objects;
|
||||||
qfv_resobj_t *dvertex_objects;
|
qfv_resobj_t *dvertex_objects;
|
||||||
|
qfv_resobj_t *lvertex_objects;
|
||||||
uint32_t svertex_index;
|
uint32_t svertex_index;
|
||||||
uint32_t svertex_max;
|
uint32_t svertex_max;
|
||||||
VkPipeline quad_pipeline;
|
VkPipeline quad_pipeline;
|
||||||
|
@ -229,8 +231,6 @@ typedef struct drawctx_s {
|
||||||
#define VERTS_PER_LINE (2)
|
#define VERTS_PER_LINE (2)
|
||||||
#define BYTES_PER_LINE (VERTS_PER_LINE * sizeof (linevert_t))
|
#define BYTES_PER_LINE (VERTS_PER_LINE * sizeof (linevert_t))
|
||||||
|
|
||||||
#define DVERTS_PER_FRAME (LINES_OFFSET + MAX_LINES*VERTS_PER_LINE)
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_dyn_descriptor (descpool_t *pool, qpic_t *pic, VkBufferView buffer_view,
|
get_dyn_descriptor (descpool_t *pool, qpic_t *pic, VkBufferView buffer_view,
|
||||||
vulkan_ctx_t *ctx)
|
vulkan_ctx_t *ctx)
|
||||||
|
@ -302,12 +302,15 @@ create_buffers (vulkan_ctx_t *ctx)
|
||||||
+ 2 * sizeof (qfv_resobj_t)
|
+ 2 * sizeof (qfv_resobj_t)
|
||||||
// frames dynamic vertex buffers and views
|
// frames dynamic vertex buffers and views
|
||||||
+ (frames) * 2 * sizeof (qfv_resobj_t)
|
+ (frames) * 2 * sizeof (qfv_resobj_t)
|
||||||
|
// frames line vertex buffers
|
||||||
|
+ (frames) * sizeof (qfv_resobj_t)
|
||||||
// frames instance buffers
|
// frames instance buffers
|
||||||
+ (frames) * sizeof (qfv_resobj_t));
|
+ (frames) * sizeof (qfv_resobj_t));
|
||||||
dctx->index_object = (qfv_resobj_t *) &dctx->draw_resource[2];
|
dctx->index_object = (qfv_resobj_t *) &dctx->draw_resource[2];
|
||||||
dctx->svertex_objects = &dctx->index_object[1];
|
dctx->svertex_objects = &dctx->index_object[1];
|
||||||
dctx->dvertex_objects = &dctx->svertex_objects[2];
|
dctx->dvertex_objects = &dctx->svertex_objects[2];
|
||||||
dctx->instance_objects = &dctx->dvertex_objects[2 * frames];
|
dctx->lvertex_objects = &dctx->dvertex_objects[2 * frames];
|
||||||
|
dctx->instance_objects = &dctx->lvertex_objects[frames];
|
||||||
|
|
||||||
dctx->svertex_index = 0;
|
dctx->svertex_index = 0;
|
||||||
dctx->svertex_max = MAX_QUADS * VERTS_PER_QUAD;
|
dctx->svertex_max = MAX_QUADS * VERTS_PER_QUAD;
|
||||||
|
@ -323,7 +326,7 @@ create_buffers (vulkan_ctx_t *ctx)
|
||||||
.name = "draw",
|
.name = "draw",
|
||||||
.va_ctx = ctx->va_ctx,
|
.va_ctx = ctx->va_ctx,
|
||||||
.memory_properties = VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
|
.memory_properties = VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
|
||||||
.num_objects = (2 * frames) + (frames),
|
.num_objects = (2 * frames) + (frames) + (frames),
|
||||||
.objects = dctx->dvertex_objects,
|
.objects = dctx->dvertex_objects,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -377,6 +380,15 @@ create_buffers (vulkan_ctx_t *ctx)
|
||||||
.size = dctx->dvertex_objects[i * 2 + 0].buffer.size,
|
.size = dctx->dvertex_objects[i * 2 + 0].buffer.size,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
dctx->lvertex_objects[i] = (qfv_resobj_t) {
|
||||||
|
.name = "line",
|
||||||
|
.type = qfv_res_buffer,
|
||||||
|
.buffer = {
|
||||||
|
.size = MAX_LINES * BYTES_PER_LINE,
|
||||||
|
.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
||||||
|
| VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
|
||||||
|
},
|
||||||
|
};
|
||||||
dctx->instance_objects[i] = (qfv_resobj_t) {
|
dctx->instance_objects[i] = (qfv_resobj_t) {
|
||||||
.name = "inst",
|
.name = "inst",
|
||||||
.type = qfv_res_buffer,
|
.type = qfv_res_buffer,
|
||||||
|
@ -400,7 +412,8 @@ create_buffers (vulkan_ctx_t *ctx)
|
||||||
frame->instance_offset = dctx->instance_objects[f].buffer.offset;
|
frame->instance_offset = dctx->instance_objects[f].buffer.offset;
|
||||||
frame->dvert_buffer = dctx->dvertex_objects[f * 2 + 0].buffer.buffer;
|
frame->dvert_buffer = dctx->dvertex_objects[f * 2 + 0].buffer.buffer;
|
||||||
frame->dvert_view = dctx->dvertex_objects[f * 2 + 1].buffer_view.view;
|
frame->dvert_view = dctx->dvertex_objects[f * 2 + 1].buffer_view.view;
|
||||||
frame->line_offset = dctx->dvertex_objects[f * 2].buffer.offset;
|
frame->line_buffer = dctx->lvertex_objects[f].buffer.buffer;
|
||||||
|
frame->line_offset = dctx->lvertex_objects[f].buffer.offset;
|
||||||
|
|
||||||
frame->dvertex_index = 0;
|
frame->dvertex_index = 0;
|
||||||
frame->dvertex_max = MAX_QUADS * VERTS_PER_QUAD;
|
frame->dvertex_max = MAX_QUADS * VERTS_PER_QUAD;
|
||||||
|
@ -411,7 +424,7 @@ create_buffers (vulkan_ctx_t *ctx)
|
||||||
.size = MAX_INSTANCES,
|
.size = MAX_INSTANCES,
|
||||||
};
|
};
|
||||||
|
|
||||||
frame->line_verts = (vertqueue_t) {
|
frame->line_verts = (linequeue_t) {
|
||||||
.verts = (linevert_t *) ((byte *)data + frame->line_offset),
|
.verts = (linevert_t *) ((byte *)data + frame->line_offset),
|
||||||
.size = MAX_INSTANCES,
|
.size = MAX_INSTANCES,
|
||||||
};
|
};
|
||||||
|
@ -1359,32 +1372,19 @@ Vulkan_Draw_Line (int x0, int y0, int x1, int y1, int c, vulkan_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
drawctx_t *dctx = ctx->draw_context;
|
drawctx_t *dctx = ctx->draw_context;
|
||||||
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
drawframe_t *frame = &dctx->frames.a[ctx->curFrame];
|
||||||
vertqueue_t *queue = &frame->line_verts;
|
linequeue_t *queue = &frame->line_verts;
|
||||||
|
|
||||||
if (queue->count >= queue->size) {
|
if (queue->count >= queue->size) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
__auto_type pd = (picdata_t *) dctx->white_pic->data;
|
|
||||||
int srcx = pd->subpic->rect->x;
|
|
||||||
int srcy = pd->subpic->rect->y;
|
|
||||||
int srcw = pd->subpic->rect->width;
|
|
||||||
int srch = pd->subpic->rect->height;
|
|
||||||
float size = pd->subpic->size;
|
|
||||||
float sl = (srcx + 0.03125) * size;
|
|
||||||
float sr = (srcx + srcw - 0.03125) * size;
|
|
||||||
float st = (srcy + 0.03125) * size;
|
|
||||||
float sb = (srcy + srch - 0.03125) * size;
|
|
||||||
|
|
||||||
linevert_t *verts = queue->verts + queue->count * VERTS_PER_LINE;
|
linevert_t *verts = queue->verts + queue->count * VERTS_PER_LINE;
|
||||||
verts[0] = (linevert_t) {
|
verts[0] = (linevert_t) {
|
||||||
.xy = { x0, y0 },
|
.xy = { x0, y0 },
|
||||||
.st = {sl, st},
|
|
||||||
.color = { VectorExpand (vid.palette + c * 3), 255 },
|
.color = { VectorExpand (vid.palette + c * 3), 255 },
|
||||||
};
|
};
|
||||||
verts[1] = (linevert_t) {
|
verts[1] = (linevert_t) {
|
||||||
.xy = { x1, y1 },
|
.xy = { x1, y1 },
|
||||||
.st = {sr, sb},
|
|
||||||
.color = { VectorExpand (vid.palette + c * 3), 255 },
|
.color = { VectorExpand (vid.palette + c * 3), 255 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1497,7 +1497,7 @@ draw_quads (qfv_renderframe_t *rFrame, VkCommandBuffer cmd)
|
||||||
}
|
}
|
||||||
DARRAY_RESIZE (&dframe->quad_batch, 0);
|
DARRAY_RESIZE (&dframe->quad_batch, 0);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
static void
|
static void
|
||||||
draw_lines (qfv_renderframe_t *rFrame, VkCommandBuffer cmd)
|
draw_lines (qfv_renderframe_t *rFrame, VkCommandBuffer cmd)
|
||||||
{
|
{
|
||||||
|
@ -1519,7 +1519,7 @@ draw_lines (qfv_renderframe_t *rFrame, VkCommandBuffer cmd)
|
||||||
dfunc->vkCmdDraw (cmd, dframe->line_verts.count * VERTS_PER_LINE,
|
dfunc->vkCmdDraw (cmd, dframe->line_verts.count * VERTS_PER_LINE,
|
||||||
1, 0, 0);
|
1, 0, 0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
void
|
void
|
||||||
Vulkan_FlushText (qfv_renderframe_t *rFrame)
|
Vulkan_FlushText (qfv_renderframe_t *rFrame)
|
||||||
{
|
{
|
||||||
|
@ -1543,9 +1543,12 @@ Vulkan_FlushText (qfv_renderframe_t *rFrame)
|
||||||
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
||||||
memory, dframe->instance_offset,
|
memory, dframe->instance_offset,
|
||||||
a(dframe->quad_insts.count * BYTES_PER_QUAD) },
|
a(dframe->quad_insts.count * BYTES_PER_QUAD) },
|
||||||
|
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
||||||
|
memory, dframe->dvert_offset,
|
||||||
|
a(dframe->dvertex_index * sizeof (quadvert_t)) },
|
||||||
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
{ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
||||||
memory, dframe->line_offset,
|
memory, dframe->line_offset,
|
||||||
a(dframe->line_verts.count * VERTS_PER_LINE * sizeof (linevert_t)) },
|
a(dframe->line_verts.count * BYTES_PER_LINE) },
|
||||||
};
|
};
|
||||||
#undef a
|
#undef a
|
||||||
dfunc->vkFlushMappedMemoryRanges (device->dev, 2, ranges);
|
dfunc->vkFlushMappedMemoryRanges (device->dev, 2, ranges);
|
||||||
|
@ -1560,13 +1563,12 @@ Vulkan_FlushText (qfv_renderframe_t *rFrame)
|
||||||
dframe->cmdSet.a[QFV_draw2d]);
|
dframe->cmdSet.a[QFV_draw2d]);
|
||||||
draw_quads (rFrame, dframe->cmdSet.a[QFV_draw2d]);
|
draw_quads (rFrame, dframe->cmdSet.a[QFV_draw2d]);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
if (dframe->line_verts.count) {
|
if (dframe->line_verts.count) {
|
||||||
bind_pipeline (rFrame, dctx->line_pipeline,
|
bind_pipeline (rFrame, dctx->line_pipeline,
|
||||||
dframe->cmdSet.a[QFV_draw2d]);
|
dframe->cmdSet.a[QFV_draw2d]);
|
||||||
draw_lines (rFrame, dframe->cmdSet.a[QFV_draw2d]);
|
draw_lines (rFrame, dframe->cmdSet.a[QFV_draw2d]);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
draw_end_subpass (dframe->cmdSet.a[QFV_draw2d], ctx);
|
draw_end_subpass (dframe->cmdSet.a[QFV_draw2d], ctx);
|
||||||
|
|
||||||
dframe->quad_insts.count = 0;
|
dframe->quad_insts.count = 0;
|
||||||
|
|
Loading…
Reference in a new issue