(D3D10/D3D11/Vulkan) Cleanups

This commit is contained in:
libretroadmin 2022-05-16 22:26:46 +02:00
parent bfa627737e
commit 3115338849
9 changed files with 154 additions and 117 deletions

View File

@ -105,7 +105,7 @@ void d3d10_init_texture(D3D10Device device, d3d10_texture_t* texture)
D3D10CreateTexture2D(device, &texture->desc, NULL, &texture->handle);
{
D3D10_SHADER_RESOURCE_VIEW_DESC view_desc = { DXGI_FORMAT_UNKNOWN };
D3D10_SHADER_RESOURCE_VIEW_DESC view_desc;
view_desc.Format = texture->desc.Format;
view_desc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
view_desc.Texture2D.MostDetailedMip = 0;
@ -142,11 +142,7 @@ void d3d10_update_texture(
d3d10_texture_t* texture)
{
D3D10_MAPPED_TEXTURE2D mapped_texture;
D3D10_BOX frame_box = { 0, 0, 0, (UINT)width,
(UINT)height, 1 };
if (!texture || !texture->staging)
return;
D3D10_BOX frame_box;
D3D10MapTexture2D(texture->staging,
0, D3D10_MAP_WRITE, 0,
@ -163,7 +159,12 @@ void d3d10_update_texture(
#endif
D3D10UnmapTexture2D(texture->staging, 0);
frame_box.left = 0;
frame_box.top = 0;
frame_box.front = 0;
frame_box.right = (UINT)width;
frame_box.bottom = (UINT)height;
frame_box.back = 1;
D3D10CopyTexture2DSubresourceRegion(
ctx, texture->handle, 0, 0, 0, 0, texture->staging, 0, &frame_box);

View File

@ -131,7 +131,7 @@ void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture)
D3D11CreateTexture2D(device, &texture->desc, NULL, &texture->handle);
{
D3D11_SHADER_RESOURCE_VIEW_DESC view_desc = { DXGI_FORMAT_UNKNOWN };
D3D11_SHADER_RESOURCE_VIEW_DESC view_desc;
view_desc.Format = texture->desc.Format;
view_desc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
view_desc.Texture2D.MostDetailedMip = 0;
@ -168,10 +168,7 @@ void d3d11_update_texture(
d3d11_texture_t* texture)
{
D3D11_MAPPED_SUBRESOURCE mapped_texture;
D3D11_BOX frame_box = { 0, 0, 0, width, height, 1 };
if (!texture || !texture->staging)
return;
D3D11_BOX frame_box;
ctx->lpVtbl->Map(
ctx, (D3D11Resource)texture->staging, 0, D3D11_MAP_WRITE, 0, &mapped_texture);
@ -186,10 +183,16 @@ void d3d11_update_texture(
mapped_texture.pData);
#endif
frame_box.left = 0;
frame_box.top = 0;
frame_box.front = 0;
frame_box.right = width;
frame_box.bottom = height;
frame_box.back = 1;
ctx->lpVtbl->Unmap(ctx, (D3D11Resource)texture->staging, 0);
ctx->lpVtbl->CopySubresourceRegion(
ctx, (D3D11Resource)texture->handle, 0, 0, 0, 0, (D3D11Resource)texture->staging, 0, &frame_box);
ctx, (D3D11Resource)texture->handle, 0, 0, 0, 0,
(D3D11Resource)texture->staging, 0, &frame_box);
if (texture->desc.MiscFlags & D3D11_RESOURCE_MISC_GENERATE_MIPS)
D3D11GenerateMips(ctx, texture->view);

View File

@ -1701,7 +1701,6 @@ static bool vulkan_context_init_device(gfx_ctx_vulkan_data_t *vk)
char api_version[64];
char version_str[128];
int pos = 0;
device_str[0] = driver_version[0] = api_version[0] = version_str[0] = '\0';
strlcpy(device_str, vk->context.gpu_properties.deviceName, sizeof(device_str));
@ -2901,9 +2900,8 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
VkSurfaceFormatKHR format;
VkExtent2D swapchain_size;
VkSwapchainKHR old_swapchain;
VkSwapchainCreateInfoKHR info;
VkSurfaceTransformFlagBitsKHR pre_transform;
VkSwapchainCreateInfoKHR info = {
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR };
VkPresentModeKHR swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR;
settings_t *settings = config_get_ptr();
VkCompositeAlphaFlagBitsKHR composite = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
@ -3172,6 +3170,9 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
old_swapchain = vk->swapchain;
info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
info.pNext = NULL;
info.flags = 0;
info.surface = vk->vk_surface;
info.minImageCount = desired_swapchain_images;
info.imageFormat = format.format;
@ -3179,14 +3180,17 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
info.imageExtent.width = swapchain_size.width;
info.imageExtent.height = swapchain_size.height;
info.imageArrayLayers = 1;
info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
| VK_IMAGE_USAGE_TRANSFER_DST_BIT;
info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
info.queueFamilyIndexCount = 0;
info.pQueueFamilyIndices = NULL;
info.preTransform = pre_transform;
info.compositeAlpha = composite;
info.presentMode = swapchain_present_mode;
info.clipped = true;
info.oldSwapchain = old_swapchain;
info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
#ifdef _WIN32
/* On Windows, do not try to reuse the swapchain.
@ -3342,10 +3346,7 @@ void vulkan_framebuffer_generate_mips(
unsigned i;
/* This is run every frame, so make sure
* we aren't opting into the "lazy" way of doing this. :) */
VkImageMemoryBarrier barriers[2] = {
{ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER },
{ VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER },
};
VkImageMemoryBarrier barriers[2];
/* First, transfer the input mip level to TRANSFER_SRC_OPTIMAL.
* This should allow the surface to stay compressed.
@ -3354,6 +3355,8 @@ void vulkan_framebuffer_generate_mips(
*/
/* Input */
barriers[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barriers[0].pNext = NULL;
barriers[0].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
barriers[0].dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
barriers[0].oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
@ -3364,9 +3367,12 @@ void vulkan_framebuffer_generate_mips(
barriers[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barriers[0].subresourceRange.baseMipLevel = 0;
barriers[0].subresourceRange.levelCount = 1;
barriers[0].subresourceRange.baseArrayLayer = 0;
barriers[0].subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
/* The rest of the mip chain */
barriers[1].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barriers[1].pNext = NULL;
barriers[1].srcAccessMask = 0;
barriers[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
barriers[1].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
@ -3377,6 +3383,7 @@ void vulkan_framebuffer_generate_mips(
barriers[1].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
barriers[1].subresourceRange.baseMipLevel = 1;
barriers[1].subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
barriers[0].subresourceRange.baseArrayLayer = 0;
barriers[1].subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
vkCmdPipelineBarrier(cmd,

View File

@ -185,6 +185,7 @@ static bool d3d10_overlay_load(void* data, const void* image_data, unsigned num_
d3d10_init_texture(d3d10->device, &d3d10->overlays.textures[i]);
if (d3d10->overlays.textures[i].staging)
d3d10_update_texture(
d3d10->device,
images[i].width,
@ -517,6 +518,7 @@ static bool d3d10_gfx_set_shader(void* data, enum rarch_shader_type type, const
d3d10_init_texture(d3d10->device, &d3d10->luts[i]);
if (d3d10->luts[i].staging)
d3d10_update_texture(
d3d10->device,
image.width, image.height, 0,
@ -1345,6 +1347,7 @@ static bool d3d10_gfx_frame(
d3d10_init_render_targets(d3d10, width, height);
if (frame != RETRO_HW_FRAME_BUFFER_VALID)
if (d3d10->frame.texture[0].staging)
d3d10_update_texture(
d3d10->device,
width, height, pitch, d3d10->format, frame, &d3d10->frame.texture[0]);
@ -1632,6 +1635,7 @@ static void d3d10_set_menu_texture_frame(
d3d10_init_texture(d3d10->device, &d3d10->menu.texture);
}
if (d3d10->menu.texture.staging)
d3d10_update_texture(d3d10->device, width, height, 0,
format, frame, &d3d10->menu.texture);
d3d10->menu.texture.sampler = d3d10->samplers
@ -1720,6 +1724,7 @@ static uintptr_t d3d10_gfx_load_texture(
d3d10_init_texture(d3d10->device, texture);
if (texture->staging)
d3d10_update_texture(
d3d10->device,
image->width, image->height, 0, DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels,

View File

@ -207,6 +207,7 @@ static bool d3d11_overlay_load(void* data, const void* image_data, unsigned num_
d3d11_init_texture(d3d11->device, &d3d11->overlays.textures[i]);
if (d3d11->overlays.textures[i].staging)
d3d11_update_texture(
d3d11->context, images[i].width,
images[i].height, 0, DXGI_FORMAT_B8G8R8A8_UNORM,
@ -708,6 +709,7 @@ static bool d3d11_gfx_set_shader(void* data, enum rarch_shader_type type, const
d3d11_init_texture(d3d11->device, &d3d11->luts[i]);
if (d3d11->luts[i].staging)
d3d11_update_texture(
d3d11->context, image.width, image.height, 0, DXGI_FORMAT_R8G8B8A8_UNORM, image.pixels,
&d3d11->luts[i]);
@ -1990,7 +1992,7 @@ uuidof(ID3D11Texture2D), (void**)&back_buffer);
Release(hw_texture);
hw_texture = NULL;
}
else
else if (d3d11->frame.texture[0].staging)
d3d11_update_texture(
context, width, height, pitch, d3d11->format, frame, &d3d11->frame.texture[0]);
}
@ -2414,6 +2416,7 @@ static void d3d11_set_menu_texture_frame(
d3d11_init_texture(d3d11->device, &d3d11->menu.texture);
}
if (d3d11->menu.texture.staging)
d3d11_update_texture(d3d11->context, width, height, 0,
format, frame, &d3d11->menu.texture);
d3d11->menu.texture.sampler = d3d11->samplers
@ -2508,6 +2511,7 @@ static uintptr_t d3d11_gfx_load_texture(
d3d11_init_texture(d3d11->device, texture);
if (texture->staging)
d3d11_update_texture(
d3d11->context, image->width, image->height, 0, DXGI_FORMAT_B8G8R8A8_UNORM, image->pixels,
texture);

View File

@ -182,15 +182,20 @@ static void gfx_display_d3d10_draw_pipeline(gfx_display_ctx_draw_t* draw,
if (!d3d10->menu_pipeline_vbo)
{
D3D10_BUFFER_DESC desc = { 0 };
desc.Usage = D3D10_USAGE_IMMUTABLE;
desc.ByteWidth = ca->coords.vertices * 2 * sizeof(float);
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
D3D10_BUFFER_DESC desc;
D3D10_SUBRESOURCE_DATA vertex_data;
{
D3D10_SUBRESOURCE_DATA vertexData = { ca->coords.vertex };
D3D10CreateBuffer(d3d10->device, &desc, &vertexData, &d3d10->menu_pipeline_vbo);
}
desc.ByteWidth = ca->coords.vertices * 2 * sizeof(float);
desc.Usage = D3D10_USAGE_IMMUTABLE;
desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
desc.CPUAccessFlags = 0;
desc.MiscFlags = 0;
vertex_data.pSysMem = ca->coords.vertex;
vertex_data.SysMemPitch = 0;
vertex_data.SysMemSlicePitch = 0;
D3D10CreateBuffer(d3d10->device, &desc, &vertex_data,
&d3d10->menu_pipeline_vbo);
}
D3D10SetVertexBuffer(d3d10->device, 0, d3d10->menu_pipeline_vbo, 2 * sizeof(float), 0);
draw->coords->vertices = ca->coords.vertices;

View File

@ -79,7 +79,9 @@ static void gfx_display_d3d12_draw(gfx_display_ctx_draw_t *draw,
{
d3d12_sprite_t* sprite;
D3D12_RANGE range = { 0, 0 };
D3D12_RANGE range;
range.Begin = 0;
range.End = 0;
D3D12Map(d3d12->sprites.vbo, 0, &range, (void**)&sprite);
sprite += d3d12->sprites.offset;
@ -196,8 +198,8 @@ static void gfx_display_d3d12_draw_pipeline(gfx_display_ctx_draw_t *draw,
if (!d3d12->menu_pipeline_vbo)
{
D3D12_RANGE read_range;
void* vertex_data_begin;
D3D12_RANGE read_range = { 0, 0 };
d3d12->menu_pipeline_vbo_view.StrideInBytes = 2 * sizeof(float);
d3d12->menu_pipeline_vbo_view.SizeInBytes =
@ -206,6 +208,8 @@ static void gfx_display_d3d12_draw_pipeline(gfx_display_ctx_draw_t *draw,
d3d12->device, d3d12->menu_pipeline_vbo_view.SizeInBytes,
&d3d12->menu_pipeline_vbo);
read_range.Begin = 0;
read_range.End = 0;
D3D12Map(d3d12->menu_pipeline_vbo, 0, &read_range, &vertex_data_begin);
memcpy(vertex_data_begin, ca->coords.vertex, d3d12->menu_pipeline_vbo_view.SizeInBytes);
D3D12Unmap(d3d12->menu_pipeline_vbo, 0, NULL);
@ -230,8 +234,11 @@ static void gfx_display_d3d12_draw_pipeline(gfx_display_ctx_draw_t *draw,
d3d12->ubo_values.time += 0.01f;
{
D3D12_RANGE read_range = { 0, 0 };
D3D12_RANGE read_range;
d3d12_uniform_t* mapped_ubo;
read_range.Begin = 0;
read_range.End = 0;
D3D12Map(d3d12->ubo, 0, &read_range, (void**)&mapped_ubo);
*mapped_ubo = d3d12->ubo_values;
D3D12Unmap(d3d12->ubo, 0, NULL);

View File

@ -58,6 +58,7 @@ d3d10_font_init_font(void* data, const char* font_path, float font_size, bool is
font->texture.desc.Height = font->atlas->height;
font->texture.desc.Format = DXGI_FORMAT_A8_UNORM;
d3d10_init_texture(d3d10->device, &font->texture);
if (font->texture.staging)
d3d10_update_texture(
d3d10->device,
font->atlas->width, font->atlas->height, font->atlas->width,
@ -209,6 +210,7 @@ static void d3d10_font_render_line(
if (font->atlas->dirty)
{
if (font->texture.staging)
d3d10_update_texture(
d3d10->device,
font->atlas->width, font->atlas->height, font->atlas->width,

View File

@ -57,6 +57,7 @@ d3d11_font_init_font(void* data, const char* font_path, float font_size, bool is
font->texture.desc.Height = font->atlas->height;
font->texture.desc.Format = DXGI_FORMAT_A8_UNORM;
d3d11_init_texture(d3d11->device, &font->texture);
if (font->texture.staging)
d3d11_update_texture(
d3d11->context, font->atlas->width, font->atlas->height, font->atlas->width,
DXGI_FORMAT_A8_UNORM, font->atlas->buffer, &font->texture);
@ -208,8 +209,10 @@ static void d3d11_font_render_line(
if (font->atlas->dirty)
{
if (font->texture.staging)
d3d11_update_texture(
d3d11->context, font->atlas->width, font->atlas->height, font->atlas->width,
d3d11->context,
font->atlas->width, font->atlas->height, font->atlas->width,
DXGI_FORMAT_A8_UNORM, font->atlas->buffer, &font->texture);
font->atlas->dirty = false;
}