summaryrefslogtreecommitdiff
path: root/video.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'video.hpp')
-rw-r--r--video.hpp60
1 files changed, 49 insertions, 11 deletions
diff --git a/video.hpp b/video.hpp
index dc0574e..658e37a 100644
--- a/video.hpp
+++ b/video.hpp
@@ -43,30 +43,68 @@ struct Sampler_Id : public Primitive_Id<uint32_t> {
using Primitive_Id<uint32_t>::Primitive_Id;
};
+#define descriptor_payload_size 8
+
struct Descriptor {
enum class Type {
texture
} type;
int slot;
- Descriptor* next;
+ uint8_t payload[descriptor_payload_size];
};
-struct Texture_Descriptor : public Descriptor {
- Sampler_Id sampler;
+struct Texture_Descriptor {
Texture_Id texture;
+ Sampler_Id sampler;
};
+static_assert(sizeof(Texture_Descriptor) <= descriptor_payload_size);
+
+#define pipeline_max_descriptors 16
+
struct Pipeline {
+ uint64_t pipeline_hash;
+ uint64_t descriptor_resource_hash;
Vertex_Format_Id vertex_format;
Shader_Id shader;
- Descriptor* descriptors;
-
- int count_descriptors() const {
- const Descriptor* d = descriptors;
- int c = 0;
- for (; d; d = d->next)
- c++;
- return c;
+ Descriptor descriptors[pipeline_max_descriptors];
+ int descriptor_count;
+
+ bool desc_layout_eq(const Pipeline& other) const {
+ int i, c = descriptor_count;
+ if (other.pipeline_hash != pipeline_hash)
+ return false;
+ if (other.descriptor_count != c)
+ return false;
+ for (i = 0; i < c; i++) {
+ auto& a = descriptors[i];
+ auto& b = other.descriptors[i];
+ if (a.type != b.type) return false;
+ if (a.slot != b.slot) return false;
+ }
+ return true;
+ }
+
+ bool desc_resources_eq(const Pipeline& other) const {
+ int i, c = descriptor_count;
+ if (other.descriptor_resource_hash != descriptor_resource_hash)
+ return false;
+ if (other.descriptor_count != c) return false;
+ for (i = 0; i < c; i++) {
+ auto& a = descriptors[i];
+ auto& b = other.descriptors[i];
+ if (a.type != b.type) return false;
+ if (a.slot != b.slot) return false;
+ switch (a.type) {
+ case Descriptor::Type::texture: {
+ Texture_Descriptor* ta = (Texture_Descriptor*)a.payload;
+ Texture_Descriptor* tb = (Texture_Descriptor*)b.payload;
+ if (ta->texture != tb->texture) return false;
+ if (ta->sampler != tb->sampler) return false;
+ } break;
+ }
+ }
+ return true;
}
};