d3d12: Add support for mipmap texture

Consider D3D12_RESOURCE_DESC.MipLevels > 1 or zero case

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7555>
This commit is contained in:
Seungha Yang 2024-09-20 22:56:08 +09:00 committed by GStreamer Marge Bot
parent f1aedd65f4
commit 8550ed5888
4 changed files with 33 additions and 3 deletions

View file

@ -205,7 +205,7 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
if (params->d3d12_format.dxgi_format != DXGI_FORMAT_UNKNOWN) {
desc[0] = CD3DX12_RESOURCE_DESC::Tex2D (params->d3d12_format.dxgi_format,
params->aligned_info.width, params->aligned_info.height,
params->array_size, 1, 1, 0, params->resource_flags);
params->array_size, params->mip_levels, 1, 0, params->resource_flags);
gst_d3d12_buffer_pool_do_align (desc[0]);
@ -218,6 +218,7 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
auto single_array_desc = desc[0];
single_array_desc.DepthOrArraySize = 1;
single_array_desc.MipLevels = 1;
UINT64 mem_size;
device->GetCopyableFootprints (&single_array_desc, 0, num_planes, 0,
@ -247,7 +248,8 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
desc[i] =
CD3DX12_RESOURCE_DESC::Tex2D (params->d3d12_format.resource_format[i],
width, height, params->array_size, 1, 1, 0, params->resource_flags);
width, height, params->array_size, params->mip_levels, 1, 0,
params->resource_flags);
gst_d3d12_buffer_pool_do_align (desc[i]);
@ -257,6 +259,7 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
D3D12_RESOURCE_STATE_COMMON, nullptr);
UINT64 mem_size;
desc[i].MipLevels = 1;
device->GetCopyableFootprints (&desc[i], 0, 1, 0,
&layout[i], nullptr, nullptr, &mem_size);

View file

@ -36,6 +36,7 @@ struct _GstD3D12AllocationParams
D3D12_HEAP_FLAGS heap_flags;
D3D12_RESOURCE_FLAGS resource_flags;
guint array_size;
guint mip_levels;
};
G_END_DECLS

View file

@ -130,6 +130,7 @@ gst_d3d12_allocation_params_new (GstD3D12Device * device,
ret->aligned_info = *info;
ret->d3d12_format = d3d12_format;
ret->array_size = 1;
ret->mip_levels = 1;
ret->flags = flags;
ret->heap_flags = heap_flags;
ret->resource_flags = resource_flags;
@ -300,6 +301,26 @@ gst_d3d12_allocation_params_set_array_size (GstD3D12AllocationParams * params,
return TRUE;
}
/**
* gst_d3d12_allocation_params_set_mip_levels:
* @params: a #GstD3D12AllocationParams
* @mip_levels: a texture mip levels
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_allocation_params_set_mip_levels (GstD3D12AllocationParams * params,
guint mip_levels)
{
g_return_val_if_fail (params, FALSE);
params->mip_levels = mip_levels;
return TRUE;
}
/* *INDENT-OFF* */
struct GstD3D12MemoryTokenData
{
@ -786,7 +807,7 @@ gst_d3d12_memory_get_shader_resource_view_heap (GstD3D12Memory * mem)
D3D12_SHADER_RESOURCE_VIEW_DESC srv_desc = { };
srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srv_desc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srv_desc.Texture2D.MipLevels = 1;
srv_desc.Texture2D.MipLevels = priv->desc.MipLevels;
auto cpu_handle =
CD3DX12_CPU_DESCRIPTOR_HANDLE (GetCPUDescriptorHandleForHeapStart
@ -1413,6 +1434,7 @@ gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * allocator,
/* Then calculate staging memory size and copyable layout */
UINT64 size;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
device_handle->GetCopyableFootprints (&desc, 0,
num_subresources, 0, priv->layout, nullptr, nullptr, &size);
priv->size = size;

View file

@ -150,6 +150,10 @@ GST_D3D12_API
gboolean gst_d3d12_allocation_params_set_array_size (GstD3D12AllocationParams * params,
guint size);
GST_D3D12_API
gboolean gst_d3d12_allocation_params_set_mip_levels (GstD3D12AllocationParams * params,
guint mip_levels);
/**
* GstD3D12Memory:
*