parameter-isolated root constants
This commit is contained in:
parent
0d1d46faa3
commit
8fbcb004fb
@ -510,11 +510,10 @@
|
|||||||
typedef double f64;
|
typedef double f64;
|
||||||
typedef i8 b8;
|
typedef i8 b8;
|
||||||
typedef u32 b32;
|
typedef u32 b32;
|
||||||
|
Struct(U128) { u64 hi; u64 lo; };
|
||||||
#elif IsLanguageGpu
|
#elif IsLanguageGpu
|
||||||
typedef int i32;
|
typedef int i32;
|
||||||
typedef int2 i64;
|
|
||||||
typedef uint u32;
|
typedef uint u32;
|
||||||
typedef uint2 u64;
|
|
||||||
typedef float f32;
|
typedef float f32;
|
||||||
typedef uint b32;
|
typedef uint b32;
|
||||||
#endif
|
#endif
|
||||||
@ -698,15 +697,6 @@
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ U128 types
|
|
||||||
|
|
||||||
Struct(U128)
|
|
||||||
{
|
|
||||||
u64 hi;
|
|
||||||
u64 lo;
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Resource types
|
//~ Resource types
|
||||||
|
|
||||||
@ -727,22 +717,21 @@ Struct(U128)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Shader types
|
//~ Shader types
|
||||||
|
|
||||||
/* D3D12 - 64 maximum root constants
|
|
||||||
* Vulkan - 32 maximum push constants
|
|
||||||
*/
|
|
||||||
#define MaxShaderConstants (32)
|
|
||||||
|
|
||||||
#define ShaderConstant(type, name) name##__shaderconst__##type
|
|
||||||
|
|
||||||
#if IsLanguageC
|
|
||||||
//- Shader linkage
|
//- Shader linkage
|
||||||
|
#if IsLanguageC
|
||||||
Struct(VertexShader) { ResourceKey resource; };
|
Struct(VertexShader) { ResourceKey resource; };
|
||||||
Struct(PixelShader) { ResourceKey resource; };
|
Struct(PixelShader) { ResourceKey resource; };
|
||||||
Struct(ComputeShader) { ResourceKey resource; };
|
Struct(ComputeShader) { ResourceKey resource; };
|
||||||
|
#elif IsLanguageGpu
|
||||||
|
#define Semantic(t, n) t n : n
|
||||||
|
#define ComputeShader(name, x) [numthreads(x, 1, 1)] void name(Semantic(u32, SV_DispatchThreadID))
|
||||||
|
#define ComputeShader2D(name, x, y) [numthreads(x, y, 1)] void name(Semantic(Vec2U32, SV_DispatchThreadID))
|
||||||
|
#define ComputeShader3D(name, x, y, z) [numthreads(x, y, z)] void name(Semantic(Vec3U32, SV_DispatchThreadID))
|
||||||
|
#define VertexShader(name, return_type) return_type name(Semantic(u32, SV_InstanceID), Semantic(u32, SV_VertexID))
|
||||||
|
#define PixelShader(name, return_type, ...) return_type name(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
//- Shader object handles
|
//- Shader resource handles
|
||||||
|
|
||||||
Struct(StructuredBufferHandle) { u32 v; };
|
Struct(StructuredBufferHandle) { u32 v; };
|
||||||
Struct(RWStructuredBufferHandle) { u32 v; };
|
Struct(RWStructuredBufferHandle) { u32 v; };
|
||||||
Struct(Texture1DHandle) { u32 v; };
|
Struct(Texture1DHandle) { u32 v; };
|
||||||
@ -751,35 +740,24 @@ Struct(U128)
|
|||||||
Struct(RWTexture2DHandle) { u32 v; };
|
Struct(RWTexture2DHandle) { u32 v; };
|
||||||
Struct(Texture3DHandle) { u32 v; };
|
Struct(Texture3DHandle) { u32 v; };
|
||||||
Struct(RWTexture3DHandle) { u32 v; };
|
Struct(RWTexture3DHandle) { u32 v; };
|
||||||
Struct(SamplerHandle) { u32 v; };
|
Struct(SamplerStateHandle) { u32 v; };
|
||||||
|
|
||||||
#define IsGpuHandleNil(h) ((h).v == 0)
|
#define IsGpuHandleNil(h) ((h).v == 0)
|
||||||
|
|
||||||
|
//- Shader constants
|
||||||
|
|
||||||
|
/* D3D12 - 64 maximum root constants
|
||||||
|
* Vulkan - 32 maximum push constants
|
||||||
|
*/
|
||||||
|
#define MaxShaderConstants (32)
|
||||||
|
|
||||||
|
#if IsLanguageC
|
||||||
|
#define ShaderConstant(type, name, slot) \
|
||||||
|
StaticAssert(sizeof(type) <= 4); \
|
||||||
|
StaticAssert(slot < MaxShaderConstants); \
|
||||||
|
Enum(name##__shaderconstantenum) { name = slot }; \
|
||||||
|
Struct(name##__shaderconstanttype) { type v; }
|
||||||
#elif IsLanguageGpu
|
#elif IsLanguageGpu
|
||||||
//- Shader declaration
|
#define ShaderConstant(type, name, slot) cbuffer name : register(b##slot) { type name; }
|
||||||
|
|
||||||
#define ComputeShader(name, x) [numthreads(x, 1, 1)] void name(Semantic(u32, SV_DispatchThreadID))
|
|
||||||
#define ComputeShader2D(name, x, y) [numthreads(x, y, 1)] void name(Semantic(Vec2U32, SV_DispatchThreadID))
|
|
||||||
#define ComputeShader3D(name, x, y, z) [numthreads(x, y, z)] void name(Semantic(Vec3U32, SV_DispatchThreadID))
|
|
||||||
#define VertexShader(name, return_type) return_type name(Semantic(u32, SV_InstanceID), Semantic(u32, SV_VertexID))
|
|
||||||
#define PixelShader(name, return_type, ...) return_type name(__VA_ARGS__)
|
|
||||||
|
|
||||||
//- Semantic declaration
|
|
||||||
|
|
||||||
# define Semantic(t, n) t n : n
|
|
||||||
|
|
||||||
//- Shader object handles
|
|
||||||
|
|
||||||
typedef u32 StructuredBufferHandle;
|
|
||||||
typedef u32 RWStructuredBufferHandle;
|
|
||||||
typedef u32 Texture1DHandle;
|
|
||||||
typedef u32 RWTexture1DHandle;
|
|
||||||
typedef u32 Texture2DHandle;
|
|
||||||
typedef u32 RWTexture2DHandle;
|
|
||||||
typedef u32 Texture3DHandle;
|
|
||||||
typedef u32 RWTexture3DHandle;
|
|
||||||
typedef u32 SamplerHandle;
|
|
||||||
|
|
||||||
#define IsGpuHandleNil(h) ((h) == 0)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -1,9 +1,3 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ Exit callback types
|
|
||||||
|
|
||||||
#define ExitFuncDef(name) void name(void)
|
|
||||||
typedef ExitFuncDef(ExitFunc);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdecl Swap hooks
|
//~ @hookdecl Swap hooks
|
||||||
|
|
||||||
|
|||||||
@ -21,45 +21,30 @@ typedef float4 Aabb;
|
|||||||
typedef float4 Quad;
|
typedef float4 Quad;
|
||||||
typedef float4x4 Mat4x4;
|
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
|
//~ Handle dereference
|
||||||
|
|
||||||
#define ResourceFromUniformHandle(h) ResourceDescriptorHeap[(h)]
|
//- Uniform resource access
|
||||||
#define ResourceFromNonUniformHandle(h) ResourceDescriptorHeap[NonUniformResourceIndex(h)]
|
template<typename T> StructuredBuffer<T> StructuredBufferFromUniformHandle(StructuredBufferHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
#define ResourceFromConstantHandle(type, name) ResourceFromUniformHandle(GetConstant(type, name))
|
template<typename T> RWStructuredBuffer<T> RWStructuredBufferFromUniformHandle(RWStructuredBufferHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
|
template<typename T> Texture1D<T> Texture1DFromUniformHandle(Texture1DHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
|
template<typename T> RWTexture1D<T> RWTexture1DFromUniformHandle(RWTexture1DHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
|
template<typename T> Texture2D<T> Texture2DFromUniformHandle(Texture2DHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
|
template<typename T> RWTexture2D<T> RWTexture2DFromUniformHandle(RWTexture2DHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
|
template<typename T> Texture3D<T> Texture3DFromUniformHandle(Texture3DHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
|
template<typename T> RWTexture3D<T> RWTexture3DFromUniformHandle(RWTexture3DHandle h) { return ResourceDescriptorHeap[h.v]; }
|
||||||
|
SamplerState SamplerStateFromUniformHandle(SamplerStateHandle h) { return SamplerDescriptorHeap[h.v]; }
|
||||||
|
|
||||||
#define SamplerFromUniformHandle(h) SamplerDescriptorHeap[(h)]
|
//- Non-uniform resource access
|
||||||
#define SamplerFromNonUniformHandle(h) SamplerDescriptorHeap[NonUniformResourceIndex(h)]
|
template<typename T> StructuredBuffer<T> StructuredBufferFromNonUniformHandle(StructuredBufferHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
#define SamplerFromConstantHandle(type, name) SamplerFromUniformHandle(GetConstant(type, name))
|
template<typename T> RWStructuredBuffer<T> RWStructuredBufferFromNonUniformHandle(RWStructuredBufferHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
template<typename T> Texture1D<T> Texture1DFromNonUniformHandle(Texture1DHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
template<typename T> RWTexture1D<T> RWTexture1DFromNonUniformHandle(RWTexture1DHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
template<typename T> Texture2D<T> Texture2DFromNonUniformHandle(Texture2DHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
template<typename T> RWTexture2D<T> RWTexture2DFromNonUniformHandle(RWTexture2DHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
template<typename T> Texture3D<T> Texture3DFromNonUniformHandle(Texture3DHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
template<typename T> RWTexture3D<T> RWTexture3DFromNonUniformHandle(RWTexture3DHandle h) { return ResourceDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
SamplerState SamplerStateFromNonUniformHandle(SamplerStateHandle h) { return SamplerDescriptorHeap[NonUniformResourceIndex(h.v)]; }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Texture dimension helpers
|
//~ Texture dimension helpers
|
||||||
|
|||||||
@ -72,7 +72,7 @@ void GPU_CopyResourceFromCpu(GPU_CommandListHandle cl, GPU_ResourceHandle dst, S
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Common resource helpers
|
//~ Common resource helpers
|
||||||
|
|
||||||
SamplerHandle GPU_GetCommonPointSampler(void)
|
SamplerStateHandle GPU_GetCommonPointSampler(void)
|
||||||
{
|
{
|
||||||
return GPU_shared_util_state.pt_sampler;
|
return GPU_shared_util_state.pt_sampler;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
Struct(GPU_SharedUtilState)
|
Struct(GPU_SharedUtilState)
|
||||||
{
|
{
|
||||||
/* Common shared resources */
|
/* Common shared resources */
|
||||||
SamplerHandle pt_sampler;
|
SamplerStateHandle pt_sampler;
|
||||||
GPU_IndexBufferDesc quad_indices;
|
GPU_IndexBufferDesc quad_indices;
|
||||||
Texture3DHandle noise_tex;
|
Texture3DHandle noise_tex;
|
||||||
|
|
||||||
@ -29,6 +29,6 @@ void GPU_CopyResourceFromCpu(GPU_CommandListHandle cl, GPU_ResourceHandle dst, S
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Common resource helpers
|
//~ Common resource helpers
|
||||||
|
|
||||||
SamplerHandle GPU_GetCommonPointSampler(void);
|
SamplerStateHandle GPU_GetCommonPointSampler(void);
|
||||||
GPU_IndexBufferDesc GPU_GetCommonQuadIndices(void);
|
GPU_IndexBufferDesc GPU_GetCommonQuadIndices(void);
|
||||||
Texture3DHandle GPU_GetCommonNoise(void);
|
Texture3DHandle GPU_GetCommonNoise(void);
|
||||||
|
|||||||
@ -543,7 +543,7 @@ b32 GPU_IsResourceNil(GPU_ResourceHandle handle);
|
|||||||
} \
|
} \
|
||||||
)
|
)
|
||||||
|
|
||||||
//- Shader handle creation
|
//- Shader resource handle creation
|
||||||
|
|
||||||
StructuredBufferHandle GPU_PushStructuredBufferHandleEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
StructuredBufferHandle GPU_PushStructuredBufferHandleEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||||
RWStructuredBufferHandle GPU_PushRWStructuredBufferHandleEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
RWStructuredBufferHandle GPU_PushRWStructuredBufferHandleEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||||
@ -553,19 +553,19 @@ Texture2DHandle GPU_PushTexture2DHandle (GPU_ArenaHandle
|
|||||||
RWTexture2DHandle GPU_PushRWTexture2DHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
RWTexture2DHandle GPU_PushRWTexture2DHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||||
Texture3DHandle GPU_PushTexture3DHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
Texture3DHandle GPU_PushTexture3DHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||||
RWTexture3DHandle GPU_PushRWTexture3DHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
RWTexture3DHandle GPU_PushRWTexture3DHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||||
SamplerHandle GPU_PushSamplerHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
SamplerStateHandle GPU_PushSamplerStateHandle (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||||
|
|
||||||
#define GPU_PushStructuredBufferHandle(arena, resource, type) GPU_PushStructuredBufferHandleEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
|
#define GPU_PushStructuredBufferHandle(arena, resource, type) GPU_PushStructuredBufferHandleEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
|
||||||
#define GPU_PushRWStructuredBufferHandle(arena, resource, type) GPU_PushRWStructuredBufferHandleEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
|
#define GPU_PushRWStructuredBufferHandle(arena, resource, type) GPU_PushRWStructuredBufferHandleEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
|
||||||
|
|
||||||
//- Count
|
//- Count
|
||||||
|
|
||||||
u64 GPU_CountBufferEx(GPU_ResourceHandle buffer, u64 element_size);
|
u64 GPU_CountBufferBytes(GPU_ResourceHandle buffer);
|
||||||
u64 GPU_Count1D(GPU_ResourceHandle texture1d);
|
u64 GPU_Count1D(GPU_ResourceHandle texture1d);
|
||||||
u64 GPU_Count2D(GPU_ResourceHandle texture2d);
|
u64 GPU_Count2D(GPU_ResourceHandle texture2d);
|
||||||
u64 GPU_Count3D(GPU_ResourceHandle texture3d);
|
u64 GPU_Count3D(GPU_ResourceHandle texture3d);
|
||||||
|
|
||||||
#define GPU_CountBuffer(buffer, type) GPU_CountBufferEx((buffer), sizeof(type))
|
#define GPU_CountBuffer(buffer, type) GPU_CountBufferSize(buffer) / sizeof(type)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdecl Command
|
//~ @hookdecl Command
|
||||||
@ -574,6 +574,7 @@ u64 GPU_Count3D(GPU_ResourceHandle texture3d);
|
|||||||
|
|
||||||
GPU_CommandListHandle GPU_PrepareCommandList(void);
|
GPU_CommandListHandle GPU_PrepareCommandList(void);
|
||||||
void GPU_CommitCommandListEx(GPU_CommandListHandle cl, GPU_QueueKind queue, u64 fence_ops_count, GPU_FenceOp *fence_ops);
|
void GPU_CommitCommandListEx(GPU_CommandListHandle cl, GPU_QueueKind queue, u64 fence_ops_count, GPU_FenceOp *fence_ops);
|
||||||
|
|
||||||
#define GPU_CommitCommandList(cl, queue) GPU_CommitCommandListEx((cl), (queue), 0, 0)
|
#define GPU_CommitCommandList(cl, queue) GPU_CommitCommandListEx((cl), (queue), 0, 0)
|
||||||
|
|
||||||
//- Arena
|
//- Arena
|
||||||
@ -590,31 +591,15 @@ void GPU_CopyCpuTexels(GPU_CommandListHandle cl, GPU_ResourceHandle dst, Vec3I32
|
|||||||
void GPU_CopyBytes(GPU_CommandListHandle cl, GPU_ResourceHandle dst, u64 dst_offset, GPU_ResourceHandle src, RngU64 src_copy_range);
|
void GPU_CopyBytes(GPU_CommandListHandle cl, GPU_ResourceHandle dst, u64 dst_offset, GPU_ResourceHandle src, RngU64 src_copy_range);
|
||||||
void GPU_CopyTexels(GPU_CommandListHandle cl, GPU_ResourceHandle dst, Vec3I32 dst_offset, GPU_ResourceHandle src, Rng3I32 src_copy_range);
|
void GPU_CopyTexels(GPU_CommandListHandle cl, GPU_ResourceHandle dst, Vec3I32 dst_offset, GPU_ResourceHandle src, Rng3I32 src_copy_range);
|
||||||
|
|
||||||
//- Constants
|
//- Constant
|
||||||
|
|
||||||
void GPU_SetConstantU32_ (GPU_CommandListHandle cl, i32 slot, u32 v);
|
void GPU_SetConstant_(GPU_CommandListHandle cl, i32 slot, void *src_32bit, u32 size);
|
||||||
void GPU_SetConstantF32_ (GPU_CommandListHandle cl, i32 slot, f32 v);
|
|
||||||
void GPU_SetConstantStructuredBufferHandle_ (GPU_CommandListHandle cl, i32 slot, StructuredBufferHandle v);
|
|
||||||
void GPU_SetConstantRWStructuredBufferHandle_ (GPU_CommandListHandle cl, i32 slot, RWStructuredBufferHandle v);
|
|
||||||
void GPU_SetConstantTexture1DHandle_ (GPU_CommandListHandle cl, i32 slot, Texture1DHandle v);
|
|
||||||
void GPU_SetConstantRWTexture1DHandle_ (GPU_CommandListHandle cl, i32 slot, RWTexture1DHandle v);
|
|
||||||
void GPU_SetConstantTexture2DHandle_ (GPU_CommandListHandle cl, i32 slot, Texture2DHandle v);
|
|
||||||
void GPU_SetConstantRWTexture2DHandle_ (GPU_CommandListHandle cl, i32 slot, RWTexture2DHandle v);
|
|
||||||
void GPU_SetConstantTexture3DHandle_ (GPU_CommandListHandle cl, i32 slot, Texture3DHandle v);
|
|
||||||
void GPU_SetConstantRWTexture3DHandle_ (GPU_CommandListHandle cl, i32 slot, RWTexture3DHandle v);
|
|
||||||
void GPU_SetConstantSamplerHandle_ (GPU_CommandListHandle cl, i32 slot, SamplerHandle v);
|
|
||||||
|
|
||||||
#define GPU_SetConstantU32(cl, name, v) GPU_SetConstantU32_((cl), ShaderConstant(u32, name), (v))
|
#define GPU_SetConstant(cl, name, value) do { \
|
||||||
#define GPU_SetConstantF32(cl, name, v) GPU_SetConstantF32_((cl), ShaderConstant(f32, name), (v))
|
name##__shaderconstanttype __src; \
|
||||||
#define GPU_SetConstantStructuredBufferHandle(cl, name, v) GPU_SetConstantStructuredBufferHandle_((cl), ShaderConstant(StructuredBufferHandle, name), (v))
|
__src.v = value; \
|
||||||
#define GPU_SetConstantRWStructuredBufferHandle(cl, name, v) GPU_SetConstantRWStructuredBufferHandle_((cl), ShaderConstant(RWStructuredBufferHandle, name), (v))
|
GPU_SetConstant_((cl), (name), &__src, sizeof(__src)); \
|
||||||
#define GPU_SetConstantTexture1DHandle(cl, name, v) GPU_SetConstantTexture1DHandle_((cl), ShaderConstant(Texture1DHandle, name), (v))
|
} while (0)
|
||||||
#define GPU_SetConstantRWTexture1DHandle(cl, name, v) GPU_SetConstantRWTexture1DHandle_((cl), ShaderConstant(RWTexture1DHandle, name), (v))
|
|
||||||
#define GPU_SetConstantTexture2DHandle(cl, name, v) GPU_SetConstantTexture2DHandle_((cl), ShaderConstant(Texture2DHandle, name), (v))
|
|
||||||
#define GPU_SetConstantRWTexture2DHandle(cl, name, v) GPU_SetConstantRWTexture2DHandle_((cl), ShaderConstant(RWTexture2DHandle, name), (v))
|
|
||||||
#define GPU_SetConstantTexture3DHandle(cl, name, v) GPU_SetConstantTexture3DHandle_((cl), ShaderConstant(Texture3DHandle, name), (v))
|
|
||||||
#define GPU_SetConstantRWTexture3DHandle(cl, name, v) GPU_SetConstantRWTexture3DHandle_((cl), ShaderConstant(RWTexture3DHandle, name), (v))
|
|
||||||
#define GPU_SetConstantSamplerHandle(cl, name, v) GPU_SetConstantSamplerHandle_((cl), ShaderConstant(SamplerHandle, name), (v))
|
|
||||||
|
|
||||||
//- Barrier
|
//- Barrier
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
GPU_D12_SharedState GPU_D12_shared_state = ZI;
|
GPU_D12_SharedState GPU_D12_shared_state = ZI;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Startup
|
//~ @hookimpl Startup
|
||||||
|
|
||||||
void GPU_D12_Startup(void)
|
void GPU_Startup(void)
|
||||||
{
|
{
|
||||||
GPU_D12_SharedState *g = &GPU_D12_shared_state;
|
GPU_D12_SharedState *g = &GPU_D12_shared_state;
|
||||||
TempArena scratch = BeginScratchNoConflict();
|
TempArena scratch = BeginScratchNoConflict();
|
||||||
@ -254,16 +254,20 @@ void GPU_D12_Startup(void)
|
|||||||
{
|
{
|
||||||
__profn("Serialize root signature");
|
__profn("Serialize root signature");
|
||||||
|
|
||||||
D3D12_ROOT_PARAMETER param = ZI;
|
D3D12_ROOT_PARAMETER params[MaxShaderConstants] = ZI;
|
||||||
param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
|
for (i32 slot = 0; slot < MaxShaderConstants; ++slot)
|
||||||
param.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
|
{
|
||||||
param.Constants.ShaderRegister = 0;
|
D3D12_ROOT_PARAMETER *param = ¶ms[slot];
|
||||||
param.Constants.RegisterSpace = 0;
|
param->ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
|
||||||
param.Constants.Num32BitValues = 64;
|
param->ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
|
||||||
|
param->Constants.ShaderRegister = slot;
|
||||||
|
param->Constants.RegisterSpace = 0;
|
||||||
|
param->Constants.Num32BitValues = 1;
|
||||||
|
}
|
||||||
|
|
||||||
D3D12_ROOT_SIGNATURE_DESC desc = ZI;
|
D3D12_ROOT_SIGNATURE_DESC desc = ZI;
|
||||||
desc.NumParameters = 1;
|
desc.NumParameters = countof(params);
|
||||||
desc.pParameters = ¶m;
|
desc.pParameters = params;
|
||||||
desc.NumStaticSamplers = 0;
|
desc.NumStaticSamplers = 0;
|
||||||
desc.pStaticSamplers = 0;
|
desc.pStaticSamplers = 0;
|
||||||
desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED;
|
desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED;
|
||||||
@ -729,14 +733,6 @@ void GPU_D12_CommitRawCommandList(GPU_D12_RawCommandList *cl)
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ @hookimpl Startup hook
|
|
||||||
|
|
||||||
void GPU_Startup(void)
|
|
||||||
{
|
|
||||||
GPU_D12_Startup();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookimpl Fence hooks
|
//~ @hookimpl Fence hooks
|
||||||
|
|
||||||
@ -1312,15 +1308,15 @@ RWTexture3DHandle GPU_PushRWTexture3DHandle(GPU_ArenaHandle arena, GPU_ResourceH
|
|||||||
return (RWTexture3DHandle) { 0 };
|
return (RWTexture3DHandle) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
SamplerHandle GPU_PushSamplerHandle(GPU_ArenaHandle arena, GPU_ResourceHandle resource)
|
SamplerStateHandle GPU_PushSamplerStateHandle(GPU_ArenaHandle arena, GPU_ResourceHandle resource)
|
||||||
{
|
{
|
||||||
/* TODO */
|
/* TODO */
|
||||||
return (SamplerHandle) { 0 };
|
return (SamplerStateHandle) { 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Count
|
//- Count
|
||||||
|
|
||||||
u64 GPU_CountBufferEx(GPU_ResourceHandle buffer, u64 element_size)
|
u64 GPU_CountBufferBytes(GPU_ResourceHandle buffer)
|
||||||
{
|
{
|
||||||
/* TODO */
|
/* TODO */
|
||||||
return 0;
|
return 0;
|
||||||
@ -1448,9 +1444,12 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, GPU_QueueKind queu
|
|||||||
GPU_D12_Pipeline *bound_pipeline = 0;
|
GPU_D12_Pipeline *bound_pipeline = 0;
|
||||||
|
|
||||||
/* Constants state */
|
/* Constants state */
|
||||||
u32 slotted_constants[MaxShaderConstants] = ZI;
|
u64 slotted_constants[MaxShaderConstants];
|
||||||
u32 bound_graphics_constants[MaxShaderConstants] = ZI;
|
u64 bound_compute_constants[MaxShaderConstants];
|
||||||
u32 bound_compute_constants[MaxShaderConstants] = ZI;
|
u64 bound_graphics_constants[MaxShaderConstants];
|
||||||
|
for (i32 i = 0; i < countof(slotted_constants); ++i) { slotted_constants[i] = U64Max; }
|
||||||
|
for (i32 i = 0; i < countof(bound_compute_constants); ++i) { bound_compute_constants[i] = U64Max; }
|
||||||
|
for (i32 i = 0; i < countof(bound_graphics_constants); ++i) { bound_graphics_constants[i] = U64Max; }
|
||||||
|
|
||||||
/* Rasterizer state */
|
/* Rasterizer state */
|
||||||
D3D12_VIEWPORT bound_viewport = ZI;
|
D3D12_VIEWPORT bound_viewport = ZI;
|
||||||
@ -1567,7 +1566,7 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, GPU_QueueKind queu
|
|||||||
{
|
{
|
||||||
i32 slot = cmd->constant.slot;
|
i32 slot = cmd->constant.slot;
|
||||||
u32 value = cmd->constant.value;
|
u32 value = cmd->constant.value;
|
||||||
if (slot > 0 && slot < countof(slotted_constants) && slotted_constants[slot] != value)
|
if (slot >= 0 && slot < countof(slotted_constants))
|
||||||
{
|
{
|
||||||
slotted_constants[slot] = value;
|
slotted_constants[slot] = value;
|
||||||
}
|
}
|
||||||
@ -1777,8 +1776,6 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, GPU_QueueKind queu
|
|||||||
if (!compute_rootsig_set)
|
if (!compute_rootsig_set)
|
||||||
{
|
{
|
||||||
ID3D12GraphicsCommandList_SetComputeRootSignature(d3d_cl, g->bindless_rootsig);
|
ID3D12GraphicsCommandList_SetComputeRootSignature(d3d_cl, g->bindless_rootsig);
|
||||||
ID3D12GraphicsCommandList_SetComputeRoot32BitConstants(d3d_cl, 0, MaxShaderConstants, slotted_constants, 0);
|
|
||||||
CopyBytes(bound_compute_constants, slotted_constants, sizeof(bound_compute_constants));
|
|
||||||
compute_rootsig_set = 1;
|
compute_rootsig_set = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1792,11 +1789,10 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, GPU_QueueKind queu
|
|||||||
/* Update root constants */
|
/* Update root constants */
|
||||||
for (i32 slot = 0; slot < MaxShaderConstants; ++slot)
|
for (i32 slot = 0; slot < MaxShaderConstants; ++slot)
|
||||||
{
|
{
|
||||||
u32 v = slotted_constants[slot];
|
if (bound_compute_constants[slot] != slotted_constants[slot])
|
||||||
if (bound_compute_constants[slot] != v)
|
|
||||||
{
|
{
|
||||||
ID3D12GraphicsCommandList_SetComputeRoot32BitConstant(d3d_cl, 0, v, slot);
|
ID3D12GraphicsCommandList_SetComputeRoot32BitConstant(d3d_cl, slot, slotted_constants[slot], 0);
|
||||||
bound_compute_constants[slot] = v;
|
bound_compute_constants[slot] = slotted_constants[slot];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1893,8 +1889,6 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, GPU_QueueKind queu
|
|||||||
if (!graphics_rootsig_set)
|
if (!graphics_rootsig_set)
|
||||||
{
|
{
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRootSignature(d3d_cl, g->bindless_rootsig);
|
ID3D12GraphicsCommandList_SetGraphicsRootSignature(d3d_cl, g->bindless_rootsig);
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstants(d3d_cl, 0, MaxShaderConstants, slotted_constants, 0);
|
|
||||||
CopyBytes(bound_graphics_constants, slotted_constants, sizeof(bound_graphics_constants));
|
|
||||||
graphics_rootsig_set = 1;
|
graphics_rootsig_set = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1908,11 +1902,10 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, GPU_QueueKind queu
|
|||||||
/* Update root constants */
|
/* Update root constants */
|
||||||
for (i32 slot = 0; slot < MaxShaderConstants; ++slot)
|
for (i32 slot = 0; slot < MaxShaderConstants; ++slot)
|
||||||
{
|
{
|
||||||
u32 v = slotted_constants[slot];
|
if (bound_graphics_constants[slot] != slotted_constants[slot])
|
||||||
if (bound_graphics_constants[slot] != v)
|
|
||||||
{
|
{
|
||||||
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstant(d3d_cl, 0, v, slot);
|
ID3D12GraphicsCommandList_SetGraphicsRoot32BitConstant(d3d_cl, slot, slotted_constants[slot], 0);
|
||||||
bound_graphics_constants[slot] = v;
|
bound_graphics_constants[slot] = slotted_constants[slot];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2153,61 +2146,15 @@ void GPU_CopyTexels(GPU_CommandListHandle cl, GPU_ResourceHandle dst, Vec3I32 ds
|
|||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Constants
|
//- Constant
|
||||||
|
|
||||||
void GPU_SetConstantU32_(GPU_CommandListHandle cl_handle, i32 slot, u32 v)
|
void GPU_SetConstant_(GPU_CommandListHandle cl_handle, i32 slot, void *src_32bit, u32 size)
|
||||||
{
|
{
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
GPU_D12_CmdList *cl = GPU_D12_CmdListFromHandle(cl_handle);
|
||||||
}
|
GPU_D12_Cmd *cmd = GPU_D12_PushCmd(cl);
|
||||||
|
cmd->kind = GPU_D12_CmdKind_Constant;
|
||||||
void GPU_SetConstantF32_(GPU_CommandListHandle cl_handle, i32 slot, f32 v)
|
cmd->constant.slot = slot;
|
||||||
{
|
CopyBytes(&cmd->constant.value, src_32bit, MinU32(size, 4));
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantStructuredBufferHandle_(GPU_CommandListHandle cl_handle, i32 slot, StructuredBufferHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantRWStructuredBufferHandle_(GPU_CommandListHandle cl_handle, i32 slot, RWStructuredBufferHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantTexture1DHandle_(GPU_CommandListHandle cl_handle, i32 slot, Texture1DHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantRWTexture1DHandle_(GPU_CommandListHandle cl_handle, i32 slot, RWTexture1DHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantTexture2DHandle_(GPU_CommandListHandle cl_handle, i32 slot, Texture2DHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantRWTexture2DHandle_(GPU_CommandListHandle cl_handle, i32 slot, RWTexture2DHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantTexture3DHandle_(GPU_CommandListHandle cl_handle, i32 slot, Texture3DHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantRWTexture3DHandle_(GPU_CommandListHandle cl_handle, i32 slot, RWTexture3DHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPU_SetConstantSamplerHandle_(GPU_CommandListHandle cl_handle, i32 slot, SamplerHandle v)
|
|
||||||
{
|
|
||||||
GPU_D12_PushConstCmd(GPU_D12_CmdListFromHandle(cl_handle), slot, &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Barrier
|
//- Barrier
|
||||||
|
|||||||
@ -335,11 +335,6 @@ Struct(GPU_D12_SharedState)
|
|||||||
ID3D12Device *device;
|
ID3D12Device *device;
|
||||||
} extern GPU_D12_shared_state;
|
} extern GPU_D12_shared_state;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
//~ Startup
|
|
||||||
|
|
||||||
void GPU_D12_Startup(void);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Helpers
|
//~ Helpers
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,9 @@ JobImpl(PR_RunForever, _sig, _id)
|
|||||||
|
|
||||||
/* Prep test pass */
|
/* Prep test pass */
|
||||||
{
|
{
|
||||||
GPU_SetConstantU32(cl, PR_DConst_TestConst, 5);
|
final_target_rwhandle.v = 12;
|
||||||
|
GPU_SetConstant(cl, PR_ShaderConst_TestTarget, final_target_rwhandle);
|
||||||
|
GPU_SetConstant(cl, PR_ShaderConst_TestConst, 3.123);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test pass */
|
/* Test pass */
|
||||||
|
|||||||
@ -1,14 +1,15 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Test shader
|
//~ Test shader
|
||||||
|
|
||||||
ComputeShader2D(PR_TestCS, 8, 8)
|
ComputeShader2D(PR_TestCS, 8, 8)
|
||||||
{
|
{
|
||||||
RWTexture2D<Vec4> target_tex = ResourceFromConstantHandle(RWTexture2DHandle, PR_DConst_TestTarget);
|
RWTexture2D<Vec4> target_tex = RWTexture2DFromUniformHandle<Vec4>(PR_ShaderConst_TestTarget);
|
||||||
Vec2U32 target_tex_size = Count2D(target_tex);
|
Vec2U32 target_tex_size = Count2D(target_tex);
|
||||||
|
|
||||||
Vec2U32 id = SV_DispatchThreadID;
|
f32 testf = PR_ShaderConst_TestConst;
|
||||||
if (id.x < target_tex_size.x && id.y < target_tex_size.y)
|
|
||||||
|
Vec2I32 id = SV_DispatchThreadID;
|
||||||
|
if ((id.x < target_tex_size.x && id.y < target_tex_size.y) || testf < 3)
|
||||||
{
|
{
|
||||||
target_tex[id] = Vec4(0, 1, 0, 1);
|
target_tex[id] = Vec4(0, 1, 0, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//~ Constants
|
||||||
|
|
||||||
Enum(PR_DConst)
|
ShaderConstant(RWTexture2DHandle, PR_ShaderConst_TestTarget, 0);
|
||||||
{
|
ShaderConstant(f32, PR_ShaderConst_TestConst, 1);
|
||||||
ShaderConstant(RWTexture2DHandle, PR_DConst_TestTarget),
|
|
||||||
ShaderConstant(u32, PR_DConst_TestConst),
|
|
||||||
};
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user