Skip to content

Commit a2ace64

Browse files
committed
meshletcodec: Fix integer truncation warnings on MSVC
Code that's implicitly converting int/size_t to unsigned char now consistently uses explicit casts. Also, the repack shuffle constant was using 0x80 when calling an intrinsic that accepts signed bytes; use -1 instead as only the top bit matters.
1 parent fbb4978 commit a2ace64

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

‎src/meshletcodec.cpp‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static size_t encodeVertices(unsigned char* ctrl, unsigned char* data, const uns
201201
{
202202
// 1 byte
203203
code = 1;
204-
*data++ = v;
204+
*data++ = (unsigned char)v;
205205
}
206206
else if (v < 65536)
207207
{
@@ -356,8 +356,8 @@ static unsigned char kDecodeTableLength[256];
356356
static bool decodeBuildTables()
357357
{
358358
#define NEXT(var, ec) \
359-
shuf[var] = (ec) ? extra : 15; \
360-
next[var] = (ec) ? 0 : nextoff; \
359+
shuf[var] = (ec) ? (unsigned char)extra : 15; \
360+
next[var] = (ec) ? 0 : (unsigned char)nextoff; \
361361
extra += (ec), nextoff += 1 - (ec)
362362

363363
// check for SSE4.1 support if we have a fallback path
@@ -415,8 +415,8 @@ static bool decodeBuildTables()
415415
int trioff = 6 + k * 3 + (2 - tri / 4) * 3;
416416

417417
// edge cb or ac
418-
shuf[9 + k * 3] = trioff + ((tri & 2) ? 2 : 0);
419-
shuf[10 + k * 3] = trioff + ((tri & 2) ? 1 : 2);
418+
shuf[9 + k * 3] = (unsigned char)(trioff + ((tri & 2) ? 2 : 0));
419+
shuf[10 + k * 3] = (unsigned char)(trioff + ((tri & 2) ? 1 : 2));
420420
}
421421

422422
// third vertex is either next or comes from extra
@@ -436,7 +436,7 @@ static bool decodeBuildTables()
436436
}
437437

438438
// next needs to advance
439-
next[15] = nextoff;
439+
next[15] = (unsigned char)nextoff;
440440

441441
// next[0..8] = 0 trivially (never written to); next[9] must also be 0 because nextoff is 0 initially
442442
// shuf[0..5] is not used, which allows us to pack next[10..15] + shuf[6..15] into a single 16-byte entry
@@ -457,16 +457,16 @@ static bool decodeBuildTables()
457457
int code = (i >> (k * 2)) & 3;
458458
int length = (code == 3) ? 4 : code; // 0/1/2/4 bytes
459459

460-
shuf[k * 4 + 0] = (length > 0) ? offset + 0 : 0x80;
461-
shuf[k * 4 + 1] = (length > 1) ? offset + 1 : 0x80;
462-
shuf[k * 4 + 2] = (length > 2) ? offset + 2 : 0x80;
463-
shuf[k * 4 + 3] = (length > 3) ? offset + 3 : 0x80;
460+
shuf[k * 4 + 0] = (length > 0) ? (unsigned char)(offset + 0) : 0x80;
461+
shuf[k * 4 + 1] = (length > 1) ? (unsigned char)(offset + 1) : 0x80;
462+
shuf[k * 4 + 2] = (length > 2) ? (unsigned char)(offset + 2) : 0x80;
463+
shuf[k * 4 + 3] = (length > 3) ? (unsigned char)(offset + 3) : 0x80;
464464

465465
offset += length;
466466
}
467467

468468
memcpy(kDecodeTableVerts[i], shuf, sizeof(shuf));
469-
kDecodeTableLength[i] = offset;
469+
kDecodeTableLength[i] = (unsigned char)offset;
470470
}
471471

472472
return true;
@@ -486,7 +486,7 @@ static const unsigned char* decodeTrianglesSimd(unsigned int* triangles, const u
486486
// 15: 'next' byte
487487
__m128i state = _mm_setzero_si128();
488488

489-
__m128i repack = _mm_setr_epi8(9, 10, 11, 0x80, 12, 13, 14, 0x80, 0, 0, 0, 0, 0, 0, 0, 0);
489+
__m128i repack = _mm_setr_epi8(9, 10, 11, -1, 12, 13, 14, -1, 0, 0, 0, 0, 0, 0, 0, 0);
490490

491491
for (size_t i = 0; i < triangle_count; i += 2)
492492
{

0 commit comments

Comments
 (0)