gpu layer refactor progress
This commit is contained in:
parent
0ac3284511
commit
f6c946cc64
@ -736,17 +736,17 @@ Struct(U128)
|
||||
|
||||
//- Pointers
|
||||
|
||||
Struct(GpuBufferPtr) { u32 v; };
|
||||
Struct(GpuRWBufferPtr) { u32 v; };
|
||||
Struct(GpuIndexBufferPtr) { u32 v; };
|
||||
Struct(GpuTexture1DPtr) { u32 v; };
|
||||
Struct(GpuRWTexture1DPtr) { u32 v; };
|
||||
Struct(GpuTexture2DPtr) { u32 v; };
|
||||
Struct(GpuRWTexture2DPtr) { u32 v; };
|
||||
Struct(GpuTexture3DPtr) { u32 v; };
|
||||
Struct(GpuRWTexture3DPtr) { u32 v; };
|
||||
Struct(GpuRasterTargetPtr) { u32 v; };
|
||||
Struct(GpuSamplerPtr) { u32 v; };
|
||||
Struct(BufferGpuPtr) { u32 v; };
|
||||
Struct(RWBufferGpuPtr) { u32 v; };
|
||||
Struct(IndexBufferGpuPtr) { u32 v; };
|
||||
Struct(Texture1DGpuPtr) { u32 v; };
|
||||
Struct(RWTexture1DGpuPtr) { u32 v; };
|
||||
Struct(Texture2DGpuPtr) { u32 v; };
|
||||
Struct(RWTexture2DGpuPtr) { u32 v; };
|
||||
Struct(Texture3DGpuPtr) { u32 v; };
|
||||
Struct(RWTexture3DGpuPtr) { u32 v; };
|
||||
Struct(RasterTargetGpuPtr) { u32 v; };
|
||||
Struct(SamplerGpuPtr) { u32 v; };
|
||||
|
||||
#define IsGpuPtrNil(p) ((p).v == 0)
|
||||
#elif IsLanguageGpu
|
||||
@ -764,17 +764,17 @@ Struct(U128)
|
||||
|
||||
//- Pointers
|
||||
|
||||
typedef GpuBufferPtr u32;
|
||||
typedef GpuRWBufferPtr u32;
|
||||
typedef GpuIndexBufferPtr u32;
|
||||
typedef GpuTexture1DPtr u32;
|
||||
typedef GpuRWTexture1DPtr u32;
|
||||
typedef GpuTexture2DPtr u32;
|
||||
typedef GpuRWTexture2DPtr u32;
|
||||
typedef GpuTexture3DPtr u32;
|
||||
typedef GpuRWTexture3DPtr u32;
|
||||
typedef GpuRasterTargetPtr u32;
|
||||
typedef GpuSamplerPtr u32;
|
||||
typedef BufferGpuPtr u32;
|
||||
typedef RWBufferGpuPtr u32;
|
||||
typedef IndexBufferGpuPtr u32;
|
||||
typedef Texture1DGpuPtr u32;
|
||||
typedef RWTexture1DGpuPtr u32;
|
||||
typedef Texture2DGpuPtr u32;
|
||||
typedef RWTexture2DGpuPtr u32;
|
||||
typedef Texture3DGpuPtr u32;
|
||||
typedef RWTexture3DGpuPtr u32;
|
||||
typedef RasterTargetGpuPtr u32;
|
||||
typedef SamplerGpuPtr u32;
|
||||
|
||||
#define IsGpuPtrNil(p) ((p) == 0)
|
||||
|
||||
|
||||
@ -7,43 +7,43 @@ void GPU_StartupCommon(void)
|
||||
{
|
||||
GPU_SharedUtilState *g = &GPU_shared_util_state;
|
||||
|
||||
GPU_ArenaHandle gpu_perm = GPU_PermArena();
|
||||
// GPU_ArenaHandle gpu_perm = GPU_PermArena();
|
||||
|
||||
/* Init point sampler */
|
||||
GPU_ResourceHandle pt_sampler = GPU_PushSampler(gpu_perm, (GPU_SamplerDesc) { .filter = GPU_Filter_MinMagMipPoint });
|
||||
g->pt_sampler = GPU_PushSamplerPtr(gpu_perm, pt_sampler);
|
||||
// /* Init point sampler */
|
||||
// GPU_ResourceHandle pt_sampler = GPU_PushSampler(gpu_perm, (GPU_SamplerDesc) { .filter = GPU_Filter_MinMagMipPoint });
|
||||
// g->pt_sampler = GPU_PushSamplerPtr(gpu_perm, pt_sampler);
|
||||
|
||||
GPU_CommandListHandle cl = GPU_OpenCommandList(GPU_QueueKind_Direct);
|
||||
{
|
||||
/* Init noise texture */
|
||||
String noise_data = DataFromResource(ResourceKeyFromStore(&GPU_Resources, Lit("noise_128x128x64_16.dat")));
|
||||
Vec3I32 noise_dims = VEC3I32(128, 128, 64);
|
||||
GPU_ResourceHandle noise_tex = ZI;
|
||||
{
|
||||
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, noise_dims, GPU_Format_R16_Uint, GPU_AccessKind_CopyWrite);
|
||||
GPU_CopyResourceFromCpu(cl, noise_tex, noise_data);
|
||||
}
|
||||
// GPU_CommandListHandle cl = GPU_PrepareCommandList();
|
||||
// {
|
||||
// /* Init noise texture */
|
||||
// String noise_data = DataFromResource(ResourceKeyFromStore(&GPU_Resources, Lit("noise_128x128x64_16.dat")));
|
||||
// Vec3I32 noise_dims = VEC3I32(128, 128, 64);
|
||||
// GPU_ResourceHandle noise_tex = ZI;
|
||||
// {
|
||||
// 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, noise_dims, GPU_Format_R16_Uint, GPU_AccessKind_CopyWrite);
|
||||
// GPU_CopyResourceFromCpu(cl, noise_tex, noise_data);
|
||||
// }
|
||||
|
||||
/* Init quad index buffer */
|
||||
GPU_ResourceHandle quad_indices = ZI;
|
||||
{
|
||||
u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
|
||||
quad_indices = GPU_PushBuffer(gpu_perm, u16, GPU_AccessKind_CopyWrite);
|
||||
GPU_CopyResourceFromCpu(cl, quad_indices, StringFromArray(quad_data));
|
||||
}
|
||||
// /* Init quad index buffer */
|
||||
// GPU_ResourceHandle quad_indices = ZI;
|
||||
// {
|
||||
// u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
|
||||
// quad_indices = GPU_PushBuffer(gpu_perm, u16, GPU_AccessKind_CopyWrite);
|
||||
// GPU_CopyResourceFromCpu(cl, quad_indices, StringFromArray(quad_data));
|
||||
// }
|
||||
|
||||
g->noise_tex = GPU_PushTexture3DPtr(gpu_perm, noise_tex);
|
||||
g->quad_indices = GPU_PushIndexBufferPtr(gpu_perm, quad_indices, u16);
|
||||
// g->noise_tex = GPU_PushTexture3DPtr(gpu_perm, noise_tex);
|
||||
// g->quad_indices = GPU_PushIndexBufferPtr(gpu_perm, quad_indices, u16);
|
||||
|
||||
/* FIXME: Block other queues until common startup finishes here */
|
||||
GPU_SetAccess(cl, noise_tex, GPU_AccessKind_AnyRead);
|
||||
GPU_SetAccess(cl, quad_indices, GPU_AccessKind_AnyRead);
|
||||
}
|
||||
GPU_CloseCommandList(cl);
|
||||
// /* FIXME: Block other queues until common startup finishes here */
|
||||
// GPU_SyncAccess(cl, noise_tex, GPU_AccessKind_AnyRead);
|
||||
// GPU_SyncAccess(cl, quad_indices, GPU_AccessKind_AnyRead);
|
||||
// }
|
||||
// GPU_CommitCommandList(cl, GPU_QueueKind_Direct);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -72,17 +72,17 @@ void GPU_CopyResourceFromCpu(GPU_CommandListHandle cl, GPU_ResourceHandle dst, S
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Common resource helpers
|
||||
|
||||
GpuSamplerPtr GPU_GetCommonPointSampler(void)
|
||||
SamplerGpuPtr GPU_GetCommonPointSampler(void)
|
||||
{
|
||||
return GPU_shared_util_state.pt_sampler;
|
||||
}
|
||||
|
||||
GpuIndexBufferPtr GPU_GetCommonQuadIndices(void)
|
||||
IndexBufferGpuPtr GPU_GetCommonQuadIndices(void)
|
||||
{
|
||||
return GPU_shared_util_state.quad_indices;
|
||||
}
|
||||
|
||||
GpuTexture3DPtr GPU_GetCommonNoise(void)
|
||||
Texture3DGpuPtr GPU_GetCommonNoise(void)
|
||||
{
|
||||
return GPU_shared_util_state.noise_tex;
|
||||
}
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
Struct(GPU_SharedUtilState)
|
||||
{
|
||||
/* Common shared resources */
|
||||
GpuSamplerPtr pt_sampler;
|
||||
GpuIndexBufferPtr quad_indices;
|
||||
GpuTexture3DPtr noise_tex;
|
||||
SamplerGpuPtr pt_sampler;
|
||||
IndexBufferGpuPtr quad_indices;
|
||||
Texture3DGpuPtr noise_tex;
|
||||
|
||||
GPU_ArenaHandle perm_arenas[MaxFibers];
|
||||
} extern GPU_shared_util_state;
|
||||
@ -29,6 +29,6 @@ void GPU_CopyResourceFromCpu(GPU_CommandListHandle cl, GPU_ResourceHandle dst, S
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Common resource helpers
|
||||
|
||||
GpuSamplerPtr GPU_GetCommonPointSampler(void);
|
||||
GpuIndexBufferPtr GPU_GetCommonQuadIndices(void);
|
||||
GpuTexture3DPtr GPU_GetCommonNoise(void);
|
||||
SamplerGpuPtr GPU_GetCommonPointSampler(void);
|
||||
IndexBufferGpuPtr GPU_GetCommonQuadIndices(void);
|
||||
Texture3DGpuPtr GPU_GetCommonNoise(void);
|
||||
|
||||
@ -187,10 +187,9 @@ Enum(GPU_AccessKind)
|
||||
GPU_AccessKind_PixelRead,
|
||||
GPU_AccessKind_PixelReadWrite,
|
||||
|
||||
GPU_AccessKind_DepthStencilRead,
|
||||
GPU_AccessKind_DepthStencilReadWrite,
|
||||
GPU_AccessKind_RasterTarget,
|
||||
|
||||
GPU_AccessKind_RasterTargetWrite,
|
||||
GPU_AccessKind_Present,
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -425,17 +424,17 @@ GPU_ResourceHandle GPU_PushSampler(GPU_ArenaHandle arena, GPU_SamplerDesc desc);
|
||||
|
||||
//- Pointer creation
|
||||
|
||||
GpuBufferPtr GPU_PushBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||
GpuRWBufferPtr GPU_PushRWBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||
GpuIndexBufferPtr GPU_PushIndexBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||
GpuTexture1DPtr GPU_PushTexture1DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
GpuRWTexture1DPtr GPU_PushRWTexture1DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
GpuTexture2DPtr GPU_PushTexture2DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
GpuRWTexture2DPtr GPU_PushRWTexture2DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
GpuTexture3DPtr GPU_PushTexture3DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
GpuRWTexture3DPtr GPU_PushRWTexture3DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
GpuRasterTargetPtr GPU_PushRasterTargetPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
GpuSamplerPtr GPU_PushSamplerPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
BufferGpuPtr GPU_PushBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||
RWBufferGpuPtr GPU_PushRWBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||
IndexBufferGpuPtr GPU_PushIndexBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
|
||||
Texture1DGpuPtr GPU_PushTexture1DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
RWTexture1DGpuPtr GPU_PushRWTexture1DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
Texture2DGpuPtr GPU_PushTexture2DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
RWTexture2DGpuPtr GPU_PushRWTexture2DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
Texture3DGpuPtr GPU_PushTexture3DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
RWTexture3DGpuPtr GPU_PushRWTexture3DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
RasterTargetGpuPtr GPU_PushRasterTargetPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
SamplerGpuPtr GPU_PushSamplerPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
|
||||
|
||||
#define GPU_PushBufferPtr(arena, resource, type) GPU_PushBufferPtrEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
|
||||
#define GPU_PushRWBufferPtr(arena, resource, type) GPU_PushRWBufferPtrEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
|
||||
@ -454,8 +453,8 @@ u64 GPU_Count3D(GPU_ResourceHandle texture3d);
|
||||
//~ @hookdecl Command
|
||||
|
||||
//- Command list
|
||||
GPU_CommandListHandle GPU_OpenCommandList(GPU_QueueKind queue);
|
||||
void GPU_CloseCommandList(GPU_CommandListHandle cl);
|
||||
GPU_CommandListHandle GPU_PrepareCommandList(void);
|
||||
void GPU_CommitCommandList(GPU_CommandListHandle cl, GPU_QueueKind queue);
|
||||
|
||||
//- Arena
|
||||
void GPU_ResetArena(GPU_CommandListHandle cl, GPU_ArenaHandle arena);
|
||||
@ -467,20 +466,18 @@ void GPU_CopyTexture(GPU_CommandListHandle cl, GPU_ResourceHandle dst, Vec3I32 d
|
||||
//- Constants
|
||||
void GPU_SetConstU32 (GPU_CommandListHandle cl, i32 slot, u32 v);
|
||||
void GPU_SetConstF32 (GPU_CommandListHandle cl, i32 slot, f32 v);
|
||||
void GPU_SetConstBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuBufferPtr v);
|
||||
void GPU_SetConstRWBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuRWBufferPtr v);
|
||||
void GPU_SetConstIndexBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuIndexBufferPtr v);
|
||||
void GPU_SetConstTexture1DPtr (GPU_CommandListHandle cl, i32 slot, GpuTexture1DPtr v);
|
||||
void GPU_SetConstRWTexture1DPtr (GPU_CommandListHandle cl, i32 slot, GpuRWTexture1DPtr v);
|
||||
void GPU_SetConstTexture2DPtr (GPU_CommandListHandle cl, i32 slot, GpuTexture2DPtr v);
|
||||
void GPU_SetConstRWTexture2DPtr (GPU_CommandListHandle cl, i32 slot, GpuRWTexture2DPtr v);
|
||||
void GPU_SetConstTexture3DPtr (GPU_CommandListHandle cl, i32 slot, GpuTexture3DPtr v);
|
||||
void GPU_SetConstRWTexture3DPtr (GPU_CommandListHandle cl, i32 slot, GpuRWTexture3DPtr v);
|
||||
void GPU_SetConstRasterTargetPtr (GPU_CommandListHandle cl, i32 slot, GpuRasterTargetPtr v);
|
||||
void GPU_SetConstSamplerPtr (GPU_CommandListHandle cl, i32 slot, GpuSamplerPtr v);
|
||||
void GPU_SetConstBuffer (GPU_CommandListHandle cl, i32 slot, BufferGpuPtr v);
|
||||
void GPU_SetConstRWBuffer (GPU_CommandListHandle cl, i32 slot, RWBufferGpuPtr v);
|
||||
void GPU_SetConstTexture1D (GPU_CommandListHandle cl, i32 slot, Texture1DGpuPtr v);
|
||||
void GPU_SetConstRWTexture1D (GPU_CommandListHandle cl, i32 slot, RWTexture1DGpuPtr v);
|
||||
void GPU_SetConstTexture2D (GPU_CommandListHandle cl, i32 slot, Texture2DGpuPtr v);
|
||||
void GPU_SetConstRWTexture2D (GPU_CommandListHandle cl, i32 slot, RWTexture2DGpuPtr v);
|
||||
void GPU_SetConstTexture3D (GPU_CommandListHandle cl, i32 slot, Texture3DGpuPtr v);
|
||||
void GPU_SetConstRWTexture3D (GPU_CommandListHandle cl, i32 slot, RWTexture3DGpuPtr v);
|
||||
void GPU_SetConstSampler (GPU_CommandListHandle cl, i32 slot, SamplerGpuPtr v);
|
||||
|
||||
//- Access
|
||||
void GPU_SetAccess(GPU_CommandListHandle cl, GPU_ResourceHandle resource, GPU_AccessKind kind);
|
||||
void GPU_SyncAccess(GPU_CommandListHandle cl, GPU_ResourceHandle resource, GPU_AccessKind kind);
|
||||
|
||||
//- Compute
|
||||
void GPU_Compute(GPU_CommandListHandle cl, ComputeShader cs, Vec3I32 groups);
|
||||
@ -488,17 +485,22 @@ void GPU_Compute(GPU_CommandListHandle cl, ComputeShader cs, Vec3I32 groups);
|
||||
//- Rasterize
|
||||
void GPU_Rasterize(GPU_CommandListHandle cl,
|
||||
VertexShader vs, PixelShader ps,
|
||||
u32 instances_count, GpuIndexBufferPtr idx_buff,
|
||||
u32 raster_targets_count, GpuRasterTargetPtr *raster_targets,
|
||||
u32 instances_count, IndexBufferGpuPtr idx_buff,
|
||||
u32 raster_targets_count, RasterTargetGpuPtr *raster_targets,
|
||||
Rng3 viewport, Rng2 scissor,
|
||||
GPU_RasterMode mode);
|
||||
|
||||
//- Clear
|
||||
void GPU_ClearRasterTarget(GPU_CommandListHandle cl, GpuRasterTargetPtr ptr);
|
||||
void GPU_ClearRasterTarget(GPU_CommandListHandle cl, RasterTargetGpuPtr ptr, Vec4 color);
|
||||
|
||||
//- Profile
|
||||
void GPU_ProfN(GPU_CommandListHandle cl, String name);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Synchronization
|
||||
|
||||
void GPU_CpuWaitOnQueue(GPU_QueueKind queue_kind);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Statistics
|
||||
|
||||
@ -507,19 +509,11 @@ GPU_Stats GPU_QueryStats(void);
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Swapchain
|
||||
|
||||
GPU_SwapchainHandle GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size);
|
||||
GPU_SwapchainHandle GPU_AcquireSwapchain(WND_Handle window);
|
||||
void GPU_ReleaseSwapchain(GPU_SwapchainHandle swapchain);
|
||||
|
||||
/* Waits until a new backbuffer is ready to be written to.
|
||||
/* Waits until a new backbuffer is ready from the swapchain.
|
||||
* This should be called before rendering for minimum latency. */
|
||||
void GPU_YieldOnSwapchain(GPU_SwapchainHandle swapchain);
|
||||
GPU_ResourceHandle GPU_PrepareBackbuffer(GPU_SwapchainHandle swapchain_handle, GPU_Format format, Vec2I32 size);
|
||||
|
||||
/* 1. Recreates backbuffer at desired size if necessary
|
||||
* 2. Clears the backbuffer using clear color
|
||||
* 3. Blits the source texture into the backbuffer
|
||||
* 4. Presents the backbuffer
|
||||
*/
|
||||
void GPU_PresentSwapchain(GPU_SwapchainHandle swapchain, Vec4 dst_clear_color,
|
||||
Vec2U32 dst_size, Vec2U32 dst_offset,
|
||||
GpuTexture2DPtr src, Vec2U32 src_offset,
|
||||
i32 vsync);
|
||||
void GPU_CommitBackbuffer(GPU_ResourceHandle backbuffer, i32 vsync);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -24,14 +24,6 @@
|
||||
#define GPU_D12_MaxSamplerDescriptors (1024 * 1)
|
||||
#define GPU_D12_MaxRtvDescriptors (1024 * 64)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Arena types
|
||||
|
||||
Struct(GPU_D12_Arena)
|
||||
{
|
||||
i32 _;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Pipeline types
|
||||
|
||||
@ -67,23 +59,18 @@ Struct(GPU_D12_PipelineBin)
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Descriptor types
|
||||
|
||||
Struct(GPU_D12_Descriptor)
|
||||
Enum(GPU_D12_DescriptorHeapKind)
|
||||
{
|
||||
GPU_D12_Descriptor *next_free;
|
||||
GPU_D12_DescriptorHeapKind_CbvSrvUav,
|
||||
GPU_D12_DescriptorHeapKind_Rtv,
|
||||
GPU_D12_DescriptorHeapKind_Sampler,
|
||||
|
||||
struct GPU_D12_DescriptorHeap *heap;
|
||||
struct GPU_D12_Resource *resource;
|
||||
|
||||
b32 valid;
|
||||
u32 index;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle;
|
||||
} extern Readonly GPU_D12_NilDescriptor = {
|
||||
.index = U32Max
|
||||
GPU_D12_DescriptorHeapKind_Count
|
||||
};
|
||||
|
||||
Struct(GPU_D12_DescriptorHeap)
|
||||
{
|
||||
Arena *arena;
|
||||
Arena *descriptors_arena;
|
||||
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE type;
|
||||
u32 descriptor_size;
|
||||
@ -91,49 +78,60 @@ Struct(GPU_D12_DescriptorHeap)
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE start_handle;
|
||||
|
||||
Mutex mutex;
|
||||
GPU_D12_Descriptor *first_free;
|
||||
struct GPU_D12_Descriptor *first_free;
|
||||
u32 allocated_count;
|
||||
u32 max_count;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_Descriptor)
|
||||
{
|
||||
GPU_D12_Descriptor *next;
|
||||
u64 queue_commit_target;
|
||||
|
||||
GPU_D12_DescriptorHeap *heap;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle;
|
||||
u32 index;
|
||||
|
||||
struct GPU_D12_Resource *resource;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_DescriptorList)
|
||||
{
|
||||
GPU_D12_Descriptor *first;
|
||||
GPU_D12_Descriptor *last;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Arena types
|
||||
|
||||
Struct(GPU_D12_Arena)
|
||||
{
|
||||
GPU_D12_DescriptorList committed_descriptors_by_heap_and_queue[GPU_D12_DescriptorHeapKind_Count][GPU_NumQueues];
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Resource types
|
||||
|
||||
Struct(GPU_D12_Resource)
|
||||
{
|
||||
GPU_D12_Resource *next_free;
|
||||
|
||||
ID3D12Resource *d3d_resource;
|
||||
|
||||
D3D12_BARRIER_LAYOUT layout;
|
||||
|
||||
/* Buffer info */
|
||||
GPU_BufferDesc buffer_desc;
|
||||
D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address;
|
||||
|
||||
/* Texture info */
|
||||
b32 is_texture;
|
||||
D3D12_BARRIER_LAYOUT texture_layout;
|
||||
GPU_TextureDesc texture_desc;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_ResourceReuseList)
|
||||
{
|
||||
u64 hash;
|
||||
GPU_D12_ResourceReuseList *next;
|
||||
GPU_D12_ResourceReuseList *prev;
|
||||
GPU_D12_Resource *first;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_ResourceReuseListBin)
|
||||
{
|
||||
Mutex mutex;
|
||||
GPU_D12_ResourceReuseList *first;
|
||||
GPU_D12_ResourceReuseList *last;
|
||||
GPU_D12_ResourceReuseList *first_free;
|
||||
/* Backbuffer info */
|
||||
struct GPU_D12_Swapchain *swapchain;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Queue types
|
||||
//~ Command queue types
|
||||
|
||||
Struct(GPU_D12_CommandQueueDesc)
|
||||
{
|
||||
@ -146,11 +144,11 @@ Struct(GPU_D12_Queue)
|
||||
ID3D12CommandQueue *d3d_queue;
|
||||
GPU_D12_CommandQueueDesc desc;
|
||||
|
||||
Mutex submit_mutex;
|
||||
ID3D12Fence *submit_fence;
|
||||
u64 submit_fence_target;
|
||||
struct GPU_D12_RawCommandList *first_submitted_cl;
|
||||
struct GPU_D12_RawCommandList *last_submitted_cl;
|
||||
Mutex commit_mutex;
|
||||
ID3D12Fence *commit_fence;
|
||||
u64 commit_fence_target;
|
||||
struct GPU_D12_RawCommandList *first_committed_cl;
|
||||
struct GPU_D12_RawCommandList *last_committed_cl;
|
||||
|
||||
Fence sync_fence;
|
||||
};
|
||||
@ -163,7 +161,7 @@ Struct(GPU_D12_RawCommandList)
|
||||
GPU_D12_Queue *queue;
|
||||
GPU_D12_RawCommandList *next;
|
||||
|
||||
u64 submit_fence_target;
|
||||
u64 commit_fence_target;
|
||||
|
||||
ID3D12CommandAllocator *ca;
|
||||
ID3D12GraphicsCommandList *cl;
|
||||
@ -179,10 +177,10 @@ Enum(GPU_D12_CmdKind)
|
||||
GPU_D12_CmdKind_None,
|
||||
|
||||
/* Access */
|
||||
GPU_D12_CmdKind_SetAccess,
|
||||
GPU_D12_CmdKind_Access,
|
||||
|
||||
/* Constant */
|
||||
GPU_D12_CmdKind_SetConstant,
|
||||
GPU_D12_CmdKind_Constant,
|
||||
|
||||
/* Copy */
|
||||
GPU_D12_CmdKind_Copy,
|
||||
@ -204,8 +202,8 @@ Struct(GPU_D12_Cmd)
|
||||
{
|
||||
struct
|
||||
{
|
||||
GPU_AccessKind kind;
|
||||
GPU_D12_Resource *resource;
|
||||
GPU_AccessKind access_kind;
|
||||
} access;
|
||||
|
||||
struct
|
||||
@ -253,6 +251,7 @@ Struct(GPU_D12_Cmd)
|
||||
struct
|
||||
{
|
||||
GPU_D12_Descriptor *rtv_descriptor;
|
||||
Vec4 color;
|
||||
} clear_rtv;
|
||||
};
|
||||
};
|
||||
@ -273,31 +272,25 @@ Struct(GPU_D12_CmdList)
|
||||
GPU_D12_CmdChunk *last_cmd_chunk;
|
||||
u64 chunks_count;
|
||||
u64 cmds_count;
|
||||
|
||||
GPU_QueueKind queue_kind;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Swapchain types
|
||||
|
||||
Struct(GPU_D12_SwapchainBuffer)
|
||||
{
|
||||
struct GPU_D12_Swapchain *swapchain;
|
||||
ID3D12Resource *d3d_resource;
|
||||
D3D12_RESOURCE_STATES state;
|
||||
};
|
||||
|
||||
Struct(GPU_D12_Swapchain)
|
||||
{
|
||||
GPU_D12_Swapchain *next;
|
||||
GPU_Format format;
|
||||
|
||||
IDXGISwapChain3 *swapchain;
|
||||
IDXGISwapChain3 *d3d_swapchain;
|
||||
HWND window_hwnd;
|
||||
HANDLE waitable;
|
||||
Vec2I32 resolution;
|
||||
|
||||
GPU_D12_SwapchainBuffer buffers[GPU_D12_SwapchainBufferCount];
|
||||
HANDLE present_event;
|
||||
ID3D12Fence *present_fence;
|
||||
u64 present_fence_target;
|
||||
|
||||
GPU_Format backbuffers_format;
|
||||
Vec2I32 backbuffers_resolution;
|
||||
GPU_D12_Resource backbuffers[GPU_D12_SwapchainBufferCount];
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -314,17 +307,15 @@ Struct(GPU_D12_SharedState)
|
||||
/* Queues */
|
||||
GPU_D12_Queue queues[GPU_NumQueues];
|
||||
|
||||
/* Descriptor heaps */
|
||||
GPU_D12_DescriptorHeap descriptor_heaps[GPU_D12_DescriptorHeapKind_Count];
|
||||
|
||||
/* Rootsig */
|
||||
ID3D12RootSignature *bindless_rootsig;
|
||||
|
||||
/* Pipelines */
|
||||
GPU_D12_PipelineBin pipeline_bins[1024];
|
||||
|
||||
/* Descriptor heaps */
|
||||
GPU_D12_DescriptorHeap cbv_srv_uav_heap;
|
||||
GPU_D12_DescriptorHeap sampler_heap;
|
||||
GPU_D12_DescriptorHeap rtv_heap;
|
||||
|
||||
/* Command lists */
|
||||
Mutex free_cmd_lists_mutex;
|
||||
GPU_D12_CmdList *first_free_cmd_list;
|
||||
@ -358,44 +349,35 @@ GPU_D12_Resource *GPU_D12_ResourceFromHandle(GPU_ResourceHandle handle);
|
||||
GPU_D12_Swapchain *GPU_D12_SwapchainFromHandle(GPU_SwapchainHandle handle);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Pipeline operations
|
||||
//~ Pipeline
|
||||
|
||||
JobDecl(GPU_D12_LoadPipeline, { GPU_D12_Pipeline *pipeline; });
|
||||
GPU_D12_Pipeline *GPU_D12_PipelineFromDesc(GPU_D12_PipelineDesc desc);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Queue operations
|
||||
//~ Queue
|
||||
|
||||
GPU_D12_Queue *GPU_D12_QueueFromKind(GPU_QueueKind kind);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Descriptor operations
|
||||
//~ Resource helpers
|
||||
|
||||
GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_DescriptorHeap *heap);
|
||||
void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor);
|
||||
|
||||
GPU_D12_Descriptor *GPU_D12_RtvDescriptorFromPtr(GpuRasterTargetPtr ptr);
|
||||
D3D12_INDEX_BUFFER_VIEW GPU_D12_IbvFromPtr(GpuIndexBufferPtr ptr);
|
||||
GPU_D12_Descriptor *GPU_D12_PushDescriptor(GPU_D12_Arena *gpu_arena, GPU_D12_Resource *resource, GPU_D12_DescriptorHeapKind heap_kind);
|
||||
GPU_D12_Descriptor *GPU_D12_DescriptorFromIndex(GPU_D12_DescriptorHeapKind heap_kind, u32 index);
|
||||
D3D12_INDEX_BUFFER_VIEW GPU_D12_IbvFromIbPtr(IndexBufferGpuPtr ptr);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Raw command list operations
|
||||
//~ Raw command list
|
||||
|
||||
GPU_D12_RawCommandList *GPU_D12_BeginRawCommandList(GPU_QueueKind queue_kind);
|
||||
u64 GPU_D12_EndRawCommandList(GPU_D12_RawCommandList *cl);
|
||||
GPU_D12_RawCommandList *GPU_D12_PrepareRawCommandList(GPU_QueueKind queue_kind);
|
||||
void GPU_D12_CommitRawCommandList(GPU_D12_RawCommandList *cl);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Command helpers
|
||||
|
||||
GPU_D12_Cmd *GPU_D12_PushCmd(GPU_D12_CmdList *cl);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Swapchain helpers
|
||||
|
||||
void GPU_D12_InitSwapchainResources(GPU_D12_Swapchain *swapchain);
|
||||
GPU_D12_SwapchainBuffer *GPU_D12_UpdateSwapchain(GPU_D12_Swapchain *swapchain, Vec2I32 resolution);
|
||||
void GPU_D12_BlitToSwapchain(GPU_D12_SwapchainBuffer *dst, GPU_D12_Resource *texture, Vec2I32 dst_p0, Vec2I32 dst_p1, Vec2I32 src_p0, Vec2I32 src_p1, Vec4 clear_color);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Sync job
|
||||
|
||||
JobDecl(GPU_D12_StartQueueSync, EmptySig);
|
||||
// JobDecl(GPU_D12_StartQueueSync, EmptySig);
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
@Layer gpu_dx12
|
||||
|
||||
//- Dependencies
|
||||
@Dep window_win32
|
||||
|
||||
//- Api
|
||||
@IncludeC gpu_dx12.h
|
||||
|
||||
|
||||
@ -1,3 +1,43 @@
|
||||
void PR_Startup(void)
|
||||
{
|
||||
GPU_ArenaHandle gpu_frame_arena = GPU_AcquireArena();
|
||||
|
||||
b32 swapchain_initialized = 0;
|
||||
GPU_SwapchainHandle swapchain = ZI;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
WND_Frame window_frame = WND_BeginFrame();
|
||||
{
|
||||
if (!swapchain_initialized)
|
||||
{
|
||||
swapchain_initialized = 1;
|
||||
swapchain = GPU_AcquireSwapchain(window_frame.window);
|
||||
}
|
||||
|
||||
GPU_ResourceHandle backbuffer = GPU_PrepareBackbuffer(swapchain, GPU_Format_R16G16B16A16_Float, window_frame.draw_size);
|
||||
{
|
||||
/* Draw to backbuffer */
|
||||
GPU_CommandListHandle cl = GPU_PrepareCommandList();
|
||||
{
|
||||
RasterTargetGpuPtr backbuffer_rt = GPU_PushRasterTargetPtr(gpu_frame_arena, backbuffer);
|
||||
|
||||
/* Clear backbuffer */
|
||||
{
|
||||
GPU_SyncAccess(cl, backbuffer, GPU_AccessKind_RasterTarget);
|
||||
GPU_ClearRasterTarget(cl, backbuffer_rt, VEC4(1, 0, 0, 1));
|
||||
}
|
||||
|
||||
/* Make backbuffer presentable */
|
||||
GPU_SyncAccess(cl, backbuffer, GPU_AccessKind_Present);
|
||||
|
||||
/* Reset */
|
||||
GPU_ResetArena(cl, gpu_frame_arena);
|
||||
}
|
||||
GPU_CommitCommandList(cl, GPU_QueueKind_Direct);
|
||||
}
|
||||
GPU_CommitBackbuffer(backbuffer, VSYNC);
|
||||
}
|
||||
WND_EndFrame(window_frame);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
//- Dependencies
|
||||
|
||||
@Dep gpu
|
||||
@Dep window
|
||||
|
||||
//- Impl
|
||||
|
||||
|
||||
@ -31,14 +31,13 @@ Struct(WND_Cmd)
|
||||
|
||||
Struct(WND_Frame)
|
||||
{
|
||||
WND_Handle window_handle;
|
||||
WND_Handle window;
|
||||
|
||||
/* User input since last update */
|
||||
ControllerEventsArray controller_events;
|
||||
|
||||
/* Window info */
|
||||
Vec2I32 draw_size;
|
||||
Vec2I32 monitor_size;
|
||||
|
||||
String restore;
|
||||
b32 minimized;
|
||||
b32 maximized;
|
||||
@ -53,7 +52,12 @@ Struct(WND_Frame)
|
||||
void WND_Startup(void);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Command operations
|
||||
//~ @hookdecl Helpers
|
||||
|
||||
u64 WND_OsHandleFromWindow(WND_Handle window);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Command
|
||||
|
||||
#define WND_PushCmd(frame, ...) WND_PushCmd_((frame), (WND_Cmd) { __VA_ARGS__ })
|
||||
void WND_PushCmd_(WND_Frame frame, WND_Cmd desc);
|
||||
|
||||
@ -108,7 +108,7 @@ JobImpl(WND_W32_ProcessMessagesForever, sig, id)
|
||||
WND_W32_Window *window = &g->window;
|
||||
window->w2u_events_arena = AcquireArena(Gibi(64));
|
||||
|
||||
//- Init hwnd
|
||||
//- Initialize hwnd
|
||||
HWND hwnd = 0;
|
||||
{
|
||||
/*
|
||||
@ -385,11 +385,20 @@ LRESULT CALLBACK WND_W32_WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM l
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookimpl Cmds
|
||||
//~ @hookimpl Helpers
|
||||
|
||||
u64 WND_OsHandleFromWindow(WND_Handle handle)
|
||||
{
|
||||
WND_W32_Window *window = WND_W32_WindowFromHandle(handle);
|
||||
return (u64)window->hwnd;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookimpl Command
|
||||
|
||||
void WND_PushCmd_(WND_Frame frame, WND_Cmd desc)
|
||||
{
|
||||
WND_W32_Window *window = WND_W32_WindowFromHandle(frame.window_handle);
|
||||
WND_W32_Window *window = WND_W32_WindowFromHandle(frame.window);
|
||||
WND_W32_CmdNode *n = PushStruct(window->frame_arena, WND_W32_CmdNode);
|
||||
n->cmd = desc;
|
||||
SllQueuePush(window->first_cmd, window->last_cmd, n);
|
||||
@ -413,7 +422,7 @@ WND_Frame WND_BeginFrame(void)
|
||||
_mm_pause();
|
||||
}
|
||||
HWND hwnd = window->hwnd;
|
||||
result.window_handle.v = (u64)window;
|
||||
result.window.v = (u64)window;
|
||||
|
||||
/* Reset per-frame data */
|
||||
if (!window->frame_arena)
|
||||
@ -515,7 +524,7 @@ void WND_EndFrame(WND_Frame frame)
|
||||
{
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
WND_W32_SharedState *g = &WND_W32_shared_state;
|
||||
WND_W32_Window *window = WND_W32_WindowFromHandle(frame.window_handle);
|
||||
WND_W32_Window *window = WND_W32_WindowFromHandle(frame.window);
|
||||
HWND hwnd = window->hwnd;
|
||||
|
||||
/* Process cmds */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user