more refactoring to support gpu pointers

This commit is contained in:
jacob 2025-11-20 01:25:37 -06:00
parent b4a51ff5af
commit 0ac3284511
81 changed files with 2098 additions and 1714 deletions

View File

@ -26,7 +26,7 @@ u64 AC_HashFromKey(String key)
void AC_RefreshDebugTable(void)
{
#if RtcIsEnabled
#if IsRtcEnabled
AC_SharedState *g = &AC_shared_state;
Lock lock = LockE(&g->dbg_table_mutex);
ZeroArray(g->dbg_table);

View File

@ -53,7 +53,7 @@ Struct(AC_SharedState)
Mutex store_mutex;
Arena *store_arena;
#if RtcIsEnabled
#if IsRtcEnabled
/* Array of len `num_assets` pointing into populated entries of `lookup`. */
AC_Asset *dbg_table[AC_AssetLookupTableCapacity];
u64 dbg_table_count;

View File

@ -5,40 +5,40 @@
#error Missing compile time definition for 'IsConsoleApp'
#endif
#ifndef RtcIsEnabled
# error Missing compile time definition for 'RtcIsEnabled'
#ifndef IsRtcEnabled
#error Missing compile time definition for 'IsRtcEnabled'
#endif
#ifndef AsanIsEnabled
# error Missing compile time definition for 'AsanIsEnabled'
#ifndef IsAsanEnabled
#error Missing compile time definition for 'IsAsanEnabled'
#endif
#ifndef CrtlibIsEnabled
# error Missing compile time definition for 'CrtlibIsEnabled'
#ifndef IsCrtlibEnabled
#error Missing compile time definition for 'IsCrtlibEnabled'
#endif
#ifndef DebinfoEnabled
# error Missing compile time definition for 'DebinfoEnabled'
#ifndef IsDebinfoEnabled
#error Missing compile time definition for 'IsDebinfoEnabled'
#endif
#ifndef DeveloperIsEnabled
# error Missing compile time definition for 'DeveloperIsEnabled'
#ifndef IsDeveloperModeEnabled
#error Missing compile time definition for 'IsDeveloperModeEnabled'
#endif
#ifndef ProfilingIsEnabled
# error Missing compile time definition for 'ProfilingIsEnabled'
#ifndef IsProfilingEnabled
#error Missing compile time definition for 'IsProfilingEnabled'
#endif
#ifndef UnoptimizedIsEnabled
# error Missing compile time definition for 'UnoptimizedIsEnabled'
#ifndef IsUnoptimized
#error Missing compile time definition for 'IsUnoptimized'
#endif
#ifndef TestsAreEnabled
# error Missing compile time definition for 'TestsAreEnabled'
#ifndef IsTestingEnabled
#error Missing compile time definition for 'IsTestingEnabled'
#endif
#ifndef HotSwappingIsEnabled
# error Missing compile time definition for 'HotSwappingIsEnabled'
#ifndef IsHotSwappingEnabled
#error Missing compile time definition for 'IsHotSwappingEnabled'
#endif
////////////////////////////////////////////////////////////
@ -46,55 +46,55 @@
//- Compiler
#if defined(__clang__)
# define CompilerIsClang 1
# define CompilerIsMsvc 0
#define IsCompilerClang 1
#define IsCompilerMsvc 0
#elif defined(_MSC_VER)
# define CompilerIsClang 0
# define CompilerIsMsvc 1
#define IsCompilerClang 0
#define IsCompilerMsvc 1
#else
#error Unknown compiler
#endif
//- Language
#if defined(__HLSL_VERSION)
# define LanguageIsC 0
# define LanguageIsGpu 1
#define IsLanguageC 0
#define IsLanguageGpu 1
#else
# define LanguageIsC 1
# define LanguageIsGpu 0
#define IsLanguageC 1
#define IsLanguageGpu 0
#endif
//- Platform system
#if defined(_WIN32)
# define PlatformIsWindows 1
# define PlatformIsMac 0
# define PlatformIsLinux 0
#define IsPlatformWindows 1
#define IsPlatformMac 0
#define IsPlatformLinux 0
#elif defined(__APPLE__) && defined(__MACH__)
# define PlatformIsWindows 0
# define PlatformIsMac 1
# define PlatformIsLinux 0
#define IsPlatformWindows 0
#define IsPlatformMac 1
#define IsPlatformLinux 0
#elif defined(__gnu_linux__)
# define PlatformIsWindows 0
# define PlatformIsMac 0
# define PlatformIsLinux 1
#elif LanguageIsGpu
# define PlatformIsWindows 0
# define PlatformIsMac 0
# define PlatformIsLinux 0
#define IsPlatformWindows 0
#define IsPlatformMac 0
#define IsPlatformLinux 1
#elif IsLanguageGpu
#define IsPlatformWindows 0
#define IsPlatformMac 0
#define IsPlatformLinux 0
#else
#error Unknown platform
#endif
//- Architecture
#if defined(_M_AMD64) || defined(__amd64__)
# define ArchIsX64 1
# define ArchIsArm64 0
#define IsArchX64 1
#define IsArchArm64 0
#elif defined(_M_ARM64) || defined(__aarch64__)
# define ArchIsX64 0
# define ArchIsArm64 1
# elif LanguageIsGpu
# define ArchIsX64 0
# define ArchIsArm64 0
#define IsArchX64 0
#define IsArchArm64 1
#elif IsLanguageGpu
#define IsArchX64 0
#define IsArchArm64 0
#else
#error Unknown architecture
#endif
@ -106,10 +106,10 @@
//- Windows NTDDI version
/* TODO: Remove this */
#if 0
#if CompilerIsMsvc
#if IsCompilerMsvc
#define NTDDI_WIN11_DT 0x0C0A0000
#define NTDDI_VERSION 0x0A000000
# if RtcIsEnabled
#if IsRtcEnabled
#define _ALLOW_RTCc_IN_STL 1
#endif
#endif
@ -119,7 +119,7 @@
//~ Platform headers
//- Windows headers
#if PlatformIsWindows
#if IsPlatformWindows
#define COBJMACROS
#define WIN32_LEAN_AND_MEAN
#define UNICODE
@ -144,8 +144,8 @@
#define StaticAssert(cond) StaticAssert1(cond, __LINE__, __COUNTER__)
//- Debug assert
#if RtcIsEnabled
# if CompilerIsMsvc
#if IsRtcEnabled
#if IsCompilerMsvc
#define Assert(cond) ((cond) ? 1 : (IsRunningInDebugger() ? (*(volatile i32 *)0 = 0) : Panic(Lit(__FILE__ ":" Stringize(__LINE__) ":0: assertion failed: "#cond""))))
#define DEBUGBREAK __debugbreak()
#else
@ -157,29 +157,8 @@
#define Assert(cond) (void)(0)
#endif
//- Root constant assert
#define AssertRootConst(s, n) StaticAssert((sizeof(s) % 16 == 0) && /* Root constant struct should pad to 16 byte alignment */ \
((sizeof(s) / 4) == (n)) && /* Root constant struct size should match the specified 32-bit-constant count */ \
(sizeof(s) <= 256)) /* Root constant struct can only fit 64 DWORDS */
//- Debug alias
/* TODO: Remove this */
#if CompilerIsMsvc
# if DebinfoEnabled
# define DebugAlias(var, alias) *(alias) = &(var)
# else
# define DebugAlias(var, alias) *(alias) = &(var)
# endif
#else
# if DebinfoEnabled
# define DebugAlias(var, alias) __attribute((used)) *(alias) = &(var)
# else
# define DebugAlias(var, alias) __attribute((unused)) *(alias) = &(var)
# endif
#endif
//- Address sanitization
#if AsanIsEnabled
#if IsAsanEnabled
void __asan_poison_memory_region(void const volatile *, size_t);
void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define AsanPoison(addr, size) __asan_poison_memory_region((addr), (size))
@ -193,7 +172,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//~ Common utility macros
//- ZeroStruct initialization macro
#if LanguageIsC
#if IsLanguageC
#define ZI { 0 }
#else
#define ZI { }
@ -202,13 +181,13 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//- Inline
#define Inline static inline
#if CompilerIsMsvc
#if IsCompilerMsvc
#define ForceInline Inline __forceinline
#else
#define ForceInline Inline __attribute((always_inline))
#endif
#if CompilerIsMsvc
#if IsCompilerMsvc
#define ForceNoInline __declspec(noinline)
#else
#define ForceNoInline __attribute__((noinline))
@ -219,27 +198,27 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define Global static
//- Read-only
#if PlatformIsWindows
# if CompilerIsMsvc
#if IsPlatformWindows
#if IsCompilerMsvc
# pragma section(".rdata$", read)
# define Readonly __declspec(allocate(".rdata$"))
#else
#define Readonly __declspec(allocate(".rdata"))
#endif
#elif PlatformIsMac
#elif IsPlatformMac
#define Readonly __attribute((section("__TEXT,__const")))
#else
#define Readonly __attribute((section(".rodata")))
#endif
//- Barriers
#if CompilerIsMsvc
#if IsCompilerMsvc
#define WriteBarrier() _WriteBarrier()
#define ReadBarrier() _ReadBarrier()
#elif defined(__x86_64) || defined(__i386__)
#define WriteBarrier() __asm__ volatile("" ::: "memory")
#define ReadBarrier() __asm__ volatile("" ::: "memory")
#elif LanguageIsGpu
#elif IsLanguageGpu
#define WriteBarrier()
#define ReadBarrier()
#else
@ -248,7 +227,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//- Unused markup
/* Strict unused markup */
#if CompilerIsClang
#if IsCompilerClang
#define UNUSED __attribute((unused))
#else
#define UNUSED
@ -258,7 +237,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define LAX (void)
//- Fallthrough
#if CompilerIsClang
#if IsCompilerClang
#define FALLTHROUGH __attribute((fallthrough))
#else
#define FALLTHROUGH
@ -433,7 +412,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////////////////////////////////
//~ Intrinsic headers
#if LanguageIsC
#if IsLanguageC
/* Intrinsic header info:
* mmintrin.h MMX
* xmmintrin.h SSE
@ -459,14 +438,14 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define AlignedBlock(n) struct alignas(n)
//- Enum
#if LanguageIsC
#if IsLanguageC
#define Enum(name) typedef enum name name; enum name
#else
#define Enum(name) enum name
#endif
//- alignof
#if LanguageIsC && (CompilerIsMsvc || __STDC_VERSION__ < 202311L)
#if IsLanguageC && (IsCompilerMsvc || __STDC_VERSION__ < 202311L)
#define alignof(type) __alignof(type)
#endif
@ -481,7 +460,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define IsArray(a) (IsIndexable(a) && (((void *)&a) == ((void *)a)))
//- offsetof
#if !CompilerIsMsvc
#if !IsCompilerMsvc
#ifdef _CRT_USE_BUILTIN_OFFSETOF
#define offsetof(type, field) __builtin_offsetof(type, field)
#else
@ -496,17 +475,17 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define ZeroFieldRegion(dst, src, r) ZeroBytes(&dst->__begfieldreg__##r, &src->__begfieldreg__##r, (u8 *)&dst->__endfieldreg__##r - (u8 *)&dst->__begfieldreg__##r)
//- Packed
#if CompilerIsMsvc
#if IsCompilerMsvc
#define Packed(s) __pragma(pack(push, 1)) s __pragma(pack(pop))
#elif CompilerIsClang
#elif IsCompilerClang
#define Packed(s) s __attribute((__packed__))
#elif LanguageIsGpu
#elif IsLanguageGpu
#define Packed(s) s
#endif
//- alignas
#if (CompilerIsMsvc && LanguageIsC) || (LanguageIsC && __STDC_VERSION__ < 202311L)
# if CompilerIsMsvc
#if (IsCompilerMsvc && IsLanguageC) || (IsLanguageC && __STDC_VERSION__ < 202311L)
#if IsCompilerMsvc
#define alignas(n) __declspec(align(n))
#else
#define alignas(n) __attribute__((aligned(n)))
@ -517,9 +496,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
////////////////////////////////////////////////////////////
//~ Scalar types
#if LanguageIsC
//- Cpu scalar types
#if IsLanguageC
#include <stdint.h>
typedef int8_t i8;
typedef int16_t i16;
@ -533,17 +510,13 @@ typedef float f32;
typedef double f64;
typedef i8 b8;
typedef u32 b32;
#elif LanguageIsGpu
//- Gpu scalar types
#elif IsLanguageGpu
typedef int i32;
typedef int2 i64;
typedef uint u32;
typedef uint2 u64;
typedef float f32;
typedef uint b32;
#endif
//- Min / max constants
@ -563,7 +536,7 @@ typedef uint b32;
#define I64Min ((i64)0x8000000000000000LL)
//- Float infinity / nan constants
#if LanguageIsC
#if IsLanguageC
Global const u32 _f32_infinity_u32 = 0x7f800000;
Global const f32 *_f32_infinity = (f32 *)&_f32_infinity_u32;
#define F32Infinity (*_f32_infinity)
@ -587,8 +560,7 @@ Global const f64 *_f64_nan = (f64 *)&_f64_nan_u64;
////////////////////////////////////////////////////////////
//~ Atomics
#if LanguageIsC
#if IsLanguageC
//- Atomic types
Struct(Atomic8) { volatile i8 _v; };
Struct(Atomic16) { volatile i16 _v; };
@ -605,7 +577,7 @@ StaticAssert(alignof(Atomic16Padded) == CachelineSize && sizeof(Atomic16Padded)
StaticAssert(alignof(Atomic32Padded) == CachelineSize && sizeof(Atomic32Padded) % CachelineSize == 0);
StaticAssert(alignof(Atomic64Padded) == CachelineSize && sizeof(Atomic64Padded) % CachelineSize == 0);
#if PlatformIsWindows && ArchIsX64
#if IsPlatformWindows && IsArchX64
//- Memory barriers
# define CompilerMemoryBarrier() _ReadWriteBarrier()
# define HardwareMemoryBarrier() MemoryBarrier()
@ -640,13 +612,12 @@ ForceInline i64 Atomic64FetchAdd (Atomic64 *x, i64 a) { return
#else
#error Atomics not implemented
#endif
#endif
////////////////////////////////////////////////////////////
//~ Ticket mutex
#if LanguageIsC
#if IsLanguageC
Struct(TicketMutex)
{
Atomic64Padded ticket;
@ -672,8 +643,7 @@ ForceInline void UnlockTicketMutex(TicketMutex *tm)
////////////////////////////////////////////////////////////
//~ String types
#if LanguageIsC
#if IsLanguageC
#define STRING(size, data) ((String) { (size), (data) })
#define Zstr ((String) { 0, 0})
#define Lit(cstr_lit) (String) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
@ -726,7 +696,6 @@ Struct(StringList)
StringListNode *last;
u64 count;
};
#endif
////////////////////////////////////////////////////////////
@ -741,8 +710,7 @@ Struct(U128)
////////////////////////////////////////////////////////////
//~ Resource types
#if LanguageIsC
#if IsLanguageC
#define ResourceEmbeddedMagic 0xfc060937194f4406
Struct(ResourceStore)
@ -754,54 +722,71 @@ Struct(ResourceKey)
{
u64 hash;
};
#endif
////////////////////////////////////////////////////////////
//~ Shader types
#if LanguageIsC
Struct(GpuPointer) { u32 v; };
Struct(GpuBufferPos) { GpuPointer p; u64 byte_offset; };
Inline b32 IsGpuPointerNil(GpuPointer p) { return p.v == 0; }
#if IsLanguageC
//- Shader linkage
Struct(VertexShader) { ResourceKey resource; };
Struct(PixelShader) { ResourceKey resource; };
Struct(ComputeShader) { ResourceKey resource; };
//- Resource descriptor index types
Struct(StructuredBufferRid) { u32 v; };
Struct(RWStructuredBufferRid) { u32 v; };
Struct(Texture1DRid) { u32 v; };
Struct(Texture2DRid) { u32 v; };
Struct(Texture3DRid) { u32 v; };
Struct(RWTexture1DRid) { u32 v; };
Struct(RWTexture2DRid) { u32 v; };
Struct(RWTexture3DRid) { u32 v; };
Struct(SamplerStateRid) { u32 v; };
//- Pointers
#elif LanguageIsGpu
typedef u32 GpuBuffer;
typedef u32 GpuTexture;
typedef u32 GpuSampler;
Struct(GpuBufferPtr) { u32 v; };
Struct(GpuRWBufferPtr) { u32 v; };
Struct(GpuIndexBufferPtr) { u32 v; };
Struct(GpuTexture1DPtr) { u32 v; };
Struct(GpuRWTexture1DPtr) { u32 v; };
Struct(GpuTexture2DPtr) { u32 v; };
Struct(GpuRWTexture2DPtr) { u32 v; };
Struct(GpuTexture3DPtr) { u32 v; };
Struct(GpuRWTexture3DPtr) { u32 v; };
Struct(GpuRasterTargetPtr) { u32 v; };
Struct(GpuSamplerPtr) { u32 v; };
#define IsGpuPtrNil(p) ((p).v == 0)
#elif IsLanguageGpu
//- Shader declaration
# define ComputeShader(name, x, y, z) [numthreads(x, y, z)] void name(Semantic(Vec3U32, SV_DispatchThreadID))
#define ComputeShader(name, x) [numthreads(x, 1, 1)] void name(Semantic(u32, SV_DispatchThreadID))
#define ComputeShader2D(name, x, y) [numthreads(x, y, 1)] void name(Semantic(Vec2U32, SV_DispatchThreadID))
#define ComputeShader3D(name, x, y, z) [numthreads(x, y, z)] void name(Semantic(Vec3U32, SV_DispatchThreadID))
#define VertexShader(name, return_type) return_type name(Semantic(u32, SV_VertexID), Semantic(u32, SV_InstanceID))
#define PixelShader(name, return_type, ...) return_type name(__VA_ARGS__)
//- Semantic declaration
# define Semantic(t, n) t n : n
//- Descriptor heap index
# define UniformResourceFromRid(rid) ResourceDescriptorHeap[rid]
# define UniformSamplerFromRid(rid) SamplerDescriptorHeap[rid]
# define NonUniformResourceFromRid(rid) ResourceDescriptorHeap[NonUniformResourceIndex(rid)]
# define NonUniformSamplerFromRid(rid) SamplerDescriptorHeap[NonUniformResourceIndex(rid)]
//- Pointers
typedef GpuBufferPtr u32;
typedef GpuRWBufferPtr u32;
typedef GpuIndexBufferPtr u32;
typedef GpuTexture1DPtr u32;
typedef GpuRWTexture1DPtr u32;
typedef GpuTexture2DPtr u32;
typedef GpuRWTexture2DPtr u32;
typedef GpuTexture3DPtr u32;
typedef GpuRWTexture3DPtr u32;
typedef GpuRasterTargetPtr u32;
typedef GpuSamplerPtr u32;
#define IsGpuPtrNil(p) ((p) == 0)
//- Pointer dereference
#define DerefUniformBuffer(p) ResourceDescriptorHeap[p]
#define DerefUniformTexture(p) ResourceDescriptorHeap[p]
#define DerefUniformSampler(p) SamplerDescriptorHeap[p]
#define DerefNonUniformBuffer(p) ResourceDescriptorHeap[NonUniformResourceIndex(p)]
#define DerefNonUniformTexture(p) ResourceDescriptorHeap[NonUniformResourceIndex(p)]
#define DerefNonUniformSampler(p) SamplerDescriptorHeap[NonUniformResourceIndex(p)]
#endif
////////////////////////////////////////////////////////////
@ -810,8 +795,8 @@ typedef u32 GpuSampler;
#define MaxFibers 4096
StaticAssert(MaxFibers < I16Max); /* MaxFibers should fit in FiberId */
#if LanguageIsC
# if PlatformIsWindows
#if IsLanguageC
#if IsPlatformWindows
#define FiberId() (*(volatile i16 *)__readgsqword(0x20))
#else
#error FiberId not implemented
@ -821,7 +806,7 @@ StaticAssert(MaxFibers < I16Max); /* MaxFibers should fit in FiberId */
////////////////////////////////////////////////////////////
//~ Exit callback types
#if LanguageIsC
#if IsLanguageC
#define ExitFuncDef(name) void name(void)
typedef ExitFuncDef(ExitFunc);
#endif
@ -829,8 +814,7 @@ typedef ExitFuncDef(ExitFunc);
////////////////////////////////////////////////////////////
//~ @hookdecl Api hooks
#if LanguageIsC
#if IsLanguageC
//- Core hooks
StringList GetRawCommandline(void);
void Echo(String msg);
@ -845,7 +829,6 @@ void ExitNow(i32 code);
//- Meta hooks
void StartupLayers(void);
#endif
////////////////////////////////////////////////////////////

