137 lines
5.0 KiB
C++
137 lines
5.0 KiB
C++
////////////////////////////////////////////////////////////
|
|
//~ Gpu math types
|
|
|
|
#define Pi ((f32)3.14159265358979323846)
|
|
#define Tau ((f32)6.28318530717958647693)
|
|
#define GoldenRatio ((f32)1.61803398874989484820)
|
|
|
|
typedef float2 Vec2;
|
|
typedef float3 Vec3;
|
|
typedef float4 Vec4;
|
|
typedef int2 Vec2I32;
|
|
typedef int3 Vec3I32;
|
|
typedef int4 Vec4I32;
|
|
typedef uint2 Vec2U32;
|
|
typedef uint3 Vec3U32;
|
|
typedef uint4 Vec4U32;
|
|
typedef float2x3 Xform;
|
|
typedef float4 Rect;
|
|
typedef float4 ClipRect;
|
|
typedef float4 Aabb;
|
|
typedef float4 Quad;
|
|
typedef float4x4 Mat4x4;
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Root constants
|
|
|
|
Struct(RootConstants_f32) { f32 c[MaxShaderConstants]; };
|
|
Struct(RootConstants_u32) { u32 c[MaxShaderConstants]; };
|
|
Struct(RootConstants_StructuredBufferHandle) { StructuredBufferHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_RWStructuredBufferHandle) { RWStructuredBufferHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_Texture1DHandle) { Texture1DHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_RWTexture1DHandle) { RWTexture1DHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_Texture2DHandle) { Texture2DHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_RWTexture2DHandle) { RWTexture2DHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_Texture3DHandle) { Texture3DHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_RWTexture3DHandle) { RWTexture3DHandle c[MaxShaderConstants]; };
|
|
Struct(RootConstants_SamplerHandle) { SamplerHandle c[MaxShaderConstants]; };
|
|
|
|
ConstantBuffer<RootConstants_f32> g_root_constants_f32 : register(b0);
|
|
ConstantBuffer<RootConstants_u32> g_root_constants_u32 : register(b0);
|
|
ConstantBuffer<RootConstants_StructuredBufferHandle> g_root_constants_StructuredBufferHandle : register(b0);
|
|
ConstantBuffer<RootConstants_RWStructuredBufferHandle> g_root_constants_RWStructuredBufferHandle : register(b0);
|
|
ConstantBuffer<RootConstants_Texture1DHandle> g_root_constants_Texture1DHandle : register(b0);
|
|
ConstantBuffer<RootConstants_RWTexture1DHandle> g_root_constants_RWTexture1DHandle : register(b0);
|
|
ConstantBuffer<RootConstants_Texture2DHandle> g_root_constants_Texture2DHandle : register(b0);
|
|
ConstantBuffer<RootConstants_RWTexture2DHandle> g_root_constants_RWTexture2DHandle : register(b0);
|
|
ConstantBuffer<RootConstants_Texture3DHandle> g_root_constants_Texture3DHandle : register(b0);
|
|
ConstantBuffer<RootConstants_RWTexture3DHandle> g_root_constants_RWTexture3DHandle : register(b0);
|
|
ConstantBuffer<RootConstants_SamplerHandle> g_root_constants_SamplerHandle : register(b0);
|
|
|
|
#define GetConstant(type, name) (g_root_constants_##type.c[ShaderConstant(type, name)])
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Handle dereference
|
|
|
|
#define ResourceFromUniformHandle(h) ResourceDescriptorHeap[(h)]
|
|
#define ResourceFromNonUniformHandle(h) ResourceDescriptorHeap[NonUniformResourceIndex(h)]
|
|
#define ResourceFromConstantHandle(type, name) ResourceFromUniformHandle(GetConstant(type, name))
|
|
|
|
#define SamplerFromUniformHandle(h) SamplerDescriptorHeap[(h)]
|
|
#define SamplerFromNonUniformHandle(h) SamplerDescriptorHeap[NonUniformResourceIndex(h)]
|
|
#define SamplerFromConstantHandle(type, name) SamplerFromUniformHandle(GetConstant(type, name))
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Texture dimension helpers
|
|
|
|
u32 Count1D(Texture1D tex)
|
|
{
|
|
u32 result;
|
|
tex.GetDimensions(result.x);
|
|
return result;
|
|
}
|
|
|
|
template<typename T>
|
|
u32 Count1D(RWTexture1D<T> tex)
|
|
{
|
|
u32 result;
|
|
tex.GetDimensions(result.x);
|
|
return result;
|
|
}
|
|
|
|
Vec2U32 Count2D(Texture2D tex)
|
|
{
|
|
Vec2U32 result;
|
|
tex.GetDimensions(result.x, result.y);
|
|
return result;
|
|
}
|
|
|
|
template<typename T>
|
|
Vec2U32 Count2D(RWTexture2D<T> tex)
|
|
{
|
|
Vec2U32 result;
|
|
tex.GetDimensions(result.x, result.y);
|
|
return result;
|
|
}
|
|
|
|
Vec3U32 Count3D(Texture3D tex)
|
|
{
|
|
Vec3U32 result;
|
|
tex.GetDimensions(result.x, result.y, result.z);
|
|
return result;
|
|
}
|
|
|
|
template<typename T>
|
|
Vec3U32 Count3D(RWTexture3D<T> tex)
|
|
{
|
|
Vec3U32 result;
|
|
tex.GetDimensions(result.x, result.y, result.z);
|
|
return result;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Vertex ID helpers
|
|
|
|
Vec2 RectUvFromVertexId(u32 id)
|
|
{
|
|
static const Vec2 uvs[4] = {
|
|
Vec2(0, 0),
|
|
Vec2(1, 0),
|
|
Vec2(1, 1),
|
|
Vec2(0, 1)
|
|
};
|
|
return uvs[id];
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
//~ Ndc helpers
|
|
|
|
Vec2 NdcFromPos(Vec2 pos, Vec2 size)
|
|
{
|
|
Vec2 result;
|
|
result = pos / size;
|
|
result *= Vec2(2, -2);
|
|
result += Vec2(-1, 1);
|
|
return result;
|
|
}
|