d3d11: Use shader model 4

Since shader model 4 is sufficient for the current pixel shader
implementations, prebuild HLSL with shader model 4 as well.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5709>
This commit is contained in:
Seungha Yang 2023-11-25 01:52:44 +09:00
parent df0e6c4140
commit 721533d042
4 changed files with 45 additions and 82 deletions

View file

@ -1677,45 +1677,16 @@ gst_d3d11_device_get_pixel_shader_uncached (GstD3D11Device * device,
"Creating pixel shader for token %" G_GINT64_FORMAT ", source:\n%s",
token, source);
if (priv->feature_level >= D3D_FEATURE_LEVEL_11_0) {
if (bytecode && bytecode_size > 1) {
data = bytecode;
size = bytecode_size;
GST_DEBUG_OBJECT (device,
"Creating shader \"%s\" using precompiled bytecode", entry_point);
} else {
hr = gst_d3d11_shader_cache_get_pixel_shader_blob (token,
source, source_size, entry_point, defines, &blob);
if (!gst_d3d11_result (hr, device))
return hr;
data = blob->GetBufferPointer ();
size = blob->GetBufferSize ();
}
if (bytecode && bytecode_size > 1) {
data = bytecode;
size = bytecode_size;
GST_DEBUG_OBJECT (device,
"Creating shader \"%s\" using precompiled bytecode", entry_point);
} else {
ComPtr < ID3DBlob > error_msg;
const gchar *target;
if (priv->feature_level >= D3D_FEATURE_LEVEL_10_0)
target = "ps_4_0";
else if (priv->feature_level >= D3D_FEATURE_LEVEL_9_3)
target = "ps_4_0_level_9_3";
else
target = "ps_4_0_level_9_1";
hr = gst_d3d11_compile (source, source_size, nullptr, defines,
nullptr, entry_point, target, 0, 0, &blob, &error_msg);
if (!gst_d3d11_result (hr, device)) {
const gchar *err = nullptr;
if (error_msg)
err = (const gchar *) error_msg->GetBufferPointer ();
GST_ERROR_OBJECT (device,
"Couldn't compile code, hr: 0x%x, error detail: %s, source code: \n%s",
(guint) hr, GST_STR_NULL (err), source);
hr = gst_d3d11_shader_cache_get_pixel_shader_blob (token,
source, source_size, entry_point, defines, &blob);
if (!gst_d3d11_result (hr, device))
return hr;
}
data = blob->GetBufferPointer ();
size = blob->GetBufferSize ();
@ -1779,6 +1750,9 @@ gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, gint64 token,
HRESULT hr;
ComPtr < ID3D11VertexShader > shader;
ComPtr < ID3D11InputLayout > input_layout;
ComPtr < ID3DBlob > blob;
const void *data;
gsize size;
GST_DEBUG_OBJECT (device, "Getting vertext shader \"%s\" for token %"
G_GINT64_FORMAT, entry_point, token);
@ -1800,41 +1774,30 @@ gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, gint64 token,
"Creating vertex shader for token %" G_GINT64_FORMAT ", shader: \n%s",
token, source);
if (priv->feature_level >= D3D_FEATURE_LEVEL_11_0) {
ComPtr < ID3DBlob > blob;
const void *data;
gsize size;
if (bytecode && bytecode_size > 1) {
data = bytecode;
size = bytecode_size;
GST_DEBUG_OBJECT (device,
"Creating shader \"%s\" using precompiled bytecode", entry_point);
} else {
hr = gst_d3d11_shader_cache_get_vertex_shader_blob (token,
source, source_size, entry_point, &blob);
if (!gst_d3d11_result (hr, device))
return hr;
data = blob->GetBufferPointer ();
size = blob->GetBufferSize ();
}
hr = priv->device->CreateVertexShader (data, size, nullptr, &shader);
if (!gst_d3d11_result (hr, device))
return hr;
hr = priv->device->CreateInputLayout (input_desc, desc_len, data,
size, &input_layout);
if (!gst_d3d11_result (hr, device))
return hr;
if (bytecode && bytecode_size > 1) {
data = bytecode;
size = bytecode_size;
GST_DEBUG_OBJECT (device,
"Creating shader \"%s\" using precompiled bytecode", entry_point);
} else {
hr = gst_d3d11_create_vertex_shader_simple (device, source, entry_point,
input_desc, desc_len, &shader, &input_layout);
hr = gst_d3d11_shader_cache_get_vertex_shader_blob (token,
source, source_size, entry_point, &blob);
if (!gst_d3d11_result (hr, device))
return hr;
data = blob->GetBufferPointer ();
size = blob->GetBufferSize ();
}
hr = priv->device->CreateVertexShader (data, size, nullptr, &shader);
if (!gst_d3d11_result (hr, device))
return hr;
hr = priv->device->CreateInputLayout (input_desc, desc_len, data,
size, &input_layout);
if (!gst_d3d11_result (hr, device))
return hr;
GST_DEBUG_OBJECT (device, "Created vertex shader \"%s\" for token %"
G_GINT64_FORMAT, entry_point, token);
priv->vs_cache[token] = std::make_pair (shader, input_layout);

View file

@ -49,7 +49,7 @@ gst_d3d11_shader_cache_get_pixel_shader_blob (gint64 token,
}
HRESULT hr = gst_d3d11_compile (source, source_size, nullptr, defines,
nullptr, entry_point, "ps_5_0", 0, 0, blob, nullptr);
nullptr, entry_point, "ps_4_0", 0, 0, blob, nullptr);
if (FAILED (hr))
return hr;
@ -74,7 +74,7 @@ gst_d3d11_shader_cache_get_vertex_shader_blob (gint64 token,
}
HRESULT hr = gst_d3d11_compile (source, source_size, nullptr, nullptr,
nullptr, entry_point, "vs_5_0", 0, 0, blob, nullptr);
nullptr, entry_point, "vs_4_0", 0, 0, blob, nullptr);
if (FAILED (hr))
return hr;