View File

@ -4,7 +4,7 @@
//- Api
#include "base.h"
#if LanguageIsC
#if IsLanguageC
# include "base_intrinsics.h"
# include "base_memory.h"
# include "base_arena.h"
@ -26,12 +26,12 @@
# include "base_bitbuff.h"
# include "base_resource.h"
# include "base_controller.h"
#elif LanguageIsGpu
#elif IsLanguageGpu
# include "base_math_gpu.h"
#endif
//- Impl
#if LanguageIsC
#if IsLanguageC
# include "base_memory.c"
# include "base_arena.c"
# include "base_futex.c"
@ -50,6 +50,6 @@
#endif
//- Include base_win32
#if LanguageIsC && PlatformIsWindows
#if IsLanguageC && IsPlatformWindows
# include "base_win32/base_win32_inc.h"
#endif

View File

@ -85,7 +85,7 @@ JobPoolId AsyncPool(void);
void job(job##_Sig *, i32); \
StaticAssert(1)
#define JobDef(job, sig_arg, id_arg) void job(job##_Sig *sig_arg, i32 id_arg)
#define JobImpl(job, sig_arg, id_arg) void job(job##_Sig *sig_arg, i32 id_arg)
////////////////////////////////////////////////////////////
//~ @hookdecl Job dispatch operations

View File

@ -29,7 +29,7 @@ Struct(LogEventsArray)
/* Log level configuration */
#ifndef LogLevel_CompTime
# if RtcIsEnabled || ProfilingIsEnabled
# if IsRtcEnabled || IsProfilingEnabled
# define LogLevel_CompTime LogLevel_Debug
# else
# define LogLevel_CompTime LogLevel_Info

View File

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//~ Win32 memory allocation
#if PlatformIsWindows
#if IsPlatformWindows
//- Reserve
void *ReserveMemory(u64 size)
@ -42,12 +42,12 @@ void SetMemoryReadWrite(void *address, u64 size)
#else
# error Memory allocation not implemented for this platform
#endif /* PlatformIsWindows */
#endif /* IsPlatformWindows */
////////////////////////////////////////////////////////////
//~ Crtlib mem op stubs
#if !CrtlibIsEnabled
#if !IsCrtlibEnabled
//- memcpy
__attribute((section(".text.memcpy")))
@ -92,4 +92,4 @@ i32 memcmp(const void *p1, const void *p2, u64 count)
return result;
}
#endif /* !CrtlibIsEnabled */
#endif /* !IsCrtlibEnabled */

