Files
chimera-gfx-Public/include/chimera/gfx/chimera_gfx.h
T
Chimera GFX release export a6037502d7
phase0-ci / build-and-audit (push) Successful in 2m14s
Publish Chimera GFX source
2026-09-03 03:27:14 +02:00

202 lines
7.0 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef CHIMERA_GFX_CHIMERA_GFX_H
#define CHIMERA_GFX_CHIMERA_GFX_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CHIMERA_GFX_API_VERSION 2u
typedef struct chimera_gfx_context chimera_gfx_context;
typedef struct chimera_gfx_surface chimera_gfx_surface;
typedef struct chimera_gfx_texture chimera_gfx_texture;
typedef enum chimera_gfx_status {
CHIMERA_GFX_STATUS_OK = 0,
CHIMERA_GFX_STATUS_INVALID_ARGUMENT = 1,
CHIMERA_GFX_STATUS_VERSION_MISMATCH = 2,
CHIMERA_GFX_STATUS_UNSUPPORTED = 3,
CHIMERA_GFX_STATUS_BACKEND_UNAVAILABLE = 4,
CHIMERA_GFX_STATUS_OUT_OF_MEMORY = 5,
CHIMERA_GFX_STATUS_SAFETY_POLICY = 6,
CHIMERA_GFX_STATUS_INTERNAL_ERROR = 7,
CHIMERA_GFX_STATUS_INVALID_STATE = 8,
CHIMERA_GFX_STATUS_RESOURCE_BUSY = 9,
CHIMERA_GFX_STATUS_LIMIT_EXCEEDED = 10
} chimera_gfx_status;
typedef enum chimera_gfx_backend {
CHIMERA_GFX_BACKEND_MOCK = 1,
CHIMERA_GFX_BACKEND_PS5 = 2
} chimera_gfx_backend;
typedef enum chimera_gfx_config_flag {
/* Reserved for a future hardware phase. Phase 0 always rejects it. */
CHIMERA_GFX_CONFIG_ALLOW_HARDWARE_RENDERING = 1u << 0
} chimera_gfx_config_flag;
/* Backward-compatible spelling retained for the initial API revision. */
#define CHIMERA_GFX_CONFIG_ALLOW_RENDERING \
CHIMERA_GFX_CONFIG_ALLOW_HARDWARE_RENDERING
typedef enum chimera_gfx_capability_flag {
CHIMERA_GFX_CAPABILITY_BACKEND_AVAILABLE = 1u << 0,
CHIMERA_GFX_CAPABILITY_NON_RENDERING = 1u << 1,
CHIMERA_GFX_CAPABILITY_HOST_TEST_ONLY = 1u << 2,
CHIMERA_GFX_CAPABILITY_SURFACE_LIFECYCLE = 1u << 3,
CHIMERA_GFX_CAPABILITY_TEXTURE_LIFECYCLE = 1u << 4,
CHIMERA_GFX_CAPABILITY_TEXTURE_UPLOAD = 1u << 5,
CHIMERA_GFX_CAPABILITY_PRESENT_MODEL = 1u << 6
} chimera_gfx_capability_flag;
typedef enum chimera_gfx_pixel_format {
CHIMERA_GFX_PIXEL_FORMAT_RGBA8_UNORM = 1
} chimera_gfx_pixel_format;
typedef struct chimera_gfx_config {
size_t struct_size;
uint32_t api_version;
uint32_t backend;
uint32_t flags;
} chimera_gfx_config;
#define CHIMERA_GFX_CONFIG_INIT \
{sizeof(chimera_gfx_config), CHIMERA_GFX_API_VERSION, \
CHIMERA_GFX_BACKEND_MOCK, 0u}
typedef struct chimera_gfx_capabilities {
size_t struct_size;
uint32_t api_version;
uint32_t backend;
uint32_t flags;
uint32_t max_surface_width;
uint32_t max_surface_height;
uint32_t max_texture_width;
uint32_t max_texture_height;
uint32_t max_live_surfaces;
uint32_t max_live_textures;
} chimera_gfx_capabilities;
#define CHIMERA_GFX_CAPABILITIES_INIT \
{sizeof(chimera_gfx_capabilities), 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u}
typedef struct chimera_gfx_surface_desc {
size_t struct_size;
uint32_t api_version;
uint32_t width;
uint32_t height;
uint32_t format;
uint32_t flags;
} chimera_gfx_surface_desc;
#define CHIMERA_GFX_SURFACE_DESC_INIT(width_value, height_value) \
{sizeof(chimera_gfx_surface_desc), \
CHIMERA_GFX_API_VERSION, \
(width_value), \
(height_value), \
CHIMERA_GFX_PIXEL_FORMAT_RGBA8_UNORM, \
0u}
typedef struct chimera_gfx_texture_desc {
size_t struct_size;
uint32_t api_version;
uint32_t width;
uint32_t height;
uint32_t format;
uint32_t flags;
} chimera_gfx_texture_desc;
#define CHIMERA_GFX_TEXTURE_DESC_INIT(width_value, height_value) \
{sizeof(chimera_gfx_texture_desc), \
CHIMERA_GFX_API_VERSION, \
(width_value), \
(height_value), \
CHIMERA_GFX_PIXEL_FORMAT_RGBA8_UNORM, \
0u}
typedef struct chimera_gfx_texture_upload_info {
size_t struct_size;
uint32_t api_version;
const void *pixels;
size_t row_pitch;
size_t data_size;
} chimera_gfx_texture_upload_info;
#define CHIMERA_GFX_TEXTURE_UPLOAD_INIT(pixel_data, pitch_value, size_value) \
{sizeof(chimera_gfx_texture_upload_info), CHIMERA_GFX_API_VERSION, \
(pixel_data), (pitch_value), (size_value)}
typedef struct chimera_gfx_present_info {
size_t struct_size;
uint32_t api_version;
chimera_gfx_surface *surface;
chimera_gfx_texture *texture;
uint32_t flags;
} chimera_gfx_present_info;
#define CHIMERA_GFX_PRESENT_INFO_INIT(surface_value, texture_value) \
{sizeof(chimera_gfx_present_info), CHIMERA_GFX_API_VERSION, \
(surface_value), (texture_value), 0u}
typedef struct chimera_gfx_surface_stats {
size_t struct_size;
uint32_t api_version;
uint64_t present_count;
uint64_t last_present_serial;
uint64_t last_texture_hash;
} chimera_gfx_surface_stats;
#define CHIMERA_GFX_SURFACE_STATS_INIT \
{sizeof(chimera_gfx_surface_stats), 0u, 0u, 0u, 0u}
chimera_gfx_status chimera_gfx_create(const chimera_gfx_config *config,
chimera_gfx_context **out_context);
chimera_gfx_status
chimera_gfx_get_capabilities(const chimera_gfx_context *context,
chimera_gfx_capabilities *out_capabilities);
chimera_gfx_status
chimera_gfx_surface_create(chimera_gfx_context *context,
const chimera_gfx_surface_desc *desc,
chimera_gfx_surface **out_surface);
chimera_gfx_status
chimera_gfx_surface_get_stats(const chimera_gfx_surface *surface,
chimera_gfx_surface_stats *out_stats);
chimera_gfx_status chimera_gfx_surface_destroy(chimera_gfx_surface *surface);
chimera_gfx_status
chimera_gfx_texture_create(chimera_gfx_context *context,
const chimera_gfx_texture_desc *desc,
chimera_gfx_texture **out_texture);
chimera_gfx_status
chimera_gfx_texture_upload(chimera_gfx_texture *texture,
const chimera_gfx_texture_upload_info *upload);
chimera_gfx_status chimera_gfx_texture_destroy(chimera_gfx_texture *texture);
chimera_gfx_status
chimera_gfx_present(chimera_gfx_context *context,
const chimera_gfx_present_info *present_info);
/* Returns RESOURCE_BUSY until all child handles have been destroyed. */
chimera_gfx_status chimera_gfx_context_destroy(chimera_gfx_context *context);
/* Version-1 compatibility wrapper. New code uses context_destroy(). */
void chimera_gfx_destroy(chimera_gfx_context *context);
const char *chimera_gfx_status_string(chimera_gfx_status status);
#ifdef __cplusplus
}
#endif
#endif