TextureCache: Extract BP enum check to VideoCommon.

We have TOO many video backends.
This commit is contained in:
degasus
2016-12-26 20:54:37 +01:00
parent d07d9ba499
commit 04f319066d
23 changed files with 112 additions and 135 deletions

View File

@ -106,9 +106,8 @@ void PSTextureEncoder::Shutdown()
}
void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_per_row,
u32 num_blocks_y, u32 memory_stride,
PEControl::PixelFormat src_format, const EFBRectangle& src_rect,
bool is_intensity, bool scale_by_half)
u32 num_blocks_y, u32 memory_stride, bool is_depth_copy,
const EFBRectangle& src_rect, bool is_intensity, bool scale_by_half)
{
if (!m_ready) // Make sure we initialized OK
return;
@ -117,7 +116,7 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
// Resolve MSAA targets before copying.
D3DTexture2D* efb_source =
(src_format == PEControl::Z24) ?
is_depth_copy ?
FramebufferManager::GetResolvedEFBDepthTexture() :
// EXISTINGD3D11TODO: Instead of resolving EFB, it would be better to pick out a
// single sample from each pixel. The game may break if it isn't
@ -163,7 +162,7 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
D3D::DrawShadedTexQuad(
efb_source, target_rect.AsRECT(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight(),
SetStaticShader(format, src_format, is_intensity, scale_by_half),
SetStaticShader(format, is_depth_copy, is_intensity, scale_by_half),
StaticShaderCache::GetSimpleVertexShader(),
StaticShaderCache::GetSimpleVertexShaderInputLayout(), D3D12_SHADER_BYTECODE(), 1.0f, 0,
DXGI_FORMAT_B8G8R8A8_UNORM, false, false /* Render target is not multisampled */
@ -219,27 +218,21 @@ 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,
PEControl::PixelFormat src_format,
D3D12_SHADER_BYTECODE PSTextureEncoder::SetStaticShader(unsigned int dst_format, bool is_depth_copy,
bool is_intensity, bool scale_by_half)
{
size_t fetch_num = static_cast<size_t>(src_format);
size_t scaled_fetch_num = scale_by_half ? 1 : 0;
size_t intensity_num = is_intensity ? 1 : 0;
size_t generator_num = dst_format;
ComboKey key = MakeComboKey(dst_format, src_format, is_intensity, scale_by_half);
ComboKey key = MakeComboKey(dst_format, is_depth_copy, is_intensity, scale_by_half);
ComboMap::iterator it = m_static_shaders_map.find(key);
if (it == m_static_shaders_map.end())
{
INFO_LOG(VIDEO, "Compiling efb encoding shader for dst_format 0x%X, src_format %d, "
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, static_cast<int>(src_format), is_intensity ? 1 : 0, scale_by_half ? 1 : 0);
dst_format, is_depth_copy, is_intensity ? 1 : 0, scale_by_half ? 1 : 0);
u32 format = dst_format;
if (src_format == PEControl::Z24)
if (is_depth_copy)
{
format |= _GX_TF_ZTF;
if (dst_format == 11)
@ -257,10 +250,9 @@ D3D12_SHADER_BYTECODE PSTextureEncoder::SetStaticShader(unsigned int dst_format,
const char* shader = TextureConversionShader::GenerateEncodingShader(format, APIType::D3D);
if (!D3D::CompilePixelShader(shader, &bytecode))
{
WARN_LOG(VIDEO, "EFB encoder shader for dst_format 0x%X, src_format %d, is_intensity %d, "
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, static_cast<int>(src_format), is_intensity ? 1 : 0,
scale_by_half ? 1 : 0);
dst_format, is_depth_copy, is_intensity ? 1 : 0, scale_by_half ? 1 : 0);
m_static_shaders_blobs[key] = {};
return {};
}

View File

@ -18,7 +18,7 @@ public:
void Init();
void Shutdown();
void Encode(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y,
u32 memory_stride, PEControl::PixelFormat src_format, const EFBRectangle& src_rect,
u32 memory_stride, bool is_depth_copy, const EFBRectangle& src_rect,
bool is_intensity, bool scale_by_half);
private:
@ -32,14 +32,14 @@ private:
ID3D12Resource* m_encode_params_buffer = nullptr;
void* m_encode_params_buffer_data = nullptr;
D3D12_SHADER_BYTECODE SetStaticShader(unsigned int dst_format, PEControl::PixelFormat src_format,
D3D12_SHADER_BYTECODE SetStaticShader(unsigned int dst_format, bool is_depth_copy,
bool is_intensity, bool scale_by_half);
using ComboKey = unsigned int; // Key for a shader combination
static ComboKey MakeComboKey(unsigned int dst_format, PEControl::PixelFormat src_format,
bool is_intensity, bool scale_by_half)
static ComboKey MakeComboKey(unsigned int dst_format, bool is_depth_copy, bool is_intensity,
bool scale_by_half)
{
return (dst_format << 4) | (static_cast<int>(src_format) << 2) | (is_intensity ? (1 << 1) : 0) |
return (dst_format << 4) | (is_depth_copy << 2) | (is_intensity ? (1 << 1) : 0) |
(scale_by_half ? (1 << 0) : 0);
}

View File

@ -229,7 +229,7 @@ TextureCacheBase::TCacheEntryBase* TextureCache::CreateTexture(const TCacheEntry
}
}
void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat src_format,
void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, bool is_depth_copy,
const EFBRectangle& srcRect, bool scale_by_half,
unsigned int cbuf_id, const float* colmat)
{
@ -237,14 +237,13 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
// This is because multisampled texture reads go through Load, not Sample, and the linear
// filter is ignored.
bool multisampled = (g_ActiveConfig.iMultisamples > 1);
D3DTexture2D* efb_tex = (src_format == PEControl::Z24) ?
FramebufferManager::GetEFBDepthTexture() :
FramebufferManager::GetEFBColorTexture();
D3DTexture2D* efb_tex = is_depth_copy ? FramebufferManager::GetEFBDepthTexture() :
FramebufferManager::GetEFBColorTexture();
if (multisampled && scale_by_half)
{
multisampled = false;
efb_tex = (src_format == PEControl::Z24) ? FramebufferManager::GetResolvedEFBDepthTexture() :
FramebufferManager::GetResolvedEFBColorTexture();
efb_tex = is_depth_copy ? FramebufferManager::GetResolvedEFBDepthTexture() :
FramebufferManager::GetResolvedEFBColorTexture();
}
// set transformation
@ -286,8 +285,8 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
// Create texture copy
D3D::DrawShadedTexQuad(
efb_tex, &sourcerect, Renderer::GetTargetWidth(), Renderer::GetTargetHeight(),
(src_format == PEControl::Z24) ? StaticShaderCache::GetDepthMatrixPixelShader(multisampled) :
StaticShaderCache::GetColorMatrixPixelShader(multisampled),
is_depth_copy ? StaticShaderCache::GetDepthMatrixPixelShader(multisampled) :
StaticShaderCache::GetColorMatrixPixelShader(multisampled),
StaticShaderCache::GetSimpleVertexShader(),
StaticShaderCache::GetSimpleVertexShaderInputLayout(),
StaticShaderCache::GetCopyGeometryShader(), 1.0f, 0, DXGI_FORMAT_R8G8B8A8_UNORM, false,
@ -305,11 +304,11 @@ void TextureCache::TCacheEntry::FromRenderTarget(u8* dst, PEControl::PixelFormat
}
void TextureCache::CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row,
u32 num_blocks_y, u32 memory_stride, PEControl::PixelFormat srcFormat,
u32 num_blocks_y, u32 memory_stride, bool is_depth_copy,
const EFBRectangle& srcRect, bool isIntensity, bool scaleByHalf)
{
s_encoder->Encode(dst, format, native_width, bytes_per_row, num_blocks_y, memory_stride,
srcFormat, srcRect, isIntensity, scaleByHalf);
is_depth_copy, srcRect, isIntensity, scaleByHalf);
}
static const constexpr char s_palette_shader_hlsl[] =

View File

@ -41,7 +41,7 @@ private:
void Load(const u8* buffer, u32 width, u32 height, u32 expanded_width, u32 levels) override;
void FromRenderTarget(u8* dst, PEControl::PixelFormat src_format, const EFBRectangle& src_rect,
void FromRenderTarget(u8* dst, bool is_depth_copy, const EFBRectangle& src_rect,
bool scale_by_half, unsigned int cbuf_id, const float* colmat) override;
void Bind(unsigned int stage) override;
@ -61,7 +61,7 @@ private:
TlutFormat format) override;
void CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y,
u32 memory_stride, PEControl::PixelFormat src_format, const EFBRectangle& src_rect,
u32 memory_stride, bool is_depth_copy, const EFBRectangle& src_rect,
bool is_intensity, bool scale_by_half) override;
bool CompileShaders() override { return true; }

View File

@ -24,7 +24,7 @@ public:
virtual void Shutdown() = 0;
// Returns size in bytes of encoded block of memory
virtual void Encode(u8* dst, u32 format, u32 native_width, u32 bytes_per_row, u32 num_blocks_y,
u32 memory_stride, PEControl::PixelFormat src_format,
const EFBRectangle& src_rect, bool is_intensity, bool scale_by_half) = 0;
u32 memory_stride, bool is_depth_copy, const EFBRectangle& src_rect,
bool is_intensity, bool scale_by_half) = 0;
};
}