working host-memory gpu resources
This commit is contained in:
parent
c7e560f98c
commit
93e9c4b78a
@ -70,7 +70,7 @@
|
||||
#define FLOOD_DEBUG 0
|
||||
|
||||
#define GPU_DEBUG 1
|
||||
#define GPU_DEBUG_VALIDATION 0
|
||||
#define GPU_DEBUG_VALIDATION 1
|
||||
|
||||
/* If enabled, bitbuffs will insert/verify magic numbers & length for each read & write */
|
||||
#define BITBUFF_DEBUG 0
|
||||
|
||||
@ -298,6 +298,8 @@ Enum(G_ResourceFlag)
|
||||
G_ResourceFlag_AllowShaderReadWrite = (1 << 0),
|
||||
G_ResourceFlag_AllowRenderTarget = (1 << 1),
|
||||
G_ResourceFlag_AllowDepthStencil = (1 << 2),
|
||||
G_ResourceFlag_HostMemory = (1 << 3),
|
||||
G_ResourceFlag_WriteCombineHostMemory = (1 << 4),
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -568,6 +570,11 @@ i32 G_CountDepth(G_ResourceHandle texture);
|
||||
|
||||
#define G_CountBuffer(buffer, type) G_CountBufferBytes(buffer) / sizeof(type)
|
||||
|
||||
//- Map
|
||||
|
||||
void *G_HostPointerFromResource(G_ResourceHandle resource);
|
||||
#define G_StructFromResource(resource, type) (type *)G_HostPointerFromResource(resource)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookdecl Shader resource reference
|
||||
|
||||
|
||||
@ -300,7 +300,12 @@ void G_Bootstrap(void)
|
||||
if (kind != G_QueueKind_AsyncCopy)
|
||||
{
|
||||
G_ArenaHandle gpu_perm = G_PermArena();
|
||||
queue->debug_print_buffer = G_PushBuffer(gpu_perm, u8, print_buffer_size, .flags = G_ResourceFlag_AllowShaderReadWrite);
|
||||
queue->debug_print_buffer = G_PushBuffer(
|
||||
gpu_perm,
|
||||
u8,
|
||||
print_buffer_size,
|
||||
.flags = G_ResourceFlag_AllowShaderReadWrite | G_ResourceFlag_HostMemory
|
||||
);
|
||||
queue->debug_print_buffer_ref = G_PushRWByteAddressBufferRef(gpu_perm, queue->debug_print_buffer);
|
||||
}
|
||||
}
|
||||
@ -718,6 +723,111 @@ void G_D12_CommitRawCommandList(G_D12_RawCommandList *cl)
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Arena
|
||||
|
||||
G_D12_ResourceHeap *G_D12_ResourceHeapFromArena(G_D12_Arena *gpu_arena, G_D12_ResourceHeapKind kind)
|
||||
{
|
||||
G_D12_SharedState *g = &G_D12_shared_state;
|
||||
G_D12_ResourceHeap *heap = &gpu_arena->resource_heaps[kind];
|
||||
|
||||
b32 is_mappable = 0;
|
||||
|
||||
/* Initialize heap */
|
||||
/* FIXME: Dynamic size */
|
||||
if (heap->d3d_heap == 0)
|
||||
{
|
||||
HRESULT hr = 0;
|
||||
|
||||
/* Create d3d heap */
|
||||
{
|
||||
D3D12_HEAP_DESC d3d_desc = ZI;
|
||||
d3d_desc.SizeInBytes = Mebi(512);
|
||||
if (kind == G_D12_ResourceHeapKind_CpuWriteBack)
|
||||
{
|
||||
d3d_desc.Properties.Type = D3D12_HEAP_TYPE_CUSTOM;
|
||||
d3d_desc.Properties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_WRITE_BACK;
|
||||
d3d_desc.Properties.MemoryPoolPreference = D3D12_MEMORY_POOL_L0;
|
||||
is_mappable = 1;
|
||||
}
|
||||
else if (kind == G_D12_ResourceHeapKind_CpuWriteCombine)
|
||||
{
|
||||
d3d_desc.Properties.Type = D3D12_HEAP_TYPE_CUSTOM;
|
||||
d3d_desc.Properties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE;
|
||||
d3d_desc.Properties.MemoryPoolPreference = D3D12_MEMORY_POOL_L0;
|
||||
is_mappable = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3d_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
}
|
||||
d3d_desc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
|
||||
d3d_desc.Flags |= D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; /* TODO: Remove this and support tier 1 resource heaps */
|
||||
hr = ID3D12Device_CreateHeap(g->device, &d3d_desc, &IID_ID3D12Heap, (void **)&heap->d3d_heap);
|
||||
heap->size = d3d_desc.SizeInBytes;
|
||||
}
|
||||
|
||||
/* Map resource */
|
||||
if (is_mappable)
|
||||
{
|
||||
/* Create heap-sized resource for mapping */
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
D3D12_RESOURCE_DESC1 d3d_desc = ZI;
|
||||
d3d_desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
d3d_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
||||
d3d_desc.Format = DXGI_FORMAT_UNKNOWN;
|
||||
d3d_desc.Width = heap->size;
|
||||
d3d_desc.Height = 1;
|
||||
d3d_desc.DepthOrArraySize = 1;
|
||||
d3d_desc.MipLevels = 1;
|
||||
d3d_desc.SampleDesc.Count = 1;
|
||||
d3d_desc.SampleDesc.Quality = 0;
|
||||
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE;
|
||||
|
||||
u64 alloc_size = 0;
|
||||
u64 alloc_align = 0;
|
||||
{
|
||||
D3D12_RESOURCE_ALLOCATION_INFO alloc_info = ZI;
|
||||
ID3D12Device_GetResourceAllocationInfo(g->device, &alloc_info, 0, 1, (D3D12_RESOURCE_DESC *)&d3d_desc);
|
||||
alloc_size = alloc_info.SizeInBytes;
|
||||
alloc_align = alloc_info.Alignment;
|
||||
}
|
||||
|
||||
if (alloc_size > heap->size)
|
||||
{
|
||||
Panic(Lit("Gpu heap overflow"));
|
||||
}
|
||||
|
||||
hr = ID3D12Device10_CreatePlacedResource2(g->device,
|
||||
heap->d3d_heap,
|
||||
0,
|
||||
&d3d_desc,
|
||||
D3D12_BARRIER_LAYOUT_UNDEFINED,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&IID_ID3D12Resource,
|
||||
(void **)&heap->d3d_mapped_resource);
|
||||
}
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
D3D12_RANGE read_range = ZI;
|
||||
hr = ID3D12Resource_Map(heap->d3d_mapped_resource, 0, &read_range, &heap->mapped);
|
||||
}
|
||||
}
|
||||
|
||||
if (!SUCCEEDED(hr))
|
||||
{
|
||||
/* TODO: Don't panic */
|
||||
Panic(Lit("Failed to create D3D12 resource heap"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return heap;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookimpl Arena
|
||||
|
||||
@ -732,6 +842,11 @@ G_ArenaHandle G_AcquireArena(void)
|
||||
}
|
||||
gpu_arena->arena = AcquireArena(Gibi(1));
|
||||
|
||||
for (u64 heap_idx = 0; heap_idx < countof(gpu_arena->resource_heaps); ++heap_idx)
|
||||
{
|
||||
gpu_arena->resource_heaps[heap_idx].kind = (G_D12_ResourceHeapKind)heap_idx;
|
||||
}
|
||||
|
||||
return G_D12_MakeHandle(G_ArenaHandle, gpu_arena);
|
||||
}
|
||||
|
||||
@ -741,7 +856,7 @@ void G_ReleaseArena(G_ArenaHandle arena)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Resource helpers
|
||||
//~ Resource
|
||||
|
||||
G_D12_Descriptor *G_D12_DescriptorFromIndex(G_D12_DescriptorHeapKind heap_kind, u32 index)
|
||||
{
|
||||
@ -826,30 +941,21 @@ G_ResourceHandle G_PushBufferEx(G_ArenaHandle arena_handle, G_BufferResourceDesc
|
||||
G_D12_SharedState *g = &G_D12_shared_state;
|
||||
G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle);
|
||||
|
||||
/* Create resource heap */
|
||||
if (!gpu_arena->d3d_resource_heap)
|
||||
/* Fetch heap */
|
||||
G_D12_ResourceHeapKind heap_kind = G_D12_ResourceHeapKind_Default;
|
||||
if (desc.flags & G_ResourceFlag_HostMemory)
|
||||
{
|
||||
/* FIXME: Dynamic size */
|
||||
D3D12_HEAP_DESC d3d_desc = ZI;
|
||||
d3d_desc.SizeInBytes = Mebi(512);
|
||||
d3d_desc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
|
||||
d3d_desc.Flags |= D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; /* TODO: Remove this and support tier 1 resource heaps */
|
||||
d3d_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
|
||||
ID3D12Heap *heap = 0;
|
||||
HRESULT hr = ID3D12Device_CreateHeap(g->device, &d3d_desc, &IID_ID3D12Heap, (void **)&heap);
|
||||
if (!SUCCEEDED(hr))
|
||||
heap_kind = G_D12_ResourceHeapKind_CpuWriteBack;
|
||||
if (desc.flags & G_ResourceFlag_WriteCombineHostMemory)
|
||||
{
|
||||
/* TODO: Don't panic */
|
||||
Panic(Lit("Failed to create D3D12 resource heap"));
|
||||
heap_kind = G_D12_ResourceHeapKind_CpuWriteCombine;
|
||||
}
|
||||
|
||||
gpu_arena->d3d_resource_heap = heap;
|
||||
gpu_arena->heap_size = d3d_desc.SizeInBytes;
|
||||
}
|
||||
G_D12_ResourceHeap *heap = G_D12_ResourceHeapFromArena(gpu_arena, heap_kind);
|
||||
|
||||
/* Create d3d resource */
|
||||
ID3D12Resource *d3d_resource = 0;
|
||||
u64 pos_in_heap = 0;
|
||||
u64 aligned_size = AlignU64(MaxU64(desc.size, 1), 4);
|
||||
{
|
||||
D3D12_RESOURCE_DESC1 d3d_desc = ZI;
|
||||
@ -873,18 +979,18 @@ G_ResourceHandle G_PushBufferEx(G_ArenaHandle arena_handle, G_BufferResourceDesc
|
||||
alloc_align = alloc_info.Alignment;
|
||||
}
|
||||
|
||||
u64 alloc_pos = gpu_arena->heap_pos;
|
||||
alloc_pos = AlignU64(alloc_pos, alloc_align);
|
||||
gpu_arena->heap_pos = alloc_pos + alloc_size;
|
||||
pos_in_heap = heap->pos;
|
||||
pos_in_heap = AlignU64(pos_in_heap, alloc_align);
|
||||
heap->pos = pos_in_heap + alloc_size;
|
||||
|
||||
if (alloc_pos + alloc_size > gpu_arena->heap_size)
|
||||
if (pos_in_heap + alloc_size > heap->size)
|
||||
{
|
||||
Panic(Lit("Gpu arena overflow"));
|
||||
}
|
||||
|
||||
HRESULT hr = ID3D12Device10_CreatePlacedResource2(g->device,
|
||||
gpu_arena->d3d_resource_heap,
|
||||
alloc_pos,
|
||||
heap->d3d_heap,
|
||||
pos_in_heap,
|
||||
&d3d_desc,
|
||||
D3D12_BARRIER_LAYOUT_UNDEFINED,
|
||||
0,
|
||||
@ -895,6 +1001,8 @@ G_ResourceHandle G_PushBufferEx(G_ArenaHandle arena_handle, G_BufferResourceDesc
|
||||
}
|
||||
|
||||
G_D12_Resource *resource = PushStruct(gpu_arena->arena, G_D12_Resource);
|
||||
resource->heap = heap;
|
||||
resource->pos_in_heap = pos_in_heap;
|
||||
resource->d3d_resource = d3d_resource;
|
||||
resource->uid = Atomic64FetchAdd(&g->resource_creation_gen.v, 1) + 1;
|
||||
resource->flags = desc.flags;
|
||||
@ -912,30 +1020,21 @@ G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena_handle, G_TextureResourceDe
|
||||
G_D12_Arena *gpu_arena = G_D12_ArenaFromHandle(arena_handle);
|
||||
D3D12_BARRIER_LAYOUT initial_layout = G_D12_BarrierLayoutFromLayout(desc.initial_layout);
|
||||
|
||||
/* Create resource heap */
|
||||
if (!gpu_arena->d3d_resource_heap)
|
||||
/* Fetch heap */
|
||||
G_D12_ResourceHeapKind heap_kind = G_D12_ResourceHeapKind_Default;
|
||||
if (desc.flags & G_ResourceFlag_HostMemory)
|
||||
{
|
||||
/* FIXME: Dynamic size */
|
||||
D3D12_HEAP_DESC d3d_desc = ZI;
|
||||
d3d_desc.SizeInBytes = Mebi(512);
|
||||
d3d_desc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
|
||||
d3d_desc.Flags |= D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; /* TODO: Remove this and support tier 1 resource heaps */
|
||||
d3d_desc.Properties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
|
||||
ID3D12Heap *heap = 0;
|
||||
HRESULT hr = ID3D12Device_CreateHeap(g->device, &d3d_desc, &IID_ID3D12Heap, (void **)&heap);
|
||||
if (!SUCCEEDED(hr))
|
||||
heap_kind = G_D12_ResourceHeapKind_CpuWriteBack;
|
||||
if (desc.flags & G_ResourceFlag_WriteCombineHostMemory)
|
||||
{
|
||||
/* TODO: Don't panic */
|
||||
Panic(Lit("Failed to create D3D12 resource heap"));
|
||||
heap_kind = G_D12_ResourceHeapKind_CpuWriteCombine;
|
||||
}
|
||||
|
||||
gpu_arena->d3d_resource_heap = heap;
|
||||
gpu_arena->heap_size = d3d_desc.SizeInBytes;
|
||||
}
|
||||
G_D12_ResourceHeap *heap = G_D12_ResourceHeapFromArena(gpu_arena, heap_kind);
|
||||
|
||||
/* Create d3d resource */
|
||||
ID3D12Resource *d3d_resource = 0;
|
||||
u64 pos_in_heap;
|
||||
{
|
||||
D3D12_RESOURCE_DESC1 d3d_desc = ZI;
|
||||
d3d_desc.Dimension = desc.kind == G_TextureKind_1D ? D3D12_RESOURCE_DIMENSION_TEXTURE1D :
|
||||
@ -961,11 +1060,11 @@ G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena_handle, G_TextureResourceDe
|
||||
alloc_align = alloc_info.Alignment;
|
||||
}
|
||||
|
||||
u64 alloc_pos = gpu_arena->heap_pos;
|
||||
alloc_pos = AlignU64(alloc_pos, alloc_align);
|
||||
gpu_arena->heap_pos = alloc_pos + alloc_size;
|
||||
pos_in_heap = heap->pos;
|
||||
pos_in_heap = AlignU64(pos_in_heap, alloc_align);
|
||||
heap->pos = pos_in_heap + alloc_size;
|
||||
|
||||
if (alloc_pos + alloc_size > gpu_arena->heap_size)
|
||||
if (pos_in_heap + alloc_size > heap->size)
|
||||
{
|
||||
Panic(Lit("Gpu arena overflow"));
|
||||
}
|
||||
@ -979,8 +1078,8 @@ G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena_handle, G_TextureResourceDe
|
||||
};
|
||||
|
||||
HRESULT hr = ID3D12Device10_CreatePlacedResource2(g->device,
|
||||
gpu_arena->d3d_resource_heap,
|
||||
alloc_pos,
|
||||
heap->d3d_heap,
|
||||
pos_in_heap,
|
||||
&d3d_desc,
|
||||
initial_layout,
|
||||
(d3d_desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) ? &clear_value : 0,
|
||||
@ -991,6 +1090,8 @@ G_ResourceHandle G_PushTextureEx(G_ArenaHandle arena_handle, G_TextureResourceDe
|
||||
}
|
||||
|
||||
G_D12_Resource *resource = PushStruct(gpu_arena->arena, G_D12_Resource);
|
||||
resource->heap = heap;
|
||||
resource->pos_in_heap = pos_in_heap;
|
||||
resource->d3d_resource = d3d_resource;
|
||||
resource->uid = Atomic64FetchAdd(&g->resource_creation_gen.v, 1) + 1;
|
||||
resource->flags = desc.flags;
|
||||
@ -1055,20 +1156,17 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re
|
||||
G_D12_Descriptor *descriptor = 0;
|
||||
if (is_buffer)
|
||||
{
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav);
|
||||
u64 num_elements_in_buffer = 0;
|
||||
u64 num_elements_after_offset = 0;
|
||||
if (is_raw)
|
||||
{
|
||||
num_elements_in_buffer = 0;
|
||||
num_elements_after_offset = 0;
|
||||
ref_desc.element_size = 4;
|
||||
ref_desc.element_offset /= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
descriptor = G_D12_PushDescriptor(gpu_arena, G_D12_DescriptorHeapKind_CbvSrvUav);
|
||||
u64 buffer_size_aligned = resource->buffer_size_aligned;
|
||||
num_elements_in_buffer = buffer_size_aligned / ref_desc.element_size;
|
||||
num_elements_after_offset = num_elements_in_buffer > ref_desc.element_offset ? num_elements_in_buffer - ref_desc.element_offset : 0;
|
||||
}
|
||||
u64 num_elements_in_buffer = buffer_size_aligned / ref_desc.element_size;
|
||||
u64 num_elements_after_offset = num_elements_in_buffer > ref_desc.element_offset ? num_elements_in_buffer - ref_desc.element_offset : 0;
|
||||
|
||||
if (num_elements_after_offset > 0)
|
||||
{
|
||||
if (is_uav)
|
||||
@ -1086,6 +1184,7 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re
|
||||
{
|
||||
desc.Format = DXGI_FORMAT_R32_TYPELESS;
|
||||
desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
|
||||
desc.Buffer.StructureByteStride = 0;
|
||||
}
|
||||
ID3D12Device_CreateUnorderedAccessView(g->device, resource->d3d_resource, 0, &desc, descriptor->handle);
|
||||
}
|
||||
@ -1105,6 +1204,7 @@ u32 G_PushRef(G_ArenaHandle arena_handle, G_ResourceHandle resource_handle, G_Re
|
||||
{
|
||||
desc.Format = DXGI_FORMAT_R32_TYPELESS;
|
||||
desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
|
||||
desc.Buffer.StructureByteStride = 0;
|
||||
}
|
||||
ID3D12Device_CreateShaderResourceView(g->device, resource->d3d_resource, &desc, descriptor->handle);
|
||||
}
|
||||
@ -1199,6 +1299,15 @@ i32 G_CountDepth(G_ResourceHandle texture)
|
||||
return resource->texture_dims.z;
|
||||
}
|
||||
|
||||
//- Map
|
||||
|
||||
void *G_HostPointerFromResource(G_ResourceHandle resource_handle)
|
||||
{
|
||||
G_D12_Resource *resource = G_D12_ResourceFromHandle(resource_handle);
|
||||
G_D12_ResourceHeap *heap = resource->heap;
|
||||
return ((u8 *)heap->mapped) + resource->pos_in_heap;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Command helpers
|
||||
|
||||
@ -2112,7 +2221,11 @@ void G_ResetArena(G_CommandListHandle cl_handle, G_ArenaHandle arena_handle)
|
||||
/* FIXME: Move descriptors into committed lists */
|
||||
|
||||
/* FIXME: Release id3d12 resource com object references */
|
||||
gpu_arena->heap_pos = 0;
|
||||
for (u64 heap_idx = 0; heap_idx < countof(gpu_arena->resource_heaps); ++heap_idx)
|
||||
{
|
||||
G_D12_ResourceHeap *heap = &gpu_arena->resource_heaps[heap_idx];
|
||||
heap->pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//- Cpu -> Gpu copy
|
||||
@ -2422,41 +2535,6 @@ void G_SyncOtherQueues(G_QueueKind completion_queue_kind)
|
||||
// ID3D12Resource_Unmap(r->d3d_resource, 0, 0);
|
||||
// }
|
||||
|
||||
// void G_CopyBytesToFootprint(void *dst, void *src, G_Resource *footprint_reference)
|
||||
// {
|
||||
// G_D12_SharedState *g = &G_D12_shared_state;
|
||||
|
||||
// D3D12_RESOURCE_DESC desc = ZI;
|
||||
// ID3D12Resource_GetDesc(((G_D12_Resource *)footprint_reference)->d3d_resource, &desc);
|
||||
|
||||
// u64 upload_size = 0;
|
||||
// u64 upload_row_size = 0;
|
||||
// u32 upload_num_rows = 0;
|
||||
// D3D12_PLACED_SUBRESOURCE_FOOTPRINT placed_footprint = ZI;
|
||||
// ID3D12Device_GetCopyableFootprints(g->device, &desc, 0, 1, 0, &placed_footprint, &upload_num_rows, &upload_row_size, &upload_size);
|
||||
// D3D12_SUBRESOURCE_FOOTPRINT footprint = placed_footprint.Footprint;
|
||||
|
||||
// {
|
||||
// D3D12_RANGE read_range = ZI;
|
||||
// u8 *dst_base = (u8 *)dst + placed_footprint.Offset;
|
||||
// u8 *src_base = src;
|
||||
|
||||
// u32 z_size = upload_row_size * upload_num_rows;
|
||||
|
||||
// b32 src_overflow = 0;
|
||||
// for (u32 z = 0; !src_overflow && z < desc.DepthOrArraySize; ++z)
|
||||
// {
|
||||
// u32 z_offset = z * z_size;
|
||||
// for (u32 y = 0; !src_overflow && y < upload_num_rows; ++y)
|
||||
// {
|
||||
// u8 *dst_row = dst_base + y * footprint.RowPitch + z_offset;
|
||||
// u8 *src_row = src_base + y * upload_row_size + z_offset;
|
||||
// CopyBytes(dst_row, src_row, upload_row_size);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ @hookimpl Statistics
|
||||
|
||||
@ -2709,5 +2787,24 @@ void G_D12_WorkerEntry(WaveLaneCtx *lane)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* FIXME: Remove this */
|
||||
|
||||
Sleep(500);
|
||||
|
||||
G_ResourceHandle debug_print_buff = queue->debug_print_buffer;
|
||||
G_D12_Resource *resource = G_D12_ResourceFromHandle(debug_print_buff);
|
||||
|
||||
if (!G_IsResourceNil(debug_print_buff))
|
||||
{
|
||||
u8 *base = G_StructFromResource(debug_print_buff, u8);
|
||||
u32 size = *((u32 *)base);
|
||||
String text = STRING(size, base + 4);
|
||||
|
||||
if (queue_kind == G_QueueKind_Direct)
|
||||
{
|
||||
DEBUGBREAKABLE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,12 +99,7 @@ Struct(G_D12_DescriptorList)
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Arena types
|
||||
|
||||
Struct(G_D12_Arena)
|
||||
{
|
||||
Arena *arena;
|
||||
G_D12_DescriptorList committed_descriptors_by_heap_and_queue[G_D12_DescriptorHeapKind_Count][G_NumQueues];
|
||||
//~ Resource heap types
|
||||
|
||||
/* TODO:
|
||||
* To support D3D12_RESOURCE_HEAP_TIER_1 devices, create separate heaps for:
|
||||
@ -112,9 +107,36 @@ Struct(G_D12_Arena)
|
||||
* - Non-render target & non-depth stencil textures
|
||||
* - Render target or depth stencil textures
|
||||
*/
|
||||
ID3D12Heap *d3d_resource_heap;
|
||||
u64 heap_pos;
|
||||
u64 heap_size;
|
||||
Enum(G_D12_ResourceHeapKind)
|
||||
{
|
||||
G_D12_ResourceHeapKind_Default,
|
||||
G_D12_ResourceHeapKind_CpuWriteBack,
|
||||
G_D12_ResourceHeapKind_CpuWriteCombine,
|
||||
|
||||
G_D12_ResourceHeapKind_Count,
|
||||
};
|
||||
|
||||
Struct(G_D12_ResourceHeap)
|
||||
{
|
||||
G_D12_ResourceHeapKind kind;
|
||||
|
||||
ID3D12Heap *d3d_heap;
|
||||
ID3D12Resource *d3d_mapped_resource;
|
||||
void *mapped;
|
||||
|
||||
u64 pos;
|
||||
u64 size;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Arena types
|
||||
|
||||
Struct(G_D12_Arena)
|
||||
{
|
||||
Arena *arena;
|
||||
G_D12_DescriptorList committed_descriptors_by_heap_and_queue[G_D12_DescriptorHeapKind_Count][G_NumQueues];
|
||||
|
||||
G_D12_ResourceHeap resource_heaps[G_D12_ResourceHeapKind_Count];
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -124,6 +146,9 @@ Struct(G_D12_Resource)
|
||||
{
|
||||
G_D12_Resource *next_free;
|
||||
|
||||
G_D12_ResourceHeap *heap;
|
||||
u64 pos_in_heap;
|
||||
|
||||
ID3D12Resource *d3d_resource;
|
||||
u64 uid;
|
||||
G_ResourceFlag flags;
|
||||
@ -414,7 +439,12 @@ G_D12_Pipeline *G_D12_PipelineFromDesc(G_D12_PipelineDesc desc);
|
||||
G_D12_Queue *G_D12_QueueFromKind(G_QueueKind kind);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Resource helpers
|
||||
//~ Arena
|
||||
|
||||
G_D12_ResourceHeap *G_D12_ResourceHeapFromArena(G_D12_Arena *gpu_arena, G_D12_ResourceHeapKind kind);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Resource
|
||||
|
||||
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);
|
||||
|
||||
@ -110,12 +110,12 @@ G_ForceDeclConstant(G_RWByteAddressBufferRef, G_DebugPrintBuffer, 8);
|
||||
#if IsLanguageG
|
||||
|
||||
/* This technique comes from MJP's article: https://therealmjp.github.io/posts/hlsl-printf/ */
|
||||
#if G__DEBUG
|
||||
#if GPU_DEBUG
|
||||
#define G_DebugPrint(fmt_cstr) do { \
|
||||
u32 __strlen = 0; \
|
||||
for (;;) { if (U32FromChar(fmt_cstr[__strlen]) == 0) { break; } ++__strlen; } \
|
||||
RWByteAddressBuffer __print_buff; \
|
||||
__print_buff = RWByteAddressBufferFromRef(G_DebugPrintBuffer); \
|
||||
__print_buff = G_RWByteAddressBufferFromRef(G_DebugPrintBuffer); \
|
||||
u32 __pos; \
|
||||
__print_buff.InterlockedAdd(0, __strlen, __pos); \
|
||||
if (__pos < countof(__print_buff)) \
|
||||
|
||||
Loading…
Reference in New Issue
Block a user