Blit11 can now blit depth stencils.

TRAC #23321

Signed-off-by: Jamie Madill
Signed-off-by: Shannon Woods
Author: Geoff Lang
diff --git a/src/libGLESv2/libGLESv2.vcxproj b/src/libGLESv2/libGLESv2.vcxproj
index c348d9e..f4c46bc 100644
--- a/src/libGLESv2/libGLESv2.vcxproj
+++ b/src/libGLESv2/libGLESv2.vcxproj
@@ -390,6 +390,7 @@
     <ClInclude Include="renderer\shaders\compiled\passthrough2d11vs.h" />

     <ClInclude Include="renderer\shaders\compiled\passthrough3d11gs.h" />

     <ClInclude Include="renderer\shaders\compiled\passthrough3d11vs.h" />

+    <ClInclude Include="renderer\shaders\compiled\passthroughdepth2d11ps.h" />

     <ClInclude Include="renderer\shaders\compiled\passthroughlum2d11ps.h" />

     <ClInclude Include="renderer\shaders\compiled\passthroughlum3d11ps.h" />

     <ClInclude Include="renderer\shaders\compiled\passthroughlumalpha2d11ps.h" />

diff --git a/src/libGLESv2/libGLESv2.vcxproj.filters b/src/libGLESv2/libGLESv2.vcxproj.filters
index 9f216fc..6fbe0e8 100644
--- a/src/libGLESv2/libGLESv2.vcxproj.filters
+++ b/src/libGLESv2/libGLESv2.vcxproj.filters
@@ -613,6 +613,9 @@
     <ClInclude Include="renderer\shaders\compiled\passthroughrg2d11ps.h">

       <Filter>Shaders\Compiled</Filter>

     </ClInclude>

+    <ClInclude Include="renderer\shaders\compiled\passthroughdepth2d11ps.h">

+      <Filter>Shaders\Compiled</Filter>

+    </ClInclude>

   </ItemGroup>

   <ItemGroup>

     <None Include="renderer\shaders\Blit.ps">

diff --git a/src/libGLESv2/renderer/Blit11.cpp b/src/libGLESv2/renderer/Blit11.cpp
index 7c1c388..1ad5c3a 100644
--- a/src/libGLESv2/renderer/Blit11.cpp
+++ b/src/libGLESv2/renderer/Blit11.cpp
@@ -15,6 +15,7 @@
 #include "libGLESv2/renderer/formatutils11.h"
 
 #include "libGLESv2/renderer/shaders/compiled/passthrough2d11vs.h"
+#include "libGLESv2/renderer/shaders/compiled/passthroughdepth2d11ps.h"
 #include "libGLESv2/renderer/shaders/compiled/passthroughrgba2d11ps.h"
 #include "libGLESv2/renderer/shaders/compiled/passthroughrgba2dui11ps.h"
 #include "libGLESv2/renderer/shaders/compiled/passthroughrgba2di11ps.h"
@@ -52,7 +53,8 @@
 
 Blit11::Blit11(rx::Renderer11 *renderer)
     : mRenderer(renderer), mShaderMap(compareBlitParameters), mVertexBuffer(NULL),
