2019-06-25 22:26:09 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKDevice.h>
|
2019-06-19 16:57:42 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKPhysicalDevice.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKRenderPass.h>
|
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-07-02 20:37:30 +08:00
|
|
|
|
RenderPass *Device::CreateRenderPass(List<VkSubpassDescription> &subpass,List<VkFormat> color_format,VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout)
|
2019-06-19 16:57:42 +08:00
|
|
|
|
{
|
|
|
|
|
int depth=-1;
|
|
|
|
|
uint atta_count=color_format.GetCount();
|
|
|
|
|
|
|
|
|
|
if(attr->physical_device->CheckDepthFormat(depth_format))
|
|
|
|
|
{
|
|
|
|
|
depth=atta_count++;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 17:54:01 +08:00
|
|
|
|
SharedArray<VkAttachmentDescription> attachments=new VkAttachmentDescription[atta_count];
|
|
|
|
|
SharedArray<VkAttachmentReference> color_references=new VkAttachmentReference[color_format.GetCount()];
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
|
|
|
|
for(uint i=0;i<atta_count;i++)
|
|
|
|
|
{
|
2019-07-02 19:52:03 +08:00
|
|
|
|
attachments[i].flags = 0;
|
2019-06-19 16:57:42 +08:00
|
|
|
|
attachments[i].samples = VK_SAMPLE_COUNT_1_BIT;
|
2019-07-01 17:54:01 +08:00
|
|
|
|
attachments[i].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; //LOAD_OP_CLEAR代表LOAD时清空内容
|
|
|
|
|
attachments[i].storeOp = VK_ATTACHMENT_STORE_OP_STORE; //STORE_OP_STROE代表SOTRE时储存内容
|
|
|
|
|
attachments[i].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; //DONT CARE表示不在意
|
2019-06-19 16:57:42 +08:00
|
|
|
|
attachments[i].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
2019-07-01 17:54:01 +08:00
|
|
|
|
attachments[i].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; //代表不关心初始布局
|
2019-06-19 16:57:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 21:12:39 +08:00
|
|
|
|
const VkFormat *cf=color_format.GetData();
|
2019-06-19 16:57:42 +08:00
|
|
|
|
for(int i=0;i<color_format.GetCount();i++)
|
|
|
|
|
{
|
|
|
|
|
attachments[i].finalLayout = color_final_layout;
|
|
|
|
|
attachments[i].format = *cf;
|
|
|
|
|
++cf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(depth!=-1)
|
|
|
|
|
{
|
|
|
|
|
attachments[depth].finalLayout = depth_final_layout;
|
|
|
|
|
attachments[depth].format = depth_format;
|
2019-07-02 20:37:30 +08:00
|
|
|
|
}
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-07-02 20:37:30 +08:00
|
|
|
|
const uint32_t subpass_count=subpass.GetCount();
|
|
|
|
|
uint32_t dependency_count;
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-07-02 20:37:30 +08:00
|
|
|
|
SharedArray<VkSubpassDependency> dependency;
|
|
|
|
|
|
|
|
|
|
if(subpass_count==1)
|
|
|
|
|
{
|
|
|
|
|
dependency_count=1;
|
|
|
|
|
dependency=new VkSubpassDependency[dependency_count];
|
|
|
|
|
|
|
|
|
|
dependency[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependency[0].dstSubpass = 0;
|
|
|
|
|
dependency[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependency[0].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependency[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependency[0].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependency[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
2019-06-19 16:57:42 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
2019-07-02 20:37:30 +08:00
|
|
|
|
{
|
|
|
|
|
dependency_count=subpass_count+1;
|
|
|
|
|
|
|
|
|
|
dependency=new VkSubpassDependency[dependency_count];
|
|
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<subpass_count+1;i++)
|
|
|
|
|
{
|
|
|
|
|
if(i==0)
|
|
|
|
|
{
|
|
|
|
|
dependency[i].srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependency[i].dstSubpass = 0;
|
|
|
|
|
dependency[i].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependency[i].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
dependency[i].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
dependency[i].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dependency[i].srcSubpass = i-1;
|
|
|
|
|
dependency[i].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
|
|
|
|
|
if(i==subpass_count)
|
|
|
|
|
{
|
|
|
|
|
dependency[i].dstSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dependency[i].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
|
|
|
dependency[i].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependency[i].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dependency[i].dstSubpass = i;
|
|
|
|
|
dependency[i].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
|
|
|
|
dependency[i].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
|
dependency[i].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dependency[i].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
|
|
|
|
VkRenderPassCreateInfo rp_info;
|
|
|
|
|
rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
|
|
rp_info.pNext = nullptr;
|
|
|
|
|
rp_info.attachmentCount = atta_count;
|
|
|
|
|
rp_info.pAttachments = attachments;
|
2019-07-02 20:37:30 +08:00
|
|
|
|
rp_info.subpassCount = subpass.GetCount();
|
|
|
|
|
rp_info.pSubpasses = subpass.GetData();
|
|
|
|
|
rp_info.dependencyCount = dependency_count;
|
|
|
|
|
rp_info.pDependencies = dependency;
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
|
|
|
|
VkRenderPass render_pass;
|
|
|
|
|
|
|
|
|
|
if(vkCreateRenderPass(attr->device,&rp_info,nullptr,&render_pass)!=VK_SUCCESS)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
|
|
return(new RenderPass(attr->device,render_pass,color_format,depth_format));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderPass *Device::CreateRenderPass(VkFormat color_format,VkFormat depth_format,VkImageLayout color_final_layout,VkImageLayout depth_final_layout)
|
|
|
|
|
{
|
2019-07-02 20:37:30 +08:00
|
|
|
|
VkAttachmentReference color_atta_ref={0,VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
|
|
|
|
|
VkAttachmentReference depth_atta_ref={1,VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
|
|
|
|
|
|
|
|
|
|
List<VkSubpassDescription> subpass_desc_list;
|
|
|
|
|
|
|
|
|
|
VkSubpassDescription subpass;
|
|
|
|
|
|
|
|
|
|
subpass.flags = 0;
|
|
|
|
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
|
|
|
|
subpass.inputAttachmentCount = 0;
|
|
|
|
|
subpass.pInputAttachments = nullptr;
|
|
|
|
|
subpass.colorAttachmentCount = 1;
|
|
|
|
|
subpass.pColorAttachments = &color_atta_ref;
|
|
|
|
|
subpass.pResolveAttachments = nullptr;
|
|
|
|
|
subpass.pDepthStencilAttachment = &depth_atta_ref;
|
|
|
|
|
subpass.preserveAttachmentCount = 0;
|
|
|
|
|
subpass.pPreserveAttachments = nullptr;
|
|
|
|
|
|
|
|
|
|
subpass_desc_list.Add(subpass);
|
|
|
|
|
|
2019-07-01 17:49:28 +08:00
|
|
|
|
List<VkFormat> color_format_list;
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-07-01 17:49:28 +08:00
|
|
|
|
color_format_list.Add(color_format);
|
2019-06-19 16:57:42 +08:00
|
|
|
|
|
2019-07-02 20:37:30 +08:00
|
|
|
|
return CreateRenderPass(subpass_desc_list,color_format_list,depth_format,color_final_layout,depth_final_layout);
|
2019-06-19 16:57:42 +08:00
|
|
|
|
}
|
|
|
|
|
VK_NAMESPACE_END
|