70 lines
1.6 KiB
C
70 lines
1.6 KiB
C
#if SH_CPU
|
|
|
|
#define SH_STRUCT(s) PACK(struct s)
|
|
#define SH_DECL(t, n) struct CAT(sh_, t) n
|
|
#define SH_ENTRY(rootsig) static
|
|
#define SH_ASSERT_32BIT(s, n) CT_ASSERT((sizeof(s) / 4) == n)
|
|
|
|
struct sh_uint { u32 v; };
|
|
INLINE struct sh_uint sh_uint_from_u32(u32 v)
|
|
{
|
|
return (struct sh_uint) { .v = v };
|
|
}
|
|
|
|
struct sh_float { f32 v; };
|
|
INLINE struct sh_float sh_float_from_f32(f32 v)
|
|
{
|
|
return (struct sh_float) { .v = v };
|
|
}
|
|
|
|
struct sh_float2 { f32 v[2]; };
|
|
INLINE struct sh_float2 sh_float2_from_v2(struct v2 v)
|
|
{
|
|
return (struct sh_float2) { .v[0] = v.x, .v[1] = v.y };
|
|
}
|
|
|
|
struct sh_float4x4 { f32 v[4][4]; };
|
|
INLINE struct sh_float4x4 sh_float4x4_from_mat4x4(struct mat4x4 v)
|
|
{
|
|
struct sh_float4x4 res;
|
|
CT_ASSERT(sizeof(res) == sizeof(v));
|
|
MEMCPY(&res, v.e, sizeof(res));
|
|
return res;
|
|
}
|
|
|
|
struct sh_float2x3 { f32 v[2][3]; };
|
|
INLINE struct sh_float2x3 sh_float2x3_from_xform(struct xform v)
|
|
{
|
|
struct sh_float2x3 res;
|
|
CT_ASSERT(sizeof(res) == sizeof(v));
|
|
MEMCPY(&res, &v, sizeof(res));
|
|
return res;
|
|
}
|
|
|
|
#else
|
|
|
|
#define SH_STRUCT(s) struct s
|
|
#define SH_DECL(t, n) t n
|
|
#define SH_ENTRY(rootsig) [RootSignature(rootsig)]
|
|
#define SH_ASSERT_32BIT(s, n)
|
|
|
|
#endif
|
|
|
|
/* ========================== *
|
|
* Material shader structs
|
|
* ========================== */
|
|
|
|
SH_STRUCT(sh_material_constants {
|
|
SH_DECL(float4x4, projection);
|
|
});
|
|
SH_ASSERT_32BIT(struct sh_material_constants, 16); /* Expected 32bit root constant size in shader */
|
|
|
|
SH_STRUCT(sh_material_instance {
|
|
SH_DECL(float2x3, xf);
|
|
SH_DECL(float2, uv0);
|
|
SH_DECL(float2, uv1);
|
|
SH_DECL(uint, texture_nuri);
|
|
SH_DECL(uint, tint_srgb);
|
|
SH_DECL(float, emittance);
|
|
});
|