create shader headers

This commit is contained in:
jacob 2025-12-09 16:26:31 -06:00
parent bb8f105309
commit 781e6ff75a
11 changed files with 115 additions and 77 deletions

View File

@ -770,15 +770,15 @@ Struct(SamplerStateHandle) { u32 v; };
* Other constants past the max can be used by the graphics * Other constants past the max can be used by the graphics
* implementation backend layer. * implementation backend layer.
*/ */
#define MaxShaderConstants (8) #define NumGeneralPurposeShaderConstants (8)
#if IsLanguageC #if IsLanguageC
#define ForceShaderConstant(type, name, slot) \ #define ForceShaderConstant(type, name, slot) \
Enum(name##__shaderconstantenum) { name = slot }; \ Enum(name##__shaderconstantenum) { name = slot }; \
Struct(name##__shaderconstanttype) { type v; } Struct(name##__shaderconstanttype) { type v; }
#define ShaderConstant(type, name, slot) \ #define ShaderConstant(type, name, slot) \
StaticAssert(sizeof(type) <= 4); \ StaticAssert(sizeof(type) <= 4); \
StaticAssert(slot < MaxShaderConstants); \ StaticAssert(slot < NumGeneralPurposeShaderConstants); \
ForceShaderConstant(type, name, slot) ForceShaderConstant(type, name, slot)
#elif IsLanguageG #elif IsLanguageG
#define ForceShaderConstant(type, name, slot) cbuffer name : register(b##slot) { type name; } #define ForceShaderConstant(type, name, slot) cbuffer name : register(b##slot) { type name; }

View File

@ -4,7 +4,9 @@
//- Api //- Api
@IncludeC gpu_dx12_core.h @IncludeC gpu_dx12_core.h
@IncludeC gpu_dx12_shader_core.cgh
@IncludeG gpu_dx12_shader_core.cgh
@IncludeG gpu_dx12_shader_core.gh @IncludeG gpu_dx12_shader_core.gh
////////////////////////////// //////////////////////////////

View File

@ -247,8 +247,8 @@ void GPU_Bootstrap(void)
ID3D10Blob *blob = 0; ID3D10Blob *blob = 0;
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
D3D12_ROOT_PARAMETER params[MaxShaderConstants] = ZI; D3D12_ROOT_PARAMETER params[GPU_D12_NumShaderConstants] = ZI;
for (i32 slot = 0; slot < MaxShaderConstants; ++slot) for (i32 slot = 0; slot < GPU_D12_NumShaderConstants; ++slot)
{ {
D3D12_ROOT_PARAMETER *param = &params[slot]; D3D12_ROOT_PARAMETER *param = &params[slot];
param->ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; param->ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
@ -1526,15 +1526,13 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, u64 fence_ops_coun
GPU_D12_Pipeline *bound_pipeline = 0; GPU_D12_Pipeline *bound_pipeline = 0;
/* Constants state */ /* Constants state */
u64 slotted_constants[MaxShaderConstants]; u64 slotted_constants[GPU_D12_NumShaderConstants];
u64 bound_compute_constants[MaxShaderConstants]; u64 bound_compute_constants[GPU_D12_NumShaderConstants];
u64 bound_graphics_constants[MaxShaderConstants]; u64 bound_graphics_constants[GPU_D12_NumShaderConstants];
for (i32 i = 0; i < countof(slotted_constants); ++i) { slotted_constants[i] = 0; } /* Zero initialze all constant slots */ for (i32 i = 0; i < countof(slotted_constants); ++i) { slotted_constants[i] = 0; } /* Zero initialze all constant slots */
for (i32 i = 0; i < countof(bound_compute_constants); ++i) { bound_compute_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; } for (i32 i = 0; i < countof(bound_graphics_constants); ++i) { bound_graphics_constants[i] = U64Max; }
slotted_constants[MaxShaderConstants - 1] = queue_kind == queue_kind == GPU_QueueKind_AsyncCompute; /* IsAsyncCompute constant */
/* Rasterizer state */ /* Rasterizer state */
D3D12_VIEWPORT bound_viewport = ZI; D3D12_VIEWPORT bound_viewport = ZI;
D3D12_RECT bound_scissor = ZI; D3D12_RECT bound_scissor = ZI;
@ -1851,7 +1849,7 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, u64 fence_ops_coun
} }
/* Update root constants */ /* Update root constants */
for (i32 slot = 0; slot < MaxShaderConstants; ++slot) for (i32 slot = 0; slot < countof(slotted_constants); ++slot)
{ {
if (bound_compute_constants[slot] != slotted_constants[slot]) if (bound_compute_constants[slot] != slotted_constants[slot])
{ {
@ -1965,7 +1963,7 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, u64 fence_ops_coun
} }
/* Update root constants */ /* Update root constants */
for (i32 slot = 0; slot < MaxShaderConstants; ++slot) for (i32 slot = 0; slot < countof(slotted_constants); ++slot)
{ {
if (bound_graphics_constants[slot] != slotted_constants[slot]) if (bound_graphics_constants[slot] != slotted_constants[slot])
{ {

View File

@ -0,0 +1,11 @@
////////////////////////////////////////////////////////////
//~ Debug types
////////////////////////////////////////////////////////////
//~ Global constants
/* Slots below assume they won't overlap user defined constants */
StaticAssert(NumGeneralPurposeShaderConstants == 8);
ForceShaderConstant(RWByteAddressBufferHandle, GPU_D12_DebugPrintBuff, 8);
#define GPU_D12_NumShaderConstants (9)

View File

@ -1,16 +1,6 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Debug types //~ Debug types
////////////////////////////////////////////////////////////
//~ Debug globals
// RWByteAddressBufferHandle print_buff;
StaticAssert(MaxShaderConstants == 8); /* Slots used below assume they won't overlap user shader constants */
ForceShaderConstant(RWByteAddressBufferHandle, GPU_D12_DebugPrintBuff, 9);
// cbuffer GPU_D12_DebugPrintCbuff_ : register(b9) { RWByteAddressBufferHandle print_buff; }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookimpl Shader printf //~ @hookimpl Shader printf

View File

@ -30,6 +30,7 @@
@IncludeC pp_vis_core.h @IncludeC pp_vis_core.h
@IncludeG pp_vis_shaders.cgh @IncludeG pp_vis_shaders.cgh
@IncludeG pp_vis_shaders.gh
@Bootstrap V_Bootstrap @Bootstrap V_Bootstrap

View File

@ -18,17 +18,6 @@ ComputeShader2D(V_BackdropCS, 8, 8)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Quad shader //~ Quad shader
Struct(V_DQuadPSInput)
{
Semantic(Vec4, SV_Position);
Semantic(nointerpolation u32, quad_idx);
};
Struct(V_DQuadPSOutput)
{
Semantic(Vec4, SV_Target0);
};
////////////////////////////// //////////////////////////////
//- Vertex shader //- Vertex shader
@ -70,18 +59,6 @@ PixelShader(V_DQuadPS, V_DQuadPSOutput, V_DQuadPSInput input)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Shape shader //~ Shape shader
Struct(V_DVertPSInput)
{
Semantic(Vec4, SV_Position);
Semantic(Vec4, color_lin);
};
Struct(V_DVertPSOutput)
{
Semantic(Vec4, SV_Target0);
};
////////////////////////////// //////////////////////////////
//- Vertex shader //- Vertex shader

View File

@ -0,0 +1,42 @@
////////////////////////////////////////////////////////////
//~ Quad shader types
Struct(V_DQuadPSInput)
{
Semantic(Vec4, SV_Position);
Semantic(nointerpolation u32, quad_idx);
};
Struct(V_DQuadPSOutput)
{
Semantic(Vec4, SV_Target0);
};
////////////////////////////////////////////////////////////
//~ Shape shader types
Struct(V_DVertPSInput)
{
Semantic(Vec4, SV_Position);
Semantic(Vec4, color_lin);
};
Struct(V_DVertPSOutput)
{
Semantic(Vec4, SV_Target0);
};
////////////////////////////////////////////////////////////
//~ Shaders
//- Backdrop
ComputeShader2D(V_BackdropCS, 8, 8);
//- Quad
VertexShader(V_DQuadVS, V_DQuadPSInput);
PixelShader(V_DQuadPS, V_DQuadPSOutput, V_DQuadPSInput input);
//- Shape
VertexShader(V_DVertVS, V_DVertPSInput);
PixelShader(V_DVertPS, V_DVertPSOutput, V_DVertPSInput input);

View File

@ -25,6 +25,7 @@
@IncludeC ui_shaders.cgh @IncludeC ui_shaders.cgh
@IncludeG ui_shaders.cgh @IncludeG ui_shaders.cgh
@IncludeG ui_shaders.gh
@Bootstrap UI_Bootstrap @Bootstrap UI_Bootstrap

View File

@ -1,21 +1,5 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Rect //~ Rect shader
Struct(UI_DRectPSInput)
{
Semantic(Vec4, sv_position);
Semantic(nointerpolation u32, rect_idx);
Semantic(Vec4, background_lin);
Semantic(Vec4, border_lin);
Semantic(Vec4, tint_lin);
Semantic(Vec2, rect_uv);
Semantic(Vec2, tex_uv);
};
Struct(UI_DRectPSOutput)
{
Semantic(Vec4, sv_target0);
};
////////////////////////////// //////////////////////////////
//- Vertex shader //- Vertex shader
@ -135,18 +119,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Blit //~ Blit shader
Struct(UI_BlitPSInput)
{
Semantic(Vec4, SV_Position);
Semantic(Vec2, src_uv);
};
Struct(UI_BlitPSOutput)
{
Semantic(Vec4, SV_Target0);
};
////////////////////////////// //////////////////////////////
//- Vertex shader //- Vertex shader

43
src/ui/ui_shaders.gh Normal file
View File

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//~ Rect shader types
Struct(UI_DRectPSInput)
{
Semantic(Vec4, sv_position);
Semantic(nointerpolation u32, rect_idx);
Semantic(Vec4, background_lin);
Semantic(Vec4, border_lin);
Semantic(Vec4, tint_lin);
Semantic(Vec2, rect_uv);
Semantic(Vec2, tex_uv);
};
Struct(UI_DRectPSOutput)
{
Semantic(Vec4, sv_target0);
};
////////////////////////////////////////////////////////////
//~ Blit shader types
Struct(UI_BlitPSInput)
{
Semantic(Vec4, SV_Position);
Semantic(Vec2, src_uv);
};
Struct(UI_BlitPSOutput)
{
Semantic(Vec4, SV_Target0);
};
////////////////////////////////////////////////////////////
//~ Shaders
//- Rect
VertexShader(UI_DRectVS, UI_DRectPSInput);
PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input);
//- Blit
VertexShader(UI_BlitVS, UI_BlitPSInput);
PixelShader(UI_BlitPS, UI_BlitPSOutput, UI_BlitPSInput input);