dxc layer refactor

This commit is contained in:
jacob 2025-07-30 17:54:31 -05:00
parent 2d953cca9b
commit 8ba63a7821
9 changed files with 32 additions and 26 deletions

View File

@ -124,7 +124,7 @@ AC_Asset *AC_TouchCache(String key, u64 hash, b32 *is_first_touch)
} }
String key_stored = ZI; String key_stored = ZI;
{ {
/* CopyStruct key to store */ /* Copy key to store */
AC_Store store = AC_OpenStore(); AC_Store store = AC_OpenStore();
key_stored = CopyString(store.arena, key); key_stored = CopyString(store.arena, key);
AC_CloseStore(&store); AC_CloseStore(&store);

View File

@ -85,7 +85,7 @@ Inline void MergesortInternal(u8 *left, u8 *right, u8 *items, u64 left_count, u6
++r; ++r;
} }
} }
/* CopyStruct remaining */ /* Copy remaining */
if (l != left_count) if (l != left_count)
{ {
u64 remaining_count = left_count - l; u64 remaining_count = left_count - l;

View File

@ -1,7 +1,13 @@
////////////////////////////////
//~ Dxc types
Struct(DXC_Result) { Struct(DXC_Result) {
String dxc; String dxc;
String errors; String errors;
b32 success; b32 success;
}; };
DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String *args); ////////////////////////////////
//~ Dxc operations
DXC_Result DXC_Compile(Arena *arena, String shader_source, i32 num_args, String *args);

View File

@ -1,6 +1,6 @@
#if !RESOURCE_RELOADING #if !RESOURCE_RELOADING
DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String *args) DXC_Result DXC_Compile(Arena *arena, String shader_source, i32 num_args, String *args)
{ {
(UNUSED)arena; (UNUSED)arena;
(UNUSED)shader_source; (UNUSED)shader_source;
@ -29,7 +29,7 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
#pragma comment(lib, "dxcompiler") #pragma comment(lib, "dxcompiler")
/* https://github.com/microsoft/DirectXShaderCompiler/wiki/Using-dxc.exe-and-dxcompiler.dll */ /* https://github.com/microsoft/DirectXShaderCompiler/wiki/Using-dxc.exe-and-dxcompiler.dll */
DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String *args) DXC_Result DXC_Compile(Arena *arena, String shader_source, i32 num_args, String *args)
{ {
__prof; __prof;
TempArena scratch = BeginScratch(arena); TempArena scratch = BeginScratch(arena);
@ -45,7 +45,7 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
dxc_src_buffer.Size = shader_source.len; dxc_src_buffer.Size = shader_source.len;
dxc_src_buffer.Encoding = DXC_CP_UTF8; dxc_src_buffer.Encoding = DXC_CP_UTF8;
/* Init compiler */ //- Init compiler
CComPtr<IDxcUtils> dxc_utils; CComPtr<IDxcUtils> dxc_utils;
CComPtr<IDxcCompiler3> dxc_compiler; CComPtr<IDxcCompiler3> dxc_compiler;
CComPtr<IDxcIncludeHandler> dxc_include_handler; CComPtr<IDxcIncludeHandler> dxc_include_handler;
@ -53,11 +53,11 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&dxc_compiler)); DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&dxc_compiler));
dxc_utils->CreateDefaultIncludeHandler(&dxc_include_handler); dxc_utils->CreateDefaultIncludeHandler(&dxc_include_handler);
/* Compile */ //- Compile
CComPtr<IDxcResult> compile_results = 0; CComPtr<IDxcResult> compile_results = 0;
dxc_compiler->Compile(&dxc_src_buffer, (LPCWSTR *)wstr_args, (u32)num_args, dxc_include_handler, IID_PPV_ARGS(&compile_results)); dxc_compiler->Compile(&dxc_src_buffer, (LPCWSTR *)wstr_args, (u32)num_args, dxc_include_handler, IID_PPV_ARGS(&compile_results));
/* CopyStruct errors */ //- Copy errors
CComPtr<IDxcBlobUtf8> dxc_errors = 0; CComPtr<IDxcBlobUtf8> dxc_errors = 0;
compile_results->GetOutput(DXC_OUT_ERRORS, IID_PPV_ARGS(&dxc_errors), 0); compile_results->GetOutput(DXC_OUT_ERRORS, IID_PPV_ARGS(&dxc_errors), 0);
if (dxc_errors != 0) { if (dxc_errors != 0) {
@ -67,12 +67,12 @@ DXC_Result dxc_compile(Arena *arena, String shader_source, i32 num_args, String
result.errors = CopyString(arena, blob_str); result.errors = CopyString(arena, blob_str);
} }
/* Get status */ //- Get status
HRESULT dxc_hr = 0; HRESULT dxc_hr = 0;
compile_results->GetStatus(&dxc_hr); compile_results->GetStatus(&dxc_hr);
result.success = SUCCEEDED(dxc_hr); result.success = SUCCEEDED(dxc_hr);
/* CopyStruct shader output */ //- Copy shader output
if (result.success) { if (result.success) {
CComPtr<IDxcBlob> dxc_shader = 0; CComPtr<IDxcBlob> dxc_shader = 0;
compile_results->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&dxc_shader), 0); compile_results->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&dxc_shader), 0);

