diff --git a/src/backend/metal/ShaderModuleMTL.mm b/src/backend/metal/ShaderModuleMTL.mm index ecd921eb88..7f944d8759 100644 --- a/src/backend/metal/ShaderModuleMTL.mm +++ b/src/backend/metal/ShaderModuleMTL.mm @@ -49,6 +49,10 @@ namespace backend { namespace metal { const PipelineLayout* layout) const { spirv_cross::CompilerMSL compiler(mSpirv); + spirv_cross::CompilerGLSL::Options options_glsl; + options_glsl.vertex.flip_vert_y = true; + compiler.spirv_cross::CompilerGLSL::set_options(options_glsl); + // By default SPIRV-Cross will give MSL resources indices in increasing order. // To make the MSL indices match the indices chosen in the PipelineLayout, we build // a table of MSLResourceBinding to give to SPIRV-Cross diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 785f1daab8..de6f59f47e 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -80,6 +80,7 @@ add_executable(nxt_end2end_tests ${END2END_TESTS_DIR}/PrimitiveTopologyTests.cpp ${END2END_TESTS_DIR}/PushConstantTests.cpp ${END2END_TESTS_DIR}/RenderPassLoadOpTests.cpp + ${END2END_TESTS_DIR}/ViewportOrientationTests.cpp ${TESTS_DIR}/End2EndTestsMain.cpp ${TESTS_DIR}/NXTTest.cpp ${TESTS_DIR}/NXTTest.h diff --git a/src/tests/end2end/ViewportOrientationTests.cpp b/src/tests/end2end/ViewportOrientationTests.cpp new file mode 100644 index 0000000000..a8d330e142 --- /dev/null +++ b/src/tests/end2end/ViewportOrientationTests.cpp @@ -0,0 +1,63 @@ +// Copyright 2017 The NXT Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "tests/NXTTest.h" + +#include "utils/NXTHelpers.h" + +class ViewportOrientationTests : public NXTTest {}; + +// Test that the pixel in viewport coordinate (-1, -1) matches texel (0, 0) +TEST_P(ViewportOrientationTests, OriginAt0x0) { + utils::BasicFramebuffer fb = utils::CreateBasicFramebuffer(device, 2, 2); + + nxt::ShaderModule vsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Vertex, R"( + #version 450 + void main() { + gl_Position = vec4(-0.5f, -0.5f, 0.0f, 1.0f); + })" + ); + + nxt::ShaderModule fsModule = utils::CreateShaderModule(device, nxt::ShaderStage::Fragment, R"( + #version 450 + layout(location = 0) out vec4 fragColor; + void main() { + fragColor = vec4(0.0f, 1.0f, 0.0f, 1.0f); + })"); + + nxt::RenderPipeline pipeline = device.CreateRenderPipelineBuilder() + .SetSubpass(fb.renderPass, 0) + .SetStage(nxt::ShaderStage::Vertex, vsModule, "main") + .SetStage(nxt::ShaderStage::Fragment, fsModule, "main") + .SetPrimitiveTopology(nxt::PrimitiveTopology::PointList) + .GetResult(); + + nxt::CommandBuffer commands = device.CreateCommandBufferBuilder() + .BeginRenderPass(fb.renderPass, fb.framebuffer) + .BeginRenderSubpass() + .SetRenderPipeline(pipeline) + .DrawArrays(1, 1, 0, 0) + .EndRenderSubpass() + .EndRenderPass() + .GetResult(); + + queue.Submit(1, &commands); + + EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), fb.color, 0, 0); + EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), fb.color, 0, 1); + EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), fb.color, 1, 0); + EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), fb.color, 1, 1); +} + +NXT_INSTANTIATE_TEST(ViewportOrientationTests, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend)