mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
[vulkan] Get the 2D pipeline up and running
First pixels! This was a nightmare of little issues that the validation layers couldn't help with: incorrect input assembly, incorrect vertex attribute specs. Though the layers did help with getting the queues working. Still, lots of work to go but this is a major breakthrough as I now have access to visual debugging for textures and the like.
This commit is contained in:
parent
8f6f32981c
commit
bb4ca7683e
8 changed files with 343 additions and 53 deletions
|
@ -166,6 +166,14 @@ DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdNextSubpass)
|
|||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdEndRenderPass)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdBindPipeline)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdClearColorImage)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdExecuteCommands)
|
||||
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdSetViewport)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdSetScissor)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdBindVertexBuffers)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdBindIndexBuffer)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdBindDescriptorSets)
|
||||
DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdDrawIndexed)
|
||||
|
||||
#undef DEVICE_LEVEL_VULKAN_FUNCTION
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
struct vulkan_ctx_s;
|
||||
|
||||
void Vulkan_Draw_Init (struct vulkan_ctx_s *ctx);
|
||||
void Vulkan_Draw_Shutdown (struct vulkan_ctx_s *ctx);
|
||||
void Vulkan_Draw_Character (int x, int y, unsigned ch,
|
||||
struct vulkan_ctx_s *ctx);
|
||||
void Vulkan_Draw_String (int x, int y, const char *str,
|
||||
|
|
|
@ -21,6 +21,8 @@ typedef struct vulkan_framebuffer_s {
|
|||
VkSemaphore renderDoneSemaphore;
|
||||
VkCommandBuffer cmdBuffer;
|
||||
|
||||
struct qfv_cmdbufferset_s *subCommand;
|
||||
|
||||
VkDescriptorSet twodDescriptors;
|
||||
} vulkan_framebuffer_t;
|
||||
|
||||
|
|
|
@ -59,9 +59,6 @@ static vulkan_ctx_t *vulkan_ctx;
|
|||
static void
|
||||
vulkan_R_Init (void)
|
||||
{
|
||||
qfv_device_t *device = vulkan_ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
|
||||
Vulkan_CreateStagingBuffers (vulkan_ctx);
|
||||
Vulkan_CreateMatrices (vulkan_ctx);
|
||||
Vulkan_CreateSwapchain (vulkan_ctx);
|
||||
|
@ -72,41 +69,18 @@ vulkan_R_Init (void)
|
|||
vulkan_ctx->pipeline = Vulkan_CreatePipeline (vulkan_ctx, "pipeline");
|
||||
Vulkan_Draw_Init (vulkan_ctx);
|
||||
|
||||
qfv_swapchain_t *sc = vulkan_ctx->swapchain;
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo
|
||||
= { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
|
||||
VkClearValue clearValues[3] = {
|
||||
{ { {0.7294, 0.8549, 0.3333, 1.0} } },
|
||||
{ { {1.0, 0.0} } },
|
||||
{ { {0, 0, 0, 0} } },
|
||||
};
|
||||
VkRenderPassBeginInfo renderPassInfo = {
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, 0,
|
||||
vulkan_ctx->renderpass.renderpass, 0,
|
||||
{ {0, 0}, sc->extent },
|
||||
2, clearValues + 2
|
||||
};
|
||||
for (size_t i = 0; i < vulkan_ctx->framebuffers.size; i++) {
|
||||
__auto_type framebuffer = &vulkan_ctx->framebuffers.a[i];
|
||||
dfunc->vkBeginCommandBuffer (framebuffer->cmdBuffer, &beginInfo);
|
||||
renderPassInfo.framebuffer = framebuffer->framebuffer;
|
||||
dfunc->vkCmdBeginRenderPass (framebuffer->cmdBuffer, &renderPassInfo,
|
||||
VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
dfunc->vkCmdEndRenderPass (framebuffer->cmdBuffer);
|
||||
dfunc->vkEndCommandBuffer (framebuffer->cmdBuffer);
|
||||
}
|
||||
Sys_Printf ("R_Init %p %d", vulkan_ctx->swapchain->swapchain,
|
||||
vulkan_ctx->swapchain->numImages);
|
||||
for (int32_t i = 0; i < vulkan_ctx->swapchain->numImages; i++) {
|
||||
Sys_Printf (" %p", vulkan_ctx->swapchain->images->a[i]);
|
||||
}
|
||||
Sys_Printf ("\n");
|
||||
|
||||
SCR_Init ();
|
||||
}
|
||||
|
||||
static void
|
||||
vulkan_R_RenderFrame (void (*f)(void), void (**g)(void))
|
||||
vulkan_R_RenderFrame (SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
|
||||
{
|
||||
static int count = 0;
|
||||
static double startTime;
|
||||
|
@ -116,6 +90,12 @@ vulkan_R_RenderFrame (void (*f)(void), void (**g)(void))
|
|||
VkDevice dev = device->dev;
|
||||
qfv_queue_t *queue = &vulkan_ctx->device->queue;
|
||||
|
||||
scr_3dfunc ();
|
||||
while (*scr_funcs) {
|
||||
(*scr_funcs) ();
|
||||
scr_funcs++;
|
||||
}
|
||||
|
||||
__auto_type framebuffer
|
||||
= &vulkan_ctx->framebuffers.a[vulkan_ctx->curFrame];
|
||||
|
||||
|
@ -124,6 +104,34 @@ vulkan_R_RenderFrame (void (*f)(void), void (**g)(void))
|
|||
framebuffer->imageAvailableSemaphore,
|
||||
0, &imageIndex);
|
||||
|
||||
Vulkan_FlushText (vulkan_ctx);
|
||||
|
||||
qfv_swapchain_t *sc = vulkan_ctx->swapchain;
|
||||
VkCommandBufferBeginInfo beginInfo
|
||||
= { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
|
||||
VkClearValue clearValues[2] = {
|
||||
{ { {0.0, 0.0, 0.0, 1.0} } },
|
||||
{ { {1.0, 0.0} } },
|
||||
};
|
||||
VkRenderPassBeginInfo renderPassInfo = {
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, 0,
|
||||
vulkan_ctx->renderpass.renderpass, 0,
|
||||
{ {0, 0}, sc->extent },
|
||||
2, clearValues
|
||||
};
|
||||
|
||||
dfunc->vkBeginCommandBuffer (framebuffer->cmdBuffer, &beginInfo);
|
||||
renderPassInfo.framebuffer = framebuffer->framebuffer;
|
||||
dfunc->vkCmdBeginRenderPass (framebuffer->cmdBuffer, &renderPassInfo,
|
||||
VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
|
||||
|
||||
dfunc->vkCmdExecuteCommands (framebuffer->cmdBuffer,
|
||||
framebuffer->subCommand->size,
|
||||
framebuffer->subCommand->a);
|
||||
|
||||
dfunc->vkCmdEndRenderPass (framebuffer->cmdBuffer);
|
||||
dfunc->vkEndCommandBuffer (framebuffer->cmdBuffer);
|
||||
|
||||
VkPipelineStageFlags waitStage
|
||||
= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
VkSubmitInfo submitInfo = {
|
||||
|
@ -425,6 +433,7 @@ vulkan_vid_render_shutdown (void)
|
|||
QFV_DeviceWaitIdle (device);
|
||||
df->vkDestroyFence (dev, vulkan_ctx->fence, 0);
|
||||
df->vkDestroyCommandPool (dev, vulkan_ctx->cmdpool, 0);
|
||||
Vulkan_Draw_Shutdown (vulkan_ctx);
|
||||
Vulkan_Shutdown_Common (vulkan_ctx);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
compareEnable = 0;//FIXME false!!!
|
||||
compareOp = always;
|
||||
minLod = 0;
|
||||
maxLod = 0.25f;
|
||||
maxLod = 0;
|
||||
borderColor = float_transparent_black;
|
||||
unnormalizedCoordinates = 1;//FIXME true!!!
|
||||
};
|
||||
|
@ -113,20 +113,26 @@
|
|||
{
|
||||
location = 0;
|
||||
binding = 0;
|
||||
format = r32g32b32a32_sfloat;
|
||||
format = r32g32_sfloat;
|
||||
offset = 0;
|
||||
},
|
||||
{
|
||||
location = 1;
|
||||
binding = 0;
|
||||
format = r32g32_sint;
|
||||
offset = 8;
|
||||
},
|
||||
{
|
||||
location = 2;
|
||||
binding = 0;
|
||||
format = r32g32b32a32_sfloat;
|
||||
offset = 4;
|
||||
offset = 16;
|
||||
},
|
||||
);
|
||||
};
|
||||
inputAssembly = {
|
||||
topology = triangle_list;
|
||||
primitiveRestartEnable = 0;
|
||||
topology = triangle_strip;
|
||||
primitiveRestartEnable = 1;
|
||||
};
|
||||
viewport = {
|
||||
viewports = (
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
layout (set = 0, binding = 0) uniform Matrices {
|
||||
mat4 Projection;
|
||||
mat4 View;
|
||||
mat4 Model;
|
||||
};
|
||||
/** Vertex position.
|
||||
|
||||
|
@ -12,8 +10,9 @@ layout (set = 0, binding = 0) uniform Matrices {
|
|||
\a vertex provides the onscreen location at which to draw the icon
|
||||
(\a x, \a y) and texture coordinate for the icon (\a s=z, \a t=w).
|
||||
*/
|
||||
layout (location = 0) in vec4 vertex;
|
||||
layout (location = 1) in vec4 vcolor;
|
||||
layout (location = 0) in vec2 vertex;
|
||||
layout (location = 1) in ivec2 uv;
|
||||
layout (location = 2) in vec4 vcolor;
|
||||
|
||||
layout (location = 0) out vec2 st;
|
||||
layout (location = 1) out vec4 color;
|
||||
|
@ -22,6 +21,6 @@ void
|
|||
main (void)
|
||||
{
|
||||
gl_Position = Projection * vec4 (vertex.xy, 0.0, 1.0);
|
||||
st = vertex.zw;
|
||||
st = vec2(uv);
|
||||
color = vcolor;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@
|
|||
#include "QF/Vulkan/qf_draw.h"
|
||||
#include "QF/Vulkan/qf_vid.h"
|
||||
#include "QF/Vulkan/barrier.h"
|
||||
#include "QF/Vulkan/buffer.h"
|
||||
#include "QF/Vulkan/command.h"
|
||||
#include "QF/Vulkan/descriptor.h"
|
||||
#include "QF/Vulkan/device.h"
|
||||
#include "QF/Vulkan/image.h"
|
||||
|
@ -62,13 +64,86 @@
|
|||
#include "vid_vulkan.h"
|
||||
#include "vkparse.h"
|
||||
|
||||
typedef struct {
|
||||
float xy[2];
|
||||
int st[2];
|
||||
float color[4];
|
||||
} drawvert_t;
|
||||
|
||||
#define MAX_QUADS (65536)
|
||||
#define VERTS_PER_QUAD (4)
|
||||
#define INDS_PER_QUAD (5) // one per vert plus primitive reset
|
||||
|
||||
//FIXME move into a context struct
|
||||
VkImage conchars_image;
|
||||
VkDeviceMemory conchars_memory;
|
||||
VkImageView conchars_view;
|
||||
VkSampler conchars_sampler;
|
||||
|
||||
VkPipeline twod;
|
||||
VkBuffer quad_vert_buffer;
|
||||
VkBuffer quad_ind_buffer;
|
||||
VkDeviceMemory quad_memory;
|
||||
drawvert_t *quad_verts;
|
||||
uint32_t *quad_inds;
|
||||
uint32_t num_quads;
|
||||
|
||||
VkPipeline twod_pipeline;
|
||||
VkPipelineLayout twod_layout;
|
||||
size_t draw_cmdBuffer;
|
||||
|
||||
static void
|
||||
create_quad_buffers (vulkan_ctx_t *ctx)
|
||||
{
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
|
||||
//FIXME quad_inds can be a completely separate buffer that is
|
||||
//pre-initialized to draw 2-tri triangle strips as the actual indices will
|
||||
//never change
|
||||
size_t vert_size = MAX_QUADS * VERTS_PER_QUAD * sizeof (drawvert_t);
|
||||
size_t ind_size = MAX_QUADS * INDS_PER_QUAD * sizeof (uint32_t);
|
||||
|
||||
quad_vert_buffer = QFV_CreateBuffer (device, vert_size,
|
||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
|
||||
quad_ind_buffer = QFV_CreateBuffer (device, ind_size,
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
|
||||
quad_memory = QFV_AllocBufferMemory (device, quad_vert_buffer,
|
||||
VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
|
||||
vert_size + ind_size, 0);
|
||||
QFV_BindBufferMemory (device, quad_vert_buffer, quad_memory, 0);
|
||||
QFV_BindBufferMemory (device, quad_ind_buffer, quad_memory, vert_size);
|
||||
void *data;
|
||||
dfunc->vkMapMemory (device->dev, quad_memory, 0, vert_size + ind_size,
|
||||
0, &data);
|
||||
quad_verts = data;
|
||||
quad_inds = (uint32_t *) (quad_verts + MAX_QUADS * VERTS_PER_QUAD);
|
||||
// pre-initialize quad_inds as the indices will never change
|
||||
uint32_t *ind = quad_inds;
|
||||
for (int i = 0; i < MAX_QUADS; i++) {
|
||||
for (int j = 0; j < VERTS_PER_QUAD; j++) {
|
||||
*ind++ = i * VERTS_PER_QUAD + j;
|
||||
}
|
||||
// mark end of primitive
|
||||
*ind++ = -1;
|
||||
}
|
||||
VkMappedMemoryRange range = {
|
||||
VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
||||
quad_memory, vert_size, ind_size,
|
||||
};
|
||||
dfunc->vkFlushMappedMemoryRanges (device->dev, 1, &range);
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_quad_buffers (vulkan_ctx_t *ctx)
|
||||
{
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
|
||||
dfunc->vkUnmapMemory (device->dev, quad_memory);
|
||||
dfunc->vkFreeMemory (device->dev, quad_memory, 0);
|
||||
dfunc->vkDestroyBuffer (device->dev, quad_vert_buffer, 0);
|
||||
dfunc->vkDestroyBuffer (device->dev, quad_ind_buffer, 0);
|
||||
}
|
||||
|
||||
static qpic_t *
|
||||
pic_data (const char *name, int w, int h, const byte *data)
|
||||
|
@ -117,14 +192,15 @@ Vulkan_Draw_TextBox (int x, int y, int width, int lines, byte alpha,
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
Vulkan_Draw_Shutdown (void *data)
|
||||
void
|
||||
Vulkan_Draw_Shutdown (vulkan_ctx_t *ctx)
|
||||
{
|
||||
vulkan_ctx_t *ctx = data;
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
|
||||
dfunc->vkDestroyPipeline (device->dev, twod, 0);
|
||||
destroy_quad_buffers (ctx);
|
||||
|
||||
dfunc->vkDestroyPipeline (device->dev, twod_pipeline, 0);
|
||||
dfunc->vkDestroyImageView (device->dev, conchars_view, 0);
|
||||
dfunc->vkFreeMemory (device->dev, conchars_memory, 0);
|
||||
dfunc->vkDestroyImage (device->dev, conchars_image, 0);
|
||||
|
@ -133,12 +209,12 @@ Vulkan_Draw_Shutdown (void *data)
|
|||
void
|
||||
Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
||||
{
|
||||
Sys_RegisterShutdown (Vulkan_Draw_Shutdown, ctx);
|
||||
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
VkCommandBuffer cmd = ctx->cmdbuffer;
|
||||
|
||||
create_quad_buffers (ctx);
|
||||
|
||||
qpic_t *charspic = Draw_Font8x8Pic ();
|
||||
VkExtent3D extent = { charspic->width, charspic->height, 1 };
|
||||
conchars_image = QFV_CreateImage (device, 0, VK_IMAGE_TYPE_2D,
|
||||
|
@ -156,7 +232,9 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
|||
VK_IMAGE_VIEW_TYPE_2D,
|
||||
VK_FORMAT_A1R5G5B5_UNORM_PACK16,
|
||||
VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
conchars_sampler = Hash_Find (ctx->samplers, "quakepic");
|
||||
handleref_t *h;
|
||||
h = Hash_Find (ctx->samplers, "quakepic");
|
||||
conchars_sampler = (VkSampler) h->handle;
|
||||
|
||||
uint16_t *chars_data = ctx->staging[0]->data;
|
||||
size_t size = charspic->width * charspic->height;
|
||||
|
@ -164,9 +242,9 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
|||
// convert 0xff = transparent, 0xfe = white to 0x0000 and 0xffff
|
||||
// for a1r5g5b5
|
||||
uint16_t pix = (charspic->data[i] & 1) - 1;
|
||||
chars_data[i] = ~pix;
|
||||
chars_data[i] = pix;
|
||||
}
|
||||
QFV_FlushStagingBuffer (ctx->staging[0], 0, size);
|
||||
QFV_FlushStagingBuffer (ctx->staging[0], 0, size * sizeof (uint16_t));
|
||||
VkImageMemoryBarrier barrier;
|
||||
qfv_pipelinestagepair_t stages;
|
||||
dfunc->vkWaitForFences (device->dev, 1, &ctx->fence, VK_TRUE, ~0ull);
|
||||
|
@ -214,9 +292,11 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
|||
dfunc->vkResetFences (device->dev, 1, &ctx->fence);
|
||||
dfunc->vkQueueSubmit (device->queue.queue, 1, &submitInfo, ctx->fence);
|
||||
|
||||
twod = Vulkan_CreatePipeline (ctx, "twod");
|
||||
twod_pipeline = Vulkan_CreatePipeline (ctx, "twod");
|
||||
|
||||
h = Hash_Find (ctx->pipelineLayouts, "twod");
|
||||
twod_layout = (VkPipelineLayout) h->handle;
|
||||
|
||||
handleref_t *h;
|
||||
__auto_type layouts = QFV_AllocDescriptorSetLayoutSet (ctx->framebuffers.size, alloca);
|
||||
for (size_t i = 0; i < layouts->size; i++) {
|
||||
h = Hash_Find (ctx->setLayouts, "twod");
|
||||
|
@ -224,31 +304,167 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
|||
}
|
||||
h = Hash_Find (ctx->descriptorPools, "twod");
|
||||
__auto_type pool = (VkDescriptorPool) h->handle;
|
||||
|
||||
VkDescriptorBufferInfo bufferInfo = {
|
||||
ctx->matrices.buffer_2d, 0, VK_WHOLE_SIZE
|
||||
};
|
||||
VkDescriptorImageInfo imageInfo = {
|
||||
conchars_sampler,
|
||||
conchars_view,
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
};
|
||||
__auto_type cmdBuffers
|
||||
= QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1,
|
||||
ctx->framebuffers.size);
|
||||
|
||||
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
|
||||
for (size_t i = 0; i < ctx->framebuffers.size; i++) {
|
||||
ctx->framebuffers.a[i].twodDescriptors = sets->a[i];
|
||||
__auto_type frame = &ctx->framebuffers.a[i];
|
||||
frame->twodDescriptors = sets->a[i];
|
||||
|
||||
VkWriteDescriptorSet write[] = {
|
||||
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0,
|
||||
frame->twodDescriptors, 0, 0, 1,
|
||||
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
0, &bufferInfo, 0 },
|
||||
{ VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, 0,
|
||||
frame->twodDescriptors, 1, 0, 1,
|
||||
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
||||
&imageInfo, 0, 0 },
|
||||
};
|
||||
dfunc->vkUpdateDescriptorSets (device->dev, 2, write, 0, 0);
|
||||
draw_cmdBuffer = frame->subCommand->size;
|
||||
DARRAY_APPEND (frame->subCommand, cmdBuffers->a[i]);
|
||||
}
|
||||
free (sets);
|
||||
free (cmdBuffers);
|
||||
}
|
||||
|
||||
static inline void
|
||||
draw_pic (float x, float y, int w, int h, qpic_t *pic,
|
||||
int srcx, int srcy, int srcw, int srch,
|
||||
float *color)
|
||||
{
|
||||
if (num_quads + VERTS_PER_QUAD > MAX_QUADS) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawvert_t *verts = quad_verts + num_quads * VERTS_PER_QUAD;
|
||||
num_quads += VERTS_PER_QUAD;
|
||||
|
||||
float sl = (srcx);
|
||||
float sr = (srcx + srcw);
|
||||
float st = (srcy);
|
||||
float sb = (srcy + srch);
|
||||
|
||||
verts[0].xy[0] = x;
|
||||
verts[0].xy[1] = y;
|
||||
verts[0].st[0] = sl;
|
||||
verts[0].st[1] = st;
|
||||
QuatCopy (color, verts[0].color);
|
||||
|
||||
verts[1].xy[0] = x;
|
||||
verts[1].xy[1] = y + h;
|
||||
verts[1].st[0] = sl;
|
||||
verts[1].st[1] = sb;
|
||||
QuatCopy (color, verts[1].color);
|
||||
|
||||
verts[2].xy[0] = x + w;
|
||||
verts[2].xy[1] = y;
|
||||
verts[2].st[0] = sr;
|
||||
verts[2].st[1] = st;
|
||||
QuatCopy (color, verts[2].color);
|
||||
|
||||
verts[3].xy[0] = x + w;
|
||||
verts[3].xy[1] = y + h;
|
||||
verts[3].st[0] = sr;
|
||||
verts[3].st[1] = sb;
|
||||
QuatCopy (color, verts[3].color);
|
||||
}
|
||||
|
||||
static inline void
|
||||
queue_character (int x, int y, byte chr, vulkan_ctx_t *ctx)
|
||||
{
|
||||
quat_t color = {1, 1, 1, 1};
|
||||
int cx, cy;
|
||||
cx = chr % 16;
|
||||
cy = chr / 16;
|
||||
|
||||
draw_pic (x, y, 8, 8, 0/*FIXME*/, cx * 8, cy * 8, 8, 8, color);
|
||||
}
|
||||
|
||||
void
|
||||
Vulkan_Draw_Character (int x, int y, unsigned int chr, vulkan_ctx_t *ctx)
|
||||
{
|
||||
if (chr == ' ') {
|
||||
return;
|
||||
}
|
||||
if (y <= -8 || y >= vid.conheight) {
|
||||
return;
|
||||
}
|
||||
if (x <= -8 || x >= vid.conwidth) {
|
||||
return;
|
||||
}
|
||||
queue_character (x, y, chr, ctx);
|
||||
}
|
||||
|
||||
void
|
||||
Vulkan_Draw_String (int x, int y, const char *str, vulkan_ctx_t *ctx)
|
||||
{
|
||||
byte chr;
|
||||
|
||||
if (!str || !str[0]) {
|
||||
return;
|
||||
}
|
||||
if (y <= -8 || y >= vid.conheight) {
|
||||
return;
|
||||
}
|
||||
while (*str) {
|
||||
if ((chr = *str++) != ' ' && x >= -8 && x < vid.conwidth) {
|
||||
queue_character (x, y, chr, ctx);
|
||||
}
|
||||
x += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Vulkan_Draw_nString (int x, int y, const char *str, int count,
|
||||
vulkan_ctx_t *ctx)
|
||||
{
|
||||
byte chr;
|
||||
|
||||
if (!str || !str[0]) {
|
||||
return;
|
||||
}
|
||||
if (y <= -8 || y >= vid.conheight) {
|
||||
return;
|
||||
}
|
||||
while (count-- > 0 && *str) {
|
||||
if ((chr = *str++) != ' ' && x >= -8 && x < vid.conwidth) {
|
||||
queue_character (x, y, chr, ctx);
|
||||
}
|
||||
x += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Vulkan_Draw_AltString (int x, int y, const char *str, vulkan_ctx_t *ctx)
|
||||
{
|
||||
byte chr;
|
||||
|
||||
if (!str || !str[0]) {
|
||||
return;
|
||||
}
|
||||
if (y <= -8 || y >= vid.conheight) {
|
||||
return;
|
||||
}
|
||||
while (*str) {
|
||||
if ((chr = *str++ | 0x80) != (' ' | 0x80)
|
||||
&& x >= -8 && x < vid.conwidth) {
|
||||
queue_character (x, y, chr, ctx);
|
||||
}
|
||||
x += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -321,6 +537,50 @@ Vulkan_DrawReset (vulkan_ctx_t *ctx)
|
|||
void
|
||||
Vulkan_FlushText (vulkan_ctx_t *ctx)
|
||||
{
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
__auto_type frame = &ctx->framebuffers.a[ctx->curFrame];
|
||||
VkCommandBuffer cmd = frame->subCommand->a[draw_cmdBuffer];
|
||||
|
||||
VkMappedMemoryRange range = {
|
||||
VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, 0,
|
||||
quad_memory, 0, num_quads * VERTS_PER_QUAD * sizeof (drawvert_t),
|
||||
};
|
||||
dfunc->vkFlushMappedMemoryRanges (device->dev, 1, &range);
|
||||
|
||||
dfunc->vkResetCommandBuffer (cmd, 0);
|
||||
VkCommandBufferInheritanceInfo inherit = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
|
||||
ctx->renderpass.renderpass, 0,
|
||||
frame->framebuffer,
|
||||
0, 0, 0
|
||||
};
|
||||
VkCommandBufferBeginInfo beginInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 0,
|
||||
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
|
||||
| VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, &inherit,
|
||||
};
|
||||
dfunc->vkBeginCommandBuffer (cmd, &beginInfo);
|
||||
|
||||
dfunc->vkCmdBindPipeline (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
twod_pipeline);
|
||||
VkViewport viewport = {0, 0, vid.width, vid.height, 0, 1};
|
||||
VkRect2D scissor = { {0, 0}, {vid.width, vid.height} };
|
||||
dfunc->vkCmdSetViewport (cmd, 0, 1, &viewport);
|
||||
dfunc->vkCmdSetScissor (cmd, 0, 1, &scissor);
|
||||
VkDeviceSize offsets[] = {0};
|
||||
dfunc->vkCmdBindVertexBuffers (cmd, 0, 1, &quad_vert_buffer, offsets);
|
||||
dfunc->vkCmdBindIndexBuffer (cmd, quad_ind_buffer, 0,
|
||||
VK_INDEX_TYPE_UINT32);
|
||||
VkDescriptorSet set = frame->twodDescriptors;
|
||||
VkPipelineLayout layout = twod_layout;
|
||||
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
layout, 0, 1, &set, 0, 0);
|
||||
dfunc->vkCmdDrawIndexed (cmd, num_quads * INDS_PER_QUAD, 1, 0, 0, 0);
|
||||
|
||||
dfunc->vkEndCommandBuffer (cmd);
|
||||
|
||||
num_quads = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
Common Vulkan video driver functions
|
||||
|
||||
Copyright (C) 1996-1997 Id Software, Inc.
|
||||
Copyright (C) 2019 Bill Currie <bill@taniwha.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
|
@ -54,6 +53,7 @@
|
|||
#include "QF/vid.h"
|
||||
#include "QF/Vulkan/qf_vid.h"
|
||||
#include "QF/Vulkan/barrier.h"
|
||||
#include "QF/Vulkan/buffer.h"
|
||||
#include "QF/Vulkan/descriptor.h"
|
||||
#include "QF/Vulkan/device.h"
|
||||
#include "QF/Vulkan/command.h"
|
||||
|
@ -127,6 +127,7 @@ Vulkan_Init_Cvars (void)
|
|||
msaaSamples = Cvar_Get ("msaaSamples", "VK_SAMPLE_COUNT_1_BIT",
|
||||
CVAR_NONE, msaaSamples_f,
|
||||
"desired MSAA sample size.");
|
||||
R_Init_Cvars ();
|
||||
}
|
||||
|
||||
static const char *instance_extensions[] = {
|
||||
|
@ -415,7 +416,11 @@ Vulkan_CreateFramebuffers (vulkan_ctx_t *ctx)
|
|||
frame->imageAvailableSemaphore = QFV_CreateSemaphore (device);
|
||||
frame->renderDoneSemaphore = QFV_CreateSemaphore (device);
|
||||
frame->cmdBuffer = cmdBuffers->a[i];
|
||||
|
||||
frame->subCommand = malloc (sizeof (qfv_cmdbufferset_t));
|
||||
DARRAY_INIT (frame->subCommand, 4);
|
||||
}
|
||||
free (cmdBuffers);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue