yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaMove switch statement bodies to their own lines (#5493)b118451e3

master
2.6 KiB84 linesraw
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{
16    if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_IRenderPassLayout)
17        return static_cast<IRenderPassLayout*>(this);
18    return nullptr;
19}
20
21static inline MTL::LoadAction translateLoadOp(IRenderPassLayout::TargetLoadOp loadOp)
22{
23    switch (loadOp)
24    {
25    case IRenderPassLayout::TargetLoadOp::Load:
26        return MTL::LoadActionLoad;
27    case IRenderPassLayout::TargetLoadOp::Clear:
28        return MTL::LoadActionClear;
29    case IRenderPassLayout::TargetLoadOp::DontCare:
30        return MTL::LoadActionDontCare;
31    default:
32        return MTL::LoadAction(0);
33    }
34}
35
36static inline MTL::StoreAction translateStoreOp(IRenderPassLayout::TargetStoreOp storeOp)
37{
38    switch (storeOp)
39    {
40    case IRenderPassLayout::TargetStoreOp::Store:
41        return MTL::StoreActionStore;
42    case IRenderPassLayout::TargetStoreOp::DontCare:
43        return MTL::StoreActionDontCare;
44    default:
45        return MTL::StoreAction(0);
46    }
47}
48
49Result RenderPassLayoutImpl::init(DeviceImpl* device, const IRenderPassLayout::Desc& desc)
50{
51    m_device = device;
52
53    FramebufferLayoutImpl* framebufferLayout =
54        static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout);
55    assert(framebufferLayout);
56
57    // Initialize render pass descriptor, filling in attachment metadata, but leaving texture data
58    // unbound.
59    m_renderPassDesc = NS::TransferPtr(MTL::RenderPassDescriptor::alloc()->init());
60
61    m_renderPassDesc->setRenderTargetArrayLength(desc.renderTargetCount);
62    for (GfxIndex i = 0; i < desc.renderTargetCount; ++i)
63    {
64        MTL::RenderPassColorAttachmentDescriptor* colorAttachment =
65            m_renderPassDesc->colorAttachments()->object(i);
66        colorAttachment->setLoadAction(translateLoadOp(desc.renderTargetAccess[i].loadOp));
67        colorAttachment->setStoreAction(translateStoreOp(desc.renderTargetAccess[i].storeOp));
68    }
69
70    m_renderPassDesc->depthAttachment()->setLoadAction(
71        translateLoadOp(desc.depthStencilAccess->loadOp));
72    m_renderPassDesc->depthAttachment()->setStoreAction(
73        translateStoreOp(desc.depthStencilAccess->storeOp));
74
75    m_renderPassDesc->stencilAttachment()->setLoadAction(
76        translateLoadOp(desc.depthStencilAccess->loadOp));
77    m_renderPassDesc->stencilAttachment()->setStoreAction(
78        translateStoreOp(desc.depthStencilAccess->storeOp));
79
80    return SLANG_OK;
81}
82
83} // namespace metal
84} // namespace gfx