vk: slightly refactor s/2d/overlay/

This commit is contained in:
Ivan 'provod' Avdeev 2022-05-30 13:04:19 -07:00 committed by Ivan Avdeev
parent b0f1b60f62
commit 09112bedef
7 changed files with 64 additions and 70 deletions

View File

@ -2,7 +2,7 @@
#include "vk_common.h"
#include "vk_textures.h"
#include "vk_2d.h"
#include "vk_overlay.h"
#include "vk_renderstate.h"
#include "vk_staging.h"
#include "vk_framectl.h"
@ -111,6 +111,10 @@ VkBool32 VKAPI_PTR debugCallback(
if (Q_strcmp(pCallbackData->pMessageIdName, "VUID-vkMapMemory-memory-00683") == 0)
return VK_FALSE;
/* if (messageSeverity != VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { */
/* gEngine.Con_Printf(S_WARN "Validation: %s\n", pCallbackData->pMessage); */
/* } */
// TODO better messages, not only errors, what are other arguments for, ...
if (messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) {
gEngine.Con_Printf(S_ERROR "Validation: %s\n", pCallbackData->pMessage);
@ -747,7 +751,7 @@ qboolean R_VkInit( void )
// All below need render_pass
if (!initVk2d())
if (!R_VkOverlay_Init())
return false;
if (!VK_BrushInit())
@ -776,7 +780,7 @@ void R_VkShutdown( void ) {
VK_BrushShutdown();
VK_StudioShutdown();
deinitVk2d();
R_VkOverlay_Shutdown();
VK_RenderShutdown();

View File

@ -1,6 +1,6 @@
#include "vk_framectl.h"
#include "vk_2d.h"
#include "vk_overlay.h"
#include "vk_scene.h"
#include "vk_render.h"
#include "vk_rtx.h"
@ -148,7 +148,7 @@ static void waitForFrameFence( void ) {
loop = false;
break;
case VK_TIMEOUT:
gEngine.Con_Printf(S_ERROR "Waitinf for frame fence to be signaled timed out after 10 seconds. Wat\n");
gEngine.Con_Printf(S_ERROR "Waiting for frame fence to be signaled timed out after 10 seconds. Wat\n");
break;
default:
XVK_CHECK(fence_result);
@ -285,7 +285,7 @@ static void enqueueRendering( VkCommandBuffer cmdbuf ) {
if (!g_frame.rtx_enabled)
VK_RenderEnd( cmdbuf );
vk2dEnd( cmdbuf );
R_VkOverlay_DrawAndFlip( cmdbuf );
vkCmdEndRenderPass(cmdbuf);

View File

@ -1,4 +1,4 @@
#include "vk_2d.h"
#include "vk_overlay.h"
#include "vk_buffer.h"
#include "vk_core.h"
@ -12,15 +12,6 @@
#include "com_strings.h"
#include "eiface.h"
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
void R_DrawTileClear( int texnum, int x, int y, int w, int h )
{
gEngine.Con_Printf(S_WARN "VK FIXME: %s\n", __FUNCTION__);
}
typedef struct vertex_2d_s {
float x, y;
@ -95,7 +86,7 @@ static vertex_2d_t* allocQuadVerts(int blending_mode, int texnum) {
void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum )
{
vertex_2d_t *p = allocQuadVerts(vk_renderstate.blending_mode, texnum);
vertex_2d_t *const p = allocQuadVerts(vk_renderstate.blending_mode, texnum);
if (!p) {
/* gEngine.Con_Printf(S_ERROR "VK FIXME %s(%f, %f, %f, %f, %f, %f, %f, %f, %d(%s))\n", __FUNCTION__, */
@ -133,18 +124,7 @@ static void drawFill( float x, float y, float w, float h, int r, int g, int b, i
vk_renderstate.blending_mode = prev_blending;
}
void CL_FillRGBA( float x, float y, float w, float h, int r, int g, int b, int a )
{
drawFill(x, y, w, h, r, g, b, a, kRenderTransAdd);
}
void CL_FillRGBABlend( float x, float y, float w, float h, int r, int g, int b, int a )
{
drawFill(x, y, w, h, r, g, b, a, kRenderTransColor);
}
static void clear( void )
{
static void clearAccumulated( void ) {
R_DEBuffer_Flip(&g2d.pics_buffer_alloc);
g2d.batch_count = 1;
@ -154,32 +134,6 @@ static void clear( void )
g2d.exhausted_this_frame = false;
}
void vk2dEnd( VkCommandBuffer cmdbuf )
{
DEBUG_BEGIN(cmdbuf, "2d overlay");
{
const VkDeviceSize offset = 0;
vkCmdBindVertexBuffers(cmdbuf, 0, 1, &g2d.pics_buffer.buffer, &offset);
}
for (int i = 0; i < g2d.batch_count && g2d.batch[i].vertex_count > 0; ++i)
{
vk_texture_t *texture = findTexture(g2d.batch[i].texture);
const VkPipeline pipeline = g2d.pipelines[g2d.batch[i].blending_mode];
if (texture->vk.descriptor)
{
vkCmdBindPipeline(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, g2d.pipeline_layout, 0, 1, &texture->vk.descriptor, 0, NULL);
vkCmdDraw(cmdbuf, g2d.batch[i].vertex_count, 1, g2d.batch[i].vertex_offset, 0);
} // FIXME else what?
}
DEBUG_END(cmdbuf);
clear();
}
static qboolean createPipelines( void )
{
{
@ -276,8 +230,7 @@ static qboolean createPipelines( void )
return true;
}
qboolean initVk2d( void )
{
qboolean R_VkOverlay_Init( void ) {
if (!createPipelines())
return false;
@ -291,11 +244,55 @@ qboolean initVk2d( void )
return true;
}
void deinitVk2d( void )
{
void R_VkOverlay_Shutdown( void ) {
VK_BufferDestroy(&g2d.pics_buffer);
for (int i = 0; i < ARRAYSIZE(g2d.pipelines); ++i)
vkDestroyPipeline(vk_core.device, g2d.pipelines[i], NULL);
vkDestroyPipelineLayout(vk_core.device, g2d.pipeline_layout, NULL);
}
void R_VkOverlay_DrawAndFlip( VkCommandBuffer cmdbuf ) {
DEBUG_BEGIN(cmdbuf, "2d overlay");
{
const VkDeviceSize offset = 0;
vkCmdBindVertexBuffers(cmdbuf, 0, 1, &g2d.pics_buffer.buffer, &offset);
}
for (int i = 0; i < g2d.batch_count && g2d.batch[i].vertex_count > 0; ++i)
{
vk_texture_t *texture = findTexture(g2d.batch[i].texture);
const VkPipeline pipeline = g2d.pipelines[g2d.batch[i].blending_mode];
if (texture->vk.descriptor)
{
vkCmdBindPipeline(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
vkCmdBindDescriptorSets(cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, g2d.pipeline_layout, 0, 1, &texture->vk.descriptor, 0, NULL);
vkCmdDraw(cmdbuf, g2d.batch[i].vertex_count, 1, g2d.batch[i].vertex_offset, 0);
} // FIXME else what?
}
DEBUG_END(cmdbuf);
clearAccumulated();
}
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
PRINT_NOT_IMPLEMENTED();
}
void R_DrawTileClear( int texnum, int x, int y, int w, int h )
{
PRINT_NOT_IMPLEMENTED_ARGS("%s", findTexture(texnum)->name );
}
void CL_FillRGBA( float x, float y, float w, float h, int r, int g, int b, int a )
{
drawFill(x, y, w, h, r, g, b, a, kRenderTransAdd);
}
void CL_FillRGBABlend( float x, float y, float w, float h, int r, int g, int b, int a )
{
drawFill(x, y, w, h, r, g, b, a, kRenderTransColor);
}

View File

@ -9,6 +9,6 @@ void R_DrawTileClear( int texnum, int x, int y, int w, int h );
void CL_FillRGBA( float x, float y, float w, float h, int r, int g, int b, int a );
void CL_FillRGBABlend( float x, float y, float w, float h, int r, int g, int b, int a );
qboolean initVk2d( void );
void deinitVk2d( void );
void vk2dEnd( VkCommandBuffer cmdbuf );
qboolean R_VkOverlay_Init( void );
void R_VkOverlay_Shutdown( void );
void R_VkOverlay_DrawAndFlip( VkCommandBuffer cmdbuf );

View File

@ -1,6 +1,5 @@
#include "vk_renderstate.h"
#include "vk_2d.h"
#include "vk_core.h"
#include "cvardef.h"

View File

@ -3,7 +3,7 @@
#include "vk_common.h"
#include "vk_textures.h"
#include "vk_renderstate.h"
#include "vk_2d.h"
#include "vk_overlay.h"
#include "vk_scene.h"
#include "vk_framectl.h"
#include "vk_lightmap.h"

View File

@ -1105,9 +1105,6 @@ static void performTracing( VkCommandBuffer cmdbuf, const vk_ray_frame_render_ar
DEBUG_END(cmdbuf);
}
qboolean initVk2d(void);
void deinitVk2d(void);
static void reloadPass( struct ray_pass_s **slot, struct ray_pass_s *new_pass ) {
if (!new_pass)
return;
@ -1132,9 +1129,6 @@ void VK_RayFrameEnd(const vk_ray_frame_render_args_t* args)
if (g_rtx.reload_pipeline) {
gEngine.Con_Printf(S_WARN "Reloading RTX shaders/pipelines\n");
// reload 2d
deinitVk2d();
initVk2d();
// TODO gracefully handle reload errors: need to change createPipeline, loadShader, VK_PipelineCreate...
//vkDestroyPipeline(vk_core.device, g_rtx.pipeline, NULL);
createPipeline();