chore: keep strict-aliasing step 1

This commit is contained in:
Hayden Kowalchuk 2019-08-17 17:51:39 -04:00
parent c741d4d622
commit 6b4ac0bc61

View File

@ -98,12 +98,17 @@ typedef struct {
GLboolean is_directional;
} LightSource;
union color_t {
uint8_t bgra[sizeof(uint32_t)];
uint32_t packed;
};
typedef struct {
/* Same 32 byte layout as pvr_vertex_t */
uint32_t flags;
float xyz[3];
float uv[2];
uint8_t bgra[4];
union color_t color;
/* In the pvr_vertex_t structure, this next 4 bytes is oargb
* but we're not using that for now, so having W here makes the code
@ -111,12 +116,14 @@ typedef struct {
float w;
} Vertex;
/* FIXME: SH4 has a swap.w instruction, we should leverage it here! */
#define _SWAP32(x, y) \
#define _SWAP32(type, x, y) \
do { \
uint32_t t = *((uint32_t*) &x); \
*((uint32_t*) &x) = *((uint32_t*) &y); \
*((uint32_t*) &y) = t; \
type t = *((type*) &x); \
*((type*) &x) = *((type*) &y); \
*((type*) &y) = t; \
} while(0)
/*
@ -127,14 +134,14 @@ do { \
#define swapVertex(a, b) \
do { \
_SWAP32(a->flags, b->flags); \
_SWAP32(a->xyz[0], b->xyz[0]); \
_SWAP32(a->xyz[1], b->xyz[1]); \
_SWAP32(a->xyz[2], b->xyz[2]); \
_SWAP32(a->uv[0], b->uv[0]); \
_SWAP32(a->uv[1], b->uv[1]); \
_SWAP32(a->bgra, b->bgra); \
_SWAP32(a->w, b->w); \
_SWAP32(uint32_t, a->flags, b->flags); \
_SWAP32(float, a->xyz[0], b->xyz[0]); \
_SWAP32(float, a->xyz[1], b->xyz[1]); \
_SWAP32(float, a->xyz[2], b->xyz[2]); \
_SWAP32(float, a->uv[0], b->uv[0]); \
_SWAP32(float, a->uv[1], b->uv[1]); \
_SWAP32(uint32_t, a->color.packed, b->color.packed); \
_SWAP32(float, a->w, b->w); \
} while(0)
/* ClipVertex doesn't have room for these, so we need to parse them