#ifndef GPU_H #define GPU_H struct sys_window; struct work_startup_receipt; /* ========================== * * Startup * ========================== */ struct gpu_startup_receipt { i32 _; }; struct gpu_startup_receipt gpu_startup(struct work_startup_receipt *work_sr, struct sys_window *window); /* ========================== * * Handle * ========================== */ struct gpu_handle { union { /* dx11 style */ u64 v; /* dx12 style */ struct { u64 gen; u64 idx; }; }; }; struct gpu_handle_array { u64 count; struct gpu_handle **handles; }; void gpu_release(struct gpu_handle handle); /* ========================== * * Texture * ========================== */ enum gpu_texture_format { GPU_TEXTURE_FORMAT_NONE, GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM, GPU_TEXTURE_FORMAT_R8G8B8A8_UNORM_SRGB, NUM_GPU_TEXTURE_FORMATS }; enum gpu_texture_flag { GPU_TEXTURE_FLAG_NONE = (0), GPU_TEXTURE_FLAG_TARGETABLE = (1 << 0) }; struct gpu_handle gpu_texture_alloc(enum gpu_texture_format format, u32 flags, struct v2i32 size, void *initial_data); void gpu_texture_clear(struct gpu_handle target_texture, u32 clear_color); struct v2i32 gpu_texture_get_size(struct gpu_handle texture); /* ========================== * * Cmd buffer * ========================== */ struct gpu_indices { u32 count; u32 *indices; }; enum gpu_cmd_kind { GPU_CMD_KIND_NONE, GPU_CMD_KIND_DRAW_MESH, GPU_CMD_KIND_DRAW_TEXTURE, GPU_CMD_KIND_DRAW_GRID, GPU_CMD_KIND_TEST, NUM_GPU_CMD_KINDS }; struct gpu_cmd_params { enum gpu_cmd_kind kind; union { struct { struct v2_array vertices; struct gpu_indices indices; u32 color; } mesh; struct { struct xform xf; struct sprite_tag sprite; struct gpu_handle texture; struct clip_rect clip; u32 tint; f32 emittance; } texture; struct { struct xform xf; f32 line_thickness; f32 line_spacing; struct v2 offset; u32 bg0_color; u32 bg1_color; u32 line_color; u32 x_color; u32 y_color; } grid; struct { struct xform xf; } test; }; }; struct gpu_handle gpu_plan_alloc(void); void gpu_push_cmd(struct gpu_handle gpu_plan, struct gpu_cmd_params params); void gpu_submit_plan(struct gpu_handle gpu_plan); /* ========================== * * Dispatch * ========================== */ struct gpu_dispatch_params { struct gpu_handle plan; struct gpu_handle draw_target; struct rect draw_target_viewport; struct xform draw_target_view; }; struct gpu_handle gpu_dispatch_state_alloc(void); void gpu_dispatch(struct gpu_handle gpu_dispatch_state, struct gpu_dispatch_params params); /* ========================== * * Present * ========================== */ /* 1. Ensures the backbuffer is at size `backbuffer_resolution` * 2. Blits `texture` to the backbuffer using `texture_xf` (applied to centered unit square) * 3. Presents the backbuffer */ void gpu_present(struct v2i32 backbuffer_resolution, struct gpu_handle texture, struct xform texture_xf, i32 vsync); #endif