View File

@ -33,7 +33,7 @@ void SetMemoryReadWrite(void *address, u64 size);
////////////////////////////////////////////////////////////
//~ Crtlib stubs
#if CrtlibIsEnabled
#if IsCrtlibEnabled
# include <memory.h>
#else
void *memcpy(void *__restrict dst, const void *__restrict src, u64 n);

View File

@ -55,7 +55,7 @@ Lock LockSpinE(Mutex *m, i32 spin)
}
}
#if RtcIsEnabled
#if IsRtcEnabled
Atomic32Set(&m->exclusive_fiber_id, FiberId());
#endif
@ -122,7 +122,7 @@ void Unlock(Lock *l)
Mutex *m = l->mutex;
if (l->exclusive)
{
#if RtcIsEnabled
#if IsRtcEnabled
Atomic32Set(&m->exclusive_fiber_id, 0);
#endif
Atomic32Set(&m->v, 0);

View File

@ -11,7 +11,7 @@ AlignedStruct(Mutex, CachelineSize)
*/
Atomic32 v;
#if RtcIsEnabled
#if IsRtcEnabled
Atomic32 exclusive_fiber_id;
#endif
};
@ -52,7 +52,7 @@ Lock LockS(Mutex *m);
void Unlock(Lock *lock);
//- Lock assertion
#if RtcIsEnabled
#if IsRtcEnabled
# define AssertLockedE(l, m) Assert((l)->mutex == (m) && (l)->exclusive == 1)
# define AssertLockedES(l, m) Assert((l)->mutex == (m))
#else

View File

