diff --git a/src/base/base.cgh b/src/base/base.cgh index 576a93c7..278a425e 100644 --- a/src/base/base.cgh +++ b/src/base/base.cgh @@ -770,15 +770,15 @@ Struct(SamplerStateHandle) { u32 v; }; * Other constants past the max can be used by the graphics * implementation backend layer. */ -#define MaxShaderConstants (8) +#define NumGeneralPurposeShaderConstants (8) #if IsLanguageC - #define ForceShaderConstant(type, name, slot) \ - Enum(name##__shaderconstantenum) { name = slot }; \ + #define ForceShaderConstant(type, name, slot) \ + Enum(name##__shaderconstantenum) { name = slot }; \ Struct(name##__shaderconstanttype) { type v; } - #define ShaderConstant(type, name, slot) \ - StaticAssert(sizeof(type) <= 4); \ - StaticAssert(slot < MaxShaderConstants); \ + #define ShaderConstant(type, name, slot) \ + StaticAssert(sizeof(type) <= 4); \ + StaticAssert(slot < NumGeneralPurposeShaderConstants); \ ForceShaderConstant(type, name, slot) #elif IsLanguageG #define ForceShaderConstant(type, name, slot) cbuffer name : register(b##slot) { type name; } diff --git a/src/gpu/gpu_dx12/gpu_dx12.lay b/src/gpu/gpu_dx12/gpu_dx12.lay index 6684dfd0..0ac35ec4 100644 --- a/src/gpu/gpu_dx12/gpu_dx12.lay +++ b/src/gpu/gpu_dx12/gpu_dx12.lay @@ -4,7 +4,9 @@ //- Api @IncludeC gpu_dx12_core.h +@IncludeC gpu_dx12_shader_core.cgh +@IncludeG gpu_dx12_shader_core.cgh @IncludeG gpu_dx12_shader_core.gh ////////////////////////////// diff --git a/src/gpu/gpu_dx12/gpu_dx12_core.c b/src/gpu/gpu_dx12/gpu_dx12_core.c index 81c4ebf4..be7fced1 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_core.c +++ b/src/gpu/gpu_dx12/gpu_dx12_core.c @@ -247,8 +247,8 @@ void GPU_Bootstrap(void) ID3D10Blob *blob = 0; if (SUCCEEDED(hr)) { - D3D12_ROOT_PARAMETER params[MaxShaderConstants] = ZI; - for (i32 slot = 0; slot < MaxShaderConstants; ++slot) + D3D12_ROOT_PARAMETER params[GPU_D12_NumShaderConstants] = ZI; + for (i32 slot = 0; slot < GPU_D12_NumShaderConstants; ++slot) { D3D12_ROOT_PARAMETER *param = ¶ms[slot]; 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; /* Constants state */ - u64 slotted_constants[MaxShaderConstants]; - u64 bound_compute_constants[MaxShaderConstants]; - u64 bound_graphics_constants[MaxShaderConstants]; + u64 slotted_constants[GPU_D12_NumShaderConstants]; + u64 bound_compute_constants[GPU_D12_NumShaderConstants]; + 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(bound_compute_constants); ++i) { bound_compute_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 */ D3D12_VIEWPORT bound_viewport = ZI; D3D12_RECT bound_scissor = ZI; @@ -1851,7 +1849,7 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, u64 fence_ops_coun } /* 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]) { @@ -1965,7 +1963,7 @@ void GPU_CommitCommandListEx(GPU_CommandListHandle cl_handle, u64 fence_ops_coun } /* 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]) { diff --git a/src/gpu/gpu_dx12/gpu_dx12_shader_core.cgh b/src/gpu/gpu_dx12/gpu_dx12_shader_core.cgh new file mode 100644 index 00000000..8012f11f --- /dev/null +++ b/src/gpu/gpu_dx12/gpu_dx12_shader_core.cgh @@ -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) diff --git a/src/gpu/gpu_dx12/gpu_dx12_shader_core.gh b/src/gpu/gpu_dx12/gpu_dx12_shader_core.gh index f0c1c9b7..055fcb9a 100644 --- a/src/gpu/gpu_dx12/gpu_dx12_shader_core.gh +++ b/src/gpu/gpu_dx12/gpu_dx12_shader_core.gh @@ -1,16 +1,6 @@ //////////////////////////////////////////////////////////// //~ 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 diff --git a/src/pp/pp_vis/pp_vis.lay b/src/pp/pp_vis/pp_vis.lay index 8b85c9b1..f75f6d66 100644 --- a/src/pp/pp_vis/pp_vis.lay +++ b/src/pp/pp_vis/pp_vis.lay @@ -30,6 +30,7 @@ @IncludeC pp_vis_core.h @IncludeG pp_vis_shaders.cgh +@IncludeG pp_vis_shaders.gh @Bootstrap V_Bootstrap diff --git a/src/pp/pp_vis/pp_vis_shaders.g b/src/pp/pp_vis/pp_vis_shaders.g index 8c1f83b0..7a936cf3 100644 --- a/src/pp/pp_vis/pp_vis_shaders.g +++ b/src/pp/pp_vis/pp_vis_shaders.g @@ -18,17 +18,6 @@ ComputeShader2D(V_BackdropCS, 8, 8) //////////////////////////////////////////////////////////// //~ Quad shader -Struct(V_DQuadPSInput) -{ - Semantic(Vec4, SV_Position); - Semantic(nointerpolation u32, quad_idx); -}; - -Struct(V_DQuadPSOutput) -{ - Semantic(Vec4, SV_Target0); -}; - ////////////////////////////// //- Vertex shader @@ -70,18 +59,6 @@ PixelShader(V_DQuadPS, V_DQuadPSOutput, V_DQuadPSInput input) //////////////////////////////////////////////////////////// //~ Shape shader -Struct(V_DVertPSInput) -{ - - Semantic(Vec4, SV_Position); - Semantic(Vec4, color_lin); -}; - -Struct(V_DVertPSOutput) -{ - Semantic(Vec4, SV_Target0); -}; - ////////////////////////////// //- Vertex shader diff --git a/src/pp/pp_vis/pp_vis_shaders.gh b/src/pp/pp_vis/pp_vis_shaders.gh new file mode 100644 index 00000000..db69f89c --- /dev/null +++ b/src/pp/pp_vis/pp_vis_shaders.gh @@ -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); diff --git a/src/ui/ui.lay b/src/ui/ui.lay index 763d6303..598ba9ca 100644 --- a/src/ui/ui.lay +++ b/src/ui/ui.lay @@ -25,6 +25,7 @@ @IncludeC ui_shaders.cgh @IncludeG ui_shaders.cgh +@IncludeG ui_shaders.gh @Bootstrap UI_Bootstrap diff --git a/src/ui/ui_shaders.g b/src/ui/ui_shaders.g index 4eeb5512..d9db300a 100644 --- a/src/ui/ui_shaders.g +++ b/src/ui/ui_shaders.g @@ -1,21 +1,5 @@ //////////////////////////////////////////////////////////// -//~ Rect - -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); -}; +//~ Rect shader ////////////////////////////// //- Vertex shader @@ -135,18 +119,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) } //////////////////////////////////////////////////////////// -//~ Blit - -Struct(UI_BlitPSInput) -{ - Semantic(Vec4, SV_Position); - Semantic(Vec2, src_uv); -}; - -Struct(UI_BlitPSOutput) -{ - Semantic(Vec4, SV_Target0); -}; +//~ Blit shader ////////////////////////////// //- Vertex shader diff --git a/src/ui/ui_shaders.gh b/src/ui/ui_shaders.gh new file mode 100644 index 00000000..88905e5c --- /dev/null +++ b/src/ui/ui_shaders.gh @@ -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);