2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

vk_texture_cache: Make use of designated initializers where applicable

This commit is contained in:
Lioncash 2020-07-16 19:42:47 -04:00
parent 08d36afd40
commit 01da386617

View file

@ -95,17 +95,18 @@ VkImageViewType GetImageViewType(SurfaceTarget target) {
vk::Buffer CreateBuffer(const VKDevice& device, const SurfaceParams& params, vk::Buffer CreateBuffer(const VKDevice& device, const SurfaceParams& params,
std::size_t host_memory_size) { std::size_t host_memory_size) {
// TODO(Rodrigo): Move texture buffer creation to the buffer cache // TODO(Rodrigo): Move texture buffer creation to the buffer cache
VkBufferCreateInfo ci; return device.GetLogical().CreateBuffer({
ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
ci.pNext = nullptr; .pNext = nullptr,
ci.flags = 0; .flags = 0,
ci.size = static_cast<VkDeviceSize>(host_memory_size); .size = static_cast<VkDeviceSize>(host_memory_size),
ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | .usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VK_BUFFER_USAGE_TRANSFER_DST_BIT,
ci.queueFamilyIndexCount = 0; .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
ci.pQueueFamilyIndices = nullptr; .queueFamilyIndexCount = 0,
return device.GetLogical().CreateBuffer(ci); .pQueueFamilyIndices = nullptr,
});
} }
VkBufferViewCreateInfo GenerateBufferViewCreateInfo(const VKDevice& device, VkBufferViewCreateInfo GenerateBufferViewCreateInfo(const VKDevice& device,
@ -113,15 +114,16 @@ VkBufferViewCreateInfo GenerateBufferViewCreateInfo(const VKDevice& device,
std::size_t host_memory_size) { std::size_t host_memory_size) {
ASSERT(params.IsBuffer()); ASSERT(params.IsBuffer());
VkBufferViewCreateInfo ci; return {
ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO,
ci.pNext = nullptr; .pNext = nullptr,
ci.flags = 0; .flags = 0,
ci.buffer = buffer; .buffer = buffer,
ci.format = MaxwellToVK::SurfaceFormat(device, FormatType::Buffer, params.pixel_format).format; .format =
ci.offset = 0; MaxwellToVK::SurfaceFormat(device, FormatType::Buffer, params.pixel_format).format,
ci.range = static_cast<VkDeviceSize>(host_memory_size); .offset = 0,
return ci; .range = static_cast<VkDeviceSize>(host_memory_size),
};
} }
VkImageCreateInfo GenerateImageCreateInfo(const VKDevice& device, const SurfaceParams& params) { VkImageCreateInfo GenerateImageCreateInfo(const VKDevice& device, const SurfaceParams& params) {
@ -130,23 +132,23 @@ VkImageCreateInfo GenerateImageCreateInfo(const VKDevice& device, const SurfaceP
const auto [format, attachable, storage] = const auto [format, attachable, storage] =
MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, params.pixel_format); MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, params.pixel_format);
VkImageCreateInfo ci; VkImageCreateInfo ci{
ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
ci.pNext = nullptr; .pNext = nullptr,
ci.flags = 0; .flags = 0,
ci.imageType = SurfaceTargetToImage(params.target); .imageType = SurfaceTargetToImage(params.target),
ci.format = format; .format = format,
ci.mipLevels = params.num_levels; .mipLevels = params.num_levels,
ci.arrayLayers = static_cast<u32>(params.GetNumLayers()); .arrayLayers = static_cast<u32>(params.GetNumLayers()),
ci.samples = VK_SAMPLE_COUNT_1_BIT; .samples = VK_SAMPLE_COUNT_1_BIT,
ci.tiling = VK_IMAGE_TILING_OPTIMAL; .tiling = VK_IMAGE_TILING_OPTIMAL,
ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; .usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
ci.queueFamilyIndexCount = 0; VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
ci.pQueueFamilyIndices = nullptr; .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; .queueFamilyIndexCount = 0,
.pQueueFamilyIndices = nullptr,
ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_USAGE_TRANSFER_SRC_BIT; };
if (attachable) { if (attachable) {
ci.usage |= params.IsPixelFormatZeta() ? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ci.usage |= params.IsPixelFormatZeta() ? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; : VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
@ -323,22 +325,25 @@ void CachedSurface::UploadImage(const std::vector<u8>& staging_buffer) {
} }
VkBufferImageCopy CachedSurface::GetBufferImageCopy(u32 level) const { VkBufferImageCopy CachedSurface::GetBufferImageCopy(u32 level) const {
VkBufferImageCopy copy; return {
copy.bufferOffset = params.GetHostMipmapLevelOffset(level, is_converted); .bufferOffset = params.GetHostMipmapLevelOffset(level, is_converted),
copy.bufferRowLength = 0; .bufferRowLength = 0,
copy.bufferImageHeight = 0; .bufferImageHeight = 0,
copy.imageSubresource.aspectMask = image->GetAspectMask(); .imageSubresource =
copy.imageSubresource.mipLevel = level; {
copy.imageSubresource.baseArrayLayer = 0; .aspectMask = image->GetAspectMask(),
copy.imageSubresource.layerCount = static_cast<u32>(params.GetNumLayers()); .mipLevel = level,
copy.imageOffset.x = 0; .baseArrayLayer = 0,
copy.imageOffset.y = 0; .layerCount = static_cast<u32>(params.GetNumLayers()),
copy.imageOffset.z = 0; },
copy.imageExtent.width = params.GetMipWidth(level); .imageOffset = {.x = 0, .y = 0, .z = 0},
copy.imageExtent.height = params.GetMipHeight(level); .imageExtent =
copy.imageExtent.depth = {
params.target == SurfaceTarget::Texture3D ? params.GetMipDepth(level) : 1; .width = params.GetMipWidth(level),
return copy; .height = params.GetMipHeight(level),
.depth = params.target == SurfaceTarget::Texture3D ? params.GetMipDepth(level) : 1U,
},
};
} }
VkImageSubresourceRange CachedSurface::GetImageSubresourceRange() const { VkImageSubresourceRange CachedSurface::GetImageSubresourceRange() const {
@ -418,20 +423,29 @@ VkImageView CachedSurfaceView::GetImageView(SwizzleSource x_source, SwizzleSourc
ASSERT(num_slices == params.depth); ASSERT(num_slices == params.depth);
} }
VkImageViewCreateInfo ci; image_view = device.GetLogical().CreateImageView({
ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
ci.pNext = nullptr; .pNext = nullptr,
ci.flags = 0; .flags = 0,
ci.image = surface.GetImageHandle(); .image = surface.GetImageHandle(),
ci.viewType = image_view_type; .viewType = image_view_type,
ci.format = surface.GetImage().GetFormat(); .format = surface.GetImage().GetFormat(),
ci.components = {swizzle[0], swizzle[1], swizzle[2], swizzle[3]}; .components =
ci.subresourceRange.aspectMask = aspect; {
ci.subresourceRange.baseMipLevel = base_level; .r = swizzle[0],
ci.subresourceRange.levelCount = num_levels; .g = swizzle[1],
ci.subresourceRange.baseArrayLayer = base_layer; .b = swizzle[2],
ci.subresourceRange.layerCount = num_layers; .a = swizzle[3],
image_view = device.GetLogical().CreateImageView(ci); },
.subresourceRange =
{
.aspectMask = aspect,
.baseMipLevel = base_level,
.levelCount = num_levels,
.baseArrayLayer = base_layer,
.layerCount = num_layers,
},
});
return last_image_view = *image_view; return last_image_view = *image_view;
} }
@ -441,17 +455,26 @@ VkImageView CachedSurfaceView::GetAttachment() {
return *render_target; return *render_target;
} }
VkImageViewCreateInfo ci; VkImageViewCreateInfo ci{
ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
ci.pNext = nullptr; .pNext = nullptr,
ci.flags = 0; .flags = 0,
ci.image = surface.GetImageHandle(); .image = surface.GetImageHandle(),
ci.format = surface.GetImage().GetFormat(); .format = surface.GetImage().GetFormat(),
ci.components = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, .components =
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}; {
ci.subresourceRange.aspectMask = aspect_mask; .r = VK_COMPONENT_SWIZZLE_IDENTITY,
ci.subresourceRange.baseMipLevel = base_level; .g = VK_COMPONENT_SWIZZLE_IDENTITY,
ci.subresourceRange.levelCount = num_levels; .b = VK_COMPONENT_SWIZZLE_IDENTITY,
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
},
.subresourceRange =
{
.aspectMask = aspect_mask,
.baseMipLevel = base_level,
.levelCount = num_levels,
},
};
if (image_view_type == VK_IMAGE_VIEW_TYPE_3D) { if (image_view_type == VK_IMAGE_VIEW_TYPE_3D) {
ci.viewType = num_slices > 1 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D; ci.viewType = num_slices > 1 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D;
ci.subresourceRange.baseArrayLayer = base_slice; ci.subresourceRange.baseArrayLayer = base_slice;
@ -504,24 +527,40 @@ void VKTextureCache::ImageCopy(Surface& src_surface, Surface& dst_surface,
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_ACCESS_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
VkImageCopy copy; const VkImageCopy copy{
copy.srcSubresource.aspectMask = src_surface->GetAspectMask(); .srcSubresource =
copy.srcSubresource.mipLevel = copy_params.source_level; {
copy.srcSubresource.baseArrayLayer = copy_params.source_z; .aspectMask = src_surface->GetAspectMask(),
copy.srcSubresource.layerCount = num_layers; .mipLevel = copy_params.source_level,
copy.srcOffset.x = copy_params.source_x; .baseArrayLayer = copy_params.source_z,
copy.srcOffset.y = copy_params.source_y; .layerCount = num_layers,
copy.srcOffset.z = 0; },
copy.dstSubresource.aspectMask = dst_surface->GetAspectMask(); .srcOffset =
copy.dstSubresource.mipLevel = copy_params.dest_level; {
copy.dstSubresource.baseArrayLayer = dst_base_layer; .x = static_cast<s32>(copy_params.source_x),
copy.dstSubresource.layerCount = num_layers; .y = static_cast<s32>(copy_params.source_y),
copy.dstOffset.x = copy_params.dest_x; .z = 0,
copy.dstOffset.y = copy_params.dest_y; },
copy.dstOffset.z = dst_offset_z; .dstSubresource =
copy.extent.width = copy_params.width; {
copy.extent.height = copy_params.height; .aspectMask = dst_surface->GetAspectMask(),
copy.extent.depth = extent_z; .mipLevel = copy_params.dest_level,
.baseArrayLayer = dst_base_layer,
.layerCount = num_layers,
},
.dstOffset =
{
.x = static_cast<s32>(copy_params.dest_x),
.y = static_cast<s32>(copy_params.dest_y),
.z = static_cast<s32>(dst_offset_z),
},
.extent =
{
.width = copy_params.width,
.height = copy_params.height,
.depth = extent_z,
},
};
const VkImage src_image = src_surface->GetImageHandle(); const VkImage src_image = src_surface->GetImageHandle();
const VkImage dst_image = dst_surface->GetImageHandle(); const VkImage dst_image = dst_surface->GetImageHandle();