Skip to content

Commit

Permalink
VulkanDevice: Work around some mobile driver issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Dec 13, 2023
1 parent 4f84a98 commit c20805f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
28 changes: 2 additions & 26 deletions data/resources/shaders/crt-lottes.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,12 @@ MaxValue = 10.0
StepAmount = 0.05
DefaultValue = 2.0
[OptionBool]
GUIName = Scale in Linear Gamma
OptionName = scaleInLinearGamma
DefaultValue = true
[/configuration]
*/

//Uncomment to reduce instructions with simpler linearization
//(fixes HD3000 Sandy Bridge IGP)
//#define SIMPLE_LINEAR_GAMMA
#define SIMPLE_LINEAR_GAMMA
#define DO_BLOOM

// ------------- //
Expand All @@ -143,35 +138,23 @@ float3 ToSrgb(float3 c)
#else
float ToLinear1(float c)
{
if (!OptionEnabled(scaleInLinearGamma))
return c;

return(c<=0.04045) ? c/12.92 : pow((c + 0.055)/1.055, 2.4);
}

float3 ToLinear(float3 c)
{
if (!OptionEnabled(scaleInLinearGamma))
return c;

return float3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b));
}

// Linear to sRGB.
// Assuming using sRGB typed textures this should not be needed.
float ToSrgb1(float c)
{
if (!OptionEnabled(scaleInLinearGamma))
return c;

return(c<0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055);
}

float3 ToSrgb(float3 c)
{
if (!OptionEnabled(scaleInLinearGamma))
return c;

return float3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b));
}
#endif
Expand Down Expand Up @@ -391,15 +374,8 @@ void main()
outColor.rgb += Bloom(pos)*GetOption(bloomAmount);
#endif

if (GetOption(shadowMask) > 0.0)
if (GetOption(shadowMask) > 0)
outColor.rgb *= Mask(gl_FragCoord.xy * 1.000001);

#ifdef GL_ES /* TODO/FIXME - hacky clamp fix */
float2 bordertest = (pos);
if ( bordertest.x > 0.0001 && bordertest.x < 0.9999 && bordertest.y > 0.0001 && bordertest.y < 0.9999)
outColor.rgb = outColor.rgb;
else
outColor.rgb = float3(0.0);
#endif
SetOutput(float4(ToSrgb(outColor.rgb), 1.0));
}
8 changes: 8 additions & 0 deletions src/util/postprocessing_shader_fx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,14 @@ bool PostProcessing::ReShadeFXShader::Apply(GPUTexture* input, GPUTexture* final
GL_SCOPE_FMT("Draw pass {}", pass.name.c_str());
DebugAssert(!pass.render_targets.empty());

// Sucks doing this twice, but we need to set the RT first (for DX11), and transition layouts (for VK).
for (const Sampler& sampler : pass.samplers)
{
GPUTexture* const tex = GetTextureByID(sampler.texture_id, input, final_target);
if (tex)
tex->MakeReadyForSampling();
}

if (pass.render_targets.size() == 1 && pass.render_targets[0] == OUTPUT_COLOR_TEXTURE && !final_target)
{
// Special case: drawing to final buffer.
Expand Down
49 changes: 47 additions & 2 deletions src/util/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const std::array<VkFormat, static_cast<u32>(GPUTexture::Format::MaxCount)> Vulka
static constexpr VkClearValue s_present_clear_color = {{{0.0f, 0.0f, 0.0f, 1.0f}}};

// Handles are always 64-bit, even on 32-bit platforms.
static const VkRenderPass DYNAMIC_RENDERING_RENDER_PASS = ((VkRenderPass)static_cast<s64>(-1LL));
static const VkRenderPass DYNAMIC_RENDERING_RENDER_PASS = ((VkRenderPass) static_cast<s64>(-1LL));

#ifdef _DEBUG
static u32 s_debug_scope_depth = 0;
Expand Down Expand Up @@ -602,6 +602,21 @@ void VulkanDevice::ProcessDeviceExtensions()

m_optional_extensions.vk_khr_push_descriptor &= (push_descriptor_properties.maxPushDescriptors >= 1);

if (IsBrokenMobileDriver())
{
// Push descriptor is broken on Adreno v502.. don't want to think about dynamic rendending.
if (m_optional_extensions.vk_khr_dynamic_rendering)
{
m_optional_extensions.vk_khr_dynamic_rendering = false;
Log_WarningPrint("Disabling VK_KHR_dynamic_rendering on broken mobile driver.");
}
if (m_optional_extensions.vk_khr_push_descriptor)
{
m_optional_extensions.vk_khr_push_descriptor = false;
Log_WarningPrint("Disabling VK_KHR_push_descriptor on broken mobile driver.");
}
}

Log_InfoPrintf("VK_EXT_memory_budget is %s",
m_optional_extensions.vk_ext_memory_budget ? "supported" : "NOT supported");
Log_InfoPrintf("VK_EXT_rasterization_order_attachment_access is %s",
Expand Down Expand Up @@ -700,7 +715,8 @@ bool VulkanDevice::CreateCommandBuffers()
LOG_VULKAN_ERROR(res, "vkCreateCommandPool failed: ");
return false;
}
Vulkan::SetObjectName(m_device, resources.command_pool, TinyString::from_format("Frame Command Pool {}", frame_index));
Vulkan::SetObjectName(m_device, resources.command_pool,
TinyString::from_format("Frame Command Pool {}", frame_index));

VkCommandBufferAllocateInfo buffer_info = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr,
resources.command_pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY,
Expand Down Expand Up @@ -1497,6 +1513,31 @@ void VulkanDevice::DisableDebugUtils()
}
}

