mirror of
https://github.com/w23/xash3d-fwgs
synced 2025-01-18 14:50:05 +01:00
add broken studio models drawing
there are several issues with it: - there are holes in models - movement is jerky - no lighting applied
This commit is contained in:
parent
e14f004785
commit
778cc60453
@ -1,10 +1,5 @@
|
||||
## 2021-02-10
|
||||
- [x] refactor brush into brushes and separate rendering/buffer management
|
||||
|
||||
# Next
|
||||
- [ ] draw studio models as bounding boxes
|
||||
- [ ] studio models
|
||||
- [ ] animated textures (accept PR)
|
||||
- [ ] studio models fixes
|
||||
|
||||
# Planned
|
||||
- [ ] move all consts to vk_const
|
||||
@ -46,3 +41,14 @@
|
||||
|
||||
## 2021-02-08
|
||||
- [x] move entity rendering-enumeration into vk_scene
|
||||
|
||||
## 2021-02-10
|
||||
- [x] refactor brush into brushes and separate rendering/buffer management
|
||||
- [x] animated textures (accept PR)
|
||||
|
||||
## 2021-02-13
|
||||
- [x] move pipelines from brush to render
|
||||
- [x] render temp buffer api
|
||||
- [x] draw studio models somehow
|
||||
- [x] studio models vk debug markers
|
||||
- [x] studio models white texture as lightmap
|
||||
|
@ -17,13 +17,6 @@
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
|
||||
typedef struct brush_vertex_s
|
||||
{
|
||||
vec3_t pos;
|
||||
vec2_t gl_tc;
|
||||
vec2_t lm_tc;
|
||||
} brush_vertex_t;
|
||||
|
||||
typedef struct vk_brush_model_surface_s {
|
||||
int texture_num;
|
||||
msurface_t *surf;
|
||||
@ -47,172 +40,10 @@ static struct {
|
||||
struct {
|
||||
int num_vertices, num_indices;
|
||||
} stat;
|
||||
VkPipelineLayout pipeline_layout;
|
||||
VkPipeline pipelines[kRenderTransAdd + 1];
|
||||
|
||||
int rtable[MOD_FRAMES][MOD_FRAMES];
|
||||
} g_brush;
|
||||
|
||||
|
||||
static qboolean createPipelines( void )
|
||||
{
|
||||
/* VkPushConstantRange push_const = { */
|
||||
/* .offset = 0, */
|
||||
/* .size = sizeof(AVec3f), */
|
||||
/* .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, */
|
||||
/* }; */
|
||||
|
||||
VkDescriptorSetLayout descriptor_layouts[] = {
|
||||
vk_core.descriptor_pool.one_uniform_buffer_layout,
|
||||
vk_core.descriptor_pool.one_texture_layout,
|
||||
vk_core.descriptor_pool.one_texture_layout,
|
||||
};
|
||||
|
||||
VkPipelineLayoutCreateInfo plci = {
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
.setLayoutCount = ARRAYSIZE(descriptor_layouts),
|
||||
.pSetLayouts = descriptor_layouts,
|
||||
/* .pushConstantRangeCount = 1, */
|
||||
/* .pPushConstantRanges = &push_const, */
|
||||
};
|
||||
|
||||
// FIXME store layout separately
|
||||
XVK_CHECK(vkCreatePipelineLayout(vk_core.device, &plci, NULL, &g_brush.pipeline_layout));
|
||||
|
||||
{
|
||||
struct ShaderSpec {
|
||||
float alpha_test_threshold;
|
||||
} spec_data = { .25f };
|
||||
const VkSpecializationMapEntry spec_map[] = {
|
||||
{.constantID = 0, .offset = offsetof(struct ShaderSpec, alpha_test_threshold), .size = sizeof(float) },
|
||||
};
|
||||
|
||||
VkSpecializationInfo alpha_test_spec = {
|
||||
.mapEntryCount = ARRAYSIZE(spec_map),
|
||||
.pMapEntries = spec_map,
|
||||
.dataSize = sizeof(struct ShaderSpec),
|
||||
.pData = &spec_data
|
||||
};
|
||||
|
||||
VkVertexInputAttributeDescription attribs[] = {
|
||||
{.binding = 0, .location = 0, .format = VK_FORMAT_R32G32B32_SFLOAT, .offset = offsetof(brush_vertex_t, pos)},
|
||||
{.binding = 0, .location = 1, .format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(brush_vertex_t, gl_tc)},
|
||||
{.binding = 0, .location = 2, .format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(brush_vertex_t, lm_tc)},
|
||||
};
|
||||
|
||||
VkPipelineShaderStageCreateInfo shader_stages[] = {
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.stage = VK_SHADER_STAGE_VERTEX_BIT,
|
||||
.module = loadShader("brush.vert.spv"),
|
||||
.pName = "main",
|
||||
}, {
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.module = loadShader("brush.frag.spv"),
|
||||
.pName = "main",
|
||||
}};
|
||||
|
||||
vk_pipeline_create_info_t ci = {
|
||||
.layout = g_brush.pipeline_layout,
|
||||
.attribs = attribs,
|
||||
.num_attribs = ARRAYSIZE(attribs),
|
||||
|
||||
.stages = shader_stages,
|
||||
.num_stages = ARRAYSIZE(shader_stages),
|
||||
|
||||
.vertex_stride = sizeof(brush_vertex_t),
|
||||
|
||||
.depthTestEnable = VK_TRUE,
|
||||
.depthWriteEnable = VK_TRUE,
|
||||
.depthCompareOp = VK_COMPARE_OP_LESS,
|
||||
|
||||
.blendEnable = VK_FALSE,
|
||||
|
||||
.cullMode = VK_CULL_MODE_FRONT_BIT,
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(g_brush.pipelines); ++i)
|
||||
{
|
||||
const char *name = "UNDEFINED";
|
||||
switch (i)
|
||||
{
|
||||
case kRenderNormal:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.blendEnable = VK_FALSE;
|
||||
ci.depthWriteEnable = VK_TRUE;
|
||||
name = "brush kRenderNormal";
|
||||
break;
|
||||
|
||||
case kRenderTransColor:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.depthWriteEnable = VK_TRUE;
|
||||
ci.blendEnable = VK_TRUE;
|
||||
ci.colorBlendOp = VK_BLEND_OP_ADD; // TODO check
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
ci.dstAlphaBlendFactor = ci.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
name = "brush kRenderTransColor";
|
||||
break;
|
||||
|
||||
case kRenderTransAdd:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.depthWriteEnable = VK_FALSE;
|
||||
ci.blendEnable = VK_TRUE;
|
||||
ci.colorBlendOp = VK_BLEND_OP_ADD; // TODO check
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
ci.dstAlphaBlendFactor = ci.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
name = "brush kRenderTransAdd";
|
||||
break;
|
||||
|
||||
case kRenderTransAlpha:
|
||||
ci.stages[1].pSpecializationInfo = &alpha_test_spec;
|
||||
ci.depthWriteEnable = VK_TRUE;
|
||||
ci.blendEnable = VK_FALSE;
|
||||
name = "brush kRenderTransAlpha(test)";
|
||||
break;
|
||||
|
||||
case kRenderGlow:
|
||||
case kRenderTransTexture:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.depthWriteEnable = VK_FALSE;
|
||||
ci.blendEnable = VK_TRUE;
|
||||
ci.colorBlendOp = VK_BLEND_OP_ADD; // TODO check
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
ci.dstAlphaBlendFactor = ci.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
name = "brush kRenderTransTexture/Glow";
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(!"Unreachable");
|
||||
}
|
||||
|
||||
g_brush.pipelines[i] = createPipeline(&ci);
|
||||
|
||||
if (!g_brush.pipelines[i])
|
||||
{
|
||||
// TODO complain
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vk_core.debug)
|
||||
{
|
||||
VkDebugUtilsObjectNameInfoEXT debug_name = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
|
||||
.objectHandle = (uint64_t)g_brush.pipelines[i],
|
||||
.objectType = VK_OBJECT_TYPE_PIPELINE,
|
||||
.pObjectName = name,
|
||||
};
|
||||
XVK_CHECK(vkSetDebugUtilsObjectNameEXT(vk_core.device, &debug_name));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)ARRAYSIZE(shader_stages); ++i)
|
||||
vkDestroyShaderModule(vk_core.device, shader_stages[i].module, NULL);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VK_InitRandomTable( void )
|
||||
{
|
||||
int tu, tv;
|
||||
@ -235,19 +66,11 @@ qboolean VK_BrushInit( void )
|
||||
{
|
||||
VK_InitRandomTable ();
|
||||
|
||||
if (!createPipelines())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int fixme_current_pipeline_index = -1;
|
||||
|
||||
void VK_BrushShutdown( void )
|
||||
{
|
||||
for (int i = 0; i < ARRAYSIZE(g_brush.pipelines); ++i)
|
||||
vkDestroyPipeline(vk_core.device, g_brush.pipelines[i], NULL);
|
||||
vkDestroyPipelineLayout( vk_core.device, g_brush.pipeline_layout, NULL );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -325,17 +148,6 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
vkCmdBeginDebugUtilsLabelEXT(vk_core.cb, &label);
|
||||
}
|
||||
|
||||
ASSERT(render_mode >= 0);
|
||||
ASSERT(render_mode < ARRAYSIZE(g_brush.pipelines));
|
||||
|
||||
if (render_mode != fixme_current_pipeline_index)
|
||||
{
|
||||
fixme_current_pipeline_index = render_mode;
|
||||
vkCmdBindPipeline(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_brush.pipelines[fixme_current_pipeline_index]);
|
||||
}
|
||||
|
||||
VK_RenderBindUniformBufferWithIndex( g_brush.pipeline_layout, ubo_index);
|
||||
|
||||
for (int i = 0; i < bmodel->num_surfaces; ++i) {
|
||||
const vk_brush_model_surface_t *bsurf = bmodel->surfaces + i;
|
||||
texture_t *t = R_TextureAnimation(ent, bsurf->surf);
|
||||
@ -345,11 +157,19 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
|
||||
if (current_texture != t->gl_texturenum)
|
||||
{
|
||||
vk_texture_t *texture = findTexture(t->gl_texturenum);
|
||||
if (index_count)
|
||||
vkCmdDrawIndexed(vk_core.cb, index_count, 1, index_offset, bmodel->vertex_offset, 0);
|
||||
if (index_count) {
|
||||
const render_draw_t draw = {
|
||||
.ubo_index = ubo_index,
|
||||
.lightmap = tglob.lightmapTextures[0],
|
||||
.texture = current_texture,
|
||||
.render_mode = render_mode,
|
||||
.element_count = index_count,
|
||||
.vertex_offset = bmodel->vertex_offset,
|
||||
.index_offset = index_offset,
|
||||
};
|
||||
|
||||
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_brush.pipeline_layout, 1, 1, &texture->vk.descriptor, 0, NULL);
|
||||
VK_RenderDraw( &draw );
|
||||
}
|
||||
|
||||
current_texture = t->gl_texturenum;
|
||||
index_count = 0;
|
||||
@ -363,8 +183,19 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
index_count += bsurf->index_count;
|
||||
}
|
||||
|
||||
if (index_count)
|
||||
vkCmdDrawIndexed(vk_core.cb, index_count, 1, index_offset, bmodel->vertex_offset, 0);
|
||||
if (index_count) {
|
||||
const render_draw_t draw = {
|
||||
.ubo_index = ubo_index,
|
||||
.lightmap = tglob.lightmapTextures[0],
|
||||
.texture = current_texture,
|
||||
.render_mode = render_mode,
|
||||
.element_count = index_count,
|
||||
.vertex_offset = bmodel->vertex_offset,
|
||||
.index_offset = index_offset,
|
||||
};
|
||||
|
||||
VK_RenderDraw( &draw );
|
||||
}
|
||||
|
||||
if (vk_core.debug)
|
||||
vkCmdEndDebugUtilsLabelEXT(vk_core.cb);
|
||||
@ -372,17 +203,12 @@ void VK_BrushDrawModel( const cl_entity_t *ent, int render_mode, int ubo_index )
|
||||
|
||||
qboolean VK_BrushRenderBegin( void )
|
||||
{
|
||||
VK_RenderBindBuffers(); // TODO in scene?
|
||||
if (!tglob.lightmapTextures[0])
|
||||
{
|
||||
gEngine.Con_Printf( S_ERROR "Don't have a lightmap texture\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_brush.pipeline_layout, 2, 1, &findTexture(tglob.lightmapTextures[0])->vk.descriptor, 0, NULL);
|
||||
|
||||
fixme_current_pipeline_index = -1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "vk_cvar.h"
|
||||
#include "vk_pipeline.h"
|
||||
#include "vk_render.h"
|
||||
#include "vk_studio.h"
|
||||
|
||||
#include "xash3d_types.h"
|
||||
#include "cvardef.h"
|
||||
@ -580,16 +581,18 @@ qboolean R_VkInit( void )
|
||||
|
||||
VK_LoadCvars();
|
||||
|
||||
if (!VK_FrameCtlInit())
|
||||
return false;
|
||||
|
||||
if (!VK_RenderInit())
|
||||
return false;
|
||||
|
||||
VK_StudioInit();
|
||||
|
||||
VK_SceneInit();
|
||||
|
||||
initTextures();
|
||||
|
||||
if (!VK_FrameCtlInit())
|
||||
return false;
|
||||
|
||||
// All below need render_pass
|
||||
|
||||
if (!initVk2d())
|
||||
@ -604,14 +607,15 @@ qboolean R_VkInit( void )
|
||||
void R_VkShutdown( void )
|
||||
{
|
||||
VK_BrushShutdown();
|
||||
VK_StudioShutdown();
|
||||
deinitVk2d();
|
||||
|
||||
VK_RenderShutdown();
|
||||
|
||||
VK_FrameCtlShutdown();
|
||||
|
||||
destroyTextures();
|
||||
|
||||
VK_RenderShutdown();
|
||||
|
||||
VK_PipelineShutdown();
|
||||
|
||||
vkDestroyDescriptorPool(vk_core.device, vk_core.descriptor_pool.pool, NULL);
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "vk_buffer.h"
|
||||
#include "vk_const.h"
|
||||
#include "vk_common.h"
|
||||
#include "vk_pipeline.h"
|
||||
#include "vk_textures.h"
|
||||
|
||||
#include "eiface.h"
|
||||
#include "xash3d_mathlib.h"
|
||||
@ -18,11 +20,12 @@ static struct {
|
||||
struct {
|
||||
int align_holes_size;
|
||||
} stat;
|
||||
} g_render;
|
||||
|
||||
static struct {
|
||||
VkPipeline current_pipeline;
|
||||
} g_render_state;
|
||||
uint32_t temp_buffer_offset;
|
||||
|
||||
VkPipelineLayout pipeline_layout;
|
||||
VkPipeline pipelines[kRenderTransAdd + 1];
|
||||
} g_render;
|
||||
|
||||
uniform_data_t *VK_RenderGetUniformSlot(int index)
|
||||
{
|
||||
@ -31,6 +34,165 @@ uniform_data_t *VK_RenderGetUniformSlot(int index)
|
||||
return (uniform_data_t*)(((uint8_t*)g_render.uniform_buffer.mapped) + (g_render.uniform_unit_size * index));
|
||||
}
|
||||
|
||||
static qboolean createPipelines( void )
|
||||
{
|
||||
/* VkPushConstantRange push_const = { */
|
||||
/* .offset = 0, */
|
||||
/* .size = sizeof(AVec3f), */
|
||||
/* .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, */
|
||||
/* }; */
|
||||
|
||||
VkDescriptorSetLayout descriptor_layouts[] = {
|
||||
vk_core.descriptor_pool.one_uniform_buffer_layout,
|
||||
vk_core.descriptor_pool.one_texture_layout,
|
||||
vk_core.descriptor_pool.one_texture_layout,
|
||||
};
|
||||
|
||||
VkPipelineLayoutCreateInfo plci = {
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
.setLayoutCount = ARRAYSIZE(descriptor_layouts),
|
||||
.pSetLayouts = descriptor_layouts,
|
||||
/* .pushConstantRangeCount = 1, */
|
||||
/* .pPushConstantRanges = &push_const, */
|
||||
};
|
||||
|
||||
// FIXME store layout separately
|
||||
XVK_CHECK(vkCreatePipelineLayout(vk_core.device, &plci, NULL, &g_render.pipeline_layout));
|
||||
|
||||
{
|
||||
struct ShaderSpec {
|
||||
float alpha_test_threshold;
|
||||
} spec_data = { .25f };
|
||||
const VkSpecializationMapEntry spec_map[] = {
|
||||
{.constantID = 0, .offset = offsetof(struct ShaderSpec, alpha_test_threshold), .size = sizeof(float) },
|
||||
};
|
||||
|
||||
VkSpecializationInfo alpha_test_spec = {
|
||||
.mapEntryCount = ARRAYSIZE(spec_map),
|
||||
.pMapEntries = spec_map,
|
||||
.dataSize = sizeof(struct ShaderSpec),
|
||||
.pData = &spec_data
|
||||
};
|
||||
|
||||
VkVertexInputAttributeDescription attribs[] = {
|
||||
{.binding = 0, .location = 0, .format = VK_FORMAT_R32G32B32_SFLOAT, .offset = offsetof(brush_vertex_t, pos)},
|
||||
{.binding = 0, .location = 1, .format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(brush_vertex_t, gl_tc)},
|
||||
{.binding = 0, .location = 2, .format = VK_FORMAT_R32G32_SFLOAT, .offset = offsetof(brush_vertex_t, lm_tc)},
|
||||
};
|
||||
|
||||
VkPipelineShaderStageCreateInfo shader_stages[] = {
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.stage = VK_SHADER_STAGE_VERTEX_BIT,
|
||||
.module = loadShader("brush.vert.spv"),
|
||||
.pName = "main",
|
||||
}, {
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.module = loadShader("brush.frag.spv"),
|
||||
.pName = "main",
|
||||
}};
|
||||
|
||||
vk_pipeline_create_info_t ci = {
|
||||
.layout = g_render.pipeline_layout,
|
||||
.attribs = attribs,
|
||||
.num_attribs = ARRAYSIZE(attribs),
|
||||
|
||||
.stages = shader_stages,
|
||||
.num_stages = ARRAYSIZE(shader_stages),
|
||||
|
||||
.vertex_stride = sizeof(brush_vertex_t),
|
||||
|
||||
.depthTestEnable = VK_TRUE,
|
||||
.depthWriteEnable = VK_TRUE,
|
||||
.depthCompareOp = VK_COMPARE_OP_LESS,
|
||||
|
||||
.blendEnable = VK_FALSE,
|
||||
|
||||
.cullMode = VK_CULL_MODE_FRONT_BIT,
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(g_render.pipelines); ++i)
|
||||
{
|
||||
const char *name = "UNDEFINED";
|
||||
switch (i)
|
||||
{
|
||||
case kRenderNormal:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.blendEnable = VK_FALSE;
|
||||
ci.depthWriteEnable = VK_TRUE;
|
||||
name = "brush kRenderNormal";
|
||||
break;
|
||||
|
||||
case kRenderTransColor:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.depthWriteEnable = VK_TRUE;
|
||||
ci.blendEnable = VK_TRUE;
|
||||
ci.colorBlendOp = VK_BLEND_OP_ADD; // TODO check
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
ci.dstAlphaBlendFactor = ci.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
name = "brush kRenderTransColor";
|
||||
break;
|
||||
|
||||
case kRenderTransAdd:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.depthWriteEnable = VK_FALSE;
|
||||
ci.blendEnable = VK_TRUE;
|
||||
ci.colorBlendOp = VK_BLEND_OP_ADD; // TODO check
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
ci.dstAlphaBlendFactor = ci.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||
name = "brush kRenderTransAdd";
|
||||
break;
|
||||
|
||||
case kRenderTransAlpha:
|
||||
ci.stages[1].pSpecializationInfo = &alpha_test_spec;
|
||||
ci.depthWriteEnable = VK_TRUE;
|
||||
ci.blendEnable = VK_FALSE;
|
||||
name = "brush kRenderTransAlpha(test)";
|
||||
break;
|
||||
|
||||
case kRenderGlow:
|
||||
case kRenderTransTexture:
|
||||
ci.stages[1].pSpecializationInfo = NULL;
|
||||
ci.depthWriteEnable = VK_FALSE;
|
||||
ci.blendEnable = VK_TRUE;
|
||||
ci.colorBlendOp = VK_BLEND_OP_ADD; // TODO check
|
||||
ci.srcAlphaBlendFactor = ci.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
|
||||
ci.dstAlphaBlendFactor = ci.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||
name = "brush kRenderTransTexture/Glow";
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(!"Unreachable");
|
||||
}
|
||||
|
||||
g_render.pipelines[i] = createPipeline(&ci);
|
||||
|
||||
if (!g_render.pipelines[i])
|
||||
{
|
||||
// TODO complain
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vk_core.debug)
|
||||
{
|
||||
VkDebugUtilsObjectNameInfoEXT debug_name = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
|
||||
.objectHandle = (uint64_t)g_render.pipelines[i],
|
||||
.objectType = VK_OBJECT_TYPE_PIPELINE,
|
||||
.pObjectName = name,
|
||||
};
|
||||
XVK_CHECK(vkSetDebugUtilsObjectNameEXT(vk_core.device, &debug_name));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)ARRAYSIZE(shader_stages); ++i)
|
||||
vkDestroyShaderModule(vk_core.device, shader_stages[i].module, NULL);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
qboolean VK_RenderInit( void )
|
||||
{
|
||||
// TODO Better estimates
|
||||
@ -66,30 +228,23 @@ qboolean VK_RenderInit( void )
|
||||
vkUpdateDescriptorSets(vk_core.device, ARRAYSIZE(wds), wds, 0, NULL);
|
||||
}
|
||||
|
||||
if (!createPipelines())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VK_RenderShutdown( void )
|
||||
{
|
||||
for (int i = 0; i < ARRAYSIZE(g_render.pipelines); ++i)
|
||||
vkDestroyPipeline(vk_core.device, g_render.pipelines[i], NULL);
|
||||
vkDestroyPipelineLayout( vk_core.device, g_render.pipeline_layout, NULL );
|
||||
|
||||
destroyBuffer( &g_render.buffer );
|
||||
destroyBuffer( &g_render.uniform_buffer );
|
||||
}
|
||||
|
||||
void VK_RenderBindBuffers( void )
|
||||
{
|
||||
const VkDeviceSize offset = 0;
|
||||
vkCmdBindVertexBuffers(vk_core.cb, 0, 1, &g_render.buffer.buffer, &offset);
|
||||
vkCmdBindIndexBuffer(vk_core.cb, g_render.buffer.buffer, 0, VK_INDEX_TYPE_UINT16);
|
||||
}
|
||||
|
||||
void VK_RenderBindUniformBufferWithIndex( VkPipelineLayout pipeline_layout, int index )
|
||||
{
|
||||
const uint32_t dynamic_offset[] = { g_render.uniform_unit_size * index };
|
||||
|
||||
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, vk_core.descriptor_pool.ubo_sets, ARRAYSIZE(dynamic_offset), dynamic_offset);
|
||||
}
|
||||
|
||||
vk_buffer_alloc_t VK_RenderBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
static vk_buffer_alloc_t renderBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
{
|
||||
const uint32_t offset = ALIGN_UP(g_render.buffer_free_offset, unit_size);
|
||||
const uint32_t alloc_size = unit_size * count;
|
||||
@ -108,6 +263,14 @@ vk_buffer_alloc_t VK_RenderBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
return ret;
|
||||
}
|
||||
|
||||
vk_buffer_alloc_t VK_RenderBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
{
|
||||
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");
|
||||
|
||||
return renderBufferAlloc( unit_size, count );
|
||||
}
|
||||
|
||||
void VK_RenderBufferClearAll( void )
|
||||
{
|
||||
g_render.buffer_free_offset = 0;
|
||||
@ -121,3 +284,97 @@ void VK_RenderBufferPrintStats( void )
|
||||
g_render.buffer.size / 1024,
|
||||
g_render.stat.align_holes_size);
|
||||
}
|
||||
|
||||
void VK_RenderTempBufferBegin( void )
|
||||
{
|
||||
g_render.temp_buffer_offset = g_render.buffer_free_offset;
|
||||
}
|
||||
|
||||
vk_buffer_alloc_t VK_RenderTempBufferAlloc( uint32_t unit_size, uint32_t count )
|
||||
{
|
||||
return renderBufferAlloc( unit_size, count );
|
||||
}
|
||||
|
||||
void VK_RenderTempBufferEnd( void )
|
||||
{
|
||||
g_render.buffer_free_offset = g_render.temp_buffer_offset;
|
||||
}
|
||||
|
||||
static struct {
|
||||
int pipeline;
|
||||
int lightmap; // TODO rename to 2nd texture
|
||||
int texture;
|
||||
int ubo_index;
|
||||
} g_render_state;
|
||||
|
||||
void VK_RenderBegin( void ) {
|
||||
g_render_state.pipeline = -1;
|
||||
g_render_state.lightmap = -1;
|
||||
g_render_state.texture = -1;
|
||||
g_render_state.ubo_index = -1;
|
||||
|
||||
{
|
||||
const VkDeviceSize offset = 0;
|
||||
vkCmdBindVertexBuffers(vk_core.cb, 0, 1, &g_render.buffer.buffer, &offset);
|
||||
vkCmdBindIndexBuffer(vk_core.cb, g_render.buffer.buffer, 0, VK_INDEX_TYPE_UINT16);
|
||||
}
|
||||
}
|
||||
|
||||
void VK_RenderDraw( 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.pipeline != draw->render_mode) {
|
||||
g_render_state.pipeline = draw->render_mode;
|
||||
vkCmdBindPipeline(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipelines[g_render_state.pipeline]);
|
||||
}
|
||||
|
||||
if (g_render_state.lightmap != draw->lightmap) {
|
||||
g_render_state.lightmap = draw->lightmap;
|
||||
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipeline_layout, 2, 1, &findTexture(g_render_state.lightmap)->vk.descriptor, 0, NULL);
|
||||
}
|
||||
|
||||
if (g_render_state.texture != draw->texture)
|
||||
{
|
||||
g_render_state.texture = draw->texture;
|
||||
// TODO names/enums for binding points
|
||||
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, "
|
||||
"lightmap=%d, "
|
||||
"texture=%d, "
|
||||
"render_mode=%d, "
|
||||
"element_count=%u, "
|
||||
"index_offset=%u, "
|
||||
"vertex_offset=%u)\n",
|
||||
draw->ubo_index,
|
||||
draw->lightmap,
|
||||
draw->texture,
|
||||
draw->render_mode,
|
||||
draw->element_count,
|
||||
draw->index_offset,
|
||||
draw->vertex_offset );
|
||||
*/
|
||||
|
||||
vkCmdDraw(vk_core.cb, draw->element_count, 1, draw->vertex_offset, 0);
|
||||
} else {
|
||||
vkCmdDrawIndexed(vk_core.cb, draw->element_count, 1, draw->index_offset, draw->vertex_offset, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void VK_RenderEnd( void )
|
||||
{
|
||||
}
|
||||
|
@ -25,8 +25,28 @@ void VK_RenderBufferClearAll( void );
|
||||
qboolean VK_RenderInit( void );
|
||||
void VK_RenderShutdown( void );
|
||||
|
||||
// TODO should this not be global?
|
||||
void VK_RenderBindBuffers( void );
|
||||
void VK_RenderBindUniformBufferWithIndex( VkPipelineLayout pipeline_layout, int index );
|
||||
|
||||
void VK_RenderBufferPrintStats( void );
|
||||
|
||||
// TODO address cringiness of this when doing buffer upload to GPU RAM properly
|
||||
void VK_RenderTempBufferBegin( void );
|
||||
vk_buffer_alloc_t VK_RenderTempBufferAlloc( uint32_t unit_size, uint32_t count );
|
||||
void VK_RenderTempBufferEnd( void );
|
||||
|
||||
// TODO is this a good place?
|
||||
typedef struct brush_vertex_s {
|
||||
vec3_t pos;
|
||||
vec2_t gl_tc;
|
||||
vec2_t lm_tc;
|
||||
} brush_vertex_t;
|
||||
|
||||
typedef struct render_draw_s {
|
||||
int ubo_index;
|
||||
int lightmap, texture;
|
||||
int render_mode;
|
||||
uint32_t element_count;
|
||||
uint32_t index_offset, vertex_offset;
|
||||
} render_draw_t;
|
||||
|
||||
void VK_RenderBegin( void );
|
||||
void VK_RenderDraw( const render_draw_t *draw );
|
||||
void VK_RenderEnd( void );
|
||||
|
@ -369,10 +369,11 @@ static void GL_DrawParticles( const struct ref_viewpass_s *rvp, qboolean trans_
|
||||
{
|
||||
PRINT_NOT_IMPLEMENTED();
|
||||
}
|
||||
static colorVec R_LightVec( const float *start, const float *end, float *lightspot, float *lightvec )
|
||||
|
||||
colorVec R_LightVec( const float *start, const float *end, float *lightspot, float *lightvec )
|
||||
{
|
||||
PRINT_NOT_IMPLEMENTED();
|
||||
return (colorVec){0};
|
||||
return (colorVec){255};
|
||||
}
|
||||
|
||||
static struct mstudiotex_s *R_StudioGetTexture( struct cl_entity_s *e )
|
||||
|
@ -506,11 +506,6 @@ static int drawEntity( cl_entity_t *ent, int render_mode, int ubo_index, const m
|
||||
if( alpha <= 0.0f )
|
||||
return 0;
|
||||
|
||||
// TODO sort by entity type?
|
||||
// TODO other entity types
|
||||
if (mod->type != mod_brush )
|
||||
return 0;
|
||||
|
||||
switch (render_mode) {
|
||||
case kRenderNormal:
|
||||
Vector4Set(ubo->color, 1.f, 1.f, 1.f, 1.f);
|
||||
@ -538,11 +533,28 @@ static int drawEntity( cl_entity_t *ent, int render_mode, int ubo_index, const m
|
||||
Vector4Set(ubo->color, 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 );
|
||||
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 );
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
VK_BrushDrawModel( ent, render_mode, ubo_index );
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -555,7 +567,13 @@ void VK_SceneRender( void )
|
||||
if (!VK_BrushRenderBegin())
|
||||
return;
|
||||
|
||||
VK_RenderTempBufferBegin();
|
||||
|
||||
VK_RenderBegin();
|
||||
|
||||
prepareMatrix( &fixme_rvp, worldview, projection, mvp );
|
||||
|
||||
// Draw world brush
|
||||
{
|
||||
cl_entity_t *world = gEngine.GetEntityByIndex( 0 );
|
||||
if( world && world->model )
|
||||
@ -598,4 +616,8 @@ void VK_SceneRender( void )
|
||||
if (vk_core.debug)
|
||||
vkCmdEndDebugUtilsLabelEXT(vk_core.cb);
|
||||
}
|
||||
|
||||
VK_RenderEnd();
|
||||
|
||||
VK_RenderTempBufferEnd();
|
||||
}
|
||||
|
3606
ref_vk/vk_studio.c
3606
ref_vk/vk_studio.c
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,8 @@ struct model_s;
|
||||
|
||||
void VK_StudioInit( void );
|
||||
void VK_StudioShutdown( void );
|
||||
void VK_StudioRender( const struct ref_viewpass_s *rvp, struct draw_list_s *draw_list );
|
||||
|
||||
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 );
|
||||
|
@ -44,6 +44,7 @@ typedef struct vk_textures_global_s
|
||||
int skyboxbasenum; // start with 5800
|
||||
} vk_textures_global_t;
|
||||
|
||||
// TODO rename this consistently
|
||||
extern vk_textures_global_t tglob;
|
||||
|
||||
// Helper functions
|
||||
|
Loading…
x
Reference in New Issue
Block a user