Skip to content

Commit e4e3271

Browse files
committed
tr_surface: prepare Tess_SurfaceIQM() for parallelism
1 parent 8a82817 commit e4e3271

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

src/engine/renderer/tr_surface.cpp

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,7 @@ void Tess_SurfaceIQM( srfIQModel_t *surf ) {
12391239
float *modelTangent = model->tangents + 3 * firstVertex;
12401240
float *modelBitangent = model->bitangents + 3 * firstVertex;
12411241
float *modelTexcoord = model->texcoords + 2 * firstVertex;
1242-
shaderVertex_t *tessVertex = tess.verts + tess.numVertexes;
1243-
shaderVertex_t *lastVertex = tessVertex + surf->num_vertexes;
1242+
shaderVertex_t *modelTessVertex = tess.verts + tess.numVertexes;
12441243

12451244
// Deform the vertices by the lerped bones.
12461245
if ( model->num_joints > 0 && model->blendWeights && model->blendIndexes )
@@ -1252,70 +1251,79 @@ void Tess_SurfaceIQM( srfIQModel_t *surf ) {
12521251
byte *modelBlendIndex = model->blendIndexes + 4 * firstVertex;
12531252
byte *modelBlendWeight = model->blendWeights + 4 * firstVertex;
12541253

1255-
for ( ; tessVertex < lastVertex; tessVertex++,
1256-
modelPosition += 3, modelNormal += 3,
1257-
modelTangent += 3, modelBitangent += 3,
1258-
modelTexcoord += 2 )
1254+
for ( size_t i = 0; i < surf->num_vertexes; i++ )
12591255
{
1260-
vec3_t position = {};
1256+
shaderVertex_t *tessVertex = modelTessVertex + i;
1257+
1258+
float *vertexPosition = modelPosition + 3 * i;
1259+
float *vertexTexcoord = modelTexcoord + 2 * i;
12611260

1262-
byte *lastBlendIndex = modelBlendIndex + 4;
1261+
byte *blendIndex = modelBlendIndex + 4 * i;
1262+
byte *lastBlendIndex = blendIndex + 4;
1263+
byte *blendWeight = modelBlendWeight + 4 * i;
12631264

1264-
for ( ; modelBlendIndex < lastBlendIndex; modelBlendIndex++,
1265-
modelBlendWeight++ )
1265+
vec3_t position = {};
1266+
1267+
for ( ; blendIndex < lastBlendIndex; blendIndex++, blendWeight++ )
12661268
{
1267-
if ( *modelBlendWeight == 0 )
1269+
if ( *blendWeight == 0 )
12681270
{
12691271
continue;
12701272
}
12711273

1272-
float weight = *modelBlendWeight * weightFactor;
1274+
float weight = *blendWeight * weightFactor;
12731275
vec3_t tmp;
12741276

1275-
TransformPoint( &bones[ *modelBlendIndex ], modelPosition, tmp );
1277+
TransformPoint( &bones[ *blendIndex ], vertexPosition, tmp );
12761278
VectorMA( position, weight, tmp, position );
12771279
}
12781280

12791281
VectorCopy( position, tessVertex->xyz );
12801282

1281-
Vector2Copy( modelTexcoord, tessVertex->texCoords );
1283+
Vector2Copy( vertexTexcoord, tessVertex->texCoords );
12821284
}
12831285
}
12841286
else
12851287
{
12861288
byte *modelBlendIndex = model->blendIndexes + 4 * firstVertex;
12871289
byte *modelBlendWeight = model->blendWeights + 4 * firstVertex;
12881290

1289-
for ( ; tessVertex < lastVertex; tessVertex++,
1290-
modelPosition += 3, modelNormal += 3,
1291-
modelTangent += 3, modelBitangent += 3,
1292-
modelTexcoord += 2 )
1291+
for ( size_t i = 0; i < surf->num_vertexes; i++ )
12931292
{
1294-
vec3_t position = {}, tangent = {}, binormal = {}, normal = {};
1293+
shaderVertex_t *tessVertex = modelTessVertex + i;
12951294

1296-
byte *lastBlendIndex = modelBlendIndex + 4;
1295+
float *vertexPosition = modelPosition + 3 * i;
1296+
float *vertexNormal = modelNormal + 3 * i;
1297+
float *vertexTangent = modelTangent + 3 * i;
1298+
float *vertexBitangent = modelBitangent + 3 * i;
1299+
float *vertexTexcoord = modelTexcoord + 2 * i;
12971300

1298-
for ( ; modelBlendIndex < lastBlendIndex; modelBlendIndex++,
1299-
modelBlendWeight++ )
1301+
byte *blendIndex = modelBlendIndex + 4 * i;
1302+
byte *lastBlendIndex = blendIndex + 4;
1303+
byte *blendWeight = modelBlendWeight + 4 * i;
1304+
1305+
vec3_t position = {}, tangent = {}, binormal = {}, normal = {};
1306+
1307+
for ( ; blendIndex < lastBlendIndex; blendIndex++, blendWeight++ )
13001308
{
1301-
if ( *modelBlendWeight == 0 )
1309+
if ( *blendWeight == 0 )
13021310
{
13031311
continue;
13041312
}
13051313

1306-
float weight = *modelBlendWeight * weightFactor;
1314+
float weight = *blendWeight * weightFactor;
13071315
vec3_t tmp;
13081316

1309-
TransformPoint( &bones[ *modelBlendIndex ], modelPosition, tmp );
1317+
TransformPoint( &bones[ *blendIndex ], vertexPosition, tmp );
13101318
VectorMA( position, weight, tmp, position );
13111319

1312-
TransformNormalVector( &bones[ *modelBlendIndex ], modelNormal, tmp );
1320+
TransformNormalVector( &bones[ *blendIndex ], vertexNormal, tmp );
13131321
VectorMA( normal, weight, tmp, normal );
13141322

1315-
TransformNormalVector( &bones[ *modelBlendIndex ], modelTangent, tmp );
1323+
TransformNormalVector( &bones[ *blendIndex ], vertexTangent, tmp );
13161324
VectorMA( tangent, weight, tmp, tangent );
13171325

1318-
TransformNormalVector( &bones[ *modelBlendIndex ], modelBitangent, tmp );
1326+
TransformNormalVector( &bones[ *blendIndex ], vertexBitangent, tmp );
13191327
VectorMA( binormal, weight, tmp, binormal );
13201328
}
13211329

@@ -1326,24 +1334,29 @@ void Tess_SurfaceIQM( srfIQModel_t *surf ) {
13261334

13271335
R_TBNtoQtangentsFast( tangent, binormal, normal, tessVertex->qtangents );
13281336

1329-
Vector2Copy( modelTexcoord, tessVertex->texCoords );
1337+
Vector2Copy( vertexTexcoord, tessVertex->texCoords );
13301338
}
13311339
}
13321340
}
13331341
else
13341342
{
13351343
float scale = model->internalScale * backEnd.currentEntity->e.skeleton.scale;
13361344

1337-
for ( ; tessVertex < lastVertex; tessVertex++,
1338-
modelPosition += 3, modelNormal += 3,
1339-
modelTangent += 3, modelBitangent += 3,
1340-
modelTexcoord += 2 )
1345+
for ( size_t i = 0; i < surf->num_vertexes; i++ )
13411346
{
1342-
VectorScale( modelPosition, scale, tessVertex->xyz );
1347+
shaderVertex_t *tessVertex = modelTessVertex + i;
1348+
1349+
float *vertexPosition = modelPosition + 3 * i;
1350+
float *vertexNormal = modelNormal + 3 * i;
1351+
float *vertexTangent = modelTangent + 3 * i;
1352+
float *vertexBitangent = modelBitangent + 3 * i;
1353+
float *vertexTexcoord = modelTexcoord + 2 * i;
1354+
1355+
VectorScale( vertexPosition, scale, tessVertex->xyz );
13431356

1344-
R_TBNtoQtangentsFast( modelTangent, modelBitangent, modelNormal, tessVertex->qtangents );
1357+
R_TBNtoQtangentsFast( vertexTangent, vertexBitangent, vertexNormal, tessVertex->qtangents );
13451358

1346-
Vector2Copy( modelTexcoord, tessVertex->texCoords );
1359+
Vector2Copy( vertexTexcoord, tessVertex->texCoords );
13471360
}
13481361
}
13491362

0 commit comments

Comments
 (0)