Skip to content

Commit

Permalink
More D3D9 work on depth textures. Something still missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Aug 21, 2022
1 parent 51a0c44 commit 77c01b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion GPU/Common/DepalettizeShaderCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config, c
writer.ConstFloat("z_offset", factors.offset);
}

writer.C(" vec4 index = ").SampleTexture2D("tex", "v_texcoord").C(";\n");

float index_multiplier = 1.0f;
// pixelformat is the format of the texture we are sampling.
bool formatOK = true;
Expand Down Expand Up @@ -233,6 +235,19 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config, c
case GE_FORMAT_DEPTH16:
{
// TODO: I think we can handle most scenarios here, but texturing from depth buffers requires an extension on ES 2.0 anyway.
// Not on D3D9 though, so this path is still relevant.

if (config.bufferFormat == GE_FORMAT_DEPTH16 && config.textureFormat == GE_TFMT_5650) {
// Convert depth to 565, without going through a CLUT.
writer.C(" float depth = (index.x - z_offset) * z_scale;\n");
writer.C(" float idepth = floor(clamp(depth, 0.0, 65535.0));\n");
writer.C(" float r = mod(idepth, 32.0) / 31.0f;\n");
writer.C(" float g = mod(floor(idepth / 32.0), 64.0) / 63.0f;\n");
writer.C(" float b = mod(floor(idepth / 2048.0), 32.0) / 31.0f;\n");
writer.C(" vec4 outColor = vec4(r, g, b, 1.0);\n");
return;
}

if (shift < 16) {
index_multiplier = 1.0f / (float)(1 << shift);
truncate_cpy(lookupMethod, "((index.x - z_offset) * z_scale)");
Expand Down Expand Up @@ -269,7 +284,6 @@ void GenerateDepalShaderFloat(ShaderWriter &writer, const DepalConfig &config, c
char offset[128] = "";
sprintf(offset, " + %f", texel_offset);

writer.C(" vec4 index = ").SampleTexture2D("tex", "v_texcoord").C(";\n");
writer.F(" float coord = (%s * %f)%s;\n", lookupMethod, index_multiplier, offset);
writer.C(" vec4 outColor = ").SampleTexture2D("pal", "vec2(coord, 0.0)").C(";\n");
}
Expand Down
1 change: 0 additions & 1 deletion GPU/Common/TextureCacheCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,6 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer
// TODO: Implement shader depal in the fragment shader generator for D3D11 at least.
if (!draw_->GetDeviceCaps().fragmentShaderInt32Supported) {
useShaderDepal = false;
depth = false; // Can't support this
}

switch (draw_->GetShaderLanguageDesc().shaderLanguage) {
Expand Down
1 change: 1 addition & 0 deletions GPU/Directx9/GPU_DX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void GPU_DX9::CheckGPUFeatures() {
u32 features = 0;
features |= GPU_SUPPORTS_16BIT_FORMATS;
features |= GPU_SUPPORTS_BLEND_MINMAX;
features |= GPU_SUPPORTS_DEPTH_TEXTURE;
features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL;

// Accurate depth is required because the Direct3D API does not support inverse Z.
Expand Down

0 comments on commit 77c01b2

Please sign in to comment.