xash3d-fwgs/ref/vk/vk_render.h

182 lines
5.8 KiB
C
Raw Normal View History

#pragma once
#include "vk_common.h"
#include "vk_const.h"
#include "vk_core.h"
qboolean VK_RenderInit( void );
void VK_RenderShutdown( void );
struct ref_viewpass_s;
void VK_RenderSetupCamera( const struct ref_viewpass_s *rvp );
// Quirk for passing surface type to the renderer
// xash3d does not really have a notion of materials. Instead there are custom code paths
// for different things. There's also render_mode for entities which determine blending mode
// and stuff.
// For ray tracing we do need to assing a material to each rendered surface, so we need to
// figure out what it is given heuristics like render_mode, texture name, surface flags, source entity type, etc.
typedef enum {
kXVkMaterialRegular = 0,
// Set for SURF_DRAWSKY surfaces in vk_brush.c.
// Used: for setting TEX_BASE_SKYBOX for skybox texture sampling and environment shadows.
// Remove: pass it as a special texture/material index (e.g. -2).
kXVkMaterialSky,
// Set for chrome studio submodels.
// Used: ray tracing sets gray roughness texture to get smooth surface look.
// Remove: Have an explicit material for chrome surfaces.
kXVkMaterialChrome,
} XVkMaterialType;
typedef struct vk_render_geometry_s {
int index_offset, vertex_offset;
uint32_t element_count;
// Maximum index of vertex used for this geometry; needed for ray tracing BLAS building
uint32_t max_vertex;
// Non-null only for brush models
// Used for updating animated textures for brush models
// Remove: have an explicit list of surfaces with animated textures
const struct msurface_s *surf_deprecate;
// Animated textures will be dynamic and change between frames
int texture;
// If this geometry is special, it will have a material type override
XVkMaterialType material;
// for kXVkMaterialEmissive{,Glow} and others
vec3_t emissive;
} vk_render_geometry_t;
typedef enum {
kVkRenderTypeSolid, // no blending, depth RW
// Mix alpha blending with depth test and write
// Set by:
// - brush: kRenderTransColor
// - studio: kRenderTransColor, kRenderTransTexture, kRenderTransAlpha, kRenderGlow
// - sprite: kRenderTransColor, kRenderTransTexture
// - triapi: kRenderTransColor, kRenderTransTexture
kVkRenderType_A_1mA_RW, // blend: src*a + dst*(1-a), depth: RW
// Mix alpha blending with depth test only
// Set by:
// - brush: kRenderTransTexture, kRenderGlow
// - sprite: kRenderTransAlpha
// - triapi: kRenderTransAlpha
kVkRenderType_A_1mA_R, // blend: src*a + dst*(1-a), depth test
// Additive alpha blending, no depth
// Set by:
// - sprite: kRenderGlow
kVkRenderType_A_1, // blend: src*a + dst, no depth test or write
// Additive alpha blending with depth test
// Set by:
// - brush: kRenderTransAdd
// - beams: all modes except kRenderNormal and beams going through triapi
// - sprite: kRenderTransAdd
// - triapi: kRenderTransAdd, kRenderGlow
kVkRenderType_A_1_R, // blend: src*a + dst, depth test
// No blend, alpha test, depth test and write
// Set by:
// - brush: kRenderTransAlpha
kVkRenderType_AT, // no blend, depth RW, alpha test
// Additive no alpha blend, depth test only
// Set by:
// - studio: kRenderTransAdd
kVkRenderType_1_1_R, // blend: src + dst, depth test
kVkRenderType_COUNT
} vk_render_type_e;
struct rt_light_add_polygon_s;
struct vk_ray_model_s;
struct rt_model_s;
2021-04-09 23:59:04 +02:00
typedef struct vk_render_model_s {
#define MAX_MODEL_NAME_LENGTH 64
char debug_name[MAX_MODEL_NAME_LENGTH];
// TODO per-geometry?
int lightmap; // <= 0 if no lightmap
int num_geometries;
vk_render_geometry_t *geometries;
struct rt_model_s *rt_model;
// This model will be one-frame only, its buffers are not preserved between frames
// TODO deprecate
qboolean dynamic;
// Non-NULL only for ray tracing
// TODO deprecate in favor of rt_model_s
struct vk_ray_model_s *ray_model;
// Polylights which need to be added per-frame dynamically
// Used for non-worldmodel brush models which are not static
// TODO this doesn't belong here at all
struct rt_light_add_polygon_s *dynamic_polylights;
int dynamic_polylights_count;
2023-01-22 00:45:29 +01:00
struct {
// TODO these two are dynamic, extract them to draw args?
vk_render_type_e render_type;
vec4_t color;
matrix4x4 transform;
// previous frame ObjectToWorld (model) matrix
matrix4x4 prev_transform;
// TODO potentially dynamic. extract to draw args?
} deprecate;
} vk_render_model_t;
qboolean VK_RenderModelInit_old( vk_render_model_t* model );
// Initialize model from scratch
typedef struct {
const char *name;
vk_render_geometry_t *geometries;
int geometries_count;
} vk_render_model_init_t;
qboolean VK_RenderModelCreate( vk_render_model_t *model, vk_render_model_init_t args );
void VK_RenderModelDestroy( vk_render_model_t* model );
void VK_RenderModelDraw_old( vk_render_model_t* model, int ent_index_prev_frame__toremove );
typedef struct {
vk_render_type_e render_type;
// These are "consumed": copied into internal storage and can be pointers to stack vars
const vec4_t *color;
const matrix4x4 *transform, *prev_transform;
// These are expected to be alive and valid until frame end at least
int geometries_changed_count;
int *geometries_changed;
} r_model_draw_t;
void R_RenderModelDraw(const vk_render_model_t *model, r_model_draw_t args);
// TODO Begin and commit should be removed
void VK_RenderModelDynamicBegin( vk_render_type_e render_type, const vec4_t color, const matrix3x4 transform, const char *debug_name_fmt, ... );
void VK_RenderModelDynamicAddGeometry( const vk_render_geometry_t *geom );
void VK_RenderModelDynamicCommit( void );
2021-06-06 23:17:35 +02:00
void VK_RenderDebugLabelBegin( const char *label );
void VK_RenderDebugLabelEnd( void );
void VK_RenderBegin( qboolean ray_tracing );
2021-06-06 23:17:35 +02:00
void VK_RenderEnd( VkCommandBuffer cmdbuf );
struct vk_combuf_s;
void VK_RenderEndRTX( struct vk_combuf_s* combuf, VkImageView img_dst_view, VkImage img_dst, uint32_t w, uint32_t h );
void VK_Render_FIXME_Barrier( VkCommandBuffer cmdbuf );