sdl3.c3l/sdl3_gpu.c3i

862 lines
35 KiB
Plaintext

module sdl3::sdl;
/* SDL3_gpu.h ported to C3 */
// these are opaque in C
typedef GPUDevice = void;
typedef GPUBuffer = void;
typedef GPUTransferBuffer = void;
typedef GPUTexture = void;
typedef GPUSampler = void;
typedef GPUShader = void;
typedef GPUComputePipeline = void;
typedef GPUGraphicsPipeline = void;
typedef GPUCommandBuffer = void;
typedef GPURenderPass = void;
typedef GPUComputePass = void;
typedef GPUCopyPass = void;
typedef GPUFence = void;
/* ----- */
/* Enums */
/* ----- */
enum GPUPrimitiveType : inline CInt {
GPU_PRIMITIVETYPE_TRIANGLELIST,
GPU_PRIMITIVETYPE_TRIANGLESTRIP,
GPU_PRIMITIVETYPE_LINELIST,
GPU_PRIMITIVETYPE_LINESTRIP,
GPU_PRIMITIVETYPE_POINTLIST
}
enum GPULoadOp : inline CInt {
GPU_LOADOP_LOAD,
GPU_LOADOP_CLEAR,
GPU_LOADOP_DONT_CARE
}
enum GPUStoreOp : inline CInt {
GPU_STOREOP_STORE,
GPU_STOREOP_DONT_CARE,
GPU_STOREOP_RESOLVE,
GPU_STOREOP_RESOLVE_AND_STORE
}
enum GPUIndexElementSize : inline CInt {
GPU_INDEXELEMENTSIZE_16BIT,
GPU_INDEXELEMENTSIZE_32BIT
}
enum GPUTextureFormat : inline CInt {
GPU_TEXTUREFORMAT_INVALID,
/* Unsigned Normalized Float Color Formats */
GPU_TEXTUREFORMAT_A8_UNORM,
GPU_TEXTUREFORMAT_R8_UNORM,
GPU_TEXTUREFORMAT_R8G8_UNORM,
GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
GPU_TEXTUREFORMAT_R16_UNORM,
GPU_TEXTUREFORMAT_R16G16_UNORM,
GPU_TEXTUREFORMAT_R16G16B16A16_UNORM,
GPU_TEXTUREFORMAT_R10G10B10A2_UNORM,
GPU_TEXTUREFORMAT_B5G6R5_UNORM,
GPU_TEXTUREFORMAT_B5G5R5A1_UNORM,
GPU_TEXTUREFORMAT_B4G4R4A4_UNORM,
GPU_TEXTUREFORMAT_B8G8R8A8_UNORM,
/* Compressed Unsigned Normalized Float Color Formats */
GPU_TEXTUREFORMAT_BC1_RGBA_UNORM,
GPU_TEXTUREFORMAT_BC2_RGBA_UNORM,
GPU_TEXTUREFORMAT_BC3_RGBA_UNORM,
GPU_TEXTUREFORMAT_BC4_R_UNORM,
GPU_TEXTUREFORMAT_BC5_RG_UNORM,
GPU_TEXTUREFORMAT_BC7_RGBA_UNORM,
/* Compressed Signed Float Color Formats */
GPU_TEXTUREFORMAT_BC6H_RGB_FLOAT,
/* Compressed Unsigned Float Color Formats */
GPU_TEXTUREFORMAT_BC6H_RGB_UFLOAT,
/* Signed Normalized Float Color Formats */
GPU_TEXTUREFORMAT_R8_SNORM,
GPU_TEXTUREFORMAT_R8G8_SNORM,
GPU_TEXTUREFORMAT_R8G8B8A8_SNORM,
GPU_TEXTUREFORMAT_R16_SNORM,
GPU_TEXTUREFORMAT_R16G16_SNORM,
GPU_TEXTUREFORMAT_R16G16B16A16_SNORM,
/* Signed Float Color Formats */
GPU_TEXTUREFORMAT_R16_FLOAT,
GPU_TEXTUREFORMAT_R16G16_FLOAT,
GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT,
GPU_TEXTUREFORMAT_R32_FLOAT,
GPU_TEXTUREFORMAT_R32G32_FLOAT,
GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT,
/* Unsigned Float Color Formats */
GPU_TEXTUREFORMAT_R11G11B10_UFLOAT,
/* Unsigned Integer Color Formats */
GPU_TEXTUREFORMAT_R8_UINT,
GPU_TEXTUREFORMAT_R8G8_UINT,
GPU_TEXTUREFORMAT_R8G8B8A8_UINT,
GPU_TEXTUREFORMAT_R16_UINT,
GPU_TEXTUREFORMAT_R16G16_UINT,
GPU_TEXTUREFORMAT_R16G16B16A16_UINT,
GPU_TEXTUREFORMAT_R32_UINT,
GPU_TEXTUREFORMAT_R32G32_UINT,
GPU_TEXTUREFORMAT_R32G32B32A32_UINT,
/* Signed Integer Color Formats */
GPU_TEXTUREFORMAT_R8_INT,
GPU_TEXTUREFORMAT_R8G8_INT,
GPU_TEXTUREFORMAT_R8G8B8A8_INT,
GPU_TEXTUREFORMAT_R16_INT,
GPU_TEXTUREFORMAT_R16G16_INT,
GPU_TEXTUREFORMAT_R16G16B16A16_INT,
GPU_TEXTUREFORMAT_R32_INT,
GPU_TEXTUREFORMAT_R32G32_INT,
GPU_TEXTUREFORMAT_R32G32B32A32_INT,
/* SRGB Unsigned Normalized Color Formats */
GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB,
GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB,
/* Compressed SRGB Unsigned Normalized Color Formats */
GPU_TEXTUREFORMAT_BC1_RGBA_UNORM_SRGB,
GPU_TEXTUREFORMAT_BC2_RGBA_UNORM_SRGB,
GPU_TEXTUREFORMAT_BC3_RGBA_UNORM_SRGB,
GPU_TEXTUREFORMAT_BC7_RGBA_UNORM_SRGB,
/* Depth Formats */
GPU_TEXTUREFORMAT_D16_UNORM,
GPU_TEXTUREFORMAT_D24_UNORM,
GPU_TEXTUREFORMAT_D32_FLOAT,
GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT,
GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT,
/* Compressed ASTC Normalized Float Color Formats*/
GPU_TEXTUREFORMAT_ASTC_4X4_UNORM,
GPU_TEXTUREFORMAT_ASTC_5X4_UNORM,
GPU_TEXTUREFORMAT_ASTC_5X5_UNORM,
GPU_TEXTUREFORMAT_ASTC_6X5_UNORM,
GPU_TEXTUREFORMAT_ASTC_6X6_UNORM,
GPU_TEXTUREFORMAT_ASTC_8X5_UNORM,
GPU_TEXTUREFORMAT_ASTC_8X6_UNORM,
GPU_TEXTUREFORMAT_ASTC_8X8_UNORM,
GPU_TEXTUREFORMAT_ASTC_10X5_UNORM,
GPU_TEXTUREFORMAT_ASTC_10X6_UNORM,
GPU_TEXTUREFORMAT_ASTC_10X8_UNORM,
GPU_TEXTUREFORMAT_ASTC_10X10_UNORM,
GPU_TEXTUREFORMAT_ASTC_12X10_UNORM,
GPU_TEXTUREFORMAT_ASTC_12X12_UNORM,
/* Compressed SRGB ASTC Normalized Float Color Formats*/
GPU_TEXTUREFORMAT_ASTC_4X4_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_5X4_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_5X5_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_6X5_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_6X6_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_8X5_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_8X6_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_8X8_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_10X5_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_10X6_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_10X8_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_10X10_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_12X10_UNORM_SRGB,
GPU_TEXTUREFORMAT_ASTC_12X12_UNORM_SRGB,
/* Compressed ASTC Signed Float Color Formats*/
GPU_TEXTUREFORMAT_ASTC_4X4_FLOAT,
GPU_TEXTUREFORMAT_ASTC_5X4_FLOAT,
GPU_TEXTUREFORMAT_ASTC_5X5_FLOAT,
GPU_TEXTUREFORMAT_ASTC_6X5_FLOAT,
GPU_TEXTUREFORMAT_ASTC_6X6_FLOAT,
GPU_TEXTUREFORMAT_ASTC_8X5_FLOAT,
GPU_TEXTUREFORMAT_ASTC_8X6_FLOAT,
GPU_TEXTUREFORMAT_ASTC_8X8_FLOAT,
GPU_TEXTUREFORMAT_ASTC_10X5_FLOAT,
GPU_TEXTUREFORMAT_ASTC_10X6_FLOAT,
GPU_TEXTUREFORMAT_ASTC_10X8_FLOAT,
GPU_TEXTUREFORMAT_ASTC_10X10_FLOAT,
GPU_TEXTUREFORMAT_ASTC_12X10_FLOAT,
GPU_TEXTUREFORMAT_ASTC_12X12_FLOAT
}
typedef GPUTextureUsageFlags = uint;
const GPUTextureUsageFlags GPU_TEXTUREUSAGE_SAMPLER @builtin = (1 << 0);
const GPUTextureUsageFlags GPU_TEXTUREUSAGE_COLOR_TARGET @builtin = (1 << 1);
const GPUTextureUsageFlags GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET @builtin = (1 << 2);
const GPUTextureUsageFlags GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ @builtin = (1 << 3);
const GPUTextureUsageFlags GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ @builtin = (1 << 4);
const GPUTextureUsageFlags GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE @builtin = (1 << 5);
const GPUTextureUsageFlags GPU_TEXTUREUSAGE_COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE @builtin = (1 << 6);
enum GPUTextureType : inline CInt {
GPU_TEXTURETYPE_2D,
GPU_TEXTURETYPE_2D_ARRAY,
GPU_TEXTURETYPE_3D,
GPU_TEXTURETYPE_CUBE,
GPU_TEXTURETYPE_CUBE_ARRAY
}
enum GPUSampleCount : inline CInt {
GPU_SAMPLECOUNT_1,
GPU_SAMPLECOUNT_2,
GPU_SAMPLECOUNT_4,
GPU_SAMPLECOUNT_8
}
enum GPUCubeMapFace : inline CInt {
GPU_CUBEMAPFACE_POSITIVEX,
GPU_CUBEMAPFACE_NEGATIVEX,
GPU_CUBEMAPFACE_POSITIVEY,
GPU_CUBEMAPFACE_NEGATIVEY,
GPU_CUBEMAPFACE_POSITIVEZ,
GPU_CUBEMAPFACE_NEGATIVEZ
}
typedef GPUBufferUsageFlags = uint;
const GPUBufferUsageFlags GPU_BUFFERUSAGE_VERTEX @builtin = (1 << 0);
const GPUBufferUsageFlags GPU_BUFFERUSAGE_INDEX @builtin = (1 << 1);
const GPUBufferUsageFlags GPU_BUFFERUSAGE_INDIRECT @builtin = (1 << 2);
const GPUBufferUsageFlags GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ @builtin = (1 << 3);
const GPUBufferUsageFlags GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ @builtin = (1 << 4);
const GPUBufferUsageFlags GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE @builtin = (1 << 5);
enum GPUTransferBufferUsage : inline CInt {
GPU_TRANSFERBUFFERUSAGE_UPLOAD,
GPU_TRANSFERBUFFERUSAGE_DOWNLOAD
}
enum GPUShaderStage : inline CInt {
GPU_SHADERSTAGE_VERTEX,
GPU_SHADERSTAGE_FRAGMENT
}
typedef GPUShaderFormat = uint;
const GPUShaderFormat GPU_SHADERFORMAT_INVALID @builtin = 0;
const GPUShaderFormat GPU_SHADERFORMAT_PRIVATE @builtin = (1 << 0);
const GPUShaderFormat GPU_SHADERFORMAT_SPIRV @builtin = (1 << 1);
const GPUShaderFormat GPU_SHADERFORMAT_DXBC @builtin = (1 << 2);
const GPUShaderFormat GPU_SHADERFORMAT_DXIL @builtin = (1 << 3);
const GPUShaderFormat GPU_SHADERFORMAT_MSL @builtin = (1 << 4);
const GPUShaderFormat GPU_SHADERFORMAT_METALLIB @builtin = (1 << 5);
enum GPUVertexElementFormat : inline CInt {
GPU_VERTEXELEMENTFORMAT_INVALID,
/* 32-bit Signed Integers */
GPU_VERTEXELEMENTFORMAT_INT,
GPU_VERTEXELEMENTFORMAT_INT2,
GPU_VERTEXELEMENTFORMAT_INT3,
GPU_VERTEXELEMENTFORMAT_INT4,
/* 32-bit Unsigned Integers */
GPU_VERTEXELEMENTFORMAT_UINT,
GPU_VERTEXELEMENTFORMAT_UINT2,
GPU_VERTEXELEMENTFORMAT_UINT3,
GPU_VERTEXELEMENTFORMAT_UINT4,
/* 32-bit Floats */
GPU_VERTEXELEMENTFORMAT_FLOAT,
GPU_VERTEXELEMENTFORMAT_FLOAT2,
GPU_VERTEXELEMENTFORMAT_FLOAT3,
GPU_VERTEXELEMENTFORMAT_FLOAT4,
/* 8-bit Signed Integers */
GPU_VERTEXELEMENTFORMAT_BYTE2,
GPU_VERTEXELEMENTFORMAT_BYTE4,
/* 8-bit Unsigned Integers */
GPU_VERTEXELEMENTFORMAT_UBYTE2,
GPU_VERTEXELEMENTFORMAT_UBYTE4,
/* 8-bit Signed Normalized */
GPU_VERTEXELEMENTFORMAT_BYTE2_NORM,
GPU_VERTEXELEMENTFORMAT_BYTE4_NORM,
/* 8-bit Unsigned Normalized */
GPU_VERTEXELEMENTFORMAT_UBYTE2_NORM,
GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM,
/* 16-bit Signed Integers */
GPU_VERTEXELEMENTFORMAT_SHORT2,
GPU_VERTEXELEMENTFORMAT_SHORT4,
/* 16-bit Unsigned Integers */
GPU_VERTEXELEMENTFORMAT_USHORT2,
GPU_VERTEXELEMENTFORMAT_USHORT4,
/* 16-bit Signed Normalized */
GPU_VERTEXELEMENTFORMAT_SHORT2_NORM,
GPU_VERTEXELEMENTFORMAT_SHORT4_NORM,
/* 16-bit Unsigned Normalized */
GPU_VERTEXELEMENTFORMAT_USHORT2_NORM,
GPU_VERTEXELEMENTFORMAT_USHORT4_NORM,
/* 16-bit Floats */
GPU_VERTEXELEMENTFORMAT_HALF2,
GPU_VERTEXELEMENTFORMAT_HALF4
}
enum GPUVertexInputRate : inline CInt {
GPU_VERTEXINPUTRATE_VERTEX,
GPU_VERTEXINPUTRATE_INSTANCE
}
enum GPUFillMode : inline CInt {
GPU_FILLMODE_FILL,
GPU_FILLMODE_LINE
}
enum GPUCullMode : inline CInt {
GPU_CULLMODE_NONE,
GPU_CULLMODE_FRONT,
GPU_CULLMODE_BACK
}
enum GPUFrontFace : inline CInt {
GPU_FRONTFACE_COUNTER_CLOCKWISE,
GPU_FRONTFACE_CLOCKWISE
}
enum GPUCompareOp : inline CInt {
GPU_COMPAREOP_INVALID,
GPU_COMPAREOP_NEVER,
GPU_COMPAREOP_LESS,
GPU_COMPAREOP_EQUAL,
GPU_COMPAREOP_LESS_OR_EQUAL,
GPU_COMPAREOP_GREATER,
GPU_COMPAREOP_NOT_EQUAL,
GPU_COMPAREOP_GREATER_OR_EQUAL,
GPU_COMPAREOP_ALWAYS
}
enum GPUStencilOp : inline CInt {
GPU_STENCILOP_INVALID,
GPU_STENCILOP_KEEP,
GPU_STENCILOP_ZERO,
GPU_STENCILOP_REPLACE,
GPU_STENCILOP_INCREMENT_AND_CLAMP,
GPU_STENCILOP_DECREMENT_AND_CLAMP,
GPU_STENCILOP_INVERT,
GPU_STENCILOP_INCREMENT_AND_WRAP,
GPU_STENCILOP_DECREMENT_AND_WRAP
}
enum GPUBlendOp : inline CInt
{
GPU_BLENDOP_INVALID,
GPU_BLENDOP_ADD,
GPU_BLENDOP_SUBTRACT,
GPU_BLENDOP_REVERSE_SUBTRACT,
GPU_BLENDOP_MIN,
GPU_BLENDOP_MAX
}
enum GPUBlendFactor : inline CInt {
GPU_BLENDFACTOR_INVALID,
GPU_BLENDFACTOR_ZERO,
GPU_BLENDFACTOR_ONE,
GPU_BLENDFACTOR_SRC_COLOR,
GPU_BLENDFACTOR_ONE_MINUS_SRC_COLOR,
GPU_BLENDFACTOR_DST_COLOR,
GPU_BLENDFACTOR_ONE_MINUS_DST_COLOR,
GPU_BLENDFACTOR_SRC_ALPHA,
GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
GPU_BLENDFACTOR_DST_ALPHA,
GPU_BLENDFACTOR_ONE_MINUS_DST_ALPHA,
GPU_BLENDFACTOR_CONSTANT_COLOR,
GPU_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR,
GPU_BLENDFACTOR_SRC_ALPHA_SATURATE
}
typedef GPUColorComponentFlags = char;
const GPUColorComponentFlags GPU_COLORCOMPONENT_R @builtin = (1 << 0);
const GPUColorComponentFlags GPU_COLORCOMPONENT_G @builtin = (1 << 1);
const GPUColorComponentFlags GPU_COLORCOMPONENT_B @builtin = (1 << 2);
const GPUColorComponentFlags GPU_COLORCOMPONENT_A @builtin = (1 << 3);
enum GPUFilter : inline CInt {
GPU_FILTER_NEAREST,
GPU_FILTER_LINEAR
}
enum GPUSamplerMipmapMode : inline CInt {
GPU_SAMPLERMIPMAPMODE_NEAREST,
GPU_SAMPLERMIPMAPMODE_LINEAR
}
enum GPUSamplerAddressMode : inline CInt {
GPU_SAMPLERADDRESSMODE_REPEAT,
GPU_SAMPLERADDRESSMODE_MIRRORED_REPEAT,
GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE
}
enum GPUPresentMode : inline CInt {
GPU_PRESENTMODE_VSYNC,
GPU_PRESENTMODE_IMMEDIATE,
GPU_PRESENTMODE_MAILBOX
}
enum GPUSwapchainComposition : inline CInt {
GPU_SWAPCHAINCOMPOSITION_SDR,
GPU_SWAPCHAINCOMPOSITION_SDR_LINEAR,
GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR,
GPU_SWAPCHAINCOMPOSITION_HDR10_ST2084
}
/* ---------- */
/* Structures */
/* ---------- */
struct GPUViewport {
float x;
float y;
float w;
float h;
float min_depth;
float max_depth;
}
struct GPUTextureTransferInfo {
GPUTransferBuffer* transfer_buffer;
uint offset;
uint pixels_per_row;
uint rows_per_layer;
}
struct GPUTransferBufferLocation {
GPUTransferBuffer* transfer_buffer;
uint offset;
}
struct GPUTextureLocation {
GPUTexture* texture;
uint mip_level;
uint layer;
uint x;
uint y;
uint z;
}
struct GPUTextureRegion {
GPUTexture* texture;
uint mip_level;
uint layer;
uint x;
uint y;
uint z;
uint w;
uint h;
uint d;
}
struct GPUBlitRegion {
GPUTexture* texture;
uint mip_level;
uint layer_or_depth_plane;
uint x;
uint y;
uint w;
uint h;
}
struct GPUBufferLocation {
GPUBuffer* buffer;
uint offset;
}
struct GPUBufferRegion {
GPUBuffer* buffer;
uint offset;
uint size;
}
struct GPUIndirectDrawCommand {
uint num_vertices;
uint num_instances;
uint first_vertex;
uint first_instance;
}
struct GPUIndexedIndirectDrawCommand {
uint num_indices;
uint num_instances;
uint first_index;
int vertex_offset;
uint first_instance;
}
struct GPUIndirectDispatchCommand {
uint groupcount_x;
uint groupcount_y;
uint groupcount_z;
}
struct GPUSamplerCreateInfo {
GPUFilter min_filter;
GPUFilter mag_filter;
GPUSamplerMipmapMode mipmap_mode;
GPUSamplerAddressMode address_mode_u;
GPUSamplerAddressMode address_mode_v;
GPUSamplerAddressMode address_mode_w;
float mip_lod_bias;
float max_anisotropy;
GPUCompareOp compare_op;
float min_lod;
float max_lod;
bool enable_anisotropy;
bool enable_compare;
char padding1;
char padding2;
PropertiesID props;
}
struct GPUVertexBufferDescription {
uint slot;
uint pitch;
GPUVertexInputRate input_rate;
uint instance_step_rate;
}
struct GPUVertexAttribute {
uint location;
uint buffer_slot;
GPUVertexElementFormat format;
uint offset;
}
struct GPUVertexInputState {
GPUVertexBufferDescription* vertex_buffer_descriptions;
uint num_vertex_buffers;
GPUVertexAttribute* vertex_attributes;
uint num_vertex_attributes;
}
struct GPUStencilOpState {
GPUStencilOp fail_op;
GPUStencilOp pass_op;
GPUStencilOp depth_fail_op;
GPUCompareOp compare_op;
}
struct GPUColorTargetBlendState {
GPUBlendFactor src_color_blendfactor;
GPUBlendFactor dst_color_blendfactor;
GPUBlendOp color_blend_op;
GPUBlendFactor src_alpha_blendfactor;
GPUBlendFactor dst_alpha_blendfactor;
GPUBlendOp alpha_blend_op;
GPUColorComponentFlags color_write_mask;
bool enable_blend;
bool enable_color_write_mask;
char padding1;
char padding2;
}
struct GPUShaderCreateInfo {
isz code_size;
char* code;
ZString entrypoint;
GPUShaderFormat format;
GPUShaderStage stage;
uint num_samplers;
uint num_storage_textures;
uint num_storage_buffers;
uint num_uniform_buffers;
PropertiesID props;
}
struct GPUTextureCreateInfo {
GPUTextureType type;
GPUTextureFormat format;
GPUTextureUsageFlags usage;
uint width;
uint height;
uint layer_count_or_depth;
uint num_levels;
GPUSampleCount sample_count;
PropertiesID props;
}
struct GPUBufferCreateInfo {
GPUBufferUsageFlags usage;
uint size;
PropertiesID props;
}
struct GPUTransferBufferCreateInfo {
GPUTransferBufferUsage usage;
uint size;
PropertiesID props;
}
struct GPURasterizerState {
GPUFillMode fill_mode;
GPUCullMode cull_mode;
GPUFrontFace front_face;
float depth_bias_constant_factor;
float depth_bias_clamp;
float depth_bias_slope_factor;
bool enable_depth_bias;
bool enable_depth_clip;
char padding1;
char padding2;
}
struct GPUMultisampleState {
GPUSampleCount sample_count;
uint sample_mask;
bool enable_mask;
char padding1;
char padding2;
char padding3;
}
struct GPUDepthStencilState {
GPUCompareOp compare_op;
GPUStencilOpState back_stencil_state;
GPUStencilOpState front_stencil_state;
char compare_mask;
char write_mask;
bool enable_depth_test;
bool enable_depth_write;
bool enable_stencil_test;
char padding1;
char padding2;
char padding3;
}
struct GPUColorTargetDescription {
GPUTextureFormat format;
GPUColorTargetBlendState blend_state;
}
struct GPUGraphicsPipelineTargetInfo {
GPUColorTargetDescription* color_target_descriptions;
uint num_color_targets;
GPUTextureFormat depth_stencil_format;
bool has_depth_stencil_target;
char padding1;
char padding2;
char padding3;
}
struct GPUGraphicsPipelineCreateInfo {
GPUShader* vertex_shader;
GPUShader* fragment_shader;
GPUVertexInputState vertex_input_state;
GPUPrimitiveType primitive_type;
GPURasterizerState rasterizer_state;
GPUMultisampleState multisample_state;
GPUDepthStencilState depth_stencil_state;
GPUGraphicsPipelineTargetInfo target_info;
PropertiesID props;
}
struct GPUComputePipelineCreateInfo {
isz code_size;
char* code;
char* entrypoint;
GPUShaderFormat format;
uint num_samplers;
uint num_readonly_storage_textures;
uint num_readonly_storage_buffers;
uint num_readwrite_storage_textures;
uint num_readwrite_storage_buffers;
uint num_uniform_buffers;
uint threadcount_x;
uint threadcount_y;
uint threadcount_z;
PropertiesID props;
}
struct GPUColorTargetInfo {
GPUTexture* texture;
uint mip_level;
uint layer_or_depth_plane;
FColor clear_color;
GPULoadOp load_op;
GPUStoreOp store_op;
GPUTexture *resolve_texture;
uint resolve_mip_level;
uint resolve_layer;
bool cycle;
bool cycle_resolve_texture;
char padding1;
char padding2;
}
struct GPUDepthStencilTargetInfo {
GPUTexture* texture;
float clear_depth;
GPULoadOp load_op;
GPUStoreOp store_op;
GPULoadOp stencil_load_op;
GPUStoreOp stencil_store_op;
bool cycle;
char clear_stencil;
char padding1;
char padding2;
}
struct GPUBlitInfo {
GPUBlitRegion source;
GPUBlitRegion destination;
GPULoadOp load_op;
FColor clear_color;
FlipMode flip_mode;
GPUFilter filter;
bool cycle;
char padding1;
char padding2;
char padding3;
}
struct GPUBufferBinding {
GPUBuffer* buffer;
uint offset;
}
struct GPUTextureSamplerBinding {
GPUTexture* texture;
GPUSampler* sampler;
}
struct SDL_GPUStorageBufferReadWriteBinding {
GPUBuffer* buffer;
bool cycle;
char padding1;
char padding2;
char padding3;
}
struct GPUStorageTextureReadWriteBinding {
GPUTexture* texture;
uint mip_level;
uint layer;
bool cycle;
char padding1;
char padding2;
char padding3;
}
/* --------- */
/* Functions */
/* --------- */
const ZString PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN @builtin = "SDL.gpu.device.create.debugmode";
const ZString PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN @builtin = "SDL.gpu.device.create.preferlowpower";
const ZString PROP_GPU_DEVICE_CREATE_NAME_STRING @builtin = "SDL.gpu.device.create.name";
const ZString PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOLEAN @builtin = "SDL.gpu.device.create.shaders.private";
const ZString PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN @builtin = "SDL.gpu.device.create.shaders.spirv";
const ZString PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN @builtin = "SDL.gpu.device.create.shaders.dxbc";
const ZString PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN @builtin = "SDL.gpu.device.create.shaders.dxil";
const ZString PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN @builtin = "SDL.gpu.device.create.shaders.msl";
const ZString PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN @builtin = "SDL.gpu.device.create.shaders.metallib";
const ZString PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING @builtin = "SDL.gpu.device.create.d3d12.semantic";
const ZString PROP_GPU_COMPUTEPIPELINE_CREATE_NAME_STRING @builtin = "SDL.gpu.computepipeline.create.name";
const ZString PROP_GPU_GRAPHICSPIPELINE_CREATE_NAME_STRING @builtin = "SDL.gpu.graphicspipeline.create.name";
const ZString PROP_GPU_SAMPLER_CREATE_NAME_STRING @builtin = "SDL.gpu.sampler.create.name";
const ZString PROP_GPU_SHADER_CREATE_NAME_STRING @builtin = "SDL.gpu.shader.create.name";
const ZString PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_R_FLOAT @builtin = "SDL.gpu.texture.create.d3d12.clear.r";
const ZString PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_G_FLOAT @builtin = "SDL.gpu.texture.create.d3d12.clear.g";
const ZString PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_B_FLOAT @builtin = "SDL.gpu.texture.create.d3d12.clear.b";
const ZString PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_A_FLOAT @builtin = "SDL.gpu.texture.create.d3d12.clear.a";
const ZString PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_DEPTH_FLOAT @builtin = "SDL.gpu.texture.create.d3d12.clear.depth";
const ZString PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_STENCIL_NUMBER @builtin = "SDL.gpu.texture.create.d3d12.clear.stencil";
const ZString PROP_GPU_TEXTURE_CREATE_NAME_STRING @builtin = "SDL.gpu.texture.create.name";
const ZString PROP_GPU_BUFFER_CREATE_NAME_STRING @builtin = "SDL.gpu.buffer.create.name";
const ZString PROP_GPU_TRANSFERBUFFER_CREATE_NAME_STRING @builtin = "SDL.gpu.transferbuffer.create.name";
extern fn bool gpu_supports_shader_formats(GPUShaderFormat format_flags, ZString name) @extern("SDL_GPUSupportsShaderFormats");
extern fn bool gpu_supports_properties(PropertiesID props) @extern("SDL_GPUSupportsProperties");
extern fn GPUDevice* create_gpu_device(GPUShaderFormat format_flags, bool debug_mode, ZString name) @extern("SDL_CreateGPUDevice");
extern fn GPUDevice* create_gpu_device_with_properties(PropertiesID props) @extern("SDL_CreateGPUDeviceWithProperties");
extern fn void destroy_gpu_device(GPUDevice* device) @extern("SDL_DestroyGPUDevice");
extern fn int get_num_gpu_drivers() @extern("SDL_GetNumGPUDrivers");
extern fn ZString get_gpu_driver(int index) @extern("SDL_GetGPUDriver");
extern fn ZString get_gpu_device_driver(GPUDevice* device) @extern("SDL_GetGPUDeviceDriver");
extern fn GPUShaderFormat get_gpu_shader_formats(GPUDevice* device) @extern("SDL_GetGPUShaderFormats");
extern fn GPUComputePipeline* create_gpu_compute_pipeline(GPUDevice* device, GPUComputePipelineCreateInfo* createinfo) @extern("SDL_CreateGPUComputePipeline");
extern fn GPUGraphicsPipeline* create_gpu_graphics_pipeline(GPUDevice* device, GPUGraphicsPipelineCreateInfo* createinfo) @extern("SDL_CreateGPUGraphicsPipeline");
extern fn GPUSampler* create_gpu_sampler(GPUDevice* device, GPUSamplerCreateInfo* createinfo) @extern("SDL_CreateGPUSampler");
extern fn GPUShader* create_gpu_shader(GPUDevice* device, GPUShaderCreateInfo* createinfo) @extern("SDL_CreateGPUShader");
extern fn GPUTexture* create_gpu_texture(GPUDevice* device, GPUTextureCreateInfo* createinfo) @extern("SDL_CreateGPUTexture");
extern fn GPUBuffer* create_gpu_buffer(GPUDevice* device, GPUBufferCreateInfo* createinfo) @extern("SDL_CreateGPUBuffer");
extern fn GPUTransferBuffer* create_gpu_transfer_buffer(GPUDevice* device, GPUTransferBufferCreateInfo *createinfo) @extern("SDL_CreateGPUTransferBuffer");
extern fn void set_gpu_buffer_name(GPUDevice* device, GPUBuffer* buffer, ZString text) @extern("SDL_SetGPUBufferName");
extern fn void set_gpu_texture_name(GPUDevice* device, GPUTexture* texture, ZString text) @extern("SDL_SetGPUTextureName");
extern fn void insert_gpu_debug_label(GPUCommandBuffer* command_buffer, ZString text) @extern("SDL_InsertGPUDebugLabel");
extern fn void push_gpu_debug_group(GPUCommandBuffer* command_buffer, ZString name) @extern("SDL_PushGPUDebugGroup");
extern fn void pop_gpu_debug_group(GPUCommandBuffer* command_buffer) @extern("SDL_PopGPUDebugGroup");
extern fn void release_gpu_texture(GPUDevice* device, GPUTexture* texture) @extern("SDL_ReleaseGPUTexture");
extern fn void release_gpu_sampler(GPUDevice* device, GPUSampler* sampler) @extern("SDL_ReleaseGPUSampler");
extern fn void release_gpu_buffer(GPUDevice* device, GPUBuffer* buffer) @extern("SDL_ReleaseGPUBuffer");
extern fn void release_gpu_transfer_buffer(GPUDevice* device, GPUTransferBuffer* transfer_buffer) @extern("SDL_ReleaseGPUTransferBuffer");
extern fn void release_gpu_compute_pipeline(GPUDevice* device, GPUComputePipeline* compute_pipeline) @extern("SDL_ReleaseGPUComputePipeline");
extern fn void release_gpu_shader(GPUDevice* device, GPUShader* shader) @extern("SDL_ReleaseGPUShader");
extern fn void release_gpu_graphics_pipeline(GPUDevice* device, GPUGraphicsPipeline* graphics_pipeline) @extern("SDL_ReleaseGPUGraphicsPipeline");
extern fn GPUCommandBuffer* acquire_gpu_command_buffer(GPUDevice* device) @extern("SDL_AcquireGPUCommandBuffer");
extern fn void push_gpu_vertex_uniform_data(GPUCommandBuffer* command_buffer, uint slot_index, void* data, uint length) @extern("SDL_PushGPUVertexUniformData");
extern fn void push_gpu_fragment_uniform_data(GPUCommandBuffer* command_buffer, uint slot_index, void* data, uint length) @extern("SDL_PushGPUFragmentUniformData");
extern fn void push_gpu_compute_uniform_data(GPUCommandBuffer* command_buffer, uint slot_index, void* data, uint length) @extern("SDL_PushGPUComputeUniformData");
extern fn GPURenderPass* begin_gpu_render_pass(GPUCommandBuffer* command_buffer, GPUColorTargetInfo* color_target_infos, uint num_color_targets, GPUDepthStencilTargetInfo* depth_stencil_target_info) @extern("SDL_BeginGPURenderPass");
extern fn void bind_gpu_graphics_pipeline(GPURenderPass* render_pass, GPUGraphicsPipeline* graphics_pipeline) @extern("SDL_BindGPUGraphicsPipeline");
extern fn void set_gpu_viewport(GPURenderPass* render_pass, GPUViewport* viewport) @extern("SDL_SetGPUViewport");
extern fn void set_gpu_scissor(GPURenderPass* render_pass, Rect* scissor) @extern("SDL_SetGPUScissor");
extern fn void set_gpu_blend_constants(GPURenderPass* render_pass, FColor blend_constants) @extern("SDL_SetGPUBlendConstants");
extern fn void set_gpu_stencil_reference(GPURenderPass* render_pass, char reference) @extern("SDL_SetGPUStencilReference");
extern fn void bind_gpu_vertex_buffers(GPURenderPass* render_pass, uint first_slot, GPUBufferBinding* bindings, uint num_bindings) @extern("SDL_BindGPUVertexBuffers");
extern fn void bind_gpu_index_buffer(GPURenderPass* render_pass, GPUBufferBinding* binding, GPUIndexElementSize index_element_size) @extern("SDL_BindGPUIndexBuffer");
extern fn void bind_gpu_vertex_samplers(GPURenderPass* render_pass, uint first_slot, GPUTextureSamplerBinding* texture_sampler_bindings, uint num_bindings) @extern("SDL_BindGPUVertexSamplers");
extern fn void bind_gpu_vertex_storage_textures(GPURenderPass* render_pass, uint first_slot,GPUTexture* *storage_textures, uint num_bindings) @extern("SDL_BindGPUVertexStorageTextures");
extern fn void bind_gpu_vertex_storage_buffers(GPURenderPass* render_pass, uint first_slot,GPUBuffer* *storage_buffers, uint num_bindings) @extern("SDL_BindGPUVertexStorageBuffers");
extern fn void bind_gpu_fragment_samplers(GPURenderPass* render_pass, uint first_slot, GPUTextureSamplerBinding* texture_sampler_bindings, uint num_bindings) @extern("SDL_BindGPUFragmentSamplers");
extern fn void bind_gpu_fragment_storage_textures(GPURenderPass* render_pass, uint first_slot,GPUTexture* *storage_textures, uint num_bindings) @extern("SDL_BindGPUFragmentStorageTextures");
extern fn void bind_gpu_fragment_storage_buffers(GPURenderPass* render_pass, uint first_slot,GPUBuffer* *storage_buffers, uint num_bindings) @extern("SDL_BindGPUFragmentStorageBuffers");
extern fn void draw_gpu_indexed_primitives(GPURenderPass* render_pass, uint num_indices, uint num_instances, uint first_index, int vertex_offset, uint first_instance) @extern("SDL_DrawGPUIndexedPrimitives");
extern fn void draw_gpu_primitives(GPURenderPass* render_pass, uint num_vertices, uint num_instances, uint first_vertex, uint first_instance) @extern("SDL_DrawGPUPrimitives");
extern fn void draw_gpu_primitives_indirect(GPURenderPass* render_pass,GPUBuffer* buffer, uint offset, uint draw_count) @extern("SDL_DrawGPUPrimitivesIndirect");
extern fn void draw_gpu_indexed_primitives_indirect(GPURenderPass* render_pass,GPUBuffer* buffer, uint offset, uint draw_count) @extern("SDL_DrawGPUIndexedPrimitivesIndirect");
extern fn void end_gpu_render_pass(GPURenderPass* render_pass) @extern("SDL_EndGPURenderPass");
extern fn GPUComputePass* begin_gpu_compute_pass(GPUCommandBuffer* command_buffer, GPUStorageTextureReadWriteBinding* storage_texture_bindings, uint num_storage_texture_bindings, SDL_GPUStorageBufferReadWriteBinding *storage_buffer_bindings, uint num_storage_buffer_bindings) @extern("SDL_BeginGPUComputePass");
extern fn void bind_gpu_compute_pipeline(GPUComputePass* compute_pass, GPUComputePipeline* compute_pipeline) @extern("SDL_BindGPUComputePipeline");
extern fn void bind_gpu_compute_samplers(GPUComputePass* compute_pass, uint first_slot, GPUTextureSamplerBinding* texture_sampler_bindings, uint num_bindings) @extern("SDL_BindGPUComputeSamplers");
extern fn void bind_gpu_compute_storage_textures(GPUComputePass* compute_pass, uint first_slot, GPUTexture* *storage_textures, uint num_bindings) @extern("SDL_BindGPUComputeStorageTextures");
extern fn void bind_gpu_compute_storage_buffers(GPUComputePass* compute_pass, uint first_slot, GPUBuffer* *storage_buffers, uint num_bindings) @extern("SDL_BindGPUComputeStorageBuffers");
extern fn void dispatch_gpu_compute(GPUComputePass* compute_pass, uint groupcount_x, uint groupcount_y, uint groupcount_z) @extern("SDL_DispatchGPUCompute");
extern fn void dispatch_gpu_compute_indirect(GPUComputePass* compute_pass, GPUBuffer* buffer, uint offset) @extern("SDL_DispatchGPUComputeIndirect");
extern fn void end_gpu_compute_pass(GPUComputePass* compute_pass) @extern("SDL_EndGPUComputePass");
extern fn void* map_gpu_transfer_buffer(GPUDevice* device, GPUTransferBuffer* transfer_buffer,bool cycle) @extern("SDL_MapGPUTransferBuffer");
extern fn void unmap_gpu_transfer_buffer(GPUDevice* device, GPUTransferBuffer* transfer_buffer) @extern("SDL_UnmapGPUTransferBuffer");
extern fn GPUCopyPass* begin_gpu_copy_pass(GPUCommandBuffer* command_buffer) @extern("SDL_BeginGPUCopyPass");
extern fn void upload_to_gpu_texture(GPUCopyPass* copy_pass, GPUTextureTransferInfo* source, GPUTextureRegion* destination,bool cycle) @extern("SDL_UploadToGPUTexture");
extern fn void upload_to_gpu_buffer(GPUCopyPass* copy_pass, GPUTransferBufferLocation* source, GPUBufferRegion* destination,bool cycle) @extern("SDL_UploadToGPUBuffer");
extern fn void copy_gpu_texture_to_texture(GPUCopyPass* copy_pass, GPUTextureLocation* source, GPUTextureLocation* destination, uint w, uint h, uint d,bool cycle) @extern("SDL_CopyGPUTextureToTexture");
extern fn void copy_gpu_buffer_to_buffer(GPUCopyPass* copy_pass, GPUBufferLocation* source, GPUBufferLocation* destination, uint size,bool cycle) @extern("SDL_CopyGPUBufferToBuffer");
extern fn void download_from_gpu_texture(GPUCopyPass* copy_pass, GPUTextureRegion* source, GPUTextureTransferInfo* destination) @extern("SDL_DownloadFromGPUTexture");
extern fn void download_from_gpu_buffer(GPUCopyPass* copy_pass, GPUBufferRegion* source, GPUTransferBufferLocation* destination) @extern("SDL_DownloadFromGPUBuffer");
extern fn void end_gpu_copy_pass(GPUCopyPass* copy_pass) @extern("SDL_EndGPUCopyPass");
extern fn void generate_mipmaps_for_gpu_texture(GPUCommandBuffer* command_buffer,GPUTexture* texture) @extern("SDL_GenerateMipmapsForGPUTexture");
extern fn void blit_gpu_texture(GPUCommandBuffer* command_buffer, GPUBlitInfo* info) @extern("SDL_BlitGPUTexture");
extern fn bool window_supports_gpu_swapchain_composition(GPUDevice* device, Window* window, GPUSwapchainComposition swapchain_composition) @extern("SDL_WindowSupportsGPUSwapchainComposition");
extern fn bool window_supports_gpu_present_mode(GPUDevice* device, Window* window, GPUPresentMode present_mode) @extern("SDL_WindowSupportsGPUPresentMode");
extern fn bool claim_window_for_gpu_device(GPUDevice* device, Window* window) @extern("SDL_ClaimWindowForGPUDevice");
extern fn void release_window_from_gpu_device(GPUDevice* device, Window* window) @extern("SDL_ReleaseWindowFromGPUDevice");
extern fn bool set_gpu_swapchain_parameters(GPUDevice* device, Window* window, GPUSwapchainComposition swapchain_composition, GPUPresentMode present_mode) @extern("SDL_SetGPUSwapchainParameters");
extern fn bool set_gpu_allowed_frames_in_flight(GPUDevice* device, uint allowed_frames_in_flight) @extern("SDL_SetGPUAllowedFramesInFlight");
extern fn GPUTextureFormat get_gpu_swapchain_texture_format(GPUDevice* device, Window* window) @extern("SDL_GetGPUSwapchainTextureFormat");
extern fn bool acquire_gpu_swapchain_texture(GPUCommandBuffer* command_buffer,Window* window,GPUTexture* *swapchain_texture, uint *swapchain_texture_width, uint *swapchain_texture_height) @extern("SDL_AcquireGPUSwapchainTexture");
extern fn bool wait_for_gpu_swapchain(GPUDevice* device, Window* window) @extern("SDL_WaitForGPUSwapchain");
extern fn bool wait_and_acquire_gpu_swapchain_texture(GPUCommandBuffer* command_buffer,Window* window,GPUTexture* *swapchain_texture, uint *swapchain_texture_width, uint *swapchain_texture_height) @extern("SDL_WaitAndAcquireGPUSwapchainTexture");
extern fn bool submit_gpu_command_buffer(GPUCommandBuffer* command_buffer) @extern("SDL_SubmitGPUCommandBuffer");
extern fn GPUFence* submit_gpu_command_buffer_and_acquire_fence(GPUCommandBuffer* command_buffer) @extern("SDL_SubmitGPUCommandBufferAndAcquireFence");
extern fn bool cancel_gpu_command_buffer(GPUCommandBuffer* command_buffer) @extern("SDL_CancelGPUCommandBuffer");
extern fn bool wait_for_gpu_idle(GPUDevice* device) @extern("SDL_WaitForGPUIdle");
extern fn bool wait_for_gpu_fences(GPUDevice* device, bool wait_all,GPUFence* *fences, uint num_fences) @extern("SDL_WaitForGPUFences");
extern fn bool query_gpu_fence(GPUDevice* device, GPUFence* fence) @extern("SDL_QueryGPUFence");
extern fn void release_gpu_fence(GPUDevice* device, GPUFence* fence) @extern("SDL_ReleaseGPUFence");
extern fn uint gpu_texture_format_texel_block_size(GPUTextureFormat format) @extern("GPUTextureFormatTexelBlockSize");
extern fn bool gpu_texture_supports_format(GPUDevice* device, GPUTextureFormat format, GPUTextureType type, GPUTextureUsageFlags usage) @extern("SDL_GPUTextureSupportsFormat");
extern fn bool gpu_texture_supports_sample_count(GPUDevice* device, GPUTextureFormat format, GPUSampleCount sample_count) @extern("SDL_GPUTextureSupportsSampleCount");
extern fn uint calculate_gpu_texture_format_size(GPUTextureFormat format, uint width, uint height, uint depth_or_layer_count) @extern("SDL_CalculateGPUTextureFormatSize");