d3d12memory: Add alloc_wrapped() method

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5870>
This commit is contained in:
Seungha Yang 2023-12-24 01:28:26 +09:00 committed by GStreamer Marge Bot
parent 3308a976bd
commit d316356bf2
2 changed files with 33 additions and 20 deletions

View file

@ -726,18 +726,30 @@ gst_d3d12_allocator_free (GstAllocator * allocator, GstMemory * mem)
g_free (dmem); g_free (dmem);
} }
static GstMemory * GstMemory *
gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * self, gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * allocator,
GstD3D12Device * device, const D3D12_RESOURCE_DESC * desc, GstD3D12Device * device, ID3D12Resource * resource, guint array_slice)
D3D12_RESOURCE_STATES initial_state, ID3D12Resource * resource,
guint array_slice)
{ {
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), nullptr);
g_return_val_if_fail (resource, nullptr);
if (!allocator) {
gst_d3d12_memory_init_once ();
allocator = _d3d12_memory_allocator;
}
auto device_handle = gst_d3d12_device_get_device_handle (device); auto device_handle = gst_d3d12_device_get_device_handle (device);
auto desc = resource->GetDesc ();
guint8 num_subresources = guint8 num_subresources =
D3D12GetFormatPlaneCount (device_handle, desc->Format); D3D12GetFormatPlaneCount (device_handle, desc.Format);
if (num_subresources == 0) { if (num_subresources == 0) {
GST_ERROR_OBJECT (self, "Couldn't get format info"); GST_ERROR_OBJECT (allocator, "Couldn't get format info");
return nullptr;
}
if (array_slice >= desc.DepthOrArraySize) {
GST_ERROR_OBJECT (allocator, "Invalid array slice");
return nullptr; return nullptr;
} }
@ -745,8 +757,7 @@ gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * self,
mem->priv = new GstD3D12MemoryPrivate (); mem->priv = new GstD3D12MemoryPrivate ();
auto priv = mem->priv; auto priv = mem->priv;
priv->desc = desc;
priv->desc = *desc;
priv->num_subresources = num_subresources; priv->num_subresources = num_subresources;
priv->resource = resource; priv->resource = resource;
gst_d3d12_dxgi_format_to_resource_formats (priv->desc.Format, gst_d3d12_dxgi_format_to_resource_formats (priv->desc.Format,
@ -779,11 +790,10 @@ gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * self,
* +-------------+-------------+-------------+ * +-------------+-------------+-------------+
*/ */
mem->priv->subresource_index[i] = D3D12CalcSubresource (0, mem->priv->subresource_index[i] = D3D12CalcSubresource (0,
array_slice, i, 1, desc->DepthOrArraySize); array_slice, i, 1, desc.DepthOrArraySize);
device_handle->GetCopyableFootprints (&priv->desc, device_handle->GetCopyableFootprints (&desc, priv->subresource_index[i],
priv->subresource_index[i], 1, 0, &priv->layout[i], nullptr, nullptr, 1, 0, &priv->layout[i], nullptr, nullptr, &size);
&size);
/* Update offset manually */ /* Update offset manually */
priv->layout[i].Offset = priv->size; priv->layout[i].Offset = priv->size;
@ -791,11 +801,11 @@ gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * self,
} }
gst_memory_init (GST_MEMORY_CAST (mem), gst_memory_init (GST_MEMORY_CAST (mem),
(GstMemoryFlags) 0, GST_ALLOCATOR_CAST (self), nullptr, (GstMemoryFlags) 0, GST_ALLOCATOR_CAST (allocator), nullptr,
mem->priv->size, 0, 0, mem->priv->size); mem->priv->size, 0, 0, mem->priv->size);
GST_LOG_OBJECT (self, "Allocated new memory %p with size %" G_GUINT64_FORMAT, GST_LOG_OBJECT (allocator,
mem, priv->size); "Allocated new memory %p with size %" G_GUINT64_FORMAT, mem, priv->size);
return GST_MEMORY_CAST (mem); return GST_MEMORY_CAST (mem);
} }
@ -819,8 +829,7 @@ gst_d3d12_allocator_alloc_internal (GstD3D12Allocator * self,
return nullptr; return nullptr;
} }
return gst_d3d12_allocator_alloc_wrapped (self, device, desc, return gst_d3d12_allocator_alloc_wrapped (self, device, resource.Get (), 0);
initial_state, resource.Get (), 0);
} }
GstMemory * GstMemory *
@ -973,8 +982,7 @@ gst_d3d12_pool_allocator_start (GstD3D12PoolAllocator * self)
GstMemory *mem; GstMemory *mem;
mem = gst_d3d12_allocator_alloc_wrapped (_d3d12_memory_allocator, mem = gst_d3d12_allocator_alloc_wrapped (_d3d12_memory_allocator,
self->device, &priv->desc, self->device, priv->resource.Get (), i);
priv->initial_state, priv->resource.Get (), i);
priv->cur_mems++; priv->cur_mems++;
priv->queue.push (mem); priv->queue.push (mem);

View file

@ -188,6 +188,11 @@ GstMemory * gst_d3d12_allocator_alloc (GstD3D12Allocator * allocator,
D3D12_RESOURCE_STATES initial_state, D3D12_RESOURCE_STATES initial_state,
const D3D12_CLEAR_VALUE * optimized_clear_value); const D3D12_CLEAR_VALUE * optimized_clear_value);
GstMemory * gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * allocator,
GstD3D12Device * device,
ID3D12Resource * resource,
guint array_slice);
gboolean gst_d3d12_allocator_set_active (GstD3D12Allocator * allocator, gboolean gst_d3d12_allocator_set_active (GstD3D12Allocator * allocator,
gboolean active); gboolean active);