summaryrefslogtreecommitdiff
path: root/pipeline.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-29 11:28:19 +1100
committerquou <quou@disroot.org>2024-12-29 11:28:19 +1100
commitdfd95c6e29c25c3ad9acc3e63a790da866339015 (patch)
tree07a96430f287a4f5303149b97e4adde2e1f67af0 /pipeline.cpp
parent82c03019867ed57d35932e5eb015c7e77f8bf1ea (diff)
seperate framebuffers and renderpasses; depth buffering.
Diffstat (limited to 'pipeline.cpp')
-rw-r--r--pipeline.cpp117
1 files changed, 106 insertions, 11 deletions
diff --git a/pipeline.cpp b/pipeline.cpp
index 88b2009..c31ef69 100644
--- a/pipeline.cpp
+++ b/pipeline.cpp
@@ -8,37 +8,115 @@ extern "C" {
#include "str.h"
}
-Pipeline_Builder::Pipeline_Builder(Arena* arena):
- arena(arena) {}
+Pipeline_Builder::Pipeline_Builder(Arena* arena, Device* dev):
+ arena(arena), dev(dev) {}
void Pipeline_Builder::begin_rp() {
pass = (Render_Pass*)arena_alloc(arena, sizeof *pass);
- pass->target = 0;
- pass->clear = { 0, 0, 0, 0 };
+ zero(pass, sizeof *pass);
}
void Pipeline_Builder::rp_target(Texture_Id id, Colour clear) {
- pass->target = id;
- pass->clear = clear;
- pass->mode = Clear_Mode::clear;
+ int i = pass->colour_count++;
+ Texture& texture = dev->get_texture(id);
+ Render_Pass::Target t{
+ .id = id,
+ .fmt = texture.fmt,
+ .mode = Clear_Mode::clear,
+ .clear = { .colour = clear }
+ };
+ assert(i < max_colour_attachments);
+ pass->colours[i] = t;
}
void Pipeline_Builder::rp_target(Texture_Id id, Clear_Mode clear) {
- pass->target = id;
+ int i = pass->colour_count++;
+ Texture& texture = dev->get_texture(id);
+ Render_Pass::Target t{
+ .id = id,
+ .fmt = texture.fmt,
+ .mode = clear,
+ .clear = { .depth = 0.0f }
+ };
+ assert(i < max_colour_attachments);
assert(clear != Clear_Mode::clear);
- pass->mode = clear;
+ pass->colours[i] = t;
+}
+
+void Pipeline_Builder::rp_depth_target(Texture_Id id, float clear) {
+ Texture& texture = dev->get_texture(id);
+ Render_Pass::Target t{
+ .id = id,
+ .fmt = texture.fmt,
+ .mode = Clear_Mode::clear,
+ .clear = { .depth = clear }
+ };
+ pass->depth = t;
+}
+
+void Pipeline_Builder::rp_depth_target(Texture_Id id, Clear_Mode mode) {
+ Texture& texture = dev->get_texture(id);
+ Render_Pass::Target t{
+ .id = id,
+ .fmt = texture.fmt,
+ .mode = mode,
+ .clear = { .depth = 0.0f }
+ };
+ assert(mode != Clear_Mode::clear);
+ pass->depth = t;
}
void Pipeline_Builder::validate_rp() {
- assert(pass->target);
+ int i, c = pass->colour_count;
+ int w, h;
+ assert(c || pass->depth.id);
+ if (c) {
+ Texture& tex = dev->get_texture(pass->colours[0].id);
+ assert(pass->colours[0].id != 0);
+ assert(pass->colours[0].fmt == tex.fmt);
+ w = tex.w;
+ h = tex.h;
+ assert(w && h);
+ }
+ for (i = 1; i < c; i++) {
+ Texture& tex = dev->get_texture(pass->colours[i].id);
+ assert(pass->colours[i].id != 0);
+ assert(pass->colours[i].fmt == tex.fmt);
+ assert(tex.w == w);
+ assert(tex.h == h);
+ }
+ if (pass->depth.id) {
+ Texture& d = dev->get_texture(pass->depth.id);
+ assert(d.fmt == pass->depth.fmt);
+ assert(
+ d.fmt == texture_format_d16 ||
+ d.fmt == texture_format_d24s8 ||
+ d.fmt == texture_format_d32
+ );
+ assert(d.w == w);
+ assert(d.h == h);
+ }
}
Render_Pass& Pipeline_Builder::build_rp() {
+ int i, c = pass->colour_count;
+#define h(n, v) \
+ n = fnv1a64_2(n, (uint8_t*)&v, sizeof v)
validate_rp();
+ h(pass->layout_hash, pass->colour_count);
+ h(pass->layout_hash, pass->depth.fmt);
+ h(pass->layout_hash, pass->depth.mode);
+ h(pass->resource_hash, pass->depth.id);
+ for (i = 0; i < c; i++) {
+ Render_Pass::Target& ct = pass->colours[i];
+ h(pass->layout_hash, ct.fmt);
+ h(pass->layout_hash, ct.mode);
+ h(pass->resource_hash, ct.id);
+ }
return *pass;
}
-void Pipeline_Builder::begin(Device* dev) {
+void Pipeline_Builder::begin() {
pip = (Pipeline*)arena_alloc(arena, sizeof *pip);
zero(pip, sizeof *pip);
if (dev) {
@@ -79,6 +157,12 @@ void Pipeline_Builder::scissor(
pip->scissor[3] = h;
}
+void Pipeline_Builder::depth(bool test, bool write, Depth_Mode mode) {
+ pip->depth_test = test;
+ pip->depth_write = write;
+ pip->depth_mode = mode;
+}
+
void Pipeline_Builder::shader(Shader_Id s) {
pip->shader = s;
}
@@ -122,6 +206,17 @@ Pipeline& Pipeline_Builder::build() {
h(pip->pipeline_hash, pip->vertex_format);
h(pip->pipeline_hash, pip->shader);
h(pip->pipeline_hash, pip->descriptor_count);
+ h(pip->pipeline_hash, pip->viewport[0]);
+ h(pip->pipeline_hash, pip->viewport[1]);
+ h(pip->pipeline_hash, pip->viewport[2]);
+ h(pip->pipeline_hash, pip->viewport[3]);
+ h(pip->pipeline_hash, pip->scissor[0]);
+ h(pip->pipeline_hash, pip->scissor[1]);
+ h(pip->pipeline_hash, pip->scissor[2]);
+ h(pip->pipeline_hash, pip->scissor[3]);
+ h(pip->pipeline_hash, pip->depth_test);
+ h(pip->pipeline_hash, pip->depth_write);
+ h(pip->pipeline_hash, pip->depth_mode);
{
int i, e = pip->descriptor_count;
pip->descriptor_resource_hash = fnv1a64(0, 0);