//////////////////////////////////////////////////////////// //~ Opaque types Struct(GPU_Arena); Struct(GPU_CommandList); Struct(GPU_Swapchain); //////////////////////////////////////////////////////////// //~ Queue types #define GPU_MultiQueueEnabled !ProfilingIsEnabled Enum(GPU_QueueKind) { #if GPU_MultiQueueEnabled GPU_QueueKind_Direct = 0, GPU_QueueKind_Compute = 1, GPU_QueueKind_Copy = 2, GPU_QueueKind_BackgroundCopy = 3, GPU_NumQueues = 4 #else GPU_QueueKind_Direct = 0, GPU_QueueKind_Compute = 0, GPU_QueueKind_Copy = 0, GPU_QueueKind_BackgroundCopy = 0, GPU_NumQueues = 1 #endif }; //////////////////////////////////////////////////////////// //~ Format types /* NOTE: Matches DirectX DXGI_FORMAT */ Enum(GPU_Format) { GPU_Format_Unknown = 0, GPU_Format_R32G32B32A32_Typeless = 1, GPU_Format_R32G32B32A32_Float = 2, GPU_Format_R32G32B32A32_Uint = 3, GPU_Format_R32G32B32A32_Sint = 4, GPU_Format_R32G32B32_Typeless = 5, GPU_Format_R32G32B32_Float = 6, GPU_Format_R32G32B32_Uint = 7, GPU_Format_R32G32B32_Sint = 8, GPU_Format_R16G16B16A16_Typeless = 9, GPU_Format_R16G16B16A16_Float = 10, GPU_Format_R16G16B16A16_Unorm = 11, GPU_Format_R16G16B16A16_Uint = 12, GPU_Format_R16G16B16A16_Snorm = 13, GPU_Format_R16G16B16A16_Sint = 14, GPU_Format_R32G32_Typeless = 15, GPU_Format_R32G32_Float = 16, GPU_Format_R32G32_Uint = 17, GPU_Format_R32G32_Sint = 18, GPU_Format_R32G8X24_Typeless = 19, GPU_Format_D32_Float_S8X24_Uint = 20, GPU_Format_R32_Float_X8X24_Typeless = 21, GPU_Format_X32_Typeless_G8X24_Uint = 22, GPU_Format_R10G10B10A2_Typeless = 23, GPU_Format_R10G10B10A2_Unorm = 24, GPU_Format_R10G10B10A2_Uint = 25, GPU_Format_R11G11B10_Float = 26, GPU_Format_R8G8B8A8_Typeless = 27, GPU_Format_R8G8B8A8_Unorm = 28, GPU_Format_R8G8B8A8_Unorm_Srgb = 29, GPU_Format_R8G8B8A8_Uint = 30, GPU_Format_R8G8B8A8_Snorm = 31, GPU_Format_R8G8B8A8_Sint = 32, GPU_Format_R16G16_Typeless = 33, GPU_Format_R16G16_Float = 34, GPU_Format_R16G16_Unorm = 35, GPU_Format_R16G16_Uint = 36, GPU_Format_R16G16_Snorm = 37, GPU_Format_R16G16_Sint = 38, GPU_Format_R32_Typeless = 39, GPU_Format_D32_Float = 40, GPU_Format_R32_Float = 41, GPU_Format_R32_Uint = 42, GPU_Format_R32_Sint = 43, GPU_Format_R24G8_Typeless = 44, GPU_Format_D24_Unorm_S8_Uint = 45, GPU_Format_R24_Unorm_X8_Typeless = 46, GPU_Format_X24_Typeless_G8_Uint = 47, GPU_Format_R8G8_Typeless = 48, GPU_Format_R8G8_Unorm = 49, GPU_Format_R8G8_Uint = 50, GPU_Format_R8G8_Snorm = 51, GPU_Format_R8G8_Sint = 52, GPU_Format_R16_Typeless = 53, GPU_Format_R16_Float = 54, GPU_Format_D16_Unorm = 55, GPU_Format_R16_Unorm = 56, GPU_Format_R16_Uint = 57, GPU_Format_R16_Snorm = 58, GPU_Format_R16_Sint = 59, GPU_Format_R8_Typeless = 60, GPU_Format_R8_Unorm = 61, GPU_Format_R8_Uint = 62, GPU_Format_R8_Snorm = 63, GPU_Format_R8_Sint = 64, GPU_Format_A8_Unorm = 65, GPU_Format_R1_Unorm = 66, GPU_Format_R9G9B9E5_SharedXP = 67, GPU_Format_R8G8_B8G8_Unorm = 68, GPU_Format_G8R8_G8B8_Unorm = 69, GPU_Format_BC1_Typeless = 70, GPU_Format_BC1_Unorm = 71, GPU_Format_BC1_Unorm_Srgb = 72, GPU_Format_BC2_Typeless = 73, GPU_Format_BC2_Unorm = 74, GPU_Format_BC2_Unorm_Srgb = 75, GPU_Format_BC3_Typeless = 76, GPU_Format_BC3_Unorm = 77, GPU_Format_BC3_Unorm_Srgb = 78, GPU_Format_BC4_Typeless = 79, GPU_Format_BC4_Unorm = 80, GPU_Format_BC4_Snorm = 81, GPU_Format_BC5_Typeless = 82, GPU_Format_BC5_Unorm = 83, GPU_Format_BC5_Snorm = 84, GPU_Format_B5G6R5_Unorm = 85, GPU_Format_B5G5R5A1_Unorm = 86, GPU_Format_B8G8R8A8_Unorm = 87, GPU_Format_B8G8R8X8_Unorm = 88, GPU_Format_R10G10B10_XR_BIAS_A2_Unorm = 89, GPU_Format_B8G8R8A8_Typeless = 90, GPU_Format_B8G8R8A8_Unorm_Srgb = 91, GPU_Format_B8G8R8X8_Typeless = 92, GPU_Format_B8G8R8X8_Unorm_Srgb = 93, GPU_Format_BC6H_Typeless = 94, GPU_Format_BC6H_UF16 = 95, GPU_Format_BC6H_SF16 = 96, GPU_Format_BC7_Typeless = 97, GPU_Format_BC7_Unorm = 98, GPU_Format_BC7_Unorm_Srgb = 99, GPU_Format_AYUV = 100, GPU_Format_Y410 = 101, GPU_Format_Y416 = 102, GPU_Format_NV12 = 103, GPU_Format_P010 = 104, GPU_Format_P016 = 105, GPU_Format_420_Opaque = 106, GPU_Format_YUY2 = 107, GPU_Format_Y210 = 108, GPU_Format_Y216 = 109, GPU_Format_NV11 = 110, GPU_Format_AI44 = 111, GPU_Format_IA44 = 112, GPU_Format_P8 = 113, GPU_Format_A8P8 = 114, GPU_Format_B4G4R4A4_Unorm = 115, GPU_Format_P208 = 130, GPU_Format_V208 = 131, GPU_Format_V408 = 132, GPU_Format_SamplerFeedbackMinMipOpaque = 189, GPU_Format_SamplerFeedbackMipRegionUsedOpaque = 190, GPU_Format_A4B4G4R4_Unorm = 191, GPU_Format_Count = 192 }; //////////////////////////////////////////////////////////// //~ Shader access types Enum(GPU_ShaderAccessKind) { GPU_ShaderAccessKind_Readonly, /* Default state for all resources */ GPU_ShaderAccessKind_ReadWrite, GPU_ShaderAccessKind_RasterTarget, }; //////////////////////////////////////////////////////////// //~ Arena types Struct(GPU_TempArena) { GPU_Arena *arena; u64 start_pos; }; //////////////////////////////////////////////////////////// //~ Buffer types Enum(GPU_BufferFlag) { GPU_BufferFlag_None = 0, GPU_BufferFlag_Writable = (1 << 0), }; //////////////////////////////////////////////////////////// //~ Texture types #define GPU_MaxRasterTargets 8 Enum(GPU_TextureFlag) { GPU_TextureFlag_None = 0, GPU_TextureFlag_Writable = (1 << 0), GPU_TextureFlag_Rasterizable = (1 << 1), }; Enum(GPU_TextureKind) { GPU_TextureKind_1D, GPU_TextureKind_2D, GPU_TextureKind_3D, }; Struct(GPU_TextureDesc) { GPU_TextureFlag flags; GPU_Format format; Vec3I32 size; Vec4 clear_color; i32 mip_levels; }; //////////////////////////////////////////////////////////// //~ Sampler types /* NOTE: Matches DirectX D3D12_FILTER */ Enum(GPU_Filter) { /* Standard filter */ GPU_Filter_MinMagMipPoint = 0, GPU_Filter_MinMagPointMipLinear = 0x1, GPU_Filter_MinPointMagLinearMipPoint = 0x4, GPU_Filter_MinPointMagMipLinear = 0x5, GPU_Filter_MinLinearMagMipPoint = 0x10, GPU_Filter_MinLinearMagPointMipLinear = 0x11, GPU_Filter_MinMagLinearMipPoint = 0x14, GPU_Filter_MinMagMipLinear = 0x15, GPU_Filter_MinMagAnisotropicMipPoint = 0x54, GPU_Filter_Anisotropic = 0x55, /* Comparison filter */ GPU_Filter_Comparison_MinMagMipPoint = 0x80, GPU_Filter_Comparison_MinMagPointMipLinear = 0x81, GPU_Filter_Comparison_MinPointMagLinearMipPoint = 0x84, GPU_Filter_Comparison_MinPointMagMipLinear = 0x85, GPU_Filter_Comparison_MinLinearMagMipPoint = 0x90, GPU_Filter_Comparison_MinLinearMagPointMipLinear = 0x91, GPU_Filter_Comparison_MinMagLinearMipPoint = 0x94, GPU_Filter_Comparison_MinMagMipLinear = 0x95, GPU_Filter_Comparison_MinMagAnisotropicMipPoint = 0xd4, GPU_Filter_Comparison_Anisotropic = 0xd5, /* Minimum filter */ GPU_Filter_Minimum_MinMagMipPoint = 0x100, GPU_Filter_Minimum_MinMagPointMipLinear = 0x101, GPU_Filter_Minimum_MinPointMagLinearMipPoint = 0x104, GPU_Filter_Minimum_MinPointMagMipLinear = 0x105, GPU_Filter_Minimum_MinLinearMagMipPoint = 0x110, GPU_Filter_Minimum_MinLinearMagPointMipLinear = 0x111, GPU_Filter_Minimum_MinMagLinearMipPoint = 0x114, GPU_Filter_Minimum_MinMagMipLinear = 0x115, GPU_Filter_Minimum_MinMagAnisotropicMipPoint = 0x155, GPU_Filter_Minimum_Anisotropic = 0x155, /* Maximum filter */ GPU_Filter_Maximum_MinMagMipPoint = 0x180, GPU_Filter_Maximum_MinMagPointMipLinear = 0x181, GPU_Filter_Maximum_MinPointMagLinearMipPoint = 0x184, GPU_Filter_Maximum_MinPointMagMipLinear = 0x185, GPU_Filter_Maximum_MinLinearMagMipPoint = 0x190, GPU_Filter_Maximum_MinLinearMagPointMipLinear = 0x191, GPU_Filter_Maximum_MinMagLinearMipPoint = 0x194, GPU_Filter_Maximum_MinMagMipLinear = 0x195, GPU_Filter_Maximum_MinMagAnisotropicMipPoint = 0x1d4, GPU_Filter_Maximum_Anisotropic = 0x1d5 }; /* NOTE: Matches DirectX D3D12_TEXTURE_ADDRESS_MODE */ Enum(GPU_AddressMode) { GPU_AddressMode_Wrap = 1, GPU_AddressMode_Mirror = 2, GPU_AddressMode_Clamp = 3, /* Default */ GPU_AddressMode_Border = 4, GPU_AddressMode_MirrorOnce = 5 }; /* NOTE: Matches DirectX D3D12_COMPARISON_FUNC */ Enum(GPU_ComparisonFunc) { GPU_ComparisonFunc_None = 0, GPU_ComparisonFunc_Never = 1, GPU_ComparisonFunc_Less = 2, GPU_ComparisonFunc_Equal = 3, GPU_ComparisonFunc_LessEqual = 4, GPU_ComparisonFunc_Greater = 5, GPU_ComparisonFunc_NotEqual = 6, GPU_ComparisonFunc_GreaterEqual = 7, GPU_ComparisonFunc_Always = 8 }; Struct(GPU_SamplerDesc) { GPU_Filter filter; GPU_AddressMode x; GPU_AddressMode y; GPU_AddressMode z; f32 mip_lod_bias; u32 max_anisotropy; GPU_ComparisonFunc comparison; Vec4 border_color; f32 min_lod; f32 max_lod; }; //////////////////////////////////////////////////////////// //~ Rasterization types Enum(GPU_RasterMode) { GPU_RasterMode_None, GPU_RasterMode_PointList, GPU_RasterMode_LineList, GPU_RasterMode_LineStrip, GPU_RasterMode_TriangleList, GPU_RasterMode_WireTriangleList, GPU_RasterMode_TriangleStrip, GPU_RasterMode_WireTriangleStrip, }; //////////////////////////////////////////////////////////// //~ Statistic types Struct(GPU_Stats) { /* Memory usage */ u64 local_committed; u64 local_budget; u64 non_local_committed; u64 non_local_budget; /* Resources */ u64 driver_resources_allocated; u64 driver_descriptors_allocated; }; //////////////////////////////////////////////////////////// //~ @hookdecl Startup void GPU_Startup(void); //////////////////////////////////////////////////////////// //~ @hookdecl Arenas GPU_Arena *GPU_AcquireArena(void); void GPU_ReleaseArena(GPU_Arena *arena); //////////////////////////////////////////////////////////// //~ @hookdecl Resource creation GpuPointer GPU_PushBufferEx(GPU_Arena *arena, i32 element_size, i32 element_align, i32 element_count, GPU_BufferFlag flags); #define GPU_PushBuffer(arena, type, count, flags) GPU_PushBufferEx((arena), sizeof(type), alignof(type), (count), (flags)) GpuPointer GPU_PushTextureEx(GPU_Arena *arena, GPU_TextureDesc desc); GpuPointer GPU_PushTexture(GPU_Arena *arena, GPU_TextureKind kind, GPU_Format format, Vec3I32 size, GPU_TextureFlag flags); GpuPointer GPU_PushSampler(GPU_Arena *arena, GPU_SamplerDesc desc); //////////////////////////////////////////////////////////// //~ @hookdecl Commands //- Command list creation GPU_CommandList *GPU_OpenCommandList(GPU_QueueKind queue); void GPU_CloseCommandList(GPU_CommandList *cl); //- Cpu -> Gpu void GPU_CopyBytesFromCpu(GPU_CommandList *cl, GpuPointer dst, RngU64 dst_range, void *src); void GPU_CopyTexelsFromCpu(GPU_CommandList *cl, GpuPointer dst, Rng3U64 dst_range, void *src); void GPU_CopyFromCpu(GPU_CommandList *cl, GpuPointer dst, String src); //- Gpu -> Cpu void GPU_AddCpuFence(GPU_CommandList *cl, Fence *fence, i64 v); void GPU_SetCpuFence(GPU_CommandList *cl, Fence *fence, i64 v); //- Implicit state void GPU_SetShaderAccess(GPU_CommandList *cl, GpuPointer ptr, GPU_ShaderAccessKind access_kind); void GPU_SetRasterizeMode(GPU_CommandList *cl, GPU_RasterMode mode); void GPU_SetConstantU32(GPU_CommandList *cl, i32 slot, u32 v); void GPU_SetConstantF32(GPU_CommandList *cl, i32 slot, f32 v); void GPU_SetConstantPtr(GPU_CommandList *cl, i32 slot, GpuPointer v); //- Clear void GPU_ClearRasterTarget(GPU_CommandList *cl, GpuPointer target); //- Compute void GPU_Compute(GPU_CommandList *cl, ComputeShader cs, Vec3U32 threads); //- Rasterize void GPU_RasterizeEx(GPU_CommandList *cl, VertexShader vs, PixelShader ps, u32 instances_count, GpuPointer idx_buff, RngU64 idx_buff_range, u32 raster_targets_count, GpuPointer *raster_targets, Rng3 viewport, Rng2 scissor); void GPU_Rasterize(GPU_CommandList *cl, VertexShader vs, PixelShader ps, u32 instances_count, GpuPointer idx_buff, u32 raster_targets_count, GpuPointer *raster_targets); //- Profiling void GPU_ProfN(GPU_CommandList *cl, String name); //////////////////////////////////////////////////////////// //~ @hookdecl Statistics GPU_Stats GPU_QueryStats(void); //////////////////////////////////////////////////////////// //~ @hookdecl Swapchain GPU_Swapchain *GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size); void GPU_ReleaseSwapchain(GPU_Swapchain *swapchain); /* Waits until a new backbuffer is ready to be written to. * This should be called before rendering for minimum latency. */ void GPU_YieldOnSwapchain(GPU_Swapchain *swapchain); /* 1. Recreates backbuffer at desired size if necessary * 2. Blits the source texture into the backbuffer * 3. 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);