change gpu layer namespace to 'G'

This commit is contained in:
jacob 2025-12-09 17:45:01 -06:00
parent f773422abf
commit 8565cbea53
17 changed files with 1057 additions and 1057 deletions

View File

@ -8,7 +8,7 @@
////////////////////////////// //////////////////////////////
//- Resources //- Resources
@EmbedDir GPU_Resources gpu_res @EmbedDir G_Resources gpu_res
////////////////////////////// //////////////////////////////
//- Api //- Api
@ -19,8 +19,8 @@
@IncludeG gpu_shader_core.cgh @IncludeG gpu_shader_core.cgh
@Bootstrap GPU_Bootstrap @Bootstrap G_Bootstrap
@Bootstrap GPU_BootstrapExtra @Bootstrap G_BootstrapExtra
////////////////////////////// //////////////////////////////
//- Impl //- Impl

View File

@ -1,24 +1,24 @@
GPU_SharedUtilState GPU_shared_util_state = ZI; G_SharedUtilState G_shared_util_state = ZI;
ThreadLocal GPU_ArenaHandle GPU_t_perm_arena = ZI; ThreadLocal G_ArenaHandle G_t_perm_arena = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Bootstrap //~ Bootstrap
void GPU_BootstrapExtra(void) void G_BootstrapExtra(void)
{ {
GPU_SharedUtilState *g = &GPU_shared_util_state; G_SharedUtilState *g = &G_shared_util_state;
GPU_ArenaHandle gpu_perm = GPU_PermArena(); G_ArenaHandle gpu_perm = G_PermArena();
GPU_CommandListHandle cl = GPU_PrepareCommandList(GPU_QueueKind_Direct); G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct);
{ {
/* Init quad index buffer */ /* Init quad index buffer */
{ {
GPU_ResourceHandle quad_indices = ZI; G_ResourceHandle quad_indices = ZI;
u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 }; u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
quad_indices = GPU_PushBuffer(gpu_perm, u16, countof(quad_data)); quad_indices = G_PushBuffer(gpu_perm, u16, countof(quad_data));
GPU_CopyCpuToBuffer(cl, quad_indices, 0, quad_data, RNGU64(0, sizeof(quad_data))); G_CopyCpuToBuffer(cl, quad_indices, 0, quad_data, RNGU64(0, sizeof(quad_data)));
g->quad_indices = GPU_IdxBuff16(quad_indices); g->quad_indices = G_IdxBuff16(quad_indices);
} }
/* TODO: Init debug print queues */ /* TODO: Init debug print queues */
@ -27,35 +27,35 @@ void GPU_BootstrapExtra(void)
/* Init point sampler */ /* Init point sampler */
{ {
GPU_ResourceHandle pt_sampler = GPU_PushSamplerResource(gpu_perm, (GPU_SamplerResourceDesc) { .filter = GPU_Filter_MinMagMipPoint }); G_ResourceHandle pt_sampler = G_PushSamplerResource(gpu_perm, (G_SamplerResourceDesc) { .filter = G_Filter_MinMagMipPoint });
GPU_PushSamplerStateRef(gpu_perm, pt_sampler, .forced = GPU_BasicPointSampler.v); G_PushSamplerStateRef(gpu_perm, pt_sampler, .forced = G_BasicPointSampler.v);
} }
/* Init noise texture */ /* Init noise texture */
{ {
GPU_ResourceHandle noise_tex = ZI; G_ResourceHandle noise_tex = ZI;
String noise_data = DataFromResource(ResourceKeyFromStore(&GPU_Resources, Lit("noise_128x128x64_16.dat"))); String noise_data = DataFromResource(ResourceKeyFromStore(&G_Resources, Lit("noise_128x128x64_16.dat")));
Vec3I32 noise_dims = VEC3I32(128, 128, 64); Vec3I32 noise_dims = VEC3I32(128, 128, 64);
if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2) if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2)
{ {
Panic(Lit("Unexpected noise texture size")); Panic(Lit("Unexpected noise texture size"));
} }
noise_tex = GPU_PushTexture3D(gpu_perm, noise_tex = G_PushTexture3D(gpu_perm,
GPU_Format_R16_Uint, G_Format_R16_Uint,
noise_dims, noise_dims,
GPU_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present); G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present);
GPU_CopyCpuToTexture(cl, G_CopyCpuToTexture(cl,
noise_tex, VEC3I32(0, 0, 0), noise_tex, VEC3I32(0, 0, 0),
noise_data.text, noise_dims, noise_data.text, noise_dims,
RNG3I32(VEC3I32(0, 0, 0), noise_dims)); RNG3I32(VEC3I32(0, 0, 0), noise_dims));
GPU_PushTexture3DRef(gpu_perm, noise_tex, .forced = GPU_BasicNoiseTexture.v); G_PushTexture3DRef(gpu_perm, noise_tex, .forced = G_BasicNoiseTexture.v);
} }
} }
GPU_CommitCommandList(cl); G_CommitCommandList(cl);
GPU_SyncOtherQueues(GPU_QueueKind_Direct); G_SyncOtherQueues(G_QueueKind_Direct);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -63,48 +63,48 @@ void GPU_BootstrapExtra(void)
//- Arena //- Arena
GPU_ArenaHandle GPU_PermArena(void) G_ArenaHandle G_PermArena(void)
{ {
GPU_ArenaHandle perm = GPU_t_perm_arena; G_ArenaHandle perm = G_t_perm_arena;
if (GPU_IsArenaNil(perm)) if (G_IsArenaNil(perm))
{ {
GPU_t_perm_arena = GPU_AcquireArena(); G_t_perm_arena = G_AcquireArena();
perm = GPU_t_perm_arena; perm = G_t_perm_arena;
} }
return perm; return perm;
} }
//- Cpu -> Gpu copy //- Cpu -> Gpu copy
GPU_ResourceHandle GPU_PushBufferFromCpu(GPU_ArenaHandle gpu_arena, GPU_CommandListHandle cl, String src) G_ResourceHandle G_PushBufferFromCpu(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src)
{ {
GPU_ResourceHandle buffer = GPU_PushBufferResource(gpu_arena, (GPU_BufferResourceDesc) { .size = src.len }); G_ResourceHandle buffer = G_PushBufferResource(gpu_arena, (G_BufferResourceDesc) { .size = src.len });
GPU_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len)); G_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len));
GPU_MemorySync( G_MemorySync(
cl, buffer, cl, buffer,
GPU_Stage_Copy, GPU_Access_CopyWrite, G_Stage_Copy, G_Access_CopyWrite,
GPU_Stage_All, GPU_Access_All G_Stage_All, G_Access_All
); );
return buffer; return buffer;
} }
//- Viewport / scissor //- Viewport / scissor
Rng3 GPU_ViewportFromTexture(GPU_ResourceHandle texture) Rng3 G_ViewportFromTexture(G_ResourceHandle texture)
{ {
Vec2I32 dims = GPU_Count2D(texture); Vec2I32 dims = G_Count2D(texture);
return RNG3(VEC3(0, 0, 0), VEC3(dims.x, dims.y, 1)); return RNG3(VEC3(0, 0, 0), VEC3(dims.x, dims.y, 1));
} }
Rng2 GPU_ScissorFromTexture(GPU_ResourceHandle texture) Rng2 G_ScissorFromTexture(G_ResourceHandle texture)
{ {
Vec2I32 dims = GPU_Count2D(texture); Vec2I32 dims = G_Count2D(texture);
return RNG2(VEC2(0, 0), VEC2(dims.x, dims.y)); return RNG2(VEC2(0, 0), VEC2(dims.x, dims.y));
} }
//- Shared resources //- Shared resources
GPU_IndexBufferDesc GPU_GetSharedQuadIndices(void) G_IndexBufferDesc G_GetSharedQuadIndices(void)
{ {
return GPU_shared_util_state.quad_indices; return G_shared_util_state.quad_indices;
} }

