mirror of
https://github.com/w23/xash3d-fwgs
synced 2025-01-18 14:50:05 +01:00
remove ubo management from "public" vk_render api
Now rendering submodules specify their colors and matrices using VK_RenderState global stat api. This is a trade-off between making all submodules track their state on their own, or managing that state centrally.
This commit is contained in:
parent
15fdcab5fe
commit
e66810a05b
@ -1,9 +1,12 @@
|
||||
# 2021-02-20
|
||||
- [ ] refactor vk_render interface:
|
||||
- [x] move uniform_data_t to global render state ~inside render_draw_t, remove any mentions of uniform/slots from api; alt: global render state?~
|
||||
- [x] rename RenderDraw to SubmitDraw
|
||||
|
||||
# Next
|
||||
- [ ] refactor vk_render interface:
|
||||
- [ ] make projection matrix independent render global/current/static state
|
||||
- [ ] move uniform_data_t inside render_draw_t, remove any mentions of uniform/slots from api; alt: global render state?
|
||||
- [ ] add debug label to render_draw_t?; alt: VK_RenderDebugNameBegin/End
|
||||
- [ ] rename RenderDraw to SubmitDraw
|
||||
- [ ] make 2nd commad buffer for resource upload
|
||||
- [ ] start building command buffers in beginframe
|
||||
- [ ] perform 3d rendering on corresponding refapi calls, not endframe
|
||||
@ -11,6 +14,8 @@
|
||||
- [ ] wrap viewmodel in vk debug label
|
||||
|
||||
# Planned
|
||||
- [ ] fix projection matrix differences w/ gl render
|
||||
- [ ] bad condition for temp vs map-permanent buffer error message
|
||||
- [ ] draw more types of beams
|
||||
- [ ] fix brush blending
|
||||
- [ ] sprite depth offset
|
||||
@ -33,6 +38,7 @@
|
||||
- [ ] studio models survive NewMap; need to compactify buffers after removing all brushes
|
||||
- [ ] sometimes it gets very slow (1fps) when ran under lldb (only on stream?)
|
||||
- [ ] optimize perf: cmdbuf managements and semaphores, upload to gpu, ...
|
||||
- [ ] RTX: studio models should not pre-transform vertices with modelView matrix
|
||||
|
||||
# Someday
|
||||
- [ ] cleanup unused stuff in vk_studio.c
|
||||
|
@ -153,7 +153,7 @@ static void applyBrightness( float brightness, const vec4_t color, vec4_t out )
|
||||
out[3] = 1.f;
|
||||
}
|
||||
|
||||
static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, int flags, int ubo_index, const vec4_t color, int texture, int render_mode )
|
||||
static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, int flags, const vec4_t color, int texture, int render_mode )
|
||||
{
|
||||
int noiseIndex, noiseStep;
|
||||
int i, total_segs, segs_drawn;
|
||||
@ -376,7 +376,6 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
|
||||
}
|
||||
{
|
||||
const render_draw_t draw = {
|
||||
.ubo_index = ubo_index,
|
||||
.lightmap = tglob.whiteTexture,
|
||||
.texture = texture,
|
||||
.render_mode = render_mode,
|
||||
@ -385,7 +384,7 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
|
||||
.index_offset = index_buffer.buffer_offset_in_units,
|
||||
};
|
||||
|
||||
VK_RenderDraw( &draw );
|
||||
VK_RenderScheduleDraw( &draw );
|
||||
}
|
||||
}
|
||||
|
||||
@ -955,8 +954,6 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
vec4_t color;
|
||||
int render_mode;
|
||||
int texturenum;
|
||||
int ubo_index = VK_RenderUniformAlloc();
|
||||
uniform_data_t *ubo = VK_RenderGetUniformSlot( ubo_index );
|
||||
|
||||
model = gEngine.pfnGetModelByIndex( pbeam->modelIndex );
|
||||
SetBits( pbeam->flags, FBEAM_ISACTIVE );
|
||||
@ -1097,10 +1094,6 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
else
|
||||
color[3] = pbeam->brightness;
|
||||
|
||||
// Ran out of UBO slots
|
||||
if (!ubo)
|
||||
return;
|
||||
|
||||
{
|
||||
matrix4x4 tmp;
|
||||
const matrix4x4 vk_proj_fixup = {
|
||||
@ -1110,9 +1103,11 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
{0, 0, .5, 1}
|
||||
};
|
||||
Matrix4x4_Concat( tmp, vk_proj_fixup, g_camera.worldviewProjectionMatrix);
|
||||
Matrix4x4_ToArrayFloatGL( tmp, (float*)ubo->mvp );
|
||||
VK_RenderStateSetMatrix( tmp );
|
||||
}
|
||||
Vector4Set(ubo->color, 1, 1, 1, 1);
|
||||
|
||||
// TODO gl renderer has per-vertex color that is updated using brightness and whatever
|
||||
VK_RenderStateSetColor( color[0], color[1], color[2], color[3] );
|
||||
|
||||
if (vk_core.debug) {
|
||||
VkDebugUtilsLabelEXT label = {
|
||||
@ -1138,7 +1133,7 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
|
||||
break;
|
||||
case TE_BEAMPOINTS:
|
||||
case TE_BEAMHOSE:
|
||||
R_DrawSegs( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments, pbeam->flags, ubo_index, color, texturenum, render_mode );
|
||||
R_DrawSegs( pbeam->source, pbeam->delta, pbeam->width, pbeam->amplitude, pbeam->freq, pbeam->speed, pbeam->segments, pbeam->flags, color, texturenum, render_mode );
|
||||
break;
|
||||
case TE_BEAMFOLLOW:
|
||||
// FIXME VK TriBegin( TRI_QUADS );
|
||||
|
@ -126,7 +126,7 @@ texture_t *R_TextureAnimation( const cl_entity_t *ent, msurface_t *s )
|
||||
return base;
|
||||
}
|
||||
|
||||
void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode )
|
||||
{
|
||||
// Expect all buffers to be bound
|
||||
const model_t *mod = ent->model;
|
||||
@ -140,6 +140,12 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tglob.lightmapTextures[0])
|
||||
{
|
||||
gEngine.Con_Printf( S_ERROR "Don't have a lightmap texture\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (vk_core.debug) {
|
||||
VkDebugUtilsLabelEXT label = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
|
||||
@ -159,7 +165,6 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
{
|
||||
if (index_count) {
|
||||
const render_draw_t draw = {
|
||||
.ubo_index = ubo_index,
|
||||
.lightmap = tglob.lightmapTextures[0],
|
||||
.texture = current_texture,
|
||||
.render_mode = render_mode,
|
||||
@ -168,7 +173,7 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
.index_offset = index_offset,
|
||||
};
|
||||
|
||||
VK_RenderDraw( &draw );
|
||||
VK_RenderScheduleDraw( &draw );
|
||||
}
|
||||
|
||||
current_texture = t->gl_texturenum;
|
||||
@ -185,7 +190,6 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
|
||||
if (index_count) {
|
||||
const render_draw_t draw = {
|
||||
.ubo_index = ubo_index,
|
||||
.lightmap = tglob.lightmapTextures[0],
|
||||
.texture = current_texture,
|
||||
.render_mode = render_mode,
|
||||
@ -194,24 +198,13 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
.index_offset = index_offset,
|
||||
};
|
||||
|
||||
VK_RenderDraw( &draw );
|
||||
VK_RenderScheduleDraw( &draw );
|
||||
}
|
||||
|
||||
if (vk_core.debug)
|
||||
vkCmdEndDebugUtilsLabelEXT(vk_core.cb);
|
||||
}
|
||||
|
||||
qboolean VK_BrushRenderBegin( void )
|
||||
{
|
||||
if (!tglob.lightmapTextures[0])
|
||||
{
|
||||
gEngine.Con_Printf( S_ERROR "Don't have a lightmap texture\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int loadBrushSurfaces( const model_t *mod, vk_brush_model_surface_t *out_surfaces) {
|
||||
vk_brush_model_t *bmodel = mod->cache.data;
|
||||
uint32_t vertex_offset = 0;
|
||||
|
@ -11,5 +11,5 @@ qboolean VK_BrushInit( void );
|
||||
void VK_BrushShutdown( void );
|
||||
qboolean VK_LoadBrushModel( struct model_s *mod, const byte *buffer );
|
||||
qboolean VK_BrushRenderBegin( void );
|
||||
void VK_BrushDrawModel( const struct cl_entity_s *ent, int render_mode, int ubo_index );
|
||||
void VK_BrushDrawModel( const struct cl_entity_s *ent, int render_mode );
|
||||
void VK_BrushClear( void );
|
||||
|
@ -6,11 +6,24 @@
|
||||
#include "vk_common.h"
|
||||
#include "vk_pipeline.h"
|
||||
#include "vk_textures.h"
|
||||
#include "vk_math.h"
|
||||
|
||||
#include "eiface.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
#define MAX_UNIFORM_SLOTS (MAX_SCENE_ENTITIES * 2 /* solid + trans */ + 1)
|
||||
|
||||
typedef struct {
|
||||
matrix4x4 mvp;
|
||||
vec4_t color;
|
||||
} uniform_data_t;
|
||||
|
||||
static struct {
|
||||
VkPipelineLayout pipeline_layout;
|
||||
VkPipeline pipelines[kRenderTransAdd + 1];
|
||||
|
||||
vk_buffer_t buffer;
|
||||
uint32_t buffer_free_offset;
|
||||
|
||||
@ -22,19 +35,8 @@ static struct {
|
||||
} stat;
|
||||
|
||||
uint32_t temp_buffer_offset;
|
||||
int next_free_uniform_slot;
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
VkPipeline pipelines[kRenderTransAdd + 1];
|
||||
} g_render;
|
||||
|
||||
uniform_data_t *VK_RenderGetUniformSlot(int index)
|
||||
{
|
||||
ASSERT(index >= 0);
|
||||
ASSERT(index < MAX_UNIFORM_SLOTS);
|
||||
return (uniform_data_t*)(((uint8_t*)g_render.uniform_buffer.mapped) + (g_render.uniform_unit_size * index));
|
||||
}
|
||||
|
||||
static qboolean createPipelines( void )
|
||||
{
|
||||
/* VkPushConstantRange push_const = { */
|
||||
@ -140,7 +142,9 @@ static qboolean createPipelines( void )
|
||||
ci.depthWriteEnable = VK_FALSE;
|
||||
ci.blendEnable = VK_TRUE;
|
||||
ci.colorBlendOp = VK_BLEND_OP_ADD; // TODO check
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
|
||||
// sprites do SRC_ALPHA
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;// TODO ? FACTOR_ONE;
|
||||
ci.dstAlphaBlendFactor = ci.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
name = "brush kRenderTransAdd";
|
||||
break;
|
||||
@ -266,8 +270,9 @@ static vk_buffer_alloc_t renderBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
|
||||
vk_buffer_alloc_t VK_RenderBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
{
|
||||
// FIXME this is not correct: on the very first map load it will trigger a lot
|
||||
if (g_render.buffer_free_offset >= g_render.temp_buffer_offset)
|
||||
gEngine.Con_Printf(S_ERROR "Trying to allocate map-permanent storage int temp buffer context\n");
|
||||
gEngine.Con_Printf(S_ERROR "Trying to allocate map-permanent storage in temp buffer context\n");
|
||||
|
||||
return renderBufferAlloc( unit_size, count );
|
||||
}
|
||||
@ -275,7 +280,6 @@ vk_buffer_alloc_t VK_RenderBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
void VK_RenderBufferClearAll( void )
|
||||
{
|
||||
g_render.buffer_free_offset = 0;
|
||||
g_render.next_free_uniform_slot = 0;
|
||||
g_render.stat.align_holes_size = 0;
|
||||
}
|
||||
|
||||
@ -306,16 +310,31 @@ static struct {
|
||||
int pipeline;
|
||||
int lightmap; // TODO rename to 2nd texture
|
||||
int texture;
|
||||
int ubo_index;
|
||||
|
||||
int uniform_data_set_mask;
|
||||
int next_free_uniform_slot;
|
||||
uniform_data_t current_uniform_data;
|
||||
uniform_data_t dirty_uniform_data;
|
||||
} g_render_state;
|
||||
|
||||
enum {
|
||||
UNIFORM_UNSET = 0,
|
||||
UNIFORM_SET_COLOR = 1,
|
||||
UNIFORM_SET_MATRIX = 2,
|
||||
UNIFORM_SET_ALL = UNIFORM_SET_COLOR | UNIFORM_SET_MATRIX,
|
||||
UNIFORM_UPLOADED = 4,
|
||||
};
|
||||
|
||||
void VK_RenderBegin( void ) {
|
||||
g_render.next_free_uniform_slot = 0;
|
||||
g_render_state.next_free_uniform_slot = 0;
|
||||
|
||||
g_render_state.pipeline = -1;
|
||||
g_render_state.lightmap = -1;
|
||||
g_render_state.texture = -1;
|
||||
g_render_state.ubo_index = -1;
|
||||
g_render_state.uniform_data_set_mask = UNIFORM_UNSET;
|
||||
|
||||
memset(&g_render_state.current_uniform_data, 0, sizeof(g_render_state.current_uniform_data));
|
||||
memset(&g_render_state.dirty_uniform_data, 0, sizeof(g_render_state.dirty_uniform_data));
|
||||
|
||||
{
|
||||
const VkDeviceSize offset = 0;
|
||||
@ -324,13 +343,67 @@ void VK_RenderBegin( void ) {
|
||||
}
|
||||
}
|
||||
|
||||
void VK_RenderDraw( const render_draw_t *draw )
|
||||
void VK_RenderStateSetColor( float r, float g, float b, float a )
|
||||
{
|
||||
g_render_state.uniform_data_set_mask |= UNIFORM_SET_COLOR;
|
||||
g_render_state.dirty_uniform_data.color[0] = r;
|
||||
g_render_state.dirty_uniform_data.color[1] = g;
|
||||
g_render_state.dirty_uniform_data.color[2] = b;
|
||||
g_render_state.dirty_uniform_data.color[3] = a;
|
||||
}
|
||||
|
||||
void VK_RenderStateSetMatrix( const matrix4x4 mvp )
|
||||
{
|
||||
g_render_state.uniform_data_set_mask |= UNIFORM_SET_MATRIX;
|
||||
Matrix4x4_ToArrayFloatGL( mvp, (float*)g_render_state.dirty_uniform_data.mvp );
|
||||
}
|
||||
|
||||
static uniform_data_t *getUniformSlot(int index)
|
||||
{
|
||||
ASSERT(index >= 0);
|
||||
ASSERT(index < MAX_UNIFORM_SLOTS);
|
||||
return (uniform_data_t*)(((uint8_t*)g_render.uniform_buffer.mapped) + (g_render.uniform_unit_size * index));
|
||||
}
|
||||
|
||||
static int allocUniformSlot( void ) {
|
||||
if (g_render_state.next_free_uniform_slot == MAX_UNIFORM_SLOTS)
|
||||
return -1;
|
||||
|
||||
return g_render_state.next_free_uniform_slot++;
|
||||
}
|
||||
|
||||
void VK_RenderScheduleDraw( const render_draw_t *draw )
|
||||
{
|
||||
ASSERT(draw->render_mode >= 0);
|
||||
ASSERT(draw->render_mode < ARRAYSIZE(g_render.pipelines));
|
||||
ASSERT(draw->lightmap >= 0);
|
||||
ASSERT(draw->texture >= 0);
|
||||
ASSERT(draw->ubo_index >= 0);
|
||||
|
||||
if ((g_render_state.uniform_data_set_mask & UNIFORM_SET_ALL) != UNIFORM_SET_ALL) {
|
||||
gEngine.Con_Printf( S_ERROR "Not all uniform state was initialized prior to rendering\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
// Figure out whether we need to update UBO data, and upload new data if we do
|
||||
// TODO generally it's not safe to do memcmp for structure
|
||||
if (((g_render_state.uniform_data_set_mask & UNIFORM_UPLOADED) == 0) || memcmp(&g_render_state.current_uniform_data, &g_render_state.dirty_uniform_data, sizeof(g_render_state.current_uniform_data)) != 0) {
|
||||
const int ubo_index = allocUniformSlot();
|
||||
uniform_data_t *ubo;
|
||||
if (ubo_index < 0) {
|
||||
gEngine.Con_Printf( S_ERROR "Ran out of uniform slots\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
ubo = getUniformSlot( ubo_index );
|
||||
memcpy(&g_render_state.current_uniform_data, &g_render_state.dirty_uniform_data, sizeof(g_render_state.dirty_uniform_data));
|
||||
memcpy(ubo, &g_render_state.current_uniform_data, sizeof(*ubo));
|
||||
g_render_state.uniform_data_set_mask |= UNIFORM_UPLOADED;
|
||||
|
||||
{
|
||||
const uint32_t dynamic_offset[] = { g_render.uniform_unit_size * ubo_index};
|
||||
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipeline_layout, 0, 1, vk_core.descriptor_pool.ubo_sets, ARRAYSIZE(dynamic_offset), dynamic_offset);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_render_state.pipeline != draw->render_mode) {
|
||||
g_render_state.pipeline = draw->render_mode;
|
||||
@ -349,12 +422,6 @@ void VK_RenderDraw( const render_draw_t *draw )
|
||||
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipeline_layout, 1, 1, &findTexture(g_render_state.texture)->vk.descriptor, 0, NULL);
|
||||
}
|
||||
|
||||
if (g_render_state.ubo_index != draw->ubo_index) {
|
||||
const uint32_t dynamic_offset[] = { g_render.uniform_unit_size * draw->ubo_index};
|
||||
g_render_state.ubo_index = draw->ubo_index;
|
||||
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipeline_layout, 0, 1, vk_core.descriptor_pool.ubo_sets, ARRAYSIZE(dynamic_offset), dynamic_offset);
|
||||
}
|
||||
|
||||
if (draw->index_offset == UINT32_MAX) {
|
||||
/*gEngine.Con_Reportf( "Draw("
|
||||
"ubo_index=%d, "
|
||||
@ -379,14 +446,6 @@ void VK_RenderDraw( const render_draw_t *draw )
|
||||
}
|
||||
}
|
||||
|
||||
int VK_RenderUniformAlloc( void ) {
|
||||
if (g_render.next_free_uniform_slot == MAX_UNIFORM_SLOTS)
|
||||
return -1;
|
||||
|
||||
return g_render.next_free_uniform_slot++;
|
||||
}
|
||||
|
||||
|
||||
void VK_RenderEnd( void )
|
||||
{
|
||||
}
|
||||
|
@ -3,14 +3,8 @@
|
||||
#include "vk_const.h"
|
||||
#include "vk_core.h"
|
||||
|
||||
typedef struct {
|
||||
matrix4x4 mvp;
|
||||
vec4_t color;
|
||||
} uniform_data_t;
|
||||
|
||||
#define MAX_UNIFORM_SLOTS (MAX_SCENE_ENTITIES * 2 /* solid + trans */ + 1)
|
||||
|
||||
uniform_data_t *VK_RenderGetUniformSlot(int index);
|
||||
qboolean VK_RenderInit( void );
|
||||
void VK_RenderShutdown( void );
|
||||
|
||||
typedef struct vk_buffer_alloc_s {
|
||||
uint32_t buffer_offset_in_units;
|
||||
@ -19,12 +13,7 @@ typedef struct vk_buffer_alloc_s {
|
||||
|
||||
// TODO uploading to GPU mem interface
|
||||
vk_buffer_alloc_t VK_RenderBufferAlloc( uint32_t unit_size, uint32_t count );
|
||||
|
||||
void VK_RenderBufferClearAll( void );
|
||||
|
||||
qboolean VK_RenderInit( void );
|
||||
void VK_RenderShutdown( void );
|
||||
|
||||
void VK_RenderBufferPrintStats( void );
|
||||
|
||||
// TODO address cringiness of this when doing buffer upload to GPU RAM properly
|
||||
@ -32,6 +21,15 @@ void VK_RenderTempBufferBegin( void );
|
||||
vk_buffer_alloc_t VK_RenderTempBufferAlloc( uint32_t unit_size, uint32_t count );
|
||||
void VK_RenderTempBufferEnd( void );
|
||||
|
||||
// Set UBO state for next VK_RenderScheduleDraw calls
|
||||
// Why? Xash Ref code is organized in a way where we can't reliably pass this info with
|
||||
// ScheduleDraw itself, so we need to either set up per-submodule global state, or
|
||||
// centralize this global state in here
|
||||
void VK_RenderStateSetColor( float r, float g, float b, float a );
|
||||
// TODO void VK_RenderStateGetColor( vec4_t color );
|
||||
void VK_RenderStateSetMatrix( const matrix4x4 mvp );
|
||||
// TODO: set projection and mv matrices separately
|
||||
|
||||
// TODO is this a good place?
|
||||
typedef struct vk_vertex_s {
|
||||
vec3_t pos;
|
||||
@ -40,7 +38,6 @@ typedef struct vk_vertex_s {
|
||||
} vk_vertex_t;
|
||||
|
||||
typedef struct render_draw_s {
|
||||
int ubo_index;
|
||||
int lightmap, texture;
|
||||
int render_mode;
|
||||
uint32_t element_count;
|
||||
@ -48,8 +45,5 @@ typedef struct render_draw_s {
|
||||
} render_draw_t;
|
||||
|
||||
void VK_RenderBegin( void );
|
||||
// Allocate one uniform slot, -1 if no slot available
|
||||
int VK_RenderUniformAlloc( void );
|
||||
// FIXME rename to Submit something
|
||||
void VK_RenderDraw( const render_draw_t *draw );
|
||||
void VK_RenderScheduleDraw( const render_draw_t *draw );
|
||||
void VK_RenderEnd( void );
|
||||
|
@ -538,9 +538,7 @@ static void drawEntity( cl_entity_t *ent, int render_mode, const matrix4x4 mvp )
|
||||
{
|
||||
const model_t *mod = ent->model;
|
||||
matrix4x4 model, ent_mvp;
|
||||
uniform_data_t *ubo;
|
||||
float alpha;
|
||||
int ubo_index;
|
||||
|
||||
if (!mod)
|
||||
return;
|
||||
@ -548,24 +546,18 @@ static void drawEntity( cl_entity_t *ent, int render_mode, const matrix4x4 mvp )
|
||||
// handle studiomodels with custom rendermodes on texture
|
||||
alpha = render_mode == kRenderNormal ? 1.f : CL_FxBlend( ent ) / 255.0f;
|
||||
|
||||
// TODO ref_gl does this earlier, can we too?
|
||||
// TODO ref_gl does this earlier (when adding entity), can we too?
|
||||
if( alpha <= 0.0f )
|
||||
return;
|
||||
|
||||
// TODO might accidentally alloc ubo for things that won't be rendered; optimize this
|
||||
ubo_index = VK_RenderUniformAlloc();
|
||||
if (ubo_index < 0)
|
||||
return; // TODO complain
|
||||
ubo = VK_RenderGetUniformSlot(ubo_index);
|
||||
|
||||
switch (render_mode) {
|
||||
case kRenderNormal:
|
||||
Vector4Set(ubo->color, 1.f, 1.f, 1.f, 1.f);
|
||||
VK_RenderStateSetColor( 1.f, 1.f, 1.f, 1.f);
|
||||
break;
|
||||
|
||||
case kRenderTransColor:
|
||||
// FIXME also zero out texture? use white texture
|
||||
Vector4Set(ubo->color,
|
||||
VK_RenderStateSetColor(
|
||||
ent->curstate.rendercolor.r / 255.f,
|
||||
ent->curstate.rendercolor.g / 255.f,
|
||||
ent->curstate.rendercolor.b / 255.f,
|
||||
@ -573,39 +565,40 @@ static void drawEntity( cl_entity_t *ent, int render_mode, const matrix4x4 mvp )
|
||||
break;
|
||||
|
||||
case kRenderTransAdd:
|
||||
Vector4Set(ubo->color, alpha, alpha, alpha, 1.f);
|
||||
VK_RenderStateSetColor( alpha, alpha, alpha, 1.f);
|
||||
break;
|
||||
|
||||
case kRenderTransAlpha:
|
||||
Vector4Set(ubo->color, 1.f, 1.f, 1.f, 1.f);
|
||||
VK_RenderStateSetColor( 1.f, 1.f, 1.f, 1.f);
|
||||
// TODO Q1compat Vector4Set(e_ubo->color, 1.f, 1.f, 1.f, alpha);
|
||||
break;
|
||||
|
||||
default:
|
||||
Vector4Set(ubo->color, 1.f, 1.f, 1.f, alpha);
|
||||
VK_RenderStateSetColor( 1.f, 1.f, 1.f, alpha);
|
||||
}
|
||||
|
||||
// TODO sort by entity type?
|
||||
// TODO other entity types
|
||||
switch (mod->type)
|
||||
{
|
||||
case mod_brush:
|
||||
R_RotateForEntity( model, ent );
|
||||
Matrix4x4_Concat( ent_mvp, mvp, model );
|
||||
Matrix4x4_ToArrayFloatGL( ent_mvp, (float*)ubo->mvp);
|
||||
VK_BrushDrawModel( ent, render_mode, ubo_index );
|
||||
VK_RenderStateSetMatrix( ent_mvp );
|
||||
VK_BrushDrawModel( ent, render_mode );
|
||||
break;
|
||||
|
||||
case mod_studio:
|
||||
/* R_RotateForEntity( model, ent ); */
|
||||
/* Matrix4x4_Concat( ent_mvp, mvp, model ); */
|
||||
Matrix4x4_ToArrayFloatGL( mvp, (float*)ubo->mvp);
|
||||
VK_StudioDrawModel( ent, render_mode, ubo_index );
|
||||
VK_RenderStateSetMatrix( mvp );
|
||||
VK_StudioDrawModel( ent, render_mode );
|
||||
break;
|
||||
|
||||
case mod_sprite:
|
||||
Matrix4x4_ToArrayFloatGL( mvp, (float*)ubo->mvp);
|
||||
VK_SpriteDrawModel( ent, ubo_index );
|
||||
VK_RenderStateSetMatrix( mvp );
|
||||
VK_SpriteDrawModel( ent );
|
||||
break;
|
||||
|
||||
case mod_alias:
|
||||
case mod_bad:
|
||||
PRINT_NOT_IMPLEMENTED();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -620,25 +613,17 @@ void VK_SceneRender( void )
|
||||
gpGlobals->time - gpGlobals->oldtime
|
||||
/* FIXME VK : 0.f */;
|
||||
|
||||
if (!VK_BrushRenderBegin())
|
||||
return;
|
||||
|
||||
VK_RenderTempBufferBegin();
|
||||
|
||||
VK_RenderBegin();
|
||||
|
||||
prepareMatrix( &fixme_rvp, worldview, projection, mvp );
|
||||
|
||||
// Draw view model
|
||||
{
|
||||
const int ubo_index = VK_RenderUniformAlloc();
|
||||
uniform_data_t *ubo;
|
||||
ASSERT(ubo_index >= 0);
|
||||
ubo = VK_RenderGetUniformSlot(ubo_index);
|
||||
Matrix4x4_ToArrayFloatGL( mvp, (float*)ubo->mvp );
|
||||
Vector4Set(ubo->color, 1.f, 1.f, 1.f, 1.f);
|
||||
VK_RenderStateSetMatrix( mvp );
|
||||
VK_RenderStateSetColor( 1.f, 1.f, 1.f, 1.f );
|
||||
R_RunViewmodelEvents();
|
||||
R_DrawViewModel( ubo_index );
|
||||
R_DrawViewModel();
|
||||
}
|
||||
|
||||
// Draw world brush
|
||||
@ -646,13 +631,9 @@ void VK_SceneRender( void )
|
||||
cl_entity_t *world = gEngine.GetEntityByIndex( 0 );
|
||||
if( world && world->model )
|
||||
{
|
||||
const int ubo_index = VK_RenderUniformAlloc();
|
||||
uniform_data_t *ubo;
|
||||
ASSERT(ubo_index >= 0);
|
||||
ubo = VK_RenderGetUniformSlot(ubo_index);
|
||||
Matrix4x4_ToArrayFloatGL( mvp, (float*)ubo->mvp );
|
||||
Vector4Set(ubo->color, 1.f, 1.f, 1.f, 1.f);
|
||||
VK_BrushDrawModel( world, kRenderNormal, ubo_index );
|
||||
VK_RenderStateSetMatrix( mvp );
|
||||
VK_RenderStateSetColor( 1.f, 1.f, 1.f, 1.f);
|
||||
VK_BrushDrawModel( world, kRenderNormal );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -639,14 +639,14 @@ qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale )
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME VK if( R_CullSpriteModel( e, origin ))
|
||||
return true;
|
||||
// FIXME VK if( R_CullSpriteModel( e, origin )) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int ubo_index, int texture, int render_mode )
|
||||
static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int texture, int render_mode )
|
||||
{
|
||||
vec3_t point;
|
||||
vk_buffer_alloc_t buf_vertex, buf_index;
|
||||
@ -705,7 +705,6 @@ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right,
|
||||
|
||||
{
|
||||
const render_draw_t draw = {
|
||||
.ubo_index = ubo_index,
|
||||
.lightmap = tglob.whiteTexture,
|
||||
.texture = texture,
|
||||
.render_mode = render_mode,
|
||||
@ -714,7 +713,7 @@ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right,
|
||||
.index_offset = buf_index.buffer_offset_in_units,
|
||||
};
|
||||
|
||||
VK_RenderDraw( &draw );
|
||||
VK_RenderScheduleDraw( &draw );
|
||||
}
|
||||
}
|
||||
|
||||
@ -766,7 +765,7 @@ static qboolean R_SpriteAllowLerping( cl_entity_t *e, msprite_t *psprite )
|
||||
return true;
|
||||
}
|
||||
|
||||
void VK_SpriteDrawModel( cl_entity_t *e, int ubo_index )
|
||||
void VK_SpriteDrawModel( cl_entity_t *e )
|
||||
{
|
||||
mspriteframe_t *frame, *oldframe;
|
||||
msprite_t *psprite;
|
||||
@ -776,7 +775,6 @@ void VK_SpriteDrawModel( cl_entity_t *e, int ubo_index )
|
||||
float lerp = 1.0f, ilerp, scale;
|
||||
vec3_t v_forward, v_right, v_up;
|
||||
vec3_t origin, color, color2 = { 0.0f };
|
||||
uniform_data_t *ubo = VK_RenderGetUniformSlot(ubo_index);
|
||||
|
||||
/* FIXME VK
|
||||
if( RI.params & RP_ENVVIEW )
|
||||
@ -945,7 +943,8 @@ void VK_SpriteDrawModel( cl_entity_t *e, int ubo_index )
|
||||
ubo->color[2] = color[2];
|
||||
ubo->color[3] = tr.blend;
|
||||
*/
|
||||
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale, ubo_index, frame->gl_texturenum, e->curstate.rendermode );
|
||||
VK_RenderStateSetColor( color[0], color[1], color[2], .5f ); // FIXME VK: tr.blend
|
||||
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -955,15 +954,16 @@ void VK_SpriteDrawModel( cl_entity_t *e, int ubo_index )
|
||||
|
||||
if( ilerp != 0.0f )
|
||||
{
|
||||
// FIXME VK make sure we end up with the same values
|
||||
ubo->color[3] *= ilerp;
|
||||
R_DrawSpriteQuad( oldframe, origin, v_right, v_up, scale, ubo_index, oldframe->gl_texturenum, e->curstate.rendermode );
|
||||
// FIXME VK make sure we end up with the same values as gl
|
||||
VK_RenderStateSetColor( color[0], color[1], color[2], 1.f * ilerp );
|
||||
R_DrawSpriteQuad( oldframe, origin, v_right, v_up, scale, oldframe->gl_texturenum, e->curstate.rendermode );
|
||||
}
|
||||
|
||||
if( lerp != 0.0f )
|
||||
{
|
||||
ubo->color[3] *= lerp;
|
||||
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale, ubo_index, frame->gl_texturenum, e->curstate.rendermode );
|
||||
// FIXME VK make sure we end up with the same values as gl
|
||||
VK_RenderStateSetColor( color[0], color[1], color[2], 1.f * lerp );
|
||||
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,4 +7,4 @@ int R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame );
|
||||
void Mod_LoadMapSprite( struct model_s *mod, const void *buffer, size_t size, qboolean *loaded );
|
||||
void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, uint texFlags );
|
||||
|
||||
void VK_SpriteDrawModel( cl_entity_t *e, int ubo_index );
|
||||
void VK_SpriteDrawModel( cl_entity_t *e );
|
||||
|
@ -107,9 +107,6 @@ typedef struct
|
||||
// drawelements renderer
|
||||
uint numverts;
|
||||
uint numelems;
|
||||
|
||||
// TODO prettify Vulkan stuff
|
||||
int vk_ubo_index;
|
||||
} studio_draw_state_t;
|
||||
|
||||
// studio-related cvars
|
||||
@ -1920,11 +1917,6 @@ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float
|
||||
uint32_t vertex_offset, index_offset;
|
||||
short* const ptricmds_initial = ptricmds;
|
||||
|
||||
if (g_studio.vk_ubo_index < 0) {
|
||||
gEngine.Con_Printf(S_ERROR "Cannot render mesh: ubo_index is unset\n"); // TODO mesh signature?
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute counts of vertices and indices
|
||||
while(( i = *( ptricmds++ )))
|
||||
{
|
||||
@ -2017,7 +2009,6 @@ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float
|
||||
// Render
|
||||
{
|
||||
const render_draw_t draw = {
|
||||
.ubo_index = g_studio.vk_ubo_index,
|
||||
.lightmap = tglob.whiteTexture,
|
||||
.texture = texture,
|
||||
.render_mode = render_mode,
|
||||
@ -2026,7 +2017,7 @@ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float
|
||||
.index_offset = buf_index.buffer_offset_in_units,
|
||||
};
|
||||
|
||||
VK_RenderDraw( &draw );
|
||||
VK_RenderScheduleDraw( &draw );
|
||||
}
|
||||
}
|
||||
|
||||
@ -3181,7 +3172,7 @@ void R_GatherPlayerLight( void )
|
||||
*/
|
||||
}
|
||||
|
||||
void R_DrawViewModel( int ubo_index )
|
||||
void R_DrawViewModel( void )
|
||||
{
|
||||
cl_entity_t *view = gEngine.GetViewModel();
|
||||
|
||||
@ -3222,7 +3213,6 @@ void R_DrawViewModel( int ubo_index )
|
||||
}
|
||||
*/
|
||||
|
||||
g_studio.vk_ubo_index = ubo_index;
|
||||
switch( RI.currententity->model->type )
|
||||
{
|
||||
/* FIXME VK
|
||||
@ -3236,7 +3226,6 @@ void R_DrawViewModel( int ubo_index )
|
||||
break;
|
||||
}
|
||||
|
||||
g_studio.vk_ubo_index = -1;
|
||||
RI.currententity = NULL;
|
||||
RI.currentmodel = NULL;
|
||||
|
||||
@ -3520,16 +3509,14 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
|
||||
PRINT_NOT_IMPLEMENTED_ARGS("(%s)", mod->name);
|
||||
}
|
||||
|
||||
void VK_StudioDrawModel( cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
void VK_StudioDrawModel( cl_entity_t *ent, int render_mode )
|
||||
{
|
||||
RI.currententity = ent;
|
||||
RI.currentmodel = ent->model;
|
||||
RI.drawWorld = true;
|
||||
|
||||
g_studio.vk_ubo_index = ubo_index;
|
||||
R_DrawStudioModel( ent );
|
||||
|
||||
g_studio.vk_ubo_index = -1;
|
||||
RI.currentmodel = NULL;
|
||||
RI.currententity = NULL;
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ void VK_StudioShutdown( void );
|
||||
void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded );
|
||||
void Mod_StudioLoadTextures( model_t *mod, void *data );
|
||||
|
||||
void VK_StudioDrawModel( cl_entity_t *ent, int render_mode, int ubo_index );
|
||||
void VK_StudioDrawModel( cl_entity_t *ent, int render_mode );
|
||||
|
||||
void R_RunViewmodelEvents( void );
|
||||
void R_DrawViewModel( int ubo_index );
|
||||
void R_DrawViewModel( void );
|
||||
|
||||
void CL_InitStudioAPI( void );
|
||||
|
Loading…
x
Reference in New Issue
Block a user