mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
[mac][ios] Was: Silenced annoying deprecation warnings
pastk: removed silencing, left only minor style etc changes Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
committed by
Yannik Bloscheck
parent
c4d5109d5b
commit
9d8e84ae5a
@@ -31,10 +31,10 @@ MetalBaseContext::MetalBaseContext(id<MTLDevice> device, m2::PointU const & scre
|
|||||||
m_renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionClear;
|
m_renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionClear;
|
||||||
m_renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionStore;
|
m_renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionStore;
|
||||||
m_renderPassDescriptor.stencilAttachment.clearStencil = 0;
|
m_renderPassDescriptor.stencilAttachment.clearStencil = 0;
|
||||||
|
|
||||||
RecreateDepthTexture(screenSize);
|
RecreateDepthTexture(screenSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::RecreateDepthTexture(m2::PointU const & screenSize)
|
void MetalBaseContext::RecreateDepthTexture(m2::PointU const & screenSize)
|
||||||
{
|
{
|
||||||
if (screenSize.x == 0 || screenSize.y == 0)
|
if (screenSize.x == 0 || screenSize.y == 0)
|
||||||
@@ -42,7 +42,7 @@ void MetalBaseContext::RecreateDepthTexture(m2::PointU const & screenSize)
|
|||||||
m_depthTexture.reset();
|
m_depthTexture.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_depthTexture = make_unique_dp<MetalTexture>(nullptr /* allocator */);
|
m_depthTexture = make_unique_dp<MetalTexture>(nullptr /* allocator */);
|
||||||
HWTexture::Params params;
|
HWTexture::Params params;
|
||||||
params.m_width = screenSize.x;
|
params.m_width = screenSize.x;
|
||||||
@@ -51,7 +51,7 @@ void MetalBaseContext::RecreateDepthTexture(m2::PointU const & screenSize)
|
|||||||
params.m_isRenderTarget = true;
|
params.m_isRenderTarget = true;
|
||||||
m_depthTexture->Create(make_ref(this), params, nullptr /* data */);
|
m_depthTexture->Create(make_ref(this), params, nullptr /* data */);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::Init(dp::ApiVersion apiVersion)
|
void MetalBaseContext::Init(dp::ApiVersion apiVersion)
|
||||||
{
|
{
|
||||||
CHECK(apiVersion == dp::ApiVersion::Metal, ());
|
CHECK(apiVersion == dp::ApiVersion::Metal, ());
|
||||||
@@ -62,7 +62,7 @@ ApiVersion MetalBaseContext::GetApiVersion() const
|
|||||||
{
|
{
|
||||||
return dp::ApiVersion::Metal;
|
return dp::ApiVersion::Metal;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MetalBaseContext::GetRendererName() const
|
std::string MetalBaseContext::GetRendererName() const
|
||||||
{
|
{
|
||||||
return std::string([m_device.name UTF8String]);
|
return std::string([m_device.name UTF8String]);
|
||||||
@@ -107,7 +107,7 @@ std::string MetalBaseContext::GetRendererVersion() const
|
|||||||
return s1.first > s2.first;
|
return s1.first > s2.first;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto featureSet : features)
|
for (auto featureSet : features)
|
||||||
{
|
{
|
||||||
if ([m_device supportsFeatureSet:featureSet.first])
|
if ([m_device supportsFeatureSet:featureSet.first])
|
||||||
@@ -115,26 +115,26 @@ std::string MetalBaseContext::GetRendererVersion() const
|
|||||||
}
|
}
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::PushDebugLabel(std::string const & label)
|
void MetalBaseContext::PushDebugLabel(std::string const & label)
|
||||||
{
|
{
|
||||||
if (m_currentCommandEncoder == nil)
|
if (m_currentCommandEncoder == nil)
|
||||||
return;
|
return;
|
||||||
[m_currentCommandEncoder pushDebugGroup:@(label.c_str())];
|
[m_currentCommandEncoder pushDebugGroup:@(label.c_str())];
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::PopDebugLabel()
|
void MetalBaseContext::PopDebugLabel()
|
||||||
{
|
{
|
||||||
if (m_currentCommandEncoder == nil)
|
if (m_currentCommandEncoder == nil)
|
||||||
return;
|
return;
|
||||||
[m_currentCommandEncoder popDebugGroup];
|
[m_currentCommandEncoder popDebugGroup];
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::Resize(int w, int h)
|
void MetalBaseContext::Resize(int w, int h)
|
||||||
{
|
{
|
||||||
if (m_depthTexture && m_depthTexture->GetWidth() == w && m_depthTexture->GetHeight() == h)
|
if (m_depthTexture && m_depthTexture->GetWidth() == w && m_depthTexture->GetHeight() == h)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RecreateDepthTexture(m2::PointU(w, h));
|
RecreateDepthTexture(m2::PointU(w, h));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ void MetalBaseContext::ApplyFramebuffer(std::string const & framebufferLabel)
|
|||||||
m_frameCommandBuffer = [m_commandQueue commandBuffer];
|
m_frameCommandBuffer = [m_commandQueue commandBuffer];
|
||||||
m_frameCommandBuffer.label = @"Frame command buffer";
|
m_frameCommandBuffer.label = @"Frame command buffer";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_currentFramebuffer)
|
if (!m_currentFramebuffer)
|
||||||
{
|
{
|
||||||
// Use default(system) framebuffer and depth-stencil.
|
// Use default(system) framebuffer and depth-stencil.
|
||||||
@@ -164,11 +164,11 @@ void MetalBaseContext::ApplyFramebuffer(std::string const & framebufferLabel)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ref_ptr<Framebuffer> framebuffer = m_currentFramebuffer;
|
ref_ptr<Framebuffer> framebuffer = m_currentFramebuffer;
|
||||||
|
|
||||||
ASSERT(dynamic_cast<MetalTexture *>(framebuffer->GetTexture()->GetHardwareTexture().get()) != nullptr, ());
|
ASSERT(dynamic_cast<MetalTexture *>(framebuffer->GetTexture()->GetHardwareTexture().get()) != nullptr, ());
|
||||||
ref_ptr<MetalTexture> colorAttachment = framebuffer->GetTexture()->GetHardwareTexture();
|
ref_ptr<MetalTexture> colorAttachment = framebuffer->GetTexture()->GetHardwareTexture();
|
||||||
m_renderPassDescriptor.colorAttachments[0].texture = colorAttachment->GetTexture();
|
m_renderPassDescriptor.colorAttachments[0].texture = colorAttachment->GetTexture();
|
||||||
|
|
||||||
auto const depthStencilRef = framebuffer->GetDepthStencilRef();
|
auto const depthStencilRef = framebuffer->GetDepthStencilRef();
|
||||||
if (depthStencilRef != nullptr)
|
if (depthStencilRef != nullptr)
|
||||||
{
|
{
|
||||||
@@ -186,12 +186,12 @@ void MetalBaseContext::ApplyFramebuffer(std::string const & framebufferLabel)
|
|||||||
m_renderPassDescriptor.stencilAttachment.texture = nil;
|
m_renderPassDescriptor.stencilAttachment.texture = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(m_currentCommandEncoder == nil, ("Current command encoder was not finished."));
|
CHECK(m_currentCommandEncoder == nil, ("Current command encoder was not finished."));
|
||||||
m_currentCommandEncoder = [m_frameCommandBuffer renderCommandEncoderWithDescriptor:m_renderPassDescriptor];
|
m_currentCommandEncoder = [m_frameCommandBuffer renderCommandEncoderWithDescriptor:m_renderPassDescriptor];
|
||||||
m_currentCommandEncoder.label = @(framebufferLabel.c_str());
|
m_currentCommandEncoder.label = @(framebufferLabel.c_str());
|
||||||
[m_currentCommandEncoder pushDebugGroup:@(framebufferLabel.c_str())];
|
[m_currentCommandEncoder pushDebugGroup:@(framebufferLabel.c_str())];
|
||||||
|
|
||||||
// Default rendering options.
|
// Default rendering options.
|
||||||
[m_currentCommandEncoder setFrontFacingWinding:MTLWindingClockwise];
|
[m_currentCommandEncoder setFrontFacingWinding:MTLWindingClockwise];
|
||||||
[m_currentCommandEncoder setCullMode:MTLCullModeBack];
|
[m_currentCommandEncoder setCullMode:MTLCullModeBack];
|
||||||
@@ -204,7 +204,7 @@ void MetalBaseContext::SetClearColor(dp::Color const & color)
|
|||||||
m_renderPassDescriptor.colorAttachments[0].clearColor =
|
m_renderPassDescriptor.colorAttachments[0].clearColor =
|
||||||
MTLClearColorMake(color.GetRedF(), color.GetGreenF(), color.GetBlueF(), color.GetAlphaF());
|
MTLClearColorMake(color.GetRedF(), color.GetGreenF(), color.GetBlueF(), color.GetAlphaF());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::Clear(uint32_t clearBits, uint32_t storeBits)
|
void MetalBaseContext::Clear(uint32_t clearBits, uint32_t storeBits)
|
||||||
{
|
{
|
||||||
if (m_currentCommandEncoder != nil)
|
if (m_currentCommandEncoder != nil)
|
||||||
@@ -215,7 +215,7 @@ void MetalBaseContext::Clear(uint32_t clearBits, uint32_t storeBits)
|
|||||||
m_cleaner.ClearColor(make_ref(this), m_currentCommandEncoder);
|
m_cleaner.ClearColor(make_ref(this), m_currentCommandEncoder);
|
||||||
else if (clearBits & ClearBits::DepthBit)
|
else if (clearBits & ClearBits::DepthBit)
|
||||||
m_cleaner.ClearDepth(make_ref(this), m_currentCommandEncoder);
|
m_cleaner.ClearDepth(make_ref(this), m_currentCommandEncoder);
|
||||||
|
|
||||||
if (clearBits & ClearBits::StencilBit)
|
if (clearBits & ClearBits::StencilBit)
|
||||||
CHECK(false, ("Stencil clearing is not implemented"));
|
CHECK(false, ("Stencil clearing is not implemented"));
|
||||||
}
|
}
|
||||||
@@ -227,42 +227,41 @@ void MetalBaseContext::Clear(uint32_t clearBits, uint32_t storeBits)
|
|||||||
m_renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
m_renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
|
||||||
else
|
else
|
||||||
m_renderPassDescriptor.colorAttachments[0].loadAction = (storeBits & ClearBits::ColorBit) ? MTLLoadActionLoad : MTLLoadActionDontCare;
|
m_renderPassDescriptor.colorAttachments[0].loadAction = (storeBits & ClearBits::ColorBit) ? MTLLoadActionLoad : MTLLoadActionDontCare;
|
||||||
|
|
||||||
if (clearBits & ClearBits::DepthBit)
|
if (clearBits & ClearBits::DepthBit)
|
||||||
m_renderPassDescriptor.depthAttachment.loadAction = MTLLoadActionClear;
|
m_renderPassDescriptor.depthAttachment.loadAction = MTLLoadActionClear;
|
||||||
else
|
else
|
||||||
m_renderPassDescriptor.depthAttachment.loadAction = (storeBits & ClearBits::DepthBit) ? MTLLoadActionLoad : MTLLoadActionDontCare;
|
m_renderPassDescriptor.depthAttachment.loadAction = (storeBits & ClearBits::DepthBit) ? MTLLoadActionLoad : MTLLoadActionDontCare;
|
||||||
|
|
||||||
if (clearBits & ClearBits::StencilBit)
|
if (clearBits & ClearBits::StencilBit)
|
||||||
m_renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionClear;
|
m_renderPassDescriptor.stencilAttachment.loadAction = MTLLoadActionClear;
|
||||||
else
|
else
|
||||||
m_renderPassDescriptor.stencilAttachment.loadAction = (storeBits & ClearBits::StencilBit) ? MTLLoadActionLoad : MTLLoadActionDontCare;
|
m_renderPassDescriptor.stencilAttachment.loadAction = (storeBits & ClearBits::StencilBit) ? MTLLoadActionLoad : MTLLoadActionDontCare;
|
||||||
|
|
||||||
// Apply storing mode.
|
// Apply storing mode.
|
||||||
if (storeBits & ClearBits::ColorBit)
|
if (storeBits & ClearBits::ColorBit)
|
||||||
m_renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
m_renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||||
else
|
else
|
||||||
m_renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionDontCare;
|
m_renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionDontCare;
|
||||||
|
|
||||||
if (storeBits & ClearBits::DepthBit)
|
if (storeBits & ClearBits::DepthBit)
|
||||||
m_renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionStore;
|
m_renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionStore;
|
||||||
else
|
else
|
||||||
m_renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionDontCare;
|
m_renderPassDescriptor.depthAttachment.storeAction = MTLStoreActionDontCare;
|
||||||
|
|
||||||
if (storeBits & ClearBits::StencilBit)
|
if (storeBits & ClearBits::StencilBit)
|
||||||
m_renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionStore;
|
m_renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionStore;
|
||||||
else
|
else
|
||||||
m_renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionDontCare;
|
m_renderPassDescriptor.stencilAttachment.storeAction = MTLStoreActionDontCare;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::SetViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
void MetalBaseContext::SetViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
||||||
{
|
{
|
||||||
id<MTLRenderCommandEncoder> encoder = GetCommandEncoder();
|
id<MTLRenderCommandEncoder> encoder = GetCommandEncoder();
|
||||||
[encoder setViewport:(MTLViewport){ static_cast<double>(x), static_cast<double>(y),
|
[encoder setViewport:{static_cast<double>(x), static_cast<double>(y), static_cast<double>(w), static_cast<double>(h),
|
||||||
static_cast<double>(w), static_cast<double>(h),
|
0.0, 1.0}];
|
||||||
0.0, 1.0 }];
|
[encoder setScissorRect:{x, y, w, h}];
|
||||||
[encoder setScissorRect:(MTLScissorRect){ x, y, w, h }];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::SetScissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
void MetalBaseContext::SetScissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
|
||||||
@@ -277,7 +276,7 @@ void MetalBaseContext::SetScissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h
|
|||||||
if (x + w > rpWidth) w = rpWidth - x;
|
if (x + w > rpWidth) w = rpWidth - x;
|
||||||
if (y + h > rpHeight) h = rpHeight - y;
|
if (y + h > rpHeight) h = rpHeight - y;
|
||||||
|
|
||||||
[encoder setScissorRect:(MTLScissorRect){ x, y, w, h }];
|
[encoder setScissorRect:{x, y, w, h}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,12 +313,12 @@ void MetalBaseContext::SetCullingEnabled(bool enabled)
|
|||||||
id<MTLRenderCommandEncoder> encoder = GetCommandEncoder();
|
id<MTLRenderCommandEncoder> encoder = GetCommandEncoder();
|
||||||
[encoder setCullMode: (enabled ? MTLCullModeBack : MTLCullModeNone)];
|
[encoder setCullMode: (enabled ? MTLCullModeBack : MTLCullModeNone)];
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLDevice> MetalBaseContext::GetMetalDevice() const
|
id<MTLDevice> MetalBaseContext::GetMetalDevice() const
|
||||||
{
|
{
|
||||||
return m_device;
|
return m_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLRenderCommandEncoder> MetalBaseContext::GetCommandEncoder() const
|
id<MTLRenderCommandEncoder> MetalBaseContext::GetCommandEncoder() const
|
||||||
{
|
{
|
||||||
CHECK(m_currentCommandEncoder != nil, ("Probably encoding commands were called before ApplyFramebuffer."));
|
CHECK(m_currentCommandEncoder != nil, ("Probably encoding commands were called before ApplyFramebuffer."));
|
||||||
@@ -331,41 +330,41 @@ id<MTLCommandBuffer> MetalBaseContext::GetCommandBuffer() const
|
|||||||
CHECK(m_frameCommandBuffer != nil, ("Probably encoding commands were called before ApplyFramebuffer."));
|
CHECK(m_frameCommandBuffer != nil, ("Probably encoding commands were called before ApplyFramebuffer."));
|
||||||
return m_frameCommandBuffer;
|
return m_frameCommandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLDepthStencilState> MetalBaseContext::GetDepthStencilState()
|
id<MTLDepthStencilState> MetalBaseContext::GetDepthStencilState()
|
||||||
{
|
{
|
||||||
return m_metalStates.GetDepthStencilState(m_device, m_currentDepthStencilKey);
|
return m_metalStates.GetDepthStencilState(m_device, m_currentDepthStencilKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLRenderPipelineState> MetalBaseContext::GetPipelineState(ref_ptr<GpuProgram> program, bool blendingEnabled)
|
id<MTLRenderPipelineState> MetalBaseContext::GetPipelineState(ref_ptr<GpuProgram> program, bool blendingEnabled)
|
||||||
{
|
{
|
||||||
CHECK(m_currentCommandEncoder != nil, ("Probably encoding commands were called before ApplyFramebuffer."));
|
CHECK(m_currentCommandEncoder != nil, ("Probably encoding commands were called before ApplyFramebuffer."));
|
||||||
|
|
||||||
id<MTLTexture> colorTexture = m_renderPassDescriptor.colorAttachments[0].texture;
|
id<MTLTexture> colorTexture = m_renderPassDescriptor.colorAttachments[0].texture;
|
||||||
// It can be nil in the case when Metal drawable is absent (e.g. finish rendering in background).
|
// It can be nil in the case when Metal drawable is absent (e.g. finish rendering in background).
|
||||||
if (colorTexture == nil)
|
if (colorTexture == nil)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
id<MTLTexture> depthTexture = m_renderPassDescriptor.depthAttachment.texture;
|
id<MTLTexture> depthTexture = m_renderPassDescriptor.depthAttachment.texture;
|
||||||
MTLPixelFormat depthStencilFormat = (depthTexture != nil) ? depthTexture.pixelFormat : MTLPixelFormatInvalid;
|
MTLPixelFormat depthStencilFormat = (depthTexture != nil) ? depthTexture.pixelFormat : MTLPixelFormatInvalid;
|
||||||
|
|
||||||
MetalStates::PipelineKey const key(program, colorTexture.pixelFormat, depthStencilFormat, blendingEnabled);
|
MetalStates::PipelineKey const key(program, colorTexture.pixelFormat, depthStencilFormat, blendingEnabled);
|
||||||
return m_metalStates.GetPipelineState(m_device, key);
|
return m_metalStates.GetPipelineState(m_device, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLSamplerState> MetalBaseContext::GetSamplerState(TextureFilter filter, TextureWrapping wrapSMode,
|
id<MTLSamplerState> MetalBaseContext::GetSamplerState(TextureFilter filter, TextureWrapping wrapSMode,
|
||||||
TextureWrapping wrapTMode)
|
TextureWrapping wrapTMode)
|
||||||
{
|
{
|
||||||
MetalStates::SamplerKey const key(filter, wrapSMode, wrapTMode);
|
MetalStates::SamplerKey const key(filter, wrapSMode, wrapTMode);
|
||||||
return m_metalStates.GetSamplerState(m_device, key);
|
return m_metalStates.GetSamplerState(m_device, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MetalBaseContext::BeginRendering()
|
bool MetalBaseContext::BeginRendering()
|
||||||
{
|
{
|
||||||
CHECK(m_currentCommandEncoder == nil, ("Current command encoder was not finished."));
|
CHECK(m_currentCommandEncoder == nil, ("Current command encoder was not finished."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::EndRendering()
|
void MetalBaseContext::EndRendering()
|
||||||
{
|
{
|
||||||
FinishCurrentEncoding();
|
FinishCurrentEncoding();
|
||||||
@@ -376,27 +375,27 @@ void MetalBaseContext::Present()
|
|||||||
RequestFrameDrawable();
|
RequestFrameDrawable();
|
||||||
if (m_frameDrawable)
|
if (m_frameDrawable)
|
||||||
[m_frameCommandBuffer presentDrawable:m_frameDrawable];
|
[m_frameCommandBuffer presentDrawable:m_frameDrawable];
|
||||||
|
|
||||||
[m_frameCommandBuffer commit];
|
[m_frameCommandBuffer commit];
|
||||||
m_frameDrawable = nil;
|
m_frameDrawable = nil;
|
||||||
[m_frameCommandBuffer waitUntilCompleted];
|
[m_frameCommandBuffer waitUntilCompleted];
|
||||||
m_frameCommandBuffer = nil;
|
m_frameCommandBuffer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::RequestFrameDrawable()
|
void MetalBaseContext::RequestFrameDrawable()
|
||||||
{
|
{
|
||||||
if (m_frameDrawable != nil)
|
if (m_frameDrawable != nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CHECK(m_drawableRequest != nullptr, ());
|
CHECK(m_drawableRequest != nullptr, ());
|
||||||
m_frameDrawable = m_drawableRequest();
|
m_frameDrawable = m_drawableRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::ResetFrameDrawable()
|
void MetalBaseContext::ResetFrameDrawable()
|
||||||
{
|
{
|
||||||
if (m_frameDrawable == nil)
|
if (m_frameDrawable == nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_frameDrawable = nil;
|
m_frameDrawable = nil;
|
||||||
RequestFrameDrawable();
|
RequestFrameDrawable();
|
||||||
}
|
}
|
||||||
@@ -408,7 +407,7 @@ void MetalBaseContext::FinishCurrentEncoding()
|
|||||||
m_currentCommandEncoder = nil;
|
m_currentCommandEncoder = nil;
|
||||||
m_lastPipelineState = nil;
|
m_lastPipelineState = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::SetSystemPrograms(drape_ptr<GpuProgram> && programClearColor,
|
void MetalBaseContext::SetSystemPrograms(drape_ptr<GpuProgram> && programClearColor,
|
||||||
drape_ptr<GpuProgram> && programClearDepth,
|
drape_ptr<GpuProgram> && programClearDepth,
|
||||||
drape_ptr<GpuProgram> && programClearColorAndDepth)
|
drape_ptr<GpuProgram> && programClearColorAndDepth)
|
||||||
@@ -416,24 +415,24 @@ void MetalBaseContext::SetSystemPrograms(drape_ptr<GpuProgram> && programClearCo
|
|||||||
m_cleaner.Init(make_ref(this), std::move(programClearColor), std::move(programClearDepth),
|
m_cleaner.Init(make_ref(this), std::move(programClearColor), std::move(programClearDepth),
|
||||||
std::move(programClearColorAndDepth));
|
std::move(programClearColorAndDepth));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::ApplyPipelineState(id<MTLRenderPipelineState> state)
|
void MetalBaseContext::ApplyPipelineState(id<MTLRenderPipelineState> state)
|
||||||
{
|
{
|
||||||
m_lastPipelineState = state;
|
m_lastPipelineState = state;
|
||||||
if (state != nil)
|
if (state != nil)
|
||||||
[GetCommandEncoder() setRenderPipelineState:state];
|
[GetCommandEncoder() setRenderPipelineState:state];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MetalBaseContext::HasAppliedPipelineState() const
|
bool MetalBaseContext::HasAppliedPipelineState() const
|
||||||
{
|
{
|
||||||
return m_lastPipelineState != nil;
|
return m_lastPipelineState != nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::ResetPipelineStatesCache()
|
void MetalBaseContext::ResetPipelineStatesCache()
|
||||||
{
|
{
|
||||||
m_metalStates.ResetPipelineStatesCache();
|
m_metalStates.ResetPipelineStatesCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetalBaseContext::DebugSynchronizeWithCPU()
|
void MetalBaseContext::DebugSynchronizeWithCPU()
|
||||||
{
|
{
|
||||||
FinishCurrentEncoding();
|
FinishCurrentEncoding();
|
||||||
@@ -444,7 +443,7 @@ void MetalBaseContext::DebugSynchronizeWithCPU()
|
|||||||
m_frameCommandBuffer = nil;
|
m_frameCommandBuffer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLRenderPassDescriptor * MetalBaseContext::GetRenderPassDescriptor() const
|
MTLRenderPassDescriptor * MetalBaseContext::GetRenderPassDescriptor() const
|
||||||
{
|
{
|
||||||
return m_renderPassDescriptor;
|
return m_renderPassDescriptor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct ProgramInfo
|
|||||||
std::string const m_vertexShaderName;
|
std::string const m_vertexShaderName;
|
||||||
std::string const m_fragmentShaderName;
|
std::string const m_fragmentShaderName;
|
||||||
Layout m_layout;
|
Layout m_layout;
|
||||||
|
|
||||||
// Layout is in the format { buffer0, buffer1, ..., bufferN }.
|
// Layout is in the format { buffer0, buffer1, ..., bufferN }.
|
||||||
// bufferX is a pair { start attribute index, end attribute index }.
|
// bufferX is a pair { start attribute index, end attribute index }.
|
||||||
ProgramInfo(std::string && vertexShaderName, std::string && fragmentShaderName,
|
ProgramInfo(std::string && vertexShaderName, std::string && fragmentShaderName,
|
||||||
@@ -39,7 +39,7 @@ struct ProgramInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::array<ProgramInfo, static_cast<size_t>(SystemProgram::SystemProgramsCount)> const kMetalSystemProgramsInfo = {{
|
std::array<ProgramInfo, static_cast<size_t>(SystemProgram::SystemProgramsCount)> const kMetalSystemProgramsInfo = {{
|
||||||
ProgramInfo("vsCleaner", "fsClearColor", {{0, 0}}), // ClearColor
|
ProgramInfo("vsCleaner", "fsClearColor", {{0, 0}}), // ClearColor
|
||||||
ProgramInfo("vsCleaner", "fsClearDepth", {{0, 0}}), // ClearDepth
|
ProgramInfo("vsCleaner", "fsClearDepth", {{0, 0}}), // ClearDepth
|
||||||
@@ -117,7 +117,7 @@ MTLVertexFormat GetFormatByDataType(MTLDataType dataType)
|
|||||||
}
|
}
|
||||||
return MTLVertexFormatInvalid;
|
return MTLVertexFormatInvalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetSizeByDataType(MTLDataType dataType)
|
uint32_t GetSizeByDataType(MTLDataType dataType)
|
||||||
{
|
{
|
||||||
switch (dataType)
|
switch (dataType)
|
||||||
@@ -130,7 +130,7 @@ uint32_t GetSizeByDataType(MTLDataType dataType)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetBindings(NSArray<MTLArgument *> * arguments, int8_t & uniformsBindingIndex,
|
void GetBindings(NSArray<MTLArgument *> * arguments, int8_t & uniformsBindingIndex,
|
||||||
dp::metal::MetalGpuProgram::TexturesBindingInfo & textureBindingInfo)
|
dp::metal::MetalGpuProgram::TexturesBindingInfo & textureBindingInfo)
|
||||||
{
|
{
|
||||||
@@ -138,7 +138,7 @@ void GetBindings(NSArray<MTLArgument *> * arguments, int8_t & uniformsBindingInd
|
|||||||
NSString * kUniformsName = @"uniforms";
|
NSString * kUniformsName = @"uniforms";
|
||||||
// Sampler name must be constructed as concatenation of texture name and kSamplerSuffix.
|
// Sampler name must be constructed as concatenation of texture name and kSamplerSuffix.
|
||||||
static std::string const kSamplerSuffix = "Sampler";
|
static std::string const kSamplerSuffix = "Sampler";
|
||||||
|
|
||||||
uniformsBindingIndex = dp::metal::MetalGpuProgram::kInvalidBindingIndex;
|
uniformsBindingIndex = dp::metal::MetalGpuProgram::kInvalidBindingIndex;
|
||||||
|
|
||||||
for (MTLArgument * arg in arguments)
|
for (MTLArgument * arg in arguments)
|
||||||
@@ -163,7 +163,7 @@ void GetBindings(NSArray<MTLArgument *> * arguments, int8_t & uniformsBindingInd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MTLVertexDescriptor * GetVertexDescriptor(id<MTLFunction> vertexShader, ProgramInfo::Layout const & layout)
|
MTLVertexDescriptor * GetVertexDescriptor(id<MTLFunction> vertexShader, ProgramInfo::Layout const & layout)
|
||||||
{
|
{
|
||||||
MTLVertexDescriptor * vertexDesc = [[MTLVertexDescriptor alloc] init];
|
MTLVertexDescriptor * vertexDesc = [[MTLVertexDescriptor alloc] init];
|
||||||
@@ -189,10 +189,10 @@ MTLVertexDescriptor * GetVertexDescriptor(id<MTLFunction> vertexShader, ProgramI
|
|||||||
sizes[bufferIndex] += sz;
|
sizes[bufferIndex] += sz;
|
||||||
attrDesc.bufferIndex = bufferIndex;
|
attrDesc.bufferIndex = bufferIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const & s : sizes)
|
for (auto const & s : sizes)
|
||||||
vertexDesc.layouts[s.first].stride = s.second;
|
vertexDesc.layouts[s.first].stride = s.second;
|
||||||
|
|
||||||
return vertexDesc;
|
return vertexDesc;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -204,19 +204,19 @@ std::string DebugPrint(SystemProgram p)
|
|||||||
case SystemProgram::ClearColor: return "ClearColor";
|
case SystemProgram::ClearColor: return "ClearColor";
|
||||||
case SystemProgram::ClearDepth: return "ClearDepth";
|
case SystemProgram::ClearDepth: return "ClearDepth";
|
||||||
case SystemProgram::ClearColorAndDepth: return "ClearColorAndDepth";
|
case SystemProgram::ClearColorAndDepth: return "ClearColorAndDepth";
|
||||||
|
|
||||||
case SystemProgram::SystemProgramsCount:
|
case SystemProgram::SystemProgramsCount:
|
||||||
CHECK(false, ("Try to output SystemProgramsCount"));
|
CHECK(false, ("Try to output SystemProgramsCount"));
|
||||||
}
|
}
|
||||||
CHECK(false, ("Unknown program"));
|
CHECK(false, ("Unknown program"));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
MetalProgramPool::MetalProgramPool(id<MTLDevice> device)
|
MetalProgramPool::MetalProgramPool(id<MTLDevice> device)
|
||||||
: m_device(device)
|
: m_device(device)
|
||||||
{
|
{
|
||||||
ProgramParams::Init();
|
ProgramParams::Init();
|
||||||
|
|
||||||
NSString * libPath = [[NSBundle mainBundle] pathForResource:@"shaders_metal" ofType:@"metallib"];
|
NSString * libPath = [[NSBundle mainBundle] pathForResource:@"shaders_metal" ofType:@"metallib"];
|
||||||
NSError * error = nil;
|
NSError * error = nil;
|
||||||
m_library = [m_device newLibraryWithFile:libPath error:&error];
|
m_library = [m_device newLibraryWithFile:libPath error:&error];
|
||||||
@@ -238,13 +238,13 @@ drape_ptr<dp::GpuProgram> MetalProgramPool::GetSystemProgram(SystemProgram progr
|
|||||||
auto const & info = kMetalSystemProgramsInfo[static_cast<size_t>(program)];
|
auto const & info = kMetalSystemProgramsInfo[static_cast<size_t>(program)];
|
||||||
return Get(DebugPrint(program), info.m_vertexShaderName, info.m_fragmentShaderName, info.m_layout);
|
return Get(DebugPrint(program), info.m_vertexShaderName, info.m_fragmentShaderName, info.m_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
drape_ptr<dp::GpuProgram> MetalProgramPool::Get(Program program)
|
drape_ptr<dp::GpuProgram> MetalProgramPool::Get(Program program)
|
||||||
{
|
{
|
||||||
auto const & info = kMetalProgramsInfo[static_cast<size_t>(program)];
|
auto const & info = kMetalProgramsInfo[static_cast<size_t>(program)];
|
||||||
return Get(DebugPrint(program), info.m_vertexShaderName, info.m_fragmentShaderName, info.m_layout);
|
return Get(DebugPrint(program), info.m_vertexShaderName, info.m_fragmentShaderName, info.m_layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
drape_ptr<dp::GpuProgram> MetalProgramPool::Get(std::string const & programName,
|
drape_ptr<dp::GpuProgram> MetalProgramPool::Get(std::string const & programName,
|
||||||
std::string const & vertexShaderName,
|
std::string const & vertexShaderName,
|
||||||
std::string const & fragmentShaderName,
|
std::string const & fragmentShaderName,
|
||||||
@@ -252,7 +252,7 @@ drape_ptr<dp::GpuProgram> MetalProgramPool::Get(std::string const & programName,
|
|||||||
{
|
{
|
||||||
CHECK(!vertexShaderName.empty(), ());
|
CHECK(!vertexShaderName.empty(), ());
|
||||||
CHECK(!fragmentShaderName.empty(), ());
|
CHECK(!fragmentShaderName.empty(), ());
|
||||||
|
|
||||||
id<MTLFunction> vertexShader = GetFunction(vertexShaderName);
|
id<MTLFunction> vertexShader = GetFunction(vertexShaderName);
|
||||||
id<MTLFunction> fragmentShader = GetFunction(fragmentShaderName);
|
id<MTLFunction> fragmentShader = GetFunction(fragmentShaderName);
|
||||||
MTLVertexDescriptor * vertexDesc = GetVertexDescriptor(vertexShader, layout);
|
MTLVertexDescriptor * vertexDesc = GetVertexDescriptor(vertexShader, layout);
|
||||||
@@ -264,7 +264,7 @@ drape_ptr<dp::GpuProgram> MetalProgramPool::Get(std::string const & programName,
|
|||||||
desc.vertexDescriptor = vertexDesc;
|
desc.vertexDescriptor = vertexDesc;
|
||||||
desc.vertexFunction = vertexShader;
|
desc.vertexFunction = vertexShader;
|
||||||
desc.fragmentFunction = fragmentShader;
|
desc.fragmentFunction = fragmentShader;
|
||||||
|
|
||||||
NSError * error = nil;
|
NSError * error = nil;
|
||||||
MTLRenderPipelineReflection * reflectionObj = nil;
|
MTLRenderPipelineReflection * reflectionObj = nil;
|
||||||
MTLPipelineOption option = MTLPipelineOptionBufferTypeInfo | MTLPipelineOptionArgumentInfo;
|
MTLPipelineOption option = MTLPipelineOptionBufferTypeInfo | MTLPipelineOptionArgumentInfo;
|
||||||
@@ -277,22 +277,22 @@ drape_ptr<dp::GpuProgram> MetalProgramPool::Get(std::string const & programName,
|
|||||||
NSLog(@"%@", error);
|
NSLog(@"%@", error);
|
||||||
CHECK(false, ("Failed to create reflection pipeline state."));
|
CHECK(false, ("Failed to create reflection pipeline state."));
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t vsUniformsBindingIndex = dp::metal::MetalGpuProgram::kInvalidBindingIndex;
|
int8_t vsUniformsBindingIndex = dp::metal::MetalGpuProgram::kInvalidBindingIndex;
|
||||||
dp::metal::MetalGpuProgram::TexturesBindingInfo vsTextureBindingInfo;
|
dp::metal::MetalGpuProgram::TexturesBindingInfo vsTextureBindingInfo;
|
||||||
GetBindings(reflectionObj.vertexArguments, vsUniformsBindingIndex, vsTextureBindingInfo);
|
GetBindings(reflectionObj.vertexArguments, vsUniformsBindingIndex, vsTextureBindingInfo);
|
||||||
|
|
||||||
int8_t fsUniformsBindingIndex = dp::metal::MetalGpuProgram::kInvalidBindingIndex;
|
int8_t fsUniformsBindingIndex = dp::metal::MetalGpuProgram::kInvalidBindingIndex;
|
||||||
dp::metal::MetalGpuProgram::TexturesBindingInfo fsTextureBindingInfo;
|
dp::metal::MetalGpuProgram::TexturesBindingInfo fsTextureBindingInfo;
|
||||||
GetBindings(reflectionObj.fragmentArguments, fsUniformsBindingIndex, fsTextureBindingInfo);
|
GetBindings(reflectionObj.fragmentArguments, fsUniformsBindingIndex, fsTextureBindingInfo);
|
||||||
|
|
||||||
return make_unique_dp<dp::metal::MetalGpuProgram>(programName, vertexShader, fragmentShader,
|
return make_unique_dp<dp::metal::MetalGpuProgram>(programName, vertexShader, fragmentShader,
|
||||||
vsUniformsBindingIndex, fsUniformsBindingIndex,
|
vsUniformsBindingIndex, fsUniformsBindingIndex,
|
||||||
std::move(vsTextureBindingInfo),
|
std::move(vsTextureBindingInfo),
|
||||||
std::move(fsTextureBindingInfo),
|
std::move(fsTextureBindingInfo),
|
||||||
vertexDesc);
|
vertexDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLFunction> MetalProgramPool::GetFunction(std::string const & name)
|
id<MTLFunction> MetalProgramPool::GetFunction(std::string const & name)
|
||||||
{
|
{
|
||||||
auto const it = m_functions.find(name);
|
auto const it = m_functions.find(name);
|
||||||
|
|||||||
Reference in New Issue
Block a user