shader print progress

This commit is contained in:
jacob 2025-12-09 19:02:27 -06:00
parent 1b02edb0b5
commit f47f7114d0
14 changed files with 160 additions and 121 deletions

View File

@ -24,7 +24,7 @@ GC_FontKey GC_FontKeyFromResource(ResourceKey resource)
GC_Run *GC_RunFromString(Arena *arena, GC_FontKey key, String str) GC_Run *GC_RunFromString(Arena *arena, GC_FontKey key, String str)
{ {
/* TODO */ /* TODO */
GC_Run *result = 0; GC_Run *result = PushStruct(arena, GC_Run);
GC_RunRect *rr = PushStruct(arena, GC_RunRect); GC_RunRect *rr = PushStruct(arena, GC_RunRect);
rr->advance = 1; rr->advance = 1;

View File

@ -20,7 +20,7 @@
@IncludeG gpu_shader_core.cgh @IncludeG gpu_shader_core.cgh
@Bootstrap G_Bootstrap @Bootstrap G_Bootstrap
@Bootstrap G_BootstrapExtra @Bootstrap G_BootstrapCommon
////////////////////////////// //////////////////////////////
//- Impl //- Impl

View File

@ -4,7 +4,7 @@ ThreadLocal G_ArenaHandle G_t_perm_arena = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Bootstrap //~ Bootstrap
void G_BootstrapExtra(void) void G_BootstrapCommon(void)
{ {
G_SharedUtilState *g = &G_shared_util_state; G_SharedUtilState *g = &G_shared_util_state;
@ -27,7 +27,7 @@ void G_BootstrapExtra(void)
/* Init point sampler */ /* Init point sampler */
{ {
G_ResourceHandle pt_sampler = G_PushSamplerResource(gpu_perm, (G_SamplerResourceDesc) { .filter = G_Filter_MinMagMipPoint }); G_ResourceHandle pt_sampler = G_PushSampler(gpu_perm, (G_SamplerResourceDesc) { .filter = G_Filter_MinMagMipPoint });
G_PushSamplerStateRef(gpu_perm, pt_sampler, .forced = G_BasicPointSampler.v); G_PushSamplerStateRef(gpu_perm, pt_sampler, .forced = G_BasicPointSampler.v);
} }
@ -76,9 +76,9 @@ G_ArenaHandle G_PermArena(void)
//- Cpu -> Gpu copy //- Cpu -> Gpu copy
G_ResourceHandle G_PushBufferFromCpu(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src) G_ResourceHandle G_PushBufferFromString_(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src, G_BufferResourceDesc desc)
{ {
G_ResourceHandle buffer = G_PushBufferResource(gpu_arena, (G_BufferResourceDesc) { .size = src.len }); G_ResourceHandle buffer = G_PushBufferEx(gpu_arena, desc);
G_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len)); G_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len));
G_MemorySync( G_MemorySync(
cl, buffer, cl, buffer,

View File

@ -12,7 +12,7 @@ extern ThreadLocal G_ArenaHandle G_t_perm_arena;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Bootstrap //~ Bootstrap
void G_BootstrapExtra(void); void G_BootstrapCommon(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Helpers //~ Helpers
@ -23,7 +23,9 @@ G_ArenaHandle G_PermArena(void);
//- Cpu -> Gpu copy //- Cpu -> Gpu copy
G_ResourceHandle G_PushBufferFromCpu(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src); G_ResourceHandle G_PushBufferFromString_(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src, G_BufferResourceDesc desc);
#define G_PushBufferFromString(_arena, _cl, _src, ...) \
G_PushBufferFromString_((_arena), (_cl), (_src), (G_BufferResourceDesc) { .size = (_src).len, __VA_ARGS__ })
//- Viewport / scissor //- Viewport / scissor

View File

@ -426,7 +426,7 @@ Struct(G_SamplerResourceDesc)
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ GPU pointer types //~ Ref types
Struct(G_RefDesc) Struct(G_RefDesc)
{ {
@ -434,10 +434,11 @@ Struct(G_RefDesc)
u64 element_size; u64 element_size;
u64 element_offset; u64 element_offset;
/* If set, then the shader-visible pointer will attempt to allocate the /* If set, then the layer will attempt to allocate the shader-visible
* pointer in the specified slot. This position can only be allocated to * ref in the specified slot. This slot can only be allocated to
* once globally. Any subsequent static allocations to the same slot will * once globally. Any subsequent static allocations to the same slot will
* cause a panic. 0 will result in a regular dynamic shader-visible pointer. * cause a panic unless it is freed. 0 will result in a regular
* dynamically-chosen slot for the reference.
*/ */
u32 forced; u32 forced;
}; };
@ -517,45 +518,45 @@ void G_ReleaseArena(G_ArenaHandle arena);
//- Resource creation //- Resource creation
G_ResourceHandle G_PushBufferResource(G_ArenaHandle arena, G_BufferResourceDesc desc); G_ResourceHandle G_PushBufferEx(G_ArenaHandle arena, G_BufferResourceDesc desc);
G_ResourceHandle G_PushTextureResource(G_ArenaHandle arena, G_TextureResourceDesc desc); G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena, G_TextureResourceDesc desc);
G_ResourceHandle G_PushSamplerResource(G_ArenaHandle arena, G_SamplerResourceDesc desc); G_ResourceHandle G_PushSampler(G_ArenaHandle arena, G_SamplerResourceDesc desc);
#define G_PushBuffer(arena, type, count, ...) G_PushBufferResource((arena), \ #define G_PushBuffer(arena, type, count, ...) G_PushBufferEx((arena), \
(G_BufferResourceDesc) { \ (G_BufferResourceDesc) { \
.size = sizeof(type) * (count), \ .size = sizeof(type) * (count), \
__VA_ARGS__ \ __VA_ARGS__ \
} \ } \
) )
#define G_PushTexture1D(arena, _format, _size, _initial_layout, ...) G_PushTextureResource((arena), \ #define G_PushTexture1D(arena, _format, _size, _initial_layout, ...) G_PushTextureEx((arena), \
(G_TextureResourceDesc) { \ (G_TextureResourceDesc) { \
.kind = G_TextureKind_1D, \ .kind = G_TextureKind_1D, \
.format = (_format), \ .format = (_format), \
.dims = VEC3I32((_size), 1, 1), \ .dims = VEC3I32((_size), 1, 1), \
.initial_layout = (_initial_layout), \ .initial_layout = (_initial_layout), \
__VA_ARGS__ \ __VA_ARGS__ \
} \ } \
) )
#define G_PushTexture2D(arena, _format, _size, _initial_layout, ...) G_PushTextureResource((arena), \ #define G_PushTexture2D(arena, _format, _size, _initial_layout, ...) G_PushTextureEx((arena), \
(G_TextureResourceDesc) { \ (G_TextureResourceDesc) { \
.kind = G_TextureKind_2D, \ .kind = G_TextureKind_2D, \
.format = (_format), \ .format = (_format), \
.dims = VEC3I32((_size).x, (_size).y, 1), \ .dims = VEC3I32((_size).x, (_size).y, 1), \
.initial_layout = (_initial_layout), \ .initial_layout = (_initial_layout), \
__VA_ARGS__ \ __VA_ARGS__ \
} \ } \
) )
#define G_PushTexture3D(arena, _format, _size, _initial_layout, ...) G_PushTextureResource((arena), \ #define G_PushTexture3D(arena, _format, _size, _initial_layout, ...) G_PushTextureEx((arena), \
(G_TextureResourceDesc) { \ (G_TextureResourceDesc) { \
.kind = G_TextureKind_3D, \ .kind = G_TextureKind_3D, \
.format = (_format), \ .format = (_format), \
.dims = (_size), \ .dims = (_size), \
.initial_layout = (_initial_layout), \ .initial_layout = (_initial_layout), \
__VA_ARGS__ \ __VA_ARGS__ \
} \ } \
) )
//- Index buffer helpers //- Index buffer helpers
@ -576,7 +577,7 @@ i32 G_CountDepth(G_ResourceHandle texture);
#define G_CountBuffer(buffer, type) G_CountBufferBytes(buffer) / sizeof(type) #define G_CountBuffer(buffer, type) G_CountBufferBytes(buffer) / sizeof(type)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Shader resource references //~ @hookdecl Shader resource reference
u32 G_PushRef(G_ArenaHandle arena, G_ResourceHandle resource, G_RefDesc desc); u32 G_PushRef(G_ArenaHandle arena, G_ResourceHandle resource, G_RefDesc desc);

View File

@ -4,9 +4,6 @@
//- Api //- Api
@IncludeC gpu_dx12_core.h @IncludeC gpu_dx12_core.h
@IncludeC gpu_dx12_shader_core.cgh
@IncludeG gpu_dx12_shader_core.cgh
////////////////////////////// //////////////////////////////
//- Impl //- Impl

View File

@ -247,8 +247,8 @@ void G_Bootstrap(void)
ID3D10Blob *blob = 0; ID3D10Blob *blob = 0;
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
D3D12_ROOT_PARAMETER params[G_D12_NumConstants] = ZI; D3D12_ROOT_PARAMETER params[G_NumConstants] = ZI;
for (i32 slot = 0; slot < G_D12_NumConstants; ++slot) for (i32 slot = 0; slot < G_NumConstants; ++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;
@ -287,7 +287,28 @@ void G_Bootstrap(void)
} }
////////////////////////////// //////////////////////////////
//- Initialize workers //- Create global resources
{
/* Create debug print buffers */
if (GPU_DEBUG)
{
u64 print_buffer_size = Mebi(64);
for (G_QueueKind kind = 0; kind < G_NumQueues; ++kind)
{
G_D12_Queue *queue = G_D12_QueueFromKind(kind);
if (kind != G_QueueKind_AsyncCopy)
{
G_ArenaHandle gpu_perm = G_PermArena();
queue->debug_print_buffer = G_PushBuffer(gpu_perm, u8, print_buffer_size, .flags = G_ResourceFlag_AllowShaderReadWrite);
queue->debug_print_buffer_ref = G_PushRWByteAddressBufferRef(gpu_perm, queue->debug_print_buffer);
}
}
}
}
//////////////////////////////
//- Start workers
for (G_QueueKind kind = 0; kind < G_NumQueues; ++kind) for (G_QueueKind kind = 0; kind < G_NumQueues; ++kind)
{ {
@ -856,7 +877,7 @@ G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorH
//- Resource creation //- Resource creation
G_ResourceHandle G_PushBufferResource(G_ArenaHandle arena_handle, G_BufferResourceDesc desc) G_ResourceHandle G_PushBufferEx(G_ArenaHandle arena_handle, G_BufferResourceDesc desc)
{ {
G_D12_SharedState *g = &G_D12_shared_state; G_D12_SharedState *g = &G_D12_shared_state;
G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle); G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle);
@ -866,7 +887,7 @@ G_ResourceHandle G_PushBufferResource(G_ArenaHandle arena_handle, G_BufferResour
{ {
/* FIXME: Dynamic size */ /* FIXME: Dynamic size */
D3D12_HEAP_DESC d3d_desc = ZI; D3D12_HEAP_DESC d3d_desc = ZI;
d3d_desc.SizeInBytes = Mebi(64); d3d_desc.SizeInBytes = Mebi(512);
d3d_desc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED; d3d_desc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
d3d_desc.Flags |= D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; /* TODO: Remove this and support tier 1 resource heaps */ d3d_desc.Flags |= D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; /* TODO: Remove this and support tier 1 resource heaps */
d3d_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT; d3d_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
@ -941,7 +962,7 @@ G_ResourceHandle G_PushBufferResource(G_ArenaHandle arena_handle, G_BufferResour
return G_D12_MakeHandle(G_ResourceHandle, resource); return G_D12_MakeHandle(G_ResourceHandle, resource);
} }
G_ResourceHandle G_PushTextureResource(G_ArenaHandle arena_handle, G_TextureResourceDesc desc) G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena_handle, G_TextureResourceDesc desc)
{ {
G_D12_SharedState *g = &G_D12_shared_state; G_D12_SharedState *g = &G_D12_shared_state;
G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle); G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle);
@ -952,7 +973,7 @@ G_ResourceHandle G_PushTextureResource(G_ArenaHandle arena_handle, G_TextureReso
{ {
/* FIXME: Dynamic size */ /* FIXME: Dynamic size */
D3D12_HEAP_DESC d3d_desc = ZI; D3D12_HEAP_DESC d3d_desc = ZI;
d3d_desc.SizeInBytes = Mebi(64); d3d_desc.SizeInBytes = Mebi(512);
d3d_desc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED; d3d_desc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
d3d_desc.Flags |= D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; /* TODO: Remove this and support tier 1 resource heaps */ d3d_desc.Flags |= D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; /* TODO: Remove this and support tier 1 resource heaps */
d3d_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT; d3d_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
@ -1039,7 +1060,7 @@ G_ResourceHandle G_PushTextureResource(G_ArenaHandle arena_handle, G_TextureReso
return G_D12_MakeHandle(G_ResourceHandle, resource); return G_D12_MakeHandle(G_ResourceHandle, resource);
} }
G_ResourceHandle G_PushSamplerResource(G_ArenaHandle arena_handle, G_SamplerResourceDesc desc) G_ResourceHandle G_PushSampler(G_ArenaHandle arena_handle, G_SamplerResourceDesc desc)
{ {
G_D12_SharedState *g = &G_D12_shared_state; G_D12_SharedState *g = &G_D12_shared_state;
G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle); G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle);
@ -1052,7 +1073,7 @@ G_ResourceHandle G_PushSamplerResource(G_ArenaHandle arena_handle, G_SamplerReso
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookimpl Shader resource references //~ @hookimpl Shader resource reference
u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_RefDesc ref_desc) u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_RefDesc ref_desc)
{ {
@ -1081,15 +1102,29 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re
kind == G_RefKind_RWTexture2D || kind == G_RefKind_RWTexture2D ||
kind == G_RefKind_RWTexture3D; kind == G_RefKind_RWTexture3D;
if (is_uav)
{
/* RW refs must be allowed on this resource */
Assert(resource->flags & G_ResourceFlag_AllowShaderReadWrite);
}
G_D12_Descriptor *descriptor = 0; G_D12_Descriptor *descriptor = 0;
if (is_buffer) if (is_buffer)
{ {
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav, ref_desc.forced); descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav, ref_desc.forced);
u64 buffer_size_aligned = resource->buffer_size_aligned; u64 num_elements_in_buffer = 0;
u64 num_elements_in_buffer = buffer_size_aligned / ref_desc.element_size; u64 num_elements_after_offset = 0;
u64 num_elements_after_offset = num_elements_in_buffer > ref_desc.element_offset ? num_elements_in_buffer - ref_desc.element_offset : 0; if (is_raw)
{
num_elements_in_buffer = 0;
num_elements_after_offset = 0;
}
else
{
u64 buffer_size_aligned = resource->buffer_size_aligned;
num_elements_in_buffer = buffer_size_aligned / ref_desc.element_size;
num_elements_after_offset = num_elements_in_buffer > ref_desc.element_offset ? num_elements_in_buffer - ref_desc.element_offset : 0;
}
if (num_elements_after_offset > 0) if (num_elements_after_offset > 0)
{ {
if (is_uav) if (is_uav)
@ -1526,13 +1561,18 @@ void G_CommitCommandListEx(G_CommandListHandle cl_handle, u64 fence_ops_count, G
G_D12_Pipeline *bound_pipeline = 0; G_D12_Pipeline *bound_pipeline = 0;
/* Constants state */ /* Constants state */
u64 slotted_constants[G_D12_NumConstants]; u64 slotted_constants[G_NumConstants];
u64 bound_compute_constants[G_D12_NumConstants]; u64 bound_compute_constants[G_NumConstants];
u64 bound_graphics_constants[G_D12_NumConstants]; u64 bound_graphics_constants[G_NumConstants];
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; }
if (GPU_DEBUG)
{
slotted_constants[G_DebugPrintBufferConstantSlot] = queue->debug_print_buffer_ref.v;
}
/* Rasterizer state */ /* Rasterizer state */
D3D12_VIEWPORT bound_viewport = ZI; D3D12_VIEWPORT bound_viewport = ZI;
D3D12_RECT bound_scissor = ZI; D3D12_RECT bound_scissor = ZI;
@ -2704,7 +2744,7 @@ void G_CommitBackbuffer(G_ResourceHandle backbuffer_handle, i32 vsync)
if (vsync != 0 && !(present_flags & DXGI_PRESENT_ALLOW_TEARING)) if (vsync != 0 && !(present_flags & DXGI_PRESENT_ALLOW_TEARING))
{ {
/* FIXME: Don't flush in fullscreen mode? */ /* FIXME: Flush in windowed mode? */
// DwmFlush(); // DwmFlush();
} }
@ -2723,8 +2763,7 @@ void G_D12_WorkerEntry(WaveLaneCtx *lane)
G_QueueKind queue_kind = (G_QueueKind)lane->wave->udata; G_QueueKind queue_kind = (G_QueueKind)lane->wave->udata;
G_D12_Queue *queue = G_D12_QueueFromKind(queue_kind); G_D12_Queue *queue = G_D12_QueueFromKind(queue_kind);
// for (;;) for (;;)
// { {
}
// }
} }

View File

@ -194,6 +194,10 @@ Struct(G_D12_Queue)
ID3D12Fence *commit_fence; ID3D12Fence *commit_fence;
u64 commit_fence_target; u64 commit_fence_target;
/* Global resources */
G_ResourceHandle debug_print_buffer;
G_RWByteAddressBufferRef debug_print_buffer_ref;
/* Raw command lists */ /* Raw command lists */
struct G_D12_RawCommandList *first_committed_cl; struct G_D12_RawCommandList *first_committed_cl;
struct G_D12_RawCommandList *last_committed_cl; struct G_D12_RawCommandList *last_committed_cl;

View File

@ -1,39 +0,0 @@
////////////////////////////////////////////////////////////
//~ Debug types
////////////////////////////////////////////////////////////
//~ Global constants
/* Slots below assume they won't overlap user defined constants */
StaticAssert(G_NumGeneralPurposeConstants == 8);
G_ForceDeclConstant(G_RWByteAddressBufferRef, G_D12_DebugPrintBuff, 8);
#define G_D12_NumConstants (9)
////////////////////////////////////////////////////////////
//~ @hookimpl Shader printf
#if IsLanguageG
/* This technique comes from MJP's article: https://therealmjp.github.io/posts/hlsl-printf/ */
#if G__DEBUG
#define G_DebugPrintImpl_(fmt_cstr) do { \
u32 __strlen = 0; \
for (;;) { if (U32FromChar(fmt_cstr[__strlen]) == 0) { break; } ++__strlen; } \
RWByteAddressBuffer __print_buff; \
__print_buff = RWByteAddressBufferFromRef(G__D12_DebugPrintBuff); \
u32 __pos; \
__print_buff.InterlockedAdd(0, __strlen, __pos); \
if (__pos < countof(__print_buff)) \
{ \
for (u32 char_idx = 0; char_idx < __strlen; ++char_idx) \
{ \
__print_buff.Store(__pos + char_idx, U32FromChar(fmt_cstr[char_idx])); \
} \
} \
} while (0)
#else
#define G_DebugPrintImpl_(fmt_cstr)
#endif
#endif

View File

@ -35,10 +35,11 @@ Struct(G_SamplerStateRef) { u32 v; };
/* /*
* NOTE: D3d12 exposes 64 root constants, and vulkan 32 push constants. * NOTE: D3d12 exposes 64 root constants, and vulkan 32 push constants.
* Other constants past the max can be used by the graphics
* implementation backend layer.
*/ */
#define G_NumGeneralPurposeConstants (8) #define G_NumGeneralPurposeConstants (8) /* Constants available for any usage */
#define G_NumReservedConstants (1) /* Constants reserved for usage by the GPU layer */
#define G_NumBackendReservedConstants (1) /* Constants reserved for usage by the implementation backend layer */
#define G_NumConstants (G_NumGeneralPurposeConstants + G_NumReservedConstants + G_NumBackendReservedConstants)
#if IsLanguageC #if IsLanguageC
#define G_ForceDeclConstant(type, name, slot) \ #define G_ForceDeclConstant(type, name, slot) \
@ -106,11 +107,39 @@ Struct(G_SamplerStateRef) { u32 v; };
#define G_BasicNoiseTexture G_StaticRef(G_Texture3DRef, 2) #define G_BasicNoiseTexture G_StaticRef(G_Texture3DRef, 2)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Debug printf //~ Reserved constants
/* The constants declared below assume this configuration is accurate for slot usage */
StaticAssert(G_NumGeneralPurposeConstants == 8);
StaticAssert(G_NumReservedConstants == 1);
#define G_DebugPrintBufferConstantSlot 8
G_ForceDeclConstant(G_RWByteAddressBufferRef, G_DebugPrintBuffer, 8);
////////////////////////////////////////////////////////////
//~ Debug printf
#if IsLanguageG #if IsLanguageG
/* Implemented per graphics platform layer */ /* This technique comes from MJP's article: https://therealmjp.github.io/posts/hlsl-printf/ */
#define G_DebugPrint(msg) G_DebugPrintImpl_(msg) #if G__DEBUG
#define G_DebugPrint(fmt_cstr) do { \
u32 __strlen = 0; \
for (;;) { if (U32FromChar(fmt_cstr[__strlen]) == 0) { break; } ++__strlen; } \
RWByteAddressBuffer __print_buff; \
__print_buff = RWByteAddressBufferFromRef(G_DebugPrintBuffer); \
u32 __pos; \
__print_buff.InterlockedAdd(0, __strlen, __pos); \
if (__pos < countof(__print_buff)) \
{ \
for (u32 char_idx = 0; char_idx < __strlen; ++char_idx) \
{ \
__print_buff.Store(__pos + char_idx, U32FromChar(fmt_cstr[char_idx])); \
} \
} \
} while (0)
#else
#define G_DebugPrint(fmt_cstr)
#endif
#endif #endif

View File

@ -1,3 +1,6 @@
#define PB_SampleRate 48000 #define PB_SampleRate 48000
////////////////////////////////////////////////////////////
//~ @hookdecl Bootstrap
void PB_Bootstrap(void); void PB_Bootstrap(void);

View File

@ -7,9 +7,9 @@
PB_WSP_SharedState PB_WSP_shared_state = ZI; PB_WSP_SharedState PB_WSP_shared_state = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Bootstrap //~ @hookimpl Bootstrap
void PB_Bootstrap(void) void PB_Bootstrap(void)
{ {
PB_WSP_SharedState *g = &PB_WSP_shared_state; PB_WSP_SharedState *g = &PB_WSP_shared_state;
PB_WSP_InitializeWasapi(); PB_WSP_InitializeWasapi();
@ -19,6 +19,9 @@ void PB_Bootstrap(void)
OnExit(&PB_WSP_Shutdown); OnExit(&PB_WSP_Shutdown);
} }
////////////////////////////////////////////////////////////
//~ Initialize wasapi
ExitFuncDef(PB_WSP_Shutdown) ExitFuncDef(PB_WSP_Shutdown)
{ {
PB_WSP_SharedState *g = &PB_WSP_shared_state; PB_WSP_SharedState *g = &PB_WSP_shared_state;

View File

@ -572,8 +572,8 @@ void V_TickForever(WaveLaneCtx *lane)
G_RWTexture2DRef draw_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, draw_target); G_RWTexture2DRef draw_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, draw_target);
/* Verts */ /* Verts */
G_ResourceHandle dverts_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->dverts_arena)); G_ResourceHandle dverts_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromArena(frame->dverts_arena));
G_ResourceHandle dvert_idxs_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->dvert_idxs_arena)); G_ResourceHandle dvert_idxs_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromArena(frame->dvert_idxs_arena));
G_StructuredBufferRef dverts_ro = G_PushStructuredBufferRef(frame->gpu_arena, dverts_buff, V_DVert); G_StructuredBufferRef dverts_ro = G_PushStructuredBufferRef(frame->gpu_arena, dverts_buff, V_DVert);
G_IndexBufferDesc dvert_idxs_ib = G_IdxBuff32(dvert_idxs_buff); G_IndexBufferDesc dvert_idxs_ib = G_IdxBuff32(dvert_idxs_buff);
@ -586,7 +586,7 @@ void V_TickForever(WaveLaneCtx *lane)
params.shape_verts = dverts_ro; params.shape_verts = dverts_ro;
params.world_to_draw_xf = world_to_draw_xf; params.world_to_draw_xf = world_to_draw_xf;
} }
G_ResourceHandle params_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(&params)); G_ResourceHandle params_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromStruct(&params));
G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams); G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams);
/* Constants */ /* Constants */

View File

@ -1381,7 +1381,7 @@ void UI_EndFrame(UI_Frame *frame)
G_Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target); G_Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target);
/* Rects */ /* Rects */
G_ResourceHandle rects_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->rects_arena)); G_ResourceHandle rects_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromArena(frame->rects_arena));
G_StructuredBufferRef rects_ro = G_PushStructuredBufferRef(frame->gpu_arena, rects_buff, UI_DRect); G_StructuredBufferRef rects_ro = G_PushStructuredBufferRef(frame->gpu_arena, rects_buff, UI_DRect);
/* Params */ /* Params */
@ -1391,7 +1391,7 @@ void UI_EndFrame(UI_Frame *frame)
params.target_ro = draw_target_ro; params.target_ro = draw_target_ro;
params.rects = rects_ro; params.rects = rects_ro;
} }
G_ResourceHandle params_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(&params)); G_ResourceHandle params_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromStruct(&params));
G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams); G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams);
/* Constants */ /* Constants */