aligned for vectorization commor primitives, uint32_t cast for color comparison in batch collection

This commit is contained in:
veclav talica 2024-07-28 22:17:53 +03:00
parent c9f4f85fce
commit 8846e788b2
3 changed files with 17 additions and 9 deletions

View File

@ -105,6 +105,7 @@ else()
-Wdouble-promotion -Wdouble-promotion
-Wconversion -Wno-sign-conversion -Wconversion -Wno-sign-conversion
-Werror=vla -Werror=vla
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Gnu>:-Wcast-align=strict>
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:${WARNING_FLAGS_CLANG}>) $<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:${WARNING_FLAGS_CLANG}>)
set(BUILD_FLAGS set(BUILD_FLAGS

View File

@ -15,6 +15,7 @@
/* interleaved vertex array data */ /* interleaved vertex array data */
/* TODO: use int16_t for uvs */ /* TODO: use int16_t for uvs */
/* TODO: use packed types? */
/* TODO: int16_t could be used for positioning, but we would need to have more CPU calcs */ /* TODO: int16_t could be used for positioning, but we would need to have more CPU calcs */
struct sprite_primitive_payload { struct sprite_primitive_payload {
/* upper-left */ /* upper-left */
@ -113,7 +114,7 @@ static struct sprite_batch {
.constant_colored = true, .constant_colored = true,
}; };
const t_color uniform_color = primitives[0].sprite.color; const uint32_t uniform_color = *(uint32_t *)&primitives[0].sprite.color;
/* batch size is clamped so that reallocated short indices could be used */ /* batch size is clamped so that reallocated short indices could be used */
if (len >= QUAD_ELEMENT_BUFFER_LENGTH) if (len >= QUAD_ELEMENT_BUFFER_LENGTH)
@ -136,10 +137,7 @@ static struct sprite_batch {
break; break;
/* if all are modulated the same we can skip sending the color data */ /* if all are modulated the same we can skip sending the color data */
if (batch.constant_colored && (current->sprite.color.r != uniform_color.r || if (batch.constant_colored && *(uint32_t *)&current->sprite.color == uniform_color)
current->sprite.color.g != uniform_color.g ||
current->sprite.color.b != uniform_color.b ||
current->sprite.color.a != uniform_color.a ))
batch.constant_colored = false; batch.constant_colored = false;
++batch.size; ++batch.size;

View File

@ -70,6 +70,7 @@ bool strends(const char *str, const char *suffix);
/* 32-bit color data */ /* 32-bit color data */
typedef struct color { typedef struct color {
_Alignas(4)
uint8_t r; uint8_t r;
uint8_t g; uint8_t g;
uint8_t b; uint8_t b;
@ -85,14 +86,19 @@ typedef struct vec2 {
/* a point in some space (floating point) */ /* a point in some space (floating point) */
typedef struct fvec2 { typedef struct fvec2 {
float x, y; _Alignas(8)
float x;
float y;
} t_fvec2; } t_fvec2;
/* a point in some three dimension space (floating point) */ /* a point in some three dimension space (floating point) */
/* y goes up, x goes to the right */ /* y goes up, x goes to the right */
typedef struct fvec3 { typedef struct fvec3 {
float x, y, z; _Alignas(8)
float x;
float y;
float z;
} t_fvec3; } t_fvec3;
@ -111,8 +117,11 @@ typedef struct rect {
/* a rectangle with the origin at the upper left (floating point) */ /* a rectangle with the origin at the upper left (floating point) */
typedef struct frect { typedef struct frect {
float x, y; _Alignas(16)
float w, h; float x;
float y;
float w;
float h;
} t_frect; } t_frect;