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:
parent
5342906098
commit
bd7f1ed4d3
@ -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),
|
.memoryTypeIndex = mem::choose_heap(phys_dev, reqs, mem_flags),
|
||||||
};
|
};
|
||||||
memory = dev.allocateMemory(alloc_info);
|
memory = dev.allocateMemory(alloc_info);
|
||||||
|
|
||||||
|
dev.bindBufferMemory(buffer, memory, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::upload(const uint8_t* data, vk::DeviceSize size) {
|
void Buffer::upload(const uint8_t* data, vk::DeviceSize size) {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include <Renderer/CommandBuffer.hpp>
|
#include <Renderer/CommandBuffer.hpp>
|
||||||
#include <Renderer/Pipeline.hpp>
|
#include <Renderer/Pipeline.hpp>
|
||||||
|
#include <Renderer/VertexBuffer.hpp>
|
||||||
|
|
||||||
#include <Memory/Buffer.hpp>
|
#include <Memory/Buffer.hpp>
|
||||||
#include <Memory/Image.hpp>
|
#include <Memory/Image.hpp>
|
||||||
@ -61,6 +62,20 @@ void CommandBuffer::bind(const GraphicsPipeline& pipeline) {
|
|||||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.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() {
|
void CommandBuffer::end() {
|
||||||
command_buffer.end();
|
command_buffer.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ struct Buffer;
|
|||||||
struct Image;
|
struct Image;
|
||||||
struct GraphicsPipeline;
|
struct GraphicsPipeline;
|
||||||
struct ComputePipeline;
|
struct ComputePipeline;
|
||||||
|
struct VertexBuffer;
|
||||||
|
|
||||||
struct CommandBuffer {
|
struct CommandBuffer {
|
||||||
CommandBuffer(vk::Device dev, u32 queue_family);
|
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 copy(Buffer& in, Image& out, vk::ImageLayout layout = vk::ImageLayout::eTransferDstOptimal);
|
||||||
|
|
||||||
void bind(const GraphicsPipeline& pipeline);
|
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 */
|
/* stop recording commands */
|
||||||
void end();
|
void end();
|
||||||
|
|||||||
@ -14,7 +14,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
|
|||||||
* kinda like how Image::Image has all those versions
|
* kinda like how Image::Image has all those versions
|
||||||
*/
|
*/
|
||||||
/* descriptor set layouts simply define a group of resources that can be relied upon */
|
/* 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(),
|
.bindingCount = bindings.size(),
|
||||||
.pBindings = bindings.data(),
|
.pBindings = bindings.data(),
|
||||||
});
|
});
|
||||||
@ -53,8 +53,6 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
|
|||||||
.pSetLayouts = &desc_layout,
|
.pSetLayouts = &desc_layout,
|
||||||
})[0];
|
})[0];
|
||||||
|
|
||||||
dev.destroyDescriptorSetLayout(desc_layout);
|
|
||||||
|
|
||||||
/* shader setup */
|
/* shader setup */
|
||||||
std::vector<vk::PipelineShaderStageCreateInfo> shader_info;
|
std::vector<vk::PipelineShaderStageCreateInfo> shader_info;
|
||||||
shader_info.reserve(shaders.size());
|
shader_info.reserve(shaders.size());
|
||||||
@ -173,8 +171,6 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
|
|||||||
}
|
}
|
||||||
|
|
||||||
pipeline = res.value;
|
pipeline = res.value;
|
||||||
|
|
||||||
dev.destroyPipelineLayout(layout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsPipeline::update(uint32_t binding, const UniformBuffer& uni) {
|
void GraphicsPipeline::update(uint32_t binding, const UniformBuffer& uni) {
|
||||||
@ -193,6 +189,8 @@ void GraphicsPipeline::update(uint32_t binding, const UniformBuffer& uni) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GraphicsPipeline::~GraphicsPipeline() {
|
GraphicsPipeline::~GraphicsPipeline() {
|
||||||
|
dev.destroyDescriptorSetLayout(desc_layout);
|
||||||
|
dev.destroyPipelineLayout(layout);
|
||||||
dev.destroyDescriptorPool(desc_pool);
|
dev.destroyDescriptorPool(desc_pool);
|
||||||
dev.destroyPipeline(pipeline);
|
dev.destroyPipeline(pipeline);
|
||||||
}
|
}
|
||||||
@ -16,6 +16,7 @@ struct GraphicsPipeline {
|
|||||||
vk::Device dev;
|
vk::Device dev;
|
||||||
vk::Pipeline pipeline;
|
vk::Pipeline pipeline;
|
||||||
vk::PipelineLayout layout;
|
vk::PipelineLayout layout;
|
||||||
|
vk::DescriptorSetLayout desc_layout;
|
||||||
vk::DescriptorPool desc_pool;
|
vk::DescriptorPool desc_pool;
|
||||||
vk::DescriptorSet desc_set;
|
vk::DescriptorSet desc_set;
|
||||||
|
|
||||||
|
|||||||
@ -243,12 +243,26 @@ void Renderer::draw() {
|
|||||||
.offset = {0, 0},
|
.offset = {0, 0},
|
||||||
.extent = swapchain->extent,
|
.extent = swapchain->extent,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* no secondary command buffers (yet), so contents are passed inline */
|
/* no secondary command buffers (yet), so contents are passed inline */
|
||||||
command_buffer->command_buffer.beginRenderPass(render_pass_info, vk::SubpassContents::eInline);
|
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.setViewport(0, viewport);
|
||||||
command_buffer->command_buffer.setScissor(0, scissor);
|
command_buffer->command_buffer.setScissor(0, scissor);
|
||||||
|
|
||||||
|
command_buffer->draw(9, 1, 0, 0);
|
||||||
|
|
||||||
command_buffer->command_buffer.endRenderPass();
|
command_buffer->command_buffer.endRenderPass();
|
||||||
|
|
||||||
command_buffer->end();
|
command_buffer->end();
|
||||||
@ -291,9 +305,13 @@ void Renderer::present() {
|
|||||||
Log::error("Failed to present surface.\n");
|
Log::error("Failed to present surface.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frame++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer() {
|
Renderer::~Renderer() {
|
||||||
|
dev.waitIdle();
|
||||||
|
|
||||||
uniform_buffer.reset();
|
uniform_buffer.reset();
|
||||||
vertex_buffer.reset();
|
vertex_buffer.reset();
|
||||||
pipeline.reset();
|
pipeline.reset();
|
||||||
|
|||||||
@ -43,4 +43,5 @@ struct Renderer {
|
|||||||
std::unique_ptr<UniformBuffer> uniform_buffer;
|
std::unique_ptr<UniformBuffer> uniform_buffer;
|
||||||
|
|
||||||
uint32_t current_image_idx;
|
uint32_t current_image_idx;
|
||||||
|
uint64_t frame = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user