-      mPointSampler(NULL), mLinearSampler(NULL), mQuad2DIL(NULL), mQuad2DVS(NULL),
+      mPointSampler(NULL), mLinearSampler(NULL), mRasterizerState(NULL), mDepthStencilState(NULL),
+      mQuad2DIL(NULL), mQuad2DVS(NULL), mDepthPS(NULL),
       mQuad3DIL(NULL), mQuad3DVS(NULL), mQuad3DGS(NULL)
 {
     HRESULT result;
@@ -126,6 +128,26 @@
     ASSERT(SUCCEEDED(result));
     d3d11::SetDebugName(mRasterizerState, "Blit11 rasterizer state");
 
+    D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
+    depthStencilDesc.DepthEnable = true;
+    depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
+    depthStencilDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
+    depthStencilDesc.StencilEnable = FALSE;
+    depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
+    depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
+    depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
+    depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
+    depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
+
+    result = device->CreateDepthStencilState(&depthStencilDesc, &mDepthStencilState);
+    ASSERT(SUCCEEDED(result));
+    d3d11::SetDebugName(mDepthStencilState, "Blit11 depth stencil state");
+
     D3D11_INPUT_ELEMENT_DESC quad2DLayout[] =
     {
         { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
@@ -140,6 +162,10 @@
     ASSERT(SUCCEEDED(result));
     d3d11::SetDebugName(mQuad2DVS, "Blit11 2D vertex shader");
 
+    result = device->CreatePixelShader(g_PS_PassthroughDepth2D, ArraySize(g_PS_PassthroughDepth2D), NULL, &mDepthPS);
+    ASSERT(SUCCEEDED(result));
+    d3d11::SetDebugName(mDepthPS, "Blit11 2D depth pixel shader");
+
     D3D11_INPUT_ELEMENT_DESC quad3DLayout[] =
     {
         { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT,    0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
@@ -168,9 +194,11 @@
     SafeRelease(mPointSampler);
     SafeRelease(mLinearSampler);
     SafeRelease(mRasterizerState);
+    SafeRelease(mDepthStencilState);
 
     SafeRelease(mQuad2DIL);
     SafeRelease(mQuad2DVS);
+    SafeRelease(mDepthPS);
 
     SafeRelease(mQuad3DIL);
     SafeRelease(mQuad3DVS);
@@ -298,19 +326,63 @@
     return true;
 }
 
-bool Blit11::compareBlitParameters(const Blit11::BlitParameters &a, const Blit11::BlitParameters &b)
+static ID3D11Resource *createStagingTexture(ID3D11Device *device, ID3D11DeviceContext *context,
+                                            ID3D11Resource *source, unsigned int subresource,
+                                            const gl::Extents &size, unsigned int cpuAccessFlags)
 {
-    return memcmp(&a, &b, sizeof(Blit11::BlitParameters)) < 0;
+    ID3D11Texture2D *sourceTexture = d3d11::DynamicCastComObject<ID3D11Texture2D>(source);
+    if (!sourceTexture)
+    {
+        return NULL;
+    }
+
+    D3D11_TEXTURE2D_DESC sourceDesc;
+    sourceTexture->GetDesc(&sourceDesc);
+
+    if (sourceDesc.SampleDesc.Count > 1)
+    {
+        // Creating a staging texture of a multisampled texture is not supported
+        SafeRelease(sourceTexture);
+        return NULL;
+    }
+
+    D3D11_TEXTURE2D_DESC stagingDesc;
+    stagingDesc.Width = size.width;
+    stagingDesc.Height = size.height;
+    stagingDesc.MipLevels = 1;
+    stagingDesc.ArraySize = 1;
+    stagingDesc.Format = sourceDesc.Format;
+    stagingDesc.SampleDesc.Count = 1;
+    stagingDesc.SampleDesc.Quality = 0;
+    stagingDesc.Usage = D3D11_USAGE_STAGING;
+    stagingDesc.CPUAccessFlags = cpuAccessFlags;
+    stagingDesc.MiscFlags = 0;
+    stagingDesc.BindFlags = 0;
+
+    SafeRelease(sourceTexture);
+
+    ID3D11Texture2D *stagingTexture = NULL;
+    HRESULT result = device->CreateTexture2D(&stagingDesc, NULL, &stagingTexture);
+
+    context->CopySubresourceRegion(stagingTexture, 0, 0, 0, 0, source, subresource, NULL);
+
+    return stagingTexture;
 }
 
-template <unsigned int N>
-static ID3D11PixelShader *compilePS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name)
+static DXGI_FORMAT getTextureFormat(ID3D11Resource *resource)
 {
-    ID3D11PixelShader *ps = NULL;
-    HRESULT result = device->CreatePixelShader(byteCode, N, NULL, &ps);
-    ASSERT(SUCCEEDED(result));
-    d3d11::SetDebugName(ps, name);
-    return ps;
+    ID3D11Texture2D *texture = d3d11::DynamicCastComObject<ID3D11Texture2D>(resource);
+    if (!texture)
+    {
+        return DXGI_FORMAT_UNKNOWN;
+    }
+
+    D3D11_TEXTURE2D_DESC desc;
+    texture->GetDesc(&desc);
+
+    SafeRelease(texture);
+
+    return desc.Format;
 }
 
 inline static void generateVertexCoords(const gl::Box &sourceArea, const gl::Extents &sourceSize,
@@ -377,6 +449,205 @@
     *outTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
 }
 
+bool Blit11::copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                         ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize)
+{
+    return copyDepthStencil(source, sourceSubresource, sourceArea, sourceSize,
+                            dest, destSubresource, destArea, destSize,
+                            true);
+}
+
+bool Blit11::copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                       ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize)
+{
+    HRESULT result;
+    ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
+
+    // Set vertices
+    D3D11_MAPPED_SUBRESOURCE mappedResource;
+    result = deviceContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
+    if (FAILED(result))
+    {
+        ERR("Failed to map vertex buffer for texture copy, HRESULT: 0x%X.", result);
+        return false;
+    }
+
+    UINT stride = 0;
+    UINT startIdx = 0;
+    UINT drawCount = 0;
+    D3D11_PRIMITIVE_TOPOLOGY topology;
+
+    write2DVertices(sourceArea, sourceSize, destArea, destSize, mappedResource.pData,
+                    &stride, &drawCount, &topology);
+
+    deviceContext->Unmap(mVertexBuffer, 0);
+
+    // Apply vertex buffer
+    deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx);
+
+    // Apply state
+    deviceContext->OMSetBlendState(NULL, NULL, 0xFFFFFFF);
+    deviceContext->OMSetDepthStencilState(mDepthStencilState, 0xFFFFFFFF);
+    deviceContext->RSSetState(mRasterizerState);
+
+    // Apply shaders
+    deviceContext->IASetInputLayout(mQuad2DIL);
+    deviceContext->IASetPrimitiveTopology(topology);
+    deviceContext->VSSetShader(mQuad2DVS, NULL, 0);
+
+    deviceContext->PSSetShader(mDepthPS, NULL, 0);
+    deviceContext->GSSetShader(NULL, NULL, 0);
+
+    // Unset the currently bound shader resource to avoid conflicts
+    ID3D11ShaderResourceView *const nullSRV = NULL;
+    deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+
+    // Apply render target
+    deviceContext->OMSetRenderTargets(0, NULL, dest);
+
+    // Set the viewport
+    D3D11_VIEWPORT viewport;
+    viewport.TopLeftX = 0;
+    viewport.TopLeftY = 0;
+    viewport.Width = destSize.width;
+    viewport.Height = destSize.height;
+    viewport.MinDepth = 0.0f;
+    viewport.MaxDepth = 1.0f;
+    deviceContext->RSSetViewports(1, &viewport);
+
+    // Apply textures
+    deviceContext->PSSetShaderResources(0, 1, &source);
+
+    // Apply samplers
+    deviceContext->PSSetSamplers(0, 1, &mPointSampler);
+
+    // Draw the quad
+    deviceContext->Draw(drawCount, 0);
+
+    // Unbind textures and render targets and vertex buffer
+    deviceContext->PSSetShaderResources(0, 1, &nullSRV);
+
+    mRenderer->unapplyRenderTargets();
+
+    UINT zero = 0;
+    ID3D11Buffer *const nullBuffer = NULL;
+    deviceContext->IASetVertexBuffers(0, 1, &nullBuffer, &zero, &zero);
+
+    mRenderer->markAllStateDirty();
+
+    return true;
+}
+
+bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                              ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize)
+{
+    return copyDepthStencil(source, sourceSubresource, sourceArea, sourceSize,
+                            dest, destSubresource, destArea, destSize,
+                            false);
+}
+
+bool Blit11::copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                              ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
+                              bool stencilOnly)
+{
+    ID3D11Device *device = mRenderer->getDevice();
+    ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
+
+    ID3D11Resource *sourceStaging = createStagingTexture(device, deviceContext, source, sourceSubresource, sourceSize, D3D11_CPU_ACCESS_READ);
+    ID3D11Resource *destStaging = createStagingTexture(device, deviceContext, dest, destSubresource, destSize, D3D11_CPU_ACCESS_WRITE);
+
+    DXGI_FORMAT format = getTextureFormat(source);
+    ASSERT(format == getTextureFormat(dest));
+
+    unsigned int pixelSize = d3d11::GetFormatPixelBytes(format);
+    unsigned int copyOffset = 0;
+    unsigned int copySize = pixelSize;
+    if (stencilOnly)
+    {
+        copyOffset = d3d11::GetStencilOffset(format) / 8;
+        copySize = d3d11::GetStencilBits(format) / 8;
+
+        // It would be expensive to have non-byte sized stencil sizes since it would
+        // require reading from the destination, currently there arn't any though.
+        ASSERT(d3d11::GetStencilBits(format)   % 8 == 0 &&
+               d3d11::GetStencilOffset(format) % 8 == 0);
+    }
+
+    D3D11_MAPPED_SUBRESOURCE sourceMapping, destMapping;
+    deviceContext->Map(sourceStaging, 0, D3D11_MAP_READ, 0, &sourceMapping);
+    deviceContext->Map(destStaging, 0, D3D11_MAP_WRITE, 0, &destMapping);
+
+    int startDestY = std::min(destArea.y, destArea.y + destArea.height);
+    int endDestY = std::max(destArea.y, destArea.y + destArea.height);
+
+    int startDestX = std::min(destArea.x, destArea.x + destArea.width);
+    int endDestX = std::max(destArea.x, destArea.x + destArea.width);
+
+    for (int y = startDestY; y < endDestY; y++)
+    {
+        float yPerc = static_cast<float>(y - startDestY) / (endDestY - startDestY - 1);
+        unsigned int readRow = sourceArea.y + yPerc * sourceArea.height;
+        unsigned int writeRow = y;
+
+        if (sourceArea.width == destArea.width && copySize == pixelSize)
+        {
+            void *sourceRow = reinterpret_cast<char*>(sourceMapping.pData) +
+                              readRow * sourceMapping.RowPitch;
+
+            void *destRow = reinterpret_cast<char*>(destMapping.pData) +
+                            writeRow * destMapping.RowPitch;
+
+            memcpy(destRow, sourceRow, pixelSize * destArea.width);
+        }
+        else
+        {
+            for (int x = startDestX; x < endDestX; x++)
+            {
+                float xPerc = static_cast<float>(x - startDestX) / (endDestX - startDestX - 1);
+                unsigned int readColumn = sourceArea.x + xPerc * sourceArea.width;
+                unsigned int writeColumn = x;
+
+                void *sourcePixel = reinterpret_cast<char*>(sourceMapping.pData) +
+                                    readRow * sourceMapping.RowPitch +
+                                    readColumn * pixelSize +
+                                    copyOffset;
+
+                void *destPixel = reinterpret_cast<char*>(destMapping.pData) +
+                                  writeRow * destMapping.RowPitch +
+                                  writeColumn * pixelSize +
+                                  copyOffset;
+
+                memcpy(destPixel, sourcePixel, copySize);
+            }
+        }
+    }
+
+    deviceContext->Unmap(sourceStaging, 0);
+    deviceContext->Unmap(destStaging, 0);
+
+    deviceContext->CopySubresourceRegion(dest, destSubresource, 0, 0, 0, destStaging, 0, NULL);
+
+    SafeRelease(sourceStaging);
+    SafeRelease(destStaging);
+
+    return true;
+}
+
+bool Blit11::compareBlitParameters(const Blit11::BlitParameters &a, const Blit11::BlitParameters &b)
+{
+    return memcmp(&a, &b, sizeof(Blit11::BlitParameters)) < 0;
+}
+
+template <unsigned int N>
+static ID3D11PixelShader *compilePS(ID3D11Device *device, const BYTE (&byteCode)[N], const char *name)
+{
+    ID3D11PixelShader *ps = NULL;
+    HRESULT result = device->CreatePixelShader(byteCode, N, NULL, &ps);
+    ASSERT(SUCCEEDED(result));
+    d3d11::SetDebugName(ps, name);
+    return ps;
+}
+
 void Blit11::add2DShaderToMap(GLenum destFormat, bool signedInteger, ID3D11PixelShader *ps)
 {
     BlitParameters params = { 0 };
diff --git a/src/libGLESv2/renderer/Blit11.h b/src/libGLESv2/renderer/Blit11.h
index 2ebb7e5..49468df 100644
--- a/src/libGLESv2/renderer/Blit11.h
+++ b/src/libGLESv2/renderer/Blit11.h
@@ -32,6 +32,15 @@
                      ID3D11RenderTargetView *dest, const gl::Box &destArea, const gl::Extents &destSize,
                      GLenum destFormat, GLenum filter);
 
