blob: 19708cfb661c248d8f7ad5e688d97a5e93e5000d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// metal-command-buffer.cpp
#include "metal-command-buffer.h"
#include "metal-command-encoder.h"
#include "metal-command-queue.h"
#include "metal-device.h"
#include "metal-shader-object.h"
namespace gfx
{
using namespace Slang;
namespace metal
{
ICommandBuffer* CommandBufferImpl::getInterface(const Guid& guid)
{
if (guid == GfxGUID::IID_ISlangUnknown || guid == GfxGUID::IID_ICommandBuffer)
return static_cast<ICommandBuffer*>(this);
return nullptr;
}
Result CommandBufferImpl::init(DeviceImpl* device, TransientResourceHeapImpl* transientHeap)
{
m_device = device;
m_commandBuffer = NS::RetainPtr(m_device->m_commandQueue->commandBuffer());
return SLANG_OK;
}
void CommandBufferImpl::encodeRenderCommands(
IRenderPassLayout* renderPass,
IFramebuffer* framebuffer,
IRenderCommandEncoder** outEncoder)
{
if (!m_renderCommandEncoder)
{
m_renderCommandEncoder = new RenderCommandEncoder;
m_renderCommandEncoder->init(this);
}
m_renderCommandEncoder->beginPass(renderPass, framebuffer);
*outEncoder = m_renderCommandEncoder;
}
void CommandBufferImpl::encodeComputeCommands(IComputeCommandEncoder** outEncoder)
{
if (!m_computeCommandEncoder)
{
m_computeCommandEncoder = new ComputeCommandEncoder;
m_computeCommandEncoder->init(this);
}
*outEncoder = m_computeCommandEncoder;
}
void CommandBufferImpl::encodeResourceCommands(IResourceCommandEncoder** outEncoder)
{
if (!m_resourceCommandEncoder)
{
m_resourceCommandEncoder = new ResourceCommandEncoder;
m_resourceCommandEncoder->init(this);
}
*outEncoder = m_resourceCommandEncoder;
}
void CommandBufferImpl::encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder)
{
if (!m_rayTracingCommandEncoder)
{
m_rayTracingCommandEncoder = new RayTracingCommandEncoder;
m_rayTracingCommandEncoder->init(this);
}
*outEncoder = m_rayTracingCommandEncoder;
}
void CommandBufferImpl::close()
{
// m_commandBuffer->commit();
}
Result CommandBufferImpl::getNativeHandle(InteropHandle* outHandle)
{
outHandle->api = InteropHandleAPI::Metal;
outHandle->handleValue = reinterpret_cast<intptr_t>(m_commandBuffer.get());
return SLANG_OK;
}
MTL::RenderCommandEncoder* CommandBufferImpl::getMetalRenderCommandEncoder(
MTL::RenderPassDescriptor* renderPassDesc)
{
if (!m_metalRenderCommandEncoder)
{
endMetalCommandEncoder();
m_metalRenderCommandEncoder =
NS::RetainPtr(m_commandBuffer->renderCommandEncoder(renderPassDesc));
}
return m_metalRenderCommandEncoder.get();
}
MTL::ComputeCommandEncoder* CommandBufferImpl::getMetalComputeCommandEncoder()
{
if (!m_metalComputeCommandEncoder)
{
endMetalCommandEncoder();
m_metalComputeCommandEncoder = NS::RetainPtr(m_commandBuffer->computeCommandEncoder());
}
return m_metalComputeCommandEncoder.get();
}
MTL::BlitCommandEncoder* CommandBufferImpl::getMetalBlitCommandEncoder()
{
if (!m_metalBlitCommandEncoder)
{
endMetalCommandEncoder();
m_metalBlitCommandEncoder = NS::RetainPtr(m_commandBuffer->blitCommandEncoder());
}
return m_metalBlitCommandEncoder.get();
}
void CommandBufferImpl::endMetalCommandEncoder()
{
if (m_metalRenderCommandEncoder)
{
m_metalRenderCommandEncoder->endEncoding();
m_metalRenderCommandEncoder.reset();
}
if (m_metalComputeCommandEncoder)
{
m_metalComputeCommandEncoder->endEncoding();
m_metalComputeCommandEncoder.reset();
}
if (m_metalBlitCommandEncoder)
{
m_metalBlitCommandEncoder->endEncoding();
m_metalBlitCommandEncoder.reset();
}
}
} // namespace metal
} // namespace gfx
|