d3d12: Use CREATE_NOT_ZEROED heap flag if possible

Zero initialization would have overhead and it's not required
most cases except for textures. Use CREATE_NOT_ZEROED flag
in case of buffer resource or if a texture will be rendered without any
prior read operation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5875>
This commit is contained in:
Seungha Yang 2024-01-01 01:18:18 +09:00 committed by GStreamer Marge Bot
parent a1ba38cd64
commit 0ce6e752e4
6 changed files with 47 additions and 25 deletions

View file

@ -435,7 +435,8 @@ struct BackgroundRender
sizeof (indices));
hr = device_handle->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_GENERIC_READ,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED, &buffer_desc,
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr, IID_PPV_ARGS (&vertex_index_upload));
if (!gst_d3d12_result (hr, device)) {
GST_ERROR_OBJECT (device, "Couldn't create vertex upload buf");
@ -456,7 +457,8 @@ struct BackgroundRender
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
hr = device_handle->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_NONE, &buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED, &buffer_desc,
D3D12_RESOURCE_STATE_COPY_DEST,
nullptr, IID_PPV_ARGS (&vertex_index_buf));
if (!gst_d3d12_result (hr, device)) {
GST_ERROR_OBJECT (device, "Couldn't create index buffer");

View file

@ -756,7 +756,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
resource_desc =
CD3DX12_RESOURCE_DESC::Buffer (sizeof (VertexData) * 4 +
sizeof (g_indices));
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS (&priv->vertex_index_buf));
if (!gst_d3d12_result (hr, self->device)) {
@ -773,7 +774,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
priv->idv.Format = DXGI_FORMAT_R16_UINT;
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD);
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&upload_data->vertex_index_upload));
if (!gst_d3d12_result (hr, self->device)) {
@ -796,7 +798,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
{
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
resource_desc = CD3DX12_RESOURCE_DESC::Buffer (sizeof (PSConstBuffer));
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS (&priv->ps_const_buf));
if (!gst_d3d12_result (hr, self->device)) {
@ -805,7 +808,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
}
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD);
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&upload_data->ps_const_upload));
if (!gst_d3d12_result (hr, self->device)) {
@ -828,7 +832,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
resource_desc = CD3DX12_RESOURCE_DESC::Tex1D (DXGI_FORMAT_R16_UNORM,
GAMMA_LUT_SIZE, 1, 1);
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS (&priv->gamma_dec_lut));
if (!gst_d3d12_result (hr, self->device)) {
@ -836,7 +841,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
return FALSE;
}
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS (&priv->gamma_enc_lut));
if (!gst_d3d12_result (hr, self->device)) {
@ -851,7 +857,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD);
resource_desc = CD3DX12_RESOURCE_DESC::Buffer (gamma_lut_size);
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&upload_data->gamma_dec_lut_upload));
if (!gst_d3d12_result (hr, self->device)) {
@ -859,7 +866,8 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
return FALSE;
}
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&resource_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&upload_data->gamma_enc_lut_upload));
if (!gst_d3d12_result (hr, self->device)) {

View file

@ -1037,7 +1037,7 @@ gst_d3d12_decoder_upload_bitstream (GstD3D12Decoder * self, gpointer data,
CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD);
D3D12_RESOURCE_DESC desc = CD3DX12_RESOURCE_DESC::Buffer (alloc_size);
hr = priv->cmd->device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_NONE, &desc,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED, &desc,
D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS (&bitstream));
if (!gst_d3d12_result (hr, self->device)) {
GST_ERROR_OBJECT (self, "Failed to create bitstream buffer");
@ -1363,7 +1363,8 @@ gst_d3d12_decoder_ensure_staging_texture (GstD3D12Decoder * self)
(D3D12_HEAP_TYPE_READBACK);
D3D12_RESOURCE_DESC desc = CD3DX12_RESOURCE_DESC::Buffer (size);
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS (&staging));
if (!gst_d3d12_result (hr, self->device))
return FALSE;

View file