@ -640,7 +640,7 @@ String FormatStringV(Arena *arena, String fmt, va_list args)
}
}
#if RtcIsEnabled
#if IsRtcEnabled
if (!no_more_args)
{
FmtArg last_arg = va_arg(args, FmtArg);

View File

@ -36,7 +36,7 @@ BOOL W32_FindEmbeddedRcData(HMODULE module, LPCWSTR type, LPWSTR wstr_entry_name
}
////////////////////////////////////////////////////////////
//~ @hookdef Core hooks
//~ @hookimpl Core hooks
StringList GetRawCommandline(void)
{
@ -110,16 +110,16 @@ void TrueRand(String buffer)
}
////////////////////////////////////////////////////////////
//~ @hookdef Swap hooks
//~ @hookimpl Swap hooks
b32 IsSwappedIn(void)
{
return HotSwappingIsEnabled;
return IsHotSwappingEnabled;
}
b32 IsSwappingOut(void)
{
return HotSwappingIsEnabled;
return IsHotSwappingEnabled;
}
String SwappedStateFromName(Arena *arena, String name)
@ -171,7 +171,7 @@ void WriteSwappedState(String name, String data)
}
////////////////////////////////////////////////////////////
//~ @hookdef Exit hooks
//~ @hookimpl Exit hooks
void OnExit(ExitFunc *func)
{
@ -199,7 +199,7 @@ void ExitNow(i32 code)
////////////////////////////////////////////////////////////
//~ Startup / shutdown jobs
JobDef(W32_StartupLayers, UNUSED sig, UNUSED id)
JobImpl(W32_StartupLayers, UNUSED sig, UNUSED id)
{
W32_SharedState *g = &W32_shared_state;
TempArena scratch = BeginScratchNoConflict();
@ -210,7 +210,7 @@ JobDef(W32_StartupLayers, UNUSED sig, UNUSED id)
EndScratch(scratch);
}
JobDef(W32_ShutdownLayers, UNUSED sig, UNUSED id)
JobImpl(W32_ShutdownLayers, UNUSED sig, UNUSED id)
{
__prof;
W32_SharedState *g = &W32_shared_state;
@ -231,7 +231,7 @@ i32 W32_Main(void)
__profthread("Main thread", PROF_THREAD_GROUP_MAIN);
W32_SharedState *g = &W32_shared_state;
#if ProfilingIsEnabled
#if IsProfilingEnabled
/* Start profiler */
{
__profn("Launch profiler");
@ -436,7 +436,7 @@ i32 W32_Main(void)
////////////////////////////////////////////////////////////
//~ Crt main
#if CrtlibIsEnabled
#if IsCrtlibEnabled
# if IsConsoleApp
int main(UNUSED char **argc, UNUSED int argv)
{
@ -448,12 +448,12 @@ int CALLBACK wWinMain(UNUSED _In_ HINSTANCE instance, UNUSED _In_opt_ HINSTANCE
return W32_Main();
}
# endif /* IsConsoleApp */
#endif /* CrtlibIsEnabled */
#endif /* IsCrtlibEnabled */
////////////////////////////////////////////////////////////
//~ Crt stub
#if !CrtlibIsEnabled
#if !IsCrtlibEnabled
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
@ -472,4 +472,4 @@ void __stdcall wWinMainCRTStartup(void)
#pragma clang diagnostic pop
#endif /* !CrtlibIsEnabled */
#endif /* !IsCrtlibEnabled */

View File

@ -1,7 +1,7 @@
W32_SharedJobState W32_shared_job_state = ZI;
////////////////////////////////////////////////////////////
//~ @hookdef Startup
//~ @hookimpl Startup
void InitJobSystem(void)
{
@ -23,7 +23,7 @@ void InitJobSystem(void)
////////////////////////////////////////////////////////////
//~ Win32 thread
JobDef(W32_DummyJob, sig, id)
JobImpl(W32_DummyJob, sig, id)
{
}
@ -456,7 +456,7 @@ W32_ThreadDef(W32_JobWorkerEntryPoint, worker_ctx_arg)
}
////////////////////////////////////////////////////////////
//~ @hookdef Fiber suspend/resume operations
//~ @hookimpl Fiber suspend/resume operations
void SuspendFiber(void)
{
@ -556,7 +556,7 @@ void ResumeFibers(i16 fiber_ids_count, i16 *fiber_ids)
}
////////////////////////////////////////////////////////////
//~ @hookdef Job pool operations
//~ @hookimpl Job pool operations
JobPoolId InitJobPool(u32 thread_count, String name, JobPoolPriority priority)
{
@ -602,7 +602,7 @@ JobPoolId HyperPool(void)
}
////////////////////////////////////////////////////////////
//~ @hookdef Job operations
//~ @hookimpl Job operations
Job *OpenJob(JobFunc *func, JobPoolId pool_id)
{
@ -649,7 +649,6 @@ u32 CloseJob(Job *job)
if (num_tasks == 0)
{
Assert(0);
job->func = W32_DummyJob;
num_tasks = 1;
}

View File

@ -1,7 +1,7 @@
W32_SharedLogState W32_shared_log_state = ZI;
////////////////////////////////////////////////////////////
//~ @hookdef Init hooks
//~ @hookimpl Init hooks
void InitLogSystem(String logfile_path)
{
@ -101,7 +101,7 @@ void W32_Log(i32 level, String msg)
}
////////////////////////////////////////////////////////////
//~ @hookdef Log hooks
//~ @hookimpl Log hooks
/* Panic log function is separate to enforce zero side effects other than
* immediately writing to log file. */

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////
//~ @hookdef DateTime hooks
//~ @hookimpl DateTime hooks
DateTime LocalDateTime(void)
{

View File

@ -4,7 +4,7 @@
#if COLLIDER_DEBUG
void CLD_DebugBreakable(void)
{
#if RtcIsEnabled
#if IsRtcEnabled
DEBUGBREAKABLE;
#endif
}

View File

@ -3,14 +3,14 @@
#define WRITE_DIR "power_play"
/* Window title */
#if RtcIsEnabled
# if DeveloperIsEnabled
#if IsRtcEnabled
# if IsDeveloperModeEnabled
# define WINDOW_TITLE "Debug (Developer Build)"
# else
# define WINDOW_TITLE "Debug"
# endif
#else
# if DeveloperIsEnabled
# if IsDeveloperModeEnabled
# define WINDOW_TITLE "Power Play (Developer Build)"
# else
# define WINDOW_TITLE "Power Play"
@ -80,7 +80,7 @@
/* If enabled, bitbuffs will insert/verify magic numbers & length for each read & write */
#define BITBUFF_DEBUG 0
#define BITBUFF_TEST RtcIsEnabled
#define BITBUFF_TEST IsRtcEnabled
/* If enabled, things like network writes & memory allocations will be tracked in a global statistics struct */
#define GstatIsEnabled 1

View File

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//~ Font load job
JobDef(F_Load, sig, _)
JobImpl(F_Load, sig, _)
{
__prof;
TempArena scratch = BeginScratchNoConflict();

View File

@ -7,51 +7,53 @@ void GPU_StartupCommon(void)
{
GPU_SharedUtilState *g = &GPU_shared_util_state;
GPU_Arena *gpu_perm = GPU_Perm();
GPU_ArenaHandle gpu_perm = GPU_PermArena();
/* Upload data to gpu */
GPU_CommandList *cl = GPU_OpenCommandList(GPU_QueueKind_Direct);
/* Init point sampler */
GPU_ResourceHandle pt_sampler = GPU_PushSampler(gpu_perm, (GPU_SamplerDesc) { .filter = GPU_Filter_MinMagMipPoint });
g->pt_sampler = GPU_PushSamplerPtr(gpu_perm, pt_sampler);
GPU_CommandListHandle cl = GPU_OpenCommandList(GPU_QueueKind_Direct);
{
/* Init noise texture */
String noise_data = DataFromResource(ResourceKeyFromStore(&GPU_Resources, Lit("noise_128x128x64_16.dat")));
Vec3I32 noise_dims = VEC3I32(128, 128, 64);
GpuPointer noise_tex = ZI;
GPU_ResourceHandle noise_tex = ZI;
{
GPU_TextureDesc noise_desc = ZI;
noise_desc.format = GPU_Format_R16_Uint;
noise_desc.size = noise_dims;
if (noise_data.len != noise_dims.x * noise_dims.y * noise_dims.z * 2)
{
Panic(Lit("Unexpected noise texture size"));
}
noise_tex = GPU_PushTexture(gpu_perm, GPU_TextureKind_2D, GPU_Format_R16_Uint, noise_dims, GPU_TextureFlag_None);
GPU_CopyFromCpu(cl, noise_tex, noise_data);
noise_tex = GPU_PushTexture3D(gpu_perm, noise_dims, GPU_Format_R16_Uint, GPU_AccessKind_CopyWrite);
GPU_CopyResourceFromCpu(cl, noise_tex, noise_data);
}
g->noise_tex = noise_tex;
/* Init quad index buffer */
GpuPointer quad_indices = ZI;
GPU_ResourceHandle quad_indices = ZI;
{
u16 quad_data[6] = { 0, 1, 2, 0, 2, 3 };
quad_indices = GPU_PushBuffer(gpu_perm, u16, countof(quad_data), GPU_BufferFlag_None);
GPU_CopyFromCpu(cl, quad_indices, StringFromArray(quad_data));
quad_indices = GPU_PushBuffer(gpu_perm, u16, GPU_AccessKind_CopyWrite);
GPU_CopyResourceFromCpu(cl, quad_indices, StringFromArray(quad_data));
}
g->quad_indices = quad_indices;
g->noise_tex = GPU_PushTexture3DPtr(gpu_perm, noise_tex);
g->quad_indices = GPU_PushIndexBufferPtr(gpu_perm, quad_indices, u16);
/* FIXME: Block other queues until common startup finishes here */
GPU_SetAccess(cl, noise_tex, GPU_AccessKind_AnyRead);
GPU_SetAccess(cl, quad_indices, GPU_AccessKind_AnyRead);
}
GPU_CloseCommandList(cl);
/* Init point sampler */
g->pt_sampler = GPU_PushSampler(gpu_perm, (GPU_SamplerDesc) { .filter = GPU_Filter_MinMagMipPoint });
}
////////////////////////////////////////////////////////////
//~ Arena helpers
GPU_Arena *GPU_Perm(void)
GPU_ArenaHandle GPU_PermArena(void)
{
i16 fiber_id = FiberId();
GPU_Arena *perm = GPU_shared_util_state.perm_arenas[fiber_id];
if (!perm)
GPU_ArenaHandle perm = GPU_shared_util_state.perm_arenas[fiber_id];
if (IsGpuPtrNil(perm))
{
GPU_shared_util_state.perm_arenas[fiber_id] = GPU_AcquireArena();
perm = GPU_shared_util_state.perm_arenas[fiber_id];
@ -59,20 +61,28 @@ GPU_Arena *GPU_Perm(void)
return perm;
}
////////////////////////////////////////////////////////////
//~ Cpu -> Gpu copy helpers
void GPU_CopyResourceFromCpu(GPU_CommandListHandle cl, GPU_ResourceHandle dst, String src)
{
/* TODO */
}
////////////////////////////////////////////////////////////
//~ Common resource helpers
GpuPointer GPU_GetCommonPointSampler(void)
GpuSamplerPtr GPU_GetCommonPointSampler(void)
{
return GPU_shared_util_state.pt_sampler;
}
GpuPointer GPU_GetCommonQuadIndices(void)
GpuIndexBufferPtr GPU_GetCommonQuadIndices(void)
{
return GPU_shared_util_state.quad_indices;
}
GpuPointer GPU_GetCommonNoise(void)
GpuTexture3DPtr GPU_GetCommonNoise(void)
{
return GPU_shared_util_state.noise_tex;
}

View File

@ -4,11 +4,11 @@
Struct(GPU_SharedUtilState)
{
/* Common shared resources */
GpuPointer pt_sampler;
GpuPointer quad_indices;
GpuPointer noise_tex;
GpuSamplerPtr pt_sampler;
GpuIndexBufferPtr quad_indices;
GpuTexture3DPtr noise_tex;
GPU_Arena *perm_arenas[MaxFibers];
GPU_ArenaHandle perm_arenas[MaxFibers];
} extern GPU_shared_util_state;
////////////////////////////////////////////////////////////
@ -19,11 +19,16 @@ void GPU_StartupCommon(void);
////////////////////////////////////////////////////////////
//~ Arena helpers
GPU_Arena *GPU_Perm(void);
GPU_ArenaHandle GPU_PermArena(void);
////////////////////////////////////////////////////////////
//~ Cpu -> Gpu copy helpers
void GPU_CopyResourceFromCpu(GPU_CommandListHandle cl, GPU_ResourceHandle dst, String src);
////////////////////////////////////////////////////////////
//~ Common resource helpers
GpuPointer GPU_GetCommonPointSampler(void);
GpuPointer GPU_GetCommonQuadIndices(void);
GpuPointer GPU_GetCommonNoise(void);
GpuSamplerPtr GPU_GetCommonPointSampler(void);
GpuIndexBufferPtr GPU_GetCommonQuadIndices(void);
GpuTexture3DPtr GPU_GetCommonNoise(void);

View File

@ -1,17 +1,22 @@
////////////////////////////////////////////////////////////
//~ Opaque types
//~ Handle types
Struct(GPU_Arena);
Struct(GPU_CommandList);
Struct(GPU_Swapchain);
Struct(GPU_ArenaHandle) { u64 v; };
Struct(GPU_CommandListHandle) { u64 v; };
Struct(GPU_ResourceHandle) { u64 v; };
Struct(GPU_SwapchainHandle) { u64 v; };
////////////////////////////////////////////////////////////
//~ Queue types
#define GPU_MultiQueueEnabled !ProfilingIsEnabled
#define GPU_MultiQueueIsEnabled (!IsProfilingEnabled)
Enum(GPU_QueueKind)
{
#if GPU_MultiQueueEnabled
#if GPU_MultiQueueIsEnabled
GPU_QueueKind_Direct = 0,
GPU_QueueKind_AsyncCompute = 1,
GPU_QueueKind_AsyncCopy = 2,
@ -156,22 +161,36 @@ Enum(GPU_Format)
};
////////////////////////////////////////////////////////////
//~ Shader access types
//~ Access types
Enum(GPU_ShaderAccessKind)
Enum(GPU_AccessKind)
{
GPU_ShaderAccessKind_Readonly, /* Default state for all resources */
GPU_ShaderAccessKind_ReadWrite,
GPU_ShaderAccessKind_RasterTarget,
};
GPU_AccessKind_AnyRead,
////////////////////////////////////////////////////////////
//~ Arena types
GPU_AccessKind_AnyReadWrite,
Struct(GPU_TempArena)
{
GPU_Arena *arena;
u64 start_pos;
GPU_AccessKind_CopyRead,
GPU_AccessKind_CopyWrite,
GPU_AccessKind_AnyShaderRead,
GPU_AccessKind_AnyShaderReadWrite,
GPU_AccessKind_ComputeRead,
GPU_AccessKind_ComputeReadWrite,
GPU_AccessKind_VertexPixelRead,
GPU_AccessKind_VertexPixelReadWrite,
GPU_AccessKind_VertexRead,
GPU_AccessKind_VertexReadWrite,
GPU_AccessKind_PixelRead,
GPU_AccessKind_PixelReadWrite,
GPU_AccessKind_DepthStencilRead,
GPU_AccessKind_DepthStencilReadWrite,
GPU_AccessKind_RasterTargetWrite,
};
////////////////////////////////////////////////////////////
@ -183,6 +202,13 @@ Enum(GPU_BufferFlag)
GPU_BufferFlag_Writable = (1 << 0),
};
Struct(GPU_BufferDesc)
{
u64 size;
GPU_BufferFlag flags;
GPU_AccessKind initial_access;
};
////////////////////////////////////////////////////////////
//~ Texture types
@ -191,8 +217,8 @@ Enum(GPU_BufferFlag)
Enum(GPU_TextureFlag)
{
GPU_TextureFlag_None = 0,
GPU_TextureFlag_Writable = (1 << 0),
GPU_TextureFlag_Rasterizable = (1 << 1),
GPU_TextureFlag_AllowWritable = (1 << 0),
GPU_TextureFlag_AllowRasterTarget = (1 << 1),
};
Enum(GPU_TextureKind)
@ -204,11 +230,13 @@ Enum(GPU_TextureKind)
Struct(GPU_TextureDesc)
{
GPU_TextureFlag flags;
GPU_TextureKind kind;
GPU_Format format;
Vec3I32 size;
Vec3I32 dims;
GPU_TextureFlag flags;
GPU_AccessKind initial_access;
i32 mip_levels; /* Will be clamped to range [1, max] */
Vec4 clear_color;
i32 mip_levels;
};
////////////////////////////////////////////////////////////
@ -314,8 +342,8 @@ Enum(GPU_RasterMode)
GPU_RasterMode_LineList,
GPU_RasterMode_LineStrip,
GPU_RasterMode_TriangleList,
GPU_RasterMode_WireTriangleList,
GPU_RasterMode_TriangleStrip,
GPU_RasterMode_WireTriangleList,
GPU_RasterMode_WireTriangleStrip,
};
@ -333,6 +361,8 @@ Struct(GPU_Stats)
/* Resources */
u64 driver_resources_allocated;
u64 driver_descriptors_allocated;
/* TODO: Arena stats (committed, reserved, etc) */
};
////////////////////////////////////////////////////////////
@ -341,66 +371,133 @@ Struct(GPU_Stats)
void GPU_Startup(void);
////////////////////////////////////////////////////////////
//~ @hookdecl Arenas
//~ @hookdecl Arena
GPU_Arena *GPU_AcquireArena(void);
void GPU_ReleaseArena(GPU_Arena *arena);
GPU_ArenaHandle GPU_AcquireArena(void);
void GPU_ReleaseArena(GPU_ArenaHandle arena);
////////////////////////////////////////////////////////////
//~ @hookdecl Resource creation
//~ @hookdecl Resource
GpuPointer GPU_PushBufferEx(GPU_Arena *arena, i32 element_size, i32 element_align, i32 element_count, GPU_BufferFlag flags);
#define GPU_PushBuffer(arena, type, count, flags) GPU_PushBufferEx((arena), sizeof(type), alignof(type), (count), (flags))
//- Resource creation
GpuPointer GPU_PushTextureEx(GPU_Arena *arena, GPU_TextureDesc desc);
GpuPointer GPU_PushTexture(GPU_Arena *arena, GPU_TextureKind kind, GPU_Format format, Vec3I32 size, GPU_TextureFlag flags);
GPU_ResourceHandle GPU_PushBufferEx(GPU_ArenaHandle arena, GPU_BufferDesc desc);
GPU_ResourceHandle GPU_PushTextureEx(GPU_ArenaHandle arena, GPU_TextureDesc desc);
GPU_ResourceHandle GPU_PushSampler(GPU_ArenaHandle arena, GPU_SamplerDesc desc);
GpuPointer GPU_PushSampler(GPU_Arena *arena, GPU_SamplerDesc desc);
#define GPU_PushBuffer(arena, type, count, ...) GPU_PushBufferEx((arena), \
(GPU_BufferDesc) { \
.initial_access = GPU_AccessKind_AnyReadWrite, \
.size = sizeof(type) * (count), \
__VA_ARGS__ \
} \
)
#define GPU_PushTexture1D(arena, _size, _format, _initial_access) GPU_PushTextureEx((arena), \
(GPU_TextureDesc) { \
.kind = GPU_TextureKind_1D, \
.format = (_format), \
.dims = Vec3I32((_size), 1, 1), \
.initial_access = (_initial_access), \
__VA_ARGS__ \
} \
)
#define GPU_PushTexture2D(arena, _size, _format, _initial_access) GPU_PushTextureEx((arena), \
(GPU_TextureDesc) { \
.kind = GPU_TextureKind_2D, \
.format = (_format), \
.dims = Vec3I32((_size).x, (_size).y, 1), \
.initial_access = (_initial_access), \
__VA_ARGS__ \
} \
)
#define GPU_PushTexture3D(arena, _size, _format, _initial_access) GPU_PushTextureEx((arena), \
(GPU_TextureDesc) { \
.kind = GPU_TextureKind_3D, \
.format = (_format), \
.dims = (_size), \
.initial_access = (_initial_access), \
__VA_ARGS__ \
} \
)
//- Pointer creation
GpuBufferPtr GPU_PushBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
GpuRWBufferPtr GPU_PushRWBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
GpuIndexBufferPtr GPU_PushIndexBufferPtrEx (GPU_ArenaHandle arena, GPU_ResourceHandle resource, u32 element_size, RngU32 element_range);
GpuTexture1DPtr GPU_PushTexture1DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
GpuRWTexture1DPtr GPU_PushRWTexture1DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
GpuTexture2DPtr GPU_PushTexture2DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
GpuRWTexture2DPtr GPU_PushRWTexture2DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
GpuTexture3DPtr GPU_PushTexture3DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
GpuRWTexture3DPtr GPU_PushRWTexture3DPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
GpuRasterTargetPtr GPU_PushRasterTargetPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
GpuSamplerPtr GPU_PushSamplerPtr (GPU_ArenaHandle arena, GPU_ResourceHandle resource);
#define GPU_PushBufferPtr(arena, resource, type) GPU_PushBufferPtrEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
#define GPU_PushRWBufferPtr(arena, resource, type) GPU_PushRWBufferPtrEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
#define GPU_PushIndexBufferPtr(arena, resource, type) GPU_PushIndexBufferPtrEx((arena), (resource), sizeof(type), RNGU32(0, GPU_CountBuffer((resource), type)))
//- Count
u64 GPU_CountBufferEx(GPU_ResourceHandle buffer, u64 element_size);
u64 GPU_Count1D(GPU_ResourceHandle texture1d);
u64 GPU_Count2D(GPU_ResourceHandle texture2d);
u64 GPU_Count3D(GPU_ResourceHandle texture3d);
#define GPU_CountBuffer(buffer, type) GPU_CountBufferEx((buffer), sizeof(type))
////////////////////////////////////////////////////////////
//~ @hookdecl Commands
//~ @hookdecl Command
//- Command list creation
GPU_CommandList *GPU_OpenCommandList(GPU_QueueKind queue);
void GPU_CloseCommandList(GPU_CommandList *cl);
//- Command list
GPU_CommandListHandle GPU_OpenCommandList(GPU_QueueKind queue);
void GPU_CloseCommandList(GPU_CommandListHandle cl);
//- Cpu -> Gpu
void GPU_CopyBytesFromCpu(GPU_CommandList *cl, GpuPointer dst, RngU64 dst_range, void *src);
void GPU_CopyTexelsFromCpu(GPU_CommandList *cl, GpuPointer dst, Rng3U64 dst_range, void *src);
void GPU_CopyFromCpu(GPU_CommandList *cl, GpuPointer dst, String src);
//- Arena
void GPU_ResetArena(GPU_CommandListHandle cl, GPU_ArenaHandle arena);
//- Gpu -> Cpu
void GPU_AddCpuFence(GPU_CommandList *cl, Fence *fence, i64 v);
void GPU_SetCpuFence(GPU_CommandList *cl, Fence *fence, i64 v);
//- Copy
void GPU_CopyBuffer(GPU_CommandListHandle cl, GPU_ResourceHandle dst, u64 dst_offset, GPU_ResourceHandle src, u64 src_offset, u64 size);
void GPU_CopyTexture(GPU_CommandListHandle cl, GPU_ResourceHandle dst, Vec3I32 dst_offset, GPU_ResourceHandle src, Vec3I32 src_offset, Vec3I32 dims);
//- Implicit state
void GPU_SetShaderAccess(GPU_CommandList *cl, GpuPointer ptr, GPU_ShaderAccessKind access_kind);
void GPU_SetRasterizeMode(GPU_CommandList *cl, GPU_RasterMode mode);
void GPU_SetConstantU32(GPU_CommandList *cl, i32 slot, u32 v);
void GPU_SetConstantF32(GPU_CommandList *cl, i32 slot, f32 v);
void GPU_SetConstantPtr(GPU_CommandList *cl, i32 slot, GpuPointer v);
//- Constants
void GPU_SetConstU32 (GPU_CommandListHandle cl, i32 slot, u32 v);
void GPU_SetConstF32 (GPU_CommandListHandle cl, i32 slot, f32 v);
void GPU_SetConstBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuBufferPtr v);
void GPU_SetConstRWBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuRWBufferPtr v);
void GPU_SetConstIndexBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuIndexBufferPtr v);
void GPU_SetConstTexture1DPtr (GPU_CommandListHandle cl, i32 slot, GpuTexture1DPtr v);
void GPU_SetConstRWTexture1DPtr (GPU_CommandListHandle cl, i32 slot, GpuRWTexture1DPtr v);
void GPU_SetConstTexture2DPtr (GPU_CommandListHandle cl, i32 slot, GpuTexture2DPtr v);
void GPU_SetConstRWTexture2DPtr (GPU_CommandListHandle cl, i32 slot, GpuRWTexture2DPtr v);
void GPU_SetConstTexture3DPtr (GPU_CommandListHandle cl, i32 slot, GpuTexture3DPtr v);
void GPU_SetConstRWTexture3DPtr (GPU_CommandListHandle cl, i32 slot, GpuRWTexture3DPtr v);
void GPU_SetConstRasterTargetPtr (GPU_CommandListHandle cl, i32 slot, GpuRasterTargetPtr v);
void GPU_SetConstSamplerPtr (GPU_CommandListHandle cl, i32 slot, GpuSamplerPtr v);
//- Clear
void GPU_ClearRasterTarget(GPU_CommandList *cl, GpuPointer target);
//- Access
void GPU_SetAccess(GPU_CommandListHandle cl, GPU_ResourceHandle resource, GPU_AccessKind kind);
//- Compute
void GPU_Compute(GPU_CommandList *cl, ComputeShader cs, Vec3U32 threads);
void GPU_Compute(GPU_CommandListHandle cl, ComputeShader cs, Vec3I32 groups);
//- Rasterize
void GPU_RasterizeEx(GPU_CommandList *cl,
void GPU_Rasterize(GPU_CommandListHandle cl,
VertexShader vs, PixelShader ps,
u32 instances_count,
GpuPointer idx_buff, RngU64 idx_buff_range,
u32 raster_targets_count, GpuPointer *raster_targets,
Rng3 viewport, Rng2 scissor);
u32 instances_count, GpuIndexBufferPtr idx_buff,
u32 raster_targets_count, GpuRasterTargetPtr *raster_targets,
Rng3 viewport, Rng2 scissor,
GPU_RasterMode mode);
void GPU_Rasterize(GPU_CommandList *cl,
VertexShader vs, PixelShader ps,
u32 instances_count, GpuPointer idx_buff,
u32 raster_targets_count, GpuPointer *raster_targets);
//- Clear
void GPU_ClearRasterTarget(GPU_CommandListHandle cl, GpuRasterTargetPtr ptr);
//- Profiling
void GPU_ProfN(GPU_CommandList *cl, String name);
//- Profile
void GPU_ProfN(GPU_CommandListHandle cl, String name);
////////////////////////////////////////////////////////////
//~ @hookdecl Statistics
@ -410,15 +507,19 @@ GPU_Stats GPU_QueryStats(void);
////////////////////////////////////////////////////////////
//~ @hookdecl Swapchain
GPU_Swapchain *GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size);
void GPU_ReleaseSwapchain(GPU_Swapchain *swapchain);
GPU_SwapchainHandle GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size);
void GPU_ReleaseSwapchain(GPU_SwapchainHandle swapchain);
/* Waits until a new backbuffer is ready to be written to.
* This should be called before rendering for minimum latency. */
void GPU_YieldOnSwapchain(GPU_Swapchain *swapchain);
void GPU_YieldOnSwapchain(GPU_SwapchainHandle swapchain);
/* 1. Recreates backbuffer at desired size if necessary
* 2. Blits the source texture into the backbuffer
* 3. Presents the backbuffer
* 2. Clears the backbuffer using clear color
* 3. Blits the source texture into the backbuffer
* 4. Presents the backbuffer
*/
void GPU_PresentSwapchain(GPU_Swapchain *swapchain, Vec2I32 dst_size, Rng2I32 dst_range, GpuPointer src, Vec2I32 src_pos, i32 vsync, Vec4 clear_color);
void GPU_PresentSwapchain(GPU_SwapchainHandle swapchain, Vec4 dst_clear_color,
Vec2U32 dst_size, Vec2U32 dst_offset,
GpuTexture2DPtr src, Vec2U32 src_offset,
i32 vsync);