View File

@ -1,35 +1,35 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ State types //~ State types
Struct(GPU_SharedUtilState) Struct(G_SharedUtilState)
{ {
/* Common shared resources */ /* Common shared resources */
GPU_IndexBufferDesc quad_indices; G_IndexBufferDesc quad_indices;
} extern GPU_shared_util_state; } extern G_shared_util_state;
extern ThreadLocal GPU_ArenaHandle GPU_t_perm_arena; extern ThreadLocal G_ArenaHandle G_t_perm_arena;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Bootstrap //~ Bootstrap
void GPU_BootstrapExtra(void); void G_BootstrapExtra(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Helpers //~ Helpers
//- Arena //- Arena
GPU_ArenaHandle GPU_PermArena(void); G_ArenaHandle G_PermArena(void);
//- Cpu -> Gpu copy //- Cpu -> Gpu copy
GPU_ResourceHandle GPU_PushBufferFromCpu(GPU_ArenaHandle gpu_arena, GPU_CommandListHandle cl, String src); G_ResourceHandle G_PushBufferFromCpu(G_ArenaHandle gpu_arena, G_CommandListHandle cl, String src);
//- Viewport / scissor //- Viewport / scissor
Rng3 GPU_ViewportFromTexture(GPU_ResourceHandle texture); Rng3 G_ViewportFromTexture(G_ResourceHandle texture);
Rng2 GPU_ScissorFromTexture(GPU_ResourceHandle texture); Rng2 G_ScissorFromTexture(G_ResourceHandle texture);
//- Shared resources //- Shared resources
GPU_IndexBufferDesc GPU_GetSharedQuadIndices(void); G_IndexBufferDesc G_GetSharedQuadIndices(void);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,61 +13,61 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Tweakable defines //~ Tweakable defines
#define GPU_D12_TearingIsAllowed 1 #define G_D12_TearingIsAllowed 1
#define GPU_D12_FrameLatency 1 #define G_D12_FrameLatency 1
#define GPU_D12_SwapchainBufferCount 3 #define G_D12_SwapchainBufferCount 3
#define GPU_D12_SwapchainFlags (((GPU_D12_TearingIsAllowed != 0) * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) \ #define G_D12_SwapchainFlags (((G_D12_TearingIsAllowed != 0) * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) \
| ((GPU_D12_FrameLatency != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT)) | ((G_D12_FrameLatency != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT))
#define GPU_D12_MaxCbvSrvUavDescriptors (1024 * 128) #define G_D12_MaxCbvSrvUavDescriptors (1024 * 128)
#define GPU_D12_MaxSamplerDescriptors (1024 * 1) #define G_D12_MaxSamplerDescriptors (1024 * 1)
#define GPU_D12_MaxRtvDescriptors (1024 * 64) #define G_D12_MaxRtvDescriptors (1024 * 64)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Pipeline types //~ Pipeline types
Struct(GPU_D12_PipelineDesc) Struct(G_D12_PipelineDesc)
{ {
VertexShader vs; VertexShader vs;
PixelShader ps; PixelShader ps;
ComputeShader cs; ComputeShader cs;
b32 is_wireframe; b32 is_wireframe;
D3D12_PRIMITIVE_TOPOLOGY_TYPE topology_type; D3D12_PRIMITIVE_TOPOLOGY_TYPE topology_type;
GPU_Format render_target_formats[GPU_MaxRenderTargets]; G_Format render_target_formats[G_MaxRenderTargets];
}; };
Struct(GPU_D12_Pipeline) Struct(G_D12_Pipeline)
{ {
GPU_D12_Pipeline *next_in_bin; G_D12_Pipeline *next_in_bin;
u64 hash; u64 hash;
GPU_D12_PipelineDesc desc; G_D12_PipelineDesc desc;
ID3D12PipelineState *pso; ID3D12PipelineState *pso;
b32 ok; b32 ok;
String error; String error;
}; };
Struct(GPU_D12_PipelineBin) Struct(G_D12_PipelineBin)
{ {
Mutex mutex; Mutex mutex;
GPU_D12_Pipeline *first; G_D12_Pipeline *first;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Descriptor types //~ Descriptor types
Enum(GPU_D12_DescriptorHeapKind) Enum(G_D12_DescriptorHeapKind)
{ {
GPU_D12_DescriptorHeapKind_CbvSrvUav, G_D12_DescriptorHeapKind_CbvSrvUav,
GPU_D12_DescriptorHeapKind_Rtv, G_D12_DescriptorHeapKind_Rtv,
GPU_D12_DescriptorHeapKind_Sampler, G_D12_DescriptorHeapKind_Sampler,
GPU_D12_DescriptorHeapKind_Count G_D12_DescriptorHeapKind_Count
}; };
Struct(GPU_D12_DescriptorHeap) Struct(G_D12_DescriptorHeap)
{ {
Arena *descriptors_arena; Arena *descriptors_arena;
@ -77,34 +77,34 @@ Struct(GPU_D12_DescriptorHeap)
D3D12_CPU_DESCRIPTOR_HANDLE start_handle; D3D12_CPU_DESCRIPTOR_HANDLE start_handle;
Mutex mutex; Mutex mutex;
struct GPU_D12_Descriptor *first_free; struct G_D12_Descriptor *first_free;
u32 max_count; u32 max_count;
}; };
Struct(GPU_D12_Descriptor) Struct(G_D12_Descriptor)
{ {
GPU_D12_Descriptor *next; G_D12_Descriptor *next;
GPU_D12_Descriptor *prev; G_D12_Descriptor *prev;
u64 queue_commit_target; u64 queue_commit_target;
GPU_D12_DescriptorHeap *heap; G_D12_DescriptorHeap *heap;
D3D12_CPU_DESCRIPTOR_HANDLE handle; D3D12_CPU_DESCRIPTOR_HANDLE handle;
u32 index; u32 index;
}; };
Struct(GPU_D12_DescriptorList) Struct(G_D12_DescriptorList)
{ {
GPU_D12_Descriptor *first; G_D12_Descriptor *first;
GPU_D12_Descriptor *last; G_D12_Descriptor *last;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Arena types //~ Arena types
Struct(GPU_D12_Arena) Struct(G_D12_Arena)
{ {
Arena *arena; Arena *arena;
GPU_D12_DescriptorList committed_descriptors_by_heap_and_queue[GPU_D12_DescriptorHeapKind_Count][GPU_NumQueues]; G_D12_DescriptorList committed_descriptors_by_heap_and_queue[G_D12_DescriptorHeapKind_Count][G_NumQueues];
/* TODO: /* TODO:
* To support D3D12_RESOURCE_HEAP_TIER_1 devices, create separate heaps for: * To support D3D12_RESOURCE_HEAP_TIER_1 devices, create separate heaps for:
@ -120,13 +120,13 @@ Struct(GPU_D12_Arena)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Resource types //~ Resource types
Struct(GPU_D12_Resource) Struct(G_D12_Resource)
{ {
GPU_D12_Resource *next_free; G_D12_Resource *next_free;
ID3D12Resource *d3d_resource; ID3D12Resource *d3d_resource;
u64 uid; u64 uid;
GPU_ResourceFlag flags; G_ResourceFlag flags;
/* Buffer info */ /* Buffer info */
u64 buffer_size; u64 buffer_size;
@ -135,41 +135,41 @@ Struct(GPU_D12_Resource)
/* Texture info */ /* Texture info */
b32 is_texture; b32 is_texture;
GPU_Format texture_format; G_Format texture_format;
Vec3I32 texture_dims; Vec3I32 texture_dims;
i32 texture_mip_levels; i32 texture_mip_levels;
D3D12_BARRIER_LAYOUT texture_layout; D3D12_BARRIER_LAYOUT texture_layout;
/* Sampler info */ /* Sampler info */
GPU_SamplerResourceDesc sampler_desc; G_SamplerResourceDesc sampler_desc;
/* Backbuffer info */ /* Backbuffer info */
struct GPU_D12_Swapchain *swapchain; struct G_D12_Swapchain *swapchain;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Staging types //~ Staging types
Struct(GPU_D12_StagingHeap) Struct(G_D12_StagingHeap)
{ {
Arena *arena; Arena *arena;
GPU_D12_Resource resource; G_D12_Resource resource;
void *mapped; void *mapped;
u64 size; u64 size;
struct GPU_D12_StagingRegionNode *head_region_node; struct G_D12_StagingRegionNode *head_region_node;
struct GPU_D12_StagingRegionNode *first_free_region_node; struct G_D12_StagingRegionNode *first_free_region_node;
}; };
Struct(GPU_D12_StagingRegionNode) Struct(G_D12_StagingRegionNode)
{ {
GPU_D12_StagingHeap *heap; G_D12_StagingHeap *heap;
/* Heap links (requires heap lock to read) */ /* Heap links (requires heap lock to read) */
GPU_D12_StagingRegionNode *prev; G_D12_StagingRegionNode *prev;
GPU_D12_StagingRegionNode *next; G_D12_StagingRegionNode *next;
/* Region info */ /* Region info */
Atomic64 completion_target; Atomic64 completion_target;
@ -179,28 +179,28 @@ Struct(GPU_D12_StagingRegionNode)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Command queue types //~ Command queue types
Struct(GPU_D12_CommandQueueDesc) Struct(G_D12_CommandQueueDesc)
{ {
D3D12_COMMAND_LIST_TYPE type; D3D12_COMMAND_LIST_TYPE type;
D3D12_COMMAND_QUEUE_PRIORITY priority; D3D12_COMMAND_QUEUE_PRIORITY priority;
}; };
Struct(GPU_D12_Queue) Struct(G_D12_Queue)
{ {
ID3D12CommandQueue *d3d_queue; ID3D12CommandQueue *d3d_queue;
GPU_D12_CommandQueueDesc desc; G_D12_CommandQueueDesc desc;
Mutex commit_mutex; Mutex commit_mutex;
ID3D12Fence *commit_fence; ID3D12Fence *commit_fence;
u64 commit_fence_target; u64 commit_fence_target;
/* Raw command lists */ /* Raw command lists */
struct GPU_D12_RawCommandList *first_committed_cl; struct G_D12_RawCommandList *first_committed_cl;
struct GPU_D12_RawCommandList *last_committed_cl; struct G_D12_RawCommandList *last_committed_cl;
/* Staging heap */ /* Staging heap */
Mutex staging_mutex; Mutex staging_mutex;
GPU_D12_StagingHeap *staging_heap; G_D12_StagingHeap *staging_heap;
Fence sync_fence; Fence sync_fence;
}; };
@ -208,10 +208,10 @@ Struct(GPU_D12_Queue)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Raw command list types //~ Raw command list types
Struct(GPU_D12_RawCommandList) Struct(G_D12_RawCommandList)
{ {
GPU_D12_Queue *queue; G_D12_Queue *queue;
GPU_D12_RawCommandList *next; G_D12_RawCommandList *next;
u64 commit_fence_target; u64 commit_fence_target;
@ -219,30 +219,30 @@ Struct(GPU_D12_RawCommandList)
ID3D12GraphicsCommandList7 *d3d_cl; ID3D12GraphicsCommandList7 *d3d_cl;
/* Direct queue command lists keep a constant list of CPU-only descriptors */ /* Direct queue command lists keep a constant list of CPU-only descriptors */
GPU_D12_Descriptor *rtv_descriptors[GPU_MaxRenderTargets]; G_D12_Descriptor *rtv_descriptors[G_MaxRenderTargets];
GPU_D12_Descriptor *rtv_clear_descriptor; G_D12_Descriptor *rtv_clear_descriptor;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Command list types //~ Command list types
#define GPU_D12_CmdsPerChunk 256 #define G_D12_CmdsPerChunk 256
Enum(GPU_D12_CmdKind) Enum(G_D12_CmdKind)
{ {
GPU_D12_CmdKind_None, G_D12_CmdKind_None,
GPU_D12_CmdKind_Barrier, G_D12_CmdKind_Barrier,
GPU_D12_CmdKind_Constant, G_D12_CmdKind_Constant,
GPU_D12_CmdKind_CopyBytes, G_D12_CmdKind_CopyBytes,
GPU_D12_CmdKind_CopyTexels, G_D12_CmdKind_CopyTexels,
GPU_D12_CmdKind_Compute, G_D12_CmdKind_Compute,
GPU_D12_CmdKind_Rasterize, G_D12_CmdKind_Rasterize,
GPU_D12_CmdKind_ClearRtv, G_D12_CmdKind_ClearRtv,
}; };
Struct(GPU_D12_Cmd) Struct(G_D12_Cmd)
{ {
GPU_D12_CmdKind kind; G_D12_CmdKind kind;
b32 skip; b32 skip;
union union
{ {
@ -254,7 +254,7 @@ Struct(GPU_D12_Cmd)
struct struct
{ {
GPU_BarrierDesc desc; G_BarrierDesc desc;
/* Post-batch data */ /* Post-batch data */
b32 is_end_of_batch; b32 is_end_of_batch;
@ -263,16 +263,16 @@ Struct(GPU_D12_Cmd)
struct struct
{ {
GPU_D12_Resource *dst; G_D12_Resource *dst;
GPU_D12_Resource *src; G_D12_Resource *src;
u64 dst_offset; u64 dst_offset;
RngU64 src_copy_range; RngU64 src_copy_range;
} copy_bytes; } copy_bytes;
struct struct
{ {
GPU_D12_Resource *dst; G_D12_Resource *dst;
GPU_D12_Resource *src; G_D12_Resource *src;
D3D12_TEXTURE_COPY_LOCATION dst_loc; D3D12_TEXTURE_COPY_LOCATION dst_loc;
D3D12_TEXTURE_COPY_LOCATION src_loc; D3D12_TEXTURE_COPY_LOCATION src_loc;
Vec3I32 dst_offset; Vec3I32 dst_offset;
@ -290,36 +290,36 @@ Struct(GPU_D12_Cmd)
VertexShader vs; VertexShader vs;
PixelShader ps; PixelShader ps;
u32 instances_count; u32 instances_count;
GPU_IndexBufferDesc index_buffer_desc; G_IndexBufferDesc index_buffer_desc;
GPU_D12_Resource *render_targets[GPU_MaxRenderTargets]; G_D12_Resource *render_targets[G_MaxRenderTargets];
Rng3 viewport; Rng3 viewport;
Rng2 scissor; Rng2 scissor;
GPU_RasterMode mode; G_RasterMode mode;
} rasterize; } rasterize;
struct struct
{ {
GPU_D12_Resource *render_target; G_D12_Resource *render_target;
Vec4 color; Vec4 color;
} clear_rtv; } clear_rtv;
}; };
}; };
Struct(GPU_D12_CmdChunk) Struct(G_D12_CmdChunk)
{ {
GPU_D12_CmdChunk *next; G_D12_CmdChunk *next;
struct GPU_D12_CmdList *cl; struct G_D12_CmdList *cl;
GPU_D12_Cmd *cmds; G_D12_Cmd *cmds;
u64 cmds_count; u64 cmds_count;
}; };
Struct(GPU_D12_CmdList) Struct(G_D12_CmdList)
{ {
GPU_QueueKind queue_kind; G_QueueKind queue_kind;
GPU_D12_CmdList *next; G_D12_CmdList *next;
GPU_D12_CmdChunk *first_cmd_chunk; G_D12_CmdChunk *first_cmd_chunk;
GPU_D12_CmdChunk *last_cmd_chunk; G_D12_CmdChunk *last_cmd_chunk;
u64 chunks_count; u64 chunks_count;
u64 cmds_count; u64 cmds_count;
}; };
@ -327,7 +327,7 @@ Struct(GPU_D12_CmdList)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Swapchain types //~ Swapchain types
Struct(GPU_D12_Swapchain) Struct(G_D12_Swapchain)
{ {
IDXGISwapChain3 *d3d_swapchain; IDXGISwapChain3 *d3d_swapchain;
@ -338,15 +338,15 @@ Struct(GPU_D12_Swapchain)
ID3D12Fence *present_fence; ID3D12Fence *present_fence;
u64 present_fence_target; u64 present_fence_target;
GPU_Format backbuffers_format; G_Format backbuffers_format;
Vec2I32 backbuffers_resolution; Vec2I32 backbuffers_resolution;
GPU_D12_Resource backbuffers[GPU_D12_SwapchainBufferCount]; G_D12_Resource backbuffers[G_D12_SwapchainBufferCount];
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ State types //~ State types
Struct(GPU_D12_SharedState) Struct(G_D12_SharedState)
{ {
Atomic64Padded resource_creation_gen; Atomic64Padded resource_creation_gen;
@ -355,80 +355,80 @@ Struct(GPU_D12_SharedState)
Atomic64 driver_descriptors_allocated; Atomic64 driver_descriptors_allocated;
/* Queues */ /* Queues */
GPU_D12_Queue queues[GPU_NumQueues]; G_D12_Queue queues[G_NumQueues];
/* Descriptor heaps */ /* Descriptor heaps */
GPU_D12_DescriptorHeap descriptor_heaps[GPU_D12_DescriptorHeapKind_Count]; G_D12_DescriptorHeap descriptor_heaps[G_D12_DescriptorHeapKind_Count];
/* Rootsig */ /* Rootsig */
ID3D12RootSignature *bindless_rootsig; ID3D12RootSignature *bindless_rootsig;
/* Pipelines */ /* Pipelines */
GPU_D12_PipelineBin pipeline_bins[1024]; G_D12_PipelineBin pipeline_bins[1024];
/* Command lists */ /* Command lists */
Mutex free_cmd_lists_mutex; Mutex free_cmd_lists_mutex;
GPU_D12_CmdList *first_free_cmd_list; G_D12_CmdList *first_free_cmd_list;
/* Command chunks */ /* Command chunks */
Mutex free_cmd_chunks_mutex; Mutex free_cmd_chunks_mutex;
GPU_D12_CmdChunk *first_free_cmd_chunk; G_D12_CmdChunk *first_free_cmd_chunk;
/* Swapchains */ /* Swapchains */
Mutex free_swapchains_mutex; Mutex free_swapchains_mutex;
GPU_D12_Swapchain *first_free_swapchain; G_D12_Swapchain *first_free_swapchain;
/* Device */ /* Device */
IDXGIFactory6 *factory; IDXGIFactory6 *factory;
IDXGIAdapter3 *adapter; IDXGIAdapter3 *adapter;
ID3D12Device10 *device; ID3D12Device10 *device;
} extern GPU_D12_shared_state; } extern G_D12_shared_state;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Helpers //~ Helpers
#define GPU_D12_MakeHandle(type, ptr) (type) { .v = (u64)(ptr) } #define G_D12_MakeHandle(type, ptr) (type) { .v = (u64)(ptr) }
GPU_D12_Arena *GPU_D12_ArenaFromHandle(GPU_ArenaHandle handle); G_D12_Arena *G_D12_ArenaFromHandle(G_ArenaHandle handle);
GPU_D12_CmdList *GPU_D12_CmdListFromHandle(GPU_CommandListHandle handle); G_D12_CmdList *G_D12_CmdListFromHandle(G_CommandListHandle handle);
GPU_D12_Resource *GPU_D12_ResourceFromHandle(GPU_ResourceHandle handle); G_D12_Resource *G_D12_ResourceFromHandle(G_ResourceHandle handle);
GPU_D12_Swapchain *GPU_D12_SwapchainFromHandle(GPU_SwapchainHandle handle); G_D12_Swapchain *G_D12_SwapchainFromHandle(G_SwapchainHandle handle);
DXGI_FORMAT GPU_D12_DxgiFormatFromGpuFormat(GPU_Format format); DXGI_FORMAT G_D12_DxgiFormatFromGpuFormat(G_Format format);
D3D12_BARRIER_SYNC GPU_D12_BarrierSyncFromStages(GPU_Stage stages); D3D12_BARRIER_SYNC G_D12_BarrierSyncFromStages(G_Stage stages);
D3D12_BARRIER_ACCESS GPU_D12_BarrierAccessFromAccesses(GPU_Access accesses); D3D12_BARRIER_ACCESS G_D12_BarrierAccessFromAccesses(G_Access accesses);
D3D12_BARRIER_LAYOUT GPU_D12_BarrierLayoutFromLayout(GPU_Layout layout); D3D12_BARRIER_LAYOUT G_D12_BarrierLayoutFromLayout(G_Layout layout);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Pipeline //~ Pipeline
GPU_D12_Pipeline *GPU_D12_PipelineFromDesc(GPU_D12_PipelineDesc desc); G_D12_Pipeline *G_D12_PipelineFromDesc(G_D12_PipelineDesc desc);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Queue //~ Queue
GPU_D12_Queue *GPU_D12_QueueFromKind(GPU_QueueKind kind); G_D12_Queue *G_D12_QueueFromKind(G_QueueKind kind);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Resource helpers //~ Resource helpers
GPU_D12_Descriptor *GPU_D12_DescriptorFromIndex(GPU_D12_DescriptorHeapKind heap_kind, u32 index); G_D12_Descriptor *G_D12_DescriptorFromIndex(G_D12_DescriptorHeapKind heap_kind, u32 index);
GPU_D12_Descriptor *GPU_D12_PushDescriptor(GPU_D12_Arena *gpu_arena, GPU_D12_DescriptorHeapKind heap_kind, u32 forced); G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorHeapKind heap_kind, u32 forced);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Raw command list //~ Raw command list
GPU_D12_RawCommandList *GPU_D12_PrepareRawCommandList(GPU_QueueKind queue_kind); G_D12_RawCommandList *G_D12_PrepareRawCommandList(G_QueueKind queue_kind);
void GPU_D12_CommitRawCommandList(GPU_D12_RawCommandList *cl); void G_D12_CommitRawCommandList(G_D12_RawCommandList *cl);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Command helpers //~ Command helpers
GPU_D12_Cmd *GPU_D12_PushCmd(GPU_D12_CmdList *cl); G_D12_Cmd *G_D12_PushCmd(G_D12_CmdList *cl);
GPU_D12_Cmd *GPU_D12_PushConstCmd(GPU_D12_CmdList *cl, i32 slot, void *v); G_D12_Cmd *G_D12_PushConstCmd(G_D12_CmdList *cl, i32 slot, void *v);
GPU_D12_StagingRegionNode *GPU_D12_PushStagingRegion(GPU_D12_CmdList *cl, u64 size); G_D12_StagingRegionNode *G_D12_PushStagingRegion(G_D12_CmdList *cl, u64 size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Workers //~ Workers
void GPU_D12_WorkerEntry(WaveLaneCtx *lane); void G_D12_WorkerEntry(WaveLaneCtx *lane);

View File

@ -7,8 +7,8 @@
/* Slots below assume they won't overlap user defined constants */ /* Slots below assume they won't overlap user defined constants */
StaticAssert(NumGeneralPurposeShaderConstants == 8); StaticAssert(NumGeneralPurposeShaderConstants == 8);
ForceShaderConstant(RWByteAddressBufferRef, GPU_D12_DebugPrintBuff, 8); ForceShaderConstant(RWByteAddressBufferRef, G_D12_DebugPrintBuff, 8);
#define GPU_D12_NumShaderConstants (9) #define G_D12_NumShaderConstants (9)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookimpl Shader printf //~ @hookimpl Shader printf
@ -16,12 +16,12 @@ ForceShaderConstant(RWByteAddressBufferRef, GPU_D12_DebugPrintBuff, 8);
#if IsLanguageG #if IsLanguageG
/* This technique comes from MJP's article: https://therealmjp.github.io/posts/hlsl-printf/ */ /* This technique comes from MJP's article: https://therealmjp.github.io/posts/hlsl-printf/ */
#if GPU_DEBUG #if G__DEBUG
#define DebugPrintImpl_(fmt_cstr) do { \ #define G_DebugPrintImpl_(fmt_cstr) do { \
u32 __strlen = 0; \ u32 __strlen = 0; \
for (;;) { if (U32FromChar(fmt_cstr[__strlen]) == 0) { break; } ++__strlen; } \ for (;;) { if (U32FromChar(fmt_cstr[__strlen]) == 0) { break; } ++__strlen; } \
RWByteAddressBuffer __print_buff; \ RWByteAddressBuffer __print_buff; \
__print_buff = RWByteAddressBufferFromRef(GPU_D12_DebugPrintBuff); \ __print_buff = RWByteAddressBufferFromRef(G__D12_DebugPrintBuff); \
u32 __pos; \ u32 __pos; \
__print_buff.InterlockedAdd(0, __strlen, __pos); \ __print_buff.InterlockedAdd(0, __strlen, __pos); \
if (__pos < countof(__print_buff)) \ if (__pos < countof(__print_buff)) \
@ -33,7 +33,7 @@ ForceShaderConstant(RWByteAddressBufferRef, GPU_D12_DebugPrintBuff, 8);
} \ } \
} while (0) } while (0)
#else #else
#define DebugPrintImpl_(fmt_cstr) #define G_DebugPrintImpl_(fmt_cstr)
#endif #endif
#endif #endif

View File

@ -2,13 +2,13 @@
//~ Shared static handles (common resources available to all shaders) //~ Shared static handles (common resources available to all shaders)
#if IsLanguageC #if IsLanguageC
#define GPU_SharedRef(type, v) ((type) { (v) }) #define G_SharedRef(type, v) ((type) { (v) })
#elif IsLanguageG #elif IsLanguageG
#define GPU_SharedRef(type, v) (type(v)) #define G_SharedRef(type, v) (type(v))
#endif #endif
#define GPU_BasicPointSampler GPU_SharedRef(SamplerStateRef, 1) #define G_BasicPointSampler G_SharedRef(SamplerStateRef, 1)
#define GPU_BasicNoiseTexture GPU_SharedRef(Texture3DRef, 2) #define G_BasicNoiseTexture G_SharedRef(Texture3DRef, 2)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Shader printf //~ @hookdecl Shader printf
@ -16,6 +16,6 @@
#if IsLanguageG #if IsLanguageG
/* Implemented per graphics platform layer */ /* Implemented per graphics platform layer */
#define DebugPrint(msg) DebugPrintImpl_(msg) #define G_DebugPrint(msg) G_DebugPrintImpl_(msg)
#endif #endif

View File

@ -35,7 +35,7 @@ void V_TickForever(WaveLaneCtx *lane)
frame->arena = AcquireArena(Gibi(64)); frame->arena = AcquireArena(Gibi(64));
frame->dverts_arena = AcquireArena(Gibi(64)); frame->dverts_arena = AcquireArena(Gibi(64));
frame->dvert_idxs_arena = AcquireArena(Gibi(64)); frame->dvert_idxs_arena = AcquireArena(Gibi(64));
frame->gpu_arena = GPU_AcquireArena(); frame->gpu_arena = G_AcquireArena();
} }
////////////////////////////// //////////////////////////////
@ -125,18 +125,18 @@ void V_TickForever(WaveLaneCtx *lane)
Arena *old_arena = frame->arena; Arena *old_arena = frame->arena;
Arena *old_dverts_arena = frame->dverts_arena; Arena *old_dverts_arena = frame->dverts_arena;
Arena *old_dvert_idxs_arena = frame->dvert_idxs_arena; Arena *old_dvert_idxs_arena = frame->dvert_idxs_arena;
GPU_ArenaHandle old_gpu_arena = frame->gpu_arena; G_ArenaHandle old_gpu_arena = frame->gpu_arena;
ZeroStruct(frame); ZeroStruct(frame);
frame->arena = old_arena; frame->arena = old_arena;
frame->dverts_arena = old_dverts_arena; frame->dverts_arena = old_dverts_arena;
frame->dvert_idxs_arena = old_dvert_idxs_arena; frame->dvert_idxs_arena = old_dvert_idxs_arena;
frame->gpu_arena = old_gpu_arena; frame->gpu_arena = old_gpu_arena;
} }
frame->cl = GPU_PrepareCommandList(GPU_QueueKind_Direct); frame->cl = G_PrepareCommandList(G_QueueKind_Direct);
ResetArena(frame->arena); ResetArena(frame->arena);
ResetArena(frame->dverts_arena); ResetArena(frame->dverts_arena);
ResetArena(frame->dvert_idxs_arena); ResetArena(frame->dvert_idxs_arena);
GPU_ResetArena(frame->cl, frame->gpu_arena); G_ResetArena(frame->cl, frame->gpu_arena);
frame->time_ns = TimeNs(); frame->time_ns = TimeNs();
frame->tick = last_frame->tick + 1; frame->tick = last_frame->tick + 1;
@ -561,21 +561,21 @@ void V_TickForever(WaveLaneCtx *lane)
//- Push data to GPU //- Push data to GPU
/* Target */ /* Target */
GPU_ResourceHandle draw_target = GPU_PushTexture2D( G_ResourceHandle draw_target = G_PushTexture2D(
frame->gpu_arena, frame->gpu_arena,
GPU_Format_R16G16B16A16_Float, G_Format_R16G16B16A16_Float,
window_frame.monitor_size, window_frame.monitor_size,
GPU_Layout_DirectQueue_ShaderReadWrite, G_Layout_DirectQueue_ShaderReadWrite,
.flags = GPU_ResourceFlag_AllowShaderReadWrite | GPU_ResourceFlag_AllowRenderTarget .flags = G_ResourceFlag_AllowShaderReadWrite | G_ResourceFlag_AllowRenderTarget
); );
Texture2DRef draw_target_ro = GPU_PushTexture2DRef(frame->gpu_arena, draw_target); Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target);
RWTexture2DRef draw_target_rw = GPU_PushRWTexture2DRef(frame->gpu_arena, draw_target); RWTexture2DRef draw_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, draw_target);
/* Verts */ /* Verts */
GPU_ResourceHandle dverts_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->dverts_arena)); G_ResourceHandle dverts_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->dverts_arena));
GPU_ResourceHandle dvert_idxs_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->dvert_idxs_arena)); G_ResourceHandle dvert_idxs_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->dvert_idxs_arena));
StructuredBufferRef dverts_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, dverts_buff, V_DVert); StructuredBufferRef dverts_ro = G_PushStructuredBufferRef(frame->gpu_arena, dverts_buff, V_DVert);
GPU_IndexBufferDesc dvert_idxs_ib = GPU_IdxBuff32(dvert_idxs_buff); G_IndexBufferDesc dvert_idxs_ib = G_IdxBuff32(dvert_idxs_buff);
/* Params */ /* Params */
V_DParams params = ZI; V_DParams params = ZI;
@ -586,11 +586,11 @@ 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;
} }
GPU_ResourceHandle params_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(&params)); G_ResourceHandle params_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(&params));
StructuredBufferRef params_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams); StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams);
/* Constants */ /* Constants */
GPU_SetConstant(frame->cl, V_ShaderConst_Params, params_ro); G_SetConstant(frame->cl, V_ShaderConst_Params, params_ro);
Rng3 viewport = RNG3(VEC3(0, 0, 0), VEC3(draw_size.x, draw_size.y, 1)); Rng3 viewport = RNG3(VEC3(0, 0, 0), VEC3(draw_size.x, draw_size.y, 1));
Rng2 scissor = RNG2(VEC2(viewport.p0.x, viewport.p0.y), VEC2(viewport.p1.x, viewport.p1.y)); Rng2 scissor = RNG2(VEC2(viewport.p0.x, viewport.p0.y), VEC2(viewport.p1.x, viewport.p1.y));
@ -601,35 +601,35 @@ void V_TickForever(WaveLaneCtx *lane)
/* Backdrop pass */ /* Backdrop pass */
{ {
GPU_Compute(frame->cl, V_BackdropCS, V_BackdropCSThreadSizeFromTexSize(draw_size)); G_Compute(frame->cl, V_BackdropCS, V_BackdropCSThreadSizeFromTexSize(draw_size));
} }
////////////////////////////// //////////////////////////////
//- Shapes pass //- Shapes pass
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_RenderTargetWrite); G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_RenderTargetWrite);
/* Shapes pass */ /* Shapes pass */
{ {
GPU_Rasterize(frame->cl, G_Rasterize(frame->cl,
V_DVertVS, V_DVertPS, V_DVertVS, V_DVertPS,
1, dvert_idxs_ib, 1, dvert_idxs_ib,
1, &draw_target, 1, &draw_target,
viewport, scissor, viewport, scissor,
GPU_RasterMode_TriangleList); G_RasterMode_TriangleList);
} }
////////////////////////////// //////////////////////////////
//- Finalize draw target //- Finalize draw target
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_ShaderRead); G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_ShaderRead);
UI_SetRawTexture(vis_box, draw_target_ro, VEC2(0, 0), VEC2(1, 1)); UI_SetRawTexture(vis_box, draw_target_ro, VEC2(0, 0), VEC2(1, 1));
} }
////////////////////////////// //////////////////////////////
//- End frame //- End frame
GPU_CommitCommandList(frame->cl); G_CommitCommandList(frame->cl);
UI_EndFrame(ui_frame); UI_EndFrame(ui_frame);

