Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes made during stream E295 #563

Merged
merged 6 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ref/vk/alolcator.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static int splitBlockAt(pool_t *blocks, int index, alo_size_t at) {
}

alo_block_t aloPoolAllocate(struct alo_pool_s* pool, alo_size_t size, alo_size_t alignment) {
alo_block_t ret = {0};
alo_block_t ret = {.offset = ALO_ALLOC_FAILED};
block_t *b;
alignment = alignment > pool->min_alignment ? alignment : pool->min_alignment;
for (int i = pool->first_block; i >= 0; i = b->next) {
Expand Down
2 changes: 1 addition & 1 deletion ref/vk/vk_ray_accel.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static VkAccelerationStructureKHR createAccel(const char *name, VkAccelerationSt
const alo_block_t block = aloPoolAllocate(g_accel.accels_buffer_alloc, size, /*TODO why? align=*/256);

if (block.offset == ALO_ALLOC_FAILED) {
ERR("Failed to allocated %u bytes for blas \"%s\"", size, name);
ERR("Failed to allocate %u bytes for blas \"%s\"", size, name);
return VK_NULL_HANDLE;
}

Expand Down
2 changes: 1 addition & 1 deletion ref/vk/vk_ray_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct vk_combuf_s;
qboolean createOrUpdateAccelerationStructure(struct vk_combuf_s *combuf, const as_build_args_t *args);

#define MAX_SCRATCH_BUFFER (32*1024*1024)
#define MAX_ACCELS_BUFFER (64*1024*1024)
#define MAX_ACCELS_BUFFER (128*1024*1024)

typedef struct {
// Geometry metadata. Lifetime is similar to geometry lifetime itself.
Expand Down
6 changes: 5 additions & 1 deletion ref/vk/vk_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ static void loadLights( const model_t *const map ) {

// Clears all old map data
static void mapLoadBegin( const model_t *const map ) {
VK_EntityDataClear();
R_StudioCacheClear();
R_GeometryBuffer_MapClear();

Expand Down Expand Up @@ -239,6 +238,11 @@ void R_NewMap( void ) {

INFO( "R_NewMap, loading save: %d", is_save_load );

// New map causes entites to be reallocated regardless of whether it was save-load.
// This realloc invalidates all previous entity data and pointers.
// Make sure that EntityData doesn't accidentally reference old pointers.
VK_EntityDataClear();

// Skip clearing already loaded data if the map hasn't changed.
if (is_save_load)
return;
Expand Down
15 changes: 6 additions & 9 deletions ref/vk/vk_sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ static qboolean spriteIsOccluded( const cl_entity_t *e, vec3_t origin, float *ps
if( v[1] < g_camera.viewport[1] || v[1] > g_camera.viewport[1] + g_camera.viewport[3] )
return true; // do scissor

*blend = R_SpriteGlowBlend( origin, e->curstate.rendermode, e->curstate.renderfx, pscale );
*blend *= R_SpriteGlowBlend( origin, e->curstate.rendermode, e->curstate.renderfx, pscale );

if( *blend <= 0.01f )
return true; // faded
Expand Down Expand Up @@ -785,16 +785,17 @@ static vk_render_type_e spriteRenderModeToRenderType( int render_mode ) {
return kVkRenderTypeSolid;
}

static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int texture, int render_mode, const vec4_t color ) {
static void R_DrawSpriteQuad( const char *debug_name, const mspriteframe_t *frame, const vec3_t org, const vec3_t v_right, const vec3_t v_up, float scale, int texture, int render_mode, const vec4_t color ) {
vec3_t v_normal;
CrossProduct(v_right, v_up, v_normal);

// TODO can frame->right/left and frame->up/down be asymmetric?
VectorScale(v_right, frame->right * scale, v_right);
VectorScale(v_up, frame->up * scale, v_up);
vec3_t right, up;
VectorScale(v_right, frame->right * scale, right);
VectorScale(v_up, frame->up * scale, up);

matrix4x4 transform;
Matrix4x4_CreateFromVectors(transform, v_right, v_up, v_normal, org);
Matrix4x4_CreateFromVectors(transform, right, up, v_normal, org);

const vk_render_type_e render_type = spriteRenderModeToRenderType(render_mode);

Expand Down Expand Up @@ -843,10 +844,6 @@ static qboolean R_SpriteAllowLerping( const cl_entity_t *e, msprite_t *psprite )
return false;
*/

// FIXME: lerping means drawing 2 coplanar quads blended on top of each other, which is not something ray tracing can do easily
if (vk_core.rtx)
return false;

if( psprite->numframes <= 1 )
return false;

Expand Down
4 changes: 2 additions & 2 deletions ref/vk/vk_studio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2207,8 +2207,8 @@ static r_studio_entity_model_t *studioEntityModelGet(const cl_entity_t* entity)
return NULL;
}

DEBUG("Created studio entity %p model %s: %p (bodyparts=%d)",
entity, entity->model->name, entmodel, entmodel->bodyparts_count);
DEBUG("Created studio entity %p(%d) model %s: %p (bodyparts=%d)",
entity, entity->index, entity->model->name, entmodel, entmodel->bodyparts_count);

VK_EntityDataSet(entity, entmodel, &studioEntityModelDestroy);
return entmodel;
Expand Down
28 changes: 18 additions & 10 deletions ref/vk/vk_studio_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,28 +259,33 @@ void VK_StudioModelInit(void) {
}

r_studio_submodel_render_t *studioSubmodelRenderModelAcquire(r_studio_submodel_info_t *subinfo) {
const char *mode = "";

r_studio_submodel_render_t *render = NULL;
if (subinfo->cached_head) {
render = subinfo->cached_head;
if (subinfo->is_dynamic) {
subinfo->cached_head = render->_.next;
render->_.next = NULL;
}
subinfo->render_refcount++;
return render;
}

render = Mem_Calloc(vk_core.pool, sizeof(*render));
render->_.info = subinfo;

if (!subinfo->is_dynamic) {
subinfo->cached_head = render;
++g_studio_cache.submodels_cached_static;
mode = "new";
} else {
++g_studio_cache.submodels_cached_dynamic;
render = Mem_Calloc(vk_core.pool, sizeof(*render));
render->_.info = subinfo;

if (!subinfo->is_dynamic) {
subinfo->cached_head = render;
++g_studio_cache.submodels_cached_static;
} else {
++g_studio_cache.submodels_cached_dynamic;
}

mode = "cached";
}

subinfo->render_refcount++;
DEBUG("%s: submodel=%p(%s) %s rendermodel=%p refcount=%d", __FUNCTION__, subinfo->submodel_key, mode, subinfo->submodel_key->name, render, subinfo->render_refcount);
return render;
}

Expand All @@ -291,6 +296,9 @@ void studioSubmodelRenderModelRelease(r_studio_submodel_render_t *render_submode
ASSERT(render_submodel->_.info->render_refcount > 0);
render_submodel->_.info->render_refcount--;

const r_studio_submodel_info_t* const subinfo = render_submodel->_.info;
DEBUG("%s: submodel=%p(%s) rendermodel=%p refcount=%d", __FUNCTION__, subinfo->submodel_key, subinfo->submodel_key->name, render_submodel, subinfo->render_refcount);

if (!render_submodel->_.info->is_dynamic)
return;

Expand Down