File diff suppressed because it is too large Load Diff

View File

@ -20,9 +20,17 @@
| ((GPU_D12_FrameLatency != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT))
#define GPU_D12_MaxCbvSrvUavDescriptors (1024 * 64)
#define GPU_D12_MaxCbvSrvUavDescriptors (1024 * 128)
#define GPU_D12_MaxSamplerDescriptors (1024 * 1)
#define GPU_D12_MaxRtvDescriptors (1024 * 1)
#define GPU_D12_MaxRtvDescriptors (1024 * 64)
////////////////////////////////////////////////////////////
//~ Arena types
Struct(GPU_D12_Arena)
{
i32 _;
};
////////////////////////////////////////////////////////////
//~ Pipeline types
@ -62,7 +70,9 @@ Struct(GPU_D12_PipelineBin)
Struct(GPU_D12_Descriptor)
{
GPU_D12_Descriptor *next_free;
struct GPU_D12_DescriptorHeap *heap;
struct GPU_D12_Resource *resource;
b32 valid;
u32 index;
@ -92,23 +102,18 @@ Struct(GPU_D12_DescriptorHeap)
Struct(GPU_D12_Resource)
{
GPU_D12_Resource *next_free;
GPU_ResourceDesc desc;
ID3D12Resource *d3d_resource;
D3D12_RESOURCE_STATES state;
u64 buffer_size; /* Actual size of buffer in GPU memory */
GPU_D12_Descriptor *srv_descriptor;
GPU_D12_Descriptor *uav_descriptor;
GPU_D12_Descriptor *rtv_descriptor;
GPU_D12_Descriptor *sampler_descriptor;
u64 barrier_gen;
D3D12_RESOURCE_BARRIER_TYPE barrier_type;
D3D12_RESOURCE_STATES barrier_state_after;
D3D12_BARRIER_LAYOUT layout;
/* Buffer info */
GPU_BufferDesc buffer_desc;
D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address;
/* Texture info */
b32 is_texture;
GPU_TextureDesc texture_desc;
};
Struct(GPU_D12_ResourceReuseList)
@ -130,10 +135,16 @@ Struct(GPU_D12_ResourceReuseListBin)
////////////////////////////////////////////////////////////
//~ Queue types
Struct(GPU_D12_CommandQueueDesc)
{
D3D12_COMMAND_LIST_TYPE type;
D3D12_COMMAND_QUEUE_PRIORITY priority;
};
Struct(GPU_D12_Queue)
{
GPU_D12_QueueDesc desc;
ID3D12CommandQueue *d3d_queue;
GPU_D12_CommandQueueDesc desc;
Mutex submit_mutex;
ID3D12Fence *submit_fence;
@ -161,83 +172,107 @@ Struct(GPU_D12_RawCommandList)
////////////////////////////////////////////////////////////
//~ Command list types
Enum(GPU_D12_CommandKind)
{
GPU_D12_CommandKind_None,
#define GPU_D12_CmdsPerChunk 256
/* Barrier */
GPU_D12_CommandKind_TransitionToSrv,
GPU_D12_CommandKind_TransitionToUav,
GPU_D12_CommandKind_TransitionToRtv,
GPU_D12_CommandKind_TransitionToCopySrc,
GPU_D12_CommandKind_TransitionToCopyDst,
GPU_D12_CommandKind_FlushUav,
Enum(GPU_D12_CmdKind)
{
GPU_D12_CmdKind_None,
/* Access */
GPU_D12_CmdKind_SetAccess,
/* Constant */
GPU_D12_CmdKind_SetConstant,
/* Copy */
GPU_D12_CommandKind_Copy,
/* Clear */
GPU_D12_CommandKind_ClearRtv,
/* Rasterize */
GPU_D12_CommandKind_Rasterize,
GPU_D12_CmdKind_Copy,
/* Compute */
GPU_D12_CommandKind_Compute,
GPU_D12_CmdKind_Compute,
/* Rasterize */
GPU_D12_CmdKind_Rasterize,
/* Clear rtv */
GPU_D12_CmdKind_ClearRtv,
};
Struct(GPU_D12_Command)
Struct(GPU_D12_Cmd)
{
GPU_D12_Command *next;
GPU_D12_CommandKind kind;
GPU_D12_CmdKind kind;
union
{
struct
{
GPU_D12_Resource *resource;
i32 rt_slot;
} barrier;
GPU_AccessKind access_kind;
} access;
struct
{
i32 slot;
u32 value;
} constant;
struct
{
GPU_D12_Resource *dst;
GPU_D12_Resource *src;
String src_string;
} copy;
u64 dst_offset;
u64 src_offset;
u64 size;
} copy_bytes;
struct
{
GPU_D12_Resource *resource;
} clear;
GPU_D12_Resource *dst;
GPU_D12_Resource *src;
Vec3I32 dst_offset;
Vec3I32 src_offset;
Vec3I32 size;
} copy_texels;
struct
{
ComputeShader cs;
Vec3I32 groups;
} compute;
struct
{
u32 sig_size;
u8 sig[256];
VertexShader vs;
PixelShader ps;
u32 rts_count;
GPU_Viewport viewport;
GPU_Scissor scissor;
u32 instances_count;
GPU_D12_Resource *index_buffer;
GPU_RasterizeMode mode;
D3D12_INDEX_BUFFER_VIEW ibv;
GPU_D12_Descriptor *rtv_descriptors[GPU_MaxRasterTargets];
Rng3 viewport;
Rng2 scissor;
GPU_RasterMode mode;
} rasterize;
struct
{
u32 sig_size;
u8 sig[256];
ComputeShader cs;
u32 num_threads_x;
u32 num_threads_y;
u32 num_threads_z;
} compute;
GPU_D12_Descriptor *rtv_descriptor;
} clear_rtv;
};
};
Struct(GPU_D12_CommandList)
Struct(GPU_D12_CmdChunk)
{
GPU_D12_CommandList *next;
GPU_D12_Command *first;
GPU_D12_Command *last;
u64 count;
GPU_D12_CmdChunk *next;
struct GPU_D12_CmdList *cl;
GPU_D12_Cmd *cmds;
u64 cmds_count;
};
Struct(GPU_D12_CmdList)
{
GPU_D12_CmdList *next;
GPU_D12_CmdChunk *first_cmd_chunk;
GPU_D12_CmdChunk *last_cmd_chunk;
u64 chunks_count;
u64 cmds_count;
GPU_QueueKind queue_kind;
};
@ -249,7 +284,6 @@ Struct(GPU_D12_SwapchainBuffer)
{
struct GPU_D12_Swapchain *swapchain;
ID3D12Resource *d3d_resource;
GPU_D12_Descriptor *rtv_descriptor;
D3D12_RESOURCE_STATES state;
};
@ -269,14 +303,6 @@ Struct(GPU_D12_Swapchain)
////////////////////////////////////////////////////////////
//~ State types
#define GPU_D12_NumResourceReuseBins 1024
Struct(GPU_D12_FiberState)
{
GPU_D12_CommandList *first_free_command_list;
GPU_D12_Command *first_free_command;
};
Struct(GPU_D12_SharedState)
{
Atomic64Padded resource_barrier_gen;
@ -286,7 +312,7 @@ Struct(GPU_D12_SharedState)
Atomic64 driver_descriptors_allocated;
/* Queues */
GPU_D12_Queue *queues[GPU_NumQueues];
GPU_D12_Queue queues[GPU_NumQueues];
/* Rootsig */
ID3D12RootSignature *bindless_rootsig;
@ -295,14 +321,17 @@ Struct(GPU_D12_SharedState)
GPU_D12_PipelineBin pipeline_bins[1024];
/* Descriptor heaps */
GPU_D12_DescriptorHeap *cbv_srv_uav_heap;
GPU_D12_DescriptorHeap *sampler_heap;
GPU_D12_DescriptorHeap *rtv_heap;
GPU_D12_DescriptorHeap cbv_srv_uav_heap;
GPU_D12_DescriptorHeap sampler_heap;
GPU_D12_DescriptorHeap rtv_heap;
/* Resources */
Mutex free_resources_mutex;
GPU_D12_Resource *first_free_resource;
GPU_D12_ResourceReuseListBin resource_reuse_bins[GPU_D12_NumResourceReuseBins];
/* Command lists */
Mutex free_cmd_lists_mutex;
GPU_D12_CmdList *first_free_cmd_list;
/* Command chunks */
Mutex free_cmd_chunks_mutex;
GPU_D12_CmdChunk *first_free_cmd_chunk;
/* Swapchains */
Mutex free_swapchains_mutex;
@ -314,33 +343,19 @@ Struct(GPU_D12_SharedState)
ID3D12Device *device;
} extern GPU_D12_shared_state;
////////////////////////////////////////////////////////////
//~ Helpers
GPU_D12_FiberState *GPU_D12_FiberStateFromId(i16 fiber_id);
DXGI_FORMAT GPU_D12_DxgiFormatFromGpuFormat(GPU_Format format);
GPU_D12_Command *GPU_D12_PushCmd(GPU_D12_CommandList *cl);
u64 GPU_D12_ReuseHashFromResourceDesc(GPU_ResourceDesc desc, u64 buffer_size);
////////////////////////////////////////////////////////////
//~ Startup
void GPU_D12_Startup(void);
////////////////////////////////////////////////////////////
//~ Initialization
//~ Helpers
//- Device initialization
void GPU_D12_InitDevice(void);
//- Queue initialization
JobDecl(GPU_D12_InitQueue, { GPU_D12_QueueDesc *descs; });
//- Heap initialization
GPU_D12_DescriptorHeap *GPU_D12_InitDescriptorHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, D3D12_DESCRIPTOR_HEAP_FLAGS flags, u32 max_descs, u32 desc_size);
//- Rootsig initialization
void GPU_D12_InitRootsig(void);
DXGI_FORMAT GPU_D12_DxgiFormatFromGpuFormat(GPU_Format format);
GPU_D12_Arena *GPU_D12_ArenaFromHandle(GPU_ArenaHandle handle);
GPU_D12_CmdList *GPU_D12_CommandListFromHandle(GPU_CommandListHandle handle);
GPU_D12_Resource *GPU_D12_ResourceFromHandle(GPU_ResourceHandle handle);
GPU_D12_Swapchain *GPU_D12_SwapchainFromHandle(GPU_SwapchainHandle handle);
////////////////////////////////////////////////////////////
//~ Pipeline operations
@ -359,18 +374,26 @@ GPU_D12_Queue *GPU_D12_QueueFromKind(GPU_QueueKind kind);
GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_DescriptorHeap *heap);
void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor);
GPU_D12_Descriptor *GPU_D12_RtvDescriptorFromPtr(GpuRasterTargetPtr ptr);
D3D12_INDEX_BUFFER_VIEW GPU_D12_IbvFromPtr(GpuIndexBufferPtr ptr);
////////////////////////////////////////////////////////////
//~ Raw command list operations
GPU_D12_RawCommandList *GPU_D12_BeginRawCommandList(GPU_QueueKind queue_kind);
u64 GPU_D12_EndRawCommandList(GPU_D12_RawCommandList *cl);
////////////////////////////////////////////////////////////
//~ Command helpers
GPU_D12_Cmd *GPU_D12_PushCmd(GPU_D12_CmdList *cl);
////////////////////////////////////////////////////////////
//~ Swapchain helpers
void GPU_D12_InitSwapchainResources(GPU_D12_Swapchain *swapchain);
GPU_D12_SwapchainBuffer *GPU_D12_UpdateSwapchain(GPU_D12_Swapchain *swapchain, Vec2I32 resolution);
i64 GPU_D12_BlitToSwapchain(GPU_D12_SwapchainBuffer *dst, GPU_D12_Resource *texture, Vec2I32 dst_p0, Vec2I32 dst_p1, Vec2I32 src_p0, Vec2I32 src_p1, Vec4 clear_color);
void GPU_D12_BlitToSwapchain(GPU_D12_SwapchainBuffer *dst, GPU_D12_Resource *texture, Vec2I32 dst_p0, Vec2I32 dst_p1, Vec2I32 src_p0, Vec2I32 src_p1, Vec4 clear_color);
////////////////////////////////////////////////////////////
//~ Sync job