bool VulkanDevice::IsDeviceAdreno() const
{
// Assume turnip is fine...
return ((m_device_properties.vendorID == 0x5143 ||
m_device_driver_properties.driverID == VK_DRIVER_ID_QUALCOMM_PROPRIETARY) &&
m_device_driver_properties.driverID != VK_DRIVER_ID_MESA_TURNIP);
}

bool VulkanDevice::IsDeviceMali() const
{
return (m_device_properties.vendorID == 0x13B5 ||
m_device_driver_properties.driverID == VK_DRIVER_ID_ARM_PROPRIETARY);
}

bool VulkanDevice::IsDeviceImgTec() const
{
return (m_device_properties.vendorID == 0x1010 ||
m_device_driver_properties.driverID == VK_DRIVER_ID_IMAGINATION_PROPRIETARY);
}

bool VulkanDevice::IsBrokenMobileDriver() const
{
return (IsDeviceAdreno() || IsDeviceMali() || IsDeviceImgTec());
}

VkRenderPass VulkanDevice::CreateCachedRenderPass(RenderPassCacheKey key)
{
VkAttachmentReference color_reference;
Expand Down Expand Up @@ -3344,6 +3385,10 @@ bool VulkanDevice::UpdateDescriptorSetsForLayout(bool new_layout, bool new_dynam
ds[num_ds++] = m_ubo_descriptor_set;
new_dynamic_offsets = true;
}
else
{
first_ds++;
}
}

if constexpr (layout == GPUPipeline::Layout::SingleTextureAndUBO ||
Expand Down
6 changes: 6 additions & 0 deletions src/util/vulkan_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ class VulkanDevice final : public GPUDevice
bool EnableDebugUtils();
void DisableDebugUtils();

// Vendor queries.
bool IsDeviceAdreno() const;
bool IsDeviceMali() const;
bool IsDeviceImgTec() const;
bool IsBrokenMobileDriver() const;

void SubmitCommandBuffer(VulkanSwapChain* present_swap_chain = nullptr, bool submit_on_thread = false);
void MoveToNextCommandBuffer();
void WaitForPresentComplete();
Expand Down

0 comments on commit c20805f

Please sign in to comment.