2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKCommandBuffer.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKRenderPass.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKFramebuffer.h>
|
2019-07-16 21:32:29 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKRenderTarget.h>
|
2019-04-30 16:42:59 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKPipeline.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKBuffer.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKMaterial.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKRenderable.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKDescriptorSets.h>
|
2019-04-09 02:02:43 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-07-10 21:00:36 +08:00
|
|
|
|
CommandBuffer::CommandBuffer(VkDevice dev,const VkExtent2D &extent,const uint32_t atta_count,VkCommandPool cp,VkCommandBuffer cb)
|
2019-04-18 22:10:24 +08:00
|
|
|
|
{
|
|
|
|
|
device=dev;
|
|
|
|
|
pool=cp;
|
|
|
|
|
cmd_buf=cb;
|
|
|
|
|
|
2019-07-10 21:00:36 +08:00
|
|
|
|
cv_count=atta_count;
|
|
|
|
|
|
|
|
|
|
if(cv_count>0)
|
|
|
|
|
{
|
|
|
|
|
clear_values=hgl_zero_new<VkClearValue>(cv_count);
|
|
|
|
|
|
|
|
|
|
clear_values[cv_count-1].depthStencil.depth = 1.0f;
|
|
|
|
|
clear_values[cv_count-1].depthStencil.stencil = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
clear_values=nullptr;
|
|
|
|
|
}
|
2019-04-20 02:28:57 +08:00
|
|
|
|
|
|
|
|
|
render_area.offset.x=0;
|
|
|
|
|
render_area.offset.y=0;
|
|
|
|
|
render_area.extent=extent;
|
2019-05-28 15:07:38 +08:00
|
|
|
|
|
2020-07-20 19:17:17 +08:00
|
|
|
|
default_line_width=1.0;
|
|
|
|
|
|
2019-07-06 16:46:19 +08:00
|
|
|
|
pipeline_layout=VK_NULL_HANDLE;
|
2019-04-18 22:10:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 02:02:43 +08:00
|
|
|
|
CommandBuffer::~CommandBuffer()
|
|
|
|
|
{
|
2019-07-10 21:00:36 +08:00
|
|
|
|
delete[] clear_values;
|
|
|
|
|
|
2019-05-05 11:54:49 +08:00
|
|
|
|
vkFreeCommandBuffers(device,pool,1,&cmd_buf);
|
2019-04-09 02:02:43 +08:00
|
|
|
|
}
|
2019-05-05 11:54:49 +08:00
|
|
|
|
|
2020-06-11 19:23:51 +08:00
|
|
|
|
void CommandBuffer::SetRenderArea(const VkExtent2D &ext2d)
|
|
|
|
|
{
|
|
|
|
|
render_area.offset.x=0;
|
|
|
|
|
render_area.offset.y=0;
|
|
|
|
|
render_area.extent=ext2d;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 14:53:56 +08:00
|
|
|
|
bool CommandBuffer::Begin()
|
2019-04-18 22:10:24 +08:00
|
|
|
|
{
|
2019-07-01 19:25:07 +08:00
|
|
|
|
VkCommandBufferBeginInfo cmd_buf_info;
|
|
|
|
|
|
2019-04-20 02:28:57 +08:00
|
|
|
|
cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
|
|
|
cmd_buf_info.pNext = nullptr;
|
|
|
|
|
cmd_buf_info.flags = 0;
|
|
|
|
|
cmd_buf_info.pInheritanceInfo = nullptr;
|
|
|
|
|
|
|
|
|
|
if(vkBeginCommandBuffer(cmd_buf, &cmd_buf_info)!=VK_SUCCESS)
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-04-29 14:53:56 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 20:22:29 +08:00
|
|
|
|
bool CommandBuffer::BeginRenderPass(VkRenderPass rp,VkFramebuffer fb)
|
2019-04-29 14:53:56 +08:00
|
|
|
|
{
|
2019-04-18 22:10:24 +08:00
|
|
|
|
VkRenderPassBeginInfo rp_begin;
|
|
|
|
|
|
2019-07-05 17:00:49 +08:00
|
|
|
|
rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
|
|
|
|
rp_begin.pNext = nullptr;
|
2019-07-16 20:22:29 +08:00
|
|
|
|
rp_begin.renderPass = rp;
|
|
|
|
|
rp_begin.framebuffer = fb;
|
2019-07-05 17:00:49 +08:00
|
|
|
|
rp_begin.renderArea = render_area;
|
2019-07-10 21:00:36 +08:00
|
|
|
|
rp_begin.clearValueCount = cv_count;
|
2019-07-05 17:00:49 +08:00
|
|
|
|
rp_begin.pClearValues = clear_values;
|
2019-04-18 22:10:24 +08:00
|
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass(cmd_buf, &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
|
2019-04-20 16:11:39 +08:00
|
|
|
|
|
2019-07-05 17:00:49 +08:00
|
|
|
|
viewport.x = 0;
|
|
|
|
|
viewport.y = 0;
|
|
|
|
|
viewport.minDepth = 0.0f;
|
|
|
|
|
viewport.maxDepth = 1.0f;
|
|
|
|
|
viewport.width = render_area.extent.width;
|
|
|
|
|
viewport.height = render_area.extent.height;
|
2019-04-20 16:11:39 +08:00
|
|
|
|
|
|
|
|
|
vkCmdSetViewport(cmd_buf,0,1,&viewport);
|
|
|
|
|
vkCmdSetScissor(cmd_buf,0,1,&render_area);
|
2020-07-20 19:17:17 +08:00
|
|
|
|
vkCmdSetLineWidth(cmd_buf,default_line_width);
|
2019-04-20 16:11:39 +08:00
|
|
|
|
|
2019-07-06 16:46:19 +08:00
|
|
|
|
pipeline_layout=VK_NULL_HANDLE;
|
2019-04-19 00:46:49 +08:00
|
|
|
|
|
2019-04-18 22:10:24 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-16 21:32:29 +08:00
|
|
|
|
bool CommandBuffer::BeginRenderPass(RenderTarget *rt)
|
|
|
|
|
{
|
|
|
|
|
return BeginRenderPass(rt->GetRenderPass(),rt->GetFramebuffer());
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 17:02:38 +08:00
|
|
|
|
bool CommandBuffer::Bind(Renderable *render_obj)
|
2019-04-18 22:10:24 +08:00
|
|
|
|
{
|
2019-04-28 17:02:38 +08:00
|
|
|
|
if(!render_obj)
|
2019-04-18 22:10:24 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-04-28 17:02:38 +08:00
|
|
|
|
const uint count=render_obj->GetBufferCount();
|
2019-04-18 22:10:24 +08:00
|
|
|
|
|
2019-04-20 19:27:10 +08:00
|
|
|
|
if(count<=0)
|
2019-04-18 22:10:24 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-04-28 17:02:38 +08:00
|
|
|
|
vkCmdBindVertexBuffers(cmd_buf,0,count,render_obj->GetBuffer(),render_obj->GetOffset());
|
2019-04-25 14:10:18 +08:00
|
|
|
|
|
2019-04-28 17:02:38 +08:00
|
|
|
|
IndexBuffer *indices_buffer=render_obj->GetIndexBuffer();
|
2019-04-25 14:10:18 +08:00
|
|
|
|
|
2019-05-05 14:22:58 +08:00
|
|
|
|
if(indices_buffer)
|
2019-07-06 16:46:19 +08:00
|
|
|
|
vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),render_obj->GetIndexOffset(),indices_buffer->GetType());
|
2019-04-25 14:10:18 +08:00
|
|
|
|
|
2019-04-18 22:10:24 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-04-09 02:02:43 +08:00
|
|
|
|
VK_NAMESPACE_END
|