Make gl_Position(-1, -1) map to texel (0, 0) of the render target

There was a lot of missing around with viewports and flip the Y
coordinate in vertex shaders before. Turns out things are simpler than
we thought: *all* APIs have gl_Position(-1, -1) map to texel (0, 0). It
is just the present coordinate system that changes.

Remove some of the hacks we had to work around non-existent viewport
issues and fix tests.
This commit is contained in:
Corentin Wallez 2018-01-12 14:50:33 -05:00 committed by Corentin Wallez
parent d0d6e5cd20
commit 47155a3555
5 changed files with 18 additions and 18 deletions

View File

@ -23,7 +23,6 @@ namespace backend { namespace d3d12 {
spirv_cross::CompilerHLSL compiler(builder->AcquireSpirv());
spirv_cross::CompilerGLSL::Options options_glsl;
options_glsl.vertex.flip_vert_y = false;
options_glsl.vertex.fixup_clipspace = true;
compiler.spirv_cross::CompilerGLSL::set_options(options_glsl);

View File

@ -56,7 +56,6 @@ namespace backend { namespace opengl {
#else
options.version = 440;
#endif
options.vertex.flip_vert_y = true;
compiler.set_options(options);
// Rename the push constant block to be prefixed with the shader stage type so that uniform

View File

@ -117,7 +117,7 @@ TEST_P(IndexFormatTest, Uint32) {
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 100, 100);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 100, 300);
}
// Test that the Uint16 index format is correctly interpreted
@ -148,7 +148,7 @@ TEST_P(IndexFormatTest, Uint16) {
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 100, 100);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 100, 300);
}
// Test for primitive restart use vertices like in the drawing and draw the following
@ -192,9 +192,9 @@ TEST_P(IndexFormatTest, Uint32PrimitiveRestart) {
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 190, 210); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 210, 190); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderTarget, 210, 210); // C
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderTarget, 210, 190); // C
}
// Test use of primitive restart with an Uint16 index format
@ -226,9 +226,9 @@ TEST_P(IndexFormatTest, Uint16PrimitiveRestart) {
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 190, 210); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 210, 190); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderTarget, 210, 210); // C
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 190, 190); // A
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 210, 210); // B
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 0, 0, 0), renderTarget, 210, 190); // C
}
// Test that the index format used is the format of the last set pipeline. This is to
@ -264,7 +264,7 @@ TEST_P(IndexFormatTest, ChangePipelineAfterSetIndexBuffer) {
queue.Submit(1, &commands);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 100, 100);
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderTarget, 100, 300);
}
NXT_INSTANTIATE_TEST(IndexFormatTest, MetalBackend, OpenGLBackend)

View File

@ -101,7 +101,7 @@ class InputStateTest : public NXTTest {
// Hard code the triangle in the shader so that we don't have to add a vertex input for it.
// Also this places the triangle in the grid based on its VertexID and InstanceID
vs << " const vec2 pos[3] = vec2[3](vec2(0.5f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, 0.0f));\n";
vs << " vec2 offset = vec2(float(gl_VertexIndex / 3), 3 - float(gl_InstanceIndex));\n";
vs << " vec2 offset = vec2(float(gl_VertexIndex / 3), float(gl_InstanceIndex));\n";
vs << " vec2 worldPos = pos[gl_VertexIndex % 3] + offset;\n";
vs << " gl_Position = vec4(worldPos / 2 - vec2(1.0f), 0.0f, 1.0f);\n";

View File

@ -97,6 +97,7 @@ constexpr TestLocation GetCentroid(const TestLocation& a, const TestLocation& b,
return { (a.x + b.x + c.x) / 3, (a.y + b.y + c.y) / 3 };
}
// clang-format off
// Offset towards one corner to avoid x or y symmetry false positives
constexpr static unsigned int kOffset = kRTSize / 8;
@ -132,13 +133,14 @@ constexpr static TestLocation kTriangleStripTestLocations[] = {
constexpr static float kRTSizef = static_cast<float>(kRTSize);
constexpr static float kVertices[] = {
2.f * (kPointTestLocations[0].x + 0.5f) / kRTSizef - 1.f, 1.f - 2.f * (kPointTestLocations[0].y + 0.5f) / kRTSizef, 0.f, 1.f,
2.f * (kPointTestLocations[1].x + 0.5f) / kRTSizef - 1.f, 1.f - 2.f * (kPointTestLocations[1].y + 0.5f) / kRTSizef, 0.f, 1.f,
2.f * (kPointTestLocations[2].x + 0.5f) / kRTSizef - 1.f, 1.f - 2.f * (kPointTestLocations[2].y + 0.5f) / kRTSizef, 0.f, 1.f,
2.f * (kPointTestLocations[3].x + 0.5f) / kRTSizef - 1.f, 1.f - 2.f * (kPointTestLocations[3].y + 0.5f) / kRTSizef, 0.f, 1.f,
2.f * (kPointTestLocations[4].x + 0.5f) / kRTSizef - 1.f, 1.f - 2.f * (kPointTestLocations[4].y + 0.5f) / kRTSizef, 0.f, 1.f,
2.f * (kPointTestLocations[5].x + 0.5f) / kRTSizef - 1.f, 1.f - 2.f * (kPointTestLocations[5].y + 0.5f) / kRTSizef, 0.f, 1.f,
2.f * (kPointTestLocations[0].x + 0.5f) / kRTSizef - 1.f, 2.f * (kPointTestLocations[0].y + 0.5f) / kRTSizef - 1.0f, 0.f, 1.f,
2.f * (kPointTestLocations[1].x + 0.5f) / kRTSizef - 1.f, 2.f * (kPointTestLocations[1].y + 0.5f) / kRTSizef - 1.0f, 0.f, 1.f,
2.f * (kPointTestLocations[2].x + 0.5f) / kRTSizef - 1.f, 2.f * (kPointTestLocations[2].y + 0.5f) / kRTSizef - 1.0f, 0.f, 1.f,
2.f * (kPointTestLocations[3].x + 0.5f) / kRTSizef - 1.f, 2.f * (kPointTestLocations[3].y + 0.5f) / kRTSizef - 1.0f, 0.f, 1.f,
2.f * (kPointTestLocations[4].x + 0.5f) / kRTSizef - 1.f, 2.f * (kPointTestLocations[4].y + 0.5f) / kRTSizef - 1.0f, 0.f, 1.f,
2.f * (kPointTestLocations[5].x + 0.5f) / kRTSizef - 1.f, 2.f * (kPointTestLocations[5].y + 0.5f) / kRTSizef - 1.0f, 0.f, 1.f,
};
// clang-format on
class PrimitiveTopologyTest : public NXTTest {
protected: