summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp
diff options
context:
space:
mode:
authorMarkus Wick <degasus@users.noreply.github.com>2017-04-12 01:09:30 +0200
committerGitHub <noreply@github.com>2017-04-12 01:09:30 +0200
commit29344cb5ff7cfaae08349726a092b78689c17a45 (patch)
tree64ac677546927d8565e0a7c1dc2dcfe3824fe244 /Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp
parent8ecc5e9b7a43c346ffa87572d45ff7e38c83c632 (diff)
parent5e7bd03d0b8aaf16b4baa716d73c4804760a84c0 (diff)
Merge pull request #5202 from stenzek/efb-copy-source-format
TextureConversionShader: Consider source format of EFB for EFB2RAM
Diffstat (limited to 'Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp')
-rw-r--r--Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp75
1 files changed, 24 insertions, 51 deletions
diff --git a/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp b/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp
index 8e70540d94..ce56588669 100644
--- a/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp
+++ b/Source/Core/VideoBackends/D3D12/PSTextureEncoder.cpp
@@ -101,18 +101,18 @@ void PSTextureEncoder::Shutdown()
D3D::command_list_mgr->DestroyResourceAfterCurrentCommandListExecuted(m_out_readback_buffer);
D3D::command_list_mgr->DestroyResourceAfterCurrentCommandListExecuted(m_encode_params_buffer);
- for (auto& it : m_static_shaders_blobs)
+ for (auto& it : m_shader_blobs)
{
SAFE_RELEASE(it);
}
- m_static_shaders_blobs.clear();
- m_static_shaders_map.clear();
+ m_shader_blobs.clear();
+ m_encoding_shaders.clear();
}
-void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_per_row,
- u32 num_blocks_y, u32 memory_stride, bool is_depth_copy,
- const EFBRectangle& src_rect, bool is_intensity, bool scale_by_half)
+void PSTextureEncoder::Encode(u8* dst, const EFBCopyFormat& format, u32 native_width,
+ u32 bytes_per_row, u32 num_blocks_y, u32 memory_stride,
+ bool is_depth_copy, const EFBRectangle& src_rect, bool scale_by_half)
{
if (!m_ready) // Make sure we initialized OK
return;
@@ -167,8 +167,7 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
D3D::DrawShadedTexQuad(
efb_source, target_rect.AsRECT(), g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(),
- SetStaticShader(format, is_depth_copy, is_intensity, scale_by_half),
- StaticShaderCache::GetSimpleVertexShader(),
+ GetEncodingPixelShader(format), StaticShaderCache::GetSimpleVertexShader(),
StaticShaderCache::GetSimpleVertexShaderInputLayout(), D3D12_SHADER_BYTECODE(), 1.0f, 0,
DXGI_FORMAT_B8G8R8A8_UNORM, false, false /* Render target is not multisampled */
);
@@ -223,53 +222,27 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
m_out_readback_buffer->Unmap(0, &write_range);
}
-D3D12_SHADER_BYTECODE PSTextureEncoder::SetStaticShader(unsigned int dst_format, bool is_depth_copy,
- bool is_intensity, bool scale_by_half)
+D3D12_SHADER_BYTECODE PSTextureEncoder::GetEncodingPixelShader(const EFBCopyFormat& format)
{
- ComboKey key = MakeComboKey(dst_format, is_depth_copy, is_intensity, scale_by_half);
+ auto iter = m_encoding_shaders.find(format);
+ if (iter != m_encoding_shaders.end())
+ return iter->second;
- ComboMap::iterator it = m_static_shaders_map.find(key);
- if (it == m_static_shaders_map.end())
+ ID3DBlob* bytecode = nullptr;
+ const char* shader = TextureConversionShader::GenerateEncodingShader(format, APIType::D3D);
+ if (!D3D::CompilePixelShader(shader, &bytecode))
{
- INFO_LOG(VIDEO, "Compiling efb encoding shader for dst_format 0x%X, is_depth_copy %d, "
- "is_intensity %d, scale_by_half %d",
- dst_format, is_depth_copy, is_intensity ? 1 : 0, scale_by_half ? 1 : 0);
-
- u32 format = dst_format;
-
- if (is_depth_copy)
- {
- format |= _GX_TF_ZTF;
- if (dst_format == 11)
- format = GX_TF_Z16;
- else if (format < GX_TF_Z8 || format > GX_TF_Z24X8)
- format |= _GX_TF_CTF;
- }
- else
- {
- if (dst_format > GX_TF_RGBA8 || (dst_format < GX_TF_RGB565 && !is_intensity))
- format |= _GX_TF_CTF;
- }
-
- ID3DBlob* bytecode = nullptr;
- const char* shader = TextureConversionShader::GenerateEncodingShader(format, APIType::D3D);
- if (!D3D::CompilePixelShader(shader, &bytecode))
- {
- WARN_LOG(VIDEO, "EFB encoder shader for dst_format 0x%X, is_depth_copy %d, is_intensity %d, "
- "scale_by_half %d failed to compile",
- dst_format, is_depth_copy, is_intensity ? 1 : 0, scale_by_half ? 1 : 0);
- m_static_shaders_blobs[key] = {};
- return {};
- }
-
- D3D12_SHADER_BYTECODE new_shader = {bytecode->GetBufferPointer(), bytecode->GetBufferSize()};
-
- it = m_static_shaders_map.emplace(key, new_shader).first;
-
- // Keep track of the ID3DBlobs, so we can free them upon shutdown.
- m_static_shaders_blobs.push_back(bytecode);
+ PanicAlert("Failed to compile texture encoding shader.");
+ m_encoding_shaders[format] = {};
+ return {};
}
- return it->second;
+ D3D12_SHADER_BYTECODE new_shader = {bytecode->GetBufferPointer(), bytecode->GetBufferSize()};
+ m_encoding_shaders.emplace(format, new_shader);
+
+ // Keep track of the ID3DBlobs, so we can free them upon shutdown.
+ m_shader_blobs.push_back(bytecode);
+
+ return new_shader;
}
}