Pipeline and shader execution is confirmed working.

Next step is to figure out how to fix the viewport to behave like I want it to.
This commit is contained in:
connellpaxton 2024-01-26 00:41:43 -05:00
parent 5342906098
commit bd7f1ed4d3
7 changed files with 46 additions and 6 deletions

View File

@ -19,6 +19,8 @@ Buffer::Buffer(vk::PhysicalDevice phys_dev, vk::Device dev, vk::DeviceSize sz, v
.memoryTypeIndex = mem::choose_heap(phys_dev, reqs, mem_flags),
};
memory = dev.allocateMemory(alloc_info);
dev.bindBufferMemory(buffer, memory, 0);
}
void Buffer::upload(const uint8_t* data, vk::DeviceSize size) {

View File

@ -1,5 +1,6 @@
#include <Renderer/CommandBuffer.hpp>
#include <Renderer/Pipeline.hpp>
#include <Renderer/VertexBuffer.hpp>
#include <Memory/Buffer.hpp>
#include <Memory/Image.hpp>
@ -61,6 +62,20 @@ void CommandBuffer::bind(const GraphicsPipeline& pipeline) {
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.pipeline);
}
void CommandBuffer::bind(vk::PipelineLayout layout, vk::ArrayProxy<vk::DescriptorSet> desc_sets) {
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, layout, 0, desc_sets, nullptr);
}
void CommandBuffer::bind(const VertexBuffer& vertex_buffer, uint32_t binding) {
const std::array<vk::DeviceSize, 1> offsets = {0};
command_buffer.bindVertexBuffers(binding, vertex_buffer.buffer->buffer, offsets);
}
void CommandBuffer::draw(uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) {
command_buffer.draw(vertex_count, instance_count, first_vertex, first_instance);
}
void CommandBuffer::end() {
command_buffer.end();
}

View File

@ -10,6 +10,7 @@ struct Buffer;
struct Image;
struct GraphicsPipeline;
struct ComputePipeline;
struct VertexBuffer;
struct CommandBuffer {
CommandBuffer(vk::Device dev, u32 queue_family);
@ -25,6 +26,10 @@ struct CommandBuffer {
void copy(Buffer& in, Image& out, vk::ImageLayout layout = vk::ImageLayout::eTransferDstOptimal);
void bind(const GraphicsPipeline& pipeline);
void bind(vk::PipelineLayout layout, vk::ArrayProxy<vk::DescriptorSet> desc_sets);
void bind(const VertexBuffer& vertex_buffer, uint32_t binding = 0);
void draw(uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex = 0, uint32_t first_instance = 0);
/* stop recording commands */
void end();

View File

@ -14,7 +14,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
* kinda like how Image::Image has all those versions
*/
/* descriptor set layouts simply define a group of resources that can be relied upon */
auto desc_layout = dev.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo {
desc_layout = dev.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo {
.bindingCount = bindings.size(),
.pBindings = bindings.data(),
});
@ -53,8 +53,6 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
.pSetLayouts = &desc_layout,
})[0];
dev.destroyDescriptorSetLayout(desc_layout);
/* shader setup */
std::vector<vk::PipelineShaderStageCreateInfo> shader_info;
shader_info.reserve(shaders.size());
@ -173,8 +171,6 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
}
pipeline = res.value;
dev.destroyPipelineLayout(layout);
}
void GraphicsPipeline::update(uint32_t binding, const UniformBuffer& uni) {
@ -193,6 +189,8 @@ void GraphicsPipeline::update(uint32_t binding, const UniformBuffer& uni) {
}
GraphicsPipeline::~GraphicsPipeline() {
dev.destroyDescriptorSetLayout(desc_layout);
dev.destroyPipelineLayout(layout);
dev.destroyDescriptorPool(desc_pool);
dev.destroyPipeline(pipeline);
}

View File

@ -16,6 +16,7 @@ struct GraphicsPipeline {
vk::Device dev;
vk::Pipeline pipeline;
vk::PipelineLayout layout;
vk::DescriptorSetLayout desc_layout;
vk::DescriptorPool desc_pool;
vk::DescriptorSet desc_set;

View File

@ -243,12 +243,26 @@ void Renderer::draw() {
.offset = {0, 0},
.extent = swapchain->extent,
};
/* no secondary command buffers (yet), so contents are passed inline */
command_buffer->command_buffer.beginRenderPass(render_pass_info, vk::SubpassContents::eInline);
command_buffer->bind(*pipeline);
command_buffer->bind(*vertex_buffer);
command_buffer->bind(pipeline->layout, pipeline->desc_set);
uniform_buffer->upload(UniformData{
.time = static_cast<float>(frame) * 0.0167f,
});
pipeline->update(0, *uniform_buffer);
command_buffer->command_buffer.setViewport(0, viewport);
command_buffer->command_buffer.setScissor(0, scissor);
command_buffer->draw(9, 1, 0, 0);
command_buffer->command_buffer.endRenderPass();
command_buffer->end();
@ -291,9 +305,13 @@ void Renderer::present() {
Log::error("Failed to present surface.\n");
break;
}
frame++;
}
Renderer::~Renderer() {
dev.waitIdle();
uniform_buffer.reset();
vertex_buffer.reset();
pipeline.reset();

View File

@ -43,4 +43,5 @@ struct Renderer {
std::unique_ptr<UniformBuffer> uniform_buffer;
uint32_t current_image_idx;
uint64_t frame = 0;
};