change gpu layer namespace to 'G'
This commit is contained in:
parent
f773422abf
commit
8565cbea53
@ -8,7 +8,7 @@
|
||||
//////////////////////////////
|
||||
//- Resources
|
||||
|
||||
@EmbedDir GPU_Resources gpu_res
|
||||
@EmbedDir G_Resources gpu_res
|
||||
|
||||
//////////////////////////////
|
||||
//- Api
|
||||
@ -19,8 +19,8 @@
|
||||
|
||||
@IncludeG gpu_shader_core.cgh
|
||||
|
||||
@Bootstrap GPU_Bootstrap
|
||||
@Bootstrap GPU_BootstrapExtra
|
||||
@Bootstrap G_Bootstrap
|
||||
@Bootstrap G_BootstrapExtra
|
||||
|
||||
//////////////////////////////
|
||||
//- Impl
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
GPU_SharedUtilState GPU_shared_util_state = ZI;
|
||||
ThreadLocal GPU_ArenaHandle GPU_t_perm_arena = ZI;
|
||||
G_SharedUtilState G_shared_util_state = ZI;
|
||||
ThreadLocal G_ArenaHandle G_t_perm_arena = ZI;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ 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 */
|
||||
{
|
||||
GPU_ResourceHandle quad_indices = ZI;
|
||||
G_ResourceHandle quad_indices = ZI;
|
||||
u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
|
||||
quad_indices = GPU_PushBuffer(gpu_perm, u16, countof(quad_data));
|
||||
GPU_CopyCpuToBuffer(cl, quad_indices, 0, quad_data, RNGU64(0, sizeof(quad_data)));
|
||||
g->quad_indices = GPU_IdxBuff16(quad_indices);
|
||||
quad_indices = G_PushBuffer(gpu_perm, u16, countof(quad_data));
|
||||
G_CopyCpuToBuffer(cl, quad_indices, 0, quad_data, RNGU64(0, sizeof(quad_data)));
|
||||
g->quad_indices = G_IdxBuff16(quad_indices);
|
||||
}
|
||||
|
||||
/* TODO: Init debug print queues */
|
||||
@ -27,35 +27,35 @@ void GPU_BootstrapExtra(void)
|
||||
|
||||
/* Init point sampler */
|
||||
{
|
||||
GPU_ResourceHandle pt_sampler = GPU_PushSamplerResource(gpu_perm, (GPU_SamplerResourceDesc) { .filter = GPU_Filter_MinMagMipPoint });
|
||||
GPU_PushSamplerStateRef(gpu_perm, pt_sampler, .forced = GPU_BasicPointSampler.v);
|
||||
G_ResourceHandle pt_sampler = G_PushSamplerResource(gpu_perm, (G_SamplerResourceDesc) { .filter = G_Filter_MinMagMipPoint });
|
||||
G_PushSamplerStateRef(gpu_perm, pt_sampler, .forced = G_BasicPointSampler.v);
|
||||
}
|
||||
|
||||
/* Init noise texture */
|
||||
{
|
||||
GPU_ResourceHandle noise_tex = ZI;
|
||||
String noise_data = DataFromResource(ResourceKeyFromStore(&GPU_Resources, Lit("noise_128x128x64_16.dat")));
|
||||
G_ResourceHandle noise_tex = ZI;
|
||||
String noise_data = DataFromResource(ResourceKeyFromStore(&G_Resources, Lit("noise_128x128x64_16.dat")));
|
||||
Vec3I32 noise_dims = VEC3I32(128, 128, 64);
|
||||
if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2)
|
||||
{
|
||||
Panic(Lit("Unexpected noise texture size"));
|
||||
}
|
||||
noise_tex = GPU_PushTexture3D(gpu_perm,
|
||||
GPU_Format_R16_Uint,
|
||||
noise_tex = G_PushTexture3D(gpu_perm,
|
||||
G_Format_R16_Uint,
|
||||
noise_dims,
|
||||
GPU_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present);
|
||||
GPU_CopyCpuToTexture(cl,
|
||||
G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present);
|
||||
G_CopyCpuToTexture(cl,
|
||||
noise_tex, VEC3I32(0, 0, 0),
|
||||
noise_data.text, 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
|
||||
|
||||
GPU_ArenaHandle GPU_PermArena(void)
|
||||
G_ArenaHandle G_PermArena(void)
|
||||
{
|
||||
GPU_ArenaHandle perm = GPU_t_perm_arena;
|
||||
if (GPU_IsArenaNil(perm))
|
||||
G_ArenaHandle perm = G_t_perm_arena;
|
||||
if (G_IsArenaNil(perm))
|
||||
{
|
||||
GPU_t_perm_arena = GPU_AcquireArena();
|
||||
perm = GPU_t_perm_arena;
|
||||
G_t_perm_arena = G_AcquireArena();
|
||||
perm = G_t_perm_arena;
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
//- 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 });
|
||||
GPU_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len));
|
||||
GPU_MemorySync(
|
||||
G_ResourceHandle buffer = G_PushBufferResource(gpu_arena, (G_BufferResourceDesc) { .size = src.len });
|
||||
G_CopyCpuToBuffer(cl, buffer, 0, src.text, RNGU64(0, src.len));
|
||||
G_MemorySync(
|
||||
cl, buffer,
|
||||
GPU_Stage_Copy, GPU_Access_CopyWrite,
|
||||
GPU_Stage_All, GPU_Access_All
|
||||
G_Stage_Copy, G_Access_CopyWrite,
|
||||
G_Stage_All, G_Access_All
|
||||
);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
//- 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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
//- 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;
|
||||
}
|
||||
|
||||
@ -1,35 +1,35 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ State types
|
||||
|
||||
Struct(GPU_SharedUtilState)
|
||||
Struct(G_SharedUtilState)
|
||||
{
|
||||
/* Common shared resources */
|
||||
GPU_IndexBufferDesc quad_indices;
|
||||
} extern GPU_shared_util_state;
|
||||
G_IndexBufferDesc quad_indices;
|
||||
} extern G_shared_util_state;
|
||||
|
||||
extern ThreadLocal GPU_ArenaHandle GPU_t_perm_arena;
|
||||
extern ThreadLocal G_ArenaHandle G_t_perm_arena;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Bootstrap
|
||||
|
||||
void GPU_BootstrapExtra(void);
|
||||
void G_BootstrapExtra(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Helpers
|
||||
|
||||
//- Arena
|
||||
|
||||
GPU_ArenaHandle GPU_PermArena(void);
|
||||
G_ArenaHandle G_PermArena(void);
|
||||
|
||||
//- 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
|
||||
|
||||
Rng3 GPU_ViewportFromTexture(GPU_ResourceHandle texture);
|
||||
Rng2 GPU_ScissorFromTexture(GPU_ResourceHandle texture);
|
||||
Rng3 G_ViewportFromTexture(G_ResourceHandle texture);
|
||||
Rng2 G_ScissorFromTexture(G_ResourceHandle texture);
|
||||
|
||||
//- 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
@ -13,61 +13,61 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Tweakable defines
|
||||
|
||||
#define GPU_D12_TearingIsAllowed 1
|
||||
#define GPU_D12_FrameLatency 1
|
||||
#define GPU_D12_SwapchainBufferCount 3
|
||||
#define GPU_D12_SwapchainFlags (((GPU_D12_TearingIsAllowed != 0) * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) \
|
||||
| ((GPU_D12_FrameLatency != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT))
|
||||
#define G_D12_TearingIsAllowed 1
|
||||
#define G_D12_FrameLatency 1
|
||||
#define G_D12_SwapchainBufferCount 3
|
||||
#define G_D12_SwapchainFlags (((G_D12_TearingIsAllowed != 0) * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) \
|
||||
| ((G_D12_FrameLatency != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT))
|
||||
|
||||
|
||||
#define GPU_D12_MaxCbvSrvUavDescriptors (1024 * 128)
|
||||
#define GPU_D12_MaxSamplerDescriptors (1024 * 1)
|
||||
#define GPU_D12_MaxRtvDescriptors (1024 * 64)
|
||||
#define G_D12_MaxCbvSrvUavDescriptors (1024 * 128)
|
||||
#define G_D12_MaxSamplerDescriptors (1024 * 1)
|
||||
#define G_D12_MaxRtvDescriptors (1024 * 64)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Pipeline types
|
||||
|
||||
Struct(GPU_D12_PipelineDesc)
|
||||
Struct(G_D12_PipelineDesc)
|
||||
{
|
||||
VertexShader vs;
|
||||
PixelShader ps;
|
||||
ComputeShader cs;
|
||||
b32 is_wireframe;
|
||||
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;
|
||||
|
||||
GPU_D12_PipelineDesc desc;
|
||||
G_D12_PipelineDesc desc;
|
||||
ID3D12PipelineState *pso;
|
||||
|
||||
b32 ok;
|
||||
String error;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_PipelineBin)
|
||||
Struct(G_D12_PipelineBin)
|
||||
{
|
||||
Mutex mutex;
|
||||
GPU_D12_Pipeline *first;
|
||||
G_D12_Pipeline *first;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Descriptor types
|
||||
|
||||
Enum(GPU_D12_DescriptorHeapKind)
|
||||
Enum(G_D12_DescriptorHeapKind)
|
||||
{
|
||||
GPU_D12_DescriptorHeapKind_CbvSrvUav,
|
||||
GPU_D12_DescriptorHeapKind_Rtv,
|
||||
GPU_D12_DescriptorHeapKind_Sampler,
|
||||
G_D12_DescriptorHeapKind_CbvSrvUav,
|
||||
G_D12_DescriptorHeapKind_Rtv,
|
||||
G_D12_DescriptorHeapKind_Sampler,
|
||||
|
||||
GPU_D12_DescriptorHeapKind_Count
|
||||
G_D12_DescriptorHeapKind_Count
|
||||
};
|
||||
|
||||
Struct(GPU_D12_DescriptorHeap)
|
||||
Struct(G_D12_DescriptorHeap)
|
||||
{
|
||||
Arena *descriptors_arena;
|
||||
|
||||
@ -77,34 +77,34 @@ Struct(GPU_D12_DescriptorHeap)
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE start_handle;
|
||||
|
||||
Mutex mutex;
|
||||
struct GPU_D12_Descriptor *first_free;
|
||||
struct G_D12_Descriptor *first_free;
|
||||
u32 max_count;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_Descriptor)
|
||||
Struct(G_D12_Descriptor)
|
||||
{
|
||||
GPU_D12_Descriptor *next;
|
||||
GPU_D12_Descriptor *prev;
|
||||
G_D12_Descriptor *next;
|
||||
G_D12_Descriptor *prev;
|
||||
u64 queue_commit_target;
|
||||
|
||||
GPU_D12_DescriptorHeap *heap;
|
||||
G_D12_DescriptorHeap *heap;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle;
|
||||
u32 index;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_DescriptorList)
|
||||
Struct(G_D12_DescriptorList)
|
||||
{
|
||||
GPU_D12_Descriptor *first;
|
||||
GPU_D12_Descriptor *last;
|
||||
G_D12_Descriptor *first;
|
||||
G_D12_Descriptor *last;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Arena types
|
||||
|
||||
Struct(GPU_D12_Arena)
|
||||
Struct(G_D12_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:
|
||||
* To support D3D12_RESOURCE_HEAP_TIER_1 devices, create separate heaps for:
|
||||
@ -120,13 +120,13 @@ Struct(GPU_D12_Arena)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Resource types
|
||||
|
||||
Struct(GPU_D12_Resource)
|
||||
Struct(G_D12_Resource)
|
||||
{
|
||||
GPU_D12_Resource *next_free;
|
||||
G_D12_Resource *next_free;
|
||||
|
||||
ID3D12Resource *d3d_resource;
|
||||
u64 uid;
|
||||
GPU_ResourceFlag flags;
|
||||
G_ResourceFlag flags;
|
||||
|
||||
/* Buffer info */
|
||||
u64 buffer_size;
|
||||
@ -135,41 +135,41 @@ Struct(GPU_D12_Resource)
|
||||
|
||||
/* Texture info */
|
||||
b32 is_texture;
|
||||
GPU_Format texture_format;
|
||||
G_Format texture_format;
|
||||
Vec3I32 texture_dims;
|
||||
i32 texture_mip_levels;
|
||||
D3D12_BARRIER_LAYOUT texture_layout;
|
||||
|
||||
/* Sampler info */
|
||||
GPU_SamplerResourceDesc sampler_desc;
|
||||
G_SamplerResourceDesc sampler_desc;
|
||||
|
||||
/* Backbuffer info */
|
||||
struct GPU_D12_Swapchain *swapchain;
|
||||
struct G_D12_Swapchain *swapchain;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Staging types
|
||||
|
||||
Struct(GPU_D12_StagingHeap)
|
||||
Struct(G_D12_StagingHeap)
|
||||
{
|
||||
Arena *arena;
|
||||
|
||||
GPU_D12_Resource resource;
|
||||
G_D12_Resource resource;
|
||||
void *mapped;
|
||||
u64 size;
|
||||
|
||||
struct GPU_D12_StagingRegionNode *head_region_node;
|
||||
struct GPU_D12_StagingRegionNode *first_free_region_node;
|
||||
struct G_D12_StagingRegionNode *head_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) */
|
||||
GPU_D12_StagingRegionNode *prev;
|
||||
GPU_D12_StagingRegionNode *next;
|
||||
G_D12_StagingRegionNode *prev;
|
||||
G_D12_StagingRegionNode *next;
|
||||
|
||||
/* Region info */
|
||||
Atomic64 completion_target;
|
||||
@ -179,28 +179,28 @@ Struct(GPU_D12_StagingRegionNode)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Command queue types
|
||||
|
||||
Struct(GPU_D12_CommandQueueDesc)
|
||||
Struct(G_D12_CommandQueueDesc)
|
||||
{
|
||||
D3D12_COMMAND_LIST_TYPE type;
|
||||
D3D12_COMMAND_QUEUE_PRIORITY priority;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_Queue)
|
||||
Struct(G_D12_Queue)
|
||||
{
|
||||
ID3D12CommandQueue *d3d_queue;
|
||||
GPU_D12_CommandQueueDesc desc;
|
||||
G_D12_CommandQueueDesc desc;
|
||||
|
||||
Mutex commit_mutex;
|
||||
ID3D12Fence *commit_fence;
|
||||
u64 commit_fence_target;
|
||||
|
||||
/* Raw command lists */
|
||||
struct GPU_D12_RawCommandList *first_committed_cl;
|
||||
struct GPU_D12_RawCommandList *last_committed_cl;
|
||||
struct G_D12_RawCommandList *first_committed_cl;
|
||||
struct G_D12_RawCommandList *last_committed_cl;
|
||||
|
||||
/* Staging heap */
|
||||
Mutex staging_mutex;
|
||||
GPU_D12_StagingHeap *staging_heap;
|
||||
G_D12_StagingHeap *staging_heap;
|
||||
|
||||
Fence sync_fence;
|
||||
};
|
||||
@ -208,10 +208,10 @@ Struct(GPU_D12_Queue)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Raw command list types
|
||||
|
||||
Struct(GPU_D12_RawCommandList)
|
||||
Struct(G_D12_RawCommandList)
|
||||
{
|
||||
GPU_D12_Queue *queue;
|
||||
GPU_D12_RawCommandList *next;
|
||||
G_D12_Queue *queue;
|
||||
G_D12_RawCommandList *next;
|
||||
|
||||
u64 commit_fence_target;
|
||||
|
||||
@ -219,30 +219,30 @@ Struct(GPU_D12_RawCommandList)
|
||||
ID3D12GraphicsCommandList7 *d3d_cl;
|
||||
|
||||
/* Direct queue command lists keep a constant list of CPU-only descriptors */
|
||||
GPU_D12_Descriptor *rtv_descriptors[GPU_MaxRenderTargets];
|
||||
GPU_D12_Descriptor *rtv_clear_descriptor;
|
||||
G_D12_Descriptor *rtv_descriptors[G_MaxRenderTargets];
|
||||
G_D12_Descriptor *rtv_clear_descriptor;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ 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,
|
||||
GPU_D12_CmdKind_Barrier,
|
||||
GPU_D12_CmdKind_Constant,
|
||||
GPU_D12_CmdKind_CopyBytes,
|
||||
GPU_D12_CmdKind_CopyTexels,
|
||||
GPU_D12_CmdKind_Compute,
|
||||
GPU_D12_CmdKind_Rasterize,
|
||||
GPU_D12_CmdKind_ClearRtv,
|
||||
G_D12_CmdKind_None,
|
||||
G_D12_CmdKind_Barrier,
|
||||
G_D12_CmdKind_Constant,
|
||||
G_D12_CmdKind_CopyBytes,
|
||||
G_D12_CmdKind_CopyTexels,
|
||||
G_D12_CmdKind_Compute,
|
||||
G_D12_CmdKind_Rasterize,
|
||||
G_D12_CmdKind_ClearRtv,
|
||||
};
|
||||
|
||||
Struct(GPU_D12_Cmd)
|
||||
Struct(G_D12_Cmd)
|
||||
{
|
||||
GPU_D12_CmdKind kind;
|
||||
G_D12_CmdKind kind;
|
||||
b32 skip;
|
||||
union
|
||||
{
|
||||
@ -254,7 +254,7 @@ Struct(GPU_D12_Cmd)
|
||||
|
||||
struct
|
||||
{
|
||||
GPU_BarrierDesc desc;
|
||||
G_BarrierDesc desc;
|
||||
|
||||
/* Post-batch data */
|
||||
b32 is_end_of_batch;
|
||||
@ -263,16 +263,16 @@ Struct(GPU_D12_Cmd)
|
||||
|
||||
struct
|
||||
{
|
||||
GPU_D12_Resource *dst;
|
||||
GPU_D12_Resource *src;
|
||||
G_D12_Resource *dst;
|
||||
G_D12_Resource *src;
|
||||
u64 dst_offset;
|
||||
RngU64 src_copy_range;
|
||||
} copy_bytes;
|
||||
|
||||
struct
|
||||
{
|
||||
GPU_D12_Resource *dst;
|
||||
GPU_D12_Resource *src;
|
||||
G_D12_Resource *dst;
|
||||
G_D12_Resource *src;
|
||||
D3D12_TEXTURE_COPY_LOCATION dst_loc;
|
||||
D3D12_TEXTURE_COPY_LOCATION src_loc;
|
||||
Vec3I32 dst_offset;
|
||||
@ -290,36 +290,36 @@ Struct(GPU_D12_Cmd)
|
||||
VertexShader vs;
|
||||
PixelShader ps;
|
||||
u32 instances_count;
|
||||
GPU_IndexBufferDesc index_buffer_desc;
|
||||
GPU_D12_Resource *render_targets[GPU_MaxRenderTargets];
|
||||
G_IndexBufferDesc index_buffer_desc;
|
||||
G_D12_Resource *render_targets[G_MaxRenderTargets];
|
||||
Rng3 viewport;
|
||||
Rng2 scissor;
|
||||
GPU_RasterMode mode;
|
||||
G_RasterMode mode;
|
||||
} rasterize;
|
||||
|
||||
struct
|
||||
{
|
||||
GPU_D12_Resource *render_target;
|
||||
G_D12_Resource *render_target;
|
||||
Vec4 color;
|
||||
} clear_rtv;
|
||||
};
|
||||
};
|
||||
|
||||
Struct(GPU_D12_CmdChunk)
|
||||
Struct(G_D12_CmdChunk)
|
||||
{
|
||||
GPU_D12_CmdChunk *next;
|
||||
struct GPU_D12_CmdList *cl;
|
||||
GPU_D12_Cmd *cmds;
|
||||
G_D12_CmdChunk *next;
|
||||
struct G_D12_CmdList *cl;
|
||||
G_D12_Cmd *cmds;
|
||||
u64 cmds_count;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_CmdList)
|
||||
Struct(G_D12_CmdList)
|
||||
{
|
||||
GPU_QueueKind queue_kind;
|
||||
GPU_D12_CmdList *next;
|
||||
G_QueueKind queue_kind;
|
||||
G_D12_CmdList *next;
|
||||
|
||||
GPU_D12_CmdChunk *first_cmd_chunk;
|
||||
GPU_D12_CmdChunk *last_cmd_chunk;
|
||||
G_D12_CmdChunk *first_cmd_chunk;
|
||||
G_D12_CmdChunk *last_cmd_chunk;
|
||||
u64 chunks_count;
|
||||
u64 cmds_count;
|
||||
};
|
||||
@ -327,7 +327,7 @@ Struct(GPU_D12_CmdList)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Swapchain types
|
||||
|
||||
Struct(GPU_D12_Swapchain)
|
||||
Struct(G_D12_Swapchain)
|
||||
{
|
||||
|
||||
IDXGISwapChain3 *d3d_swapchain;
|
||||
@ -338,15 +338,15 @@ Struct(GPU_D12_Swapchain)
|
||||
ID3D12Fence *present_fence;
|
||||
u64 present_fence_target;
|
||||
|
||||
GPU_Format backbuffers_format;
|
||||
G_Format backbuffers_format;
|
||||
Vec2I32 backbuffers_resolution;
|
||||
GPU_D12_Resource backbuffers[GPU_D12_SwapchainBufferCount];
|
||||
G_D12_Resource backbuffers[G_D12_SwapchainBufferCount];
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ State types
|
||||
|
||||
Struct(GPU_D12_SharedState)
|
||||
Struct(G_D12_SharedState)
|
||||
{
|
||||
Atomic64Padded resource_creation_gen;
|
||||
|
||||
@ -355,80 +355,80 @@ Struct(GPU_D12_SharedState)
|
||||
Atomic64 driver_descriptors_allocated;
|
||||
|
||||
/* Queues */
|
||||
GPU_D12_Queue queues[GPU_NumQueues];
|
||||
G_D12_Queue queues[G_NumQueues];
|
||||
|
||||
/* Descriptor heaps */
|
||||
GPU_D12_DescriptorHeap descriptor_heaps[GPU_D12_DescriptorHeapKind_Count];
|
||||
G_D12_DescriptorHeap descriptor_heaps[G_D12_DescriptorHeapKind_Count];
|
||||
|
||||
/* Rootsig */
|
||||
ID3D12RootSignature *bindless_rootsig;
|
||||
|
||||
/* Pipelines */
|
||||
GPU_D12_PipelineBin pipeline_bins[1024];
|
||||
G_D12_PipelineBin pipeline_bins[1024];
|
||||
|
||||
/* Command lists */
|
||||
Mutex free_cmd_lists_mutex;
|
||||
GPU_D12_CmdList *first_free_cmd_list;
|
||||
G_D12_CmdList *first_free_cmd_list;
|
||||
|
||||
/* Command chunks */
|
||||
Mutex free_cmd_chunks_mutex;
|
||||
GPU_D12_CmdChunk *first_free_cmd_chunk;
|
||||
G_D12_CmdChunk *first_free_cmd_chunk;
|
||||
|
||||
/* Swapchains */
|
||||
Mutex free_swapchains_mutex;
|
||||
GPU_D12_Swapchain *first_free_swapchain;
|
||||
G_D12_Swapchain *first_free_swapchain;
|
||||
|
||||
/* Device */
|
||||
IDXGIFactory6 *factory;
|
||||
IDXGIAdapter3 *adapter;
|
||||
ID3D12Device10 *device;
|
||||
} extern GPU_D12_shared_state;
|
||||
} extern G_D12_shared_state;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ 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);
|
||||
GPU_D12_CmdList *GPU_D12_CmdListFromHandle(GPU_CommandListHandle handle);
|
||||
GPU_D12_Resource *GPU_D12_ResourceFromHandle(GPU_ResourceHandle handle);
|
||||
GPU_D12_Swapchain *GPU_D12_SwapchainFromHandle(GPU_SwapchainHandle handle);
|
||||
G_D12_Arena *G_D12_ArenaFromHandle(G_ArenaHandle handle);
|
||||
G_D12_CmdList *G_D12_CmdListFromHandle(G_CommandListHandle handle);
|
||||
G_D12_Resource *G_D12_ResourceFromHandle(G_ResourceHandle handle);
|
||||
G_D12_Swapchain *G_D12_SwapchainFromHandle(G_SwapchainHandle handle);
|
||||
|
||||
DXGI_FORMAT GPU_D12_DxgiFormatFromGpuFormat(GPU_Format format);
|
||||
D3D12_BARRIER_SYNC GPU_D12_BarrierSyncFromStages(GPU_Stage stages);
|
||||
D3D12_BARRIER_ACCESS GPU_D12_BarrierAccessFromAccesses(GPU_Access accesses);
|
||||
D3D12_BARRIER_LAYOUT GPU_D12_BarrierLayoutFromLayout(GPU_Layout layout);
|
||||
DXGI_FORMAT G_D12_DxgiFormatFromGpuFormat(G_Format format);
|
||||
D3D12_BARRIER_SYNC G_D12_BarrierSyncFromStages(G_Stage stages);
|
||||
D3D12_BARRIER_ACCESS G_D12_BarrierAccessFromAccesses(G_Access accesses);
|
||||
D3D12_BARRIER_LAYOUT G_D12_BarrierLayoutFromLayout(G_Layout layout);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Pipeline
|
||||
|
||||
GPU_D12_Pipeline *GPU_D12_PipelineFromDesc(GPU_D12_PipelineDesc desc);
|
||||
G_D12_Pipeline *G_D12_PipelineFromDesc(G_D12_PipelineDesc desc);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Queue
|
||||
|
||||
GPU_D12_Queue *GPU_D12_QueueFromKind(GPU_QueueKind kind);
|
||||
G_D12_Queue *G_D12_QueueFromKind(G_QueueKind kind);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Resource helpers
|
||||
|
||||
GPU_D12_Descriptor *GPU_D12_DescriptorFromIndex(GPU_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_DescriptorFromIndex(G_D12_DescriptorHeapKind heap_kind, u32 index);
|
||||
G_D12_Descriptor *G_D12_PushDescriptor(G_D12_Arena *gpu_arena, G_D12_DescriptorHeapKind heap_kind, u32 forced);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Raw command list
|
||||
|
||||
GPU_D12_RawCommandList *GPU_D12_PrepareRawCommandList(GPU_QueueKind queue_kind);
|
||||
void GPU_D12_CommitRawCommandList(GPU_D12_RawCommandList *cl);
|
||||
G_D12_RawCommandList *G_D12_PrepareRawCommandList(G_QueueKind queue_kind);
|
||||
void G_D12_CommitRawCommandList(G_D12_RawCommandList *cl);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Command helpers
|
||||
|
||||
GPU_D12_Cmd *GPU_D12_PushCmd(GPU_D12_CmdList *cl);
|
||||
GPU_D12_Cmd *GPU_D12_PushConstCmd(GPU_D12_CmdList *cl, i32 slot, void *v);
|
||||
GPU_D12_StagingRegionNode *GPU_D12_PushStagingRegion(GPU_D12_CmdList *cl, u64 size);
|
||||
G_D12_Cmd *G_D12_PushCmd(G_D12_CmdList *cl);
|
||||
G_D12_Cmd *G_D12_PushConstCmd(G_D12_CmdList *cl, i32 slot, void *v);
|
||||
G_D12_StagingRegionNode *G_D12_PushStagingRegion(G_D12_CmdList *cl, u64 size);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Workers
|
||||
|
||||
void GPU_D12_WorkerEntry(WaveLaneCtx *lane);
|
||||
void G_D12_WorkerEntry(WaveLaneCtx *lane);
|
||||
|
||||
@ -7,8 +7,8 @@
|
||||
/* Slots below assume they won't overlap user defined constants */
|
||||
StaticAssert(NumGeneralPurposeShaderConstants == 8);
|
||||
|
||||
ForceShaderConstant(RWByteAddressBufferRef, GPU_D12_DebugPrintBuff, 8);
|
||||
#define GPU_D12_NumShaderConstants (9)
|
||||
ForceShaderConstant(RWByteAddressBufferRef, G_D12_DebugPrintBuff, 8);
|
||||
#define G_D12_NumShaderConstants (9)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookimpl Shader printf
|
||||
@ -16,12 +16,12 @@ ForceShaderConstant(RWByteAddressBufferRef, GPU_D12_DebugPrintBuff, 8);
|
||||
#if IsLanguageG
|
||||
|
||||
/* This technique comes from MJP's article: https://therealmjp.github.io/posts/hlsl-printf/ */
|
||||
#if GPU_DEBUG
|
||||
#define DebugPrintImpl_(fmt_cstr) do { \
|
||||
#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(GPU_D12_DebugPrintBuff); \
|
||||
__print_buff = RWByteAddressBufferFromRef(G__D12_DebugPrintBuff); \
|
||||
u32 __pos; \
|
||||
__print_buff.InterlockedAdd(0, __strlen, __pos); \
|
||||
if (__pos < countof(__print_buff)) \
|
||||
@ -33,7 +33,7 @@ ForceShaderConstant(RWByteAddressBufferRef, GPU_D12_DebugPrintBuff, 8);
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define DebugPrintImpl_(fmt_cstr)
|
||||
#define G_DebugPrintImpl_(fmt_cstr)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,13 +2,13 @@
|
||||
//~ Shared static handles (common resources available to all shaders)
|
||||
|
||||
#if IsLanguageC
|
||||
#define GPU_SharedRef(type, v) ((type) { (v) })
|
||||
#define G_SharedRef(type, v) ((type) { (v) })
|
||||
#elif IsLanguageG
|
||||
#define GPU_SharedRef(type, v) (type(v))
|
||||
#define G_SharedRef(type, v) (type(v))
|
||||
#endif
|
||||
|
||||
#define GPU_BasicPointSampler GPU_SharedRef(SamplerStateRef, 1)
|
||||
#define GPU_BasicNoiseTexture GPU_SharedRef(Texture3DRef, 2)
|
||||
#define G_BasicPointSampler G_SharedRef(SamplerStateRef, 1)
|
||||
#define G_BasicNoiseTexture G_SharedRef(Texture3DRef, 2)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Shader printf
|
||||
@ -16,6 +16,6 @@
|
||||
#if IsLanguageG
|
||||
|
||||
/* Implemented per graphics platform layer */
|
||||
#define DebugPrint(msg) DebugPrintImpl_(msg)
|
||||
#define G_DebugPrint(msg) G_DebugPrintImpl_(msg)
|
||||
|
||||
#endif
|
||||
|
||||
@ -35,7 +35,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
frame->arena = AcquireArena(Gibi(64));
|
||||
frame->dverts_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_dverts_arena = frame->dverts_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);
|
||||
frame->arena = old_arena;
|
||||
frame->dverts_arena = old_dverts_arena;
|
||||
frame->dvert_idxs_arena = old_dvert_idxs_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->dverts_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->tick = last_frame->tick + 1;
|
||||
@ -561,21 +561,21 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
//- Push data to GPU
|
||||
|
||||
/* Target */
|
||||
GPU_ResourceHandle draw_target = GPU_PushTexture2D(
|
||||
G_ResourceHandle draw_target = G_PushTexture2D(
|
||||
frame->gpu_arena,
|
||||
GPU_Format_R16G16B16A16_Float,
|
||||
G_Format_R16G16B16A16_Float,
|
||||
window_frame.monitor_size,
|
||||
GPU_Layout_DirectQueue_ShaderReadWrite,
|
||||
.flags = GPU_ResourceFlag_AllowShaderReadWrite | GPU_ResourceFlag_AllowRenderTarget
|
||||
G_Layout_DirectQueue_ShaderReadWrite,
|
||||
.flags = G_ResourceFlag_AllowShaderReadWrite | G_ResourceFlag_AllowRenderTarget
|
||||
);
|
||||
Texture2DRef draw_target_ro = GPU_PushTexture2DRef(frame->gpu_arena, draw_target);
|
||||
RWTexture2DRef draw_target_rw = GPU_PushRWTexture2DRef(frame->gpu_arena, draw_target);
|
||||
Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target);
|
||||
RWTexture2DRef draw_target_rw = G_PushRWTexture2DRef(frame->gpu_arena, draw_target);
|
||||
|
||||
/* Verts */
|
||||
GPU_ResourceHandle dverts_buff = GPU_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));
|
||||
StructuredBufferRef dverts_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, dverts_buff, V_DVert);
|
||||
GPU_IndexBufferDesc dvert_idxs_ib = GPU_IdxBuff32(dvert_idxs_buff);
|
||||
G_ResourceHandle dverts_buff = G_PushBufferFromCpu(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));
|
||||
StructuredBufferRef dverts_ro = G_PushStructuredBufferRef(frame->gpu_arena, dverts_buff, V_DVert);
|
||||
G_IndexBufferDesc dvert_idxs_ib = G_IdxBuff32(dvert_idxs_buff);
|
||||
|
||||
/* Params */
|
||||
V_DParams params = ZI;
|
||||
@ -586,11 +586,11 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
params.shape_verts = dverts_ro;
|
||||
params.world_to_draw_xf = world_to_draw_xf;
|
||||
}
|
||||
GPU_ResourceHandle params_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(¶ms));
|
||||
StructuredBufferRef params_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams);
|
||||
G_ResourceHandle params_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(¶ms));
|
||||
StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams);
|
||||
|
||||
/* 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));
|
||||
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 */
|
||||
{
|
||||
GPU_Compute(frame->cl, V_BackdropCS, V_BackdropCSThreadSizeFromTexSize(draw_size));
|
||||
G_Compute(frame->cl, V_BackdropCS, V_BackdropCSThreadSizeFromTexSize(draw_size));
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- Shapes pass
|
||||
|
||||
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_RenderTargetWrite);
|
||||
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_RenderTargetWrite);
|
||||
|
||||
/* Shapes pass */
|
||||
{
|
||||
GPU_Rasterize(frame->cl,
|
||||
G_Rasterize(frame->cl,
|
||||
V_DVertVS, V_DVertPS,
|
||||
1, dvert_idxs_ib,
|
||||
1, &draw_target,
|
||||
viewport, scissor,
|
||||
GPU_RasterMode_TriangleList);
|
||||
G_RasterMode_TriangleList);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- 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));
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- End frame
|
||||
|
||||
GPU_CommitCommandList(frame->cl);
|
||||
G_CommitCommandList(frame->cl);
|
||||
|
||||
UI_EndFrame(ui_frame);
|
||||
|
||||
|
||||
@ -78,11 +78,11 @@ Struct(V_Frame)
|
||||
Arena *arena;
|
||||
Arena *dverts_arena;
|
||||
Arena *dvert_idxs_arena;
|
||||
GPU_ArenaHandle gpu_arena;
|
||||
G_ArenaHandle gpu_arena;
|
||||
|
||||
i64 tick;
|
||||
i64 time_ns;
|
||||
GPU_CommandListHandle cl;
|
||||
G_CommandListHandle cl;
|
||||
};
|
||||
|
||||
Struct(V_State)
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
void PT_RunForever(WaveLaneCtx *lane)
|
||||
{
|
||||
GPU_ArenaHandle gpu_frame_arena = GPU_AcquireArena();
|
||||
G_ArenaHandle gpu_frame_arena = G_AcquireArena();
|
||||
|
||||
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)
|
||||
{
|
||||
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 */
|
||||
Vec2I32 final_target_size = window_frame.draw_size;
|
||||
GPU_ResourceHandle final_target = GPU_PushTexture2D(gpu_frame_arena,
|
||||
GPU_Format_R16G16B16A16_Float,
|
||||
G_ResourceHandle final_target = G_PushTexture2D(gpu_frame_arena,
|
||||
G_Format_R16G16B16A16_Float,
|
||||
final_target_size,
|
||||
GPU_Layout_DirectQueue_ShaderReadWrite,
|
||||
.flags = GPU_ResourceFlag_AllowShaderReadWrite);
|
||||
G_Layout_DirectQueue_ShaderReadWrite,
|
||||
.flags = G_ResourceFlag_AllowShaderReadWrite);
|
||||
|
||||
/* Push resource handles */
|
||||
Texture2DRef final_target_rhandle = GPU_PushTexture2DRef(gpu_frame_arena, final_target);
|
||||
RWTexture2DRef final_target_rwhandle = GPU_PushRWTexture2DRef(gpu_frame_arena, final_target);
|
||||
Texture2DRef final_target_rhandle = G_PushTexture2DRef(gpu_frame_arena, final_target);
|
||||
RWTexture2DRef final_target_rwhandle = G_PushRWTexture2DRef(gpu_frame_arena, final_target);
|
||||
|
||||
/* Prep test pass */
|
||||
{
|
||||
GPU_SetConstant(cl, PT_ShaderConst_TestTargetWidth, final_target_size.x);
|
||||
GPU_SetConstant(cl, PT_ShaderConst_TestTargetHeight, final_target_size.y);
|
||||
GPU_SetConstant(cl, PT_ShaderConst_TestTarget, final_target_rwhandle);
|
||||
GPU_SetConstant(cl, PT_ShaderConst_TestConst, 3.123);
|
||||
GPU_SetConstant(cl, PT_ShaderConst_BlitSampler, GPU_BasicPointSampler);
|
||||
GPU_SetConstant(cl, PT_ShaderConst_BlitSrc, final_target_rhandle);
|
||||
GPU_SetConstant(cl, PT_ShaderConst_NoiseTex, GPU_BasicNoiseTexture);
|
||||
G_SetConstant(cl, PT_ShaderConst_TestTargetWidth, final_target_size.x);
|
||||
G_SetConstant(cl, PT_ShaderConst_TestTargetHeight, final_target_size.y);
|
||||
G_SetConstant(cl, PT_ShaderConst_TestTarget, final_target_rwhandle);
|
||||
G_SetConstant(cl, PT_ShaderConst_TestConst, 3.123);
|
||||
G_SetConstant(cl, PT_ShaderConst_BlitSampler, G_BasicPointSampler);
|
||||
G_SetConstant(cl, PT_ShaderConst_BlitSrc, final_target_rhandle);
|
||||
G_SetConstant(cl, PT_ShaderConst_NoiseTex, G_BasicNoiseTexture);
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
{
|
||||
GPU_DumbMemoryLayoutSync(cl, final_target, GPU_Layout_DirectQueue_ShaderRead);
|
||||
GPU_DumbMemoryLayoutSync(cl, window_frame.backbuffer, GPU_Layout_DirectQueue_RenderTargetWrite);
|
||||
G_DumbMemoryLayoutSync(cl, final_target, G_Layout_DirectQueue_ShaderRead);
|
||||
G_DumbMemoryLayoutSync(cl, window_frame.backbuffer, G_Layout_DirectQueue_RenderTargetWrite);
|
||||
}
|
||||
|
||||
/* Blit pass */
|
||||
{
|
||||
GPU_Rasterize(cl,
|
||||
G_Rasterize(cl,
|
||||
PT_BlitVS, PT_BlitPS,
|
||||
1, GPU_GetSharedQuadIndices(),
|
||||
1, G_GetSharedQuadIndices(),
|
||||
1, &window_frame.backbuffer,
|
||||
GPU_ViewportFromTexture(window_frame.backbuffer), GPU_ScissorFromTexture(window_frame.backbuffer),
|
||||
GPU_RasterMode_TriangleList);
|
||||
G_ViewportFromTexture(window_frame.backbuffer), G_ScissorFromTexture(window_frame.backbuffer),
|
||||
G_RasterMode_TriangleList);
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
{
|
||||
GPU_ResetArena(cl, gpu_frame_arena);
|
||||
G_ResetArena(cl, gpu_frame_arena);
|
||||
}
|
||||
}
|
||||
GPU_CommitCommandList(cl);
|
||||
G_CommitCommandList(cl);
|
||||
}
|
||||
}
|
||||
WND_EndFrame(window_frame, VSYNC);
|
||||
|
||||
@ -458,7 +458,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
|
||||
UI_Frame *frame = &g->frames[i];
|
||||
frame->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_rects_arena = frame->arena;
|
||||
GPU_ArenaHandle old_gpu_arena = frame->gpu_arena;
|
||||
G_ArenaHandle old_gpu_arena = frame->gpu_arena;
|
||||
ZeroStruct(frame);
|
||||
frame->arena = old_arena;
|
||||
frame->rects_arena = old_rects_arena;
|
||||
frame->gpu_arena = old_gpu_arena;
|
||||
}
|
||||
frame->window_frame = WND_BeginFrame(GPU_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchMonitor);
|
||||
frame->cl = GPU_PrepareCommandList(GPU_QueueKind_Direct);
|
||||
frame->window_frame = WND_BeginFrame(G_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchMonitor);
|
||||
frame->cl = G_PrepareCommandList(G_QueueKind_Direct);
|
||||
ResetArena(frame->arena);
|
||||
ResetArena(frame->rects_arena);
|
||||
GPU_ResetArena(frame->cl, frame->gpu_arena);
|
||||
G_ResetArena(frame->cl, frame->gpu_arena);
|
||||
|
||||
{
|
||||
i64 now_ns = TimeNs();
|
||||
@ -1208,7 +1208,7 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
//////////////////////////////
|
||||
//- Render
|
||||
|
||||
GPU_ResourceHandle backbuffer = frame->window_frame.backbuffer;
|
||||
G_ResourceHandle backbuffer = frame->window_frame.backbuffer;
|
||||
{
|
||||
//////////////////////////////
|
||||
//- Build render data
|
||||
@ -1371,18 +1371,18 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
//- Push data to GPU
|
||||
|
||||
/* Target */
|
||||
GPU_ResourceHandle draw_target = GPU_PushTexture2D(
|
||||
G_ResourceHandle draw_target = G_PushTexture2D(
|
||||
frame->gpu_arena,
|
||||
GPU_Format_R16G16B16A16_Float,
|
||||
G_Format_R16G16B16A16_Float,
|
||||
monitor_size,
|
||||
GPU_Layout_DirectQueue_RenderTargetWrite,
|
||||
.flags = GPU_ResourceFlag_AllowRenderTarget
|
||||
G_Layout_DirectQueue_RenderTargetWrite,
|
||||
.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 */
|
||||
GPU_ResourceHandle rects_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->rects_arena));
|
||||
StructuredBufferRef rects_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, rects_buff, UI_DRect);
|
||||
G_ResourceHandle rects_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromArena(frame->rects_arena));
|
||||
StructuredBufferRef rects_ro = G_PushStructuredBufferRef(frame->gpu_arena, rects_buff, UI_DRect);
|
||||
|
||||
/* Params */
|
||||
UI_DParams params = ZI;
|
||||
@ -1391,70 +1391,70 @@ void UI_EndFrame(UI_Frame *frame)
|
||||
params.target_ro = draw_target_ro;
|
||||
params.rects = rects_ro;
|
||||
}
|
||||
GPU_ResourceHandle params_buff = GPU_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(¶ms));
|
||||
StructuredBufferRef params_ro = GPU_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams);
|
||||
G_ResourceHandle params_buff = G_PushBufferFromCpu(frame->gpu_arena, frame->cl, StringFromStruct(¶ms));
|
||||
StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams);
|
||||
|
||||
/* Constants */
|
||||
GPU_SetConstant(frame->cl, UI_ShaderConst_Params, params_ro);
|
||||
G_SetConstant(frame->cl, UI_ShaderConst_Params, params_ro);
|
||||
|
||||
//////////////////////////////
|
||||
//- Dispatch shaders
|
||||
|
||||
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_RenderTargetWrite);
|
||||
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_RenderTargetWrite);
|
||||
|
||||
//- 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
|
||||
|
||||
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 */
|
||||
GPU_Rasterize(frame->cl,
|
||||
G_Rasterize(frame->cl,
|
||||
UI_DRectVS, UI_DRectPS,
|
||||
1, GPU_GetSharedQuadIndices(),
|
||||
1, G_GetSharedQuadIndices(),
|
||||
1, &draw_target,
|
||||
draw_viewport, draw_scissor,
|
||||
GPU_RasterMode_TriangleList);
|
||||
G_RasterMode_TriangleList);
|
||||
|
||||
/* Render rect wireframes */
|
||||
if (AnyBit(frame->frame_flags, UI_FrameFlag_Debug))
|
||||
{
|
||||
GPU_SetConstant(frame->cl, UI_ShaderConst_DebugDraw, 1);
|
||||
GPU_Rasterize(frame->cl,
|
||||
G_SetConstant(frame->cl, UI_ShaderConst_DebugDraw, 1);
|
||||
G_Rasterize(frame->cl,
|
||||
UI_DRectVS, UI_DRectPS,
|
||||
1, GPU_GetSharedQuadIndices(),
|
||||
1, G_GetSharedQuadIndices(),
|
||||
1, &draw_target,
|
||||
draw_viewport, draw_scissor,
|
||||
GPU_RasterMode_WireTriangleList);
|
||||
G_RasterMode_WireTriangleList);
|
||||
}
|
||||
}
|
||||
|
||||
//- Backbuffer blit pass
|
||||
|
||||
GPU_DumbMemoryLayoutSync(frame->cl, draw_target, GPU_Layout_DirectQueue_ShaderRead);
|
||||
GPU_DumbMemoryLayoutSync(frame->cl, backbuffer, GPU_Layout_DirectQueue_RenderTargetWrite);
|
||||
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_ShaderRead);
|
||||
G_DumbMemoryLayoutSync(frame->cl, backbuffer, G_Layout_DirectQueue_RenderTargetWrite);
|
||||
|
||||
{
|
||||
GPU_Rasterize(frame->cl,
|
||||
G_Rasterize(frame->cl,
|
||||
UI_BlitVS, UI_BlitPS,
|
||||
1, GPU_GetSharedQuadIndices(),
|
||||
1, G_GetSharedQuadIndices(),
|
||||
1, &backbuffer,
|
||||
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
|
||||
|
||||
GPU_CommitCommandList(frame->cl);
|
||||
G_CommitCommandList(frame->cl);
|
||||
WND_EndFrame(frame->window_frame, VSYNC);
|
||||
|
||||
EndScratch(scratch);
|
||||
|
||||
@ -313,11 +313,11 @@ Struct(UI_Frame)
|
||||
{
|
||||
Arena *arena;
|
||||
Arena *rects_arena;
|
||||
GPU_ArenaHandle gpu_arena;
|
||||
G_ArenaHandle gpu_arena;
|
||||
|
||||
WND_Frame window_frame;
|
||||
GPU_ResourceHandle backbuffer;
|
||||
GPU_CommandListHandle cl;
|
||||
G_ResourceHandle backbuffer;
|
||||
G_CommandListHandle cl;
|
||||
|
||||
u64 transient_key_seed;
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input)
|
||||
{
|
||||
UI_DParams params = StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0];
|
||||
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];
|
||||
|
||||
@ -140,12 +140,12 @@ PixelShader(UI_BlitPS, UI_BlitPSOutput, UI_BlitPSInput input)
|
||||
{
|
||||
UI_DParams params = StructuredBufferFromRef<UI_DParams>(UI_ShaderConst_Params)[0];
|
||||
Texture2D<Vec4> tex = Texture2DFromRef<Vec4>(params.target_ro);
|
||||
SamplerState sampler = SamplerStateFromRef(GPU_BasicPointSampler);
|
||||
SamplerState sampler = SamplerStateFromRef(G_BasicPointSampler);
|
||||
|
||||
Vec2 uv = input.src_uv;
|
||||
Vec4 result = tex.Sample(sampler, uv);
|
||||
|
||||
DebugPrint("Hello there");
|
||||
G_DebugPrint("Hello there");
|
||||
|
||||
UI_BlitPSOutput output;
|
||||
output.SV_Target0 = result;
|
||||
|
||||
@ -38,7 +38,7 @@ Enum(WND_BackbufferSizeMode)
|
||||
Struct(WND_Frame)
|
||||
{
|
||||
WND_Handle window;
|
||||
GPU_ResourceHandle backbuffer;
|
||||
G_ResourceHandle backbuffer;
|
||||
|
||||
ControllerEventsArray controller_events;
|
||||
|
||||
@ -67,5 +67,5 @@ void WND_PushCmd_(WND_Frame frame, WND_Cmd desc);
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @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);
|
||||
|
||||
@ -145,7 +145,7 @@ void WND_W32_ProcessMessagesForever(WaveLaneCtx *lane)
|
||||
|
||||
//- Acquire swapchain
|
||||
{
|
||||
window->swapchain = GPU_AcquireSwapchain((u64)window->hwnd);
|
||||
window->swapchain = G_AcquireSwapchain((u64)window->hwnd);
|
||||
}
|
||||
|
||||
//- Begin processing messages
|
||||
@ -403,7 +403,7 @@ void WND_PushCmd_(WND_Frame frame, WND_Cmd desc)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @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_Window *window = &g->window;
|
||||
@ -449,7 +449,7 @@ WND_Frame WND_BeginFrame(GPU_Format backbuffer_format, WND_BackbufferSizeMode ba
|
||||
{
|
||||
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 */
|
||||
if (!window->frame_arena)
|
||||
@ -663,7 +663,7 @@ void WND_EndFrame(WND_Frame frame, i32 vsync)
|
||||
}
|
||||
|
||||
/* Commit backbuffer */
|
||||
GPU_CommitBackbuffer(frame.backbuffer, vsync);
|
||||
G_CommitBackbuffer(frame.backbuffer, vsync);
|
||||
|
||||
++window->frame_gen;
|
||||
EndScratch(scratch);
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
Struct(WND_W32_Window)
|
||||
{
|
||||
HWND hwnd;
|
||||
GPU_SwapchainHandle swapchain;
|
||||
GPU_ResourceHandle backbuffer;
|
||||
G_SwapchainHandle swapchain;
|
||||
G_ResourceHandle backbuffer;
|
||||
Atomic32 is_ready;
|
||||
|
||||
/* Window proc state */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user