From 49feffb4b6a4d47482e095b7aa59634b1ce1902e Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Wed, 1 Sep 2010 17:10:51 -0400 Subject: [PATCH] Bug 589395. d3d9: adjust vertex locations in the vertex shader. r=bas,a=blocking Previously we adjusted the vertex locations directly, now they have an implicit adjustment that happens in the vertex shader. This should let us ignore the pixel center differences between opengl/d3d9/d3d10. --- gfx/layers/d3d9/CanvasLayerD3D9.cpp | 6 +-- gfx/layers/d3d9/ContainerLayerD3D9.cpp | 4 +- gfx/layers/d3d9/ImageLayerD3D9.cpp | 8 ++-- gfx/layers/d3d9/LayerManagerD3D9Shaders.h | 40 ++++++++++++-------- gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl | 6 +++ gfx/layers/d3d9/ThebesLayerD3D9.cpp | 4 +- 6 files changed, 41 insertions(+), 27 deletions(-) diff --git a/gfx/layers/d3d9/CanvasLayerD3D9.cpp b/gfx/layers/d3d9/CanvasLayerD3D9.cpp index 12057ecb77cc..b34a45ed4968 100644 --- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp +++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp @@ -218,13 +218,13 @@ CanvasLayerD3D9::RenderLayer() quadTransform[0][0] = (float)mBounds.width; if (mNeedsYFlip) { quadTransform[1][1] = (float)-mBounds.height; - quadTransform[3][1] = (float)mBounds.height - 0.5f; + quadTransform[3][1] = (float)mBounds.height; } else { quadTransform[1][1] = (float)mBounds.height; - quadTransform[3][1] = -0.5f; + quadTransform[3][1] = 0.0f; } quadTransform[2][2] = 1.0f; - quadTransform[3][0] = -0.5f; + quadTransform[3][0] = 0.0f; quadTransform[3][3] = 1.0f; device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4); diff --git a/gfx/layers/d3d9/ContainerLayerD3D9.cpp b/gfx/layers/d3d9/ContainerLayerD3D9.cpp index 8f1b2a708b45..5ed9eee70f38 100644 --- a/gfx/layers/d3d9/ContainerLayerD3D9.cpp +++ b/gfx/layers/d3d9/ContainerLayerD3D9.cpp @@ -239,8 +239,8 @@ ContainerLayerD3D9::RenderLayer() quadTransform[0][0] = (float)visibleRect.width; quadTransform[1][1] = (float)visibleRect.height; quadTransform[2][2] = 1.0f; - quadTransform[3][0] = (float)visibleRect.x - 0.5f; - quadTransform[3][1] = (float)visibleRect.y - 0.5f; + quadTransform[3][0] = (float)visibleRect.x; + quadTransform[3][1] = (float)visibleRect.y; quadTransform[3][3] = 1.0f; device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4); diff --git a/gfx/layers/d3d9/ImageLayerD3D9.cpp b/gfx/layers/d3d9/ImageLayerD3D9.cpp index d19596d3a28d..f10f87c7171e 100644 --- a/gfx/layers/d3d9/ImageLayerD3D9.cpp +++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp @@ -172,8 +172,8 @@ ImageLayerD3D9::RenderLayer() * beyond all edges. */ memset(&quadTransform, 0, sizeof(quadTransform)); - quadTransform[0][0] = (float)yuvImage->mSize.width + 0.5f; - quadTransform[1][1] = (float)yuvImage->mSize.height + 0.5f; + quadTransform[0][0] = (float)yuvImage->mSize.width; + quadTransform[1][1] = (float)yuvImage->mSize.height; quadTransform[2][2] = 1.0f; quadTransform[3][3] = 1.0f; @@ -226,8 +226,8 @@ ImageLayerD3D9::RenderLayer() * beyond all edges. */ memset(&quadTransform, 0, sizeof(quadTransform)); - quadTransform[0][0] = (float)cairoImage->mSize.width + 0.5f; - quadTransform[1][1] = (float)cairoImage->mSize.height + 0.5f; + quadTransform[0][0] = (float)cairoImage->mSize.width; + quadTransform[1][1] = (float)cairoImage->mSize.height; quadTransform[2][2] = 1.0f; quadTransform[3][3] = 1.0f; diff --git a/gfx/layers/d3d9/LayerManagerD3D9Shaders.h b/gfx/layers/d3d9/LayerManagerD3D9Shaders.h index 19e5d893e393..7201f070f275 100644 --- a/gfx/layers/d3d9/LayerManagerD3D9Shaders.h +++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.h @@ -25,6 +25,7 @@ // vs_2_0 + def c13, -0.5, 0, 0, 0 dcl_position v0 mul r0, v0.y, c1 mad r0, c0, v0.x, r0 @@ -35,13 +36,14 @@ mad r1, c6, r0.z, r1 mad r0, c7, r0.w, r1 add r0, r0, -c12 + add r0.xy, r0, c13.x mul r1, r0.y, c9 mad r1, c8, r0.x, r1 mad r1, c10, r0.z, r1 mad oPos, c11, r0.w, r1 mov oT0.xy, v0 -// approximately 14 instruction slots used +// approximately 15 instruction slots used #endif const BYTE LayerQuadVS[] = @@ -92,6 +94,10 @@ const BYTE LayerQuadVS[] = 108, 101, 114, 32, 57, 46, 50, 57, 46, 57, 53, 50, 46, 51, 49, 49, 49, 0, + 81, 0, 0, 5, 13, 0, + 15, 160, 0, 0, 0, 191, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 31, 0, 0, 2, 0, 0, 0, 128, 0, 0, 15, 144, 5, 0, 0, 3, 0, 0, @@ -122,22 +128,24 @@ const BYTE LayerQuadVS[] = 228, 128, 2, 0, 0, 3, 0, 0, 15, 128, 0, 0, 228, 128, 12, 0, 228, 161, - 5, 0, 0, 3, 1, 0, - 15, 128, 0, 0, 85, 128, - 9, 0, 228, 160, 4, 0, + 2, 0, 0, 3, 0, 0, + 3, 128, 0, 0, 228, 128, + 13, 0, 0, 160, 5, 0, + 0, 3, 1, 0, 15, 128, + 0, 0, 85, 128, 9, 0, + 228, 160, 4, 0, 0, 4, + 1, 0, 15, 128, 8, 0, + 228, 160, 0, 0, 0, 128, + 1, 0, 228, 128, 4, 0, 0, 4, 1, 0, 15, 128, - 8, 0, 228, 160, 0, 0, - 0, 128, 1, 0, 228, 128, - 4, 0, 0, 4, 1, 0, - 15, 128, 10, 0, 228, 160, - 0, 0, 170, 128, 1, 0, - 228, 128, 4, 0, 0, 4, - 0, 0, 15, 192, 11, 0, - 228, 160, 0, 0, 255, 128, - 1, 0, 228, 128, 1, 0, - 0, 2, 0, 0, 3, 224, - 0, 0, 228, 144, 255, 255, - 0, 0 + 10, 0, 228, 160, 0, 0, + 170, 128, 1, 0, 228, 128, + 4, 0, 0, 4, 0, 0, + 15, 192, 11, 0, 228, 160, + 0, 0, 255, 128, 1, 0, + 228, 128, 1, 0, 0, 2, + 0, 0, 3, 224, 0, 0, + 228, 144, 255, 255, 0, 0 }; #if 0 // diff --git a/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl b/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl index ef9eed7e0e11..0bbba3c216ed 100644 --- a/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl +++ b/gfx/layers/d3d9/LayerManagerD3D9Shaders.hlsl @@ -28,7 +28,13 @@ VS_OUTPUT LayerQuadVS(const VS_INPUT aVertex) outp.vPosition = mul(mLayerQuadTransform, outp.vPosition); outp.vPosition = mul(mLayerTransform, outp.vPosition); outp.vPosition = outp.vPosition - vRenderTargetOffset; + + // adjust our vertices to match d3d9's pixel coordinate system + // which has pixel centers at integer locations + outp.vPosition.xy -= 0.5; + outp.vPosition = mul(mProjection, outp.vPosition); + outp.vTexCoords = aVertex.vPosition.xy; return outp; } diff --git a/gfx/layers/d3d9/ThebesLayerD3D9.cpp b/gfx/layers/d3d9/ThebesLayerD3D9.cpp index 786b2fb5aad0..2c567b987577 100644 --- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp +++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp @@ -239,8 +239,8 @@ ThebesLayerD3D9::RenderLayer() quadTransform[0][0] = (float)visibleRect.width; quadTransform[1][1] = (float)visibleRect.height; quadTransform[2][2] = 1.0f; - quadTransform[3][0] = (float)visibleRect.x - 0.5f; - quadTransform[3][1] = (float)visibleRect.y - 0.5f; + quadTransform[3][0] = (float)visibleRect.x; + quadTransform[3][1] = (float)visibleRect.y; quadTransform[3][3] = 1.0f; device()->SetVertexShaderConstantF(0, &quadTransform[0][0], 4);