working shader dispatch

This commit is contained in:
jacob 2025-09-19 20:57:59 -05:00
parent 6251feb451
commit 27c2e34e24
5 changed files with 103 additions and 84 deletions

View File

@ -196,6 +196,7 @@ Struct(GPU_ResourceDesc)
{ {
GPU_ResourceKind kind; GPU_ResourceKind kind;
GPU_ResourceFlag flags; GPU_ResourceFlag flags;
Vec4 clear_color;
union union
{ {
struct struct
@ -315,7 +316,7 @@ void GPU_FlushWritable(GPU_CommandList *cl, GPU_Resource *resource); /*
//////////////////////////////// ////////////////////////////////
//~ @hookdecl Dispatch operations //~ @hookdecl Dispatch operations
void GPU_Clear(GPU_CommandList *cl, GPU_Resource *resource, Vec4 clear_value); void GPU_ClearRenderable(GPU_CommandList *cl, GPU_Resource *resource);
#define GPU_Rasterize(cl, sig_ptr, vs, ps, rts_count, viewport, scissor, instances_count, index_buffer, mode) \ #define GPU_Rasterize(cl, sig_ptr, vs, ps, rts_count, viewport, scissor, instances_count, index_buffer, mode) \
GPU_Rasterize_((cl), sizeof(*(sig_ptr)), (sig_ptr), (vs), (ps), (rts_count), (viewport), (scissor), (instances_count), (index_buffer), (mode)) GPU_Rasterize_((cl), sizeof(*(sig_ptr)), (sig_ptr), (vs), (ps), (rts_count), (viewport), (scissor), (instances_count), (index_buffer), (mode))

View File

@ -70,15 +70,18 @@ void GPU_D12_Startup(void)
} }
/* Init descriptor heaps */ /* Init descriptor heaps */
g->cbv_srv_uav_heap = GPU_D12_InitCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, g->cbv_srv_uav_heap = GPU_D12_InitDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
GPU_D12_MaxCbvSrvUavDescriptors, GPU_D12_MaxCbvSrvUavDescriptors,
ID3D12Device_GetDescriptorHandleIncrementSize(g->device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV)); ID3D12Device_GetDescriptorHandleIncrementSize(g->device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
g->sampler_heap = GPU_D12_InitCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, g->sampler_heap = GPU_D12_InitDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER,
D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE,
GPU_D12_MaxSamplerDescriptors, GPU_D12_MaxSamplerDescriptors,
ID3D12Device_GetDescriptorHandleIncrementSize(g->device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER)); ID3D12Device_GetDescriptorHandleIncrementSize(g->device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER));
g->rtv_heap = GPU_D12_InitCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV, g->rtv_heap = GPU_D12_InitDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
D3D12_DESCRIPTOR_HEAP_FLAG_NONE,
GPU_D12_MaxRtvDescriptors, GPU_D12_MaxRtvDescriptors,
ID3D12Device_GetDescriptorHandleIncrementSize(g->device, D3D12_DESCRIPTOR_HEAP_TYPE_RTV)); ID3D12Device_GetDescriptorHandleIncrementSize(g->device, D3D12_DESCRIPTOR_HEAP_TYPE_RTV));
@ -265,11 +268,11 @@ JobDef(GPU_D12_InitQueue, sig, id)
//- Heap initialization //- Heap initialization
GPU_D12_CpuDescriptorHeap *GPU_D12_InitCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, u32 max_descs, u32 desc_size) GPU_D12_DescriptorHeap *GPU_D12_InitDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flags, u32 max_descs, u32 desc_size)
{ {
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
Arena *arena = AcquireArena(Gibi(64)); Arena *arena = AcquireArena(Gibi(64));
GPU_D12_CpuDescriptorHeap *heap = PushStruct(arena, GPU_D12_CpuDescriptorHeap); GPU_D12_DescriptorHeap *heap = PushStruct(arena, GPU_D12_DescriptorHeap);
heap->arena = arena; heap->arena = arena;
heap->type = type; heap->type = type;
@ -278,6 +281,7 @@ GPU_D12_CpuDescriptorHeap *GPU_D12_InitCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_T
D3D12_DESCRIPTOR_HEAP_DESC d3d_desc = ZI; D3D12_DESCRIPTOR_HEAP_DESC d3d_desc = ZI;
d3d_desc.Type = type; d3d_desc.Type = type;
d3d_desc.Flags = flags;
d3d_desc.NumDescriptors = max_descs; d3d_desc.NumDescriptors = max_descs;
HRESULT hr = ID3D12Device_CreateDescriptorHeap(g->device, &d3d_desc, &IID_ID3D12DescriptorHeap, (void **)&heap->d3d_heap); HRESULT hr = ID3D12Device_CreateDescriptorHeap(g->device, &d3d_desc, &IID_ID3D12DescriptorHeap, (void **)&heap->d3d_heap);
if (FAILED(hr)) if (FAILED(hr))
@ -515,9 +519,9 @@ GPU_D12_Queue *GPU_D12_QueueFromKind(GPU_QueueKind kind)
//////////////////////////////// ////////////////////////////////
//~ Descriptor operations //~ Descriptor operations
GPU_D12_CpuDescriptor *GPU_D12_AcquireCpuDescriptor(GPU_D12_CpuDescriptorHeap *heap) GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_DescriptorHeap *heap)
{ {
GPU_D12_CpuDescriptor *d = 0; GPU_D12_Descriptor *d = 0;
u32 index = 0; u32 index = 0;
D3D12_CPU_DESCRIPTOR_HANDLE handle = ZI; D3D12_CPU_DESCRIPTOR_HANDLE handle = ZI;
{ {
@ -535,7 +539,7 @@ GPU_D12_CpuDescriptor *GPU_D12_AcquireCpuDescriptor(GPU_D12_CpuDescriptorHeap *h
{ {
Panic(Lit("Max descriptors reached in heap")); Panic(Lit("Max descriptors reached in heap"));
} }
d = PushStructNoZero(heap->arena, GPU_D12_CpuDescriptor); d = PushStructNoZero(heap->arena, GPU_D12_Descriptor);
index = heap->allocated_count++; index = heap->allocated_count++;
handle.ptr = heap->start_handle.ptr + (index * heap->descriptor_size); handle.ptr = heap->start_handle.ptr + (index * heap->descriptor_size);
} }
@ -548,13 +552,13 @@ GPU_D12_CpuDescriptor *GPU_D12_AcquireCpuDescriptor(GPU_D12_CpuDescriptorHeap *h
return d; return d;
} }
void GPU_D12_ReleaseCpuDescriptor(GPU_D12_CpuDescriptor *descriptor) void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor)
{ {
GPU_D12_CpuDescriptorHeap *dh = descriptor->heap; GPU_D12_DescriptorHeap *heap = descriptor->heap;
Lock lock = LockE(&dh->mutex); Lock lock = LockE(&heap->mutex);
{ {
descriptor->next_free = dh->first_free; descriptor->next_free = heap->first_free;
dh->first_free = descriptor; heap->first_free = descriptor;
} }
Unlock(&lock); Unlock(&lock);
} }
@ -688,7 +692,7 @@ void GPU_D12_InitSwapchainResources(GPU_D12_Swapchain *swapchain)
ZeroStruct(sb); ZeroStruct(sb);
sb->swapchain = swapchain; sb->swapchain = swapchain;
sb->d3d_resource = resource; sb->d3d_resource = resource;
sb->rtv_descriptor = GPU_D12_AcquireCpuDescriptor(g->rtv_heap); sb->rtv_descriptor = GPU_D12_AcquireDescriptor(g->rtv_heap);
sb->state = D3D12_RESOURCE_STATE_COMMON; sb->state = D3D12_RESOURCE_STATE_COMMON;
ID3D12Device_CreateRenderTargetView(g->device, sb->d3d_resource, 0, sb->rtv_descriptor->handle); ID3D12Device_CreateRenderTargetView(g->device, sb->d3d_resource, 0, sb->rtv_descriptor->handle);
} }
@ -724,7 +728,7 @@ GPU_D12_SwapchainBuffer *GPU_D12_UpdateSwapchain(GPU_D12_Swapchain *swapchain, V
for (u32 i = 0; i < countof(swapchain->buffers); ++i) for (u32 i = 0; i < countof(swapchain->buffers); ++i)
{ {
GPU_D12_SwapchainBuffer *sb = &swapchain->buffers[i]; GPU_D12_SwapchainBuffer *sb = &swapchain->buffers[i];
GPU_D12_ReleaseCpuDescriptor(sb->rtv_descriptor); GPU_D12_ReleaseDescriptor(sb->rtv_descriptor);
ID3D12Resource_Release(sb->d3d_resource); ID3D12Resource_Release(sb->d3d_resource);
} }
@ -875,14 +879,24 @@ void GPU_QueueWait(GPU_QueueKind a, GPU_QueueKind b, i64 b_target_fence_value)
GPU_Viewport GPU_ViewportFromRect(Rect rect) GPU_Viewport GPU_ViewportFromRect(Rect rect)
{ {
/* TODO */ GPU_Viewport viewport = ZI;
return (GPU_Viewport) ZI; viewport.top_left_x = rect.x;
viewport.top_left_y = rect.y;
viewport.width = rect.width;
viewport.height = rect.height;
viewport.min_depth = 0.0f;
viewport.max_depth = 1.0f;
return viewport;
} }
GPU_Scissor GPU_ScissorFromRect(Rect rect) GPU_Scissor GPU_ScissorFromRect(Rect rect)
{ {
/* TODO */ GPU_Scissor scissor = ZI;
return (GPU_Scissor) ZI; scissor.left = rect.x;
scissor.top = rect.y;
scissor.right = rect.x + rect.width;
scissor.bottom = rect.y + rect.height;
return scissor;
} }
//////////////////////////////// ////////////////////////////////
@ -1013,6 +1027,10 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET * !!(desc.flags & GPU_ResourceFlag_Renderable); d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET * !!(desc.flags & GPU_ResourceFlag_Renderable);
r->state = D3D12_RESOURCE_STATE_COPY_DEST; r->state = D3D12_RESOURCE_STATE_COPY_DEST;
D3D12_CLEAR_VALUE clear_value = { .Format = d3d_desc.Format, .Color = { 0 } }; D3D12_CLEAR_VALUE clear_value = { .Format = d3d_desc.Format, .Color = { 0 } };
clear_value.Color[0] = desc.clear_color.x;
clear_value.Color[1] = desc.clear_color.y;
clear_value.Color[2] = desc.clear_color.z;
clear_value.Color[3] = desc.clear_color.w;
D3D12_CLEAR_VALUE *clear_value_ptr = d3d_desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET ? &clear_value : 0; D3D12_CLEAR_VALUE *clear_value_ptr = d3d_desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET ? &clear_value : 0;
HRESULT hr = ID3D12Device_CreateCommittedResource(g->device, &heap_props, heap_flags, &d3d_desc, r->state, clear_value_ptr, &IID_ID3D12Resource, (void **)&r->d3d_resource); HRESULT hr = ID3D12Device_CreateCommittedResource(g->device, &heap_props, heap_flags, &d3d_desc, r->state, clear_value_ptr, &IID_ID3D12Resource, (void **)&r->d3d_resource);
if (FAILED(hr)) if (FAILED(hr))
@ -1030,7 +1048,7 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
|| desc.kind == GPU_ResourceKind_Texture2D || desc.kind == GPU_ResourceKind_Texture2D
|| desc.kind == GPU_ResourceKind_Texture3D) || desc.kind == GPU_ResourceKind_Texture3D)
{ {
r->srv_descriptor = GPU_D12_AcquireCpuDescriptor(g->cbv_srv_uav_heap); r->srv_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
ID3D12Device_CreateShaderResourceView(g->device, r->d3d_resource, 0, r->srv_descriptor->handle); ID3D12Device_CreateShaderResourceView(g->device, r->d3d_resource, 0, r->srv_descriptor->handle);
} }
@ -1047,21 +1065,21 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
srv_desc.Buffer.NumElements = MaxU32(desc.buffer.element_count, 1); srv_desc.Buffer.NumElements = MaxU32(desc.buffer.element_count, 1);
srv_desc.Buffer.StructureByteStride = desc.buffer.element_size; srv_desc.Buffer.StructureByteStride = desc.buffer.element_size;
srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE; srv_desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
r->srv_descriptor = GPU_D12_AcquireCpuDescriptor(g->cbv_srv_uav_heap); r->srv_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
ID3D12Device_CreateShaderResourceView(g->device, r->d3d_resource, &srv_desc, r->srv_descriptor->handle); ID3D12Device_CreateShaderResourceView(g->device, r->d3d_resource, &srv_desc, r->srv_descriptor->handle);
} }
/* Create uav descriptor */ /* Create uav descriptor */
if (desc.flags & GPU_ResourceFlag_Writable) if (desc.flags & GPU_ResourceFlag_Writable)
{ {
r->uav_descriptor = GPU_D12_AcquireCpuDescriptor(g->cbv_srv_uav_heap); r->uav_descriptor = GPU_D12_AcquireDescriptor(g->cbv_srv_uav_heap);
ID3D12Device_CreateUnorderedAccessView(g->device, r->d3d_resource, 0, 0, r->uav_descriptor->handle); ID3D12Device_CreateUnorderedAccessView(g->device, r->d3d_resource, 0, 0, r->uav_descriptor->handle);
} }
/* Create rtv descriptor */ /* Create rtv descriptor */
if (desc.flags & GPU_ResourceFlag_Renderable) if (desc.flags & GPU_ResourceFlag_Renderable)
{ {
r->rtv_descriptor = GPU_D12_AcquireCpuDescriptor(g->rtv_heap); r->rtv_descriptor = GPU_D12_AcquireDescriptor(g->rtv_heap);
ID3D12Device_CreateRenderTargetView(g->device, r->d3d_resource, 0, r->rtv_descriptor->handle); ID3D12Device_CreateRenderTargetView(g->device, r->d3d_resource, 0, r->rtv_descriptor->handle);
} }
@ -1098,19 +1116,19 @@ void GPU_ReleaseResource(GPU_Resource *gpu_resource, GPU_ReleaseFlag flags)
if (r->srv_descriptor) if (r->srv_descriptor)
{ {
GPU_D12_ReleaseCpuDescriptor(r->srv_descriptor); GPU_D12_ReleaseDescriptor(r->srv_descriptor);
} }
if (r->uav_descriptor) if (r->uav_descriptor)
{ {
GPU_D12_ReleaseCpuDescriptor(r->uav_descriptor); GPU_D12_ReleaseDescriptor(r->uav_descriptor);
} }
if (r->rtv_descriptor) if (r->rtv_descriptor)
{ {
GPU_D12_ReleaseCpuDescriptor(r->uav_descriptor); GPU_D12_ReleaseDescriptor(r->rtv_descriptor);
} }
if (r->sampler_descriptor) if (r->sampler_descriptor)
{ {
GPU_D12_ReleaseCpuDescriptor(r->sampler_descriptor); GPU_D12_ReleaseDescriptor(r->sampler_descriptor);
} }
Lock lock = LockE(&g->free_resources_mutex); Lock lock = LockE(&g->free_resources_mutex);
@ -1320,11 +1338,17 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
} }
} break; } break;
//- Clear resource //- Clear rtv
case GPU_D12_CommandKind_Clear: case GPU_D12_CommandKind_ClearRtv:
{ {
/* TODO */ GPU_D12_Resource *resource = cmd->clear.resource;
/* TODO: Set descriptor heaps if UAV copy */ Assert(resource->state == D3D12_RESOURCE_STATE_RENDER_TARGET);
f32 clear_color[4] = ZI;
clear_color[0] = resource->desc.clear_color.x;
clear_color[1] = resource->desc.clear_color.y;
clear_color[2] = resource->desc.clear_color.z;
clear_color[3] = resource->desc.clear_color.w;
ID3D12GraphicsCommandList_ClearRenderTargetView(rcl, resource->rtv_descriptor->handle, clear_color, 0, 0);
cmd = cmd->next; cmd = cmd->next;
} break; } break;
@ -1395,20 +1419,12 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
&& cmd->rasterize.index_buffer->desc.buffer.element_count > 0) && cmd->rasterize.index_buffer->desc.buffer.element_count > 0)
{ {
/* Set descriptor heaps */ /* Set descriptor heaps */
#if 0
if (!descriptor_heaps_set) if (!descriptor_heaps_set)
{ {
{ ID3D12DescriptorHeap *heaps[] = { g->cbv_srv_uav_heap->d3d_heap, g->sampler_heap->d3d_heap };
ID3D12DescriptorHeap *heap = g->cbv_srv_uav_heap; ID3D12GraphicsCommandList_SetDescriptorHeaps(rcl, countof(heaps), heaps);
Lock lock = LockS(&heap->mutex);
ID3D12Device_CopyDescriptorsSimple(g->device, heap->allocated_count, cdh->start_cpu_handle, dh_cpu->handle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
Unlock(&lock);
}
ID3D12DescriptorHeap *heaps[] = { cl->gpu_cbv_srv_uav_heap, cl->gpu_sampler_heap };
ID3D12GraphicsCommandList_SetDescriptorHeaps(cl->cl, countof(heaps), heaps);
descriptor_heaps_set = 1; descriptor_heaps_set = 1;
} }
#endif
/* Bind rootsig */ /* Bind rootsig */
if (!graphics_rootsig_set) if (!graphics_rootsig_set)
@ -1510,7 +1526,7 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
} }
/* Dispatch */ /* Dispatch */
ID3D12GraphicsCommandList_DrawIndexedInstanced(rcl, cmd->rasterize.instances_count, indices_count, 0, 0, 0); ID3D12GraphicsCommandList_DrawIndexedInstanced(rcl, indices_count, cmd->rasterize.instances_count, 0, 0, 0);
} }
cmd = cmd->next; cmd = cmd->next;
@ -1528,6 +1544,14 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
if (pipeline) if (pipeline)
{ {
/* Set descriptor heaps */
if (!descriptor_heaps_set)
{
ID3D12DescriptorHeap *heaps[] = { g->cbv_srv_uav_heap->d3d_heap, g->sampler_heap->d3d_heap };
ID3D12GraphicsCommandList_SetDescriptorHeaps(rcl, countof(heaps), heaps);
descriptor_heaps_set = 1;
}
/* Bind rootsig */ /* Bind rootsig */
if (!compute_rootsig_set) if (!compute_rootsig_set)
{ {
@ -1635,13 +1659,12 @@ void GPU_FlushWritable(GPU_CommandList *cl, GPU_Resource *resource)
//////////////////////////////// ////////////////////////////////
//~ @hookdef Dispatch hooks //~ @hookdef Dispatch hooks
void GPU_Clear(GPU_CommandList *gpu_cl, GPU_Resource *resource, Vec4 clear_value) void GPU_ClearRenderable(GPU_CommandList *gpu_cl, GPU_Resource *resource)
{ {
GPU_D12_CommandList *cl = (GPU_D12_CommandList *)gpu_cl; GPU_D12_CommandList *cl = (GPU_D12_CommandList *)gpu_cl;
GPU_D12_Command *cmd = GPU_D12_PushCmd(cl); GPU_D12_Command *cmd = GPU_D12_PushCmd(cl);
cmd->kind = GPU_D12_CommandKind_Clear; cmd->kind = GPU_D12_CommandKind_ClearRtv;
cmd->clear.resource = (GPU_D12_Resource *)resource; cmd->clear.resource = (GPU_D12_Resource *)resource;
cmd->clear.value = clear_value;
} }
void GPU_Rasterize_(GPU_CommandList *gpu_cl, void GPU_Rasterize_(GPU_CommandList *gpu_cl,
@ -1875,7 +1898,6 @@ i64 GPU_PresentSwapchain(GPU_Swapchain *gpu_swapchain, GPU_Resource *gpu_texture
ID3D12Resource_GetDesc(swapchain_buffer->d3d_resource, &dst_desc); ID3D12Resource_GetDesc(swapchain_buffer->d3d_resource, &dst_desc);
b32 is_blitable = src_desc.Dimension == dst_desc.Dimension b32 is_blitable = src_desc.Dimension == dst_desc.Dimension
&& src_desc.Format == dst_desc.Format
&& src_desc.SampleDesc.Count == dst_desc.SampleDesc.Count && src_desc.SampleDesc.Count == dst_desc.SampleDesc.Count
&& src_desc.SampleDesc.Quality == dst_desc.SampleDesc.Quality && src_desc.SampleDesc.Quality == dst_desc.SampleDesc.Quality
&& src_desc.Width == dst_desc.Width && src_desc.Width == dst_desc.Width

View File

@ -56,16 +56,16 @@ Struct(GPU_D12_PipelineBin)
//////////////////////////////// ////////////////////////////////
//~ Descriptor types //~ Descriptor types
Struct(GPU_D12_CpuDescriptor) Struct(GPU_D12_Descriptor)
{ {
GPU_D12_CpuDescriptor *next_free; GPU_D12_Descriptor *next_free;
struct GPU_D12_CpuDescriptorHeap *heap; struct GPU_D12_DescriptorHeap *heap;
u32 index; u32 index;
D3D12_CPU_DESCRIPTOR_HANDLE handle; D3D12_CPU_DESCRIPTOR_HANDLE handle;
}; };
Struct(GPU_D12_CpuDescriptorHeap) Struct(GPU_D12_DescriptorHeap)
{ {
Arena *arena; Arena *arena;
@ -75,7 +75,7 @@ Struct(GPU_D12_CpuDescriptorHeap)
D3D12_CPU_DESCRIPTOR_HANDLE start_handle; D3D12_CPU_DESCRIPTOR_HANDLE start_handle;
Mutex mutex; Mutex mutex;
GPU_D12_CpuDescriptor *first_free; GPU_D12_Descriptor *first_free;
u32 allocated_count; u32 allocated_count;
u32 max_count; u32 max_count;
}; };
@ -92,10 +92,10 @@ Struct(GPU_D12_Resource)
D3D12_RESOURCE_STATES state; D3D12_RESOURCE_STATES state;
u64 reuse_hash; u64 reuse_hash;
GPU_D12_CpuDescriptor *srv_descriptor; GPU_D12_Descriptor *srv_descriptor;
GPU_D12_CpuDescriptor *uav_descriptor; GPU_D12_Descriptor *uav_descriptor;
GPU_D12_CpuDescriptor *rtv_descriptor; GPU_D12_Descriptor *rtv_descriptor;
GPU_D12_CpuDescriptor *sampler_descriptor; GPU_D12_Descriptor *sampler_descriptor;
D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address; D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address;
}; };
@ -137,9 +137,6 @@ Struct(GPU_D12_RawCommandList)
ID3D12CommandAllocator *ca; ID3D12CommandAllocator *ca;
ID3D12GraphicsCommandList *cl; ID3D12GraphicsCommandList *cl;
ID3D12DescriptorHeap *gpu_cbv_srv_uav_heap;
ID3D12DescriptorHeap *gpu_sampler_heap;
}; };
//////////////////////////////// ////////////////////////////////
@ -161,7 +158,7 @@ Enum(GPU_D12_CommandKind)
GPU_D12_CommandKind_Copy, GPU_D12_CommandKind_Copy,
/* Clear */ /* Clear */
GPU_D12_CommandKind_Clear, GPU_D12_CommandKind_ClearRtv,
/* Rasterize */ /* Rasterize */
GPU_D12_CommandKind_Rasterize, GPU_D12_CommandKind_Rasterize,
@ -190,7 +187,6 @@ Struct(GPU_D12_Command)
struct struct
{ {
GPU_D12_Resource *resource; GPU_D12_Resource *resource;
Vec4 value;
} clear; } clear;
struct struct
{ {
@ -234,7 +230,7 @@ Struct(GPU_D12_SwapchainBuffer)
{ {
struct GPU_D12_Swapchain *swapchain; struct GPU_D12_Swapchain *swapchain;
ID3D12Resource *d3d_resource; ID3D12Resource *d3d_resource;
GPU_D12_CpuDescriptor *rtv_descriptor; GPU_D12_Descriptor *rtv_descriptor;
D3D12_RESOURCE_STATES state; D3D12_RESOURCE_STATES state;
}; };
@ -273,9 +269,9 @@ Struct(GPU_D12_SharedState)
GPU_D12_PipelineBin pipeline_bins[1024]; GPU_D12_PipelineBin pipeline_bins[1024];
/* Descriptor heaps */ /* Descriptor heaps */
GPU_D12_CpuDescriptorHeap *cbv_srv_uav_heap; GPU_D12_DescriptorHeap *cbv_srv_uav_heap;
GPU_D12_CpuDescriptorHeap *sampler_heap; GPU_D12_DescriptorHeap *sampler_heap;
GPU_D12_CpuDescriptorHeap *rtv_heap; GPU_D12_DescriptorHeap *rtv_heap;
/* Resources */ /* Resources */
Mutex free_resources_mutex; Mutex free_resources_mutex;
@ -314,7 +310,7 @@ void GPU_D12_InitDevice(void);
JobDecl(GPU_D12_InitQueue, { GPU_D12_QueueDesc *descs; }); JobDecl(GPU_D12_InitQueue, { GPU_D12_QueueDesc *descs; });
//- Heap initialization //- Heap initialization
GPU_D12_CpuDescriptorHeap *GPU_D12_InitCpuDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, u32 max_descs, u32 desc_size); GPU_D12_DescriptorHeap *GPU_D12_InitDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flags, u32 max_descs, u32 desc_size);
//- Rootsig initialization //- Rootsig initialization
void GPU_D12_InitRootsig(void); void GPU_D12_InitRootsig(void);
@ -333,8 +329,8 @@ GPU_D12_Queue *GPU_D12_QueueFromKind(GPU_QueueKind kind);
//////////////////////////////// ////////////////////////////////
//~ Descriptor operations //~ Descriptor operations
GPU_D12_CpuDescriptor *GPU_D12_AcquireCpuDescriptor(GPU_D12_CpuDescriptorHeap *heap); GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_DescriptorHeap *heap);
void GPU_D12_ReleaseCpuDescriptor(GPU_D12_CpuDescriptor *descriptor); void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor);
//////////////////////////////// ////////////////////////////////
//~ Raw command list operations //~ Raw command list operations

View File

@ -2222,8 +2222,8 @@ void UpdateUser(P_Window *window)
GPU_ProfN(cl, Lit("Clear gbuffers")); GPU_ProfN(cl, Lit("Clear gbuffers"));
GPU_TransitionToRenderable(cl, g->albedo, 0); GPU_TransitionToRenderable(cl, g->albedo, 0);
GPU_TransitionToRenderable(cl, g->emittance, 1); GPU_TransitionToRenderable(cl, g->emittance, 1);
GPU_Clear(cl, g->albedo, VEC4(0, 0, 0, 0)); GPU_ClearRenderable(cl, g->albedo);
GPU_Clear(cl, g->emittance, VEC4(0, 0, 0, 0)); GPU_ClearRenderable(cl, g->emittance);
} }
//- Material pass //- Material pass
@ -2311,7 +2311,6 @@ void UpdateUser(P_Window *window)
GPU_TransitionToWritable(cl, g->shade_target); GPU_TransitionToWritable(cl, g->shade_target);
GPU_FlushWritable(cl, g->emittance_flood_read); GPU_FlushWritable(cl, g->emittance_flood_read);
GPU_FlushWritable(cl, g->shade_read); GPU_FlushWritable(cl, g->shade_read);
GPU_Clear(cl, g->shade_target, VEC4(0, 0, 0, 0));
} }
//- Shade pass //- Shade pass
@ -2351,9 +2350,9 @@ void UpdateUser(P_Window *window)
{ {
__profn("Clear ui target"); __profn("Clear ui target");
GPU_ProfN(cl, Lit("Clear ui target")); GPU_ProfN(cl, Lit("Clear ui target"));
GPU_TransitionToRenderable(cl, g->ui_target, 0);
GPU_FlushWritable(cl, g->shade_read); GPU_FlushWritable(cl, g->shade_read);
GPU_Clear(cl, g->ui_target, VEC4(0, 0, 0, 0)); GPU_TransitionToRenderable(cl, g->ui_target, 0);
GPU_ClearRenderable(cl, g->ui_target);
} }
//- Ui blit pass //- Ui blit pass

View File

@ -361,7 +361,13 @@ UiBlitPS_Output PSDef(UiBlitPS, UiBlitPS_Input input)
color = pow(abs(color), 1/sig.gamma); color = pow(abs(color), 1/sig.gamma);
} }
/* FIXME: Enable this */
#if 0
output.SV_Target = color; output.SV_Target = color;
#else
output.SV_Target = Vec4(1, 0, 0, 1);
#endif
return output; return output;
} }
@ -458,11 +464,6 @@ UiShapePS_Input VSDef(UiShapeVS, Semantic(u32, SV_VertexID))
UiShapePS_Output PSDef(UiShapePS, UiShapePS_Input input) UiShapePS_Output PSDef(UiShapePS, UiShapePS_Input input)
{ {
UiShapePS_Output output; UiShapePS_Output output;
/* FIXME: Enable this */
#if 0
output.SV_Target = input.color_srgb; output.SV_Target = input.color_srgb;
#else
output.SV_Target = Vec4(1, 0, 0, 1);
#endif
return output; return output;
} }