mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-19 05:45:58 +00:00
d3d11: translate windows error codes to human readable strings
This will help with debugging.
This commit is contained in:
parent
da584995f6
commit
e9891dfe14
8 changed files with 95 additions and 34 deletions
|
@ -538,7 +538,7 @@ create_shader_input_resource (GstD3D11ColorConvert * self,
|
|||
|
||||
hr = ID3D11Device_CreateTexture2D (device_handle,
|
||||
&texture_desc, NULL, &tex[i]);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
|
||||
goto error;
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ create_shader_input_resource (GstD3D11ColorConvert * self,
|
|||
|
||||
hr = ID3D11Device_CreateTexture2D (device_handle,
|
||||
&texture_desc, NULL, &tex[0]);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
|
||||
goto error;
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ create_shader_input_resource (GstD3D11ColorConvert * self,
|
|||
hr = ID3D11Device_CreateShaderResourceView (device_handle,
|
||||
(ID3D11Resource *) tex[i], &view_desc, &view[i]);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (self,
|
||||
"Failed to create resource view (0x%x)", (guint) hr);
|
||||
goto error;
|
||||
|
@ -642,7 +642,7 @@ create_shader_output_resource (GstD3D11ColorConvert * self,
|
|||
|
||||
hr = ID3D11Device_CreateTexture2D (device_handle,
|
||||
&texture_desc, NULL, &tex[i]);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
|
||||
goto error;
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ create_shader_output_resource (GstD3D11ColorConvert * self,
|
|||
|
||||
hr = ID3D11Device_CreateTexture2D (device_handle,
|
||||
&texture_desc, NULL, &tex[0]);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (self, "Failed to create texture (0x%x)", (guint) hr);
|
||||
goto error;
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ create_shader_output_resource (GstD3D11ColorConvert * self,
|
|||
view_desc.Format = format->resource_format[i];
|
||||
hr = ID3D11Device_CreateRenderTargetView (device_handle,
|
||||
(ID3D11Resource *) tex[i], &view_desc, &view[i]);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (self,
|
||||
"Failed to create %dth render target view (0x%x)", i, (guint) hr);
|
||||
goto error;
|
||||
|
|
|
@ -567,7 +567,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Device * device,
|
|||
sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
|
||||
hr = ID3D11Device_CreateSamplerState (device_handle, &sampler_desc, &sampler);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("Couldn't create sampler state, hr: 0x%x", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
goto clear;
|
||||
|
@ -604,7 +604,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Device * device,
|
|||
hr = ID3D11Device_CreateBuffer (device_handle, &const_buffer_desc, NULL,
|
||||
&const_buffer);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("Couldn't create constant buffer, hr: 0x%x", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
goto clear;
|
||||
|
@ -613,7 +613,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Device * device,
|
|||
hr = ID3D11DeviceContext_Map (context_handle,
|
||||
(ID3D11Resource *) const_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("Couldn't map constant buffer, hr: 0x%x", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
goto clear;
|
||||
|
@ -658,7 +658,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Device * device,
|
|||
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL,
|
||||
&vertex_buffer);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("Couldn't create vertex buffer, hr: 0x%x", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
goto clear;
|
||||
|
@ -672,7 +672,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Device * device,
|
|||
hr = ID3D11Device_CreateBuffer (device_handle, &buffer_desc, NULL,
|
||||
&index_buffer);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("Couldn't create index buffer, hr: 0x%x", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
goto clear;
|
||||
|
@ -681,7 +681,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Device * device,
|
|||
hr = ID3D11DeviceContext_Map (context_handle,
|
||||
(ID3D11Resource *) vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("Couldn't map vertex buffer, hr: 0x%x", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
goto clear;
|
||||
|
@ -692,7 +692,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Device * device,
|
|||
hr = ID3D11DeviceContext_Map (context_handle,
|
||||
(ID3D11Resource *) index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("Couldn't map index buffer, hr: 0x%x", (guint) hr);
|
||||
ID3D11DeviceContext_Unmap (context_handle,
|
||||
(ID3D11Resource *) vertex_buffer, 0);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#endif
|
||||
|
||||
#include "gstd3d11device.h"
|
||||
#include "gstd3d11utils.h"
|
||||
#include "gmodule.h"
|
||||
|
||||
#ifdef HAVE_D3D11SDKLAYER_H
|
||||
|
@ -124,7 +125,7 @@ gst_d3d11_device_get_message (GstD3D11Device * self)
|
|||
for (i = 0; i < num_msg; i++) {
|
||||
hr = ID3D11InfoQueue_GetMessage (priv->info_queue, i, NULL, &msg_len);
|
||||
|
||||
if (FAILED (hr) || msg_len == 0) {
|
||||
if (!gst_d3d11_result (hr) || msg_len == 0) {
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -221,7 +222,7 @@ gst_d3d11_device_constructed (GObject * object)
|
|||
|
||||
#ifdef HAVE_DXGI_1_5_H
|
||||
hr = CreateDXGIFactory1 (&IID_IDXGIFactory5, (void **) &factory);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_INFO_OBJECT (self, "IDXGIFactory5 was unavailable");
|
||||
factory = NULL;
|
||||
}
|
||||
|
@ -234,7 +235,7 @@ gst_d3d11_device_constructed (GObject * object)
|
|||
hr = CreateDXGIFactory1 (&IID_IDXGIFactory1, (void **) &factory);
|
||||
}
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (self, "cannot create dxgi factory, hr: 0x%x", (guint) hr);
|
||||
goto error;
|
||||
}
|
||||
|
@ -284,7 +285,7 @@ gst_d3d11_device_constructed (GObject * object)
|
|||
D3D11_SDK_VERSION, &priv->device, &selected_level, &priv->device_context);
|
||||
priv->feature_level = selected_level;
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
/* Retry if the system could not recognize D3D_FEATURE_LEVEL_11_1 */
|
||||
hr = D3D11CreateDevice ((IDXGIAdapter *) adapter, D3D_DRIVER_TYPE_UNKNOWN,
|
||||
NULL, d3d11_flags, &feature_levels[1],
|
||||
|
@ -293,7 +294,7 @@ gst_d3d11_device_constructed (GObject * object)
|
|||
priv->feature_level = selected_level;
|
||||
}
|
||||
|
||||
if (SUCCEEDED (hr)) {
|
||||
if (gst_d3d11_result (hr)) {
|
||||
GST_DEBUG_OBJECT (self, "Selected feature level 0x%x", selected_level);
|
||||
} else {
|
||||
GST_ERROR_OBJECT (self, "cannot create d3d11 device, hr: 0x%x", (guint) hr);
|
||||
|
@ -711,7 +712,7 @@ gst_d3d11_device_create_swap_chain_internal (GstD3D11Device * device,
|
|||
hr = IDXGIFactory1_CreateSwapChain (priv->factory, (IUnknown *) priv->device,
|
||||
(DXGI_SWAP_CHAIN_DESC *) data->desc, &data->swap_chain);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (device, "Cannot create SwapChain Object: 0x%x",
|
||||
(guint) hr);
|
||||
data->swap_chain = NULL;
|
||||
|
@ -788,7 +789,7 @@ gst_d3d11_device_create_texture_internal (GstD3D11Device * device,
|
|||
|
||||
hr = ID3D11Device_CreateTexture2D (priv->device, data->desc,
|
||||
data->inital_data, &data->texture);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
const D3D11_TEXTURE2D_DESC *desc = data->desc;
|
||||
|
||||
GST_ERROR ("Failed to create texture (0x%x)", (guint) hr);
|
||||
|
|
|
@ -241,7 +241,7 @@ map_cpu_access_data (GstD3D11Device * device, D3D11MapData * map_data)
|
|||
hr = ID3D11DeviceContext_Map (device_context,
|
||||
staging, 0, map_data->map_type, 0, &dmem->map);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (GST_MEMORY_CAST (dmem)->allocator,
|
||||
"Failed to map staging texture (0x%x)", (guint) hr);
|
||||
map_data->ret = FALSE;
|
||||
|
@ -500,7 +500,7 @@ calculate_mem_size (GstD3D11Device * device, CalSizeData * data)
|
|||
hr = ID3D11DeviceContext_Map (device_context,
|
||||
data->texture, 0, data->map_mode, 0, &map);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (device, "Failed to map texture (0x%x)", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ create_shader_resource_views (GstD3D11Device * device, GstD3D11Memory * mem)
|
|||
(ID3D11Resource *) mem->texture, &resource_desc,
|
||||
&mem->shader_resource_view[i]);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (device,
|
||||
"Failed to create %dth resource view (0x%x)", i, (guint) hr);
|
||||
goto error;
|
||||
|
@ -640,7 +640,7 @@ create_render_target_views (GstD3D11Device * device, GstD3D11Memory * mem)
|
|||
hr = ID3D11Device_CreateRenderTargetView (device_handle,
|
||||
(ID3D11Resource *) mem->texture, &render_desc,
|
||||
&mem->render_target_view[i]);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (device,
|
||||
"Failed to create %dth render target view (0x%x)", i, (guint) hr);
|
||||
goto error;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "gstd3d11shader.h"
|
||||
#include "gstd3d11device.h"
|
||||
#include "gstd3d11utils.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_shader_debug);
|
||||
#define GST_CAT_DEFAULT gst_d3d11_shader_debug
|
||||
|
@ -54,7 +55,7 @@ compile_shader (GstD3D11Device * device, const gchar * shader_source,
|
|||
hr = D3DCompile (shader_source, strlen (shader_source), NULL, NULL, NULL,
|
||||
"main", shader_target, 0, 0, &ret, &error);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
const gchar *err = NULL;
|
||||
|
||||
if (error)
|
||||
|
@ -101,7 +102,7 @@ create_pixel_shader (GstD3D11Device * device, CreatePSData * data)
|
|||
(gpointer) ID3D10Blob_GetBufferPointer (ps_blob),
|
||||
ID3D10Blob_GetBufferSize (ps_blob), NULL, &data->shader);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("could not create pixel shader, hr: 0x%x", (guint) hr);
|
||||
data->ret = FALSE;
|
||||
}
|
||||
|
@ -162,7 +163,7 @@ create_vertex_shader (GstD3D11Device * device, CreateVSData * data)
|
|||
(gpointer) ID3D10Blob_GetBufferPointer (vs_blob),
|
||||
ID3D10Blob_GetBufferSize (vs_blob), NULL, &vshader);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("could not create vertex shader, hr: 0x%x", (guint) hr);
|
||||
ID3D10Blob_Release (vs_blob);
|
||||
data->ret = FALSE;
|
||||
|
@ -173,7 +174,7 @@ create_vertex_shader (GstD3D11Device * device, CreateVSData * data)
|
|||
data->desc_len, (gpointer) ID3D10Blob_GetBufferPointer (vs_blob),
|
||||
ID3D10Blob_GetBufferSize (vs_blob), &in_layout);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR ("could not create input layout shader, hr: 0x%x", (guint) hr);
|
||||
ID3D10Blob_Release (vs_blob);
|
||||
ID3D11VertexShader_Release (vshader);
|
||||
|
|
|
@ -350,7 +350,7 @@ upload_transform_dynamic (GstD3D11Device * device, UploadTransformData * data)
|
|||
hr = ID3D11DeviceContext_Map (device_context,
|
||||
(ID3D11Resource *) dmem->texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (filter,
|
||||
"Failed to map staging texture (0x%x)", (guint) hr);
|
||||
data->ret = GST_FLOW_ERROR;
|
||||
|
|
|
@ -58,6 +58,65 @@ gboolean gst_query_is_d3d11_usage (GstQuery * query);
|
|||
GstCaps * gst_d3d11_caps_fixate_format (GstCaps * caps,
|
||||
GstCaps * othercaps);
|
||||
|
||||
static void
|
||||
gst_d3d11_format_error (gint error_code, gchar ** str)
|
||||
{
|
||||
g_return_if_fail(str);
|
||||
|
||||
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL, error_code,
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)str, 0, NULL);
|
||||
};
|
||||
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
static inline gboolean
|
||||
_gst_d3d11_debug(HRESULT result, GstDebugCategory * category,
|
||||
const gchar * file, const gchar * function, gint line)
|
||||
{
|
||||
if (FAILED(result)) {
|
||||
gchar *error_text = NULL;
|
||||
|
||||
gst_d3d11_format_error(result,&error_text);
|
||||
gst_debug_log (category, GST_LEVEL_WARNING, file, function, line,
|
||||
NULL, "D3D11 call failed: 0x%x, %s", (guint)result, error_text);
|
||||
LocalFree(error_text);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_d3d11_result:
|
||||
* @result: D3D11 API return code #HRESULT
|
||||
*
|
||||
* Returns: %TRUE if D3D11 API call result is SUCCESS
|
||||
*/
|
||||
#define gst_d3d11_result(result) \
|
||||
_gst_d3d11_debug(result, GST_CAT_DEFAULT, __FILE__, GST_FUNCTION, __LINE__)
|
||||
#else
|
||||
|
||||
static inline gboolean
|
||||
_gst_d3d11_debug(HRESULT result, GstDebugCategory * category,
|
||||
const gchar * file, const gchar * function, gint line)
|
||||
{
|
||||
return SUCCESS(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_d3d11_result:
|
||||
* @result: D3D11 API return code #HRESULT
|
||||
*
|
||||
* Returns: %TRUE if D3D11 API call result is SUCCESS
|
||||
*/
|
||||
#define gst_d3d11_result(result) \
|
||||
_gst_d3d11_debug(result, NULL, __FILE__, GST_FUNCTION, __LINE__)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_D3D11_UTILS_H__ */
|
||||
|
|
|
@ -600,14 +600,14 @@ gst_d3d11_window_on_resize (GstD3D11Device * device, GstD3D11Window * window)
|
|||
|
||||
hr = IDXGISwapChain_ResizeBuffers (window->swap_chain,
|
||||
0, width, height, DXGI_FORMAT_UNKNOWN, 0);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (window, "Couldn't resize buffers, hr: 0x%x", (guint) hr);
|
||||
return;
|
||||
}
|
||||
|
||||
hr = IDXGISwapChain_GetBuffer (window->swap_chain,
|
||||
0, &IID_ID3D11Texture2D, (void **) &window->backbuffer);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (window,
|
||||
"Cannot get backbuffer from swapchain, hr: 0x%x", (guint) hr);
|
||||
return;
|
||||
|
@ -615,7 +615,7 @@ gst_d3d11_window_on_resize (GstD3D11Device * device, GstD3D11Window * window)
|
|||
|
||||
hr = ID3D11Device_CreateRenderTargetView (d3d11_dev,
|
||||
(ID3D11Resource *) window->backbuffer, NULL, &window->rtv);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_ERROR_OBJECT (window, "Cannot create render target view, hr: 0x%x",
|
||||
(guint) hr);
|
||||
return;
|
||||
|
@ -1023,7 +1023,7 @@ gst_d3d11_window_prepare (GstD3D11Window * window, guint width, guint height,
|
|||
hr = IDXGISwapChain4_SetHDRMetaData ((IDXGISwapChain4 *)
|
||||
window->swap_chain, DXGI_HDR_METADATA_TYPE_HDR10,
|
||||
sizeof (DXGI_HDR_METADATA_HDR10), &metadata);
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_WARNING_OBJECT (window, "Couldn't set HDR metadata, hr 0x%x",
|
||||
(guint) hr);
|
||||
}
|
||||
|
@ -1184,7 +1184,7 @@ _present_on_device_thread (GstD3D11Device * device, FramePresentData * data)
|
|||
|
||||
hr = IDXGISwapChain_Present (self->swap_chain, 0, DXGI_PRESENT_DO_NOT_WAIT);
|
||||
|
||||
if (FAILED (hr)) {
|
||||
if (!gst_d3d11_result (hr)) {
|
||||
GST_WARNING_OBJECT (self, "Direct3D cannot present texture, hr: 0x%x",
|
||||
(guint) hr);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue