mirror of
https://github.com/libretro/RetroArch
synced 2025-03-23 19:21:03 +00:00
(D3D11) autogen mipmaps when needed.
This commit is contained in:
parent
ccc9d36949
commit
2a54cbca75
@ -59,9 +59,6 @@ void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture)
|
|||||||
Release(texture->staging);
|
Release(texture->staging);
|
||||||
Release(texture->view);
|
Release(texture->view);
|
||||||
|
|
||||||
// .Usage = D3D11_USAGE_DYNAMIC,
|
|
||||||
// .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE,
|
|
||||||
|
|
||||||
texture->desc.MipLevels = 1;
|
texture->desc.MipLevels = 1;
|
||||||
texture->desc.ArraySize = 1;
|
texture->desc.ArraySize = 1;
|
||||||
texture->desc.SampleDesc.Count = 1;
|
texture->desc.SampleDesc.Count = 1;
|
||||||
@ -69,7 +66,20 @@ void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture)
|
|||||||
texture->desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
texture->desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||||
texture->desc.CPUAccessFlags =
|
texture->desc.CPUAccessFlags =
|
||||||
texture->desc.Usage == D3D11_USAGE_DYNAMIC ? D3D11_CPU_ACCESS_WRITE : 0;
|
texture->desc.Usage == D3D11_USAGE_DYNAMIC ? D3D11_CPU_ACCESS_WRITE : 0;
|
||||||
texture->desc.MiscFlags = 0;
|
|
||||||
|
if (texture->desc.MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS)
|
||||||
|
{
|
||||||
|
texture->desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
|
||||||
|
unsigned width = texture->desc.Width >> 5;
|
||||||
|
unsigned height = texture->desc.Height >> 5;
|
||||||
|
while (width && height)
|
||||||
|
{
|
||||||
|
width >>= 1;
|
||||||
|
height >>= 1;
|
||||||
|
texture->desc.MipLevels++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
D3D11CreateTexture2D(device, &texture->desc, NULL, &texture->handle);
|
D3D11CreateTexture2D(device, &texture->desc, NULL, &texture->handle);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -84,7 +94,9 @@ void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture)
|
|||||||
|
|
||||||
{
|
{
|
||||||
D3D11_TEXTURE2D_DESC desc = texture->desc;
|
D3D11_TEXTURE2D_DESC desc = texture->desc;
|
||||||
|
desc.MipLevels = 1;
|
||||||
desc.BindFlags = 0;
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
desc.Usage = D3D11_USAGE_STAGING;
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
D3D11CreateTexture2D(device, &desc, NULL, &texture->staging);
|
D3D11CreateTexture2D(device, &desc, NULL, &texture->staging);
|
||||||
@ -101,6 +113,7 @@ void d3d11_update_texture(
|
|||||||
d3d11_texture_t* texture)
|
d3d11_texture_t* texture)
|
||||||
{
|
{
|
||||||
D3D11_MAPPED_SUBRESOURCE mapped_texture;
|
D3D11_MAPPED_SUBRESOURCE mapped_texture;
|
||||||
|
D3D11_BOX frame_box = { 0, 0, 0, width, height, 1 };
|
||||||
|
|
||||||
D3D11MapTexture2D(ctx, texture->staging, 0, D3D11_MAP_WRITE, 0, &mapped_texture);
|
D3D11MapTexture2D(ctx, texture->staging, 0, D3D11_MAP_WRITE, 0, &mapped_texture);
|
||||||
|
|
||||||
@ -110,8 +123,11 @@ void d3d11_update_texture(
|
|||||||
|
|
||||||
D3D11UnmapTexture2D(ctx, texture->staging, 0);
|
D3D11UnmapTexture2D(ctx, texture->staging, 0);
|
||||||
|
|
||||||
if (texture->desc.Usage == D3D11_USAGE_DEFAULT)
|
D3D11CopyTexture2DSubresourceRegion(
|
||||||
texture->dirty = true;
|
ctx, texture->handle, 0, 0, 0, 0, texture->staging, 0, &frame_box);
|
||||||
|
|
||||||
|
if (texture->desc.MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS)
|
||||||
|
D3D11GenerateMips(ctx, texture->view);
|
||||||
}
|
}
|
||||||
|
|
||||||
DXGI_FORMAT
|
DXGI_FORMAT
|
||||||
|
@ -2470,7 +2470,7 @@ typedef struct
|
|||||||
D3D11Texture2D staging;
|
D3D11Texture2D staging;
|
||||||
D3D11_TEXTURE2D_DESC desc;
|
D3D11_TEXTURE2D_DESC desc;
|
||||||
D3D11ShaderResourceView view;
|
D3D11ShaderResourceView view;
|
||||||
bool dirty;
|
D3D11SamplerState sampler;
|
||||||
} d3d11_texture_t;
|
} d3d11_texture_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -2521,7 +2521,6 @@ typedef struct
|
|||||||
{
|
{
|
||||||
d3d11_texture_t texture;
|
d3d11_texture_t texture;
|
||||||
D3D11Buffer vbo;
|
D3D11Buffer vbo;
|
||||||
D3D11SamplerState sampler;
|
|
||||||
bool enabled;
|
bool enabled;
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
} menu;
|
} menu;
|
||||||
@ -2530,7 +2529,6 @@ typedef struct
|
|||||||
d3d11_texture_t texture;
|
d3d11_texture_t texture;
|
||||||
D3D11Buffer vbo;
|
D3D11Buffer vbo;
|
||||||
D3D11Buffer ubo;
|
D3D11Buffer ubo;
|
||||||
D3D11SamplerState sampler;
|
|
||||||
D3D11_VIEWPORT viewport;
|
D3D11_VIEWPORT viewport;
|
||||||
int rotation;
|
int rotation;
|
||||||
} frame;
|
} frame;
|
||||||
@ -2567,3 +2565,10 @@ d3d11_get_closest_match_texture2D(D3D11Device device, DXGI_FORMAT desired_format
|
|||||||
device, desired_format,
|
device, desired_format,
|
||||||
D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE);
|
D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline d3d11_set_texture_and_sampler(
|
||||||
|
D3D11DeviceContext ctx, UINT slot, d3d11_texture_t* texture)
|
||||||
|
{
|
||||||
|
D3D11SetPShaderResources(ctx, slot, 1, &texture->view);
|
||||||
|
D3D11SetPShaderSamplers(ctx, slot, 1, &texture->sampler);
|
||||||
|
}
|
||||||
|
@ -35,9 +35,9 @@ static void d3d11_set_filtering(void* data, unsigned index, bool smooth)
|
|||||||
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
||||||
|
|
||||||
if (smooth)
|
if (smooth)
|
||||||
d3d11->frame.sampler = d3d11->sampler_linear;
|
d3d11->frame.texture.sampler = d3d11->sampler_linear;
|
||||||
else
|
else
|
||||||
d3d11->frame.sampler = d3d11->sampler_nearest;
|
d3d11->frame.texture.sampler = d3d11->sampler_nearest;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void d3d11_gfx_set_rotation(void* data, unsigned rotation)
|
static void d3d11_gfx_set_rotation(void* data, unsigned rotation)
|
||||||
@ -467,9 +467,6 @@ static bool d3d11_gfx_frame(
|
|||||||
|
|
||||||
d3d11_update_texture(
|
d3d11_update_texture(
|
||||||
d3d11->ctx, width, height, pitch, d3d11->format, frame, &d3d11->frame.texture);
|
d3d11->ctx, width, height, pitch, d3d11->format, frame, &d3d11->frame.texture);
|
||||||
D3D11CopyTexture2DSubresourceRegion(
|
|
||||||
d3d11->ctx, d3d11->frame.texture.handle, 0, 0, 0, 0, d3d11->frame.texture.staging, 0,
|
|
||||||
&frame_box);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -482,8 +479,7 @@ static bool d3d11_gfx_frame(
|
|||||||
d3d11_update_viewport(d3d11, false);
|
d3d11_update_viewport(d3d11, false);
|
||||||
|
|
||||||
D3D11SetViewports(d3d11->ctx, 1, &d3d11->frame.viewport);
|
D3D11SetViewports(d3d11->ctx, 1, &d3d11->frame.viewport);
|
||||||
D3D11SetPShaderResources(d3d11->ctx, 0, 1, &d3d11->frame.texture.view);
|
d3d11_set_texture_and_sampler(d3d11->ctx, 0, &d3d11->frame.texture);
|
||||||
D3D11SetPShaderSamplers(d3d11->ctx, 0, 1, &d3d11->frame.sampler);
|
|
||||||
|
|
||||||
D3D11SetVertexBuffers(d3d11->ctx, 0, 1, &d3d11->frame.vbo, &stride, &offset);
|
D3D11SetVertexBuffers(d3d11->ctx, 0, 1, &d3d11->frame.vbo, &stride, &offset);
|
||||||
D3D11SetVShaderConstantBuffers(d3d11->ctx, 0, 1, &d3d11->frame.ubo);
|
D3D11SetVShaderConstantBuffers(d3d11->ctx, 0, 1, &d3d11->frame.ubo);
|
||||||
@ -493,20 +489,11 @@ static bool d3d11_gfx_frame(
|
|||||||
|
|
||||||
if (d3d11->menu.enabled && d3d11->menu.texture.handle)
|
if (d3d11->menu.enabled && d3d11->menu.texture.handle)
|
||||||
{
|
{
|
||||||
if (d3d11->menu.texture.dirty)
|
|
||||||
{
|
|
||||||
D3D11CopyTexture2DSubresourceRegion(
|
|
||||||
d3d11->ctx, d3d11->menu.texture.handle, 0, 0, 0, 0, d3d11->menu.texture.staging,
|
|
||||||
0, NULL);
|
|
||||||
d3d11->menu.texture.dirty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d3d11->menu.fullscreen)
|
if (d3d11->menu.fullscreen)
|
||||||
D3D11SetViewports(d3d11->ctx, 1, &d3d11->viewport);
|
D3D11SetViewports(d3d11->ctx, 1, &d3d11->viewport);
|
||||||
D3D11SetVertexBuffers(d3d11->ctx, 0, 1, &d3d11->menu.vbo, &stride, &offset);
|
D3D11SetVertexBuffers(d3d11->ctx, 0, 1, &d3d11->menu.vbo, &stride, &offset);
|
||||||
D3D11SetVShaderConstantBuffers(d3d11->ctx, 0, 1, &d3d11->ubo);
|
D3D11SetVShaderConstantBuffers(d3d11->ctx, 0, 1, &d3d11->ubo);
|
||||||
D3D11SetPShaderResources(d3d11->ctx, 0, 1, &d3d11->menu.texture.view);
|
d3d11_set_texture_and_sampler(d3d11->ctx, 0, &d3d11->menu.texture);
|
||||||
D3D11SetPShaderSamplers(d3d11->ctx, 0, 1, &d3d11->menu.sampler);
|
|
||||||
|
|
||||||
D3D11Draw(d3d11->ctx, 4, 0);
|
D3D11Draw(d3d11->ctx, 4, 0);
|
||||||
}
|
}
|
||||||
@ -521,7 +508,6 @@ static bool d3d11_gfx_frame(
|
|||||||
D3D11SetInputLayout(d3d11->ctx, d3d11->sprites.layout);
|
D3D11SetInputLayout(d3d11->ctx, d3d11->sprites.layout);
|
||||||
D3D11SetPrimitiveTopology(d3d11->ctx, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
D3D11SetPrimitiveTopology(d3d11->ctx, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
|
||||||
D3D11SetVertexBuffers(d3d11->ctx, 0, 1, &d3d11->sprites.vbo, &sprite_stride, &offset);
|
D3D11SetVertexBuffers(d3d11->ctx, 0, 1, &d3d11->sprites.vbo, &sprite_stride, &offset);
|
||||||
D3D11SetPShaderSamplers(d3d11->ctx, 0, 1, &d3d11->sampler_linear);
|
|
||||||
D3D11SetBlendState(d3d11->ctx, d3d11->blend_enable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
D3D11SetBlendState(d3d11->ctx, d3d11->blend_enable, NULL, D3D11_DEFAULT_SAMPLE_MASK);
|
||||||
|
|
||||||
d3d11->sprites.enabled = true;
|
d3d11->sprites.enabled = true;
|
||||||
@ -621,7 +607,7 @@ static void d3d11_set_menu_texture_frame(
|
|||||||
}
|
}
|
||||||
|
|
||||||
d3d11_update_texture(d3d11->ctx, width, height, pitch, format, frame, &d3d11->menu.texture);
|
d3d11_update_texture(d3d11->ctx, width, height, pitch, format, frame, &d3d11->menu.texture);
|
||||||
d3d11->menu.sampler = config_get_ptr()->bools.menu_linear_filter ? d3d11->sampler_linear
|
d3d11->menu.texture.sampler = config_get_ptr()->bools.menu_linear_filter ? d3d11->sampler_linear
|
||||||
: d3d11->sampler_nearest;
|
: d3d11->sampler_nearest;
|
||||||
}
|
}
|
||||||
static void d3d11_set_menu_texture_enable(void* data, bool state, bool full_screen)
|
static void d3d11_set_menu_texture_enable(void* data, bool state, bool full_screen)
|
||||||
@ -672,13 +658,28 @@ static uintptr_t d3d11_gfx_load_texture(
|
|||||||
{
|
{
|
||||||
d3d11_video_t* d3d11 = (d3d11_video_t*)video_data;
|
d3d11_video_t* d3d11 = (d3d11_video_t*)video_data;
|
||||||
struct texture_image* image = (struct texture_image*)data;
|
struct texture_image* image = (struct texture_image*)data;
|
||||||
D3D11_BOX frame_box = { 0, 0, 0, image->width, image->height, 1 };
|
|
||||||
|
|
||||||
if (!d3d11)
|
if (!d3d11)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
d3d11_texture_t* texture = calloc(1, sizeof(*texture));
|
d3d11_texture_t* texture = calloc(1, sizeof(*texture));
|
||||||
|
|
||||||
|
switch(filter_type)
|
||||||
|
{
|
||||||
|
case TEXTURE_FILTER_MIPMAP_LINEAR:
|
||||||
|
texture->desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
||||||
|
/* fallthrough */
|
||||||
|
case TEXTURE_FILTER_LINEAR:
|
||||||
|
texture->sampler = d3d11->sampler_linear;
|
||||||
|
break;
|
||||||
|
case TEXTURE_FILTER_MIPMAP_NEAREST:
|
||||||
|
texture->desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
|
||||||
|
/* fallthrough */
|
||||||
|
case TEXTURE_FILTER_NEAREST:
|
||||||
|
texture->sampler = d3d11->sampler_nearest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
texture->desc.Width = image->width;
|
texture->desc.Width = image->width;
|
||||||
texture->desc.Height = image->height;
|
texture->desc.Height = image->height;
|
||||||
texture->desc.Format =
|
texture->desc.Format =
|
||||||
@ -689,8 +690,6 @@ static uintptr_t d3d11_gfx_load_texture(
|
|||||||
d3d11_update_texture(
|
d3d11_update_texture(
|
||||||
d3d11->ctx, image->width, image->height, 0, DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels,
|
d3d11->ctx, image->width, image->height, 0, DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels,
|
||||||
texture);
|
texture);
|
||||||
D3D11CopyTexture2DSubresourceRegion(
|
|
||||||
d3d11->ctx, texture->handle, 0, 0, 0, 0, texture->staging, 0, &frame_box);
|
|
||||||
|
|
||||||
return (uintptr_t)texture;
|
return (uintptr_t)texture;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ d3d11_font_init_font(void* data, const char* font_path, float font_size, bool is
|
|||||||
}
|
}
|
||||||
|
|
||||||
font->atlas = font->font_driver->get_atlas(font->font_data);
|
font->atlas = font->font_driver->get_atlas(font->font_data);
|
||||||
|
font->texture.sampler = d3d11->sampler_linear;
|
||||||
font->texture.desc.Width = font->atlas->width;
|
font->texture.desc.Width = font->atlas->width;
|
||||||
font->texture.desc.Height = font->atlas->height;
|
font->texture.desc.Height = font->atlas->height;
|
||||||
font->texture.desc.Format =
|
font->texture.desc.Format =
|
||||||
@ -60,7 +61,6 @@ d3d11_font_init_font(void* data, const char* font_path, float font_size, bool is
|
|||||||
d3d11_update_texture(
|
d3d11_update_texture(
|
||||||
d3d11->ctx, font->atlas->width, font->atlas->height, font->atlas->width,
|
d3d11->ctx, font->atlas->width, font->atlas->height, font->atlas->width,
|
||||||
DXGI_FORMAT_A8_UNORM, font->atlas->buffer, &font->texture);
|
DXGI_FORMAT_A8_UNORM, font->atlas->buffer, &font->texture);
|
||||||
font->texture.dirty = true;
|
|
||||||
font->atlas->dirty = false;
|
font->atlas->dirty = false;
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
@ -209,19 +209,10 @@ static void d3d11_font_render_line(
|
|||||||
d3d11->ctx, font->atlas->width, font->atlas->height, font->atlas->width,
|
d3d11->ctx, font->atlas->width, font->atlas->height, font->atlas->width,
|
||||||
DXGI_FORMAT_A8_UNORM, font->atlas->buffer, &font->texture);
|
DXGI_FORMAT_A8_UNORM, font->atlas->buffer, &font->texture);
|
||||||
font->atlas->dirty = false;
|
font->atlas->dirty = false;
|
||||||
font->texture.dirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (font->texture.dirty)
|
|
||||||
{
|
|
||||||
D3D11_BOX frame_box = { 0, 0, 0, font->atlas->width, font->atlas->height, 1 };
|
|
||||||
D3D11CopyTexture2DSubresourceRegion(
|
|
||||||
d3d11->ctx, font->texture.handle, 0, 0, 0, 0, font->texture.staging, 0, &frame_box);
|
|
||||||
font->texture.dirty = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
D3D11SetPShader(d3d11->ctx, d3d11->sprites.ps_8bit, NULL, 0);
|
D3D11SetPShader(d3d11->ctx, d3d11->sprites.ps_8bit, NULL, 0);
|
||||||
D3D11SetPShaderResources(d3d11->ctx, 0, 1, &font->texture.view);
|
d3d11_set_texture_and_sampler(d3d11->ctx, 0, &font->texture);
|
||||||
D3D11Draw(d3d11->ctx, count, d3d11->sprites.offset);
|
D3D11Draw(d3d11->ctx, count, d3d11->sprites.offset);
|
||||||
D3D11SetPShader(d3d11->ctx, d3d11->sprites.ps, NULL, 0);
|
D3D11SetPShader(d3d11->ctx, d3d11->sprites.ps, NULL, 0);
|
||||||
|
|
||||||
|
@ -55,7 +55,6 @@ static void menu_display_d3d11_draw(void* data)
|
|||||||
if (d3d11->sprites.offset + 1 > d3d11->sprites.capacity)
|
if (d3d11->sprites.offset + 1 > d3d11->sprites.capacity)
|
||||||
d3d11->sprites.offset = 0;
|
d3d11->sprites.offset = 0;
|
||||||
|
|
||||||
|
|
||||||
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
|
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
|
||||||
D3D11MapBuffer(d3d11->ctx, d3d11->sprites.vbo, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped_vbo);
|
D3D11MapBuffer(d3d11->ctx, d3d11->sprites.vbo, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped_vbo);
|
||||||
d3d11_sprite_t* v = (d3d11_sprite_t*)mapped_vbo.pData + d3d11->sprites.offset;
|
d3d11_sprite_t* v = (d3d11_sprite_t*)mapped_vbo.pData + d3d11->sprites.offset;
|
||||||
@ -93,8 +92,7 @@ static void menu_display_d3d11_draw(void* data)
|
|||||||
#if 0
|
#if 0
|
||||||
D3D11SetPShader(d3d11->ctx, d3d11->sprites.ps, NULL, 0);
|
D3D11SetPShader(d3d11->ctx, d3d11->sprites.ps, NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
D3D11SetPShaderResources(d3d11->ctx, 0, 1, &((d3d11_texture_t*)draw->texture)->view);
|
d3d11_set_texture_and_sampler(d3d11->ctx, 0, (d3d11_texture_t*)draw->texture);
|
||||||
|
|
||||||
|
|
||||||
D3D11Draw(d3d11->ctx, 1, d3d11->sprites.offset);
|
D3D11Draw(d3d11->ctx, 1, d3d11->sprites.offset);
|
||||||
d3d11->sprites.offset++;
|
d3d11->sprites.offset++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user