mirror of
https://github.com/libretro/RetroArch
synced 2025-02-07 03:40:24 +00:00
(D3D11/D3D12) Small cleanups/micro-opts
This commit is contained in:
parent
29584b9960
commit
7402d6ec94
@ -191,8 +191,8 @@ d3d11_get_closest_match(D3D11Device device, DXGI_FORMAT desired_format, UINT des
|
|||||||
{
|
{
|
||||||
UINT format_support;
|
UINT format_support;
|
||||||
if (SUCCEEDED(device->lpVtbl->CheckFormatSupport(device, *format,
|
if (SUCCEEDED(device->lpVtbl->CheckFormatSupport(device, *format,
|
||||||
&format_support)) &&
|
&format_support))
|
||||||
((format_support & desired_format_support) == desired_format_support))
|
&& ((format_support & desired_format_support) == desired_format_support))
|
||||||
break;
|
break;
|
||||||
format++;
|
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)
|
static int d3d11_font_get_message_width(void* data, const char* msg, size_t msg_len, float scale)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int delta_x = 0;
|
int delta_x = 0;
|
||||||
const struct font_glyph* glyph_q = NULL;
|
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)
|
if (!font)
|
||||||
return 0;
|
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.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.y = (y + (glyph->draw_offset_y * scale)) / (float)d3d11->viewport.Height;
|
||||||
v->pos.w = glyph->width * scale / (float)d3d11->viewport.Width;
|
v->pos.w = glyph->width * scale / (float)d3d11->viewport.Width;
|
||||||
v->pos.h = glyph->height * scale / (float)d3d11->viewport.Height;
|
v->pos.h = glyph->height * scale / (float)d3d11->viewport.Height;
|
||||||
|
|
||||||
v->coords.u = glyph->atlas_offset_x / (float)font->texture.desc.Width;
|
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.v = glyph->atlas_offset_y / (float)font->texture.desc.Height;
|
||||||
v->coords.w = glyph->width / (float)font->texture.desc.Width;
|
v->coords.w = glyph->width / (float)font->texture.desc.Width;
|
||||||
v->coords.h = glyph->height / (float)font->texture.desc.Height;
|
v->coords.h = glyph->height / (float)font->texture.desc.Height;
|
||||||
|
|
||||||
v->params.scaling = 1;
|
v->params.scaling = 1;
|
||||||
v->params.rotation = 0;
|
v->params.rotation = 0;
|
||||||
@ -531,8 +531,8 @@ static void d3d11_font_render_message(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* If font line metrics are not supported just draw as usual */
|
/* If font line metrics are not supported just draw as usual */
|
||||||
if (!font->font_driver->get_line_metrics ||
|
if ( !font->font_driver->get_line_metrics
|
||||||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
|| !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
||||||
{
|
{
|
||||||
size_t msg_len = strlen(msg);
|
size_t msg_len = strlen(msg);
|
||||||
if (msg_len <= (unsigned)d3d11->sprites.capacity)
|
if (msg_len <= (unsigned)d3d11->sprites.capacity)
|
||||||
|
@ -71,15 +71,6 @@
|
|||||||
/*
|
/*
|
||||||
* D3D12 COMMON
|
* 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)
|
static D3D12_CPU_DESCRIPTOR_HANDLE d3d12_descriptor_heap_slot_alloc(d3d12_descriptor_heap_t* heap)
|
||||||
{
|
{
|
||||||
int i;
|
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))
|
if (texture->srv_heap && texture->desc.MipLevels <= countof(texture->cpu_descriptor))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
d3d12_descriptor_heap_t *heap = texture->srv_heap;
|
||||||
for (i = 0; i < texture->desc.MipLevels; i++)
|
for (i = 0; i < texture->desc.MipLevels; i++)
|
||||||
{
|
{
|
||||||
if (texture->cpu_descriptor[i].ptr)
|
D3D12_CPU_DESCRIPTOR_HANDLE handle = texture->cpu_descriptor[i];
|
||||||
d3d12_descriptor_heap_slot_free(texture->srv_heap, 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;
|
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 };
|
D3D12_FEATURE_DATA_FORMAT_SUPPORT format_support = { *format };
|
||||||
if (SUCCEEDED(device->lpVtbl->CheckFeatureSupport(
|
if (SUCCEEDED(device->lpVtbl->CheckFeatureSupport(
|
||||||
device, D3D12_FEATURE_FORMAT_SUPPORT, &format_support, sizeof(format_support))) &&
|
device, D3D12_FEATURE_FORMAT_SUPPORT, &format_support, sizeof(format_support)))
|
||||||
((format_support.Support1 & desired->Support1) == desired->Support1) &&
|
&& ((format_support.Support1 & desired->Support1) == desired->Support1)
|
||||||
((format_support.Support2 & desired->Support2) == desired->Support2))
|
&& ((format_support.Support2 & desired->Support2) == desired->Support2))
|
||||||
break;
|
break;
|
||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
@ -148,8 +146,8 @@ static void d3d12_init_texture(D3D12Device device, d3d12_texture_t* texture)
|
|||||||
if (!texture->desc.MipLevels)
|
if (!texture->desc.MipLevels)
|
||||||
texture->desc.MipLevels = 1;
|
texture->desc.MipLevels = 1;
|
||||||
|
|
||||||
if (!(texture->desc.Width >> (texture->desc.MipLevels - 1)) &&
|
if ( !(texture->desc.Width >> (texture->desc.MipLevels - 1))
|
||||||
!(texture->desc.Height >> (texture->desc.MipLevels - 1)))
|
&& !(texture->desc.Height >> (texture->desc.MipLevels - 1)))
|
||||||
{
|
{
|
||||||
unsigned width = texture->desc.Width >> 5;
|
unsigned width = texture->desc.Width >> 5;
|
||||||
unsigned height = texture->desc.Height >> 5;
|
unsigned height = texture->desc.Height >> 5;
|
||||||
@ -256,22 +254,14 @@ static void d3d12_update_texture(
|
|||||||
{
|
{
|
||||||
uint8_t *dst;
|
uint8_t *dst;
|
||||||
D3D12_RANGE read_range;
|
D3D12_RANGE read_range;
|
||||||
|
ID3D12Resource *resource = (ID3D12Resource*)texture->upload_buffer;
|
||||||
if (!texture || !texture->upload_buffer)
|
read_range.Begin = 0;
|
||||||
return;
|
read_range.End = 0;
|
||||||
|
resource->lpVtbl->Map(resource, 0, &read_range, (void**)&dst);
|
||||||
read_range.Begin = 0;
|
dxgi_copy(width, height, format, pitch, data, texture->desc.Format,
|
||||||
read_range.End = 0;
|
|
||||||
|
|
||||||
D3D12Map(texture->upload_buffer, 0, &read_range, (void**)&dst);
|
|
||||||
|
|
||||||
dxgi_copy(
|
|
||||||
width, height, format, pitch, data, texture->desc.Format,
|
|
||||||
texture->layout.Footprint.RowPitch, dst + texture->layout.Offset);
|
texture->layout.Footprint.RowPitch, dst + texture->layout.Offset);
|
||||||
|
resource->lpVtbl->Unmap(resource, 0, NULL);
|
||||||
D3D12Unmap(texture->upload_buffer, 0, NULL);
|
texture->dirty = true;
|
||||||
|
|
||||||
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;
|
font->texture.srv_heap = &d3d12->desc.srv_heap;
|
||||||
d3d12_release_texture(&font->texture);
|
d3d12_release_texture(&font->texture);
|
||||||
d3d12_init_texture(d3d12->device, &font->texture);
|
d3d12_init_texture(d3d12->device, &font->texture);
|
||||||
d3d12_update_texture(
|
if (font->texture.upload_buffer)
|
||||||
font->atlas->width, font->atlas->height,
|
d3d12_update_texture(
|
||||||
font->atlas->width, DXGI_FORMAT_A8_UNORM,
|
font->atlas->width, font->atlas->height,
|
||||||
font->atlas->buffer, &font->texture);
|
font->atlas->width, DXGI_FORMAT_A8_UNORM,
|
||||||
|
font->atlas->buffer, &font->texture);
|
||||||
font->atlas->dirty = false;
|
font->atlas->dirty = false;
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
@ -463,10 +454,11 @@ static void d3d12_font_render_line(
|
|||||||
|
|
||||||
if (font->atlas->dirty)
|
if (font->atlas->dirty)
|
||||||
{
|
{
|
||||||
d3d12_update_texture(
|
if (font->texture.upload_buffer)
|
||||||
font->atlas->width, font->atlas->height,
|
d3d12_update_texture(
|
||||||
font->atlas->width, DXGI_FORMAT_A8_UNORM,
|
font->atlas->width, font->atlas->height,
|
||||||
font->atlas->buffer, &font->texture);
|
font->atlas->width, DXGI_FORMAT_A8_UNORM,
|
||||||
|
font->atlas->buffer, &font->texture);
|
||||||
font->atlas->dirty = false;
|
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_release_texture(&d3d12->overlays.textures[i]);
|
||||||
d3d12_init_texture(d3d12->device, &d3d12->overlays.textures[i]);
|
d3d12_init_texture(d3d12->device, &d3d12->overlays.textures[i]);
|
||||||
d3d12_update_texture(
|
if (d3d12->overlays.textures[i].upload_buffer)
|
||||||
images[i].width, images[i].height,
|
d3d12_update_texture(
|
||||||
0, DXGI_FORMAT_B8G8R8A8_UNORM, images[i].pixels,
|
images[i].width, images[i].height,
|
||||||
&d3d12->overlays.textures[i]);
|
0, DXGI_FORMAT_B8G8R8A8_UNORM, images[i].pixels,
|
||||||
|
&d3d12->overlays.textures[i]);
|
||||||
|
|
||||||
sprites[i].pos.x = 0.0f;
|
sprites[i].pos.x = 0.0f;
|
||||||
sprites[i].pos.y = 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_release_texture(&d3d12->luts[i]);
|
||||||
d3d12_init_texture(d3d12->device, &d3d12->luts[i]);
|
d3d12_init_texture(d3d12->device, &d3d12->luts[i]);
|
||||||
|
|
||||||
d3d12_update_texture(
|
if (d3d12->luts[i].upload_buffer)
|
||||||
image.width, image.height, 0, DXGI_FORMAT_R8G8B8A8_UNORM, image.pixels,
|
d3d12_update_texture(
|
||||||
&d3d12->luts[i]);
|
image.width, image.height, 0, DXGI_FORMAT_R8G8B8A8_UNORM, image.pixels,
|
||||||
|
&d3d12->luts[i]);
|
||||||
|
|
||||||
image_texture_free(&image);
|
image_texture_free(&image);
|
||||||
}
|
}
|
||||||
@ -3049,8 +3043,9 @@ static bool d3d12_gfx_frame(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d3d12_update_texture(width, height, pitch, d3d12->format,
|
if (d3d12->frame.texture[0].upload_buffer)
|
||||||
frame, &d3d12->frame.texture[0]);
|
d3d12_update_texture(width, height, pitch, d3d12->format,
|
||||||
|
frame, &d3d12->frame.texture[0]);
|
||||||
|
|
||||||
d3d12_upload_texture(cmd, &d3d12->frame.texture[0], d3d12);
|
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_init_texture(d3d12->device, &d3d12->menu.texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
d3d12_update_texture(width, height, pitch,
|
if (d3d12->menu.texture.upload_buffer)
|
||||||
format, frame, &d3d12->menu.texture);
|
d3d12_update_texture(width, height, pitch,
|
||||||
|
format, frame, &d3d12->menu.texture);
|
||||||
|
|
||||||
d3d12->menu.alpha = alpha;
|
d3d12->menu.alpha = alpha;
|
||||||
|
|
||||||
@ -3667,9 +3663,10 @@ static uintptr_t d3d12_gfx_load_texture(
|
|||||||
d3d12_release_texture(texture);
|
d3d12_release_texture(texture);
|
||||||
d3d12_init_texture(d3d12->device, texture);
|
d3d12_init_texture(d3d12->device, texture);
|
||||||
|
|
||||||
d3d12_update_texture(
|
if (texture->upload_buffer)
|
||||||
image->width, image->height, 0,
|
d3d12_update_texture(
|
||||||
DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels, texture);
|
image->width, image->height, 0,
|
||||||
|
DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels, texture);
|
||||||
|
|
||||||
return (uintptr_t)texture;
|
return (uintptr_t)texture;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user