From 7402d6ec949434c81c3f34a5ad33f4a022126e97 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Wed, 31 May 2023 20:51:03 +0200 Subject: [PATCH] (D3D11/D3D12) Small cleanups/micro-opts --- gfx/drivers/d3d11.c | 20 ++++----- gfx/drivers/d3d12.c | 103 +++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 63 deletions(-) diff --git a/gfx/drivers/d3d11.c b/gfx/drivers/d3d11.c index 3bf02ac749..aaf4c203db 100644 --- a/gfx/drivers/d3d11.c +++ b/gfx/drivers/d3d11.c @@ -191,8 +191,8 @@ d3d11_get_closest_match(D3D11Device device, DXGI_FORMAT desired_format, UINT des { UINT format_support; if (SUCCEEDED(device->lpVtbl->CheckFormatSupport(device, *format, - &format_support)) && - ((format_support & desired_format_support) == desired_format_support)) + &format_support)) + && ((format_support & desired_format_support) == desired_format_support)) break; format++; } @@ -366,9 +366,9 @@ static void d3d11_font_free(void* data, bool is_threaded) static int d3d11_font_get_message_width(void* data, const char* msg, size_t msg_len, float scale) { int i; - int delta_x = 0; + int delta_x = 0; const struct font_glyph* glyph_q = NULL; - d3d11_font_t* font = (d3d11_font_t*)data; + d3d11_font_t* font = (d3d11_font_t*)data; if (!font) return 0; @@ -453,13 +453,13 @@ static void d3d11_font_render_line( v->pos.x = (x + (glyph->draw_offset_x * scale)) / (float)d3d11->viewport.Width; v->pos.y = (y + (glyph->draw_offset_y * scale)) / (float)d3d11->viewport.Height; - v->pos.w = glyph->width * scale / (float)d3d11->viewport.Width; - v->pos.h = glyph->height * scale / (float)d3d11->viewport.Height; + v->pos.w = glyph->width * scale / (float)d3d11->viewport.Width; + v->pos.h = glyph->height * scale / (float)d3d11->viewport.Height; v->coords.u = glyph->atlas_offset_x / (float)font->texture.desc.Width; v->coords.v = glyph->atlas_offset_y / (float)font->texture.desc.Height; - v->coords.w = glyph->width / (float)font->texture.desc.Width; - v->coords.h = glyph->height / (float)font->texture.desc.Height; + v->coords.w = glyph->width / (float)font->texture.desc.Width; + v->coords.h = glyph->height / (float)font->texture.desc.Height; v->params.scaling = 1; v->params.rotation = 0; @@ -531,8 +531,8 @@ static void d3d11_font_render_message( return; /* If font line metrics are not supported just draw as usual */ - if (!font->font_driver->get_line_metrics || - !font->font_driver->get_line_metrics(font->font_data, &line_metrics)) + if ( !font->font_driver->get_line_metrics + || !font->font_driver->get_line_metrics(font->font_data, &line_metrics)) { size_t msg_len = strlen(msg); if (msg_len <= (unsigned)d3d11->sprites.capacity) diff --git a/gfx/drivers/d3d12.c b/gfx/drivers/d3d12.c index b54dfe30df..dc572eeaab 100644 --- a/gfx/drivers/d3d12.c +++ b/gfx/drivers/d3d12.c @@ -71,15 +71,6 @@ /* * D3D12 COMMON */ -static void -d3d12_descriptor_heap_slot_free(d3d12_descriptor_heap_t* heap, D3D12_CPU_DESCRIPTOR_HANDLE handle) -{ - unsigned i = (handle.ptr - heap->cpu.ptr) / heap->stride; - heap->map[i] = false; - if (heap->start > (int)i) - heap->start = i; -} - static D3D12_CPU_DESCRIPTOR_HANDLE d3d12_descriptor_heap_slot_alloc(d3d12_descriptor_heap_t* heap) { int i; @@ -108,10 +99,17 @@ static void d3d12_release_texture(d3d12_texture_t* texture) if (texture->srv_heap && texture->desc.MipLevels <= countof(texture->cpu_descriptor)) { int i; + d3d12_descriptor_heap_t *heap = texture->srv_heap; for (i = 0; i < texture->desc.MipLevels; i++) { - if (texture->cpu_descriptor[i].ptr) - d3d12_descriptor_heap_slot_free(texture->srv_heap, texture->cpu_descriptor[i]); + D3D12_CPU_DESCRIPTOR_HANDLE handle = texture->cpu_descriptor[i]; + if (handle.ptr) + { + unsigned _i = (handle.ptr - heap->cpu.ptr) / heap->stride; + heap->map[_i] = false; + if (heap->start > (int)_i) + heap->start = _i; + } texture->cpu_descriptor[i].ptr = 0; } } @@ -132,9 +130,9 @@ static DXGI_FORMAT d3d12_get_closest_match(D3D12Device device, D3D12_FEATURE_DAT { D3D12_FEATURE_DATA_FORMAT_SUPPORT format_support = { *format }; if (SUCCEEDED(device->lpVtbl->CheckFeatureSupport( - device, D3D12_FEATURE_FORMAT_SUPPORT, &format_support, sizeof(format_support))) && - ((format_support.Support1 & desired->Support1) == desired->Support1) && - ((format_support.Support2 & desired->Support2) == desired->Support2)) + device, D3D12_FEATURE_FORMAT_SUPPORT, &format_support, sizeof(format_support))) + && ((format_support.Support1 & desired->Support1) == desired->Support1) + && ((format_support.Support2 & desired->Support2) == desired->Support2)) break; format++; } @@ -148,8 +146,8 @@ static void d3d12_init_texture(D3D12Device device, d3d12_texture_t* texture) if (!texture->desc.MipLevels) texture->desc.MipLevels = 1; - if (!(texture->desc.Width >> (texture->desc.MipLevels - 1)) && - !(texture->desc.Height >> (texture->desc.MipLevels - 1))) + if ( !(texture->desc.Width >> (texture->desc.MipLevels - 1)) + && !(texture->desc.Height >> (texture->desc.MipLevels - 1))) { unsigned width = texture->desc.Width >> 5; unsigned height = texture->desc.Height >> 5; @@ -256,22 +254,14 @@ static void d3d12_update_texture( { uint8_t *dst; D3D12_RANGE read_range; - - if (!texture || !texture->upload_buffer) - return; - - read_range.Begin = 0; - read_range.End = 0; - - D3D12Map(texture->upload_buffer, 0, &read_range, (void**)&dst); - - dxgi_copy( - width, height, format, pitch, data, texture->desc.Format, + ID3D12Resource *resource = (ID3D12Resource*)texture->upload_buffer; + read_range.Begin = 0; + read_range.End = 0; + resource->lpVtbl->Map(resource, 0, &read_range, (void**)&dst); + dxgi_copy(width, height, format, pitch, data, texture->desc.Format, texture->layout.Footprint.RowPitch, dst + texture->layout.Offset); - - D3D12Unmap(texture->upload_buffer, 0, NULL); - - texture->dirty = true; + resource->lpVtbl->Unmap(resource, 0, NULL); + texture->dirty = true; } /* @@ -311,10 +301,11 @@ static void * d3d12_font_init(void* data, const char* font_path, font->texture.srv_heap = &d3d12->desc.srv_heap; d3d12_release_texture(&font->texture); d3d12_init_texture(d3d12->device, &font->texture); - d3d12_update_texture( - font->atlas->width, font->atlas->height, - font->atlas->width, DXGI_FORMAT_A8_UNORM, - font->atlas->buffer, &font->texture); + if (font->texture.upload_buffer) + d3d12_update_texture( + font->atlas->width, font->atlas->height, + font->atlas->width, DXGI_FORMAT_A8_UNORM, + font->atlas->buffer, &font->texture); font->atlas->dirty = false; return font; @@ -463,10 +454,11 @@ static void d3d12_font_render_line( if (font->atlas->dirty) { - d3d12_update_texture( - font->atlas->width, font->atlas->height, - font->atlas->width, DXGI_FORMAT_A8_UNORM, - font->atlas->buffer, &font->texture); + if (font->texture.upload_buffer) + d3d12_update_texture( + font->atlas->width, font->atlas->height, + font->atlas->width, DXGI_FORMAT_A8_UNORM, + font->atlas->buffer, &font->texture); font->atlas->dirty = false; } @@ -823,10 +815,11 @@ static bool d3d12_overlay_load(void* data, const void* image_data, unsigned num_ d3d12_release_texture(&d3d12->overlays.textures[i]); d3d12_init_texture(d3d12->device, &d3d12->overlays.textures[i]); - d3d12_update_texture( - images[i].width, images[i].height, - 0, DXGI_FORMAT_B8G8R8A8_UNORM, images[i].pixels, - &d3d12->overlays.textures[i]); + if (d3d12->overlays.textures[i].upload_buffer) + d3d12_update_texture( + images[i].width, images[i].height, + 0, DXGI_FORMAT_B8G8R8A8_UNORM, images[i].pixels, + &d3d12->overlays.textures[i]); sprites[i].pos.x = 0.0f; sprites[i].pos.y = 0.0f; @@ -1409,9 +1402,10 @@ static bool d3d12_gfx_set_shader(void* data, enum rarch_shader_type type, const d3d12_release_texture(&d3d12->luts[i]); d3d12_init_texture(d3d12->device, &d3d12->luts[i]); - d3d12_update_texture( - image.width, image.height, 0, DXGI_FORMAT_R8G8B8A8_UNORM, image.pixels, - &d3d12->luts[i]); + if (d3d12->luts[i].upload_buffer) + d3d12_update_texture( + image.width, image.height, 0, DXGI_FORMAT_R8G8B8A8_UNORM, image.pixels, + &d3d12->luts[i]); image_texture_free(&image); } @@ -3049,8 +3043,9 @@ static bool d3d12_gfx_frame( } else { - d3d12_update_texture(width, height, pitch, d3d12->format, - frame, &d3d12->frame.texture[0]); + if (d3d12->frame.texture[0].upload_buffer) + d3d12_update_texture(width, height, pitch, d3d12->format, + frame, &d3d12->frame.texture[0]); d3d12_upload_texture(cmd, &d3d12->frame.texture[0], d3d12); } @@ -3559,8 +3554,9 @@ static void d3d12_set_menu_texture_frame( d3d12_init_texture(d3d12->device, &d3d12->menu.texture); } - d3d12_update_texture(width, height, pitch, - format, frame, &d3d12->menu.texture); + if (d3d12->menu.texture.upload_buffer) + d3d12_update_texture(width, height, pitch, + format, frame, &d3d12->menu.texture); d3d12->menu.alpha = alpha; @@ -3667,9 +3663,10 @@ static uintptr_t d3d12_gfx_load_texture( d3d12_release_texture(texture); d3d12_init_texture(d3d12->device, texture); - d3d12_update_texture( - image->width, image->height, 0, - DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels, texture); + if (texture->upload_buffer) + d3d12_update_texture( + image->width, image->height, 0, + DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels, texture); return (uintptr_t)texture; }