diff options
author | quou <quou@disroot.org> | 2024-12-29 11:28:19 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-12-29 11:28:19 +1100 |
commit | dfd95c6e29c25c3ad9acc3e63a790da866339015 (patch) | |
tree | 07a96430f287a4f5303149b97e4adde2e1f67af0 /video.hpp | |
parent | 82c03019867ed57d35932e5eb015c7e77f8bf1ea (diff) |
seperate framebuffers and renderpasses; depth buffering.
Diffstat (limited to 'video.hpp')
-rw-r--r-- | video.hpp | 89 |
1 files changed, 76 insertions, 13 deletions
@@ -69,11 +69,23 @@ static_assert(sizeof(Constant_Buffer_Descriptor) <= descriptor_payload_size); #define pipeline_max_descriptors 16 +enum class Depth_Mode { + less, + less_equal, + equal, + greater, + greater_equal, + always, + never +}; + struct Pipeline { uint64_t pipeline_hash; uint64_t descriptor_resource_hash; int viewport[4]; int scissor[4]; + bool depth_test, depth_write; + Depth_Mode depth_mode; Vertex_Format_Id vertex_format; Shader_Id shader; Descriptor descriptors[pipeline_max_descriptors]; @@ -90,7 +102,10 @@ struct Pipeline { scissor[0] == other.scissor[0] && scissor[1] == other.scissor[1] && scissor[2] == other.scissor[2] && - scissor[3] == other.scissor[3]; + scissor[3] == other.scissor[3] && + depth_test == other.depth_test && + depth_write == other.depth_write && + depth_mode == other.depth_mode; } bool desc_layout_eq(const Pipeline& other) const { @@ -148,17 +163,48 @@ struct Colour { uint8_t r, g, b, a; }; +#define max_colour_attachments 8 + struct Render_Pass { - Texture_Id target; - Colour clear; - Clear_Mode mode; - - bool operator==(const Render_Pass& other) const { - int size = sizeof *this, i; - uint8_t* bba = (uint8_t*)this; - uint8_t* bbb = (uint8_t*)&other; - for (i = 0; i < size; i++, bba++, bbb++) - if (*bba != *bbb) return false; + struct Target { + Texture_Id id; + Texture_Format fmt; + Clear_Mode mode; + union { + Colour colour; + float depth; + } clear; + }; + Target colours[max_colour_attachments]; + int colour_count; + Target depth; + uint64_t layout_hash; + uint64_t resource_hash; + + bool layout_eq(const Render_Pass& other) const { + int i, c = colour_count; + if (layout_hash != other.layout_hash) return false; + if (c != other.colour_count) return false; + if (depth.fmt != other.depth.fmt) return false; + if (depth.mode != other.depth.mode) return false; + for (i = 0; i < c; i++) { + const Target& ac = colours[i]; + const Target& bc = other.colours[i]; + if (ac.fmt != bc.fmt) return false; + if (ac.mode != bc.mode) return false; + } + return true; + } + + bool resources_eq(const Render_Pass& other) const { + int i, c = colour_count; + if (resource_hash != other.resource_hash) return false; + if (!layout_eq(other)) return false; + for (i = 0; i < c; i++) { + const Target& ac = colours[i]; + const Target& bc = other.colours[i]; + if (ac.id != bc.id) return false; + } return true; } }; @@ -189,18 +235,22 @@ struct Pipeline_Builder { Arena* arena; Render_Pass* pass; Pipeline* pip; + Device* dev; - Pipeline_Builder(Arena* arena); + Pipeline_Builder(Arena* arena, Device* dev); void begin_rp(); void rp_target(Texture_Id id, Colour clear_colour); void rp_target(Texture_Id id, Clear_Mode mode); + void rp_depth_target(Texture_Id id, float clear_depth); + void rp_depth_target(Texture_Id id, Clear_Mode mode); Render_Pass& build_rp(); void validate_rp(); - void begin(Device* dev); + void begin(); void viewport(float x, float y, float w, float h); void scissor(float x, float y, float w, float h); + void depth(bool test, bool write, Depth_Mode mode); void shader(Shader_Id s); void vertex_format(Vertex_Format_Id vf); void texture(int binding, Texture_Id t, Sampler_Id s); @@ -220,6 +270,7 @@ enum Resource_State { struct Texture : public Asset { Texture_Id id; + Texture_Format fmt; int w, h; bool alias; }; @@ -237,6 +288,16 @@ namespace Buffer_Flags { }; }; +namespace Texture_Flags { + enum { + sampleable = 1 << 0, + colour_target = 1 << 1, + depth_stencil_target = 1 << 2, + copy_src = 1 << 3, + copy_dst = 1 << 4 + }; +}; + struct Buffer { Buffer_Id id; }; @@ -305,11 +366,13 @@ struct Device { Texture_Id create_texture( Texture_Format fmt, + int flags, int w, int h, Buffer_Id init ); Texture_Id get_backbuffer(); + Texture_Id get_depth_target(); Texture& get_texture(Texture_Id id); void destroy_texture(Texture_Id id); |