(D3D11) Look at D3D11 feature level - if we are 11.0 or above,

we use Shader Model 5.0 instead of the default SM 4.0 - this fixes
FSR on D3D11 which requires SM5.0
This commit is contained in:
twinaphex 2021-09-03 07:51:44 +02:00
parent b900555494
commit 274638b89e
3 changed files with 107 additions and 25 deletions

View File

@ -226,30 +226,52 @@ bool d3d11_init_shader(
LPCSTR gs_entry,
const D3D11_INPUT_ELEMENT_DESC* input_element_descs,
UINT num_elements,
d3d11_shader_t* out)
d3d11_shader_t* out,
enum d3d11_feature_level_hint hint)
{
D3DBlob vs_code = NULL;
D3DBlob ps_code = NULL;
D3DBlob gs_code = NULL;
D3DBlob vs_code = NULL;
D3DBlob ps_code = NULL;
D3DBlob gs_code = NULL;
bool success = true;
const char *vs_str = NULL;
const char *ps_str = NULL;
const char *gs_str = NULL;
bool success = true;
switch (hint)
{
case D3D11_FEATURE_LEVEL_HINT_11_0:
case D3D11_FEATURE_LEVEL_HINT_11_1:
case D3D11_FEATURE_LEVEL_HINT_12_0:
case D3D11_FEATURE_LEVEL_HINT_12_1:
case D3D11_FEATURE_LEVEL_HINT_12_2:
vs_str = "vs_5_0";
ps_str = "ps_5_0";
gs_str = "gs_5_0";
break;
case D3D11_FEATURE_LEVEL_HINT_DONTCARE:
default:
vs_str = "vs_4_0";
ps_str = "ps_4_0";
gs_str = "gs_4_0";
break;
}
if (!src) /* LPCWSTR filename */
{
if (vs_entry && !d3d_compile_from_file((LPCWSTR)src_name, vs_entry, "vs_4_0", &vs_code))
if (vs_entry && !d3d_compile_from_file((LPCWSTR)src_name, vs_entry, vs_str, &vs_code))
success = false;
if (ps_entry && !d3d_compile_from_file((LPCWSTR)src_name, ps_entry, "ps_4_0", &ps_code))
if (ps_entry && !d3d_compile_from_file((LPCWSTR)src_name, ps_entry, ps_str, &ps_code))
success = false;
if (gs_entry && !d3d_compile_from_file((LPCWSTR)src_name, gs_entry, "gs_4_0", &gs_code))
if (gs_entry && !d3d_compile_from_file((LPCWSTR)src_name, gs_entry, gs_str, &gs_code))
success = false;
}
else /* char array */
{
if (vs_entry && !d3d_compile(src, size, (LPCSTR)src_name, vs_entry, "vs_4_0", &vs_code))
if (vs_entry && !d3d_compile(src, size, (LPCSTR)src_name, vs_entry, vs_str, &vs_code))
success = false;
if (ps_entry && !d3d_compile(src, size, (LPCSTR)src_name, ps_entry, "ps_4_0", &ps_code))
if (ps_entry && !d3d_compile(src, size, (LPCSTR)src_name, ps_entry, ps_str, &ps_code))
success = false;
if (gs_entry && !d3d_compile(src, size, (LPCSTR)src_name, gs_entry, "gs_4_0", &gs_code))
if (gs_entry && !d3d_compile(src, size, (LPCSTR)src_name, gs_entry, gs_str, &gs_code))
success = false;
}

View File

@ -2664,6 +2664,22 @@ void d3d11_update_texture(
DXGI_FORMAT d3d11_get_closest_match(
D3D11Device device, DXGI_FORMAT desired_format, UINT desired_format_support);
enum d3d11_feature_level_hint
{
D3D11_FEATURE_LEVEL_HINT_DONTCARE,
D3D11_FEATURE_LEVEL_HINT_1_0_CORE,
D3D11_FEATURE_LEVEL_HINT_9_1,
D3D11_FEATURE_LEVEL_HINT_9_2,
D3D11_FEATURE_LEVEL_HINT_9_3,
D3D11_FEATURE_LEVEL_HINT_10_0,
D3D11_FEATURE_LEVEL_HINT_10_1,
D3D11_FEATURE_LEVEL_HINT_11_0,
D3D11_FEATURE_LEVEL_HINT_11_1,
D3D11_FEATURE_LEVEL_HINT_12_0,
D3D11_FEATURE_LEVEL_HINT_12_1,
D3D11_FEATURE_LEVEL_HINT_12_2
};
bool d3d11_init_shader(
D3D11Device device,
const char* src,
@ -2674,7 +2690,8 @@ bool d3d11_init_shader(
LPCSTR gs_entry,
const D3D11_INPUT_ELEMENT_DESC* input_element_descs,
UINT num_elements,
d3d11_shader_t* out);
d3d11_shader_t* out,
enum d3d11_feature_level_hint hint);
static INLINE void d3d11_release_shader(d3d11_shader_t* shader)
{

View File

@ -433,13 +433,39 @@ static void d3d11_free_shader_preset(d3d11_video_t* d3d11)
static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const char* path)
{
#if defined(HAVE_SLANG) && defined(HAVE_SPIRV_CROSS)
enum d3d11_feature_level_hint
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_DONTCARE;
unsigned i;
d3d11_texture_t* source = NULL;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
unsigned shader_model = 40;
if (!d3d11)
return false;
/* Feature Level 11.0 and up should all support Shader Model 5.0 */
switch (d3d11->supportedFeatureLevel)
{
case D3D_FEATURE_LEVEL_11_0:
shader_model = 50;
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_11_0;
break;
case D3D_FEATURE_LEVEL_11_1:
shader_model = 50;
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_11_1;
break;
case D3D_FEATURE_LEVEL_12_0:
shader_model = 50;
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_12_0;
break;
case D3D_FEATURE_LEVEL_12_1:
shader_model = 50;
feat_level_hint = D3D11_FEATURE_LEVEL_HINT_12_1;
break;
default:
break;
}
D3D11Flush(d3d11->context);
d3d11_free_shader_preset(d3d11);
@ -499,7 +525,8 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
/* clang-format on */
if (!slang_process(
d3d11->shader_preset, i, RARCH_SHADER_HLSL, 40, &semantics_map,
d3d11->shader_preset, i, RARCH_SHADER_HLSL, shader_model,
&semantics_map,
&d3d11->pass[i].semantics))
goto error;
@ -530,12 +557,16 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
if (!d3d11_init_shader(
d3d11->device, vs_src, 0, vs_path, "main", NULL, NULL, desc, countof(desc),
&d3d11->pass[i].shader))
&d3d11->pass[i].shader,
feat_level_hint
))
save_hlsl = true;
if (!d3d11_init_shader(
d3d11->device, ps_src, 0, ps_path, NULL, "main", NULL, NULL, 0,
&d3d11->pass[i].shader))
&d3d11->pass[i].shader,
feat_level_hint
))
save_hlsl = true;
if (save_hlsl)
@ -1230,7 +1261,9 @@ static void *d3d11_gfx_init(const video_info_t* video,
if (!d3d11_init_shader(
d3d11->device, shader, sizeof(shader),
NULL, "VSMain", "PSMain", NULL, desc,
countof(desc), &d3d11->shaders[VIDEO_SHADER_STOCK_HDR]))
countof(desc), &d3d11->shaders[VIDEO_SHADER_STOCK_HDR],
D3D11_FEATURE_LEVEL_HINT_DONTCARE
))
goto error;
}
#endif
@ -1251,7 +1284,9 @@ static void *d3d11_gfx_init(const video_info_t* video,
if (!d3d11_init_shader(
d3d11->device, shader, sizeof(shader), NULL, "VSMain", "PSMain", NULL, desc,
countof(desc), &d3d11->shaders[VIDEO_SHADER_STOCK_BLEND]))
countof(desc), &d3d11->shaders[VIDEO_SHADER_STOCK_BLEND],
D3D11_FEATURE_LEVEL_HINT_DONTCARE
))
goto error;
}
@ -1279,11 +1314,13 @@ static void *d3d11_gfx_init(const video_info_t* video,
if (!d3d11_init_shader(
d3d11->device, shader, sizeof(shader), NULL, "VSMain", "PSMain", "GSMain", desc,
countof(desc), &d3d11->sprites.shader))
countof(desc), &d3d11->sprites.shader,
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
if (!d3d11_init_shader(
d3d11->device, shader, sizeof(shader), NULL, "VSMain", "PSMainA8", "GSMain", desc,
countof(desc), &d3d11->sprites.shader_font))
countof(desc), &d3d11->sprites.shader_font,
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
}
@ -1303,12 +1340,14 @@ static void *d3d11_gfx_init(const video_info_t* video,
if (!d3d11_init_shader(
d3d11->device, ribbon, sizeof(ribbon), NULL, "VSMain", "PSMain", NULL, desc,
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU]))
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU],
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
if (!d3d11_init_shader(
d3d11->device, ribbon_simple, sizeof(ribbon_simple), NULL, "VSMain", "PSMain", NULL,
desc, countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_2]))
desc, countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_2],
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
}
@ -1335,21 +1374,25 @@ static void *d3d11_gfx_init(const video_info_t* video,
if (!d3d11_init_shader(
d3d11->device, simple_snow, sizeof(simple_snow), NULL, "VSMain", "PSMain", NULL,
desc, countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_3]))
desc, countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_3],
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
if (!d3d11_init_shader(
d3d11->device, snow, sizeof(snow), NULL, "VSMain", "PSMain", NULL, desc,
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_4]))
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_4],
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
if (!d3d11_init_shader(
d3d11->device, bokeh, sizeof(bokeh), NULL, "VSMain", "PSMain", NULL, desc,
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_5]))
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_5],
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
if (!d3d11_init_shader(
d3d11->device, snowflake, sizeof(snowflake), NULL, "VSMain", "PSMain", NULL, desc,
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_6]))
countof(desc), &d3d11->shaders[VIDEO_SHADER_MENU_6],
D3D11_FEATURE_LEVEL_HINT_DONTCARE))
goto error;
}
}