Fix clip space on D3D12 and OpenGL

The range of the Z-coordinate in clipping volume is [-w, w] on OpenGL,
while it is [0, w] on D3D12, Metal and Vulkan.

In this patch, the "fixup_clipspace" flag of SPIRV-Cross is enabled on
OpenGL backend and disabled on D3D12 backend to unify the behaviour of
clip space on all Dawn backends. An end2end test is also added for this
fix.

This patch also fix a bug when clearing depth stencil attachments on
OpenGL backend. Before clearing depth stencil attachments, we should
enable depth stencil writing by properly setting depth and stencil
masks. We do not need to set the depth and stencil masks back because
they will be set again when applying the render pipeline. The newly
added test will fail without this fix when running the test together
with all the end2ends.

BUG=dawn:122
TEST=dawn_end2end_tests

Change-Id: I4f50ce3eb1f16d731ee4cffc12a56e17844b4675
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5860
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao
2019-03-27 00:01:33 +00:00
committed by Commit Bot service account
parent 91e949292f
commit 5490e9aca1
7 changed files with 126 additions and 2 deletions

View File

@@ -54,6 +54,12 @@ namespace dawn_native { namespace opengl {
// updated.
spirv_cross::CompilerGLSL::Options options;
// The range of Z-coordinate in the clipping volume of OpenGL is [-w, w], while it is [0, w]
// in D3D12, Metal and Vulkan, so we should normalize it in shaders in all backends.
// See the documentation of spirv_cross::CompilerGLSL::Options::vertex::fixup_clipspace for
// more details.
options.vertex.fixup_clipspace = true;
// TODO(cwallez@chromium.org): discover the backing context version and use that.
#if defined(DAWN_PLATFORM_APPLE)
options.version = 410;