View File

@ -78,11 +78,11 @@ Struct(V_Frame)
Arena *arena; Arena *arena;
Arena *dverts_arena; Arena *dverts_arena;
Arena *dvert_idxs_arena; Arena *dvert_idxs_arena;
GPU_ArenaHandle gpu_arena; G_ArenaHandle gpu_arena;
i64 tick; i64 tick;
i64 time_ns; i64 time_ns;
GPU_CommandListHandle cl; G_CommandListHandle cl;
}; };
Struct(V_State) Struct(V_State)

View File

@ -1,10 +1,10 @@
void PT_RunForever(WaveLaneCtx *lane) void PT_RunForever(WaveLaneCtx *lane)
{ {
GPU_ArenaHandle gpu_frame_arena = GPU_AcquireArena(); G_ArenaHandle gpu_frame_arena = G_AcquireArena();
for (;;) for (;;)
{ {
WND_Frame window_frame = WND_BeginFrame(GPU_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchWindow); WND_Frame window_frame = WND_BeginFrame(G_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchWindow);
for (u64 cev_idx = 0; cev_idx < window_frame.controller_events.count; ++cev_idx) for (u64 cev_idx = 0; cev_idx < window_frame.controller_events.count; ++cev_idx)
{ {
ControllerEvent *cev = &window_frame.controller_events.events[cev_idx]; ControllerEvent *cev = &window_frame.controller_events.events[cev_idx];
@ -17,64 +17,64 @@ void PT_RunForever(WaveLaneCtx *lane)
{ {
{ {
GPU_CommandListHandle cl = GPU_PrepareCommandList(GPU_QueueKind_Direct); G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct);
{ {
/* Push resources */ /* Push resources */
Vec2I32 final_target_size = window_frame.draw_size; Vec2I32 final_target_size = window_frame.draw_size;
GPU_ResourceHandle final_target = GPU_PushTexture2D(gpu_frame_arena, G_ResourceHandle final_target = G_PushTexture2D(gpu_frame_arena,
GPU_Format_R16G16B16A16_Float, G_Format_R16G16B16A16_Float,
final_target_size, final_target_size,
GPU_Layout_DirectQueue_ShaderReadWrite, G_Layout_DirectQueue_ShaderReadWrite,
.flags = GPU_ResourceFlag_AllowShaderReadWrite); .flags = G_ResourceFlag_AllowShaderReadWrite);
/* Push resource handles */ /* Push resource handles */
Texture2DRef final_target_rhandle = GPU_PushTexture2DRef(gpu_frame_arena, final_target); Texture2DRef final_target_rhandle = G_PushTexture2DRef(gpu_frame_arena, final_target);
RWTexture2DRef final_target_rwhandle = GPU_PushRWTexture2DRef(gpu_frame_arena, final_target); RWTexture2DRef final_target_rwhandle = G_PushRWTexture2DRef(gpu_frame_arena, final_target);
/* Prep test pass */ /* Prep test pass */
{ {
GPU_SetConstant(cl, PT_ShaderConst_TestTargetWidth, final_target_size.x); G_SetConstant(cl, PT_ShaderConst_TestTargetWidth, final_target_size.x);
GPU_SetConstant(cl, PT_ShaderConst_TestTargetHeight, final_target_size.y); G_SetConstant(cl, PT_ShaderConst_TestTargetHeight, final_target_size.y);
GPU_SetConstant(cl, PT_ShaderConst_TestTarget, final_target_rwhandle); G_SetConstant(cl, PT_ShaderConst_TestTarget, final_target_rwhandle);
GPU_SetConstant(cl, PT_ShaderConst_TestConst, 3.123); G_SetConstant(cl, PT_ShaderConst_TestConst, 3.123);
GPU_SetConstant(cl, PT_ShaderConst_BlitSampler, GPU_BasicPointSampler); G_SetConstant(cl, PT_ShaderConst_BlitSampler, G_BasicPointSampler);
GPU_SetConstant(cl, PT_ShaderConst_BlitSrc, final_target_rhandle); G_SetConstant(cl, PT_ShaderConst_BlitSrc, final_target_rhandle);
GPU_SetConstant(cl, PT_ShaderConst_NoiseTex, GPU_BasicNoiseTexture); G_SetConstant(cl, PT_ShaderConst_NoiseTex, G_BasicNoiseTexture);
} }
/* Test pass */ /* Test pass */
{ {
GPU_Compute(cl, PT_TestCS, VEC3I32((final_target_size.x + 7) / 8, (final_target_size.y + 7) / 8, 1)); G_Compute(cl, PT_TestCS, VEC3I32((final_target_size.x + 7) / 8, (final_target_size.y + 7) / 8, 1));
} }
GPU_DumbMemorySync(cl, final_target); G_DumbMemorySync(cl, final_target);
/* Prep blit pass */ /* Prep blit pass */
{ {
GPU_DumbMemoryLayoutSync(cl, final_target, GPU_Layout_DirectQueue_ShaderRead); G_DumbMemoryLayoutSync(cl, final_target, G_Layout_DirectQueue_ShaderRead);
GPU_DumbMemoryLayoutSync(cl, window_frame.backbuffer, GPU_Layout_DirectQueue_RenderTargetWrite); G_DumbMemoryLayoutSync(cl, window_frame.backbuffer, G_Layout_DirectQueue_RenderTargetWrite);
} }
/* Blit pass */ /* Blit pass */
{ {
GPU_Rasterize(cl, G_Rasterize(cl,
PT_BlitVS, PT_BlitPS, PT_BlitVS, PT_BlitPS,
1, GPU_GetSharedQuadIndices(), 1, G_GetSharedQuadIndices(),
1, &window_frame.backbuffer, 1, &window_frame.backbuffer,
GPU_ViewportFromTexture(window_frame.backbuffer), GPU_ScissorFromTexture(window_frame.backbuffer), G_ViewportFromTexture(window_frame.backbuffer), G_ScissorFromTexture(window_frame.backbuffer),
GPU_RasterMode_TriangleList); G_RasterMode_TriangleList);
} }
/* Finalize backbuffer layout */ /* Finalize backbuffer layout */
{ {
GPU_DumbMemoryLayoutSync(cl, window_frame.backbuffer, GPU_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present); G_DumbMemoryLayoutSync(cl, window_frame.backbuffer, G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present);
} }
/* Reset */ /* Reset */
{ {
GPU_ResetArena(cl, gpu_frame_arena); G_ResetArena(cl, gpu_frame_arena);
} }
} }
GPU_CommitCommandList(cl); G_CommitCommandList(cl);
} }
} }
WND_EndFrame(window_frame, VSYNC); WND_EndFrame(window_frame, VSYNC);

View File

@ -458,7 +458,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
UI_Frame *frame = &g->frames[i]; UI_Frame *frame = &g->frames[i];
frame->arena = AcquireArena(Gibi(64)); frame->arena = AcquireArena(Gibi(64));
frame->rects_arena = AcquireArena(Gibi(64)); frame->rects_arena = AcquireArena(Gibi(64));
frame->gpu_arena = GPU_AcquireArena(); frame->gpu_arena = G_AcquireArena();
} }
} }
@ -479,17 +479,17 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
{ {
Arena *old_arena = frame->arena; Arena *old_arena = frame->arena;
Arena *old_rects_arena = frame->arena; Arena *old_rects_arena = frame->arena;
GPU_ArenaHandle old_gpu_arena = frame->gpu_arena; G_ArenaHandle old_gpu_arena = frame->gpu_arena;
ZeroStruct(frame); ZeroStruct(frame);
frame->arena = old_arena; frame->arena = old_arena;
frame->rects_arena = old_rects_arena; frame->rects_arena = old_rects_arena;
frame->gpu_arena = old_gpu_arena; frame->gpu_arena = old_gpu_arena;
} }
frame->window_frame = WND_BeginFrame(GPU_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchMonitor); frame->window_frame = WND_BeginFrame(G_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchMonitor);
frame->cl = GPU_PrepareCommandList(GPU_QueueKind_Direct); frame->cl = G_PrepareCommandList(G_QueueKind_Direct);
ResetArena(frame->arena); ResetArena(frame->arena);
ResetArena(frame->rects_arena); ResetArena(frame->rects_arena);
GPU_ResetArena(frame->cl, frame->gpu_arena); G_ResetArena(frame->cl, frame->gpu_arena);
{ {
i64 now_ns = TimeNs(); i64 now_ns = TimeNs();
@ -1208,7 +1208,7 @@ void UI_EndFrame(UI_Frame *frame)
////////////////////////////// //////////////////////////////
//- Render //- Render
GPU_ResourceHandle backbuffer = frame->window_frame.backbuffer; G_ResourceHandle backbuffer = frame->window_frame.backbuffer;
{ {
////////////////////////////// //////////////////////////////
//- Build render data //- Build render data
@ -1371,18 +1371,18 @@ void UI_EndFrame(UI_Frame *frame)
//- Push data to GPU //- Push data to GPU
/* Target */ /* Target */
GPU_ResourceHandle draw_target = GPU_PushTexture2D( G_ResourceHandle draw_target = G_PushTexture2D(
frame->gpu_arena, frame->gpu_arena,
GPU_Format_R16G16B16A16_Float, G_Format_R16G16B16A16_Float,
monitor_size, monitor_size,
GPU_Layout_DirectQueue_RenderTargetWrite, G_Layout_DirectQueue_RenderTargetWrite,
.flags = GPU_ResourceFlag_AllowRenderTarget .flags = G_ResourceFlag_AllowRenderTarget
); );
Texture2DRef draw_target_ro = GPU_PushTexture2DRef(frame->gpu_arena, draw_target); Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target);
/* Rects */ /* Rects */
GPU_ResourceHandle rects_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->rects_arena)); G_ResourceHandle rects_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->rects_arena));
StructuredBufferRef rects_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, rects_buff, UI_DRect); StructuredBufferRef rects_ro = G_PushStructuredBufferRef(frame->gpu_arena, rects_buff, UI_DRect);
/* Params */ /* Params */
UI_DParams params = ZI; UI_DParams params = ZI;
@ -1391,70 +1391,70 @@ 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;
} }
GPU_ResourceHandle params_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(&params)); G_ResourceHandle params_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(&params));
StructuredBufferRef params_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams); StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams);
/* Constants */ /* Constants */
GPU_SetConstant(frame->cl, UI_ShaderConst_Params, params_ro); G_SetConstant(frame->cl, UI_ShaderConst_Params, params_ro);
////////////////////////////// //////////////////////////////
//- Dispatch shaders //- Dispatch shaders
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_RenderTargetWrite); G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_RenderTargetWrite);
//- Clear pass //- Clear pass
{ {
GPU_ClearRenderTarget(frame->cl, draw_target, VEC4(1, 0, 0, 1)); G_ClearRenderTarget(frame->cl, draw_target, VEC4(1, 0, 0, 1));
} }
//- Rect pass //- Rect pass
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_RenderTargetWrite); G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_RenderTargetWrite);
if (GPU_CountBufferBytes(rects_buff) > 0) if (G_CountBufferBytes(rects_buff) > 0)
{ {
/* Render rects */ /* Render rects */
GPU_Rasterize(frame->cl, G_Rasterize(frame->cl,
UI_DRectVS, UI_DRectPS, UI_DRectVS, UI_DRectPS,
1, GPU_GetSharedQuadIndices(), 1, G_GetSharedQuadIndices(),
1, &draw_target, 1, &draw_target,
draw_viewport, draw_scissor, draw_viewport, draw_scissor,
GPU_RasterMode_TriangleList); G_RasterMode_TriangleList);
/* Render rect wireframes */ /* Render rect wireframes */
if (AnyBit(frame->frame_flags, UI_FrameFlag_Debug)) if (AnyBit(frame->frame_flags, UI_FrameFlag_Debug))
{ {
GPU_SetConstant(frame->cl, UI_ShaderConst_DebugDraw, 1); G_SetConstant(frame->cl, UI_ShaderConst_DebugDraw, 1);
GPU_Rasterize(frame->cl, G_Rasterize(frame->cl,
UI_DRectVS, UI_DRectPS, UI_DRectVS, UI_DRectPS,
1, GPU_GetSharedQuadIndices(), 1, G_GetSharedQuadIndices(),
1, &draw_target, 1, &draw_target,
draw_viewport, draw_scissor, draw_viewport, draw_scissor,
GPU_RasterMode_WireTriangleList); G_RasterMode_WireTriangleList);
} }
} }
//- Backbuffer blit pass //- Backbuffer blit pass
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_ShaderRead); G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_ShaderRead);
GPU_DumbMemoryLayoutSync(frame->cl, backbuffer, GPU_Layout_DirectQueue_RenderTargetWrite); G_DumbMemoryLayoutSync(frame->cl, backbuffer, G_Layout_DirectQueue_RenderTargetWrite);
{ {
GPU_Rasterize(frame->cl, G_Rasterize(frame->cl,
UI_BlitVS, UI_BlitPS, UI_BlitVS, UI_BlitPS,
1, GPU_GetSharedQuadIndices(), 1, G_GetSharedQuadIndices(),
1, &backbuffer, 1, &backbuffer,
draw_viewport, draw_scissor, draw_viewport, draw_scissor,
GPU_RasterMode_TriangleList); G_RasterMode_TriangleList);
} }
GPU_DumbMemoryLayoutSync(frame->cl, backbuffer, GPU_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present); G_DumbMemoryLayoutSync(frame->cl, backbuffer, G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present);
} }
////////////////////////////// //////////////////////////////
//- End frame //- End frame
GPU_CommitCommandList(frame->cl); G_CommitCommandList(frame->cl);
WND_EndFrame(frame->window_frame, VSYNC); WND_EndFrame(frame->window_frame, VSYNC);
EndScratch(scratch); EndScratch(scratch);

View File

@ -313,11 +313,11 @@ Struct(UI_Frame)
{ {
Arena *arena; Arena *arena;
Arena *rects_arena; Arena *rects_arena;
GPU_ArenaHandle gpu_arena; G_ArenaHandle gpu_arena;
WND_Frame window_frame; WND_Frame window_frame;
GPU_ResourceHandle backbuffer; G_ResourceHandle backbuffer;
GPU_CommandListHandle cl; G_CommandListHandle cl;
u64 transient_key_seed; u64 transient_key_seed;

View File

@ -33,7 +33,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input)
{ {
UI_DParams params = StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0]; UI_DParams params = StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0];
StructuredBuffer<UI_DRect> rects = StructuredBufferFromRef<UI_DRect>(params.rects); StructuredBuffer<UI_DRect> rects = StructuredBufferFromRef<UI_DRect>(params.rects);
SamplerState sampler = SamplerStateFromRef(GPU_BasicPointSampler); SamplerState sampler = SamplerStateFromRef(G_BasicPointSampler);
UI_DRect rect = rects[input.rect_idx]; UI_DRect rect = rects[input.rect_idx];
@ -140,12 +140,12 @@ PixelShader(UI_BlitPS, UI_BlitPSOutput, UI_BlitPSInput input)
{ {
UI_DParams params = StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0]; UI_DParams params = StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0];
Texture2D<Vec4> tex = Texture2DFromRef<Vec4>(params.target_ro); Texture2D<Vec4> tex = Texture2DFromRef<Vec4>(params.target_ro);
SamplerState sampler = SamplerStateFromRef(GPU_BasicPointSampler); SamplerState sampler = SamplerStateFromRef(G_BasicPointSampler);
Vec2 uv = input.src_uv; Vec2 uv = input.src_uv;
Vec4 result = tex.Sample(sampler, uv); Vec4 result = tex.Sample(sampler, uv);
DebugPrint("Hello there"); G_DebugPrint("Hello there");
UI_BlitPSOutput output; UI_BlitPSOutput output;
output.SV_Target0 = result; output.SV_Target0 = result;

View File

@ -38,7 +38,7 @@ Enum(WND_BackbufferSizeMode)
Struct(WND_Frame) Struct(WND_Frame)
{ {
WND_Handle window; WND_Handle window;
GPU_ResourceHandle backbuffer; G_ResourceHandle backbuffer;
ControllerEventsArray controller_events; ControllerEventsArray controller_events;
@ -67,5 +67,5 @@ void WND_PushCmd_(WND_Frame frame, WND_Cmd desc);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Frame //~ @hookdecl Frame
WND_Frame WND_BeginFrame(GPU_Format backbuffer_format, WND_BackbufferSizeMode backbuffer_size_mode); WND_Frame WND_BeginFrame(G_Format backbuffer_format, WND_BackbufferSizeMode backbuffer_size_mode);
void WND_EndFrame(WND_Frame frame, i32 vsync); void WND_EndFrame(WND_Frame frame, i32 vsync);

View File

@ -145,7 +145,7 @@ void WND_W32_ProcessMessagesForever(WaveLaneCtx *lane)
//- Acquire swapchain //- Acquire swapchain
{ {
window->swapchain = GPU_AcquireSwapchain((u64)window->hwnd); window->swapchain = G_AcquireSwapchain((u64)window->hwnd);
} }
//- Begin processing messages //- Begin processing messages
@ -403,7 +403,7 @@ void WND_PushCmd_(WND_Frame frame, WND_Cmd desc)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookimpl Frame //~ @hookimpl Frame
WND_Frame WND_BeginFrame(GPU_Format backbuffer_format, WND_BackbufferSizeMode backbuffer_size_mode) WND_Frame WND_BeginFrame(G_Format backbuffer_format, WND_BackbufferSizeMode backbuffer_size_mode)
{ {
WND_W32_SharedState *g = &WND_W32_shared_state; WND_W32_SharedState *g = &WND_W32_shared_state;
WND_W32_Window *window = &g->window; WND_W32_Window *window = &g->window;
@ -449,7 +449,7 @@ WND_Frame WND_BeginFrame(GPU_Format backbuffer_format, WND_BackbufferSizeMode ba
{ {
backbuffer_size = result.monitor_size; backbuffer_size = result.monitor_size;
} }
result.backbuffer = GPU_PrepareBackbuffer(window->swapchain, backbuffer_format, backbuffer_size); result.backbuffer = G_PrepareBackbuffer(window->swapchain, backbuffer_format, backbuffer_size);
/* Reset per-frame data */ /* Reset per-frame data */
if (!window->frame_arena) if (!window->frame_arena)
@ -663,7 +663,7 @@ void WND_EndFrame(WND_Frame frame, i32 vsync)
} }
/* Commit backbuffer */ /* Commit backbuffer */
GPU_CommitBackbuffer(frame.backbuffer, vsync); G_CommitBackbuffer(frame.backbuffer, vsync);
++window->frame_gen; ++window->frame_gen;
EndScratch(scratch); EndScratch(scratch);

View File

@ -4,8 +4,8 @@
Struct(WND_W32_Window) Struct(WND_W32_Window)
{ {
HWND hwnd; HWND hwnd;
GPU_SwapchainHandle swapchain; G_SwapchainHandle swapchain;
GPU_ResourceHandle backbuffer; G_ResourceHandle backbuffer;
Atomic32 is_ready; Atomic32 is_ready;
/* Window proc state */ /* Window proc state */