View File

@ -9,44 +9,44 @@
# define IsConsoleApp 1
#endif
#ifndef RtcIsEnabled
# define RtcIsEnabled 1
#ifndef IsRtcEnabled
# define IsRtcEnabled 1
#endif
#ifndef UnoptimizedIsEnabled
# define UnoptimizedIsEnabled 1
#ifndef IsUnoptimized
# define IsUnoptimized 1
#endif
#ifndef AsanIsEnabled
# define AsanIsEnabled 0
#ifndef IsAsanEnabled
# define IsAsanEnabled 0
#endif
#ifndef CrtlibIsEnabled
# define CrtlibIsEnabled 1
#ifndef IsCrtlibEnabled
# define IsCrtlibEnabled 1
#endif
#ifndef DebinfoEnabled
# define DebinfoEnabled 1
#ifndef IsDebinfoEnabled
# define IsDebinfoEnabled 1
#endif
#ifndef DeveloperIsEnabled
# define DeveloperIsEnabled 1
#ifndef IsDeveloperModeEnabled
# define IsDeveloperModeEnabled 1
#endif
#ifndef ProfilingIsEnabled
# define ProfilingIsEnabled 0
#ifndef IsProfilingEnabled
# define IsProfilingEnabled 0
#endif
#ifndef UnoptimizedIsEnabled
# define UnoptimizedIsEnabled 1
#ifndef IsUnoptimized
# define IsUnoptimized 1
#endif
#ifndef TestsAreEnabled
# define TestsAreEnabled 0
#ifndef IsTestingEnabled
# define IsTestingEnabled 0
#endif
#ifndef HotSwappingIsEnabled
# define HotSwappingIsEnabled 0
#ifndef IsHotSwappingEnabled
# define IsHotSwappingEnabled 0
#endif
////////////////////////////////////////////////////////////
@ -118,7 +118,7 @@ Struct(RunCommandResult)
};
JobDecl(RunCommand, { String *cmds; RunCommandResult *results; });
JobDef(RunCommand, sig, id)
JobImpl(RunCommand, sig, id)
{
i64 start_ns = TimeNs();
Arena *arena = PermArena();
@ -204,7 +204,7 @@ void InheritStepResults(Arena *arena, StepResult *dst, u64 srcs_count, StepResul
}
JobDecl(Step, { StepParams *params; StepResult *results; });
JobDef(Step, sig, id)
JobImpl(Step, sig, id)
{
StepParams *params = &sig->params[id];
StepParamsFlag flags = params->flags;
@ -788,7 +788,7 @@ JobDef(Step, sig, id)
F_ClearWrite(arc_out_file, arc_contents);
PushStringToList(arena, output, StringF(arena, "%F (%F mb)", FmtString(F_GetFileName(arc_out_file)), FmtFloatP((f32)arc_contents.len / 1024 / 1024, 3)));
if (PlatformIsWindows)
if (IsPlatformWindows)
{
//- Generate rc file
String rc_out_file = StringF(arena, "%F.rc", FmtString(store));
@ -833,7 +833,7 @@ JobDef(Step, sig, id)
//~ Startup
JobDecl(Build, EmptySig);
JobDef(Build, _, __)
JobImpl(Build, _, __)
{
Arena *arena = PermArena();
M_ErrorList errors = ZI;
@ -916,15 +916,15 @@ JobDef(Build, _, __)
//- Common
{
PushStringToList(arena, &cp.defs, Lit("-DIsConsoleApp=0"));
PushStringToList(arena, &cp.defs, Lit("-DRtcIsEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DAsanIsEnabled=0"));
PushStringToList(arena, &cp.defs, Lit("-DCrtlibIsEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DDebinfoEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DDeveloperIsEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DProfilingIsEnabled=0"));
PushStringToList(arena, &cp.defs, Lit("-DUnoptimizedIsEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DTestsAreEnabled=0"));
PushStringToList(arena, &cp.defs, Lit("-DHotSwappingIsEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DIsRtcEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DIsAsanEnabled=0"));
PushStringToList(arena, &cp.defs, Lit("-DIsCrtlibEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DIsDebinfoEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DIsDeveloperModeEnabled=1"));
PushStringToList(arena, &cp.defs, Lit("-DIsProfilingEnabled=0"));
PushStringToList(arena, &cp.defs, Lit("-DIsUnoptimized=1"));
PushStringToList(arena, &cp.defs, Lit("-DIsTestingEnabled=0"));
PushStringToList(arena, &cp.defs, Lit("-DIsHotSwappingEnabled=1"));
}
//- Msvc
@ -1168,7 +1168,7 @@ JobDef(Build, _, __)
}
////////////////////////////////////////////////////////////
//~ @hookdef Startup
//~ @hookimpl Startup
void StartupLayers(void)
{

View File

@ -467,7 +467,7 @@ M_Layer M_GetFlattenedEntries(Arena *arena, M_LayerList unflattened, StringList
/* Push downstream impl enters to stack */
for (M_Entry *entry = layer->first; entry->valid; entry = entry->next)
{
b32 include = (PlatformIsWindows && entry->kind == M_EntryKind_DefaultWindowsImpl);
b32 include = (IsPlatformWindows && entry->kind == M_EntryKind_DefaultWindowsImpl);
if (include)
{
M_Token *impl_token = entry->arg_tokens[0];

View File

@ -1,5 +1,5 @@
#include "meta_os.h"
#if PlatformIsWindows
#if IsPlatformWindows
# include "meta_os_win32/meta_os_win32_inc.h"
#endif

View File

@ -26,14 +26,14 @@ String W32_StringFromError(Arena *arena, DWORD err)
}
////////////////////////////////////////////////////////////
//~ @hookdef Startup hook
//~ @hookimpl Startup hook
void OS_Startup(void)
{
}
////////////////////////////////////////////////////////////
//~ @hookdef File system hooks
//~ @hookimpl File system hooks
OS_File OS_OpenFile(String path, OS_FileFlag flags, i64 timeout_ns)
{
@ -151,7 +151,7 @@ u64 OS_LastWriteTimestampFromPath(String path)
}
////////////////////////////////////////////////////////////
//~ @hookdef Directory helper hooks
//~ @hookimpl Directory helper hooks
b32 OS_FileOrDirExists(String path)
{
@ -197,7 +197,7 @@ void OS_Rm(String path)
}
////////////////////////////////////////////////////////////
//~ @hookdef Shell hooks
//~ @hookimpl Shell hooks
OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
{

View File

@ -1,7 +1,7 @@
P_W32_SharedState P_W32_shared_state = ZI;
////////////////////////////////////////////////////////////
//~ @hookdef Startup
//~ @hookimpl Startup
void P_Startup(void)
{
@ -158,7 +158,7 @@ P_Address P_W32_PlatformAddressFromWin32Address(P_W32_Address ws_addr)
////////////////////////////////////////////////////////////
//~ Timer job
JobDef(P_W32_StartTimerSync, _, __)
JobImpl(P_W32_StartTimerSync, _, __)
{
P_W32_SharedState *g = &P_W32_shared_state;
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
@ -220,7 +220,7 @@ JobDef(P_W32_StartTimerSync, _, __)
}
////////////////////////////////////////////////////////////
//~ @hookdef File system hooks
//~ @hookimpl File system hooks
//- File system helpers
String P_GetWritePath(Arena *arena)
@ -514,7 +514,7 @@ P_FileTime P_GetFileTime(P_File file)
}
////////////////////////////////////////////////////////////
//~ @hookdef File map hooks
//~ @hookimpl File map hooks
P_FileMap P_OpenFileMap(P_File file)
{
@ -582,7 +582,7 @@ String P_GetFileMapData(P_FileMap map)
}
////////////////////////////////////////////////////////////
//~ @hookdef Address helper hooks
//~ @hookimpl Address helper hooks
P_Address P_AddressFromIpPortCstr(char *ip_cstr, char *port_cstr)
{
@ -784,7 +784,7 @@ b32 P_MatchAddress(P_Address a, P_Address b)
}
////////////////////////////////////////////////////////////
//~ @hookdef Sock hooks
//~ @hookimpl Sock hooks
P_Sock *P_AcquireSock(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size)
{
@ -864,7 +864,7 @@ P_SockReadResult P_ReadSock(Arena *arena, P_Sock *sock)
}
else
{
#if RtcIsEnabled
#if IsRtcEnabled
i32 err = WSAGetLastError();
if (err != WSAEWOULDBLOCK && err != WSAETIMEDOUT && err != WSAECONNRESET)
{
@ -885,7 +885,7 @@ void P_WriteSock(P_Sock *sock, P_Address address, String data)
{
AddGstat(GSTAT_SOCK_BYTES_SENT, size);
}
#if RtcIsEnabled
#if IsRtcEnabled
if (size != (i32)data.len)
{
i32 err = WSAGetLastError();
@ -896,7 +896,7 @@ void P_WriteSock(P_Sock *sock, P_Address address, String data)
}
////////////////////////////////////////////////////////////
//~ @hookdef Utility hooks
//~ @hookimpl Utility hooks
void P_MessageBox(P_MessageBoxKind kind, String message)
{
@ -978,7 +978,7 @@ String P_GetClipboardText(Arena *arena)
}
////////////////////////////////////////////////////////////
//~ @hookdef Timer hooks
//~ @hookimpl Timer hooks
Fence *P_GetTimerFence(void)
{
@ -993,7 +993,7 @@ i64 P_GetCurrentTimerPeriodNs(void)
}
////////////////////////////////////////////////////////////
//~ @hookdef Sleep hooks
//~ @hookimpl Sleep hooks
void P_SleepPrecise(i64 sleep_time_ns)
{

View File

@ -182,7 +182,7 @@ void PB_WSP_EndUpdate(PB_WSP_Buff *wspbuf, MIX_PcmF32 src)
////////////////////////////////////////////////////////////
//~ Playback job
JobDef(PB_WSP_Playback, UNUSED sig, UNUSED id)
JobImpl(PB_WSP_Playback, UNUSED sig, UNUSED id)
{
__prof;
PB_WSP_SharedState *g = &PB_WSP_shared_state;

View File

@ -1,48 +1,4 @@
@Layer pp
//- Dependencies
@Dep gpu
@Dep sprite
@Dep font
@Dep collider
@Dep net
@Dep mixer
@Dep rendertest
@Dep playback
@Dep platform
@Dep window
@Dep ui
//- Api
@IncludeC pp_sim.h
@IncludeC pp_phys.h
@IncludeC pp_space.h
@IncludeC pp_ent.h
@IncludeC pp_step.h
@IncludeC pp_widgets.h
@IncludeC pp_draw.h
@IncludeC pp.h
@IncludeGpu pp_draw.h
//- Impl
@IncludeC pp_sim.c
@IncludeC pp_phys.c
@IncludeC pp_space.c
@IncludeC pp_ent.c
@IncludeC pp_step.c
@IncludeC pp_widgets.c
@IncludeC pp.c
@IncludeGpu pp_draw.gpu
//- Embeds
@EmbedDir PP_Resources pp_res
//- Shaders
@VertexShader PP_MaterialVS
@PixelShader PP_MaterialPS
@ComputeShader PP_FloodCS
@ComputeShader PP_ShadeCS
//- Startup
@Startup PP_StartupSim
@Startup PP_StartupUser
@Dep pp_sim
@Dep pp_vis

View File

@ -296,7 +296,7 @@ MergesortCompareFuncDef(S_SortEntsByKeyCmp, arg_a, arg_b, _)
////////////////////////////////////////////////////////////
//~ Sim worker
JobDef(S_SimWorker, _, __)
JobImpl(S_SimWorker, _, __)
{
S_SharedState *shared = &S_shared_state;
Arena *frame_arena = AcquireArena(Gibi(64));

View File

@ -25,7 +25,7 @@ void V_Shutdown(void)
////////////////////////////////////////////////////////////
//~ Vis worker
JobDef(V_VisWorker, _, __)
JobImpl(V_VisWorker, _, __)
{
V_SharedState *vis_shared = &V_shared_state;
S_SharedState *sim_shared = &S_shared_state;
@ -581,13 +581,13 @@ JobDef(V_VisWorker, _, __)
/* Backdrop pass */
{
GPU_SetShaderAccess(cl, draw_target, GPU_ShaderAccessKind_ReadWrite);
GPU_SyncAccess(cl, draw_target, GPU_AccessKind_ComputeReadWrite);
GPU_Compute(cl, V_BackdropCS, V_BackdropCSThreadSizeFromTexSize(draw_size));
}
/* Shapes pass */
{
GPU_SetShaderAccess(cl, draw_target, GPU_ShaderAccessKind_RasterTarget);
GPU_SyncAccess(cl, draw_target, GPU_AccessKind_RasterTarget)
GPU_Rasterize(cl,
V_DVertVS, V_DVertPS,
1, dvert_idxs_buffer,

View File

@ -5,10 +5,10 @@ ConstantBuffer<V_DVertSig> V_dvert_sig : register (b0);
////////////////////////////////////////////////////////////
//~ Backdrop shader
ComputeShader(V_BackdropCS, 8, 8, 1)
ComputeShader2D(V_BackdropCS, 8, 8)
{
ConstantBuffer<V_BackdropSig> sig = V_backdrop_sig;
Vec2U32 target_pos = SV_DispatchThreadID.xy;
Vec2U32 target_pos = SV_DispatchThreadID;
Vec2I32 target_size = sig.target_size;
if (target_pos.x < target_size.x && target_pos.y < target_size.y)
{

View File

@ -1398,7 +1398,7 @@ void PP_UpdateUser(void)
LAX e0;
LAX e1;
#if DeveloperIsEnabled
#if IsDeveloperModeEnabled
/* Draw contact points */
{
f32 radius = 5;
@ -1893,7 +1893,7 @@ void PP_UpdateUser(void)
}
}
#if RtcIsEnabled
#if IsRtcEnabled
/* Gjk steps */
{
if (g->bind_states[PP_BindKind_ResetDebugSteps].num_presses_and_repeats > 0)
@ -2173,7 +2173,7 @@ void PP_UpdateUser(void)
//UI_BuildLabelF(\n"));
//UI_BuildLabelF(\n"));
#if RtcIsEnabled
#if IsRtcEnabled
UI_BuildSpacer(UI_FNT(1, 0));
UI_BuildLabelF("Debug steps: %F", FmtUint(GetGstat(GSTAT_DEBUG_STEPS)));
//UI_BuildLabelF(\n"));
@ -2410,7 +2410,7 @@ void PP_UpdateUser(void)
////////////////////////////////////////////////////////////
//~ User update job
JobDef(PP_UpdateUserOrSleep, UNUSED sig, UNUSED key)
JobImpl(PP_UpdateUserOrSleep, UNUSED sig, UNUSED key)
{
PP_SharedUserState *g = &PP_shared_user_state;
i64 time_ns = TimeNs();
@ -2470,7 +2470,7 @@ void PP_GenerateuserInputCmds(PP_Client *user_input_client, u64 tick)
////////////////////////////////////////////////////////////
//~ Sim update
JobDef(PP_UpdateSim, UNUSED sig, UNUSED key)
JobImpl(PP_UpdateSim, UNUSED sig, UNUSED key)
{
PP_SharedUserState *g = &PP_shared_user_state;
#if 0

View File

@ -40,7 +40,7 @@ Enum(PP_BindKind)
PP_BindKind_ZoomOut,
PP_BindKind_Pan,
#if RtcIsEnabled
#if IsRtcEnabled
/* Debug */
PP_BindKind_ResetDebugSteps,
@ -92,7 +92,7 @@ Global Readonly PP_BindKind g_binds[Btn_Count] = {
[Btn_MWheelDown] = PP_BindKind_ZoomOut,
[Btn_M3] = PP_BindKind_Pan,
#if RtcIsEnabled
#if IsRtcEnabled
[Btn_ForwardSlash] = PP_BindKind_ResetDebugSteps,
[Btn_Comma] = PP_BindKind_DecrementDebugSteps,
[Btn_Period] = PP_BindKind_IncrementDebugSteps

48
src/pp_old/pp.lay Normal file
View File

@ -0,0 +1,48 @@
@Layer pp_old
//- Dependencies
@Dep gpu
@Dep sprite
@Dep font
@Dep collider
@Dep net
@Dep mixer
@Dep rendertest
@Dep playback
@Dep platform
@Dep window
@Dep ui
//- Api
@IncludeC pp_sim.h
@IncludeC pp_phys.h
@IncludeC pp_space.h
@IncludeC pp_ent.h
@IncludeC pp_step.h
@IncludeC pp_widgets.h
@IncludeC pp_draw.h
@IncludeC pp.h
@IncludeGpu pp_draw.h
//- Impl
@IncludeC pp_sim.c
@IncludeC pp_phys.c
@IncludeC pp_space.c
@IncludeC pp_ent.c
@IncludeC pp_step.c
@IncludeC pp_widgets.c
@IncludeC pp.c
@IncludeGpu pp_draw.gpu
//- Embeds
@EmbedDir PP_Resources pp_res
//- Shaders
@VertexShader PP_MaterialVS
@PixelShader PP_MaterialPS
@ComputeShader PP_FloodCS
@ComputeShader PP_ShadeCS
//- Startup
@Startup PP_StartupSim
@Startup PP_StartupUser

View File

@ -236,7 +236,7 @@ void PP_SetEntKey(PP_Ent *ent, PP_EntKey key)
/* Insert new key into lookup */
if (!PP_IsNilEntKey(key))
{
#if RtcIsEnabled
#if IsRtcEnabled
{
PP_Ent *existing = PP_EntFromKey(ss, key);
/* Collision should be extremely unlikely under normal circumstances, there's probably a logic error somewhere. */

View File

@ -170,7 +170,7 @@ void PP_CreateAndUpdateContacts(PP_PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_it
contact->vcp1 = SubVec2(point, e1_xf.og);
contact->starting_separation = sep;
#if DeveloperIsEnabled
#if IsDeveloperModeEnabled
contact->dbg_pt = point;
#endif
}

View File

@ -54,7 +54,7 @@ Struct(PP_ContactPoint)
f32 inv_tangent_mass;
/* Debugging */
#if DeveloperIsEnabled
#if IsDeveloperModeEnabled
Vec2 dbg_pt;
#endif
};

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,4 +1,4 @@
#if defined(ProfilingIsEnabled) && ProfilingIsEnabled == 1
#if defined(IsProfilingEnabled) && IsProfilingEnabled == 1
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"

View File

@ -1,10 +1,10 @@
#if defined(ProfilingIsEnabled) && ProfilingIsEnabled == 1
#if defined(IsProfilingEnabled) && IsProfilingEnabled == 1
////////////////////////////////////////////////////////////
//~ Profiling enabled
#ifndef __clang__
# error Only clang is supported when compiling with ProfilingIsEnabled=1 (cleanup attributes are required for profiling markup)
# error Only clang is supported when compiling with IsProfilingEnabled=1 (cleanup attributes are required for profiling markup)
#endif
#define ProfilingSystemTrace 0
@ -82,7 +82,7 @@ enum __prof_plot_type {
#define __prof_plot_i(name, val)
#define __prof_is_connected() 0
#endif /* ProfilingIsEnabled */
#endif /* IsProfilingEnabled */
#if ProfilingLocks
# define __proflock_ctx(name) struct TracyCSharedLockCtx *name
@ -111,7 +111,7 @@ enum __prof_plot_type {
# define __proflock_after_try_shared_lock(ctx, acquired)
# define __proflock_mark(ctx)
# define __proflock_custom_name(ctx, name, len)
#endif /* ProfilingIsEnabled && ProfilingLocks */
#endif /* IsProfilingEnabled && ProfilingLocks */
#if ProfilingGpu
/* Dx11 */

View File

@ -1,4 +0,0 @@
@Layer proto
@Dep pp_sim
@Dep pp_vis

3
src/proto/proto.c Normal file
View File

@ -0,0 +1,3 @@
void PR_Startup(void)
{
}

13
src/proto/proto.lay Normal file
View File

@ -0,0 +1,13 @@
@Layer proto
//- Dependencies
@Dep gpu
//- Impl
@IncludeC proto.c
//- Startup
@Startup PR_Startup

View File

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//~ Load job
JobDef(SND_Load, sig, UNUSED id)
JobImpl(SND_Load, sig, UNUSED id)
{
__prof;
TempArena scratch = BeginScratchNoConflict();

View File

@ -5,7 +5,7 @@ SPR_SharedState SPR_shared_state = ZI;
////////////////////////////////////////////////////////////
//~ Load jobs
JobDef(SPR_LoadTexture, sig, _)
JobImpl(SPR_LoadTexture, sig, _)
{
TempArena scratch = BeginScratchNoConflict();
SPR_Entry *entry = sig->entry;
@ -44,7 +44,7 @@ JobDef(SPR_LoadTexture, sig, _)
EndScratch(scratch);
}
JobDef(SPR_LoadSheet, sig, _)
JobImpl(SPR_LoadSheet, sig, _)
{
TempArena scratch = BeginScratchNoConflict();
Arena *perm = PermArena();

View File

@ -4,7 +4,7 @@
TTF_DW_SharedState TTF_DW_shared_state = ZI;
////////////////////////////////////////////////////////////
//~ @hookdef Startup
//~ @hookimpl Startup
/* Call this during font system startup */
void TTF_Startup(void)
@ -16,7 +16,7 @@ void TTF_Startup(void)
* 10? Need to verify. Maybe should just use a custom loader. (We're only
* using a factory5 since I think WriteInMemoryFileLoader wasn't
* implemented until then) */
#if CompilerIsClang
#if IsCompilerClang
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wlanguage-extension-token" /* for __uuidof */
#endif
@ -25,7 +25,7 @@ void TTF_Startup(void)
&IID_IDWriteFactory5,
(void **)&g->factory
);
#if CompilerIsClang
#if IsCompilerClang
# pragma clang diagnostic pop
#endif
if (error != S_OK)
@ -36,7 +36,7 @@ void TTF_Startup(void)
}
////////////////////////////////////////////////////////////
//~ @hookdef Decode
//~ @hookimpl Decode
TTF_Decoded TTF_Decode(Arena *arena, String encoded, f32 em_size, u32 *cache_codes, u32 cache_codes_count)
{

View File

@ -1,7 +1,7 @@
WND_W32_SharedState WND_W32_shared_state = ZI;
////////////////////////////////////////////////////////////
//~ @hookdef Startup
//~ @hookimpl Startup
void WND_Startup(void)
{
@ -102,7 +102,7 @@ WND_W32_Window *WND_W32_WindowFromHandle(WND_Handle handle)
//~ Initialization
/* Win32 limitation: Window must be initialized on same thread that processes events */
JobDef(WND_W32_ProcessMessagesForever, sig, id)
JobImpl(WND_W32_ProcessMessagesForever, sig, id)
{
WND_W32_SharedState *g = &WND_W32_shared_state;
WND_W32_Window *window = &g->window;
@ -385,7 +385,7 @@ LRESULT CALLBACK WND_W32_WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM l
}
////////////////////////////////////////////////////////////
//~ @hookdef Cmds
//~ @hookimpl Cmds
void WND_PushCmd_(WND_Frame frame, WND_Cmd desc)
{
@ -400,7 +400,7 @@ void WND_PushCmd_(WND_Frame frame, WND_Cmd desc)
}
////////////////////////////////////////////////////////////
//~ @hookdef Frame
//~ @hookimpl Frame
WND_Frame WND_BeginFrame(void)
{