yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
b118451e3
master
1// metal-render-pass.cpp 2#include "metal-render-pass.h" 3 4// #include "metal-helper-functions.h" 5 6namespace gfx 7{ 8 9using namespace Slang ; 10 11namespace metal 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 21static inline MTL ::LoadAction translateLoadOp (IRenderPassLayout ::TargetLoadOp loadOp ) 22{ 23switch (loadOp ) 24 { 25case IRenderPassLayout ::TargetLoadOp ::Load : 26return MTL ::LoadActionLoad ; 27case IRenderPassLayout ::TargetLoadOp ::Clear : 28return MTL ::LoadActionClear ; 29case IRenderPassLayout ::TargetLoadOp ::DontCare : 30return MTL ::LoadActionDontCare ; 31default : 32return MTL ::LoadAction (0 ); 33 } 34} 35 36static inline MTL ::StoreAction translateStoreOp (IRenderPassLayout ::TargetStoreOp storeOp ) 37{ 38switch (storeOp ) 39 { 40case IRenderPassLayout ::TargetStoreOp ::Store : 41return MTL ::StoreActionStore ; 42case IRenderPassLayout ::TargetStoreOp ::DontCare : 43return MTL ::StoreActionDontCare ; 44default : 45return MTL ::StoreAction (0 ); 46 } 47} 48 49Result RenderPassLayoutImpl ::init (DeviceImpl * device ,const IRenderPassLayout ::Desc & desc ) 50{ 51m_device = device ; 52 53FramebufferLayoutImpl * framebufferLayout = 54static_cast < FramebufferLayoutImpl *> (desc .framebufferLayout ); 55assert (framebufferLayout ); 56 57// Initialize render pass descriptor, filling in attachment metadata, but leaving texture data 58// unbound. 59m_renderPassDesc = NS ::TransferPtr (MTL ::RenderPassDescriptor ::alloc ()-> init ()); 60 61m_renderPassDesc -> setRenderTargetArrayLength (desc .renderTargetCount ); 62for (GfxIndex i = 0 ;i < desc .renderTargetCount ;++ i ) 63 { 64MTL ::RenderPassColorAttachmentDescriptor * colorAttachment = 65m_renderPassDesc -> colorAttachments ()-> object (i ); 66colorAttachment -> setLoadAction (translateLoadOp (desc .renderTargetAccess [i ].loadOp )); 67colorAttachment -> setStoreAction (translateStoreOp (desc .renderTargetAccess [i ].storeOp )); 68 } 69 70m_renderPassDesc -> depthAttachment ()-> setLoadAction ( 71translateLoadOp (desc .depthStencilAccess -> loadOp )); 72m_renderPassDesc -> depthAttachment ()-> setStoreAction ( 73translateStoreOp (desc .depthStencilAccess -> storeOp )); 74 75m_renderPassDesc -> stencilAttachment ()-> setLoadAction ( 76translateLoadOp (desc .depthStencilAccess -> loadOp )); 77m_renderPassDesc -> stencilAttachment ()-> setStoreAction ( 78translateStoreOp (desc .depthStencilAccess -> storeOp )); 79 80return SLANG_OK ; 81} 82 83}// namespace metal 84}// namespace gfx