meta layer progress

This commit is contained in:
jacob 2025-08-12 08:38:13 -05:00
parent deed0e2013
commit 014b8e84c3
54 changed files with 1077 additions and 5015 deletions

View File

@ -47,7 +47,7 @@ if "%meta%" == "1" (
if "%pp%" == "1" (
echo [Building power play]
"build/meta.exe" pp.lay
"build/meta.exe" pp
if not "!errorlevel!" == "0" (
echo.

View File

@ -23,4 +23,4 @@
////////////////////////////////
//~ Api
@CpuApi app_core
@ApiC app_core

View File

@ -9,4 +9,4 @@
////////////////////////////////
//~ Api
@CpuApi ase_core
@ApiC ase_core

View File

@ -9,7 +9,7 @@
////////////////////////////////
//~ Api
@CpuApi asset_cache_core
@ApiC asset_cache_core
////////////////////////////////
//~ Init

View File

@ -1,37 +1,31 @@
@Layer base
////////////////////////////////
//~ Deps
@Dep prof
////////////////////////////////
//~ Api
@CpuApi base_core
@GpuApi base_core
@ApiC base_core
@ApiC base_intrinsics
@ApiC base_memory
@ApiC base_arena
@ApiC base_snc
@ApiC base_job
@ApiC base_uid
@ApiC base_string
@ApiC base_uni
@ApiC base_gstat
@ApiC base_buddy
@ApiC base_math
@ApiC base_rand
@ApiC base_util
@ApiC base_incbin
@ApiC base_entry
@CpuApi base_intrinsics
@CpuApi base_memory
@CpuApi base_arena
@CpuApi base_snc
@CpuApi base_job
@CpuApi base_uid
@CpuApi base_string
@CpuApi base_uni
@CpuApi base_gstat
@CpuApi base_buddy
@CpuApi base_math
@CpuApi base_rand
@CpuApi base_util
@CpuApi base_incbin
@CpuApi base_entry
@GpuApi base_math_gpu
@ApiGpu base_core
@ApiGpu base_math_gpu
//- Win32
@CpuApiWindows win32/base_win32_job
@CpuApiWindows win32/base_win32_entry
@ApiCWindows win32/base_win32_job
@ApiCWindows win32/base_win32_entry
////////////////////////////////
//~ Init

View File

@ -14,7 +14,8 @@ Struct(Arena)
#endif
};
Struct(TempArena) {
Struct(TempArena)
{
Arena *arena;
u64 start_pos;
@ -118,16 +119,22 @@ void SetArenaReadWrite(Arena *arena);
Inline void *AlignArena(Arena *arena, u64 align)
{
Assert(!arena->readonly);
if (align > 0) {
if (align > 0)
{
u64 aligned_start_pos = (arena->pos + (align - 1));
aligned_start_pos -= aligned_start_pos % align;
u64 align_bytes = aligned_start_pos - (u64)arena->pos;
if (align_bytes > 0) {
if (align_bytes > 0)
{
return (void *)PushStructsNoZero(arena, u8, align_bytes);
} else {
}
else
{
return (void *)(ArenaBase(arena) + arena->pos);
}
} else {
}
else
{
/* 0 alignment */
Assert(0);
return (void *)(ArenaBase(arena) + arena->pos);
@ -163,9 +170,11 @@ Inline ArenaCtx *ArenaCtxFromFiberId(i16 fiber_id)
{
SharedArenaCtx *shared = &shared_arena_ctx;
ArenaCtx *ctx = &shared->arena_contexts[fiber_id];
if (!ctx->scratch_arenas[0]) {
if (!ctx->scratch_arenas[0])
{
__profn("Initialize fiber arena ctx");
for (i32 i = 0; i < (i32)countof(ctx->scratch_arenas); ++i) {
for (i32 i = 0; i < (i32)countof(ctx->scratch_arenas); ++i)
{
ctx->scratch_arenas[i] = AcquireArena(Gibi(64));
}
ctx->perm_arena = AcquireArena(Gibi(64));
@ -196,7 +205,8 @@ Inline TempArena _BeginScratch(Arena *potential_conflict)
ArenaCtx *ctx = ArenaCtxFromFiberId(FiberId());
Arena *scratch_arena = ctx->scratch_arenas[0];
if (potential_conflict && scratch_arena == potential_conflict) {
if (potential_conflict && scratch_arena == potential_conflict)
{
scratch_arena = ctx->scratch_arenas[1];
}
TempArena temp = BeginTempArena(scratch_arena);

View File

@ -59,16 +59,10 @@ extern "C" {
#endif
//- Language
#if defined(__cplusplus)
# define LanguageIsCpp 1
# define LanguageIsC 0
# define LanguageIsGpu 0
#elif defined(__STDC_VERSION__)
# define LanguageIsCpp 0
#if defined(__STDC_VERSION__)
# define LanguageIsC 1
# define LanguageIsGpu 0
#elif defined(__HLSL_VERSION)
# define LanguageIsCpp 0
# define LanguageIsC 0
# define LanguageIsGpu 1
#else
@ -173,13 +167,6 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Common utility macros
//- Initlist compatibility
#if CompilerIsMsvc && LanguageIsCpp
# define CppCompatInitListType(type)
#else
# define CppCompatInitListType(type) (type)
#endif
//- ZeroStruct initialization macro
#if LanguageIsC
# define ZI { 0 }
@ -248,16 +235,10 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define LAX (void)
//- Fallthrough
#if CompilerIsMsvc
# if LanguageIsCpp
# define FALLTHROUGH [[fallthrough]]
# else
#if CompilerIsClang
# define FALLTHROUGH
# endif
#elif CompilerIsClang
#else
# define FALLTHROUGH __attribute((fallthrough))
#else
# define FALLTHROUGH
#endif
//- Preprocessor concatenation
@ -281,18 +262,6 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Type helper macros
//- typeof
#if CompilerIsMsvc
/* Typeof not supported in MSVC */
# define TypeofIsDefined 0
# define typeof(type) Assert(0)
#else
# define TypeofIsDefined 1
# if LanguageIsCpp || (__STDC_VERSION__ < 202311L)
# define typeof(type) __typeof__(type)
# endif
#endif
//- alignof
#if (CompilerIsMsvc && LanguageIsC) || (LanguageIsC && (__STDC_VERSION__ < 202311L))
# define alignof(type) __alignof(type)
@ -383,7 +352,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Intrinsic headers
#if !LanguageIsGpu
#if LanguageIsC
/* Intrinsic header info:
* <mmintrin.h" MMX
* <xmmintrin.h" SSE
@ -409,7 +378,8 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Scalar types
#if !LanguageIsGpu
#if LanguageIsC
//- Cpu scalar types
#include "stdint.h"
typedef int8_t i8;
@ -449,7 +419,7 @@ typedef uint b32;
#define I64Min ((i64)0x8000000000000000LL)
//- Float infinity / nan constants
#if !LanguageIsGpu
#if LanguageIsC
Global const u32 _f32_infinity_u32 = 0x7f800000;
Global const f32 *_f32_infinity = (f32 *)&_f32_infinity_u32;
#define F32Infinity (*_f32_infinity)
@ -468,12 +438,13 @@ Global const f64 *_f64_nan = (f64 *)&_f64_nan_u64;
#define IsF32Nan(x) (x != x)
#define IsF64Nan(x) (x != x)
#endif
////////////////////////////////
//~ Atomics
#if !LanguageIsGpu
#if LanguageIsC
//- Atomic types
Struct(Atomic8) { volatile i8 _v; };
@ -525,7 +496,7 @@ ForceInline i64 Atomic64FetchAdd(Atomic64 *x, i64 a) { return (i64)_InterlockedE
////////////////////////////////
//~ Ticket mutex
#if !LanguageIsGpu
#if LanguageIsC
Struct(TicketMutex)
{
@ -553,15 +524,11 @@ ForceInline void UnlockTicketMutex(TicketMutex *tm)
#define MaxFibers 1024
#if !LanguageIsGpu
#if LanguageIsC
# if PlatformIsWindows
ForceInline i16 FiberId(void)
{
#if LanguageIsCpp
i16 *v = reinterpret_cast<i16 *>((void *)__readgsqword(32));
#else
i16 *v = (void *)__readgsqword(32);
#endif
return *v;
}
# else

View File

@ -8,4 +8,4 @@
////////////////////////////////
//~ Api
@CpuApi bitbuff_core
@ApiC bitbuff_core

View File

@ -8,4 +8,4 @@
////////////////////////////////
//~ Api
@CpuApi collider_core
@ApiC collider_core

View File

@ -143,7 +143,8 @@ void CLD_DebugBreakable(void);
if (dbg_step >= GetGstat(GSTAT_DEBUG_STEPS)) \
{ \
goto abort; \
} else if (dbg_step >= GetGstat(GSTAT_DEBUG_STEPS) - 1) \
} \
else if (dbg_step >= GetGstat(GSTAT_DEBUG_STEPS) - 1) \
{ \
CLD_DebugBreakable(); \
} (void)0

View File

@ -12,7 +12,7 @@
////////////////////////////////
//~ Api
@CpuApi draw_core
@ApiC draw_core
////////////////////////////////
//~ Init

View File

@ -1,14 +0,0 @@
@Layer dxc
////////////////////////////////
//~ Dependencies
@Dep base
////////////////////////////////
//~ Api
@CpuApi dxc_core
//- Win32
@CpuApiWindows win32/dxc_win32

View File

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

View File

@ -1,97 +0,0 @@
#if !RESOURCE_RELOADING
DXC_Result DXC_Compile(Arena *arena, String shader_source, i32 num_args, String *args)
{
LAX arena;
LAX shader_source;
LAX num_args;
LAX args;
DXC_Result result = ZI;
return result;
}
#else
#if CompilerIsClang
# pragma clang diagnostic ignored "-Wlanguage-extension-token"
#endif
////////////////////////////////
//~ Windows headers
#pragma warning(push, 0)
# define WIN32_LEAN_AND_MEAN
# define UNICODE
# include <Windows.h>
# include <atlbase.h>
# include <dxcapi.h>
# include <d3d12shader.h>
#pragma warning(pop)
#pragma comment(lib, "d3dcompiler")
#pragma comment(lib, "dxcompiler")
////////////////////////////////
//~ Compile
/* 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)
{
__prof;
TempArena scratch = BeginScratch(arena);
DXC_Result result = ZI;
wchar_t **wstr_args = PushStructs(scratch.arena, wchar_t *, num_args);
for (i32 i = 0; i < num_args; ++i) {
wstr_args[i] = WstrFromString(scratch.arena, args[i]);
}
DxcBuffer dxc_src_buffer = ZI;
dxc_src_buffer.Ptr = shader_source.text;
dxc_src_buffer.Size = shader_source.len;
dxc_src_buffer.Encoding = DXC_CP_UTF8;
//- Init compiler
CComPtr<IDxcUtils> dxc_utils;
CComPtr<IDxcCompiler3> dxc_compiler;
CComPtr<IDxcIncludeHandler> dxc_include_handler;
DxcCreateInstance(CLSID_DxcUtils, IID_PPV_ARGS(&dxc_utils));
DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&dxc_compiler));
dxc_utils->CreateDefaultIncludeHandler(&dxc_include_handler);
//- Compile
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));
//- Copy errors
CComPtr<IDxcBlobUtf8> dxc_errors = 0;
compile_results->GetOutput(DXC_OUT_ERRORS, IID_PPV_ARGS(&dxc_errors), 0);
if (dxc_errors != 0) {
String blob_str = ZI;
blob_str.len = dxc_errors->GetBufferSize();
blob_str.text = (u8 *)dxc_errors->GetBufferPointer();
result.errors = PushString(arena, blob_str);
}
//- Get status
HRESULT dxc_hr = 0;
compile_results->GetStatus(&dxc_hr);
result.success = SUCCEEDED(dxc_hr);
//- Copy shader output
if (result.success) {
CComPtr<IDxcBlob> dxc_shader = 0;
compile_results->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&dxc_shader), 0);
if (dxc_shader != 0) {
String blob_str = ZI;
blob_str.len = dxc_shader->GetBufferSize();
blob_str.text = (u8 *)dxc_shader->GetBufferPointer();
result.dxc = PushString(arena, blob_str);
}
}
EndScratch(scratch);
return result;
}
#endif

View File

@ -12,4 +12,4 @@
////////////////////////////////
//~ Api
@CpuApi font_core
@ApiC font_core

File diff suppressed because it is too large Load Diff

View File

@ -1,590 +0,0 @@
////////////////////////////////
//~ D3D12 headers
#pragma warning(push, 0)
# define UNICODE
# define COBJMACROS
# include <Windows.h>
# include <d3d12.h>
# include <dxgidebug.h>
# include <dxgi1_6.h>
# include <combaseapi.h>
# include <d3dcompiler.h>
#pragma warning(pop)
////////////////////////////////
//~ Dx12
#define DX12_ALLOW_TEARING 1
#define DX12_WAIT_FRAME_LATENCY 1
#define DX12_SWAPCHAIN_FLAGS (((DX12_ALLOW_TEARING != 0) * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) | ((DX12_WAIT_FRAME_LATENCY != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT))
#define DX12_SWAPCHAIN_BUFFER_COUNT (4)
/* Arbitrary limits */
#define DX12_NUM_CBV_SRV_UAV_DESCRIPTORS (1024 * 64)
#define DX12_NUM_RTV_DESCRIPTORS (1024 * 1)
#define DX12_COMMAND_BUFFER_MIN_SIZE (1024 * 64)
#define DX12_MULTI_QUEUE !ProfilingIsEnabled
#if DX12_MULTI_QUEUE
# define DX12_QUEUE_DIRECT 0
# define DX12_QUEUE_COMPUTE 1
# define DX12_QUEUE_COPY 2
# define DX12_QUEUE_COPY_BACKGROUND 3
# define DX12_NUM_QUEUES 4
#else
# define DX12_QUEUE_DIRECT 0
# define DX12_QUEUE_COMPUTE 0
# define DX12_QUEUE_COPY 0
# define DX12_QUEUE_COPY_BACKGROUND 0
# define DX12_NUM_QUEUES 1
#endif
#if RtcIsEnabled
//# define DX12_DEBUG 1
# define DX12_DEBUG 0
#else
# define DX12_DEBUG 0
#endif
////////////////////////////////
//~ structs
Struct(GPU_D12_Descriptor)
{
struct GPU_D12_CpuDescriptorHeap *heap;
u32 index;
D3D12_CPU_DESCRIPTOR_HANDLE handle;
GPU_D12_Descriptor *next_free;
};
Struct(GPU_D12_Resource)
{
enum D3D12_RESOURCE_STATES state;
ID3D12Resource *resource;
GPU_D12_Descriptor *cbv_descriptor;
GPU_D12_Descriptor *srv_descriptor;
GPU_D12_Descriptor *uav_descriptor;
GPU_D12_Descriptor *rtv_descriptor;
D3D12_GPU_VIRTUAL_ADDRESS gpu_address; /* NOTE: 0 for textures */
Vec2I32 texture_size;
GPU_D12_Resource *next_free;
};
Struct(GPU_D12_RtvDesc)
{
DXGI_FORMAT format;
b32 blending;
};
Struct(GPU_D12_PipelineDesc)
{
String name;
/* If a dxc string is set, then it will be used directly instead of looking up dxc from archive using pipeline name */
String vs_dxc;
String ps_dxc;
String cs_dxc;
GPU_D12_RtvDesc rtvs[8];
};
Struct(GPU_D12_Pipeline)
{
String name;
u64 hash;
b32 success;
b32 is_gfx;
String error;
i64 compilation_time_ns;
/* Lock global pipelines mutex when accessing */
i64 refcount;
ID3D12PipelineState *pso;
ID3D12RootSignature *rootsig;
GPU_D12_PipelineDesc desc;
GPU_D12_Pipeline *next;
};
Struct(GPU_D12_PipelineScope)
{
Arena *arena;
Dict *refs;
GPU_D12_PipelineScope *next_free;
};
Struct(GPU_D12_CommandQueueDesc)
{
enum D3D12_COMMAND_LIST_TYPE type;
enum D3D12_COMMAND_QUEUE_PRIORITY priority;
String dbg_name;
};
Struct(GPU_D12_CommandQueue)
{
GPU_D12_CommandQueueDesc desc;
ID3D12CommandQueue *cq;
Arena *arena;
Mutex submit_fence_mutex;
u64 submit_fence_target;
ID3D12Fence *submit_fence;
struct GPU_D12_CommandListPool *cl_pool;
#if ProfilingGpu
__prof_dx12_ctx(prof);
#endif
};
Struct(GPU_D12_CommandListPool)
{
GPU_D12_CommandQueue *cq;
Arena *arena;
Mutex mutex;
struct GPU_D12_CommandList *first_submitted_command_list;
struct GPU_D12_CommandList *last_submitted_command_list;
};
Struct(GPU_D12_CommandDescriptorHeap)
{
D3D12_DESCRIPTOR_HEAP_TYPE type;
ID3D12DescriptorHeap *heap;
D3D12_CPU_DESCRIPTOR_HANDLE start_cpu_handle;
D3D12_GPU_DESCRIPTOR_HANDLE start_gpu_handle;
GPU_D12_CommandDescriptorHeap *next_in_command_list;
u64 submitted_fence_target;
GPU_D12_CommandQueue *submitted_cq;
GPU_D12_CommandDescriptorHeap *prev_submitted;
GPU_D12_CommandDescriptorHeap *next_submitted;
};
Struct(GPU_D12_CommandBuffer)
{
struct GPU_D12_CommandBufferGroup *group;
u64 size;
GPU_D12_Resource *resource;
D3D12_VERTEX_BUFFER_VIEW vbv;
D3D12_INDEX_BUFFER_VIEW Ibv;
GPU_D12_CommandBuffer *next_in_command_list;
u64 submitted_fence_target;
GPU_D12_CommandQueue *submitted_cq;
GPU_D12_CommandBuffer *prev_submitted;
GPU_D12_CommandBuffer *next_submitted;
};
Struct(GPU_D12_CommandBufferGroup)
{
GPU_D12_CommandBuffer *first_submitted;
GPU_D12_CommandBuffer *last_submitted;
};
Struct(GPU_D12_CommandList)
{
GPU_D12_CommandQueue *cq;
GPU_D12_CommandListPool *pool;
struct ID3D12CommandAllocator *ca;
struct ID3D12GraphicsCommandList *cl;
Lock global_record_lock;
GPU_D12_Pipeline *cur_pipeline;
GPU_D12_CommandDescriptorHeap *first_command_descriptor_heap;
GPU_D12_CommandBuffer *first_command_buffer;
u64 submitted_fence_target;
GPU_D12_CommandList *prev_submitted;
GPU_D12_CommandList *next_submitted;
};
Struct(GPU_D12_SwapchainBuffer)
{
struct GPU_D12_Swapchain *swapchain;
ID3D12Resource *resource;
GPU_D12_Descriptor *rtv_descriptor;
D3D12_RESOURCE_STATES state;
};
Struct(GPU_D12_Swapchain)
{
IDXGISwapChain3 *swapchain;
HWND hwnd;
HANDLE waitable;
Vec2I32 resolution;
GPU_D12_SwapchainBuffer buffers[DX12_SWAPCHAIN_BUFFER_COUNT];
GPU_D12_Swapchain *next_free;
};
Struct(GPU_D12_CpuDescriptorHeap)
{
enum D3D12_DESCRIPTOR_HEAP_TYPE type;
Arena *arena;
Mutex mutex;
u32 descriptor_size;
u32 num_descriptors_reserved;
u32 num_descriptors_capacity;
GPU_D12_Descriptor *first_free_descriptor;
ID3D12DescriptorHeap *heap;
struct D3D12_CPU_DESCRIPTOR_HANDLE handle;
};
typedef i32 GPU_D12_FencedReleaseKind; enum
{
GPU_D12_FencedReleaseKind_None,
GPU_D12_FencedReleaseKind_Resource,
GPU_D12_FencedReleaseKind_Pipeline
};
Struct(GPU_D12_FencedReleaseData)
{
GPU_D12_FencedReleaseKind kind;
void *ptr;
};
Struct(GPU_D12_ShaderDesc)
{
String src;
String friendly_name;
String entry;
String target;
};
Struct(GPU_D12_CompiledShaderResult)
{
i64 elapsed_ns;
String dxc;
String errors;
b32 success;
};
Struct(GPU_D12_RenderSig)
{
Arena *arena;
RandState rand;
u32 frame_index;
/* Material instances */
u32 num_material_instance_descs;
Arena *material_instance_descs_arena;
/* Ui instances */
u32 num_ui_rect_instance_descs;
Arena *ui_rect_instance_descs_arena;
/* UI shapes */
Arena *ui_shape_verts_arena;
Arena *ui_shape_indices_arena;
/* Grids */
u32 num_material_grid_descs;
Arena *material_grid_descs_arena;
/* Resources */
GPU_D12_Resource *albedo;
GPU_D12_Resource *emittance;
GPU_D12_Resource *emittance_flood_read;
GPU_D12_Resource *emittance_flood_target;
GPU_D12_Resource *shade_read;
GPU_D12_Resource *shade_target;
GPU_D12_Resource *ui_target;
};
Struct(GPU_D12_MaterialInstanceDesc)
{
Xform xf;
u32 texture_id;
ClipRect clip;
u32 tint;
b32 is_light;
Vec3 light_emittance;
u32 grid_id;
};
Struct(GPU_D12_UiRectInstanceDesc)
{
Xform xf;
u32 texture_id;
ClipRect clip;
u32 tint;
};
Struct(GPU_D12_MaterialGridDesc)
{
f32 line_thickness;
f32 line_spacing;
Vec2 offset;
u32 bg0_color;
u32 bg1_color;
u32 line_color;
u32 x_color;
u32 y_color;
};
Struct(GPU_D12_ResourceBarrierDesc)
{
enum D3D12_RESOURCE_BARRIER_TYPE type;
GPU_D12_Resource *resource;
enum D3D12_RESOURCE_STATES new_state; /* 0 if type != D3D12_RESOURCE_BARRIER_TYPE_TRANSITION */
};
////////////////////////////////
//~ Shared state
Struct(GPU_D12_SharedState)
{
Atomic32 initialized;
/* Descriptor heaps pool */
Mutex command_descriptor_heaps_mutex;
Arena *command_descriptor_heaps_arena;
GPU_D12_CommandDescriptorHeap *first_submitted_command_descriptor_heap;
GPU_D12_CommandDescriptorHeap *last_submitted_command_descriptor_heap;
/* Command buffers pool */
Mutex command_buffers_mutex;
Arena *command_buffers_arena;
Dict *command_buffers_dict;
/* Resources pool */
Mutex resources_mutex;
Arena *resources_arena;
GPU_D12_Resource *first_free_resource;
/* Swapchains pool */
Mutex swapchains_mutex;
Arena *swapchains_arena;
GPU_D12_Swapchain *first_free_swapchain;
/* Shader bytecode archive */
TAR_Archive dxc_archive;
/* Pipeline cache */
Mutex pipelines_mutex;
Arena *pipelines_arena;
GPU_D12_Pipeline *first_free_pipeline;
Dict *pipeline_descs;
Dict *top_pipelines; /* Latest pipelines */
Dict *top_successful_pipelines; /* Latest pipelines that successfully compiled */
GPU_D12_PipelineScope *first_free_pipeline_scope;
/* Fenced release queue */
Mutex fenced_releases_mutex;
Arena *fenced_releases_arena;
u64 fenced_release_targets[DX12_NUM_QUEUES];
/* Factory */
IDXGIFactory6 *factory;
/* Adapter */
IDXGIAdapter1 *adapter;
/* Device */
ID3D12Device *device;
/* Descriptor sizes */
u32 desc_sizes[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];
u32 desc_counts[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];
/* Global descriptor heaps */
GPU_D12_CpuDescriptorHeap *cbv_srv_uav_heap;
GPU_D12_CpuDescriptorHeap *rtv_heap;
/* Command queues */
Mutex global_command_list_record_mutex;
Mutex global_submit_mutex;
GPU_D12_CommandQueue *command_queues[DX12_NUM_QUEUES];
/* Evictor job */
Counter evictor_job_counter;
Cv evictor_wake_cv;
Mutex evictor_wake_mutex;
i64 evictor_wake_gen;
b32 evictor_shutdown;
};
extern GPU_D12_SharedState GPU_D12_shared_state;
////////////////////////////////
//~ Startup
ExitFuncDef(GPU_D12_Shutdown);
////////////////////////////////
//~ Dx12 device initialization
void GPU_D12_PushInitError(String error);
void GPU_D12_InitDevice(void);
////////////////////////////////
//~ Dx12 object initialization
void GPU_D12_InitObjects(void);
////////////////////////////////
//~ Dx12 pipeline initialization
void GPU_InitPipelines(void);
////////////////////////////////
//~ Noise texture initialization
void GPU_D12_InitNoise(void);
////////////////////////////////
//~ Shader compilation
JobDecl(GPU_D12_CompileShaderJob, { Arena *arena; GPU_D12_ShaderDesc *descs; GPU_D12_CompiledShaderResult *results; });
////////////////////////////////
//~ Pipeline
JobDecl(GPU_D12_AcquirePipelineJob, { GPU_D12_PipelineDesc *descs_in; GPU_D12_Pipeline **pipelines_out; });
void GPU_D12_ReleasePipelineNow(GPU_D12_Pipeline *pipeline);
////////////////////////////////
//~ Pipeline cache
GPU_D12_PipelineScope *GPU_D12_BeginPipelineScope(void);
void GPU_D12_EndPipelineScope(GPU_D12_PipelineScope *scope);
extern Readonly GPU_D12_Pipeline GPU_D12_nil_pipeline;
GPU_D12_Pipeline *GPU_D12_PipelineFromName(GPU_D12_PipelineScope *scope, String name);
void GPU_D12_RegisterPipeline(u64 num_pipelines, GPU_D12_Pipeline **pipelines);
W_CallbackFuncDef(GPU_D12_WatchPipelineCallback, name);
////////////////////////////////
//~ Descriptor
GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_CpuDescriptorHeap *dh);
void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor);
////////////////////////////////
//~ CPU descriptor heap
GPU_D12_CpuDescriptorHeap *GPU_D12_AcquireCpuDescriptorHeap(enum D3D12_DESCRIPTOR_HEAP_TYPE type);
////////////////////////////////
//~ Fenced release
void GPU_D12_ReleaseDataFenced(void *data, GPU_D12_FencedReleaseKind kind);
////////////////////////////////
//~ Resource
GPU_D12_Resource *GPU_D12_AcquireResource(D3D12_HEAP_PROPERTIES heap_props, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC desc, D3D12_RESOURCE_STATES initial_state);
void GPU_D12_ReleaseResourceNow(GPU_D12_Resource *t);
void GPU_ReleaseResourceFenced(GPU_Resource *resource);
////////////////////////////////
//~ Resource barrier
void GPU_D12_InsertBarrier(ID3D12GraphicsCommandList *cl, i32 num_descs, GPU_D12_ResourceBarrierDesc *descs);
////////////////////////////////
//~ Command queue
JobDecl(GPU_D12_AcquireCommandQueueJob, { GPU_D12_CommandQueueDesc *descs_in; GPU_D12_CommandQueue **cqs_out; });
void GPU_D12_ReleaseCommandQueue(GPU_D12_CommandQueue *cq);
////////////////////////////////
//~ Command list
GPU_D12_CommandListPool *GPU_D12_AcquireCommandListPool(GPU_D12_CommandQueue *cq);
GPU_D12_CommandList *GPU_D12_BeginCommandList(GPU_D12_CommandListPool *pool);
/* TODO: Allow multiple command list submissions */
u64 GPU_D12_EndCommandList(GPU_D12_CommandList *cl);
////////////////////////////////
//~ Command descriptor heap (GPU / shader visible descriptor heap)
GPU_D12_CommandDescriptorHeap *GPU_D12_PushDescriptorHeap(GPU_D12_CommandList *cl, GPU_D12_CpuDescriptorHeap *dh_cpu);
////////////////////////////////
//~ Command buffer
u64 GPU_D12_CommandBufferHashFromSize(u64 size);
#define GPU_D12_PushCommandBuffer(cl, count, elems) GPU_D12_PushCommandBufferEx((cl), count * ((elems) ? sizeof(*(elems)) : 0), (elems), (elems) ? sizeof(*(elems)) : 1)
GPU_D12_CommandBuffer *GPU_D12_PushCommandBufferEx(GPU_D12_CommandList *cl, u64 data_len, void *data, u64 data_stride);
////////////////////////////////
//~ Wait job
JobDecl(GPU_D12_WaitOnFenceJob, { ID3D12Fence *fence; u64 target; });
////////////////////////////////
//~ Upload
JobDecl(GPU_D12_UploadJob, { GPU_D12_Resource *resource; void *data; });
////////////////////////////////
//~ Run utils
void GPU_D12_SetPipeline(GPU_D12_CommandList *cl, GPU_D12_Pipeline *pipeline);
void GPU_D12_SetSig(GPU_D12_CommandList *cl, void *src, u32 size);
struct D3D12_VIEWPORT GPU_D12_ViewportFromRect(Rect r);
D3D12_RECT GPU_D12_ScissorRectFromRect(Rect r);
D3D12_VERTEX_BUFFER_VIEW GPU_D12_VbvFromCommandBuffer(GPU_D12_CommandBuffer *cb, u32 vertex_size);
D3D12_INDEX_BUFFER_VIEW GPU_D12_IbvFromCommandBuffer(GPU_D12_CommandBuffer *cb, DXGI_FORMAT format);
GPU_D12_Resource *GPU_D12_AcquireGbuff(DXGI_FORMAT format, Vec2I32 size, D3D12_RESOURCE_STATES initial_state);
D3D12_GPU_DESCRIPTOR_HANDLE GPU_D12_GpuHandleFromDescriptor(GPU_D12_Descriptor *descriptor, GPU_D12_CommandDescriptorHeap *cdh);
////////////////////////////////
//~ Render sig
GPU_D12_RenderSig *GPU_D12_AcquireRenderSig(void);
void GPU_D12_ResetRenderSig(GPU_D12_RenderSig *sig);
GPU_RenderSig *GPU_AcquireRenderSig(void);
////////////////////////////////
//~ Swapchain
void GPU_D12_InitSwapchainResources(GPU_D12_Swapchain *swapchain);
GPU_D12_SwapchainBuffer *GPU_D12_UpdateSwapchain(GPU_D12_Swapchain *swapchain, Vec2I32 resolution);
////////////////////////////////
//~ Present
void GPU_D12_BlitToSwapchain(GPU_D12_SwapchainBuffer *dst, GPU_D12_Resource *src, Xform src_xf);
////////////////////////////////
//~ Evictor job
JobDecl(GPU_D12_EvictorJob, EmptySig);

View File

@ -5,20 +5,14 @@
@Dep base
@Dep platform
@Dep tar
@Dep ase
@Dep dxc
@Dep inc
@Dep resource
@Dep watch
////////////////////////////////
//~ Api
@CpuApi gpu_core
@ApiC gpu_core
//- Dx12
@CpuApi dx12/gpu_dx12
@ApiCWindows dx12/gpu_dx12
////////////////////////////////
//~ Init

View File

@ -2,109 +2,262 @@
//~ Opaque types
Struct(GPU_Resource);
Struct(GPU_RenderSig);
Struct(GPU_CommandList);
Struct(GPU_VertexShader);
Struct(GPU_PixelShader);
Struct(GPU_ComputeShader);
Struct(GPU_Swapchain);
////////////////////////////////
//~ Render
//~ Queue types
Struct(GPU_Indices)
#define GPU_MultiQueueEnabled !ProfilingIsEnabled
typedef i32 GPU_QueueKind;
#if GPU_MultiQueueEnabled
# define GPU_QueueKind_Direct 0
# define GPU_QueueKind_Compute 1
# define GPU_QueueKind_Copy 2
# define GPU_QueueKind_BackgroundCopy 3
# define GPU_NumQueues 4
#else
# define GPU_QueueKind_Direct 0
# define GPU_QueueKind_Compute 0
# define GPU_QueueKind_Copy 0
# define GPU_QueueKind_BackgroundCopy 0
# define GPU_NumQueues 1
#endif
////////////////////////////////
//~ Format types
/* NOTE: Matches DXGI_FORMAT */
typedef i32 GPU_Format; enum
{
u32 count;
u32 *indices;
GPU_Format_Unknown = 0,
GPU_Format_R32G32B32A32_Typeless = 1,
GPU_Format_R32G32B32A32_Float = 2,
GPU_Format_R32G32B32A32_Uint = 3,
GPU_Format_R32G32B32A32_Sint = 4,
GPU_Format_R32G32B32_Typeless = 5,
GPU_Format_R32G32B32_Float = 6,
GPU_Format_R32G32B32_Uint = 7,
GPU_Format_R32G32B32_Sint = 8,
GPU_Format_R16G16B16A16_Typeless = 9,
GPU_Format_R16G16B16A16_Float = 10,
GPU_Format_R16G16B16A16_Unorm = 11,
GPU_Format_R16G16B16A16_Uint = 12,
GPU_Format_R16G16B16A16_Snorm = 13,
GPU_Format_R16G16B16A16_Sint = 14,
GPU_Format_R32G32_Typeless = 15,
GPU_Format_R32G32_Float = 16,
GPU_Format_R32G32_Uint = 17,
GPU_Format_R32G32_Sint = 18,
GPU_Format_R32G8X24_Typeless = 19,
GPU_Format_D32_Float_S8X24_Uint = 20,
GPU_Format_R32_Float_X8X24_Typeless = 21,
GPU_Format_X32_Typeless_G8X24_Uint = 22,
GPU_Format_R10G10B10A2_Typeless = 23,
GPU_Format_R10G10B10A2_Unorm = 24,
GPU_Format_R10G10B10A2_Uint = 25,
GPU_Format_R11G11B10_Float = 26,
GPU_Format_R8G8B8A8_Typeless = 27,
GPU_Format_R8G8B8A8_Unorm = 28,
GPU_Format_R8G8B8A8_Unorm_Srgb = 29,
GPU_Format_R8G8B8A8_Uint = 30,
GPU_Format_R8G8B8A8_Snorm = 31,
GPU_Format_R8G8B8A8_Sint = 32,
GPU_Format_R16G16_Typeless = 33,
GPU_Format_R16G16_Float = 34,
GPU_Format_R16G16_Unorm = 35,
GPU_Format_R16G16_Uint = 36,
GPU_Format_R16G16_Snorm = 37,
GPU_Format_R16G16_Sint = 38,
GPU_Format_R32_Typeless = 39,
GPU_Format_D32_Float = 40,
GPU_Format_R32_Float = 41,
GPU_Format_R32_Uint = 42,
GPU_Format_R32_Sint = 43,
GPU_Format_R24G8_Typeless = 44,
GPU_Format_D24_Unorm_S8_Uint = 45,
GPU_Format_R24_Unorm_X8_Typeless = 46,
GPU_Format_X24_Typeless_G8_Uint = 47,
GPU_Format_R8G8_Typeless = 48,
GPU_Format_R8G8_Unorm = 49,
GPU_Format_R8G8_Uint = 50,
GPU_Format_R8G8_Snorm = 51,
GPU_Format_R8G8_Sint = 52,
GPU_Format_R16_Typeless = 53,
GPU_Format_R16_Float = 54,
GPU_Format_D16_Unorm = 55,
GPU_Format_R16_Unorm = 56,
GPU_Format_R16_Uint = 57,
GPU_Format_R16_Snorm = 58,
GPU_Format_R16_Sint = 59,
GPU_Format_R8_Typeless = 60,
GPU_Format_R8_Unorm = 61,
GPU_Format_R8_Uint = 62,
GPU_Format_R8_Snorm = 63,
GPU_Format_R8_Sint = 64,
GPU_Format_A8_Unorm = 65,
GPU_Format_R1_Unorm = 66,
GPU_Format_R9G9B9E5_SharedXP = 67,
GPU_Format_R8G8_B8G8_Unorm = 68,
GPU_Format_G8R8_G8B8_Unorm = 69,
GPU_Format_BC1_Typeless = 70,
GPU_Format_BC1_Unorm = 71,
GPU_Format_BC1_Unorm_Srgb = 72,
GPU_Format_BC2_Typeless = 73,
GPU_Format_BC2_Unorm = 74,
GPU_Format_BC2_Unorm_Srgb = 75,
GPU_Format_BC3_Typeless = 76,
GPU_Format_BC3_Unorm = 77,
GPU_Format_BC3_Unorm_Srgb = 78,
GPU_Format_BC4_Typeless = 79,
GPU_Format_BC4_Unorm = 80,
GPU_Format_BC4_Snorm = 81,
GPU_Format_BC5_Typeless = 82,
GPU_Format_BC5_Unorm = 83,
GPU_Format_BC5_Snorm = 84,
GPU_Format_B5G6R5_Unorm = 85,
GPU_Format_B5G5R5A1_Unorm = 86,
GPU_Format_B8G8R8A8_Unorm = 87,
GPU_Format_B8G8R8X8_Unorm = 88,
GPU_Format_R10G10B10_XR_BIAS_A2_Unorm = 89,
GPU_Format_B8G8R8A8_Typeless = 90,
GPU_Format_B8G8R8A8_Unorm_Srgb = 91,
GPU_Format_B8G8R8X8_Typeless = 92,
GPU_Format_B8G8R8X8_Unorm_Srgb = 93,
GPU_Format_BC6H_Typeless = 94,
GPU_Format_BC6H_UF16 = 95,
GPU_Format_BC6H_SF16 = 96,
GPU_Format_BC7_Typeless = 97,
GPU_Format_BC7_Unorm = 98,
GPU_Format_BC7_Unorm_Srgb = 99,
GPU_Format_AYUV = 100,
GPU_Format_Y410 = 101,
GPU_Format_Y416 = 102,
GPU_Format_NV12 = 103,
GPU_Format_P010 = 104,
GPU_Format_P016 = 105,
GPU_Format_420_Opaque = 106,
GPU_Format_YUY2 = 107,
GPU_Format_Y210 = 108,
GPU_Format_Y216 = 109,
GPU_Format_NV11 = 110,
GPU_Format_AI44 = 111,
GPU_Format_IA44 = 112,
GPU_Format_P8 = 113,
GPU_Format_A8P8 = 114,
GPU_Format_B4G4R4A4_Unorm = 115,
GPU_Format_P208 = 130,
GPU_Format_V208 = 131,
GPU_Format_V408 = 132,
GPU_Format_SAMPLER_FEEDBACK_MIN_MIP_Opaque = 189,
GPU_Format_SAMPLER_FEEDBACK_MIP_REGION_USED_Opaque = 190,
GPU_Format_A4B4G4R4_Unorm = 191,
GPU_Format_Count = 192
};
typedef i32 GPU_RenderCmdKind; enum
{
GP_RENDER_CMD_KIND_NONE,
GP_RENDER_CMD_KIND_DRAW_MATERIAL,
GP_RENDER_CMD_KIND_DRAW_UI_RECT,
GP_RENDER_CMD_KIND_DRAW_UI_SHAPE,
GP_RENDER_CMD_KIND_PUSH_GRID,
////////////////////////////////
//~ Resource types
NUM_GP_RENDER_CMD_KINDS
typedef i32 GPU_ResourceKind; enum
{
GPU_ResourceKind_Unknown,
GPU_ResourceKind_Buffer,
GPU_ResourceKind_Texture1D,
GPU_ResourceKind_Texture2D,
GPU_ResourceKind_Texture3D,
GPU_ResourceKind_Sampler
};
Struct(GPU_RenderCmdDesc)
typedef i32 GPU_ResourceFlag; enum
{
GPU_RenderCmdKind kind;
GPU_ResourceFlag_None = 0,
GPU_ResourceFlag_AllowSrv = (1 << 0),
GPU_ResourceFlag_AllowUav = (1 << 1),
GPU_ResourceFlag_AllowRtv = (1 << 2)
};
typedef i32 GPU_HeapKind; enum
{
GPU_HeapKind_Default,
GPU_HeapKind_Upload,
GPU_HeapKind_Download
};
typedef i32 GPU_ReleaseFlag; enum
{
GPU_ReleaseFlag_None = 0,
GPU_ReleaseFlag_Reuse = (1 << 0)
};
Struct(GPU_ResourceDesc)
{
GPU_ResourceKind kind;
GPU_ResourceFlag flags;
union
{
struct
{
Xform xf;
GPU_Resource *texture;
ClipRect clip;
u32 tint;
b32 is_light;
Vec3 light_emittance;
u32 grid_cmd_id;
} material;
GPU_Format format;
Vec3I32 size;
i32 mip_levels;
} texture;
struct
{
Xform xf;
GPU_Resource *texture;
ClipRect clip;
u32 tint;
} ui_rect;
struct
{
Vec2Array vertices;
GPU_Indices indices;
u32 color;
} ui_shape;
struct
{
f32 line_thickness;
f32 line_spacing;
Vec2 offset;
u32 bg0_color;
u32 bg1_color;
u32 line_color;
u32 x_color;
u32 y_color;
} grid;
GPU_HeapKind heap_kind;
u32 size;
u32 element_count;
u32 element_size;
} buffer;
};
};
Struct(GPU_RenderParams)
{
Vec2I32 ui_size;
Vec2I32 render_size;
Xform world_to_render_xf;
Xform render_to_ui_xf;
b32 effects_disabled;
};
////////////////////////////////
//~ Texture
//~ Shader types
typedef i32 GPU_TextureFormat; enum
Struct(GPU_ShaderDesc)
{
GP_TEXTURE_FORMAT_NONE,
GP_TEXTURE_FORMAT_R8_UNORM,
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM,
GP_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB,
GP_TEXTURE_FORMAT_R16G16B16A16_FLOAT,
NUM_GP_TEXTURE_FORMATS
char *shader_id;
};
typedef i32 GPU_TextureFlag; enum
#define GPU_ShaderDecl(name) static GPU_ShaderDesc name = { .shader_id = #name }
////////////////////////////////
//~ Rasterizer types
typedef i32 GPU_RasterizeMode; enum
{
GP_TEXTURE_FLAG_NONE = 0,
GP_TEXTURE_FLAG_TARGETABLE = (1 << 0)
GPU_RasterizeMode_None,
GPU_RasterizeMode_TriangleList
};
Struct(GPU_Viewport)
{
i32 _;
};
Struct(GPU_Scissor)
{
i32 _;
};
////////////////////////////////
//~ Memory info
//~ Fence types
Struct(GPU_Fence)
{
u64 targets[GPU_NumQueues];
u32 num_targets;
};
////////////////////////////////
//~ Memory info types
Struct(GPU_MemoryInfo)
{
u64 local_used;
u64 local_budget;
u64 non_local_used;
u64 non_local_budget;
i32 _;
};
////////////////////////////////
@ -112,50 +265,85 @@ Struct(GPU_MemoryInfo)
void GPU_StartupCore(void);
////////////////////////////////
//~ Rasterizer helpers
GPU_Viewport GPU_ViewportFromRect(Rect rect);
GPU_Scissor GPU_ScissorFromRect(Rect rect);
////////////////////////////////
//~ Fence operations
GPU_Fence GPU_GetGlobalFence(void);
////////////////////////////////
//~ Resource operations
/* NOTE: Internally, the layer will make sure to not release any resources
* until after any in-flight GPU runs finish using them. However, it is up to
* the caller to make sure the released resources aren't then referenced in
* any runs
*/
void GPU_ReleaseResourceFenced(GPU_Resource *resource);
GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc);
void GPU_ReleaseResource(GPU_Resource *resource, GPU_Fence fence, GPU_ReleaseFlag flags);
u32 GPU_GetResourceId(GPU_Resource *resource);
Vec2I32 GPU_GetTextureSize(GPU_Resource *resource);
////////////////////////////////
//~ Texture operations
//~ Command list operations
GPU_Resource *GPU_AcquireTexture(GPU_TextureFormat format, u32 flags, Vec2I32 size, void *initial_data);
GPU_CommandList *GPU_BeginCommandList(void);
GPU_Fence GPU_EndCommandList(GPU_CommandList *cl);
Vec2I32 GPU_GetTextureSize(GPU_Resource *texture);
void GPU_ProfileDF(GPU_CommandList *cl, String zone_name);
////////////////////////////////
//~ Render operations
//~ Resource transition operations
GPU_RenderSig *GPU_AcquireRenderSig(void);
/* Returns a cmd id internal to the sig */
u32 GPU_PushRenderCmd(GPU_RenderSig *render_sig, GPU_RenderCmdDesc *desc);
GPU_Resource *GPU_RunRender(GPU_RenderSig *gp_render_sig, GPU_RenderParams render_params);
void GPU_TransitionToSrv(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_TransitionToUav(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_TransitionToRtv(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_Flush(GPU_CommandList *cl, GPU_Resource *resource);
////////////////////////////////
//~ Memory query
//~ Dispatch operations
void GPU_DispatchClear(GPU_CommandList *cl, GPU_Resource *resource);
void GPU_DispatchRasterize(GPU_CommandList *cl,
GPU_ShaderDesc vs,
GPU_ShaderDesc ps,
void *sig,
u32 rts_count,
GPU_Resource **rts,
u32 viewports_count,
GPU_Viewport *viewports,
u32 scissors_count,
GPU_Scissor *scissors,
u32 instances_count,
GPU_Resource *index_buffer,
GPU_RasterizeMode mode);
void GPU_DispatchCompute(GPU_CommandList *cl, GPU_ShaderDesc cs, void *sig, u32 num_threads_x, u32 num_threads_y, u32 num_threads_z);
////////////////////////////////
//~ Resource copy operations
void GPU_PushResource(GPU_CommandList *cl, GPU_Resource *dst, GPU_Resource *src);
void GPU_PushString(GPU_CommandList *cl, GPU_Resource *dst, String src);
////////////////////////////////
//~ Memory info operations
GPU_MemoryInfo GPU_QueryMemoryInfo(void);
////////////////////////////////
//~ Swapchain
//~ Swapchain operations
GPU_Swapchain *GPU_AcquireSwapchain(P_Window *window, Vec2I32 resolution);
void GPU_ReleaseSwapchain(GPU_Swapchain *gp_swapchain);
GPU_Swapchain *GPU_AcquireSwapchain(P_Window *window, Vec2I32 size);
void GPU_ReleaseSwapchain(GPU_Swapchain *swapchain);
/* Waits until a new backbuffer is ready to be written to.
* This should be called before rendering for minimum latency. */
void GPU_WaitOnSwapchain(GPU_Swapchain *gp_swapchain);
void GPU_WaitOnSwapchain(GPU_Swapchain *swapchain);
/* 1. Clears the backbuffer and ensures it's at size `backbuffer_resolution`
* 2. Blits `texture` to the backbuffer using `texture_xf`
* 3. Presents the backbuffer */
void GPU_PresentSwapchain(GPU_Swapchain *gp_swapchain, Vec2I32 backbuffer_resolution, GPU_Resource *texture, Xform texture_xf, i32 vsync);
void GPU_PresentSwapchain(GPU_Swapchain *swapchain, Vec2I32 backbuffer_resolution, GPU_Resource *texture, Xform texture_xf, i32 vsync);

View File

@ -1,206 +0,0 @@
////////////////////////////////
//~ @hookdef Startup hook
void GT_StartupCore(void)
{
}
////////////////////////////////
//~ @hookdef Rasterizer helper hooks
GT_Viewport GT_ViewportFromRect(Rect rect)
{
LAX rect;
return (GT_Viewport) ZI;
}
GT_Scissor GT_ScissorRectFromRect(Rect rect)
{
LAX rect;
return (GT_Scissor) ZI;
}
////////////////////////////////
//~ @hookdef Fence hooks
GT_Fence GT_GetGlobalFence(void)
{
return (GT_Fence) ZI;
}
////////////////////////////////
//~ @hookdef Resource hooks
GT_Resource *GT_AcquireResource(GT_ResourceDesc desc)
{
LAX desc;
return (GT_Resource *)0;
}
void GT_ReleaseResource(GT_Resource *resource, GT_Fence fence, GT_ReleaseFlag flags)
{
LAX resource;
LAX fence;
LAX flags;
}
u32 GT_GetResourceId(GT_Resource *resource)
{
LAX resource;
return 0;
}
Vec2I32 GT_GetTextureSize(GT_Resource *resource)
{
LAX resource;
return VEC2I32(0, 0);
}
////////////////////////////////
//~ @hookdef Command list hooks
GT_CommandList *GT_BeginCommandList(void)
{
return 0;
}
GT_Fence GT_EndCommandList(GT_CommandList *cl)
{
LAX cl;
return (GT_Fence) ZI;
}
void GT_ProfileDF(GT_CommandList *cl, String zone_name)
{
LAX cl;
LAX zone_name;
}
////////////////////////////////
//~ @hookdef Resource transition hooks
void GT_TransitionToSrv(GT_CommandList *cl, GT_Resource *resource)
{
LAX cl;
LAX resource;
}
void GT_TransitionToUav(GT_CommandList *cl, GT_Resource *resource)
{
LAX cl;
LAX resource;
}
void GT_TransitionToRtv(GT_CommandList *cl, GT_Resource *resource)
{
LAX cl;
LAX resource;
}
void GT_Flush(GT_CommandList *cl, GT_Resource *resource)
{
LAX cl;
LAX resource;
}
////////////////////////////////
//~ @hookdef Dispatch hooks
void GT_DispatchClear(GT_CommandList *cl, GT_Resource *resource)
{
LAX cl;
LAX resource;
}
void GT_DispatchRasterize(GT_CommandList *cl,
GT_ShaderDesc vs,
GT_ShaderDesc ps,
void *sig,
u32 rts_count,
GT_Resource **rts,
u32 viewports_count,
GT_Viewport *viewports,
u32 scissors_count,
GT_Scissor *scissors,
u32 instances_count,
GT_Resource *index_buffer,
GT_RasterizeMode mode)
{
LAX cl;
LAX vs;
LAX ps;
LAX sig;
LAX rts_count;
LAX rts;
LAX viewports_count;
LAX *viewports;
LAX scissors_count;
LAX scissors;
LAX instances_count;
LAX index_buffer;
LAX mode;
}
void GT_DispatchCompute(GT_CommandList *cl, GT_ShaderDesc cs, void *sig, u32 num_threads_x, u32 num_threads_y, u32 num_threads_z)
{
LAX cl;
LAX cs;
LAX sig;
LAX num_threads_x;
LAX num_threads_y;
LAX num_threads_z;
}
////////////////////////////////
//~ @hookdef Copy hooks
void GT_PushResource(GT_CommandList *cl, GT_Resource *dst, GT_Resource *src)
{
LAX cl;
LAX dst;
LAX src;
}
void GT_PushString(GT_CommandList *cl, GT_Resource *dst, String src)
{
LAX cl;
LAX dst;
LAX src;
}
////////////////////////////////
//~ @hookdef Memory info hooks
GT_MemoryInfo GT_QueryMemoryInfo(void)
{
return (GT_MemoryInfo) ZI;
}
////////////////////////////////
//~ @hookdef Swapchain hooks
GT_Swapchain *GT_AcquireSwapchain(P_Window *window, Vec2I32 size)
{
LAX window;
LAX size;
return 0;
}
void GT_ReleaseSwapchain(GT_Swapchain *swapchain)
{
LAX swapchain;
}
void GT_WaitOnSwapchain(GT_Swapchain *swapchain)
{
LAX swapchain;
}
void GT_PresentSwapchain(GT_Swapchain *swapchain, Vec2I32 backbuffer_resolution, GT_Resource *texture, Xform texture_xf, i32 vsync)
{
LAX swapchain;
LAX backbuffer_resolution;
LAX texture;
LAX texture_xf;
LAX vsync;
}

View File

@ -1,20 +0,0 @@
@Layer gtest
////////////////////////////////
//~ Dependencies
@Dep base
@Dep platform
////////////////////////////////
//~ Api
@CpuApi gtest_core
//- Dx12
@CpuApiWindows dx12/gtest_dx12
////////////////////////////////
//~ Init
@Init GT_StartupCore

View File

@ -1,349 +0,0 @@
////////////////////////////////
//~ Opaque types
Struct(GT_Resource);
Struct(GT_CommandList);
Struct(GT_VertexShader);
Struct(GT_PixelShader);
Struct(GT_ComputeShader);
Struct(GT_Swapchain);
////////////////////////////////
//~ Queue types
#define GT_MultiQueueEnabled !ProfilingIsEnabled
typedef i32 GT_QueueKind;
#if GT_MultiQueueEnabled
# define GT_QueueKind_Direct 0
# define GT_QueueKind_Compute 1
# define GT_QueueKind_Copy 2
# define GT_QueueKind_BackgroundCopy 3
# define GT_NumQueues 4
#else
# define GT_QueueKind_Direct 0
# define GT_QueueKind_Compute 0
# define GT_QueueKind_Copy 0
# define GT_QueueKind_BackgroundCopy 0
# define GT_NumQueues 1
#endif
////////////////////////////////
//~ Format types
/* NOTE: Matches DXGI_FORMAT */
typedef i32 GT_Format; enum
{
GT_Format_Unknown = 0,
GT_Format_R32G32B32A32_Typeless = 1,
GT_Format_R32G32B32A32_Float = 2,
GT_Format_R32G32B32A32_Uint = 3,
GT_Format_R32G32B32A32_Sint = 4,
GT_Format_R32G32B32_Typeless = 5,
GT_Format_R32G32B32_Float = 6,
GT_Format_R32G32B32_Uint = 7,
GT_Format_R32G32B32_Sint = 8,
GT_Format_R16G16B16A16_Typeless = 9,
GT_Format_R16G16B16A16_Float = 10,
GT_Format_R16G16B16A16_Unorm = 11,
GT_Format_R16G16B16A16_Uint = 12,
GT_Format_R16G16B16A16_Snorm = 13,
GT_Format_R16G16B16A16_Sint = 14,
GT_Format_R32G32_Typeless = 15,
GT_Format_R32G32_Float = 16,
GT_Format_R32G32_Uint = 17,
GT_Format_R32G32_Sint = 18,
GT_Format_R32G8X24_Typeless = 19,
GT_Format_D32_Float_S8X24_Uint = 20,
GT_Format_R32_Float_X8X24_Typeless = 21,
GT_Format_X32_Typeless_G8X24_Uint = 22,
GT_Format_R10G10B10A2_Typeless = 23,
GT_Format_R10G10B10A2_Unorm = 24,
GT_Format_R10G10B10A2_Uint = 25,
GT_Format_R11G11B10_Float = 26,
GT_Format_R8G8B8A8_Typeless = 27,
GT_Format_R8G8B8A8_Unorm = 28,
GT_Format_R8G8B8A8_Unorm_Srgb = 29,
GT_Format_R8G8B8A8_Uint = 30,
GT_Format_R8G8B8A8_Snorm = 31,
GT_Format_R8G8B8A8_Sint = 32,
GT_Format_R16G16_Typeless = 33,
GT_Format_R16G16_Float = 34,
GT_Format_R16G16_Unorm = 35,
GT_Format_R16G16_Uint = 36,
GT_Format_R16G16_Snorm = 37,
GT_Format_R16G16_Sint = 38,
GT_Format_R32_Typeless = 39,
GT_Format_D32_Float = 40,
GT_Format_R32_Float = 41,
GT_Format_R32_Uint = 42,
GT_Format_R32_Sint = 43,
GT_Format_R24G8_Typeless = 44,
GT_Format_D24_Unorm_S8_Uint = 45,
GT_Format_R24_Unorm_X8_Typeless = 46,
GT_Format_X24_Typeless_G8_Uint = 47,
GT_Format_R8G8_Typeless = 48,
GT_Format_R8G8_Unorm = 49,
GT_Format_R8G8_Uint = 50,
GT_Format_R8G8_Snorm = 51,
GT_Format_R8G8_Sint = 52,
GT_Format_R16_Typeless = 53,
GT_Format_R16_Float = 54,
GT_Format_D16_Unorm = 55,
GT_Format_R16_Unorm = 56,
GT_Format_R16_Uint = 57,
GT_Format_R16_Snorm = 58,
GT_Format_R16_Sint = 59,
GT_Format_R8_Typeless = 60,
GT_Format_R8_Unorm = 61,
GT_Format_R8_Uint = 62,
GT_Format_R8_Snorm = 63,
GT_Format_R8_Sint = 64,
GT_Format_A8_Unorm = 65,
GT_Format_R1_Unorm = 66,
GT_Format_R9G9B9E5_SharedXP = 67,
GT_Format_R8G8_B8G8_Unorm = 68,
GT_Format_G8R8_G8B8_Unorm = 69,
GT_Format_BC1_Typeless = 70,
GT_Format_BC1_Unorm = 71,
GT_Format_BC1_Unorm_Srgb = 72,
GT_Format_BC2_Typeless = 73,
GT_Format_BC2_Unorm = 74,
GT_Format_BC2_Unorm_Srgb = 75,
GT_Format_BC3_Typeless = 76,
GT_Format_BC3_Unorm = 77,
GT_Format_BC3_Unorm_Srgb = 78,
GT_Format_BC4_Typeless = 79,
GT_Format_BC4_Unorm = 80,
GT_Format_BC4_Snorm = 81,
GT_Format_BC5_Typeless = 82,
GT_Format_BC5_Unorm = 83,
GT_Format_BC5_Snorm = 84,
GT_Format_B5G6R5_Unorm = 85,
GT_Format_B5G5R5A1_Unorm = 86,
GT_Format_B8G8R8A8_Unorm = 87,
GT_Format_B8G8R8X8_Unorm = 88,
GT_Format_R10G10B10_XR_BIAS_A2_Unorm = 89,
GT_Format_B8G8R8A8_Typeless = 90,
GT_Format_B8G8R8A8_Unorm_Srgb = 91,
GT_Format_B8G8R8X8_Typeless = 92,
GT_Format_B8G8R8X8_Unorm_Srgb = 93,
GT_Format_BC6H_Typeless = 94,
GT_Format_BC6H_UF16 = 95,
GT_Format_BC6H_SF16 = 96,
GT_Format_BC7_Typeless = 97,
GT_Format_BC7_Unorm = 98,
GT_Format_BC7_Unorm_Srgb = 99,
GT_Format_AYUV = 100,
GT_Format_Y410 = 101,
GT_Format_Y416 = 102,
GT_Format_NV12 = 103,
GT_Format_P010 = 104,
GT_Format_P016 = 105,
GT_Format_420_Opaque = 106,
GT_Format_YUY2 = 107,
GT_Format_Y210 = 108,
GT_Format_Y216 = 109,
GT_Format_NV11 = 110,
GT_Format_AI44 = 111,
GT_Format_IA44 = 112,
GT_Format_P8 = 113,
GT_Format_A8P8 = 114,
GT_Format_B4G4R4A4_Unorm = 115,
GT_Format_P208 = 130,
GT_Format_V208 = 131,
GT_Format_V408 = 132,
GT_Format_SAMPLER_FEEDBACK_MIN_MIP_Opaque = 189,
GT_Format_SAMPLER_FEEDBACK_MIP_REGION_USED_Opaque = 190,
GT_Format_A4B4G4R4_Unorm = 191,
GT_Format_Count = 192
};
////////////////////////////////
//~ Resource types
typedef i32 GT_ResourceKind; enum
{
GT_ResourceKind_Unknown,
GT_ResourceKind_Buffer,
GT_ResourceKind_Texture1D,
GT_ResourceKind_Texture2D,
GT_ResourceKind_Texture3D,
GT_ResourceKind_Sampler
};
typedef i32 GT_ResourceFlag; enum
{
GT_ResourceFlag_None = 0,
GT_ResourceFlag_AllowSrv = (1 << 0),
GT_ResourceFlag_AllowUav = (1 << 1),
GT_ResourceFlag_AllowRtv = (1 << 2)
};
typedef i32 GT_HeapKind; enum
{
GT_HeapKind_Default,
GT_HeapKind_Upload,
GT_HeapKind_Download
};
typedef i32 GT_ReleaseFlag; enum
{
GT_ReleaseFlag_None = 0,
GT_ReleaseFlag_Reuse = (1 << 0)
};
Struct(GT_ResourceDesc)
{
GT_ResourceKind kind;
GT_ResourceFlag flags;
union
{
struct
{
GT_Format format;
Vec3I32 size;
i32 mip_levels;
} texture;
struct
{
GT_HeapKind heap_kind;
u32 size;
u32 element_count;
u32 element_size;
} buffer;
};
};
////////////////////////////////
//~ Shader types
Struct(GT_ShaderDesc)
{
char *shader_id;
};
#define GT_ShaderDecl(name) static GT_ShaderDesc name = { .shader_id = #name }
////////////////////////////////
//~ Rasterizer types
typedef i32 GT_RasterizeMode; enum
{
GT_RasterizeMode_None,
GT_RasterizeMode_TriangleList
};
Struct(GT_Viewport)
{
i32 _;
};
Struct(GT_Scissor)
{
i32 _;
};
////////////////////////////////
//~ Fence types
Struct(GT_Fence)
{
u64 targets[GT_NumQueues];
u32 num_targets;
};
////////////////////////////////
//~ Memory info types
Struct(GT_MemoryInfo)
{
i32 _;
};
////////////////////////////////
//~ Startup
void GT_StartupCore(void);
////////////////////////////////
//~ Rasterizer helpers
GT_Viewport GT_ViewportFromRect(Rect rect);
GT_Scissor GT_ScissorRectFromRect(Rect rect);
////////////////////////////////
//~ Fence operations
GT_Fence GT_GetGlobalFence(void);
////////////////////////////////
//~ Resource operations
GT_Resource *GT_AcquireResource(GT_ResourceDesc desc);
void GT_ReleaseResource(GT_Resource *resource, GT_Fence fence, GT_ReleaseFlag flags);
u32 GT_GetResourceId(GT_Resource *resource);
Vec2I32 GT_GetTextureSize(GT_Resource *resource);
////////////////////////////////
//~ Command list operations
GT_CommandList *GT_BeginCommandList(void);
GT_Fence GT_EndCommandList(GT_CommandList *cl);
void GT_ProfileDF(GT_CommandList *cl, String zone_name);
////////////////////////////////
//~ Resource transition operations
void GT_TransitionToSrv(GT_CommandList *cl, GT_Resource *resource);
void GT_TransitionToUav(GT_CommandList *cl, GT_Resource *resource);
void GT_TransitionToRtv(GT_CommandList *cl, GT_Resource *resource);
void GT_Flush(GT_CommandList *cl, GT_Resource *resource);
////////////////////////////////
//~ Dispatch operations
void GT_DispatchClear(GT_CommandList *cl, GT_Resource *resource);
void GT_DispatchRasterize(GT_CommandList *cl,
GT_ShaderDesc vs,
GT_ShaderDesc ps,
void *sig,
u32 rts_count,
GT_Resource **rts,
u32 viewports_count,
GT_Viewport *viewports,
u32 scissors_count,
GT_Scissor *scissors,
u32 instances_count,
GT_Resource *index_buffer,
GT_RasterizeMode mode);
void GT_DispatchCompute(GT_CommandList *cl, GT_ShaderDesc cs, void *sig, u32 num_threads_x, u32 num_threads_y, u32 num_threads_z);
////////////////////////////////
//~ Resource copy operations
void GT_PushResource(GT_CommandList *cl, GT_Resource *dst, GT_Resource *src);
void GT_PushString(GT_CommandList *cl, GT_Resource *dst, String src);
////////////////////////////////
//~ Memory info operations
GT_MemoryInfo GT_QueryMemoryInfo(void);
////////////////////////////////
//~ Swapchain operations
GT_Swapchain *GT_AcquireSwapchain(P_Window *window, Vec2I32 size);
void GT_ReleaseSwapchain(GT_Swapchain *swapchain);
/* Waits until a new backbuffer is ready to be written to.
* This should be called before rendering for minimum latency. */
void GT_WaitOnSwapchain(GT_Swapchain *swapchain);
/* 1. Clears the backbuffer and ensures it's at size `backbuffer_resolution`
* 2. Blits `texture` to the backbuffer using `texture_xf`
* 3. Presents the backbuffer */
void GT_PresentSwapchain(GT_Swapchain *swapchain, Vec2I32 backbuffer_resolution, GT_Resource *texture, Xform texture_xf, i32 vsync);

View File

@ -8,4 +8,4 @@
////////////////////////////////
//~ Api
@CpuApi inc_core
@ApiC inc_core

View File

@ -8,4 +8,4 @@
////////////////////////////////
//~ Api
@CpuApi json_core
@ApiC json_core

View File

@ -8,5 +8,5 @@
////////////////////////////////
//~ Api
@CpuApi kernel_core
@GpuApi kernel_core
@ApiC kernel_core
@ApiGpu kernel_core

View File

@ -1,5 +1,5 @@
/* Determine if file was included from C or from HLSL */
#if !LanguageIsGpu
#if LanguageIsC
# define K_IS_CPU 1
#else
# define K_IS_CPU 0

View File

@ -52,21 +52,411 @@ i32 main(i32 argc, u8 **argv)
Arena *arena = AcquireArena(Gibi(64));
//- Unpack args
StringList args = ZI;
StringList exe_layer_names = ZI;
StringList args = ZI;
i32 hyphens = 0;
for (i32 i = 1; i < argc; ++i)
{
String arg = StringFromCstrNoLimit(argv[i]);
if (EndsWith(arg, Lit(".exe")))
if (EqString(arg, Lit("-"))
{
String layer_name = TrimRight(arg, Lit(".exe"));
PushStringToList(arena, layer_name);
++hyphens;
}
else
{
PushStringToList(arena, &args, arg);
if (hyphens == 0)
{
PushStringToList(perm, &exe_layer_names, arg);
}
else
{
PushStringToList(perm, &args, arg);
}
}
}
StringList lay_dirs = ZI;
PushStringToList(perm, &lay_dirs, Lit("src"));
LayResult lay_result = ParseLay(lay_dirs, exe_layer_names);
// Things to do:
// - For each leaf layer:
// - Walk deps to determine all layers that must be built
for (
for (StringListNode *n = exe_layer_names; n; n = n->next)
{
String name = n->s;
Lay *lay = LayFromName(name);
for (LayItem *dep_objs
Run("cl.exe obj_files out_path");
}
for (StringListNode *n = exe_layer_names.first; n; n = n->next)
{
String name = n->s;
Lay *lay = LayFromName(name);
Dict *visited_dict = InitDict(arena, 64);
u64 level = 1;
for (LayEntry *dep = lay->deps.first; dep; dep = dep->next)
{
String dep_name = dep->name;
u64 dep_hash = dep->name_hash;
SetDictValue(visited_dict, dep_hash, level);
// Lay *dep_lay = LayFromName(dep_name);
}
}
for (LayNode *leaf_lay_node = leaf_lays.first; leaf_lay_node; leaf_lay_node = leaf_lay_node->next)
{
Lay *lay = leaf_lay_node->l;
String name = lay->name;
for (LayNode *dep_node = lay->deps.first;
}
for (StringListNode *n = obj_files.first; n; n = n->next)
{
String file = n->s;
String cmd = StringF("cl.exe /c /Zi /DEBUG %F", file);
}
for (StringListNode *n = gpu_code_files.first; n; n = n->next)
{
}
#if 0
StringList src_files;
FilesFromDir(arena, &src_files, Lit("src"), FileIterFlag_Recurse);
//- Parse layer files in source directory
Dict *lay_info_dict = InitDict(arena, 1024);
for (StringListNode *n = src_files.first; n; n = n->next)
{
String file = n->s;
String extension = GetFileExtension(name);
if (MatchString(extension, Lit("lay"))
{
String file_data = StringFromFile(arena, file);
LayInfo *lay_info = PushStruct(arena, LayInfo);
*lay_info = LayInfoFromString(arena, file_data);
u64 hash = HashFnv64(Fnv64Basis, lay_info->name);
SetDictValue(lay_info_dict, hash, lay_info);
}
}
for (DictEntry *e = lay_info_dict->first; e; e = e->next)
{
LayInfo *lay_info = (LayInfo *)e->value;
}
for (MetaNode *layer_node = layers.first; layer_node; layer_node = layer_node->next)
{
b32 has_cpu_code = 0;
b32 has_gpu_code = 0;
Meta *layer = layer_node->m;
StringList cpu_api_header_files = ZI;
StringList gpu_api_header_files = ZI;
StringList c_api_code_files = ZI;
StringList cpp_api_code_files = ZI;
StringList gpu_api_code_files = ZI;
for (MetaNode *api_node = layer->apis.first; api_node; api_node = api_node->next)
{
Meta *api = api_node->m;
String api_name = api->name;
String h_file = StringF(arena, "%F.h", FmtStr(api_name));
String c_file = StringF(arena, "%F.c", FmtStr(api_name));
String cpp_file = StringF(arena, "%F.cpp", FmtStr(api_name));
String gpu_file = StringF(arena, "%F.gpu", FmtStr(api_name));
if (FileExists(h_file))
{
if (api->api_kind == MetaApiKind_Cpu)
{
PushStringToList(arena, &cpu_api_header_files, h_file);
}
else if (api->api_kind == MetaApiKind_Gpu)
{
PushStringToList(arena, &gpu_api_header_files, h_file);
}
}
if (FileExists(c_file))
{
PushStringToList(arena, &c_api_code_files, c_file);
has_cpu_code = 1;
}
if (FileExists(cpp_file))
{
PushStringToList(arena, &cpp_api_code_files, cpp_file);
has_cpu_code = 1;
}
if (FileExists(gpu_file))
{
PushStringToList(arena, &gpu_api_code_files, gpu_file);
has_gpu_code = 1;
}
}
StringList cpu_dep_header_files = ZI;
StringList gpu_dep_header_files = ZI;
if (has_cpu_code || has_gpu_code)
{
for (MetaNode *dep_node = layer->deps.first; dep_node; dep_node = dep_node->next)
{
MetaNode *dep = dep_node->m;
String dep_name = dep->name;
}
}
}
#endif
#if 0
//- Build tree
String graph_file = ZI;
if (args.first)
{
graph_file = args.first->s;
}
MetaTree *tree = MetaTreeFromFile(graph_file);
Rm("build/layers");
Mkdir("build/layers");
StringList init_funcs = ZI;
for (MetaNode *layer = tree->first_layer; layer; layer = layer->next)
{
StringList cpu_header_files = ZI;
StringList gpu_header_files = ZI;
StringList c_files = ZI;
StringList cpp_files = ZI;
StringList gpu_files = ZI;
for (MetaNode *api = layer->first_api; api; api = api->next)
{
String api_name = api->name;
String h_file = StringF(arena, "%F.h", FmtStr(api_name));
String c_file = StringF(arena, "%F.c", FmtStr(api_name));
String cpp_file = StringF(arena, "%F.cpp", FmtStr(api_name));
String gpu_file = StringF(arena, "%F.gpu", FmtStr(api_name));
if (FileExists(h_file))
{
if (api->api_kind == MetaApiKind_Cpu)
{
PushStringToList(arena, &cpu_header_files, h_file);
}
else if (api->api_kind == MetaApiKind_Gpu)
{
PushStringToList(arena, &gpu_header_files, h_file);
}
}
if (FileExists(c_file)) PushStringToList(arena, &c_files, c_file);
if (FileExists(cpp_file)) PushStringToList(arena, &cpp_files, cpp_file);
if (FileExists(gpu_file)) PushStringToList(arena, &gpu_files, gpu_file);
}
StringList cpu_dep_files = ZI;
StringList gpu_dep_files = ZI;
for (MetaNode *dep = layer->first_dep; dep; dep = dep->next)
{
String dep_name = dep->name;
if (dep->has_cpu_api)
{
String cpu_dep_file = StringF(arena, "%F__cpu_api.h", FmtStr(dep_name));
PushStringToList(arena, &cpu_dep_files, cpu_dep_file);
}
if (dep->has_gpu_api)
{
String gpu_dep_file = StringF(arena, "%F__gpu_api.h", FmtStr(dep_name));
PushStringToList(arena, &gpu_dep_files, gpu_dep_file);
}
}
StringList cpu_header_lines = ZI;
StringList gpu_header_lines = ZI;
StringList c_code_lines = ZI;
StringList cpp_code_lines = ZI;
StringList gpu_code_lines = ZI;
//- Cpu header file
{
PushStringNodeF(arena, &cpu_header_lines, "// Auto generated Cpu layer header file");
PushStringNodeF(arena, &cpu_header_lines, "////////////////////////////////\n//~ Api header includes");
for (StringListNode *n = cpu_header_files.first; n; n = n->next)
{
String line = StringF(arena, "#include <%F>", FmtStr(n->s));
PushStringToList(arena, &cpu_header_lines, line);
}
}
//- Gpu header file
{
PushStringNodeF(arena, &gpu_header_lines, "// Auto generated Gpu layer header file");
PushStringNodeF(arena, &gpu_header_lines, "////////////////////////////////\n//~ Api header includes");
for (StringListNode *n = gpu_header_files.first; n; n = n->next)
{
String line = StringF(arena, "#include <%F>", FmtStr(n->s));
PushStringToList(arena, &gpu_header_lines, line);
}
}
//- C code file
{
PushStringNodeF(arena, &c_code_lines, "// Auto generated C layer code file");
PushStringNodeF(arena, &c_code_lines, "////////////////////////////////\n//~ Layer dependency includes");
for (StringListNode *n = cpu_dep_files.first; n; n = n->next)
{
String line = StringF(arena, "#include <%F>", FmtStr(n->s));
PushStringToList(arena, &c_code_lines, line);
}
PushStringNodeF(arena, &c_code_lines, "////////////////////////////////\n//~ Api code includes");
for (StringListNode *n = c_files.first; n; n = n->next)
{
String line = StringF(arena, "#include <%F>", FmtStr(n->s));
PushStringToList(arena, &c_code_lines, line);
}
}
//- Gpu code file
{
PushStringNodeF(arena, &gpu_code_lines, "// Auto generated Gpu layer code file");
PushStringNodeF(arena, &c_code_lines, "////////////////////////////////\n//~ Layer dependency includes");
for (StringListNode *n = gpu_dep_files.first; n; n = n->next)
{
String line = StringF(arena, "#include <%F>", FmtStr(n->s));
PushStringToList(arena, &gpu_code_lines, line);
}
PushStringNodeF(arena, &gpu_code_lines, "////////////////////////////////\n//~ Api code includes");
for (StringListNode *n = gpu_files.first; n; n = n->next)
{
String line = StringF(arena, "#include <%F>", FmtStr(n->s));
PushStringToList(arena, &gpu_code_lines, line);
}
}
// {
// String init_name = init->name;
// PushStringToList(arena, init_funcs, init_name);
// }
// full_path = n->full_path;
// String line = StringF(arena, "#include <%F>", full_path);
// PushStringToList(arena, &gen_lines, line);
}
#endif
return 0;
}

View File

@ -14,7 +14,8 @@ Struct(Arena)
#endif
};
Struct(TempArena) {
Struct(TempArena)
{
Arena *arena;
u64 start_pos;
@ -118,16 +119,22 @@ void SetArenaReadWrite(Arena *arena);
Inline void *AlignArena(Arena *arena, u64 align)
{
Assert(!arena->readonly);
if (align > 0) {
if (align > 0)
{
u64 aligned_start_pos = (arena->pos + (align - 1));
aligned_start_pos -= aligned_start_pos % align;
u64 align_bytes = aligned_start_pos - (u64)arena->pos;
if (align_bytes > 0) {
if (align_bytes > 0)
{
return (void *)PushStructsNoZero(arena, u8, align_bytes);
} else {
}
else
{
return (void *)(ArenaBase(arena) + arena->pos);
}
} else {
}
else
{
/* 0 alignment */
Assert(0);
return (void *)(ArenaBase(arena) + arena->pos);
@ -163,9 +170,11 @@ Inline ArenaCtx *ArenaCtxFromThreadId(i16 thread_id)
{
SharedArenaCtx *shared = &shared_arena_ctx;
ArenaCtx *ctx = &shared->arena_contexts[thread_id];
if (!ctx->scratch_arenas[0]) {
if (!ctx->scratch_arenas[0])
{
__profn("Initialize thread arena ctx");
for (i32 i = 0; i < (i32)countof(ctx->scratch_arenas); ++i) {
for (i32 i = 0; i < (i32)countof(ctx->scratch_arenas); ++i)
{
ctx->scratch_arenas[i] = AcquireArena(Gibi(64));
}
ctx->perm_arena = AcquireArena(Gibi(64));
@ -196,7 +205,8 @@ Inline TempArena _BeginScratch(Arena *potential_conflict)
ArenaCtx *ctx = ArenaCtxFromThreadId(ThreadId());
Arena *scratch_arena = ctx->scratch_arenas[0];
if (potential_conflict && scratch_arena == potential_conflict) {
if (potential_conflict && scratch_arena == potential_conflict)
{
scratch_arena = ctx->scratch_arenas[1];
}
TempArena temp = BeginTempArena(scratch_arena);

View File

@ -59,16 +59,10 @@
#endif
//- Language
#if defined(__cplusplus)
# define LanguageIsCpp 1
# define LanguageIsC 0
# define LanguageIsGpu 0
#elif defined(__HLSL_VERSION)
# define LanguageIsCpp 0
#if defined(__HLSL_VERSION)
# define LanguageIsC 0
# define LanguageIsGpu 1
#else
# define LanguageIsCpp 0
# define LanguageIsC 1
# define LanguageIsGpu 0
#endif
@ -172,13 +166,6 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Common utility macros
//- Initlist compatibility
#if CompilerIsMsvc && LanguageIsCpp
# define CppCompatInitListType(type)
#else
# define CppCompatInitListType(type) (type)
#endif
//- ZeroStruct initialization macro
#if LanguageIsC
# define ZI { 0 }
@ -247,16 +234,10 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define LAX (void)
//- Fallthrough
#if CompilerIsMsvc
# if LanguageIsCpp
# define FALLTHROUGH [[fallthrough]]
# else
#if CompilerIsClang
# define FALLTHROUGH
# endif
#elif CompilerIsClang
#else
# define FALLTHROUGH __attribute((fallthrough))
#else
# define FALLTHROUGH
#endif
//- Preprocessor concatenation
@ -280,18 +261,6 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Type helper macros
//- typeof
#if CompilerIsMsvc
/* Typeof not supported in MSVC */
# define TypeofIsDefined 0
# define typeof(type) Assert(0)
#else
# define TypeofIsDefined 1
# if LanguageIsCpp || (__STDC_VERSION__ < 202311L)
# define typeof(type) __typeof__(type)
# endif
#endif
//- alignof
#if (CompilerIsMsvc && LanguageIsC) || (LanguageIsC && (__STDC_VERSION__ < 202311L))
# define alignof(type) __alignof(type)
@ -382,7 +351,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Intrinsic headers
#if !LanguageIsGpu
#if LanguageIsC
/* Intrinsic header info:
* <mmintrin.h" MMX
* <xmmintrin.h" SSE
@ -408,7 +377,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////
//~ Scalar types
#if !LanguageIsGpu
#if LanguageIsC
//- Cpu scalar types
#include "stdint.h"
typedef int8_t i8;
@ -448,7 +417,7 @@ typedef uint b32;
#define I64Min ((i64)0x8000000000000000LL)
//- Float infinity / nan constants
#if !LanguageIsGpu
#if LanguageIsC
Global const u32 _f32_infinity_u32 = 0x7f800000;
Global const f32 *_f32_infinity = (f32 *)&_f32_infinity_u32;
#define F32Infinity (*_f32_infinity)
@ -472,7 +441,7 @@ Global const f64 *_f64_nan = (f64 *)&_f64_nan_u64;
////////////////////////////////
//~ Atomics
#if !LanguageIsGpu
#if LanguageIsC
//- Atomic types
Struct(Atomic8) { volatile i8 _v; };
@ -524,7 +493,7 @@ ForceInline i64 Atomic64FetchAdd(Atomic64 *x, i64 a) { return (i64)_InterlockedE
////////////////////////////////
//~ Ticket mutex
#if !LanguageIsGpu
#if LanguageIsC
Struct(TicketMutex)
{

View File

@ -210,7 +210,8 @@ u64 PowU64(u64 base, u8 exp)
{
return 1;
}
// if (base == -1) {
// if (base == -1)
// {
// return 1 - 2 * (exp & 1);
// }
return 0;

View File

@ -10,7 +10,7 @@
////////////////////////////////
//~ Api
@CpuApi mixer_core
@ApiC mixer_core
////////////////////////////////
//~ Init

View File

@ -28,10 +28,13 @@ MP3_Result MP3_Decode(Arena *arena, String encoded, u32 sample_rate, MP3_DecodeF
u64 channel_count;
u32 channel_mask;
if (flags & MP3_DecodeFlag_Stereo) {
if (flags & MP3_DecodeFlag_Stereo)
{
channel_count = 2;
channel_mask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
} else {
}
else
{
channel_count = 1;
channel_mask = SPEAKER_FRONT_CENTER;
}
@ -83,16 +86,19 @@ MP3_Result MP3_Decode(Arena *arena, String encoded, u32 sample_rate, MP3_DecodeF
result.samples = PushDry(arena, i16);
u64 sample_bytes_read = 0;
for (;;) {
for (;;)
{
IMFSample *sample;
DWORD sample_flags = 0;
HRESULT hr = IMFSourceReader_ReadSample(reader, (DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, 0, &sample_flags, 0, &sample);
if (FAILED(hr)) {
if (FAILED(hr))
{
break;
}
/* Check if done */
if (sample_flags & MF_SOURCE_READERF_ENDOFSTREAM) {
if (sample_flags & MF_SOURCE_READERF_ENDOFSTREAM)
{
result.success = 1;
break;
}

View File

@ -8,7 +8,7 @@
////////////////////////////////
//~ Api
@CpuApi mp3_core
@ApiC mp3_core
//- Mmf
@CpuApiWindows mp3_mmf
@ApiCWindows mp3_mmf

View File

@ -10,4 +10,4 @@
////////////////////////////////
//~ Api
@CpuApi net_core
@ApiC net_core

View File

@ -8,11 +8,11 @@
////////////////////////////////
//~ Api
@CpuApi platform_core
@CpuApi platform_log
@ApiC platform_core
@ApiC platform_log
//- Win32
@CpuApiWindows platform_win32
@ApiCWindows platform_win32
////////////////////////////////
//~ Init

View File

@ -10,10 +10,10 @@
////////////////////////////////
//~ Api
@CpuApi playback_core
@ApiC playback_core
//- Wasapi
@CpuApiWindows wasapi/playback_wasapi
@ApiCWindows wasapi/playback_wasapi
////////////////////////////////
//~ Init

View File

@ -4,7 +4,7 @@
//~ Dependencies
@Dep base
@Dep gtest
@Dep gpu
@Dep sprite
@Dep font
@Dep collider
@ -17,13 +17,13 @@
////////////////////////////////
//~ Api
@CpuApi pp_sim
@CpuApi pp_phys
@CpuApi pp_space
@CpuApi pp_ent
@CpuApi pp_step
@CpuApi pp_draw
@CpuApi pp_core
@ApiC pp_sim
@ApiC pp_phys
@ApiC pp_space
@ApiC pp_ent
@ApiC pp_step
@ApiC pp_draw
@ApiC pp_core
////////////////////////////////
//~ Init

View File

@ -44,7 +44,7 @@ void StartupUser(void)
//P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Success);
P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Debug);
g->window = P_AcquireWindow();
g->swapchain = GT_AcquireSwapchain(g->window, VEC2I32(100, 100));
g->swapchain = GPU_AcquireSwapchain(g->window, VEC2I32(100, 100));
P_ShowWindow(g->window);
/* Start jobs */
@ -389,44 +389,44 @@ void DrawDebugConsole(i32 level, b32 minimized)
//- Gbuffer
GT_Resource *AcquireGbuffer(GT_Format format, Vec2I32 size)
GPU_Resource *AcquireGbuffer(GPU_Format format, Vec2I32 size)
{
__prof;
GT_ResourceDesc desc = ZI;
desc.kind = GT_ResourceKind_Texture2D;
desc.flags = GT_ResourceFlag_AllowSrv | GT_ResourceFlag_AllowUav | GT_ResourceFlag_AllowRtv;
GPU_ResourceDesc desc = ZI;
desc.kind = GPU_ResourceKind_Texture2D;
desc.flags = GPU_ResourceFlag_AllowSrv | GPU_ResourceFlag_AllowUav | GPU_ResourceFlag_AllowRtv;
desc.texture.format = format;
desc.texture.size = VEC3I32(size.x, size.y, 1);
desc.texture.mip_levels = 1;
return GT_AcquireResource(desc);
return GPU_AcquireResource(desc);
}
//- Transfer buffer
GT_Resource *AcquireTransferBuffer(u32 element_count, u32 element_size, void *src)
GPU_Resource *AcquireTransferBuffer(u32 element_count, u32 element_size, void *src)
{
__prof;
u64 size = element_size * element_count;
GT_ResourceDesc desc = ZI;
desc.kind = GT_ResourceKind_Buffer;
desc.flags = GT_ResourceFlag_None;
desc.buffer.heap_kind = GT_HeapKind_Upload;
GPU_ResourceDesc desc = ZI;
desc.kind = GPU_ResourceKind_Buffer;
desc.flags = GPU_ResourceFlag_None;
desc.buffer.heap_kind = GPU_HeapKind_Upload;
desc.buffer.size = size;
desc.buffer.element_count = element_count;
desc.buffer.element_size = element_size;
GT_Resource *r = GT_AcquireResource(desc);
GPU_Resource *r = GPU_AcquireResource(desc);
{
__profn("Copy to transfer buffer");
GT_PushString(0, r, STRING(size, src));
GPU_PushString(0, r, STRING(size, src));
}
return r;
}
GT_Resource *AcquireTransferBufferFromArena(u32 element_count, Arena *arena)
GPU_Resource *AcquireTransferBufferFromArena(u32 element_count, Arena *arena)
{
__prof;
u64 element_size = element_count > 0 ? arena->pos / element_count : 0;
GT_Resource *r = AcquireTransferBuffer(element_count, element_size, (void *)ArenaBase(arena));
GPU_Resource *r = AcquireTransferBuffer(element_count, element_size, (void *)ArenaBase(arena));
return r;
}
@ -1256,9 +1256,9 @@ void UpdateUser(P_Window *window)
{
Vec2I32 local_tile_index = VEC2I32(tile_x, tile_y);
TileKind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)];
//if (tile > -1) {
/* FIXME: Enable this */
#if 0
//if (tile > -1)
if (tile == TileKind_Wall)
{
Vec2I32 world_tile_index = WorldTileIndexFromLocalTileIndex(chunk_index, local_tile_index);
@ -1793,7 +1793,7 @@ void UpdateUser(P_Window *window)
{
/* Queue player move cmd */
f32 move_speed = 1.0f;
//if (g->bind_states[BindKind_Walk].is_held) {
//if (g->bind_states[BindKind_Walk].is_held)
if (g->bind_states[BindKind_FullscreenMod].is_held)
{
//const f32 walk_ratio = 0.25f;
@ -2008,7 +2008,7 @@ void UpdateUser(P_Window *window)
//- Query vram
GT_MemoryInfo vram = GT_QueryMemoryInfo();
GPU_MemoryInfo vram = GPU_QueryMemoryInfo();
//- Draw global debug info
@ -2149,51 +2149,51 @@ void UpdateUser(P_Window *window)
Rect render_viewport = RectFromVec2(VEC2(0, 0), VEC2(g->render_size.x, g->render_size.y));
/* Acquire gbuffers */
if (g->shade_target && !EqVec2I32(g->render_size, GT_GetTextureSize(g->shade_target)))
if (g->shade_target && !EqVec2I32(g->render_size, GPU_GetTextureSize(g->shade_target)))
{
__profn("Release render resources");
GT_ReleaseResource(g->albedo, g->render_fence, GT_ReleaseFlag_None);
GT_ReleaseResource(g->emittance, g->render_fence, GT_ReleaseFlag_None);
GT_ReleaseResource(g->emittance_flood_read, g->render_fence, GT_ReleaseFlag_None);
GT_ReleaseResource(g->emittance_flood_target, g->render_fence, GT_ReleaseFlag_None);
GT_ReleaseResource(g->shade_read, g->render_fence, GT_ReleaseFlag_None);
GT_ReleaseResource(g->shade_target, g->render_fence, GT_ReleaseFlag_None);
GPU_ReleaseResource(g->albedo, g->render_fence, GPU_ReleaseFlag_None);
GPU_ReleaseResource(g->emittance, g->render_fence, GPU_ReleaseFlag_None);
GPU_ReleaseResource(g->emittance_flood_read, g->render_fence, GPU_ReleaseFlag_None);
GPU_ReleaseResource(g->emittance_flood_target, g->render_fence, GPU_ReleaseFlag_None);
GPU_ReleaseResource(g->shade_read, g->render_fence, GPU_ReleaseFlag_None);
GPU_ReleaseResource(g->shade_target, g->render_fence, GPU_ReleaseFlag_None);
g->shade_target = 0;
}
if (!g->shade_target)
{
__profn("Acquire sig resources");
g->albedo = AcquireGbuffer(GT_Format_R8G8B8A8_Unorm, g->render_size);
g->emittance = AcquireGbuffer(GT_Format_R16G16B16A16_Float, g->render_size);
g->emittance_flood_read = AcquireGbuffer(GT_Format_R16G16_Uint, g->render_size);
g->emittance_flood_target = AcquireGbuffer(GT_Format_R16G16_Uint, g->render_size);
g->shade_read = AcquireGbuffer(GT_Format_R16G16B16A16_Float, g->render_size);
g->shade_target = AcquireGbuffer(GT_Format_R16G16B16A16_Float, g->render_size);
g->albedo = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->render_size);
g->emittance = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
g->emittance_flood_read = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size);
g->emittance_flood_target = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size);
g->shade_read = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
g->shade_target = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size);
}
/* Acquire ui buffers */
if (g->ui_target && !EqVec2I32(g->ui_size, GT_GetTextureSize(g->ui_target)))
if (g->ui_target && !EqVec2I32(g->ui_size, GPU_GetTextureSize(g->ui_target)))
{
GT_ReleaseResource(g->ui_target, g->render_fence, GT_ReleaseFlag_None);
GPU_ReleaseResource(g->ui_target, g->render_fence, GPU_ReleaseFlag_None);
g->ui_target = 0;
}
if (!g->ui_target)
{
g->ui_target = AcquireGbuffer(GT_Format_R8G8B8A8_Unorm, g->ui_size);
g->ui_target = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->ui_size);
}
/* Acquire transfer buffers */
/* TODO: Make these static */
LocalPersist u16 quad_indices[6] = { 0, 1, 2, 0, 2, 3 };
GT_Resource *quad_index_buffer = AcquireTransferBuffer(countof(quad_indices), sizeof(*quad_indices), quad_indices);
GT_Resource *material_instance_buffer = AcquireTransferBufferFromArena(g->material_instances_count, g->material_instances_arena);
GT_Resource *ui_rect_instance_buffer = AcquireTransferBufferFromArena(g->ui_rect_instances_count, g->ui_rect_instances_arena);
GT_Resource *ui_shape_verts_buffer = AcquireTransferBufferFromArena(g->ui_shape_verts_count, g->ui_shape_verts_arena);
GT_Resource *ui_shape_indices_buffer = AcquireTransferBufferFromArena(g->ui_shape_indices_count, g->ui_shape_indices_arena);
GT_Resource *grids_buffer = AcquireTransferBufferFromArena(g->grids_count, g->grids_arena);
GPU_Resource *quad_index_buffer = AcquireTransferBuffer(countof(quad_indices), sizeof(*quad_indices), quad_indices);
GPU_Resource *material_instance_buffer = AcquireTransferBufferFromArena(g->material_instances_count, g->material_instances_arena);
GPU_Resource *ui_rect_instance_buffer = AcquireTransferBufferFromArena(g->ui_rect_instances_count, g->ui_rect_instances_arena);
GPU_Resource *ui_shape_verts_buffer = AcquireTransferBufferFromArena(g->ui_shape_verts_count, g->ui_shape_verts_arena);
GPU_Resource *ui_shape_indices_buffer = AcquireTransferBufferFromArena(g->ui_shape_indices_count, g->ui_shape_indices_arena);
GPU_Resource *grids_buffer = AcquireTransferBufferFromArena(g->grids_count, g->grids_arena);
GT_CommandList *cl = GT_BeginCommandList();
GT_ProfileDF(cl, Lit("Run render"));
GPU_CommandList *cl = GPU_BeginCommandList();
GPU_ProfileDF(cl, Lit("Run render"));
{
__profn("Run render");
Mat4x4 world_to_render_vp_matrix = ProjectMat4x4View(g->world_to_render_xf, render_viewport.width, render_viewport.height);
@ -2207,32 +2207,32 @@ void UpdateUser(P_Window *window)
}
//- Prep material pass
GT_ProfileDF(cl, Lit("Clear gbuffers"));
GPU_ProfileDF(cl, Lit("Clear gbuffers"));
{
__profn("Clear gbuffers");
GT_TransitionToRtv(cl, g->albedo);
GT_TransitionToRtv(cl, g->emittance);
GT_DispatchClear(cl, g->albedo);
GT_DispatchClear(cl, g->emittance);
GPU_TransitionToRtv(cl, g->albedo);
GPU_TransitionToRtv(cl, g->emittance);
GPU_DispatchClear(cl, g->albedo);
GPU_DispatchClear(cl, g->emittance);
}
//- Material pass
GT_ProfileDF(cl, Lit("Material pass"));
GPU_ProfileDF(cl, Lit("Material pass"));
{
__profn("Material pass");
GT_Resource *rts[] = {
GPU_Resource *rts[] = {
g->albedo,
g->emittance
};
GT_Viewport viewport = GT_ViewportFromRect(render_viewport);
GT_Scissor scissor = GT_ScissorRectFromRect(render_viewport);
GPU_Viewport viewport = GPU_ViewportFromRect(render_viewport);
GPU_Scissor scissor = GPU_ScissorFromRect(render_viewport);
MaterialSig sig = ZI;
sig.projection = world_to_render_vp_matrix;
sig.instances_urid = GT_GetResourceId(material_instance_buffer);
sig.grids_urid = GT_GetResourceId(grids_buffer);
GT_DispatchRasterize(cl,
sig.instances_urid = GPU_GetResourceId(material_instance_buffer);
sig.grids_urid = GPU_GetResourceId(grids_buffer);
GPU_DispatchRasterize(cl,
MaterialVS, MaterialPS,
&sig,
countof(rts), rts,
@ -2240,19 +2240,19 @@ void UpdateUser(P_Window *window)
1, &scissor,
g->material_instances_count,
quad_index_buffer,
GT_RasterizeMode_TriangleList);
GPU_RasterizeMode_TriangleList);
}
//- Prep flood pass
{
GT_TransitionToSrv(cl, g->emittance);
GT_TransitionToUav(cl, g->emittance_flood_read);
GT_TransitionToUav(cl, g->emittance_flood_target);
GPU_TransitionToSrv(cl, g->emittance);
GPU_TransitionToUav(cl, g->emittance_flood_read);
GPU_TransitionToUav(cl, g->emittance_flood_target);
}
//- Flood pass
if (!effects_disabled)
GT_ProfileDF(cl, Lit("Flood pass"));
GPU_ProfileDF(cl, Lit("Flood pass"));
{
__profn("Flood pass");
@ -2262,23 +2262,23 @@ void UpdateUser(P_Window *window)
u64 max_steps = GetGstat(GSTAT_DEBUG_STEPS);
u64 step = 0;
while (step_length != 0 && step < max_steps)
GT_ProfileDF(cl, Lit("Flood step"));
GPU_ProfileDF(cl, Lit("Flood step"));
{
__profn("Flood step");
GT_Flush(cl, g->emittance_flood_read);
GPU_Flush(cl, g->emittance_flood_read);
FloodSig sig = ZI;
sig.step_len = step_length;
sig.emittance_tex_urid = GT_GetResourceId(g->emittance);
sig.read_flood_tex_urid = GT_GetResourceId(g->emittance_flood_read);
sig.target_flood_tex_urid = GT_GetResourceId(g->emittance_flood_target);
sig.emittance_tex_urid = GPU_GetResourceId(g->emittance);
sig.read_flood_tex_urid = GPU_GetResourceId(g->emittance_flood_read);
sig.target_flood_tex_urid = GPU_GetResourceId(g->emittance_flood_target);
sig.tex_width = g->render_size.x;
sig.tex_height = g->render_size.y;
GT_DispatchCompute(cl, FloodCS, &sig, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
GPU_DispatchCompute(cl, FloodCS, &sig, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
/* Swap buffers */
GT_Resource *swp = g->emittance_flood_read;
GPU_Resource *swp = g->emittance_flood_read;
g->emittance_flood_read = g->emittance_flood_target;
g->emittance_flood_target = swp;
@ -2296,19 +2296,19 @@ void UpdateUser(P_Window *window)
}
//- Prep shade pass
GT_ProfileDF(cl, Lit("Clear shade target"));
GPU_ProfileDF(cl, Lit("Clear shade target"));
{
__profn("Clear shade target");
GT_TransitionToSrv(cl, g->albedo);
GT_TransitionToSrv(cl, g->emittance);
GT_TransitionToUav(cl, g->shade_target);
GT_Flush(cl, g->emittance_flood_read);
GT_Flush(cl, g->shade_read);
GT_DispatchClear(cl, g->shade_target);
GPU_TransitionToSrv(cl, g->albedo);
GPU_TransitionToSrv(cl, g->emittance);
GPU_TransitionToUav(cl, g->shade_target);
GPU_Flush(cl, g->emittance_flood_read);
GPU_Flush(cl, g->shade_read);
GPU_DispatchClear(cl, g->shade_target);
}
//- Shade pass
GT_ProfileDF(cl, Lit("Shade pass"));
GPU_ProfileDF(cl, Lit("Shade pass"));
{
__profn("Shade pass");
@ -2327,43 +2327,43 @@ void UpdateUser(P_Window *window)
(u32)(RandU64FromState(&g->frame_rand) & 0xFFFFFFFF));
sig.frame_index = g->frame_index;
sig.camera_offset = g->world_to_render_xf.og;
sig.albedo_tex_urid = GT_GetResourceId(g->albedo);
sig.emittance_tex_urid = GT_GetResourceId(g->emittance);
sig.emittance_flood_tex_urid = GT_GetResourceId(g->emittance_flood_read);
sig.read_tex_urid = GT_GetResourceId(g->shade_read);
sig.target_tex_urid = GT_GetResourceId(g->shade_target);
GT_DispatchCompute(cl, ShadeCS, &sig, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
sig.albedo_tex_urid = GPU_GetResourceId(g->albedo);
sig.emittance_tex_urid = GPU_GetResourceId(g->emittance);
sig.emittance_flood_tex_urid = GPU_GetResourceId(g->emittance_flood_read);
sig.read_tex_urid = GPU_GetResourceId(g->shade_read);
sig.target_tex_urid = GPU_GetResourceId(g->shade_target);
GPU_DispatchCompute(cl, ShadeCS, &sig, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
/* Swap */
GT_Resource *swp = g->shade_read;
GPU_Resource *swp = g->shade_read;
g->shade_read = g->shade_target;
g->shade_target = swp;
}
//- Prep ui pass
GT_ProfileDF(cl, Lit("Clear ui target"));
GPU_ProfileDF(cl, Lit("Clear ui target"));
{
__profn("Clear ui target");
GT_TransitionToRtv(cl, g->ui_target);
GT_Flush(cl, g->shade_read);
GT_DispatchClear(cl, g->ui_target);
GPU_TransitionToRtv(cl, g->ui_target);
GPU_Flush(cl, g->shade_read);
GPU_DispatchClear(cl, g->ui_target);
}
//- Ui blit pass
GT_ProfileDF(cl, Lit("UI blit pass"));
GPU_ProfileDF(cl, Lit("UI blit pass"));
{
__profn("UI blit pass");
GT_Viewport viewport = GT_ViewportFromRect(ui_viewport);
GT_Scissor scissor = GT_ScissorRectFromRect(ui_viewport);
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
UiBlitSig sig = ZI;
sig.projection = blit_vp_matrix;
sig.flags = UiBlitFlag_ToneMap | UiBlitFlag_GammaCorrect;
sig.exposure = 2.0;
sig.gamma = (f32)2.2;
sig.tex_urid = GT_GetResourceId(g->shade_read);
GT_DispatchRasterize(cl,
sig.tex_urid = GPU_GetResourceId(g->shade_read);
GPU_DispatchRasterize(cl,
UiBlitVS, UiBlitPS,
&sig,
1, &g->ui_target,
@ -2371,21 +2371,21 @@ void UpdateUser(P_Window *window)
1, &scissor,
1,
quad_index_buffer,
GT_RasterizeMode_TriangleList);
GPU_RasterizeMode_TriangleList);
}
//- Ui rect pass
GT_ProfileDF(cl, Lit("UI rect pass"));
GPU_ProfileDF(cl, Lit("UI rect pass"));
{
__profn("UI rect pass");
GT_Viewport viewport = GT_ViewportFromRect(ui_viewport);
GT_Scissor scissor = GT_ScissorRectFromRect(ui_viewport);
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
UiRectSig sig = ZI;
sig.projection = ui_vp_matrix;
sig.instances_urid = GT_GetResourceId(ui_rect_instance_buffer);
GT_DispatchRasterize(cl,
sig.instances_urid = GPU_GetResourceId(ui_rect_instance_buffer);
GPU_DispatchRasterize(cl,
UiRectVS, UiRectPS,
&sig,
1, &g->ui_target,
@ -2393,21 +2393,21 @@ void UpdateUser(P_Window *window)
1, &scissor,
g->ui_rect_instances_count,
quad_index_buffer,
GT_RasterizeMode_TriangleList);
GPU_RasterizeMode_TriangleList);
}
//- Ui shape pass
GT_ProfileDF(cl, Lit("UI shape pass"));
GPU_ProfileDF(cl, Lit("UI shape pass"));
{
__profn("UI shape pass");
GT_Viewport viewport = GT_ViewportFromRect(ui_viewport);
GT_Scissor scissor = GT_ScissorRectFromRect(ui_viewport);
GPU_Viewport viewport = GPU_ViewportFromRect(ui_viewport);
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
UiShapeSig sig = ZI;
sig.projection = ui_vp_matrix;
sig.verts_urid = GT_GetResourceId(ui_shape_verts_buffer);
GT_DispatchRasterize(cl,
sig.verts_urid = GPU_GetResourceId(ui_shape_verts_buffer);
GPU_DispatchRasterize(cl,
UiShapeVS, UiShapePS,
&sig,
1, &g->ui_target,
@ -2415,19 +2415,19 @@ void UpdateUser(P_Window *window)
1, &scissor,
1,
ui_shape_indices_buffer,
GT_RasterizeMode_TriangleList);
GPU_RasterizeMode_TriangleList);
}
}
g->render_fence = GT_EndCommandList(cl);
g->render_fence = GPU_EndCommandList(cl);
/* Release transfer buffers */
{
GT_ReleaseResource(quad_index_buffer, g->render_fence, GT_ReleaseFlag_Reuse);
GT_ReleaseResource(material_instance_buffer, g->render_fence, GT_ReleaseFlag_Reuse);
GT_ReleaseResource(ui_rect_instance_buffer, g->render_fence, GT_ReleaseFlag_Reuse);
GT_ReleaseResource(ui_shape_verts_buffer, g->render_fence, GT_ReleaseFlag_Reuse);
GT_ReleaseResource(ui_shape_indices_buffer, g->render_fence, GT_ReleaseFlag_Reuse);
GT_ReleaseResource(grids_buffer, g->render_fence, GT_ReleaseFlag_Reuse);
GPU_ReleaseResource(quad_index_buffer, g->render_fence, GPU_ReleaseFlag_Reuse);
GPU_ReleaseResource(material_instance_buffer, g->render_fence, GPU_ReleaseFlag_Reuse);
GPU_ReleaseResource(ui_rect_instance_buffer, g->render_fence, GPU_ReleaseFlag_Reuse);
GPU_ReleaseResource(ui_shape_verts_buffer, g->render_fence, GPU_ReleaseFlag_Reuse);
GPU_ReleaseResource(ui_shape_indices_buffer, g->render_fence, GPU_ReleaseFlag_Reuse);
GPU_ReleaseResource(grids_buffer, g->render_fence, GPU_ReleaseFlag_Reuse);
ResetArena(g->material_instances_arena);
ResetArena(g->ui_rect_instances_arena);
ResetArena(g->ui_shape_verts_arena);
@ -2462,7 +2462,7 @@ JobDef(UpdateUserJob, UNUSED sig, UNUSED id)
__profn("User sleep");
{
__profn("Swapchain wait");
GT_WaitOnSwapchain(g->swapchain);
GPU_WaitOnSwapchain(g->swapchain);
}
{
__profn("Frame limiter wait");

View File

@ -155,7 +155,7 @@ Struct(SharedUserState)
Atomic32 shutdown;
Counter shutdown_job_counters;
P_Window *window;
GT_Swapchain *swapchain;
GPU_Swapchain *swapchain;
Arena *arena;
String connect_address_str;
@ -171,13 +171,13 @@ Struct(SharedUserState)
SecondsStat net_bytes_sent;
//- Gpu resources
GT_Resource *albedo;
GT_Resource *emittance;
GT_Resource *emittance_flood_read;
GT_Resource *emittance_flood_target;
GT_Resource *shade_read;
GT_Resource *shade_target;
GT_Resource *ui_target;
GPU_Resource *albedo;
GPU_Resource *emittance;
GPU_Resource *emittance_flood_read;
GPU_Resource *emittance_flood_target;
GPU_Resource *shade_read;
GPU_Resource *shade_target;
GPU_Resource *ui_target;
RandState frame_rand;
u64 frame_index;
@ -193,7 +193,7 @@ Struct(SharedUserState)
u32 ui_shape_indices_count;
u32 grids_count;
GT_Fence render_fence;
GPU_Fence render_fence;
//- Bind state
BindState bind_states[BindKind_Count];
@ -296,9 +296,9 @@ void DrawDebugConsole(i32 level, b32 minimized);
////////////////////////////////
//~ Gpu buffer helpers
GT_Resource *AcquireGbuffer(GT_Format format, Vec2I32 size);
GT_Resource *AcquireTransferBuffer(u32 element_count, u32 element_size, void *src);
GT_Resource *AcquireTransferBufferFromArena(u32 element_count, Arena *arena);
GPU_Resource *AcquireGbuffer(GPU_Format format, Vec2I32 size);
GPU_Resource *AcquireTransferBuffer(u32 element_count, u32 element_size, void *src);
GPU_Resource *AcquireTransferBufferFromArena(u32 element_count, Arena *arena);
////////////////////////////////
//~ Entity sorting

View File

@ -308,7 +308,7 @@ Vec3 tone_map(Vec3 v)
//- Vertex shader
UiBlitPS_Input GT_VertexShaderDef(UiBlitVS)(Semantic(u32, SV_VertexID))
UiBlitPS_Input GPUVertexShaderDef(UiBlitVS)(Semantic(u32, SV_VertexID))
{
static const Vec2 unit_quad_verts[4] = {
Vec2(-0.5f, -0.5f),
@ -327,7 +327,7 @@ UiBlitPS_Input GT_VertexShaderDef(UiBlitVS)(Semantic(u32, SV_VertexID))
//- Pixel shader
UiBlitPS_Output GT_PixelShaderDef(UiBlitPS)(UiBlitPS_Input input)
UiBlitPS_Output GPUPixelShaderDef(UiBlitPS)(UiBlitPS_Input input)
{
UiBlitPS_Output output;
Texture2D<Vec4> tex = GpuResourceFromUrid(sig.tex_urid);
@ -369,7 +369,7 @@ Struct(UiRectPS_Output)
//- Vertex shader
UiRectPS_Input GT_VertexShaderDef(UiRectVS)(Semantic(u32, SV_InstanceID), Semantic(u32, SV_VertexID))
UiRectPS_Input GPUVertexShaderDef(UiRectVS)(Semantic(u32, SV_InstanceID), Semantic(u32, SV_VertexID))
{
static const Vec2 unit_quad_verts[4] = {
Vec2(-0.5f, -0.5f),
@ -393,7 +393,7 @@ UiRectPS_Input GT_VertexShaderDef(UiRectVS)(Semantic(u32, SV_InstanceID), Semant
//- Pixel shader
UiRectPS_Output GT_PixelShaderDef(UiRectPS)(PSInput input)
UiRectPS_Output GPUPixelShaderDef(UiRectPS)(PSInput input)
{
UiRectPS_Output output;
Vec4 color = input.tint_srgb;
@ -425,7 +425,7 @@ Struct(UiShapePS_Output)
//- Vertex shader
UiShapePS_Input GT_VertexShaderDef(UiShapeVS)(Semantic(u32, SV_VertexID))
UiShapePS_Input GPUVertexShaderDef(UiShapeVS)(Semantic(u32, SV_VertexID))
{
StructuredBuffer<UiShapeVert> verts = GpuResourceFromUrid(sig.verts_urid);
UiShapeVert vert = verts[SV_VertexID];
@ -437,7 +437,7 @@ UiShapePS_Input GT_VertexShaderDef(UiShapeVS)(Semantic(u32, SV_VertexID))
//- Pixel shader
UiShapePS_Output GT_PixelShaderDef(UiShapePS)(PSInput input)
UiShapePS_Output GPUPixelShaderDef(UiShapePS)(PSInput input)
{
UiShapePS_Output output;
output.SV_Target = input.color_srgb;

View File

@ -158,23 +158,23 @@ Struct(UiShapeVert)
//~ Shaders
//- Material
GT_ShaderDecl(MaterialVS);
GT_ShaderDecl(MaterialPS);
GPU_ShaderDecl(MaterialVS);
GPU_ShaderDecl(MaterialPS);
//- Flood
GT_ShaderDecl(FloodCS);
GPU_ShaderDecl(FloodCS);
//- Shade
GT_ShaderDecl(ShadeCS);
GPU_ShaderDecl(ShadeCS);
//- Ui blit
GT_ShaderDecl(UiBlitVS);
GT_ShaderDecl(UiBlitPS);
GPU_ShaderDecl(UiBlitVS);
GPU_ShaderDecl(UiBlitPS);
//- Ui rect
GT_ShaderDecl(UiRectVS);
GT_ShaderDecl(UiRectPS);
GPU_ShaderDecl(UiRectVS);
GPU_ShaderDecl(UiRectPS);
//- Ui shape
GT_ShaderDecl(UiShapeVS);
GT_ShaderDecl(UiShapePS);
GPU_ShaderDecl(UiShapeVS);
GPU_ShaderDecl(UiShapePS);

View File

@ -1,6 +0,0 @@
@Lay prof
////////////////////////////////
//~ Api
@CpuApi prof_tracy

View File

@ -12,7 +12,7 @@
////////////////////////////////
//~ Api
@CpuApi rendertest_core
@ApiC rendertest_core
////////////////////////////////
//~ Init

View File

@ -11,7 +11,7 @@
////////////////////////////////
//~ Api
@CpuApi resource_core
@ApiC resource_core
////////////////////////////////
//~ Init

View File

@ -10,4 +10,4 @@
////////////////////////////////
//~ Api
@CpuApi settings_core
@ApiC settings_core

View File

@ -12,4 +12,4 @@
////////////////////////////////
//~ Api
@CpuApi sound_core
@ApiC sound_core

View File

@ -5,7 +5,7 @@
@Dep base
@Dep platform
@Dep gtest
@Dep gpu
@Dep ase
@Dep resource
@Dep watch
@ -13,7 +13,7 @@
////////////////////////////////
//~ Api
@CpuApi sprite_core
@ApiC sprite_core
////////////////////////////////
//~ Init

View File

@ -17,13 +17,13 @@ void S_StartupCore(void)
g->nil_texture->loaded = 1;
{
TempArena scratch = BeginScratchNoConflict();
GT_ResourceDesc desc = ZI;
desc.kind = GT_ResourceKind_Texture2D;
desc.texture.format = GT_Format_R8G8B8A8_Unorm;
GPU_ResourceDesc desc = ZI;
desc.kind = GPU_ResourceKind_Texture2D;
desc.texture.format = GPU_Format_R8G8B8A8_Unorm;
desc.texture.size = VEC3I32(64, 64, 1);
g->nil_texture->gpu_resource = GT_AcquireResource(desc);
g->nil_texture->gpu_resource = GPU_AcquireResource(desc);
u32 *pixels = S_GeneratePurpleBlackImage(scratch.arena, desc.texture.size.x, desc.texture.size.y);
GT_PushString(0, g->nil_texture->gpu_resource, STRING(desc.texture.size.x * desc.texture.size.y * 4, (u8 *)pixels));
GPU_PushString(0, g->nil_texture->gpu_resource, STRING(desc.texture.size.x * desc.texture.size.y * 4, (u8 *)pixels));
EndScratch(scratch);
}
@ -494,19 +494,19 @@ void S_LoadCacheEntryTexture(S_CacheEntryRef ref, S_Tag tag)
if (decoded.success)
{
/* Initialize */
GT_ResourceDesc gpu_desc = ZI;
gpu_desc.kind = GT_ResourceKind_Texture2D;
GPU_ResourceDesc gpu_desc = ZI;
gpu_desc.kind = GPU_ResourceKind_Texture2D;
gpu_desc.texture.size = VEC3I32(decoded.width, decoded.height, 1);
gpu_desc.texture.format = GT_Format_R8G8B8A8_Unorm_Srgb;
gpu_desc.texture.format = GPU_Format_R8G8B8A8_Unorm_Srgb;
e->texture = PushStruct(e->arena, S_Texture);
e->texture->width = decoded.width;
e->texture->height = decoded.height;
e->texture->valid = 1;
e->texture->loaded = 1;
e->texture->gpu_resource = GT_AcquireResource(gpu_desc);
e->texture->gpu_resource = GPU_AcquireResource(gpu_desc);
{
u64 size = decoded.width * decoded.height * 4;
GT_PushString(0, e->texture->gpu_resource, STRING(size, (u8 *)decoded.pixels));
GPU_PushString(0, e->texture->gpu_resource, STRING(size, (u8 *)decoded.pixels));
}
/* TODO: Query gpu for more accurate texture size in VRAM */
memory_size += (decoded.width * decoded.height) * sizeof(*decoded.pixels);
@ -1294,13 +1294,13 @@ JobDef(S_EvictorJob, UNUSED sig, UNUSED job_id)
/* Release evicted node memory */
{
__profn("Evictor memory release");
GT_Fence gpu_fence = GT_GetGlobalFence();
GPU_Fence gpu_fence = GPU_GetGlobalFence();
for (S_EvictorNode *en = first_evicted; en; en = en->next_evicted)
{
S_CacheEntry *n = en->cache_entry;
if (n->kind == S_CacheEntryKind_Texture && n->texture->valid)
{
GT_ReleaseResource(n->texture->gpu_resource, gpu_fence, GT_ReleaseFlag_None);
GPU_ReleaseResource(n->texture->gpu_resource, gpu_fence, GPU_ReleaseFlag_None);
}
ReleaseArena(n->arena);
}

View File

@ -14,7 +14,7 @@ Struct(S_Texture)
{
b32 loaded;
b32 valid;
GT_Resource *gpu_resource;
GPU_Resource *gpu_resource;
u32 width;
u32 height;
};

View File

@ -10,4 +10,4 @@
////////////////////////////////
//~ Api
@CpuApi tar_core
@ApiC tar_core

View File

@ -2,7 +2,7 @@
//~ Dependencies
AddDep("../base/base.h");
AddDep("../gtest/gtest.h");
AddDep("../gpu/gpu.h");
AddDep("../sprite/sprite.h");
AddDep("../font/font.h");
AddDep("../collider/collider.h");

View File

@ -9,7 +9,7 @@
////////////////////////////////
//~ Api
@CpuApi watch_core
@ApiC watch_core
////////////////////////////////
//~ Init