video_core: Minor fixes
This commit is contained in:
@@ -110,7 +110,7 @@ void Framebuffer::PrepareAttachments() {
|
|||||||
|
|
||||||
if (info.depth_stencil.IsValid()) {
|
if (info.depth_stencil.IsValid()) {
|
||||||
Texture* depth_stencil = static_cast<Texture*>(info.depth_stencil.Get());
|
Texture* depth_stencil = static_cast<Texture*>(info.depth_stencil.Get());
|
||||||
depth_stencil->Transition(command_buffer, vk::ImageLayout::eDepthAttachmentOptimal);
|
depth_stencil->Transition(command_buffer, vk::ImageLayout::eDepthStencilAttachmentOptimal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -266,14 +266,15 @@ Pipeline::Pipeline(Instance& instance, CommandScheduler& scheduler, PoolManager&
|
|||||||
};
|
};
|
||||||
|
|
||||||
const vk::PipelineColorBlendAttachmentState colorblend_attachment = {
|
const vk::PipelineColorBlendAttachmentState colorblend_attachment = {
|
||||||
.blendEnable = true,
|
.blendEnable = info.blending.blend_enable.Value(),
|
||||||
.srcColorBlendFactor = PicaToVK::BlendFunc(info.blending.src_color_blend_factor),
|
.srcColorBlendFactor = PicaToVK::BlendFunc(info.blending.src_color_blend_factor),
|
||||||
.dstColorBlendFactor = PicaToVK::BlendFunc(info.blending.dst_color_blend_factor),
|
.dstColorBlendFactor = PicaToVK::BlendFunc(info.blending.dst_color_blend_factor),
|
||||||
.colorBlendOp = PicaToVK::BlendEquation(info.blending.color_blend_eq),
|
.colorBlendOp = PicaToVK::BlendEquation(info.blending.color_blend_eq),
|
||||||
.srcAlphaBlendFactor = PicaToVK::BlendFunc(info.blending.src_alpha_blend_factor),
|
.srcAlphaBlendFactor = PicaToVK::BlendFunc(info.blending.src_alpha_blend_factor),
|
||||||
.dstAlphaBlendFactor = PicaToVK::BlendFunc(info.blending.dst_alpha_blend_factor),
|
.dstAlphaBlendFactor = PicaToVK::BlendFunc(info.blending.dst_alpha_blend_factor),
|
||||||
.alphaBlendOp = PicaToVK::BlendEquation(info.blending.alpha_blend_eq),
|
.alphaBlendOp = PicaToVK::BlendEquation(info.blending.alpha_blend_eq),
|
||||||
.colorWriteMask = static_cast<vk::ColorComponentFlags>(info.blending.color_write_mask)
|
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG |
|
||||||
|
vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA
|
||||||
};
|
};
|
||||||
|
|
||||||
const vk::PipelineColorBlendStateCreateInfo color_blending = {
|
const vk::PipelineColorBlendStateCreateInfo color_blending = {
|
||||||
|
@@ -83,7 +83,7 @@ vk::RenderPass RenderpassCache::GetRenderpass(TextureFormat color, TextureFormat
|
|||||||
const u32 color_index = static_cast<u32>(color);
|
const u32 color_index = static_cast<u32>(color);
|
||||||
const u32 depth_index = (depth == TextureFormat::Undefined ? 0 : (static_cast<u32>(depth) - MAX_COLOR_FORMATS));
|
const u32 depth_index = (depth == TextureFormat::Undefined ? 0 : (static_cast<u32>(depth) - MAX_COLOR_FORMATS));
|
||||||
|
|
||||||
ASSERT(color_index < MAX_COLOR_FORMATS && depth_index < MAX_DEPTH_FORMATS);
|
ASSERT(color_index <= MAX_COLOR_FORMATS && depth_index <= MAX_DEPTH_FORMATS);
|
||||||
return cached_renderpasses[color_index][depth_index][is_clear];
|
return cached_renderpasses[color_index][depth_index][is_clear];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,19 +137,6 @@ vk::RenderPass RenderpassCache::CreateRenderPass(vk::Format color, vk::Format de
|
|||||||
use_depth = true;
|
use_depth = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vk::SubpassDependency subpass_dependency = {
|
|
||||||
.srcSubpass = VK_SUBPASS_EXTERNAL,
|
|
||||||
.dstSubpass = 0,
|
|
||||||
.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput |
|
|
||||||
vk::PipelineStageFlagBits::eEarlyFragmentTests,
|
|
||||||
.dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput |
|
|
||||||
vk::PipelineStageFlagBits::eEarlyFragmentTests,
|
|
||||||
.srcAccessMask = vk::AccessFlagBits::eNone,
|
|
||||||
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite |
|
|
||||||
vk::AccessFlagBits::eDepthStencilAttachmentWrite,
|
|
||||||
.dependencyFlags = vk::DependencyFlagBits::eByRegion
|
|
||||||
};
|
|
||||||
|
|
||||||
// We also require only one subpass
|
// We also require only one subpass
|
||||||
const vk::SubpassDescription subpass = {
|
const vk::SubpassDescription subpass = {
|
||||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||||
@@ -166,8 +153,8 @@ vk::RenderPass RenderpassCache::CreateRenderPass(vk::Format color, vk::Format de
|
|||||||
.pAttachments = attachments.data(),
|
.pAttachments = attachments.data(),
|
||||||
.subpassCount = 1,
|
.subpassCount = 1,
|
||||||
.pSubpasses = &subpass,
|
.pSubpasses = &subpass,
|
||||||
.dependencyCount = 1,
|
.dependencyCount = 0,
|
||||||
.pDependencies = &subpass_dependency
|
.pDependencies = nullptr
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the renderpass
|
// Create the renderpass
|
||||||
|
@@ -13,7 +13,7 @@ namespace VideoCore::Vulkan {
|
|||||||
|
|
||||||
// 16MB should be enough for a single frame
|
// 16MB should be enough for a single frame
|
||||||
constexpr BufferInfo STAGING_INFO = {
|
constexpr BufferInfo STAGING_INFO = {
|
||||||
.capacity = 16 * 1024 * 1024,
|
.capacity = 32 * 1024 * 1024,
|
||||||
.usage = BufferUsage::Staging
|
.usage = BufferUsage::Staging
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -411,11 +411,17 @@ void Texture::Download(Rect2D rectangle, u32 stride, std::span<u8> data, u32 lev
|
|||||||
Buffer& staging = scheduler.GetCommandUploadBuffer();
|
Buffer& staging = scheduler.GetCommandUploadBuffer();
|
||||||
const u64 staging_offset = staging.GetCurrentOffset();
|
const u64 staging_offset = staging.GetCurrentOffset();
|
||||||
|
|
||||||
// TODO: Handle format convertions and depth/stencil downloads
|
if (advertised_format == vk::Format::eD24UnormS8Uint) {
|
||||||
ASSERT(aspect == vk::ImageAspectFlagBits::eColor &&
|
ASSERT(16 * 1024 * 1024 - staging_offset >= data.size() * 2);
|
||||||
|
} else {
|
||||||
|
ASSERT(aspect == vk::ImageAspectFlagBits::eColor &&
|
||||||
advertised_format == internal_format);
|
advertised_format == internal_format);
|
||||||
|
}
|
||||||
|
|
||||||
const vk::BufferImageCopy copy_region = {
|
u32 region_count = 0;
|
||||||
|
std::array<vk::BufferImageCopy, 2> copy_regions;
|
||||||
|
|
||||||
|
vk::BufferImageCopy copy_region = {
|
||||||
.bufferOffset = staging_offset,
|
.bufferOffset = staging_offset,
|
||||||
.bufferRowLength = stride,
|
.bufferRowLength = stride,
|
||||||
.bufferImageHeight = rectangle.height,
|
.bufferImageHeight = rectangle.height,
|
||||||
@@ -429,18 +435,50 @@ void Texture::Download(Rect2D rectangle, u32 stride, std::span<u8> data, u32 lev
|
|||||||
.imageExtent = {rectangle.width, rectangle.height, 1}
|
.imageExtent = {rectangle.width, rectangle.height, 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (aspect & vk::ImageAspectFlagBits::eColor) {
|
||||||
|
copy_regions[region_count++] = copy_region;
|
||||||
|
} else if (aspect & vk::ImageAspectFlagBits::eStencil) {
|
||||||
|
// Depth aspect download
|
||||||
|
copy_region.imageSubresource.aspectMask = vk::ImageAspectFlagBits::eDepth;
|
||||||
|
copy_regions[region_count++] = copy_region;
|
||||||
|
|
||||||
|
// Stencil aspect download
|
||||||
|
copy_region.bufferOffset += data.size();
|
||||||
|
copy_region.imageSubresource.aspectMask = vk::ImageAspectFlagBits::eStencil;
|
||||||
|
copy_regions[region_count++] = copy_region;
|
||||||
|
}
|
||||||
|
|
||||||
Transition(command_buffer, vk::ImageLayout::eTransferSrcOptimal);
|
Transition(command_buffer, vk::ImageLayout::eTransferSrcOptimal);
|
||||||
|
|
||||||
// Copy pixel data to the staging buffer
|
// Copy pixel data to the staging buffer
|
||||||
command_buffer.copyImageToBuffer(image, vk::ImageLayout::eTransferSrcOptimal,
|
command_buffer.copyImageToBuffer(image, vk::ImageLayout::eTransferSrcOptimal,
|
||||||
staging.GetHandle(), copy_region);
|
staging.GetHandle(), region_count, copy_regions.data());
|
||||||
|
|
||||||
// TODO: Async downloads
|
// TODO: Async downloads
|
||||||
scheduler.Submit(true);
|
scheduler.Submit(true);
|
||||||
|
|
||||||
// Copy data to the destination
|
// Copy data to the destination
|
||||||
auto memory = staging.Map(byte_count);
|
if (advertised_format == vk::Format::eD24UnormS8Uint) {
|
||||||
std::memcpy(data.data(), memory.data(), byte_count);
|
const u32 new_byte_count = data.size() + (data.size() / 4);
|
||||||
|
auto memory = staging.Map(new_byte_count);
|
||||||
|
|
||||||
|
u32 depth_offset = 0;
|
||||||
|
u32 stencil_offset = data.size();
|
||||||
|
for (u32 dst_offset = 0; dst_offset < byte_count; dst_offset += 4) {
|
||||||
|
float depth;
|
||||||
|
std::memcpy(&depth, memory.data() + depth_offset, sizeof(float));
|
||||||
|
u32 depth_uint = depth * 0xFFFFFF;
|
||||||
|
|
||||||
|
std::memcpy(data.data() + dst_offset, &depth_uint, 3);
|
||||||
|
data[dst_offset+3] = memory[stencil_offset];
|
||||||
|
|
||||||
|
depth_offset += 4;
|
||||||
|
stencil_offset += 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto memory = staging.Map(byte_count);
|
||||||
|
std::memcpy(data.data(), memory.data(), byte_count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Transition(command_buffer, vk::ImageLayout::eShaderReadOnlyOptimal);
|
Transition(command_buffer, vk::ImageLayout::eShaderReadOnlyOptimal);
|
||||||
|
Reference in New Issue
Block a user