View file

@ -83,7 +83,7 @@ foreach input_format : hlsl_ps_input_formats
output : header,
command : [fxc, '/Fh', '@OUTPUT@',
'/E', entry_point,
'/T', 'ps_5_0',
'/T', 'ps_4_0',
'/D', 'BUILDING_HLSL=1',
'/D', 'OUTPUT_TYPE=@0@'.format(output_type),
'/D', 'ENTRY_POINT=@0@'.format(entry_point),
@ -109,7 +109,7 @@ generated_collection = custom_target(header_collection,
hlsl_precompiled += generated_collection
hlsl_vs_sources = [
[files('VSMain_converter.hlsl'), 'VSMain_converter', 'vs_5_0'],
[files('VSMain_converter.hlsl'), 'VSMain_converter', 'vs_4_0'],
]
foreach shader : hlsl_vs_sources

View file

@ -1,15 +1,15 @@
hlsl_sources = [
['PSMain_checker_luma', 'ps_5_0'],
['PSMain_checker_rgb', 'ps_5_0'],
['PSMain_checker_vuya', 'ps_5_0'],
['PSMain_checker', 'ps_5_0'],
['PSMain_color', 'ps_5_0'],
['PSMain_sample_premul', 'ps_5_0'],
['PSMain_sample', 'ps_5_0'],
['PSMain_snow', 'ps_5_0'],
['VSMain_color', 'vs_5_0'],
['VSMain_coord', 'vs_5_0'],
['VSMain_pos', 'vs_5_0'],
['PSMain_checker_luma', 'ps_4_0'],
['PSMain_checker_rgb', 'ps_4_0'],
['PSMain_checker_vuya', 'ps_4_0'],
['PSMain_checker', 'ps_4_0'],
['PSMain_color', 'ps_4_0'],
['PSMain_sample_premul', 'ps_4_0'],
['PSMain_sample', 'ps_4_0'],
['PSMain_snow', 'ps_4_0'],
['VSMain_color', 'vs_4_0'],
['VSMain_coord', 'vs_4_0'],
['VSMain_pos', 'vs_4_0'],
]
foreach shader : hlsl_sources