yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// vk-render-pass.cpp 2#include "vk-render-pass.h" 3 4#include "vk-helper-functions.h" 5 6namespace gfx 7{ 8 9using namespace Slang ; 10 11namespace vk 12{ 13 14IRenderPassLayout * RenderPassLayoutImpl ::getInterface (const Guid & guid ) 15{ 16if (guid == GfxGUID ::IID_ISlangUnknown || guid == GfxGUID ::IID_IRenderPassLayout ) 17return static_cast < IRenderPassLayout *> (this ); 18return nullptr ; 19} 20 21RenderPassLayoutImpl ::~RenderPassLayoutImpl () 22{ 23m_renderer -> m_api .vkDestroyRenderPass (m_renderer -> m_api .m_device ,m_renderPass ,nullptr ); 24} 25 26Result RenderPassLayoutImpl ::init (DeviceImpl * renderer ,const IRenderPassLayout ::Desc & desc ) 27{ 28m_renderer = renderer ; 29 30// Create render pass using load/storeOp and layouts info from `desc`. 31auto framebufferLayout = static_cast < FramebufferLayoutImpl *> (desc .framebufferLayout ); 32assert (desc .renderTargetCount == framebufferLayout -> m_renderTargetCount ); 33 34// We need extra space if we have depth buffer 35Array < VkAttachmentDescription ,kMaxTargets > targetDescs ; 36targetDescs = framebufferLayout -> m_targetDescs ; 37for (GfxIndex i = 0 ;i < desc .renderTargetCount ;++ i ) 38 { 39VkAttachmentDescription & dst = targetDescs [i ]; 40auto access = desc .renderTargetAccess [i ]; 41// Fill in loadOp/storeOp and layout from desc. 42dst .loadOp = translateLoadOp (access .loadOp ); 43dst .storeOp = translateStoreOp (access .storeOp ); 44dst .stencilLoadOp = translateLoadOp (access .stencilLoadOp ); 45dst .stencilStoreOp = translateStoreOp (access .stencilStoreOp ); 46dst .initialLayout = VulkanUtil ::mapResourceStateToLayout (access .initialState ); 47dst .finalLayout = VulkanUtil ::mapResourceStateToLayout (access .finalState ); 48 } 49 50if (framebufferLayout -> m_hasDepthStencilTarget ) 51 { 52VkAttachmentDescription & dst = targetDescs [desc .renderTargetCount ]; 53auto access = * desc .depthStencilAccess ; 54dst .loadOp = translateLoadOp (access .loadOp ); 55dst .storeOp = translateStoreOp (access .storeOp ); 56dst .stencilLoadOp = translateLoadOp (access .stencilLoadOp ); 57dst .stencilStoreOp = translateStoreOp (access .stencilStoreOp ); 58dst .initialLayout = VulkanUtil ::mapResourceStateToLayout (access .initialState ); 59dst .finalLayout = VulkanUtil ::mapResourceStateToLayout (access .finalState ); 60 } 61 62VkSubpassDescription subpassDesc = {}; 63subpassDesc .flags = 0 ; 64subpassDesc .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS ; 65subpassDesc .inputAttachmentCount = 0u ; 66subpassDesc .pInputAttachments = nullptr ; 67subpassDesc .colorAttachmentCount = desc .renderTargetCount ; 68subpassDesc .pColorAttachments = framebufferLayout -> m_colorReferences .getBuffer (); 69subpassDesc .pResolveAttachments = nullptr ; 70subpassDesc .pDepthStencilAttachment = 71framebufferLayout -> m_hasDepthStencilTarget ?& framebufferLayout -> m_depthReference :nullptr ; 72subpassDesc .preserveAttachmentCount = 0u ; 73subpassDesc .pPreserveAttachments = nullptr ; 74 75VkRenderPassCreateInfo renderPassCreateInfo = {}; 76renderPassCreateInfo .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO ; 77renderPassCreateInfo .attachmentCount = (uint32_t )targetDescs .getCount (); 78renderPassCreateInfo .pAttachments = targetDescs .getBuffer (); 79renderPassCreateInfo .subpassCount = 1 ; 80renderPassCreateInfo .pSubpasses = & subpassDesc ; 81SLANG_VK_RETURN_ON_FAIL (m_renderer -> m_api .vkCreateRenderPass ( 82m_renderer -> m_api .m_device , 83& renderPassCreateInfo , 84nullptr , 85& m_renderPass )); 86return SLANG_OK ; 87} 88 89}// namespace vk 90}// namespace gfx