summaryrefslogtreecommitdiff
path: root/pipeline.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pipeline.cpp')
-rw-r--r--pipeline.cpp51
1 files changed, 38 insertions, 13 deletions
diff --git a/pipeline.cpp b/pipeline.cpp
index 1715930..527c1e7 100644
--- a/pipeline.cpp
+++ b/pipeline.cpp
@@ -1,8 +1,11 @@
#include "video.hpp"
+#include <string.h>
+
extern "C" {
-#include "qstd/memory.h"
-#include "qstd/plat.h"
+#include "memory.h"
+#include "plat.h"
+#include "str.h"
}
Pipeline_Builder::Pipeline_Builder(Arena* arena):
@@ -30,9 +33,7 @@ Render_Pass& Pipeline_Builder::build_rp() {
void Pipeline_Builder::begin() {
pip = (Pipeline*)arena_alloc(arena, sizeof *pip);
- pip->vertex_format = 0;
- pip->shader = 0;
- pip->descriptors = 0;
+ memset(pip, 0, sizeof *pip);
}
void Pipeline_Builder::shader(Shader_Id s) {
@@ -44,16 +45,15 @@ void Pipeline_Builder::texture(
Texture_Id t,
Sampler_Id s
) {
- Texture_Descriptor* d = (Texture_Descriptor*)arena_alloc(
- arena,
- sizeof *d
- );
+ Descriptor* d;
+ Texture_Descriptor* td;
+ assert(pip->descriptor_count < pipeline_max_descriptors);
+ d = &pip->descriptors[pip->descriptor_count++];
+ td = (Texture_Descriptor*)d->payload;
d->slot = binding;
d->type = Descriptor::Type::texture;
- d->sampler = s;
- d->texture = t;
- d->next = pip->descriptors;
- pip->descriptors = d;
+ td->sampler = s;
+ td->texture = t;
}
void Pipeline_Builder::vertex_format(Vertex_Format_Id vf) {
@@ -61,8 +61,33 @@ void Pipeline_Builder::vertex_format(Vertex_Format_Id vf) {
}
Pipeline& Pipeline_Builder::build() {
+#define h(n, v) \
+ n = fnv1a64_2(n, (uint8_t*)&v, sizeof v)
validate();
+ pip->pipeline_hash = fnv1a64(0, 0);
+ h(pip->pipeline_hash, pip->vertex_format);
+ h(pip->pipeline_hash, pip->shader);
+ h(pip->pipeline_hash, pip->descriptor_count);
+ {
+ int i, e = pip->descriptor_count;
+ pip->descriptor_resource_hash = fnv1a64(0, 0);
+ for (i = 0; i < e; i++) {
+ Descriptor* d = &pip->descriptors[i];
+ h(pip->pipeline_hash, d->type);
+ h(pip->pipeline_hash, d->slot);
+ h(pip->descriptor_resource_hash, d->type);
+ h(pip->descriptor_resource_hash, d->slot);
+ switch (d->type) {
+ case Descriptor::Type::texture: {
+ auto td = (Texture_Descriptor*)d->payload;
+ h(pip->descriptor_resource_hash, td->sampler);
+ h(pip->descriptor_resource_hash, td->texture);
+ } break;
+ }
+ }
+ }
return *pip;
+#undef h
}
void Pipeline_Builder::validate() {