Skip to content

Commit

Permalink
Fix regression for D3D EFB depth copies.
Browse files Browse the repository at this point in the history
On D3D, we read from the depth buffer using the format
DXGI_FORMAT_R24_UNORM_X8_TYPELESS (essentially, the "r" component contains
the depth).

Fixes issue 8163.
  • Loading branch information
magumagu committed Feb 2, 2015
1 parent 031422c commit 94cb0a4
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Source/Core/VideoCommon/TextureConversionShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,22 +455,27 @@ static void WriteCC8Encoder(char*& p, const char* comp, API_TYPE ApiType)
WriteEncoderEnd(p, ApiType);
}

static const char* GetDepthComponent(API_TYPE ApiType)
{
return ApiType == API_OPENGL ? "b" : "r";
}

static void WriteZ8Encoder(char*& p, const char* multiplier,API_TYPE ApiType)
{
WriteSwizzler(p, GX_CTF_Z8M, ApiType);

WRITE(p, " float depth;\n");

WriteSampleColor(p, "b", "depth", 0, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 0, ApiType);
WRITE(p, "ocol0.b = frac(depth * %s);\n", multiplier);

WriteSampleColor(p, "b", "depth", 1, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 1, ApiType);
WRITE(p, "ocol0.g = frac(depth * %s);\n", multiplier);

WriteSampleColor(p, "b", "depth", 2, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 2, ApiType);
WRITE(p, "ocol0.r = frac(depth * %s);\n", multiplier);

WriteSampleColor(p, "b", "depth", 3, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 3, ApiType);
WRITE(p, "ocol0.a = frac(depth * %s);\n", multiplier);

WriteEncoderEnd(p, ApiType);
Expand All @@ -485,7 +490,7 @@ static void WriteZ16Encoder(char*& p,API_TYPE ApiType)

// byte order is reversed

WriteSampleColor(p, "b", "depth", 0, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 0, ApiType);

WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
Expand All @@ -495,7 +500,7 @@ static void WriteZ16Encoder(char*& p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.g / 255.0;\n");
WRITE(p, " ocol0.g = expanded.r / 255.0;\n");

WriteSampleColor(p, "b", "depth", 1, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 1, ApiType);

WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
Expand All @@ -517,7 +522,7 @@ static void WriteZ16LEncoder(char*& p,API_TYPE ApiType)

// byte order is reversed

WriteSampleColor(p, "b", "depth", 0, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 0, ApiType);

WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
Expand All @@ -529,7 +534,7 @@ static void WriteZ16LEncoder(char*& p,API_TYPE ApiType)
WRITE(p, " ocol0.b = expanded.b / 255.0;\n");
WRITE(p, " ocol0.g = expanded.g / 255.0;\n");

WriteSampleColor(p, "b", "depth", 1, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth", 1, ApiType);

WRITE(p, " depth *= 16777215.0;\n");
WRITE(p, " expanded.r = floor(depth / (256.0 * 256.0));\n");
Expand All @@ -553,8 +558,8 @@ static void WriteZ24Encoder(char*& p, API_TYPE ApiType)
WRITE(p, " float3 expanded0;\n");
WRITE(p, " float3 expanded1;\n");

WriteSampleColor(p, "b", "depth0", 0, ApiType);
WriteSampleColor(p, "b", "depth1", 1, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth0", 0, ApiType);
WriteSampleColor(p, GetDepthComponent(ApiType), "depth1", 1, ApiType);

for (int i = 0; i < 2; i++)
{
Expand Down Expand Up @@ -641,7 +646,7 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
WriteCC8Encoder(p, "gb", ApiType);
break;
case GX_TF_Z8:
WriteC8Encoder(p, "b", ApiType);
WriteC8Encoder(p, GetDepthComponent(ApiType), ApiType);
break;
case GX_TF_Z16:
WriteZ16Encoder(p, ApiType);
Expand All @@ -650,7 +655,7 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType)
WriteZ24Encoder(p, ApiType);
break;
case GX_CTF_Z4:
WriteC4Encoder(p, "b", ApiType);
WriteC4Encoder(p, GetDepthComponent(ApiType), ApiType);
break;
case GX_CTF_Z8M:
WriteZ8Encoder(p, "256.0", ApiType);
Expand Down

0 comments on commit 94cb0a4

Please sign in to comment.