summaryrefslogtreecommitdiff
path: root/video.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-26 22:06:57 +1100
committerquou <quou@disroot.org>2024-12-26 22:06:57 +1100
commit7fa078995b3ed62925788ce2460441bc3d373392 (patch)
tree3ea7cb6288319ed56b28b7443d628a4f40a4e5fd /video.cpp
parentdac7103df9f748d3409ac87ac3d015e329f6c7f5 (diff)
constant buffers
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/video.cpp b/video.cpp
index 7335a32..7c88b54 100644
--- a/video.cpp
+++ b/video.cpp
@@ -479,7 +479,7 @@ struct Buffer_Vk : public Buffer, public Late_Terminated {
r |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
if (flags & Buffer_Flags::vertex_buffer)
r |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
- if (flags & Buffer_Flags::uniform_buffer)
+ if (flags & Buffer_Flags::constant_buffer)
r |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
if (flags & Buffer_Flags::storage_buffer)
r |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
@@ -2266,8 +2266,8 @@ void Pipeline_Vk::init_descriptors(
case Descriptor::Type::texture:
dst.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
break;
- default:
- assert(0);
+ case Descriptor::Type::constant_buffer:
+ dst.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
break;
}
dst.binding = src.slot;
@@ -2382,8 +2382,8 @@ void Descriptor_Set_Vk::init(
case Descriptor::Type::texture:
sampler_count++;
break;
- default:
- assert(0);
+ case Descriptor::Type::constant_buffer:
+ cbuffer_count++;
break;
}
}
@@ -2428,6 +2428,7 @@ void Descriptor_Set_Vk::init(
}
for (i = 0; i < count; i++) {
VkDescriptorImageInfo img{};
+ VkDescriptorBufferInfo buf{};
VkWriteDescriptorSet wd{};
auto& src = desc.descriptors[i];
wd.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
@@ -2439,16 +2440,27 @@ void Descriptor_Set_Vk::init(
switch (src.type) {
case Descriptor::Type::texture: {
Texture_Descriptor* td = (Texture_Descriptor*)src.payload;
- assert(td->texture);
- assert(td->sampler);
Texture_Vk& t = *(Texture_Vk*)&dev->get_texture(td->texture);
Sampler_Vk& s = *(Sampler_Vk*)&dev->samplers[td->sampler];
+ assert(td->texture);
+ assert(td->sampler);
img.imageView = t.view;
img.sampler = s.sampler;
img.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
wd.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
wd.pImageInfo = &img;
} break;
+ case Descriptor::Type::constant_buffer: {
+ Constant_Buffer_Descriptor* cd =
+ (Constant_Buffer_Descriptor*)src.payload;
+ Buffer_Vk& b = *(Buffer_Vk*)&dev->get_buffer(cd->buffer);
+ assert(cd->buffer);
+ buf.buffer = b.buf;
+ buf.offset = 0;
+ buf.range = b.size;
+ wd.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+ wd.pBufferInfo = &buf;
+ } break;
}
vkUpdateDescriptorSets(dev->dev, 1, &wd, 0, 0);
}
@@ -2667,7 +2679,7 @@ int Shader::binding_index(const char* name) {
Shader_Vk* sh = (Shader_Vk*)this;
idx = sh->vfd.find_binding(name);
if (idx < 0 || !sh->vfd.bindings[idx].name[0]) return -1;
- return idx;
+ return sh->vfd.bindings[idx].index;
}
int Shader::attribute_index(const char* name) {
@@ -2675,15 +2687,15 @@ int Shader::attribute_index(const char* name) {
Shader_Vk* sh = (Shader_Vk*)this;
idx = sh->vfd.find_attribute(name);
if (idx < 0 || !sh->vfd.attributes[idx].name[0]) return -1;
- return idx;
+ return sh->vfd.attributes[idx].index;
}
-int Shader::descriptor_index(const char* name) {
+int Shader::descriptor_binding(const char* name) {
int idx;
Shader_Vk* sh = (Shader_Vk*)this;
idx = sh->find_descriptor(name);
if (idx < 0 || !sh->descs[idx].name[0]) return -1;
- return idx;
+ return sh->descs[idx].slot;
}
int Shader::descriptor_stage(int slot) {