Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Metal:Reset Encoder viewport and scissor rect in case the command specifies no opinion #34252

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -429,28 +429,28 @@ static bool Bind(PassBindingsCache& pass,
: MTLWindingCounterClockwise];
[encoder setCullMode:ToMTLCullMode(command.cull_mode)];
[encoder setStencilReferenceValue:command.stencil_reference];
if (command.viewport.has_value()) {
auto v = command.viewport.value();
MTLViewport viewport = {
.originX = v.rect.origin.x,
.originY = v.rect.origin.y,
.width = v.rect.size.width,
.height = v.rect.size.height,
.znear = v.depth_range.z_near,
.zfar = v.depth_range.z_far,
};
[encoder setViewport:viewport];
}
if (command.scissor.has_value()) {
auto s = command.scissor.value();
MTLScissorRect scissor = {
.x = static_cast<NSUInteger>(s.origin.x),
.y = static_cast<NSUInteger>(s.origin.y),
.width = static_cast<NSUInteger>(s.size.width),
.height = static_cast<NSUInteger>(s.size.height),
};
[encoder setScissorRect:scissor];
}

auto v = command.viewport.value_or<Viewport>(
{.rect = Rect::MakeSize(Size(GetRenderTargetSize()))});
MTLViewport viewport = {
.originX = v.rect.origin.x,
.originY = v.rect.origin.y,
.width = v.rect.size.width,
.height = v.rect.size.height,
.znear = v.depth_range.z_near,
.zfar = v.depth_range.z_far,
};
[encoder setViewport:viewport];

auto s = command.scissor.value_or(IRect::MakeSize(GetRenderTargetSize()));
MTLScissorRect scissor = {
.x = static_cast<NSUInteger>(s.origin.x),
.y = static_cast<NSUInteger>(s.origin.y),
.width = static_cast<NSUInteger>(s.size.width),
.height = static_cast<NSUInteger>(s.size.height),
};
[encoder setScissorRect:scissor];

if (!bind_stage_resources(command.vertex_bindings, ShaderStage::kVertex)) {
return false;
}
Expand Down