@ -242,7 +242,8 @@ gst_d3d12_memory_ensure_staging_resource (GstD3D12Memory * dmem)
D3D12_MEMORY_POOL_L0);
D3D12_RESOURCE_DESC desc = CD3DX12_RESOURCE_DESC::Buffer (priv->size);
ComPtr < ID3D12Resource > staging;
hr = device->CreateCommittedResource (&prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS (&staging));
if (!gst_d3d12_result (hr, dmem->device)) {
GST_ERROR_OBJECT (dmem->device, "Couldn't create staging resource");

View file

@ -203,7 +203,8 @@ gst_d3d12_overlay_rect_new (GstD3D12OverlayCompositor * self,
vmeta->height, 1, 1);
ComPtr < ID3D12Resource > texture;
auto hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
auto hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS (&texture));
if (!gst_d3d12_result (hr, self->device)) {
GST_ERROR_OBJECT (self, "Couldn't create texture");
@ -218,7 +219,8 @@ gst_d3d12_overlay_rect_new (GstD3D12OverlayCompositor * self,
ComPtr < ID3D12Resource > staging;
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD);
desc = CD3DX12_RESOURCE_DESC::Buffer (size);
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&staging));
if (!gst_d3d12_result (hr, self->device)) {
@ -303,7 +305,8 @@ gst_d3d12_overlay_rect_new (GstD3D12OverlayCompositor * self,
ComPtr < ID3D12Resource > vertex_buf;
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD);
desc = CD3DX12_RESOURCE_DESC::Buffer (sizeof (VertexData) * 4);
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&vertex_buf));
if (!gst_d3d12_result (hr, self->device)) {
@ -491,7 +494,8 @@ gst_d3d12_overlay_compositor_setup_shader (GstD3D12OverlayCompositor * self)
D3D12_RESOURCE_DESC buffer_desc =
CD3DX12_RESOURCE_DESC::Buffer (sizeof (indices));
ComPtr < ID3D12Resource > index_buf;
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&buffer_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&index_buf));
if (!gst_d3d12_result (hr, self->device)) {

View file

@ -535,7 +535,8 @@ setup_snow_render (GstD3D12TestSrc * self, RenderContext * ctx,
CD3DX12_RESOURCE_DESC::Buffer (sizeof (UvVertexData) * 4
+ sizeof (indices));
ComPtr < ID3D12Resource > vertex_index_upload;
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&buffer_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&vertex_index_upload));
if (!gst_d3d12_result (hr, self->device)) {
@ -557,7 +558,8 @@ setup_snow_render (GstD3D12TestSrc * self, RenderContext * ctx,
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
ComPtr < ID3D12Resource > vertex_index_buf;
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS (&vertex_index_buf));
if (!gst_d3d12_result (hr, self->device)) {
@ -910,7 +912,8 @@ setup_smpte_render (GstD3D12TestSrc * self, RenderContext * ctx)
CD3DX12_RESOURCE_DESC::Buffer (sizeof (ColorVertexData) * 4 * 20
+ sizeof (WORD) * 6 * 20);
ComPtr < ID3D12Resource > vertex_index_upload;
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&buffer_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&vertex_index_upload));
if (!gst_d3d12_result (hr, self->device)) {
@ -933,7 +936,8 @@ setup_smpte_render (GstD3D12TestSrc * self, RenderContext * ctx)
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
ComPtr < ID3D12Resource > vertex_index_buf;
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS (&vertex_index_buf));
if (!gst_d3d12_result (hr, self->device)) {
@ -1075,7 +1079,8 @@ setup_checker_render (GstD3D12TestSrc * self, RenderContext * ctx,
CD3DX12_RESOURCE_DESC::Buffer (sizeof (UvVertexData) * 4
+ sizeof (indices));
ComPtr < ID3D12Resource > vertex_index_upload;
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&buffer_desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
IID_PPV_ARGS (&vertex_index_upload));
if (!gst_d3d12_result (hr, self->device)) {
@ -1097,7 +1102,8 @@ setup_checker_render (GstD3D12TestSrc * self, RenderContext * ctx,
heap_prop = CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
ComPtr < ID3D12Resource > vertex_index_buf;
hr = device->CreateCommittedResource (&heap_prop, D3D12_HEAP_FLAG_NONE,
hr = device->CreateCommittedResource (&heap_prop,
D3D12_HEAP_FLAG_CREATE_NOT_ZEROED,
&buffer_desc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
IID_PPV_ARGS (&vertex_index_buf));
if (!gst_d3d12_result (hr, self->device)) {
@ -1539,7 +1545,7 @@ gst_d3d12_test_src_setup_context (GstD3D12TestSrc * self, GstCaps * caps)
D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET |
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
D3D12_CLEAR_VALUE clear_value = { };
D3D12_HEAP_FLAGS heap_flags = D3D12_HEAP_FLAG_NONE;
D3D12_HEAP_FLAGS heap_flags = D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
clear_value.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
clear_value.Color[0] = 0.0f;
clear_value.Color[1] = 0.0f;
@ -1565,7 +1571,7 @@ gst_d3d12_test_src_setup_context (GstD3D12TestSrc * self, GstCaps * caps)
break;
case GST_D3D12_TEST_SRC_CIRCULAR:
case GST_D3D12_TEST_SRC_BALL:
heap_flags = D3D12_HEAP_FLAG_SHARED;
heap_flags |= D3D12_HEAP_FLAG_SHARED;
break;
default:
break;