diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index 035980d16b..3e201e8ee4 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -968,6 +968,19 @@ namespace dawn_native { namespace d3d12 { commandList->OMSetStencilRef(cmd->reference); } break; + case Command::SetViewport: { + SetViewportCmd* cmd = mCommands.NextCommand(); + D3D12_VIEWPORT viewport; + viewport.TopLeftX = cmd->x; + viewport.TopLeftY = cmd->y; + viewport.Width = cmd->width; + viewport.Height = cmd->height; + viewport.MinDepth = cmd->minDepth; + viewport.MaxDepth = cmd->maxDepth; + + commandList->RSSetViewports(1, &viewport); + } break; + case Command::SetScissorRect: { SetScissorRectCmd* cmd = mCommands.NextCommand(); D3D12_RECT rect; diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index f960d94b0c..c6c440ac8c 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -825,6 +825,19 @@ namespace dawn_native { namespace metal { [encoder setStencilReferenceValue:cmd->reference]; } break; + case Command::SetViewport: { + SetViewportCmd* cmd = mCommands.NextCommand(); + MTLViewport viewport; + viewport.originX = cmd->x; + viewport.originY = cmd->y; + viewport.width = cmd->width; + viewport.height = cmd->height; + viewport.znear = cmd->minDepth; + viewport.zfar = cmd->maxDepth; + + [encoder setViewport:viewport]; + } break; + case Command::SetScissorRect: { SetScissorRectCmd* cmd = mCommands.NextCommand(); MTLScissorRect rect; diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index e1035bab11..a67096794b 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -811,8 +811,7 @@ namespace dawn_native { namespace opengl { case Command::SetViewport: { SetViewportCmd* cmd = mCommands.NextCommand(); - gl.Viewport(static_cast(cmd->x), static_cast(cmd->y), - static_cast(cmd->width), static_cast(cmd->height)); + gl.ViewportIndexedf(0, cmd->x, cmd->y, cmd->width, cmd->height); gl.DepthRangef(cmd->minDepth, cmd->maxDepth); } break; diff --git a/src/tests/end2end/ViewportTests.cpp b/src/tests/end2end/ViewportTests.cpp index e2bd9e9dca..42f8ded682 100644 --- a/src/tests/end2end/ViewportTests.cpp +++ b/src/tests/end2end/ViewportTests.cpp @@ -364,4 +364,4 @@ TEST_P(ViewportTest, ShrinkViewportAndShiftToBottomRightAndApplyDepth) { DoTest(info); } -DAWN_INSTANTIATE_TEST(ViewportTest, OpenGLBackend, VulkanBackend); +DAWN_INSTANTIATE_TEST(ViewportTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend);