summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp')
-rw-r--r--Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp94
1 files changed, 30 insertions, 64 deletions
diff --git a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp
index 7b9bfaeaa3..403e768599 100644
--- a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp
+++ b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp
@@ -75,11 +75,11 @@ void PSTextureEncoder::Shutdown()
{
m_ready = false;
- for (auto& it : m_staticShaders)
+ for (auto& it : m_encoding_shaders)
{
SAFE_RELEASE(it.second);
}
- m_staticShaders.clear();
+ m_encoding_shaders.clear();
SAFE_RELEASE(m_encodeParams);
SAFE_RELEASE(m_outStage);
@@ -87,9 +87,9 @@ void PSTextureEncoder::Shutdown()
SAFE_RELEASE(m_out);
}
-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& srcRect, bool isIntensity, bool scaleByHalf)
+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;
@@ -120,10 +120,10 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
D3D::context->OMSetRenderTargets(1, &m_outRTV, nullptr);
EFBEncodeParams params;
- params.SrcLeft = srcRect.left;
- params.SrcTop = srcRect.top;
+ params.SrcLeft = src_rect.left;
+ params.SrcTop = src_rect.top;
params.DestWidth = native_width;
- params.ScaleFactor = scaleByHalf ? 2 : 1;
+ params.ScaleFactor = scale_by_half ? 2 : 1;
D3D::context->UpdateSubresource(m_encodeParams, 0, nullptr, &params, 0, 0);
D3D::stateman->SetPixelConstants(m_encodeParams);
@@ -131,15 +131,15 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
// TODO: This only produces perfect downsampling for 1.5x and 2x IR, other resolution will
// need more complex down filtering to average all pixels and produce the correct result.
// Also, box filtering won't be correct for anything other than 1x IR
- if (scaleByHalf || g_ActiveConfig.iEFBScale != SCALE_1X)
+ if (scale_by_half || g_ActiveConfig.iEFBScale != SCALE_1X)
D3D::SetLinearCopySampler();
else
D3D::SetPointCopySampler();
- D3D::drawShadedTexQuad(
- pEFB, targetRect.AsRECT(), g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(),
- SetStaticShader(format, is_depth_copy, isIntensity, scaleByHalf),
- VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout());
+ D3D::drawShadedTexQuad(pEFB, targetRect.AsRECT(), g_renderer->GetTargetWidth(),
+ g_renderer->GetTargetHeight(), GetEncodingPixelShader(format),
+ VertexShaderCache::GetSimpleVertexShader(),
+ VertexShaderCache::GetSimpleInputLayout());
// Copy to staging buffer
D3D11_BOX srcBox = CD3D11_BOX(0, 0, 0, words_per_row, num_blocks_y, 1);
@@ -168,61 +168,27 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
FramebufferManager::GetEFBDepthTexture()->GetDSV());
}
-ID3D11PixelShader* PSTextureEncoder::SetStaticShader(unsigned int dstFormat, bool is_depth_copy,
- bool isIntensity, bool scaleByHalf)
+ID3D11PixelShader* PSTextureEncoder::GetEncodingPixelShader(const EFBCopyFormat& format)
{
- ComboKey key = MakeComboKey(dstFormat, is_depth_copy, isIntensity, scaleByHalf);
+ auto iter = m_encoding_shaders.find(format);
+ if (iter != m_encoding_shaders.end())
+ return iter->second;
- ComboMap::iterator it = m_staticShaders.find(key);
- if (it == m_staticShaders.end())
+ D3DBlob* bytecode = nullptr;
+ const char* shader = TextureConversionShader::GenerateEncodingShader(format, APIType::D3D);
+ if (!D3D::CompilePixelShader(shader, &bytecode))
{
- INFO_LOG(VIDEO,
- "Compiling efb encoding shader for dstFormat 0x%X, is_depth_copy %d, isIntensity "
- "%d, scaleByHalf %d",
- dstFormat, is_depth_copy, isIntensity ? 1 : 0, scaleByHalf ? 1 : 0);
-
- u32 format = dstFormat;
-
- if (is_depth_copy)
- {
- format |= _GX_TF_ZTF;
- if (dstFormat == 11)
- format = GX_TF_Z16;
- else if (format < GX_TF_Z8 || format > GX_TF_Z24X8)
- format |= _GX_TF_CTF;
- }
- else
- {
- if (dstFormat > GX_TF_RGBA8 || (dstFormat < GX_TF_RGB565 && !isIntensity))
- format |= _GX_TF_CTF;
- }
-
- D3DBlob* bytecode = nullptr;
- const char* shader = TextureConversionShader::GenerateEncodingShader(format, APIType::D3D);
- if (!D3D::CompilePixelShader(shader, &bytecode))
- {
- WARN_LOG(VIDEO, "EFB encoder shader for dstFormat 0x%X, is_depth_copy %d, isIntensity %d, "
- "scaleByHalf %d failed to compile",
- dstFormat, is_depth_copy, isIntensity ? 1 : 0, scaleByHalf ? 1 : 0);
- m_staticShaders[key] = nullptr;
- return nullptr;
- }
-
- ID3D11PixelShader* newShader;
- HRESULT hr =
- D3D::device->CreatePixelShader(bytecode->Data(), bytecode->Size(), nullptr, &newShader);
- CHECK(SUCCEEDED(hr), "create efb encoder pixel shader");
-
- char debugName[255] = {};
- sprintf_s(debugName,
- "efb encoder pixel shader (dst:%d, is_depth_copy:%d, intensity:%d, scale:%d)",
- dstFormat, is_depth_copy, isIntensity, scaleByHalf);
- D3D::SetDebugObjectName(newShader, debugName);
-
- it = m_staticShaders.emplace(key, newShader).first;
- bytecode->Release();
+ PanicAlert("Failed to compile texture encoding shader.");
+ m_encoding_shaders[format] = nullptr;
+ return nullptr;
}
- return it->second;
+ ID3D11PixelShader* newShader;
+ HRESULT hr =
+ D3D::device->CreatePixelShader(bytecode->Data(), bytecode->Size(), nullptr, &newShader);
+ CHECK(SUCCEEDED(hr), "create efb encoder pixel shader");
+
+ m_encoding_shaders.emplace(format, newShader);
+ return newShader;
}
}