Skip to content

Commit

Permalink
Reorganization of the model data handling, see NVIDIA#171
Browse files Browse the repository at this point in the history
- Replaced the arrays of primitive attributes that were specific to BSP or models with a single, unified storage format: VboPrimitive.
- Added support for static models with their own BLAS that never go through the instnace_geometry shader.
- Increased the limits for primitive and mesh counts, removed the limits on BSP or instanced buffer sizes.
- Expanded support for translucent materials, so cl_gunalpha works now.
- Fixed some long-standing resource leaks on map changes.
  • Loading branch information
apanteleev committed Dec 21, 2021
1 parent a59658a commit e7d671d
Show file tree
Hide file tree
Showing 39 changed files with 2,467 additions and 1,898 deletions.
1 change: 0 additions & 1 deletion cmake/compileShaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ set(SHADER_SOURCE_DEPENDENCIES
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/precomputed_sky.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/precomputed_sky_params.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/projection.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/read_visbuf.glsl
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/sky.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/tiny_encryption_algorithm.h
${CMAKE_SOURCE_DIR}/src/refresh/vkpt/shader/tone_mapping_utils.glsl
Expand Down
2 changes: 1 addition & 1 deletion inc/common/bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void BSP_TransformedLightPoint(lightpoint_t *point, vec3_t start, vec3_t end,
#endif

byte *BSP_ClusterVis(bsp_t *bsp, byte *mask, int cluster, int vis);
mleaf_t *BSP_PointLeaf(mnode_t *node, vec3_t p);
mleaf_t *BSP_PointLeaf(mnode_t *node, const vec3_t p);
mmodel_t *BSP_InlineModel(bsp_t *bsp, const char *name);

byte* BSP_GetPvs(bsp_t *bsp, int cluster);
Expand Down
2 changes: 1 addition & 1 deletion inc/common/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static inline int BoxOnPlaneSideFast(vec3_t emins, vec3_t emaxs, cplane_t *p)
return BoxOnPlaneSide(emins, emaxs, p);
}

static inline vec_t PlaneDiffFast(vec3_t v, cplane_t *p)
static inline vec_t PlaneDiffFast(const vec3_t v, cplane_t *p)
{
// fast axial cases
if (p->type < 3) {
Expand Down
2 changes: 1 addition & 1 deletion inc/refresh/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ typedef struct
float* tangents;
byte* colors;
byte* blend_indices; // byte4 per vertex
float* blend_weights; // float4 per vertex
byte* blend_weights; // byte4 per vertex

char* jointNames;
int* jointParents;
Expand Down
2 changes: 1 addition & 1 deletion src/common/bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ byte *BSP_ClusterVis(bsp_t *bsp, byte *mask, int cluster, int vis)
return mask;
}

mleaf_t *BSP_PointLeaf(mnode_t *node, vec3_t p)
mleaf_t *BSP_PointLeaf(mnode_t *node, const vec3_t p)
{
float d;

Expand Down
55 changes: 32 additions & 23 deletions src/refresh/model_iqm.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ int MOD_LoadIQM_Base(model_t* model, const void* rawdata, size_t length, const c
}
}

CHECK(iqmData = (iqm_model_t*)MOD_Malloc(sizeof(iqm_model_t)));
CHECK(iqmData = MOD_Malloc(sizeof(iqm_model_t)));
model->iqmData = iqmData;

// fill header
Expand All @@ -459,20 +459,20 @@ int MOD_LoadIQM_Base(model_t* model, const void* rawdata, size_t length, const c

if (header->num_meshes)
{
CHECK(iqmData->meshes = (iqm_mesh_t*)MOD_Malloc(header->num_meshes * sizeof(iqm_mesh_t)));
CHECK(iqmData->indices = (uint32_t*)MOD_Malloc(header->num_triangles * 3 * sizeof(int)));
CHECK(iqmData->positions = (float*)MOD_Malloc(header->num_vertexes * 3 * sizeof(float)));
CHECK(iqmData->texcoords = (float*)MOD_Malloc(header->num_vertexes * 2 * sizeof(float)));
CHECK(iqmData->normals = (float*)MOD_Malloc(header->num_vertexes * 3 * sizeof(float)));
CHECK(iqmData->meshes = MOD_Malloc(header->num_meshes * sizeof(iqm_mesh_t)));
CHECK(iqmData->indices = MOD_Malloc(header->num_triangles * 3 * sizeof(int)));
CHECK(iqmData->positions = MOD_Malloc(header->num_vertexes * 3 * sizeof(float)));
CHECK(iqmData->texcoords = MOD_Malloc(header->num_vertexes * 2 * sizeof(float)));
CHECK(iqmData->normals = MOD_Malloc(header->num_vertexes * 3 * sizeof(float)));

if (vertexArrayFormat[IQM_TANGENT] != -1)
{
CHECK(iqmData->tangents = (float*)MOD_Malloc(header->num_vertexes * 4 * sizeof(float)));
CHECK(iqmData->tangents = MOD_Malloc(header->num_vertexes * 4 * sizeof(float)));
}

if (vertexArrayFormat[IQM_COLOR] != -1)
{
CHECK(iqmData->colors = (byte*)MOD_Malloc(header->num_vertexes * 4 * sizeof(byte)));
CHECK(iqmData->colors = MOD_Malloc(header->num_vertexes * 4 * sizeof(byte)));
}

if (vertexArrayFormat[IQM_BLENDINDEXES] != -1)
Expand All @@ -482,30 +482,30 @@ int MOD_LoadIQM_Base(model_t* model, const void* rawdata, size_t length, const c

if (vertexArrayFormat[IQM_BLENDWEIGHTS] != -1)
{
CHECK(iqmData->blend_weights = (float*)MOD_Malloc(header->num_vertexes * 4 * sizeof(float)));
CHECK(iqmData->blend_weights = MOD_Malloc(header->num_vertexes * 4 * sizeof(byte)));
}
}

if (header->num_joints)
{
CHECK(iqmData->jointNames = (char*)MOD_Malloc(joint_names));
CHECK(iqmData->jointParents = (int*)MOD_Malloc(header->num_joints * sizeof(int)));
CHECK(iqmData->bindJoints = (float*)MOD_Malloc(header->num_joints * 12 * sizeof(float))); // bind joint matricies
CHECK(iqmData->invBindJoints = (float*)MOD_Malloc(header->num_joints * 12 * sizeof(float))); // inverse bind joint matricies
CHECK(iqmData->jointNames = MOD_Malloc(joint_names));
CHECK(iqmData->jointParents = MOD_Malloc(header->num_joints * sizeof(int)));
CHECK(iqmData->bindJoints = MOD_Malloc(header->num_joints * 12 * sizeof(float))); // bind joint matricies
CHECK(iqmData->invBindJoints = MOD_Malloc(header->num_joints * 12 * sizeof(float))); // inverse bind joint matricies
}

if (header->num_poses)
{
CHECK(iqmData->poses = (iqm_transform_t*)MOD_Malloc(header->num_poses * header->num_frames * sizeof(iqm_transform_t))); // pose transforms
CHECK(iqmData->poses = MOD_Malloc(header->num_poses * header->num_frames * sizeof(iqm_transform_t))); // pose transforms
}

if (header->ofs_bounds)
{
CHECK(iqmData->bounds = (float*)MOD_Malloc(header->num_frames * 6 * sizeof(float))); // model bounds
CHECK(iqmData->bounds = MOD_Malloc(header->num_frames * 6 * sizeof(float))); // model bounds
}
else if (header->num_meshes && header->num_frames == 0)
{
CHECK(iqmData->bounds = (float*)MOD_Malloc(6 * sizeof(float))); // model bounds
CHECK(iqmData->bounds = MOD_Malloc(6 * sizeof(float))); // model bounds
}

if (header->num_meshes)
Expand Down Expand Up @@ -575,20 +575,29 @@ int MOD_LoadIQM_Base(model_t* model, const void* rawdata, size_t length, const c
n * sizeof(float));
break;
case IQM_BLENDWEIGHTS:
if (vertexArrayFormat[IQM_BLENDWEIGHTS] == IQM_FLOAT)
if (vertexArrayFormat[IQM_BLENDWEIGHTS] == IQM_UBYTE)
{
memcpy(iqmData->blend_weights,
(const byte*)header + vertexarray->offset,
n * sizeof(float));
n * sizeof(byte));
}
else
else if(vertexArrayFormat[IQM_BLENDWEIGHTS] == IQM_FLOAT)
{
// convert blend weights from byte to float
for (uint32_t vertex_idx = 0; vertex_idx < 4 * header->num_vertexes; vertex_idx++)
const float* weights = (const float*)((const byte*)header + vertexarray->offset);

// convert blend weights from float to byte
for (uint32_t weight_idx = 0; weight_idx < 4 * header->num_vertexes; weight_idx++)
{
iqmData->blend_weights[vertex_idx] = (float)((const byte*)header + vertexarray->offset)[vertex_idx] / 255.f;
float integer_weight = weights[weight_idx] * 255.f;
clamp(integer_weight, 0.f, 255.f);
iqmData->blend_weights[weight_idx] = (byte)integer_weight;
}
}
else
{
Com_WPrintf("R_LoadIQM: unsupported format for blend weights (%d)\n", vertexArrayFormat[IQM_BLENDWEIGHTS]);
memset(iqmData->blend_weights, 0, n * sizeof(byte));
}
break;
case IQM_COLOR:
memcpy(iqmData->colors,
Expand Down Expand Up @@ -718,7 +727,7 @@ int MOD_LoadIQM_Base(model_t* model, const void* rawdata, size_t length, const c
if (header->num_anims)
{
iqmData->num_animations = header->num_anims;
CHECK(iqmData->animations = (iqm_anim_t*)MOD_Malloc(header->num_anims * sizeof(iqm_anim_t)));
CHECK(iqmData->animations = MOD_Malloc(header->num_anims * sizeof(iqm_anim_t)));

const iqmAnim_t* src = (const iqmAnim_t*)((const byte*)header + header->ofs_anims);
iqm_anim_t* dst = iqmData->animations;
Expand Down
Loading

0 comments on commit e7d671d

Please sign in to comment.