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) void AC_RefreshDebugTable(void)
{ {
#if RtcIsEnabled #if IsRtcEnabled
AC_SharedState *g = &AC_shared_state; AC_SharedState *g = &AC_shared_state;
Lock lock = LockE(&g->dbg_table_mutex); Lock lock = LockE(&g->dbg_table_mutex);
ZeroArray(g->dbg_table); ZeroArray(g->dbg_table);

View File

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

View File

@ -2,43 +2,43 @@
//~ Compiler flag checks //~ Compiler flag checks
#ifndef IsConsoleApp #ifndef IsConsoleApp
# error Missing compile time definition for 'IsConsoleApp' #error Missing compile time definition for 'IsConsoleApp'
#endif #endif
#ifndef RtcIsEnabled #ifndef IsRtcEnabled
# error Missing compile time definition for 'RtcIsEnabled' #error Missing compile time definition for 'IsRtcEnabled'
#endif #endif
#ifndef AsanIsEnabled #ifndef IsAsanEnabled
# error Missing compile time definition for 'AsanIsEnabled' #error Missing compile time definition for 'IsAsanEnabled'
#endif #endif
#ifndef CrtlibIsEnabled #ifndef IsCrtlibEnabled
# error Missing compile time definition for 'CrtlibIsEnabled' #error Missing compile time definition for 'IsCrtlibEnabled'
#endif #endif
#ifndef DebinfoEnabled #ifndef IsDebinfoEnabled
# error Missing compile time definition for 'DebinfoEnabled' #error Missing compile time definition for 'IsDebinfoEnabled'
#endif #endif
#ifndef DeveloperIsEnabled #ifndef IsDeveloperModeEnabled
# error Missing compile time definition for 'DeveloperIsEnabled' #error Missing compile time definition for 'IsDeveloperModeEnabled'
#endif #endif
#ifndef ProfilingIsEnabled #ifndef IsProfilingEnabled
# error Missing compile time definition for 'ProfilingIsEnabled' #error Missing compile time definition for 'IsProfilingEnabled'
#endif #endif
#ifndef UnoptimizedIsEnabled #ifndef IsUnoptimized
# error Missing compile time definition for 'UnoptimizedIsEnabled' #error Missing compile time definition for 'IsUnoptimized'
#endif #endif
#ifndef TestsAreEnabled #ifndef IsTestingEnabled
# error Missing compile time definition for 'TestsAreEnabled' #error Missing compile time definition for 'IsTestingEnabled'
#endif #endif
#ifndef HotSwappingIsEnabled #ifndef IsHotSwappingEnabled
# error Missing compile time definition for 'HotSwappingIsEnabled' #error Missing compile time definition for 'IsHotSwappingEnabled'
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -46,58 +46,58 @@
//- Compiler //- Compiler
#if defined(__clang__) #if defined(__clang__)
# define CompilerIsClang 1 #define IsCompilerClang 1
# define CompilerIsMsvc 0 #define IsCompilerMsvc 0
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
# define CompilerIsClang 0 #define IsCompilerClang 0
# define CompilerIsMsvc 1 #define IsCompilerMsvc 1
#else #else
# error Unknown compiler #error Unknown compiler
#endif #endif
//- Language //- Language
#if defined(__HLSL_VERSION) #if defined(__HLSL_VERSION)
# define LanguageIsC 0 #define IsLanguageC 0
# define LanguageIsGpu 1 #define IsLanguageGpu 1
#else #else
# define LanguageIsC 1 #define IsLanguageC 1
# define LanguageIsGpu 0 #define IsLanguageGpu 0
#endif #endif
//- Platform system //- Platform system
#if defined(_WIN32) #if defined(_WIN32)
# define PlatformIsWindows 1 #define IsPlatformWindows 1
# define PlatformIsMac 0 #define IsPlatformMac 0
# define PlatformIsLinux 0 #define IsPlatformLinux 0
#elif defined(__APPLE__) && defined(__MACH__) #elif defined(__APPLE__) && defined(__MACH__)
# define PlatformIsWindows 0 #define IsPlatformWindows 0
# define PlatformIsMac 1 #define IsPlatformMac 1
# define PlatformIsLinux 0 #define IsPlatformLinux 0
#elif defined(__gnu_linux__) #elif defined(__gnu_linux__)
# define PlatformIsWindows 0 #define IsPlatformWindows 0
# define PlatformIsMac 0 #define IsPlatformMac 0
# define PlatformIsLinux 1 #define IsPlatformLinux 1
#elif LanguageIsGpu #elif IsLanguageGpu
# define PlatformIsWindows 0 #define IsPlatformWindows 0
# define PlatformIsMac 0 #define IsPlatformMac 0
# define PlatformIsLinux 0 #define IsPlatformLinux 0
#else #else
# error Unknown platform #error Unknown platform
#endif #endif
//- Architecture //- Architecture
# if defined(_M_AMD64) || defined(__amd64__) #if defined(_M_AMD64) || defined(__amd64__)
# define ArchIsX64 1 #define IsArchX64 1
# define ArchIsArm64 0 #define IsArchArm64 0
# elif defined(_M_ARM64) || defined(__aarch64__) #elif defined(_M_ARM64) || defined(__aarch64__)
# define ArchIsX64 0 #define IsArchX64 0
# define ArchIsArm64 1 #define IsArchArm64 1
# elif LanguageIsGpu #elif IsLanguageGpu
# define ArchIsX64 0 #define IsArchX64 0
# define ArchIsArm64 0 #define IsArchArm64 0
# else #else
# error Unknown architecture #error Unknown architecture
# endif #endif
//- Cache line size //- Cache line size
/* TODO: Just hard-code to something like 128 or 256 if Apple silicon is ever supported */ /* TODO: Just hard-code to something like 128 or 256 if Apple silicon is ever supported */
@ -106,33 +106,33 @@
//- Windows NTDDI version //- Windows NTDDI version
/* TODO: Remove this */ /* TODO: Remove this */
#if 0 #if 0
#if CompilerIsMsvc #if IsCompilerMsvc
# define NTDDI_WIN11_DT 0x0C0A0000 #define NTDDI_WIN11_DT 0x0C0A0000
# define NTDDI_VERSION 0x0A000000 #define NTDDI_VERSION 0x0A000000
# if RtcIsEnabled #if IsRtcEnabled
# define _ALLOW_RTCc_IN_STL 1 #define _ALLOW_RTCc_IN_STL 1
# endif #endif
#endif #endif
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Platform headers //~ Platform headers
//- Windows headers //- Windows headers
#if PlatformIsWindows #if IsPlatformWindows
# define COBJMACROS #define COBJMACROS
# define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
# define UNICODE #define UNICODE
# pragma warning(push, 0) #pragma warning(push, 0)
# include <Windows.h> #include <Windows.h>
# include <combaseapi.h> #include <combaseapi.h>
# include <dcommon.h> #include <dcommon.h>
# include <initguid.h> #include <initguid.h>
# include <unknwn.h> #include <unknwn.h>
# include <objbase.h> #include <objbase.h>
# include <uuids.h> #include <uuids.h>
# include <Knownfolders.h> #include <Knownfolders.h>
# pragma warning(pop) #pragma warning(pop)
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -144,74 +144,53 @@
#define StaticAssert(cond) StaticAssert1(cond, __LINE__, __COUNTER__) #define StaticAssert(cond) StaticAssert1(cond, __LINE__, __COUNTER__)
//- Debug assert //- Debug assert
#if RtcIsEnabled #if IsRtcEnabled
# if CompilerIsMsvc #if IsCompilerMsvc
# define Assert(cond) ((cond) ? 1 : (IsRunningInDebugger() ? (*(volatile i32 *)0 = 0) : Panic(Lit(__FILE__ ":" Stringize(__LINE__) ":0: assertion failed: "#cond"")))) #define Assert(cond) ((cond) ? 1 : (IsRunningInDebugger() ? (*(volatile i32 *)0 = 0) : Panic(Lit(__FILE__ ":" Stringize(__LINE__) ":0: assertion failed: "#cond""))))
# define DEBUGBREAK __debugbreak() #define DEBUGBREAK __debugbreak()
# else #else
# define Assert(cond) ((cond) ? 1 : (__builtin_trap(), 0)) #define Assert(cond) ((cond) ? 1 : (__builtin_trap(), 0))
# define DEBUGBREAK __builtin_debugtrap() #define DEBUGBREAK __builtin_debugtrap()
# endif #endif
# define DEBUGBREAKABLE { volatile i32 __DEBUGBREAKABLE_VAR = 0; LAX __DEBUGBREAKABLE_VAR; } (void)0 #define DEBUGBREAKABLE { volatile i32 __DEBUGBREAKABLE_VAR = 0; LAX __DEBUGBREAKABLE_VAR; } (void)0
#else #else
# define Assert(cond) (void)(0) #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 #endif
//- Address sanitization //- Address sanitization
#if AsanIsEnabled #if IsAsanEnabled
void __asan_poison_memory_region(void const volatile *, size_t); void __asan_poison_memory_region(void const volatile *, size_t);
void __asan_unpoison_memory_region(void const volatile *add, size_t); void __asan_unpoison_memory_region(void const volatile *add, size_t);
# define AsanPoison(addr, size) __asan_poison_memory_region((addr), (size)) #define AsanPoison(addr, size) __asan_poison_memory_region((addr), (size))
# define AsanUnpoison(addr, size) __asan_unpoison_memory_region((addr), (size)) #define AsanUnpoison(addr, size) __asan_unpoison_memory_region((addr), (size))
#else #else
# define AsanPoison(addr, size) #define AsanPoison(addr, size)
# define AsanUnpoison(addr, size) #define AsanUnpoison(addr, size)
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Common utility macros //~ Common utility macros
//- ZeroStruct initialization macro //- ZeroStruct initialization macro
#if LanguageIsC #if IsLanguageC
# define ZI { 0 } #define ZI { 0 }
#else #else
# define ZI { } #define ZI { }
#endif #endif
//- Inline //- Inline
#define Inline static inline #define Inline static inline
#if CompilerIsMsvc #if IsCompilerMsvc
# define ForceInline Inline __forceinline #define ForceInline Inline __forceinline
#else #else
# define ForceInline Inline __attribute((always_inline)) #define ForceInline Inline __attribute((always_inline))
#endif #endif
#if CompilerIsMsvc #if IsCompilerMsvc
# define ForceNoInline __declspec(noinline) #define ForceNoInline __declspec(noinline)
#else #else
# define ForceNoInline __attribute__((noinline)) #define ForceNoInline __attribute__((noinline))
#endif #endif
//- Static //- Static
@ -219,49 +198,49 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define Global static #define Global static
//- Read-only //- Read-only
#if PlatformIsWindows #if IsPlatformWindows
# if CompilerIsMsvc #if IsCompilerMsvc
# pragma section(".rdata$", read) # pragma section(".rdata$", read)
# define Readonly __declspec(allocate(".rdata$")) # define Readonly __declspec(allocate(".rdata$"))
# else #else
# define Readonly __declspec(allocate(".rdata")) #define Readonly __declspec(allocate(".rdata"))
# endif #endif
#elif PlatformIsMac #elif IsPlatformMac
# define Readonly __attribute((section("__TEXT,__const"))) #define Readonly __attribute((section("__TEXT,__const")))
#else #else
# define Readonly __attribute((section(".rodata"))) #define Readonly __attribute((section(".rodata")))
#endif #endif
//- Barriers //- Barriers
#if CompilerIsMsvc #if IsCompilerMsvc
# define WriteBarrier() _WriteBarrier() #define WriteBarrier() _WriteBarrier()
# define ReadBarrier() _ReadBarrier() #define ReadBarrier() _ReadBarrier()
#elif defined(__x86_64) || defined(__i386__) #elif defined(__x86_64) || defined(__i386__)
# define WriteBarrier() __asm__ volatile("" ::: "memory") #define WriteBarrier() __asm__ volatile("" ::: "memory")
# define ReadBarrier() __asm__ volatile("" ::: "memory") #define ReadBarrier() __asm__ volatile("" ::: "memory")
#elif LanguageIsGpu #elif IsLanguageGpu
# define WriteBarrier() #define WriteBarrier()
# define ReadBarrier() #define ReadBarrier()
#else #else
# error Memory barriers not implemented #error Memory barriers not implemented
#endif #endif
//- Unused markup //- Unused markup
/* Strict unused markup */ /* Strict unused markup */
#if CompilerIsClang #if IsCompilerClang
# define UNUSED __attribute((unused)) #define UNUSED __attribute((unused))
#else #else
# define UNUSED #define UNUSED
#endif #endif
/* Relaxed unused markup */ /* Relaxed unused markup */
#define LAX (void) #define LAX (void)
//- Fallthrough //- Fallthrough
#if CompilerIsClang #if IsCompilerClang
# define FALLTHROUGH __attribute((fallthrough)) #define FALLTHROUGH __attribute((fallthrough))
#else #else
# define FALLTHROUGH #define FALLTHROUGH
#endif #endif
//- Preprocessor concatenation //- Preprocessor concatenation
@ -433,8 +412,8 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Intrinsic headers //~ Intrinsic headers
#if LanguageIsC #if IsLanguageC
/* Intrinsic header info: /* Intrinsic header info:
* mmintrin.h MMX * mmintrin.h MMX
* xmmintrin.h SSE * xmmintrin.h SSE
* emmintrin.h SSE2 * emmintrin.h SSE2
@ -445,9 +424,9 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
* ammintrin.h SSE4A * ammintrin.h SSE4A
* wmmintrin.h AES * wmmintrin.h AES
* immintrin.h AVX, AVX2, FMA * immintrin.h AVX, AVX2, FMA
*/ */
#include <intrin.h> #include <intrin.h>
#include <nmmintrin.h> /* SSE4.2 */ #include <nmmintrin.h> /* SSE4.2 */
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -459,15 +438,15 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define AlignedBlock(n) struct alignas(n) #define AlignedBlock(n) struct alignas(n)
//- Enum //- Enum
#if LanguageIsC #if IsLanguageC
# define Enum(name) typedef enum name name; enum name #define Enum(name) typedef enum name name; enum name
#else #else
# define Enum(name) enum name #define Enum(name) enum name
#endif #endif
//- alignof //- alignof
#if LanguageIsC && (CompilerIsMsvc || __STDC_VERSION__ < 202311L) #if IsLanguageC && (IsCompilerMsvc || __STDC_VERSION__ < 202311L)
# define alignof(type) __alignof(type) #define alignof(type) __alignof(type)
#endif #endif
//- field sizeof //- field sizeof
@ -481,12 +460,12 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define IsArray(a) (IsIndexable(a) && (((void *)&a) == ((void *)a))) #define IsArray(a) (IsIndexable(a) && (((void *)&a) == ((void *)a)))
//- offsetof //- offsetof
#if !CompilerIsMsvc #if !IsCompilerMsvc
# ifdef _CRT_USE_BUILTIN_OFFSETOF #ifdef _CRT_USE_BUILTIN_OFFSETOF
# define offsetof(type, field) __builtin_offsetof(type, field) #define offsetof(type, field) __builtin_offsetof(type, field)
# else #else
# define offsetof(type, field) ((u64)&(((type *)0)->field)) #define offsetof(type, field) ((u64)&(((type *)0)->field))
# endif #endif
#endif #endif
//- struct region //- struct region
@ -496,54 +475,48 @@ 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) #define ZeroFieldRegion(dst, src, r) ZeroBytes(&dst->__begfieldreg__##r, &src->__begfieldreg__##r, (u8 *)&dst->__endfieldreg__##r - (u8 *)&dst->__begfieldreg__##r)
//- Packed //- Packed
#if CompilerIsMsvc #if IsCompilerMsvc
# define Packed(s) __pragma(pack(push, 1)) s __pragma(pack(pop)) #define Packed(s) __pragma(pack(push, 1)) s __pragma(pack(pop))
#elif CompilerIsClang #elif IsCompilerClang
# define Packed(s) s __attribute((__packed__)) #define Packed(s) s __attribute((__packed__))
#elif LanguageIsGpu #elif IsLanguageGpu
# define Packed(s) s #define Packed(s) s
#endif #endif
//- alignas //- alignas
#if (CompilerIsMsvc && LanguageIsC) || (LanguageIsC && __STDC_VERSION__ < 202311L) #if (IsCompilerMsvc && IsLanguageC) || (IsLanguageC && __STDC_VERSION__ < 202311L)
# if CompilerIsMsvc #if IsCompilerMsvc
# define alignas(n) __declspec(align(n)) #define alignas(n) __declspec(align(n))
# else #else
# define alignas(n) __attribute__((aligned(n))) #define alignas(n) __attribute__((aligned(n)))
# endif #endif
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Scalar types //~ Scalar types
#if LanguageIsC #if IsLanguageC
#include <stdint.h>
//- Cpu scalar types typedef int8_t i8;
#include <stdint.h> typedef int16_t i16;
typedef int8_t i8; typedef int32_t i32;
typedef int16_t i16; typedef int64_t i64;
typedef int32_t i32; typedef uint8_t u8;
typedef int64_t i64; typedef uint16_t u16;
typedef uint8_t u8; typedef uint32_t u32;
typedef uint16_t u16; typedef uint64_t u64;
typedef uint32_t u32; typedef float f32;
typedef uint64_t u64; typedef double f64;
typedef float f32; typedef i8 b8;
typedef double f64; typedef u32 b32;
typedef i8 b8; #elif IsLanguageGpu
typedef u32 b32; typedef int i32;
typedef int2 i64;
#elif LanguageIsGpu typedef uint u32;
typedef uint2 u64;
//- Gpu scalar types typedef float f32;
typedef int i32; typedef uint b32;
typedef int2 i64;
typedef uint u32;
typedef uint2 u64;
typedef float f32;
typedef uint b32;
#endif #endif
//- Min / max constants //- Min / max constants
@ -563,170 +536,166 @@ typedef uint b32;
#define I64Min ((i64)0x8000000000000000LL) #define I64Min ((i64)0x8000000000000000LL)
//- Float infinity / nan constants //- Float infinity / nan constants
#if LanguageIsC #if IsLanguageC
Global const u32 _f32_infinity_u32 = 0x7f800000; Global const u32 _f32_infinity_u32 = 0x7f800000;
Global const f32 *_f32_infinity = (f32 *)&_f32_infinity_u32; Global const f32 *_f32_infinity = (f32 *)&_f32_infinity_u32;
#define F32Infinity (*_f32_infinity) #define F32Infinity (*_f32_infinity)
Global const u64 _f64_infinity_u64 = 0x7ff0000000000000ULL; Global const u64 _f64_infinity_u64 = 0x7ff0000000000000ULL;
Global const f64 *_f64_infinity = (f64 *)&_f64_infinity_u64; Global const f64 *_f64_infinity = (f64 *)&_f64_infinity_u64;
#define F64Infinity (*_f64_infinity) #define F64Infinity (*_f64_infinity)
Global const u32 _f32_nan_u32 = 0x7f800001; Global const u32 _f32_nan_u32 = 0x7f800001;
Global const f32 *_f32_nan = (f32 *)&_f32_nan_u32; Global const f32 *_f32_nan = (f32 *)&_f32_nan_u32;
#define F32Nan (*_f32_nan) #define F32Nan (*_f32_nan)
Global const u64 _f64_nan_u64 = 0x7ff8000000000001; Global const u64 _f64_nan_u64 = 0x7ff8000000000001;
Global const f64 *_f64_nan = (f64 *)&_f64_nan_u64; Global const f64 *_f64_nan = (f64 *)&_f64_nan_u64;
#define F64Nan (*_f64_nan) #define F64Nan (*_f64_nan)
#define IsF32Nan(x) (x != x) #define IsF32Nan(x) (x != x)
#define IsF64Nan(x) (x != x) #define IsF64Nan(x) (x != x)
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Atomics //~ Atomics
#if LanguageIsC #if IsLanguageC
//- Atomic types
Struct(Atomic8) { volatile i8 _v; };
Struct(Atomic16) { volatile i16 _v; };
Struct(Atomic32) { volatile i32 _v; };
Struct(Atomic64) { volatile i64 _v; };
//- Atomic types //- Cache-line isolated aligned atomic types
Struct(Atomic8) { volatile i8 _v; }; AlignedStruct(Atomic8Padded, CachelineSize) { Atomic8 v; };
Struct(Atomic16) { volatile i16 _v; }; AlignedStruct(Atomic16Padded, CachelineSize) { Atomic16 v; };
Struct(Atomic32) { volatile i32 _v; }; AlignedStruct(Atomic32Padded, CachelineSize) { Atomic32 v; };
Struct(Atomic64) { volatile i64 _v; }; AlignedStruct(Atomic64Padded, CachelineSize) { Atomic64 v; };
StaticAssert(alignof(Atomic8Padded) == CachelineSize && sizeof(Atomic8Padded) % CachelineSize == 0);
//- Cache-line isolated aligned atomic types StaticAssert(alignof(Atomic16Padded) == CachelineSize && sizeof(Atomic16Padded) % CachelineSize == 0);
AlignedStruct(Atomic8Padded, CachelineSize) { Atomic8 v; }; StaticAssert(alignof(Atomic32Padded) == CachelineSize && sizeof(Atomic32Padded) % CachelineSize == 0);
AlignedStruct(Atomic16Padded, CachelineSize) { Atomic16 v; }; StaticAssert(alignof(Atomic64Padded) == CachelineSize && sizeof(Atomic64Padded) % CachelineSize == 0);
AlignedStruct(Atomic32Padded, CachelineSize) { Atomic32 v; };
AlignedStruct(Atomic64Padded, CachelineSize) { Atomic64 v; };
StaticAssert(alignof(Atomic8Padded) == CachelineSize && sizeof(Atomic8Padded) % CachelineSize == 0);
StaticAssert(alignof(Atomic16Padded) == CachelineSize && sizeof(Atomic16Padded) % CachelineSize == 0);
StaticAssert(alignof(Atomic32Padded) == CachelineSize && sizeof(Atomic32Padded) % CachelineSize == 0);
StaticAssert(alignof(Atomic64Padded) == CachelineSize && sizeof(Atomic64Padded) % CachelineSize == 0);
#if PlatformIsWindows && ArchIsX64
//- Memory barriers
# define CompilerMemoryBarrier() _ReadWriteBarrier()
# define HardwareMemoryBarrier() MemoryBarrier()
//- 8 bit atomic operations
ForceInline i8 Atomic8Fetch (Atomic8 *x) { i8 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic8Set (Atomic8 *x, i8 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i8 Atomic8FetchSet (Atomic8 *x, i8 e) { return (i8)_InterlockedExchange8((volatile char *)&(x)->_v, (e)); }
ForceInline i8 Atomic8FetchTestSet (Atomic8 *x, i8 c, i8 e) { return (i8)_InterlockedCompareExchange8((volatile char *)&(x)->_v, (e), (c)); }
ForceInline i8 Atomic8FetchXor (Atomic8 *x, i8 c) { return (i8)_InterlockedXor8((volatile char *)&(x)->_v, (c)); }
ForceInline i8 Atomic8FetchAdd (Atomic8 *x, i8 a) { return (i8)_InterlockedExchangeAdd8((volatile char *)&(x)->_v, (a)); }
//- 16 bit atomic operations
ForceInline i16 Atomic16Fetch (Atomic16 *x) { i16 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic16Set (Atomic16 *x, i16 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i16 Atomic16FetchSet (Atomic16 *x, i16 e) { return (i16)_InterlockedExchange16(&(x)->_v, (e)); }
ForceInline i16 Atomic16FetchTestSet (Atomic16 *x, i16 c, i16 e) { return (i16)_InterlockedCompareExchange16(&(x)->_v, (e), (c)); }
ForceInline i16 Atomic16FetchXor (Atomic16 *x, i16 c) { return (i16)_InterlockedXor16(&(x)->_v, (c)); }
ForceInline i16 Atomic16FetchAdd (Atomic16 *x, i16 a) { return (i16)_InterlockedExchangeAdd16(&(x)->_v, (a)); }
//- 32 bit atomic operations
ForceInline i32 Atomic32Fetch (Atomic32 *x) { i32 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic32Set (Atomic32 *x, i32 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i32 Atomic32FetchSet (Atomic32 *x, i32 e) { return (i32)_InterlockedExchange((volatile long *)&(x)->_v, (e)); }
ForceInline i32 Atomic32FetchTestSet (Atomic32 *x, i32 c, i32 e) { return (i32)_InterlockedCompareExchange((volatile long *)&(x)->_v, (e), (c)); }
ForceInline i32 Atomic32FetchXor (Atomic32 *x, i32 c) { return (i32)_InterlockedXor((volatile long *)&(x)->_v, (c)); }
ForceInline i32 Atomic32FetchAdd (Atomic32 *x, i32 a) { return (i32)_InterlockedExchangeAdd((volatile long *)&(x)->_v, (a)); }
//- 64 bit atomic operations
ForceInline i64 Atomic64Fetch (Atomic64 *x) { i64 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic64Set (Atomic64 *x, i64 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i64 Atomic64FetchSet (Atomic64 *x, i64 e) { return (i64)_InterlockedExchange64(&(x)->_v, (e)); }
ForceInline i64 Atomic64FetchTestSet (Atomic64 *x, i64 c, i64 e) { return (i64)_InterlockedCompareExchange64(&(x)->_v, (e), (c)); }
ForceInline i64 Atomic64FetchXor (Atomic64 *x, i64 c) { return (i64)_InterlockedXor64(&(x)->_v, (c)); }
ForceInline i64 Atomic64FetchAdd (Atomic64 *x, i64 a) { return (i64)_InterlockedExchangeAdd64(&(x)->_v, (a)); }
#else
# error Atomics not implemented
#endif
#if IsPlatformWindows && IsArchX64
//- Memory barriers
# define CompilerMemoryBarrier() _ReadWriteBarrier()
# define HardwareMemoryBarrier() MemoryBarrier()
//- 8 bit atomic operations
ForceInline i8 Atomic8Fetch (Atomic8 *x) { i8 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic8Set (Atomic8 *x, i8 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i8 Atomic8FetchSet (Atomic8 *x, i8 e) { return (i8)_InterlockedExchange8((volatile char *)&(x)->_v, (e)); }
ForceInline i8 Atomic8FetchTestSet (Atomic8 *x, i8 c, i8 e) { return (i8)_InterlockedCompareExchange8((volatile char *)&(x)->_v, (e), (c)); }
ForceInline i8 Atomic8FetchXor (Atomic8 *x, i8 c) { return (i8)_InterlockedXor8((volatile char *)&(x)->_v, (c)); }
ForceInline i8 Atomic8FetchAdd (Atomic8 *x, i8 a) { return (i8)_InterlockedExchangeAdd8((volatile char *)&(x)->_v, (a)); }
//- 16 bit atomic operations
ForceInline i16 Atomic16Fetch (Atomic16 *x) { i16 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic16Set (Atomic16 *x, i16 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i16 Atomic16FetchSet (Atomic16 *x, i16 e) { return (i16)_InterlockedExchange16(&(x)->_v, (e)); }
ForceInline i16 Atomic16FetchTestSet (Atomic16 *x, i16 c, i16 e) { return (i16)_InterlockedCompareExchange16(&(x)->_v, (e), (c)); }
ForceInline i16 Atomic16FetchXor (Atomic16 *x, i16 c) { return (i16)_InterlockedXor16(&(x)->_v, (c)); }
ForceInline i16 Atomic16FetchAdd (Atomic16 *x, i16 a) { return (i16)_InterlockedExchangeAdd16(&(x)->_v, (a)); }
//- 32 bit atomic operations
ForceInline i32 Atomic32Fetch (Atomic32 *x) { i32 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic32Set (Atomic32 *x, i32 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i32 Atomic32FetchSet (Atomic32 *x, i32 e) { return (i32)_InterlockedExchange((volatile long *)&(x)->_v, (e)); }
ForceInline i32 Atomic32FetchTestSet (Atomic32 *x, i32 c, i32 e) { return (i32)_InterlockedCompareExchange((volatile long *)&(x)->_v, (e), (c)); }
ForceInline i32 Atomic32FetchXor (Atomic32 *x, i32 c) { return (i32)_InterlockedXor((volatile long *)&(x)->_v, (c)); }
ForceInline i32 Atomic32FetchAdd (Atomic32 *x, i32 a) { return (i32)_InterlockedExchangeAdd((volatile long *)&(x)->_v, (a)); }
//- 64 bit atomic operations
ForceInline i64 Atomic64Fetch (Atomic64 *x) { i64 result = (x)->_v; CompilerMemoryBarrier(); return result; }
ForceInline void Atomic64Set (Atomic64 *x, i64 e) { CompilerMemoryBarrier(); (x)->_v = e; }
ForceInline i64 Atomic64FetchSet (Atomic64 *x, i64 e) { return (i64)_InterlockedExchange64(&(x)->_v, (e)); }
ForceInline i64 Atomic64FetchTestSet (Atomic64 *x, i64 c, i64 e) { return (i64)_InterlockedCompareExchange64(&(x)->_v, (e), (c)); }
ForceInline i64 Atomic64FetchXor (Atomic64 *x, i64 c) { return (i64)_InterlockedXor64(&(x)->_v, (c)); }
ForceInline i64 Atomic64FetchAdd (Atomic64 *x, i64 a) { return (i64)_InterlockedExchangeAdd64(&(x)->_v, (a)); }
#else
#error Atomics not implemented
#endif
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Ticket mutex //~ Ticket mutex
#if LanguageIsC #if IsLanguageC
Struct(TicketMutex) Struct(TicketMutex)
{ {
Atomic64Padded ticket; Atomic64Padded ticket;
Atomic64Padded serving; Atomic64Padded serving;
}; };
ForceInline void LockTicketMutex(TicketMutex *tm) ForceInline void LockTicketMutex(TicketMutex *tm)
{ {
i64 ticket = Atomic64FetchAdd(&tm->ticket.v, 1); i64 ticket = Atomic64FetchAdd(&tm->ticket.v, 1);
while (Atomic64Fetch(&tm->serving.v) != ticket) while (Atomic64Fetch(&tm->serving.v) != ticket)
{ {
_mm_pause(); _mm_pause();
} }
} }
ForceInline void UnlockTicketMutex(TicketMutex *tm) ForceInline void UnlockTicketMutex(TicketMutex *tm)
{ {
/* TODO: Atomic set w/ known ticket + 1 */ /* TODO: Atomic set w/ known ticket + 1 */
Atomic64FetchAdd(&tm->serving.v, 1); Atomic64FetchAdd(&tm->serving.v, 1);
} }
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ String types //~ 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) }
#define CompLit(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
#define StringFromPointers(p0, p1) ((String) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
#define StringFromStruct(ptr) ((String) { sizeof(*(ptr)), (u8 *)(ptr) })
#define StringFromArena(arena) (STRING((arena)->pos, ArenaBase(arena)))
#define STRING(size, data) ((String) { (size), (data) }) /* String from static array */
#define Zstr ((String) { 0, 0}) #define StringFromArray(a) \
#define Lit(cstr_lit) (String) { (sizeof((cstr_lit)) - 1), (u8 *)(cstr_lit) }
#define CompLit(cstr_lit) { .len = (sizeof((cstr_lit)) - 1), .text = (u8 *)(cstr_lit) }
#define StringFromPointers(p0, p1) ((String) { (u8 *)(p1) - (u8 *)(p0), (u8 *)p0 })
#define StringFromStruct(ptr) ((String) { sizeof(*(ptr)), (u8 *)(ptr) })
#define StringFromArena(arena) (STRING((arena)->pos, ArenaBase(arena)))
/* String from static array */
#define StringFromArray(a) \
( \ ( \
Assert(IsArray(a)), \ Assert(IsArray(a)), \
((String) { .len = sizeof(a), .text = (u8 *)(a) }) \ ((String) { .len = sizeof(a), .text = (u8 *)(a) }) \
) )
Struct(String) Struct(String)
{ {
u64 len; u64 len;
u8 *text; u8 *text;
}; };
Struct(String16) Struct(String16)
{ {
u64 len; u64 len;
u16 *text; u16 *text;
}; };
Struct(String32) Struct(String32)
{ {
u64 len; u64 len;
u32 *text; u32 *text;
}; };
Struct(StringArray) Struct(StringArray)
{ {
u64 count; u64 count;
String *strings; String *strings;
}; };
Struct(StringListNode) Struct(StringListNode)
{ {
String s; String s;
StringListNode *next; StringListNode *next;
StringListNode *prev; StringListNode *prev;
}; };
Struct(StringList) Struct(StringList)
{ {
StringListNode *first; StringListNode *first;
StringListNode *last; StringListNode *last;
u64 count; u64 count;
}; };
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -741,111 +710,125 @@ Struct(U128)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Resource types //~ Resource types
#if LanguageIsC #if IsLanguageC
#define ResourceEmbeddedMagic 0xfc060937194f4406
#define ResourceEmbeddedMagic 0xfc060937194f4406 Struct(ResourceStore)
{
Struct(ResourceStore)
{
u64 hash; u64 hash;
}; };
Struct(ResourceKey) Struct(ResourceKey)
{ {
u64 hash; u64 hash;
}; };
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Shader types //~ Shader types
#if LanguageIsC #if IsLanguageC
//- Shader linkage
Struct(GpuPointer) { u32 v; }; Struct(VertexShader) { ResourceKey resource; };
Struct(GpuBufferPos) { GpuPointer p; u64 byte_offset; }; Struct(PixelShader) { ResourceKey resource; };
Struct(ComputeShader) { ResourceKey resource; };
Inline b32 IsGpuPointerNil(GpuPointer p) { return p.v == 0; } //- Pointers
Struct(VertexShader) { ResourceKey resource; }; Struct(GpuBufferPtr) { u32 v; };
Struct(PixelShader) { ResourceKey resource; }; Struct(GpuRWBufferPtr) { u32 v; };
Struct(ComputeShader) { ResourceKey resource; }; 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; };
//- Resource descriptor index types #define IsGpuPtrNil(p) ((p).v == 0)
Struct(StructuredBufferRid) { u32 v; }; #elif IsLanguageGpu
Struct(RWStructuredBufferRid) { u32 v; }; //- Shader declaration
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; };
#elif LanguageIsGpu #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__)
typedef u32 GpuBuffer; //- Semantic declaration
typedef u32 GpuTexture;
typedef u32 GpuSampler;
//- Shader declaration # define Semantic(t, n) t n : n
# define ComputeShader(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 //- Pointers
# define Semantic(t, n) t n : n
//- Descriptor heap index typedef GpuBufferPtr u32;
# define UniformResourceFromRid(rid) ResourceDescriptorHeap[rid] typedef GpuRWBufferPtr u32;
# define UniformSamplerFromRid(rid) SamplerDescriptorHeap[rid] typedef GpuIndexBufferPtr u32;
# define NonUniformResourceFromRid(rid) ResourceDescriptorHeap[NonUniformResourceIndex(rid)] typedef GpuTexture1DPtr u32;
# define NonUniformSamplerFromRid(rid) SamplerDescriptorHeap[NonUniformResourceIndex(rid)] 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 #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Fibers //~ Fibers
# define MaxFibers 4096 #define MaxFibers 4096
StaticAssert(MaxFibers < I16Max); /* MaxFibers should fit in FiberId */ StaticAssert(MaxFibers < I16Max); /* MaxFibers should fit in FiberId */
#if LanguageIsC #if IsLanguageC
# if PlatformIsWindows #if IsPlatformWindows
# define FiberId() (*(volatile i16 *)__readgsqword(0x20)) #define FiberId() (*(volatile i16 *)__readgsqword(0x20))
# else #else
# error FiberId not implemented #error FiberId not implemented
# endif #endif
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Exit callback types //~ Exit callback types
#if LanguageIsC #if IsLanguageC
# define ExitFuncDef(name) void name(void) #define ExitFuncDef(name) void name(void)
typedef ExitFuncDef(ExitFunc); typedef ExitFuncDef(ExitFunc);
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Api hooks //~ @hookdecl Api hooks
#if LanguageIsC #if IsLanguageC
//- Core hooks
//- Core hooks StringList GetRawCommandline(void);
StringList GetRawCommandline(void); void Echo(String msg);
void Echo(String msg); b32 Panic(String msg);
b32 Panic(String msg); b32 IsRunningInDebugger(void);
b32 IsRunningInDebugger(void); i64 TimeNs(void);
i64 TimeNs(void); u32 GetNumHardwareThreads(void);
u32 GetNumHardwareThreads(void); void TrueRand(String buffer);
void TrueRand(String buffer); void OnExit(ExitFunc *func);
void OnExit(ExitFunc *func); void SignalExit(i32 code);
void SignalExit(i32 code); void ExitNow(i32 code);
void ExitNow(i32 code);
//- Meta hooks
void StartupLayers(void);
//- Meta hooks
void StartupLayers(void);
#endif #endif
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

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

View File

@ -85,7 +85,7 @@ JobPoolId AsyncPool(void);
void job(job##_Sig *, i32); \ void job(job##_Sig *, i32); \
StaticAssert(1) 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 //~ @hookdecl Job dispatch operations

View File

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

View File

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

View File

@ -33,7 +33,7 @@ void SetMemoryReadWrite(void *address, u64 size);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Crtlib stubs //~ Crtlib stubs
#if CrtlibIsEnabled #if IsCrtlibEnabled
# include <memory.h> # include <memory.h>
#else #else
void *memcpy(void *__restrict dst, const void *__restrict src, u64 n); 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()); Atomic32Set(&m->exclusive_fiber_id, FiberId());
#endif #endif
@ -122,7 +122,7 @@ void Unlock(Lock *l)
Mutex *m = l->mutex; Mutex *m = l->mutex;
if (l->exclusive) if (l->exclusive)
{ {
#if RtcIsEnabled #if IsRtcEnabled
Atomic32Set(&m->exclusive_fiber_id, 0); Atomic32Set(&m->exclusive_fiber_id, 0);
#endif #endif
Atomic32Set(&m->v, 0); Atomic32Set(&m->v, 0);

View File

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

View File

@ -640,7 +640,7 @@ String FormatStringV(Arena *arena, String fmt, va_list args)
} }
} }
#if RtcIsEnabled #if IsRtcEnabled
if (!no_more_args) if (!no_more_args)
{ {
FmtArg last_arg = va_arg(args, FmtArg); 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) StringList GetRawCommandline(void)
{ {
@ -110,16 +110,16 @@ void TrueRand(String buffer)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Swap hooks //~ @hookimpl Swap hooks
b32 IsSwappedIn(void) b32 IsSwappedIn(void)
{ {
return HotSwappingIsEnabled; return IsHotSwappingEnabled;
} }
b32 IsSwappingOut(void) b32 IsSwappingOut(void)
{ {
return HotSwappingIsEnabled; return IsHotSwappingEnabled;
} }
String SwappedStateFromName(Arena *arena, String name) 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) void OnExit(ExitFunc *func)
{ {
@ -199,7 +199,7 @@ void ExitNow(i32 code)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Startup / shutdown jobs //~ Startup / shutdown jobs
JobDef(W32_StartupLayers, UNUSED sig, UNUSED id) JobImpl(W32_StartupLayers, UNUSED sig, UNUSED id)
{ {
W32_SharedState *g = &W32_shared_state; W32_SharedState *g = &W32_shared_state;
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
@ -210,7 +210,7 @@ JobDef(W32_StartupLayers, UNUSED sig, UNUSED id)
EndScratch(scratch); EndScratch(scratch);
} }
JobDef(W32_ShutdownLayers, UNUSED sig, UNUSED id) JobImpl(W32_ShutdownLayers, UNUSED sig, UNUSED id)
{ {
__prof; __prof;
W32_SharedState *g = &W32_shared_state; W32_SharedState *g = &W32_shared_state;
@ -231,7 +231,7 @@ i32 W32_Main(void)
__profthread("Main thread", PROF_THREAD_GROUP_MAIN); __profthread("Main thread", PROF_THREAD_GROUP_MAIN);
W32_SharedState *g = &W32_shared_state; W32_SharedState *g = &W32_shared_state;
#if ProfilingIsEnabled #if IsProfilingEnabled
/* Start profiler */ /* Start profiler */
{ {
__profn("Launch profiler"); __profn("Launch profiler");
@ -436,7 +436,7 @@ i32 W32_Main(void)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Crt main //~ Crt main
#if CrtlibIsEnabled #if IsCrtlibEnabled
# if IsConsoleApp # if IsConsoleApp
int main(UNUSED char **argc, UNUSED int argv) 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(); return W32_Main();
} }
# endif /* IsConsoleApp */ # endif /* IsConsoleApp */
#endif /* CrtlibIsEnabled */ #endif /* IsCrtlibEnabled */
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Crt stub //~ Crt stub
#if !CrtlibIsEnabled #if !IsCrtlibEnabled
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-variable-declarations" #pragma clang diagnostic ignored "-Wmissing-variable-declarations"
@ -472,4 +472,4 @@ void __stdcall wWinMainCRTStartup(void)
#pragma clang diagnostic pop #pragma clang diagnostic pop
#endif /* !CrtlibIsEnabled */ #endif /* !IsCrtlibEnabled */

View File

@ -1,7 +1,7 @@
W32_SharedJobState W32_shared_job_state = ZI; W32_SharedJobState W32_shared_job_state = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Startup //~ @hookimpl Startup
void InitJobSystem(void) void InitJobSystem(void)
{ {
@ -23,7 +23,7 @@ void InitJobSystem(void)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Win32 thread //~ 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) 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) 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) Job *OpenJob(JobFunc *func, JobPoolId pool_id)
{ {
@ -649,7 +649,6 @@ u32 CloseJob(Job *job)
if (num_tasks == 0) if (num_tasks == 0)
{ {
Assert(0);
job->func = W32_DummyJob; job->func = W32_DummyJob;
num_tasks = 1; num_tasks = 1;
} }

View File

@ -1,7 +1,7 @@
W32_SharedLogState W32_shared_log_state = ZI; W32_SharedLogState W32_shared_log_state = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Init hooks //~ @hookimpl Init hooks
void InitLogSystem(String logfile_path) 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 /* Panic log function is separate to enforce zero side effects other than
* immediately writing to log file. */ * immediately writing to log file. */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,11 +4,11 @@
Struct(GPU_SharedUtilState) Struct(GPU_SharedUtilState)
{ {
/* Common shared resources */ /* Common shared resources */
GpuPointer pt_sampler; GpuSamplerPtr pt_sampler;
GpuPointer quad_indices; GpuIndexBufferPtr quad_indices;
GpuPointer noise_tex; GpuTexture3DPtr noise_tex;
GPU_Arena *perm_arenas[MaxFibers]; GPU_ArenaHandle perm_arenas[MaxFibers];
} extern GPU_shared_util_state; } extern GPU_shared_util_state;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -19,11 +19,16 @@ void GPU_StartupCommon(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Arena helpers //~ 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 //~ Common resource helpers
GpuPointer GPU_GetCommonPointSampler(void); GpuSamplerPtr GPU_GetCommonPointSampler(void);
GpuPointer GPU_GetCommonQuadIndices(void); GpuIndexBufferPtr GPU_GetCommonQuadIndices(void);
GpuPointer GPU_GetCommonNoise(void); GpuTexture3DPtr GPU_GetCommonNoise(void);

View File

@ -1,17 +1,22 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Opaque types //~ Handle types
Struct(GPU_Arena); Struct(GPU_ArenaHandle) { u64 v; };
Struct(GPU_CommandList);
Struct(GPU_Swapchain); Struct(GPU_CommandListHandle) { u64 v; };
Struct(GPU_ResourceHandle) { u64 v; };
Struct(GPU_SwapchainHandle) { u64 v; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Queue types //~ Queue types
#define GPU_MultiQueueEnabled !ProfilingIsEnabled #define GPU_MultiQueueIsEnabled (!IsProfilingEnabled)
Enum(GPU_QueueKind) Enum(GPU_QueueKind)
{ {
#if GPU_MultiQueueEnabled #if GPU_MultiQueueIsEnabled
GPU_QueueKind_Direct = 0, GPU_QueueKind_Direct = 0,
GPU_QueueKind_AsyncCompute = 1, GPU_QueueKind_AsyncCompute = 1,
GPU_QueueKind_AsyncCopy = 2, 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_AccessKind_AnyRead,
GPU_ShaderAccessKind_ReadWrite,
GPU_ShaderAccessKind_RasterTarget,
};
//////////////////////////////////////////////////////////// GPU_AccessKind_AnyReadWrite,
//~ Arena types
Struct(GPU_TempArena) GPU_AccessKind_CopyRead,
{ GPU_AccessKind_CopyWrite,
GPU_Arena *arena;
u64 start_pos; 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), GPU_BufferFlag_Writable = (1 << 0),
}; };
Struct(GPU_BufferDesc)
{
u64 size;
GPU_BufferFlag flags;
GPU_AccessKind initial_access;
};
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Texture types //~ Texture types
@ -191,8 +217,8 @@ Enum(GPU_BufferFlag)
Enum(GPU_TextureFlag) Enum(GPU_TextureFlag)
{ {
GPU_TextureFlag_None = 0, GPU_TextureFlag_None = 0,
GPU_TextureFlag_Writable = (1 << 0), GPU_TextureFlag_AllowWritable = (1 << 0),
GPU_TextureFlag_Rasterizable = (1 << 1), GPU_TextureFlag_AllowRasterTarget = (1 << 1),
}; };
Enum(GPU_TextureKind) Enum(GPU_TextureKind)
@ -204,11 +230,13 @@ Enum(GPU_TextureKind)
Struct(GPU_TextureDesc) Struct(GPU_TextureDesc)
{ {
GPU_TextureFlag flags; GPU_TextureKind kind;
GPU_Format format; 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; Vec4 clear_color;
i32 mip_levels;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -314,8 +342,8 @@ Enum(GPU_RasterMode)
GPU_RasterMode_LineList, GPU_RasterMode_LineList,
GPU_RasterMode_LineStrip, GPU_RasterMode_LineStrip,
GPU_RasterMode_TriangleList, GPU_RasterMode_TriangleList,
GPU_RasterMode_WireTriangleList,
GPU_RasterMode_TriangleStrip, GPU_RasterMode_TriangleStrip,
GPU_RasterMode_WireTriangleList,
GPU_RasterMode_WireTriangleStrip, GPU_RasterMode_WireTriangleStrip,
}; };
@ -333,6 +361,8 @@ Struct(GPU_Stats)
/* Resources */ /* Resources */
u64 driver_resources_allocated; u64 driver_resources_allocated;
u64 driver_descriptors_allocated; u64 driver_descriptors_allocated;
/* TODO: Arena stats (committed, reserved, etc) */
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -341,66 +371,133 @@ Struct(GPU_Stats)
void GPU_Startup(void); void GPU_Startup(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Arenas //~ @hookdecl Arena
GPU_Arena *GPU_AcquireArena(void); GPU_ArenaHandle GPU_AcquireArena(void);
void GPU_ReleaseArena(GPU_Arena *arena); 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); //- Resource creation
#define GPU_PushBuffer(arena, type, count, flags) GPU_PushBufferEx((arena), sizeof(type), alignof(type), (count), (flags))
GpuPointer GPU_PushTextureEx(GPU_Arena *arena, GPU_TextureDesc desc); GPU_ResourceHandle GPU_PushBufferEx(GPU_ArenaHandle arena, GPU_BufferDesc desc);
GpuPointer GPU_PushTexture(GPU_Arena *arena, GPU_TextureKind kind, GPU_Format format, Vec3I32 size, GPU_TextureFlag flags); 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 //- Command list
GPU_CommandList *GPU_OpenCommandList(GPU_QueueKind queue); GPU_CommandListHandle GPU_OpenCommandList(GPU_QueueKind queue);
void GPU_CloseCommandList(GPU_CommandList *cl); void GPU_CloseCommandList(GPU_CommandListHandle cl);
//- Cpu -> Gpu //- Arena
void GPU_CopyBytesFromCpu(GPU_CommandList *cl, GpuPointer dst, RngU64 dst_range, void *src); void GPU_ResetArena(GPU_CommandListHandle cl, GPU_ArenaHandle arena);
void GPU_CopyTexelsFromCpu(GPU_CommandList *cl, GpuPointer dst, Rng3U64 dst_range, void *src);
void GPU_CopyFromCpu(GPU_CommandList *cl, GpuPointer dst, String src);
//- Gpu -> Cpu //- Copy
void GPU_AddCpuFence(GPU_CommandList *cl, Fence *fence, i64 v); void GPU_CopyBuffer(GPU_CommandListHandle cl, GPU_ResourceHandle dst, u64 dst_offset, GPU_ResourceHandle src, u64 src_offset, u64 size);
void GPU_SetCpuFence(GPU_CommandList *cl, Fence *fence, i64 v); void GPU_CopyTexture(GPU_CommandListHandle cl, GPU_ResourceHandle dst, Vec3I32 dst_offset, GPU_ResourceHandle src, Vec3I32 src_offset, Vec3I32 dims);
//- Implicit state //- Constants
void GPU_SetShaderAccess(GPU_CommandList *cl, GpuPointer ptr, GPU_ShaderAccessKind access_kind); void GPU_SetConstU32 (GPU_CommandListHandle cl, i32 slot, u32 v);
void GPU_SetRasterizeMode(GPU_CommandList *cl, GPU_RasterMode mode); void GPU_SetConstF32 (GPU_CommandListHandle cl, i32 slot, f32 v);
void GPU_SetConstantU32(GPU_CommandList *cl, i32 slot, u32 v); void GPU_SetConstBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuBufferPtr v);
void GPU_SetConstantF32(GPU_CommandList *cl, i32 slot, f32 v); void GPU_SetConstRWBufferPtr (GPU_CommandListHandle cl, i32 slot, GpuRWBufferPtr v);
void GPU_SetConstantPtr(GPU_CommandList *cl, i32 slot, GpuPointer 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 //- Access
void GPU_ClearRasterTarget(GPU_CommandList *cl, GpuPointer target); void GPU_SetAccess(GPU_CommandListHandle cl, GPU_ResourceHandle resource, GPU_AccessKind kind);
//- Compute //- Compute
void GPU_Compute(GPU_CommandList *cl, ComputeShader cs, Vec3U32 threads); void GPU_Compute(GPU_CommandListHandle cl, ComputeShader cs, Vec3I32 groups);
//- Rasterize //- Rasterize
void GPU_RasterizeEx(GPU_CommandList *cl, void GPU_Rasterize(GPU_CommandListHandle cl,
VertexShader vs, PixelShader ps, VertexShader vs, PixelShader ps,
u32 instances_count, u32 instances_count, GpuIndexBufferPtr idx_buff,
GpuPointer idx_buff, RngU64 idx_buff_range, u32 raster_targets_count, GpuRasterTargetPtr *raster_targets,
u32 raster_targets_count, GpuPointer *raster_targets, Rng3 viewport, Rng2 scissor,
Rng3 viewport, Rng2 scissor); GPU_RasterMode mode);
void GPU_Rasterize(GPU_CommandList *cl, //- Clear
VertexShader vs, PixelShader ps, void GPU_ClearRasterTarget(GPU_CommandListHandle cl, GpuRasterTargetPtr ptr);
u32 instances_count, GpuPointer idx_buff,
u32 raster_targets_count, GpuPointer *raster_targets);
//- Profiling //- Profile
void GPU_ProfN(GPU_CommandList *cl, String name); void GPU_ProfN(GPU_CommandListHandle cl, String name);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Statistics //~ @hookdecl Statistics
@ -410,15 +507,19 @@ GPU_Stats GPU_QueryStats(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Swapchain //~ @hookdecl Swapchain
GPU_Swapchain *GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size); GPU_SwapchainHandle GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size);
void GPU_ReleaseSwapchain(GPU_Swapchain *swapchain); void GPU_ReleaseSwapchain(GPU_SwapchainHandle swapchain);
/* Waits until a new backbuffer is ready to be written to. /* Waits until a new backbuffer is ready to be written to.
* This should be called before rendering for minimum latency. */ * 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 /* 1. Recreates backbuffer at desired size if necessary
* 2. Blits the source texture into the backbuffer * 2. Clears the backbuffer using clear color
* 3. Presents the backbuffer * 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)) | ((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_MaxSamplerDescriptors (1024 * 1)
#define GPU_D12_MaxRtvDescriptors (1024 * 1) #define GPU_D12_MaxRtvDescriptors (1024 * 64)
////////////////////////////////////////////////////////////
//~ Arena types
Struct(GPU_D12_Arena)
{
i32 _;
};
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Pipeline types //~ Pipeline types
@ -62,7 +70,9 @@ Struct(GPU_D12_PipelineBin)
Struct(GPU_D12_Descriptor) Struct(GPU_D12_Descriptor)
{ {
GPU_D12_Descriptor *next_free; GPU_D12_Descriptor *next_free;
struct GPU_D12_DescriptorHeap *heap; struct GPU_D12_DescriptorHeap *heap;
struct GPU_D12_Resource *resource;
b32 valid; b32 valid;
u32 index; u32 index;
@ -92,23 +102,18 @@ Struct(GPU_D12_DescriptorHeap)
Struct(GPU_D12_Resource) Struct(GPU_D12_Resource)
{ {
GPU_D12_Resource *next_free; GPU_D12_Resource *next_free;
GPU_ResourceDesc desc;
ID3D12Resource *d3d_resource; ID3D12Resource *d3d_resource;
D3D12_RESOURCE_STATES state;
u64 buffer_size; /* Actual size of buffer in GPU memory */ D3D12_BARRIER_LAYOUT layout;
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;
/* Buffer info */
GPU_BufferDesc buffer_desc;
D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address; D3D12_GPU_VIRTUAL_ADDRESS buffer_gpu_address;
/* Texture info */
b32 is_texture;
GPU_TextureDesc texture_desc;
}; };
Struct(GPU_D12_ResourceReuseList) Struct(GPU_D12_ResourceReuseList)
@ -130,10 +135,16 @@ Struct(GPU_D12_ResourceReuseListBin)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Queue types //~ Queue types
Struct(GPU_D12_CommandQueueDesc)
{
D3D12_COMMAND_LIST_TYPE type;
D3D12_COMMAND_QUEUE_PRIORITY priority;
};
Struct(GPU_D12_Queue) Struct(GPU_D12_Queue)
{ {
GPU_D12_QueueDesc desc;
ID3D12CommandQueue *d3d_queue; ID3D12CommandQueue *d3d_queue;
GPU_D12_CommandQueueDesc desc;
Mutex submit_mutex; Mutex submit_mutex;
ID3D12Fence *submit_fence; ID3D12Fence *submit_fence;
@ -161,83 +172,107 @@ Struct(GPU_D12_RawCommandList)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Command list types //~ Command list types
Enum(GPU_D12_CommandKind) #define GPU_D12_CmdsPerChunk 256
{
GPU_D12_CommandKind_None,
/* Barrier */ Enum(GPU_D12_CmdKind)
GPU_D12_CommandKind_TransitionToSrv, {
GPU_D12_CommandKind_TransitionToUav, GPU_D12_CmdKind_None,
GPU_D12_CommandKind_TransitionToRtv,
GPU_D12_CommandKind_TransitionToCopySrc, /* Access */
GPU_D12_CommandKind_TransitionToCopyDst, GPU_D12_CmdKind_SetAccess,
GPU_D12_CommandKind_FlushUav,
/* Constant */
GPU_D12_CmdKind_SetConstant,
/* Copy */ /* Copy */
GPU_D12_CommandKind_Copy, GPU_D12_CmdKind_Copy,
/* Clear */
GPU_D12_CommandKind_ClearRtv,
/* Rasterize */
GPU_D12_CommandKind_Rasterize,
/* Compute */ /* 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_CmdKind kind;
GPU_D12_CommandKind kind;
union union
{ {
struct struct
{ {
GPU_D12_Resource *resource; GPU_D12_Resource *resource;
i32 rt_slot; GPU_AccessKind access_kind;
} barrier; } access;
struct
{
i32 slot;
u32 value;
} constant;
struct struct
{ {
GPU_D12_Resource *dst; GPU_D12_Resource *dst;
GPU_D12_Resource *src; GPU_D12_Resource *src;
String src_string; u64 dst_offset;
} copy; u64 src_offset;
u64 size;
} copy_bytes;
struct struct
{ {
GPU_D12_Resource *resource; GPU_D12_Resource *dst;
} clear; GPU_D12_Resource *src;
Vec3I32 dst_offset;
Vec3I32 src_offset;
Vec3I32 size;
} copy_texels;
struct
{
ComputeShader cs;
Vec3I32 groups;
} compute;
struct struct
{ {
u32 sig_size;
u8 sig[256];
VertexShader vs; VertexShader vs;
PixelShader ps; PixelShader ps;
u32 rts_count;
GPU_Viewport viewport;
GPU_Scissor scissor;
u32 instances_count; u32 instances_count;
GPU_D12_Resource *index_buffer; D3D12_INDEX_BUFFER_VIEW ibv;
GPU_RasterizeMode mode; GPU_D12_Descriptor *rtv_descriptors[GPU_MaxRasterTargets];
Rng3 viewport;
Rng2 scissor;
GPU_RasterMode mode;
} rasterize; } rasterize;
struct struct
{ {
u32 sig_size; GPU_D12_Descriptor *rtv_descriptor;
u8 sig[256]; } clear_rtv;
ComputeShader cs;
u32 num_threads_x;
u32 num_threads_y;
u32 num_threads_z;
} compute;
}; };
}; };
Struct(GPU_D12_CommandList) Struct(GPU_D12_CmdChunk)
{ {
GPU_D12_CommandList *next; GPU_D12_CmdChunk *next;
GPU_D12_Command *first; struct GPU_D12_CmdList *cl;
GPU_D12_Command *last; GPU_D12_Cmd *cmds;
u64 count; 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; GPU_QueueKind queue_kind;
}; };
@ -249,7 +284,6 @@ Struct(GPU_D12_SwapchainBuffer)
{ {
struct GPU_D12_Swapchain *swapchain; struct GPU_D12_Swapchain *swapchain;
ID3D12Resource *d3d_resource; ID3D12Resource *d3d_resource;
GPU_D12_Descriptor *rtv_descriptor;
D3D12_RESOURCE_STATES state; D3D12_RESOURCE_STATES state;
}; };
@ -269,14 +303,6 @@ Struct(GPU_D12_Swapchain)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ State types //~ 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) Struct(GPU_D12_SharedState)
{ {
Atomic64Padded resource_barrier_gen; Atomic64Padded resource_barrier_gen;
@ -286,7 +312,7 @@ Struct(GPU_D12_SharedState)
Atomic64 driver_descriptors_allocated; Atomic64 driver_descriptors_allocated;
/* Queues */ /* Queues */
GPU_D12_Queue *queues[GPU_NumQueues]; GPU_D12_Queue queues[GPU_NumQueues];
/* Rootsig */ /* Rootsig */
ID3D12RootSignature *bindless_rootsig; ID3D12RootSignature *bindless_rootsig;
@ -295,14 +321,17 @@ Struct(GPU_D12_SharedState)
GPU_D12_PipelineBin pipeline_bins[1024]; GPU_D12_PipelineBin pipeline_bins[1024];
/* Descriptor heaps */ /* Descriptor heaps */
GPU_D12_DescriptorHeap *cbv_srv_uav_heap; GPU_D12_DescriptorHeap cbv_srv_uav_heap;
GPU_D12_DescriptorHeap *sampler_heap; GPU_D12_DescriptorHeap sampler_heap;
GPU_D12_DescriptorHeap *rtv_heap; GPU_D12_DescriptorHeap rtv_heap;
/* Resources */ /* Command lists */
Mutex free_resources_mutex; Mutex free_cmd_lists_mutex;
GPU_D12_Resource *first_free_resource; GPU_D12_CmdList *first_free_cmd_list;
GPU_D12_ResourceReuseListBin resource_reuse_bins[GPU_D12_NumResourceReuseBins];
/* Command chunks */
Mutex free_cmd_chunks_mutex;
GPU_D12_CmdChunk *first_free_cmd_chunk;
/* Swapchains */ /* Swapchains */
Mutex free_swapchains_mutex; Mutex free_swapchains_mutex;
@ -314,33 +343,19 @@ Struct(GPU_D12_SharedState)
ID3D12Device *device; ID3D12Device *device;
} extern GPU_D12_shared_state; } 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 //~ Startup
void GPU_D12_Startup(void); void GPU_D12_Startup(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Initialization //~ Helpers
//- Device initialization DXGI_FORMAT GPU_D12_DxgiFormatFromGpuFormat(GPU_Format format);
void GPU_D12_InitDevice(void); GPU_D12_Arena *GPU_D12_ArenaFromHandle(GPU_ArenaHandle handle);
GPU_D12_CmdList *GPU_D12_CommandListFromHandle(GPU_CommandListHandle handle);
//- Queue initialization GPU_D12_Resource *GPU_D12_ResourceFromHandle(GPU_ResourceHandle handle);
JobDecl(GPU_D12_InitQueue, { GPU_D12_QueueDesc *descs; }); GPU_D12_Swapchain *GPU_D12_SwapchainFromHandle(GPU_SwapchainHandle handle);
//- 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);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Pipeline operations //~ 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); GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_DescriptorHeap *heap);
void GPU_D12_ReleaseDescriptor(GPU_D12_Descriptor *descriptor); 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 //~ Raw command list operations
GPU_D12_RawCommandList *GPU_D12_BeginRawCommandList(GPU_QueueKind queue_kind); GPU_D12_RawCommandList *GPU_D12_BeginRawCommandList(GPU_QueueKind queue_kind);
u64 GPU_D12_EndRawCommandList(GPU_D12_RawCommandList *cl); u64 GPU_D12_EndRawCommandList(GPU_D12_RawCommandList *cl);
////////////////////////////////////////////////////////////
//~ Command helpers
GPU_D12_Cmd *GPU_D12_PushCmd(GPU_D12_CmdList *cl);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Swapchain helpers //~ Swapchain helpers
void GPU_D12_InitSwapchainResources(GPU_D12_Swapchain *swapchain); void GPU_D12_InitSwapchainResources(GPU_D12_Swapchain *swapchain);
GPU_D12_SwapchainBuffer *GPU_D12_UpdateSwapchain(GPU_D12_Swapchain *swapchain, Vec2I32 resolution); 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 //~ Sync job

View File

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

View File

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

View File

@ -26,14 +26,14 @@ String W32_StringFromError(Arena *arena, DWORD err)
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Startup hook //~ @hookimpl Startup hook
void OS_Startup(void) void OS_Startup(void)
{ {
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef File system hooks //~ @hookimpl File system hooks
OS_File OS_OpenFile(String path, OS_FileFlag flags, i64 timeout_ns) 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) 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) OS_CommandResult OS_RunCommand(Arena *arena, String cmd)
{ {

View File

@ -1,7 +1,7 @@
P_W32_SharedState P_W32_shared_state = ZI; P_W32_SharedState P_W32_shared_state = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Startup //~ @hookimpl Startup
void P_Startup(void) void P_Startup(void)
{ {
@ -158,7 +158,7 @@ P_Address P_W32_PlatformAddressFromWin32Address(P_W32_Address ws_addr)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Timer job //~ Timer job
JobDef(P_W32_StartTimerSync, _, __) JobImpl(P_W32_StartTimerSync, _, __)
{ {
P_W32_SharedState *g = &P_W32_shared_state; P_W32_SharedState *g = &P_W32_shared_state;
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); 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 //- File system helpers
String P_GetWritePath(Arena *arena) 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) 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) 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) 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 else
{ {
#if RtcIsEnabled #if IsRtcEnabled
i32 err = WSAGetLastError(); i32 err = WSAGetLastError();
if (err != WSAEWOULDBLOCK && err != WSAETIMEDOUT && err != WSAECONNRESET) 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); AddGstat(GSTAT_SOCK_BYTES_SENT, size);
} }
#if RtcIsEnabled #if IsRtcEnabled
if (size != (i32)data.len) if (size != (i32)data.len)
{ {
i32 err = WSAGetLastError(); 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) 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) 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) 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 //~ Playback job
JobDef(PB_WSP_Playback, UNUSED sig, UNUSED id) JobImpl(PB_WSP_Playback, UNUSED sig, UNUSED id)
{ {
__prof; __prof;
PB_WSP_SharedState *g = &PB_WSP_shared_state; PB_WSP_SharedState *g = &PB_WSP_shared_state;

View File

@ -1,48 +1,4 @@
@Layer pp @Layer pp
//- Dependencies @Dep pp_sim
@Dep gpu @Dep pp_vis
@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

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

View File

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

View File

@ -5,10 +5,10 @@ ConstantBuffer<V_DVertSig> V_dvert_sig : register (b0);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Backdrop shader //~ Backdrop shader
ComputeShader(V_BackdropCS, 8, 8, 1) ComputeShader2D(V_BackdropCS, 8, 8)
{ {
ConstantBuffer<V_BackdropSig> sig = V_backdrop_sig; ConstantBuffer<V_BackdropSig> sig = V_backdrop_sig;
Vec2U32 target_pos = SV_DispatchThreadID.xy; Vec2U32 target_pos = SV_DispatchThreadID;
Vec2I32 target_size = sig.target_size; Vec2I32 target_size = sig.target_size;
if (target_pos.x < target_size.x && target_pos.y < target_size.y) 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 e0;
LAX e1; LAX e1;
#if DeveloperIsEnabled #if IsDeveloperModeEnabled
/* Draw contact points */ /* Draw contact points */
{ {
f32 radius = 5; f32 radius = 5;
@ -1893,7 +1893,7 @@ void PP_UpdateUser(void)
} }
} }
#if RtcIsEnabled #if IsRtcEnabled
/* Gjk steps */ /* Gjk steps */
{ {
if (g->bind_states[PP_BindKind_ResetDebugSteps].num_presses_and_repeats > 0) 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"));
//UI_BuildLabelF(\n")); //UI_BuildLabelF(\n"));
#if RtcIsEnabled #if IsRtcEnabled
UI_BuildSpacer(UI_FNT(1, 0)); UI_BuildSpacer(UI_FNT(1, 0));
UI_BuildLabelF("Debug steps: %F", FmtUint(GetGstat(GSTAT_DEBUG_STEPS))); UI_BuildLabelF("Debug steps: %F", FmtUint(GetGstat(GSTAT_DEBUG_STEPS)));
//UI_BuildLabelF(\n")); //UI_BuildLabelF(\n"));
@ -2410,7 +2410,7 @@ void PP_UpdateUser(void)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ User update job //~ User update job
JobDef(PP_UpdateUserOrSleep, UNUSED sig, UNUSED key) JobImpl(PP_UpdateUserOrSleep, UNUSED sig, UNUSED key)
{ {
PP_SharedUserState *g = &PP_shared_user_state; PP_SharedUserState *g = &PP_shared_user_state;
i64 time_ns = TimeNs(); i64 time_ns = TimeNs();
@ -2470,7 +2470,7 @@ void PP_GenerateuserInputCmds(PP_Client *user_input_client, u64 tick)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Sim update //~ Sim update
JobDef(PP_UpdateSim, UNUSED sig, UNUSED key) JobImpl(PP_UpdateSim, UNUSED sig, UNUSED key)
{ {
PP_SharedUserState *g = &PP_shared_user_state; PP_SharedUserState *g = &PP_shared_user_state;
#if 0 #if 0

View File

@ -40,7 +40,7 @@ Enum(PP_BindKind)
PP_BindKind_ZoomOut, PP_BindKind_ZoomOut,
PP_BindKind_Pan, PP_BindKind_Pan,
#if RtcIsEnabled #if IsRtcEnabled
/* Debug */ /* Debug */
PP_BindKind_ResetDebugSteps, PP_BindKind_ResetDebugSteps,
@ -92,7 +92,7 @@ Global Readonly PP_BindKind g_binds[Btn_Count] = {
[Btn_MWheelDown] = PP_BindKind_ZoomOut, [Btn_MWheelDown] = PP_BindKind_ZoomOut,
[Btn_M3] = PP_BindKind_Pan, [Btn_M3] = PP_BindKind_Pan,
#if RtcIsEnabled #if IsRtcEnabled
[Btn_ForwardSlash] = PP_BindKind_ResetDebugSteps, [Btn_ForwardSlash] = PP_BindKind_ResetDebugSteps,
[Btn_Comma] = PP_BindKind_DecrementDebugSteps, [Btn_Comma] = PP_BindKind_DecrementDebugSteps,
[Btn_Period] = PP_BindKind_IncrementDebugSteps [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 */ /* Insert new key into lookup */
if (!PP_IsNilEntKey(key)) if (!PP_IsNilEntKey(key))
{ {
#if RtcIsEnabled #if IsRtcEnabled
{ {
PP_Ent *existing = PP_EntFromKey(ss, key); PP_Ent *existing = PP_EntFromKey(ss, key);
/* Collision should be extremely unlikely under normal circumstances, there's probably a logic error somewhere. */ /* 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->vcp1 = SubVec2(point, e1_xf.og);
contact->starting_separation = sep; contact->starting_separation = sep;
#if DeveloperIsEnabled #if IsDeveloperModeEnabled
contact->dbg_pt = point; contact->dbg_pt = point;
#endif #endif
} }

View File

@ -54,7 +54,7 @@ Struct(PP_ContactPoint)
f32 inv_tangent_mass; f32 inv_tangent_mass;
/* Debugging */ /* Debugging */
#if DeveloperIsEnabled #if IsDeveloperModeEnabled
Vec2 dbg_pt; Vec2 dbg_pt;
#endif #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 push
#pragma clang diagnostic ignored "-Weverything" #pragma clang diagnostic ignored "-Weverything"

View File

@ -1,10 +1,10 @@
#if defined(ProfilingIsEnabled) && ProfilingIsEnabled == 1 #if defined(IsProfilingEnabled) && IsProfilingEnabled == 1
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Profiling enabled //~ Profiling enabled
#ifndef __clang__ #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 #endif
#define ProfilingSystemTrace 0 #define ProfilingSystemTrace 0
@ -82,7 +82,7 @@ enum __prof_plot_type {
#define __prof_plot_i(name, val) #define __prof_plot_i(name, val)
#define __prof_is_connected() 0 #define __prof_is_connected() 0
#endif /* ProfilingIsEnabled */ #endif /* IsProfilingEnabled */
#if ProfilingLocks #if ProfilingLocks
# define __proflock_ctx(name) struct TracyCSharedLockCtx *name # 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_after_try_shared_lock(ctx, acquired)
# define __proflock_mark(ctx) # define __proflock_mark(ctx)
# define __proflock_custom_name(ctx, name, len) # define __proflock_custom_name(ctx, name, len)
#endif /* ProfilingIsEnabled && ProfilingLocks */ #endif /* IsProfilingEnabled && ProfilingLocks */
#if ProfilingGpu #if ProfilingGpu
/* Dx11 */ /* 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 //~ Load job
JobDef(SND_Load, sig, UNUSED id) JobImpl(SND_Load, sig, UNUSED id)
{ {
__prof; __prof;
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();

View File

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

View File

@ -4,7 +4,7 @@
TTF_DW_SharedState TTF_DW_shared_state = ZI; TTF_DW_SharedState TTF_DW_shared_state = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Startup //~ @hookimpl Startup
/* Call this during font system startup */ /* Call this during font system startup */
void TTF_Startup(void) 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 * 10? Need to verify. Maybe should just use a custom loader. (We're only
* using a factory5 since I think WriteInMemoryFileLoader wasn't * using a factory5 since I think WriteInMemoryFileLoader wasn't
* implemented until then) */ * implemented until then) */
#if CompilerIsClang #if IsCompilerClang
# pragma clang diagnostic push # pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wlanguage-extension-token" /* for __uuidof */ # pragma clang diagnostic ignored "-Wlanguage-extension-token" /* for __uuidof */
#endif #endif
@ -25,7 +25,7 @@ void TTF_Startup(void)
&IID_IDWriteFactory5, &IID_IDWriteFactory5,
(void **)&g->factory (void **)&g->factory
); );
#if CompilerIsClang #if IsCompilerClang
# pragma clang diagnostic pop # pragma clang diagnostic pop
#endif #endif
if (error != S_OK) 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) 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; WND_W32_SharedState WND_W32_shared_state = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Startup //~ @hookimpl Startup
void WND_Startup(void) void WND_Startup(void)
{ {
@ -102,7 +102,7 @@ WND_W32_Window *WND_W32_WindowFromHandle(WND_Handle handle)
//~ Initialization //~ Initialization
/* Win32 limitation: Window must be initialized on same thread that processes events */ /* 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_SharedState *g = &WND_W32_shared_state;
WND_W32_Window *window = &g->window; 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) 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) WND_Frame WND_BeginFrame(void)
{ {