+    bool copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                     ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize);
+
+    bool copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                   ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize);
+
+    bool copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                          ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize);
+
   private:
     rx::Renderer11 *mRenderer;
 
@@ -42,6 +51,10 @@
         bool m3DBlit;
     };
 
+    bool copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
+                          ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
+                          bool stencilOnly);
+
     static bool compareBlitParameters(const BlitParameters &a, const BlitParameters &b);
 
     typedef void (*WriteVertexFunction)(const gl::Box &sourceArea, const gl::Extents &sourceSize,
@@ -72,9 +85,11 @@
     ID3D11SamplerState *mPointSampler;
     ID3D11SamplerState *mLinearSampler;
     ID3D11RasterizerState *mRasterizerState;
+    ID3D11DepthStencilState *mDepthStencilState;
 
     ID3D11InputLayout *mQuad2DIL;
     ID3D11VertexShader *mQuad2DVS;
+    ID3D11PixelShader *mDepthPS;
 
     ID3D11InputLayout *mQuad3DIL;
     ID3D11VertexShader *mQuad3DVS;
diff --git a/src/libGLESv2/renderer/Renderer11.cpp b/src/libGLESv2/renderer/Renderer11.cpp
index ce2d811..d475b04 100644
--- a/src/libGLESv2/renderer/Renderer11.cpp
+++ b/src/libGLESv2/renderer/Renderer11.cpp
@@ -3295,6 +3295,11 @@
 bool Renderer11::blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget,
                                       RenderTarget *drawRenderTarget, GLenum filter, bool colorBlit, bool depthBlit, bool stencilBlit)
 {
+    // Since blitRenderbufferRect is called for each render buffer that needs to be blitted,
+    // it should never be the case that both color and depth/stencil need to be blitted at
+    // at the same time.
+    ASSERT(colorBlit != (depthBlit || stencilBlit));
+
     bool result = true;
 
     RenderTarget11 *readRenderTarget11 = RenderTarget11::makeRenderTarget11(readRenderTarget);
@@ -3388,9 +3393,19 @@
         gl::Box drawArea(drawRect.x, drawRect.y, 0, drawRect.width, drawRect.height, 1);
         gl::Extents drawSize(drawRenderTarget->getWidth(), drawRenderTarget->getHeight(), 1);
 
-        if (depthBlit || stencilBlit)
+        if (depthBlit && stencilBlit)
         {
-            UNIMPLEMENTED();
+            result = mBlit->copyDepthStencil(readTexture, readSubresource, readArea, readSize,
+                                             drawTexture, drawSubresource, drawArea, drawSize);
+        }
+        else if (depthBlit)
+        {
+            result = mBlit->copyDepth(readSRV, readArea, readSize, drawDSV, drawArea, drawSize);
+        }
+        else if (stencilBlit)
+        {
+            result = mBlit->copyStencil(readTexture, readSubresource, readArea, readSize,
+                                        drawTexture, drawSubresource, drawArea, drawSize);
         }
         else
         {
diff --git a/src/libGLESv2/renderer/shaders/Passthrough2D11.hlsl b/src/libGLESv2/renderer/shaders/Passthrough2D11.hlsl
index 046b46d..8671c39 100644
--- a/src/libGLESv2/renderer/shaders/Passthrough2D11.hlsl
+++ b/src/libGLESv2/renderer/shaders/Passthrough2D11.hlsl
@@ -11,6 +11,11 @@
     outTexCoord = inTexCoord;
 }
 
+float PS_PassthroughDepth2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_DEPTH
+{
+    return TextureF.Sample(Sampler, inTexCoord).r;
+}
+
 float4 PS_PassthroughRGBA2D(in float4 inPosition : SV_POSITION, in float2 inTexCoord : TEXCOORD0) : SV_TARGET0
 {
     return TextureF.Sample(Sampler, inTexCoord).rgba;
diff --git a/src/libGLESv2/renderer/shaders/compiled/passthroughdepth2d11ps.h b/src/libGLESv2/renderer/shaders/compiled/passthroughdepth2d11ps.h
new file mode 100644
index 0000000..33e019c
--- /dev/null
+++ b/src/libGLESv2/renderer/shaders/compiled/passthroughdepth2d11ps.h
@@ -0,0 +1,149 @@
+#if 0

+//

+// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111

+//

+//

+//   fxc /E PS_PassthroughDepth2D /T ps_4_0 /Fh

+//    compiled/passthroughdepth2d11ps.h Passthrough2D11.hlsl

+//

+//

+// Resource Bindings:

+//

+// Name                                 Type  Format         Dim Slot Elements

+// ------------------------------ ---------- ------- ----------- ---- --------

+// Sampler                           sampler      NA          NA    0        1

+// TextureF                          texture  float4          2d    0        1

+//

+//

+//

+// Input signature:

+//

+// Name                 Index   Mask Register SysValue Format   Used

+// -------------------- ----- ------ -------- -------- ------ ------

+// SV_POSITION              0   xyzw        0      POS  float       

+// TEXCOORD                 0   xy          1     NONE  float   xy  

+//

+//

+// Output signature:

+//

+// Name                 Index   Mask Register SysValue Format   Used

+// -------------------- ----- ------ -------- -------- ------ ------

+// SV_DEPTH                 0    N/A   oDepth    DEPTH  float    YES

+//

+ps_4_0

+dcl_sampler s0, mode_default

+dcl_resource_texture2d (float,float,float,float) t0

+dcl_input_ps linear v1.xy

+dcl_output oDepth

+dcl_temps 1

+sample r0.xyzw, v1.xyxx, t0.xyzw, s0

+mov oDepth, r0.x

+ret 

+// Approximately 3 instruction slots used

+#endif

+

+const BYTE g_PS_PassthroughDepth2D[] =

+{

+     68,  88,  66,  67,  18, 100, 

+    210, 152, 138, 132,   5,  51, 

+     93, 169, 189, 245,  32, 164, 

+     14, 233,   1,   0,   0,   0, 

+    100,   2,   0,   0,   5,   0, 

+      0,   0,  52,   0,   0,   0, 

+    220,   0,   0,   0,  52,   1, 

+      0,   0, 104,   1,   0,   0, 

+    232,   1,   0,   0,  82,  68, 

+     69,  70, 160,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   2,   0,   0,   0, 

+     28,   0,   0,   0,   0,   4, 

+    255, 255,   0,   1,   0,   0, 

+    109,   0,   0,   0,  92,   0, 

+      0,   0,   3,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   1,   0, 

+      0,   0,   1,   0,   0,   0, 

+    100,   0,   0,   0,   2,   0, 

+      0,   0,   5,   0,   0,   0, 

+      4,   0,   0,   0, 255, 255, 

+    255, 255,   0,   0,   0,   0, 

+      1,   0,   0,   0,  13,   0, 

+      0,   0,  83,  97, 109, 112, 

+    108, 101, 114,   0,  84, 101, 

+    120, 116, 117, 114, 101,  70, 

+      0,  77, 105,  99, 114, 111, 

+    115, 111, 102, 116,  32,  40, 

+     82,  41,  32,  72,  76,  83, 

+     76,  32,  83, 104,  97, 100, 

+    101, 114,  32,  67, 111, 109, 

+    112, 105, 108, 101, 114,  32, 

+     57,  46,  50,  57,  46,  57, 

+     53,  50,  46,  51,  49,  49, 

+     49,   0, 171, 171,  73,  83, 

+     71,  78,  80,   0,   0,   0, 

+      2,   0,   0,   0,   8,   0, 

+      0,   0,  56,   0,   0,   0, 

+      0,   0,   0,   0,   1,   0, 

+      0,   0,   3,   0,   0,   0, 

+      0,   0,   0,   0,  15,   0, 

+      0,   0,  68,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   3,   0,   0,   0, 

+      1,   0,   0,   0,   3,   3, 

+      0,   0,  83,  86,  95,  80, 

+     79,  83,  73,  84,  73,  79, 

+     78,   0,  84,  69,  88,  67, 

+     79,  79,  82,  68,   0, 171, 

+    171, 171,  79,  83,  71,  78, 

+     44,   0,   0,   0,   1,   0, 

+      0,   0,   8,   0,   0,   0, 

+     32,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      3,   0,   0,   0, 255, 255, 

+    255, 255,   1,  14,   0,   0, 

+     83,  86,  95,  68,  69,  80, 

+     84,  72,   0, 171, 171, 171, 

+     83,  72,  68,  82, 120,   0, 

+      0,   0,  64,   0,   0,   0, 

+     30,   0,   0,   0,  90,   0, 

+      0,   3,   0,  96,  16,   0, 

+      0,   0,   0,   0,  88,  24, 

+      0,   4,   0, 112,  16,   0, 

+      0,   0,   0,   0,  85,  85, 

+      0,   0,  98,  16,   0,   3, 

+     50,  16,  16,   0,   1,   0, 

+      0,   0, 101,   0,   0,   2, 

+      1, 192,   0,   0, 104,   0, 

+      0,   2,   1,   0,   0,   0, 

+     69,   0,   0,   9, 242,   0, 

+     16,   0,   0,   0,   0,   0, 

+     70,  16,  16,   0,   1,   0, 

+      0,   0,  70, 126,  16,   0, 

+      0,   0,   0,   0,   0,  96, 

+     16,   0,   0,   0,   0,   0, 

+     54,   0,   0,   4,   1, 192, 

+      0,   0,  10,   0,  16,   0, 

+      0,   0,   0,   0,  62,   0, 

+      0,   1,  83,  84,  65,  84, 

+    116,   0,   0,   0,   3,   0, 

+      0,   0,   1,   0,   0,   0, 

+      0,   0,   0,   0,   2,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   1,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      1,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   1,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0, 

+      0,   0,   0,   0,   0,   0

+};

diff --git a/src/libGLESv2/renderer/shaders/generate_shaders.bat b/src/libGLESv2/renderer/shaders/generate_shaders.bat
index 2a8ef85..5b65741 100644
--- a/src/libGLESv2/renderer/shaders/generate_shaders.bat
+++ b/src/libGLESv2/renderer/shaders/generate_shaders.bat
@@ -14,6 +14,7 @@
 fxc /E componentmaskps /T ps_2_0 /Fh compiled/componentmaskps.h Blit.ps

 

 fxc /E VS_Passthrough2D /T vs_4_0 /Fh compiled/passthrough2d11vs.h Passthrough2D11.hlsl

+fxc /E PS_PassthroughDepth2D /T ps_4_0 /Fh compiled/passthroughdepth2d11ps.h Passthrough2D11.hlsl

 fxc /E PS_PassthroughRGBA2D /T ps_4_0 /Fh compiled/passthroughrgba2d11ps.h Passthrough2D11.hlsl

 fxc /E PS_PassthroughRGBA2DUI /T ps_4_0 /Fh compiled/passthroughrgba2dui11ps.h Passthrough2D11.hlsl

 fxc /E PS_PassthroughRGBA2DI /T ps_4_0 /Fh compiled/passthroughrgba2di11ps.h Passthrough2D11.hlsl