Skip to content

Commit

Permalink
vkd3d: Add workaround for The First Descendant
Browse files Browse the repository at this point in the history
The game generates broken reflection probes since not all mips are
correctly computed.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
  • Loading branch information
HansKristian-Work committed Dec 12, 2024
1 parent acd84f2 commit a3fe231
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/vkd3d_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ enum vkd3d_shader_quirk

/* Works around cases where app is relying on coherency between threads in a workgroup,
* but forgets to use Device memory barriers properly. */
VKD3D_SHADER_QUIRK_FORCE_DEVICE_MEMORY_BARRIER_THREAD_GROUP_COHERENCY = (1 << 21)
VKD3D_SHADER_QUIRK_FORCE_DEVICE_MEMORY_BARRIER_THREAD_GROUP_COHERENCY = (1 << 21),

/* Extremely specific workaround for cubemap importance sampling pass.
* The lowest res mips may contain garbage. */
VKD3D_SHADER_QUIRK_ASSUME_BROKEN_SUB_8x8_CUBE_MIPS = (1 << 22)
};

struct vkd3d_shader_quirk_hash
Expand Down
28 changes: 28 additions & 0 deletions libs/vkd3d-shader/dxil.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,20 @@ int vkd3d_shader_compile_dxil(const struct vkd3d_shader_code *dxbc,
}
}

if (quirks & VKD3D_SHADER_QUIRK_ASSUME_BROKEN_SUB_8x8_CUBE_MIPS)
{
const dxil_spv_option_shader_quirk helper =
{ { DXIL_SPV_OPTION_SHADER_QUIRK },
DXIL_SPV_SHADER_QUIRK_ASSUME_BROKEN_SUB_8x8_CUBE_MIPS };

if (dxil_spv_converter_add_option(converter, &helper.base) != DXIL_SPV_SUCCESS)
{
ERR("dxil-spirv does not support SHADER_QUIRK.\n");
ret = VKD3D_ERROR_NOT_IMPLEMENTED;
goto end;
}
}

remap_userdata.shader_interface_info = shader_interface_info;
remap_userdata.shader_interface_local_info = NULL;
remap_userdata.num_root_descriptors = num_root_descriptors;
Expand Down Expand Up @@ -1618,6 +1632,20 @@ int vkd3d_shader_compile_dxil_export(const struct vkd3d_shader_code *dxil,
}
}

if (quirks & VKD3D_SHADER_QUIRK_ASSUME_BROKEN_SUB_8x8_CUBE_MIPS)
{
const dxil_spv_option_shader_quirk helper =
{ { DXIL_SPV_OPTION_SHADER_QUIRK },
DXIL_SPV_SHADER_QUIRK_ASSUME_BROKEN_SUB_8x8_CUBE_MIPS };

if (dxil_spv_converter_add_option(converter, &helper.base) != DXIL_SPV_SUCCESS)
{
ERR("dxil-spirv does not support SHADER_QUIRK.\n");
ret = VKD3D_ERROR_NOT_IMPLEMENTED;
goto end;
}
}

if (compiler_args)
{
for (i = 0; i < compiler_args->target_extension_count; i++)
Expand Down
13 changes: 13 additions & 0 deletions libs/vkd3d/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,17 @@ static const struct vkd3d_shader_quirk_info veilguard_quirks = {
NULL, 0, VKD3D_SHADER_QUIRK_FORCE_DEVICE_MEMORY_BARRIER_THREAD_GROUP_COHERENCY,
};

static const struct vkd3d_shader_quirk_hash tfd_hashes[] = {
/* ReflectionCaptureFilteredImportanceSamplingCS is somewhat broken as it assumes
* that the lowest res mips are valid, but they are never written to by ReflectionCaptureGenerateMipmapCS.
* It stops at 8x8 (the workgroup size). The workaround just clamps the explicit LOD to whatever mips is 8x8. */
{ 0x74b8eaf23e3d166c, VKD3D_SHADER_QUIRK_ASSUME_BROKEN_SUB_8x8_CUBE_MIPS },
};

static const struct vkd3d_shader_quirk_info tfd_quirks = {
tfd_hashes, ARRAY_SIZE(tfd_hashes), 0,
};

static const struct vkd3d_shader_quirk_meta application_shader_quirks[] = {
/* F1 2020 (1080110) */
{ VKD3D_STRING_COMPARE_EXACT, "F1_2020_dx12.exe", &f1_2019_2020_quirks },
Expand Down Expand Up @@ -769,6 +780,8 @@ static const struct vkd3d_shader_quirk_meta application_shader_quirks[] = {
{ VKD3D_STRING_COMPARE_EXACT, "HuntGame.exe", &hunt_quirks },
/* Dragon Age: The Veilguard (1845910) */
{ VKD3D_STRING_COMPARE_EXACT, "Dragon Age The Veilguard.exe", &veilguard_quirks },
/* The First Descendant (2074920) */
{ VKD3D_STRING_COMPARE_EXACT, "M1-Win64-Shipping.exe", &tfd_quirks },
/* Unreal Engine 4 */
{ VKD3D_STRING_COMPARE_ENDS_WITH, "-Shipping.exe", &ue4_quirks },
/* MSVC fails to compile empty array. */
Expand Down

0 comments on commit a3fe231

Please sign in to comment.