Merge pull request #8252 from stenzek/glsl-es-is-annoying

FramebufferShaderGen: Fix format reinterpret shaders on GLES
This commit is contained in:
Connor McLaughlin 2019-07-19 16:08:49 +10:00 committed by GitHub
commit a9abf2838e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 11 deletions

View File

@ -597,29 +597,30 @@ std::string GenerateTextureReinterpretShader(TextureFormat from_format, TextureF
case TextureFormat::I8:
case TextureFormat::C8:
{
ss << " ocol0.rgba = (float(raw_value & 0xFFu) / 255.0).rrrr;\n";
ss << " float orgba = float(raw_value & 0xFFu) / 255.0;\n";
ss << " ocol0 = float4(orgba, orgba, orgba, orgba);\n";
}
break;
case TextureFormat::IA8:
{
ss << " ocol0.rgb = (float(raw_value & 0xFFu) / 255.0).rrr;\n";
ss << " ocol0.a = float((raw_value >> 8) & 0xFFu) / 255.0;\n";
ss << " float orgb = float(raw_value & 0xFFu) / 255.0;\n";
ss << " ocol0 = float4(orgb, orgb, orgb, float((raw_value >> 8) & 0xFFu) / 255.0);\n";
}
break;
case TextureFormat::IA4:
{
ss << " ocol0.rgb = (float(raw_value & 0xFu) / 15.0).rrr;\n";
ss << " ocol0.a = float((raw_value >> 4) & 0xFu) / 15.0;\n";
ss << " float orgb = float(raw_value & 0xFu) / 15.0;\n";
ss << " ocol0 = float4(orgb, orgb, orgb, float((raw_value >> 4) & 0xFu) / 15.0);\n";
}
break;
case TextureFormat::RGB565:
{
ss << " ocol0 = float4(float((raw_value >> 10) & 0x1Fu) / 31.0\n";
ss << " ocol0 = float4(float((raw_value >> 10) & 0x1Fu) / 31.0,\n";
ss << " float((raw_value >> 5) & 0x1Fu) / 31.0,\n";
ss << " float(raw_value & 0x1Fu) / 31.0,, 1.0);\n";
ss << " float(raw_value & 0x1Fu) / 31.0, 1.0);\n";
}
break;

View File

@ -254,6 +254,14 @@ TextureCacheBase::ApplyPaletteToEntry(TCacheEntry* entry, u8* palette, TLUTForma
{
DEBUG_ASSERT(g_ActiveConfig.backend_info.bSupportsPaletteConversion);
const AbstractPipeline* pipeline = g_shader_cache->GetPaletteConversionPipeline(tlutfmt);
if (!pipeline)
{
ERROR_LOG(VIDEO, "Failed to get conversion pipeline for format 0x%02X",
static_cast<u32>(tlutfmt));
return nullptr;
}
TextureConfig new_config = entry->texture->GetConfig();
new_config.levels = 1;
new_config.flags |= AbstractTextureFlag_RenderTarget;
@ -293,7 +301,7 @@ TextureCacheBase::ApplyPaletteToEntry(TCacheEntry* entry, u8* palette, TLUTForma
g_renderer->SetAndDiscardFramebuffer(decoded_entry->framebuffer.get());
g_renderer->SetViewportAndScissor(decoded_entry->texture->GetRect());
g_renderer->SetPipeline(g_shader_cache->GetPaletteConversionPipeline(tlutfmt));
g_renderer->SetPipeline(pipeline);
g_renderer->SetTexture(1, entry->texture.get());
g_renderer->SetSamplerState(1, RenderState::GetPointSamplerState());
g_renderer->Draw(0, 3);
@ -314,6 +322,16 @@ TextureCacheBase::ApplyPaletteToEntry(TCacheEntry* entry, u8* palette, TLUTForma
TextureCacheBase::TCacheEntry* TextureCacheBase::ReinterpretEntry(const TCacheEntry* existing_entry,
TextureFormat new_format)
{
const AbstractPipeline* pipeline =
g_shader_cache->GetTextureReinterpretPipeline(existing_entry->format.texfmt, new_format);
if (!pipeline)
{
ERROR_LOG(VIDEO,
"Failed to obtain texture reinterpreting pipeline from format 0x%02X to 0x%02X",
static_cast<u32>(existing_entry->format.texfmt), static_cast<u32>(new_format));
return nullptr;
}
TextureConfig new_config = existing_entry->texture->GetConfig();
new_config.levels = 1;
new_config.flags |= AbstractTextureFlag_RenderTarget;
@ -336,8 +354,7 @@ TextureCacheBase::TCacheEntry* TextureCacheBase::ReinterpretEntry(const TCacheEn
g_renderer->BeginUtilityDrawing();
g_renderer->SetAndDiscardFramebuffer(reinterpreted_entry->framebuffer.get());
g_renderer->SetViewportAndScissor(reinterpreted_entry->texture->GetRect());
g_renderer->SetPipeline(
g_shader_cache->GetTextureReinterpretPipeline(existing_entry->format.texfmt, new_format));
g_renderer->SetPipeline(pipeline);
g_renderer->SetTexture(0, existing_entry->texture.get());
g_renderer->SetSamplerState(1, RenderState::GetPointSamplerState());
g_renderer->Draw(0, 3);
@ -432,7 +449,10 @@ TextureCacheBase::DoPartialTextureUpdates(TCacheEntry* entry_to_update, u8* pale
continue;
}
entry = ReinterpretEntry(entry, entry_to_update->format.texfmt);
TCacheEntry* reinterpreted_entry =
ReinterpretEntry(entry, entry_to_update->format.texfmt);
if (reinterpreted_entry)
entry = reinterpreted_entry;
}
if (isPaletteTexture)