View File

@ -651,7 +651,7 @@ internal void dx12_init_objects(void)
struct command_queue_desc params[] = { struct command_queue_desc params[] = {
{.type = D3D12_COMMAND_LIST_TYPE_DIRECT, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Direct queue") }, {.type = D3D12_COMMAND_LIST_TYPE_DIRECT, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Direct queue") },
{.type = D3D12_COMMAND_LIST_TYPE_COMPUTE, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Compute queue") }, {.type = D3D12_COMMAND_LIST_TYPE_COMPUTE, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Compute queue") },
{.type = D3D12_COMMAND_LIST_TYPE_COPY, .priority = D3D12_COMMAND_QUEUE_PRIORITY_HIGH, .dbg_name = Lit("CopyStruct queue") }, {.type = D3D12_COMMAND_LIST_TYPE_COPY, .priority = D3D12_COMMAND_QUEUE_PRIORITY_HIGH, .dbg_name = Lit("Copyqueue") },
{.type = D3D12_COMMAND_LIST_TYPE_COPY, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Background copy queue") } {.type = D3D12_COMMAND_LIST_TYPE_COPY, .priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL, .dbg_name = Lit("Background copy queue") }
}; };
struct command_queue_alloc_job_sig sig = ZI; struct command_queue_alloc_job_sig sig = ZI;
@ -899,7 +899,7 @@ internal P_JobDef(shader_compile_job, job)
for (u32 i = 0; i < dxc_args_array.count; ++i) { for (u32 i = 0; i < dxc_args_array.count; ++i) {
args[i + countof(shader_args)] = dxc_args_array.strings[i]; args[i + countof(shader_args)] = dxc_args_array.strings[i];
} }
dxc_result = dxc_compile(arena, desc->src, num_args, args); dxc_result = DXC_Compile(arena, desc->src, num_args, args);
} }
result->success = dxc_result.success; result->success = dxc_result.success;
result->dxc = dxc_result.dxc; result->dxc = dxc_result.dxc;
@ -2015,7 +2015,7 @@ internal struct command_descriptor_heap *command_list_push_descriptor_heap(struc
ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(cdh->heap, &cdh->start_gpu_handle); ID3D12DescriptorHeap_GetGPUDescriptorHandleForHeapStart(cdh->heap, &cdh->start_gpu_handle);
} }
/* CopyStruct CPU heap */ /* CopyCPU heap */
{ {
P_Lock lock = P_LockS(&dh_cpu->mutex); P_Lock lock = P_LockS(&dh_cpu->mutex);
ID3D12Device_CopyDescriptorsSimple(G.device, dh_cpu->num_descriptors_reserved, cdh->start_cpu_handle, dh_cpu->handle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); ID3D12Device_CopyDescriptorsSimple(G.device, dh_cpu->num_descriptors_reserved, cdh->start_cpu_handle, dh_cpu->handle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
@ -2328,7 +2328,7 @@ internal P_JobDef(dx12_upload_job, job)
struct command_queue *cq = G.command_queues[DX12_QUEUE_COPY_BACKGROUND]; struct command_queue *cq = G.command_queues[DX12_QUEUE_COPY_BACKGROUND];
struct command_list *cl = command_list_open(cq->cl_pool); struct command_list *cl = command_list_open(cq->cl_pool);
{ {
/* CopyStruct to upload heap */ /* Copyto upload heap */
{ {
D3D12_RANGE read_range = ZI; D3D12_RANGE read_range = ZI;
void *mapped = 0; void *mapped = 0;
@ -2351,7 +2351,7 @@ internal P_JobDef(dx12_upload_job, job)
ID3D12Resource_Unmap(upload->resource, 0, 0); ID3D12Resource_Unmap(upload->resource, 0, 0);
} }
/* CopyStruct from upload heap to texture */ /* Copyfrom upload heap to texture */
{ {
__profnc_dx12(cl->cq->prof, cl->cl, "Upload texture", Rgb32F(0.2, 0.5, 0.2)); __profnc_dx12(cl->cq->prof, cl->cl, "Upload texture", Rgb32F(0.2, 0.5, 0.2));
D3D12_TEXTURE_COPY_LOCATION dst_loc = { D3D12_TEXTURE_COPY_LOCATION dst_loc = {
@ -3500,11 +3500,11 @@ internal P_JobDef(dx12_evictor_job, _)
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
u64 targets[countof(completed_targets)] = ZI; u64 targets[countof(completed_targets)] = ZI;
/* CopyStruct queued data */ /* Copyqueued data */
u32 num_fenced_releases = 0; u32 num_fenced_releases = 0;
struct fenced_release_data *fenced_releases = 0; struct fenced_release_data *fenced_releases = 0;
{ {
__profn("CopyStruct queued releases"); __profn("Copyqueued releases");
P_Lock lock = P_LockE(&G.fenced_releases_mutex); P_Lock lock = P_LockE(&G.fenced_releases_mutex);
num_fenced_releases = G.fenced_releases_arena->pos / sizeof(struct fenced_release_data); num_fenced_releases = G.fenced_releases_arena->pos / sizeof(struct fenced_release_data);
fenced_releases = PushStructsNoZero(scratch.arena, struct fenced_release_data, num_fenced_releases); fenced_releases = PushStructsNoZero(scratch.arena, struct fenced_release_data, num_fenced_releases);

View File

@ -102,7 +102,7 @@ P_W32_Thread *P_W32_AllocThread(P_W32_ThreadFunc *entry_point, void *thread_data
t->thread_data = thread_data; t->thread_data = thread_data;
t->profiler_group = profiler_group; t->profiler_group = profiler_group;
/* CopyStruct thread name to params */ /* Copy thread name to params */
{ {
u64 CstrLen = MinU64((countof(t->thread_name_cstr) - 1), thread_name.len); u64 CstrLen = MinU64((countof(t->thread_name_cstr) - 1), thread_name.len);
CopyBytes(t->thread_name_cstr, thread_name.text, CstrLen * sizeof(*t->thread_name_cstr)); CopyBytes(t->thread_name_cstr, thread_name.text, CstrLen * sizeof(*t->thread_name_cstr));
@ -2886,7 +2886,7 @@ P_Address P_AddressFromString(String str)
} }
else else
{ {
/* CopyStruct address without port */ /* Copy address without port */
ip_len = MinU64(str.len, countof(ip_buff) - 1); ip_len = MinU64(str.len, countof(ip_buff) - 1);
CopyBytes(ip_buff, str.text, ip_len); CopyBytes(ip_buff, str.text, ip_len);
} }

View File

@ -189,7 +189,7 @@ internal void wasapi_update_end(struct wasapi_buffer *wspbuf, M_PcmF32 src)
u32 flags = 0; u32 flags = 0;
if (frames_in_source == frames_in_output) { if (frames_in_source == frames_in_output) {
/* CopyStruct bytes to output */ /* Copy bytes to output */
u32 bytes_per_sample = G.buffer_format->nBlockAlign / G.buffer_format->nChannels; u32 bytes_per_sample = G.buffer_format->nBlockAlign / G.buffer_format->nChannels;
u32 write_size = frames_in_source * 2 * bytes_per_sample; u32 write_size = frames_in_source * 2 * bytes_per_sample;
CopyBytes(wspbuf->frames, src.samples, write_size); CopyBytes(wspbuf->frames, src.samples, write_size);

View File

@ -303,14 +303,14 @@ Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick)
ss->client = client; ss->client = client;
++client->num_ticks; ++client->num_ticks;
/* CopyStruct src info */ /* Copy src info */
ss->sim_dt_ns = src->sim_dt_ns; ss->sim_dt_ns = src->sim_dt_ns;
ss->sim_time_ns = src->sim_time_ns; ss->sim_time_ns = src->sim_time_ns;
ss->continuity_gen = src->continuity_gen; ss->continuity_gen = src->continuity_gen;
ss->local_player = src->local_player; ss->local_player = src->local_player;
ss->phys_iteration = src->phys_iteration; ss->phys_iteration = src->phys_iteration;
/* CopyStruct id lookup bins */ /* Copy id lookup bins */
ss->num_id_bins = src->num_id_bins > 0 ? src->num_id_bins : ID_LOOKUP_BINS; ss->num_id_bins = src->num_id_bins > 0 ? src->num_id_bins : ID_LOOKUP_BINS;
ss->id_bins = PushStructsNoZero(ss->arena, EntBin, ss->num_id_bins); ss->id_bins = PushStructsNoZero(ss->arena, EntBin, ss->num_id_bins);
if (src->num_id_bins > 0) { if (src->num_id_bins > 0) {
@ -321,7 +321,7 @@ Snapshot *sim_snapshot_alloc(Client *client, Snapshot *src, u64 tick)
ZeroBytes(ss->id_bins, sizeof(*ss->id_bins) * ss->num_id_bins); ZeroBytes(ss->id_bins, sizeof(*ss->id_bins) * ss->num_id_bins);
} }
/* CopyStruct entities */ /* Copy entities */
ss->first_free_ent = src->first_free_ent; ss->first_free_ent = src->first_free_ent;
ss->num_ents_allocated = src->num_ents_allocated; ss->num_ents_allocated = src->num_ents_allocated;
ss->num_ents_reserved = src->num_ents_reserved; ss->num_ents_reserved = src->num_ents_reserved;
@ -689,7 +689,7 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntId remot
if (should_sync) { if (should_sync) {
Ent *remote_ent = sim_ent_from_id(remote_ss, local_ent->id); Ent *remote_ent = sim_ent_from_id(remote_ss, local_ent->id);
if (remote_ent->valid) { if (remote_ent->valid) {
/* CopyStruct all ent data from remote */ /* Copy all ent data from remote */
sim_ent_sync(local_ent, remote_ent); sim_ent_sync(local_ent, remote_ent);
} else { } else {
/* Remote ent is no longer valid / networked, release it */ /* Remote ent is no longer valid / networked, release it */

View File

@ -1137,7 +1137,7 @@ internal void user_update(P_Window *window)
Ent **sorted = PushDry(scratch.arena, Ent *); Ent **sorted = PushDry(scratch.arena, Ent *);
u64 sorted_count = 0; u64 sorted_count = 0;
{ {
/* CopyStruct valid entities */ /* Copy valid entities */
{ {
__profn("Build ents list for sorting"); __profn("Build ents list for sorting");
for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) { for (u64 ent_index = 0; ent_index < G.ss_blended->num_ents_reserved; ++ent_index) {
@ -2745,7 +2745,7 @@ internal P_JobDef(local_sim_job, _)
} }
} }
/* CopyStruct local snapshot to user client */ /* Copy local snapshot to user client */
{ {
Snapshot *local_ss = sim_snapshot_from_tick(local_client, local_client->last_tick); Snapshot *local_ss = sim_snapshot_from_tick(local_client, local_client->last_tick);
if (local_ss->valid) { if (local_ss->valid) {