Skip to content

Commit

Permalink
video_core: restored presenter aspect calculations (shadps4-emu#1583)
Browse files Browse the repository at this point in the history
* video_core: restored presenter aspect calculations

* code simplification
  • Loading branch information
psucien authored Nov 23, 2024
1 parent 5976300 commit d7d28aa
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/video_core/renderer_vulkan/vk_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,32 @@ bool CanBlitToSwapchain(const vk::PhysicalDevice physical_device, vk::Format for
return MakeImageBlit(frame_width, frame_height, swapchain_width, swapchain_height, 0, 0);
}

[[nodiscard]] vk::ImageBlit MakeImageBlitFit(s32 frame_width, s32 frame_height, s32 swapchain_width,
s32 swapchain_height) {
static vk::Rect2D FitImage(s32 frame_width, s32 frame_height, s32 swapchain_width,
s32 swapchain_height) {
float frame_aspect = static_cast<float>(frame_width) / frame_height;
float swapchain_aspect = static_cast<float>(swapchain_width) / swapchain_height;

s32 dst_width = swapchain_width;
s32 dst_height = swapchain_height;
u32 dst_width = swapchain_width;
u32 dst_height = swapchain_height;

if (frame_aspect > swapchain_aspect) {
dst_height = static_cast<s32>(swapchain_width / frame_aspect);
} else {
dst_width = static_cast<s32>(swapchain_height * frame_aspect);
}

s32 offset_x = (swapchain_width - dst_width) / 2;
s32 offset_y = (swapchain_height - dst_height) / 2;
const s32 offset_x = (swapchain_width - dst_width) / 2;
const s32 offset_y = (swapchain_height - dst_height) / 2;

return vk::Rect2D{{offset_x, offset_y}, {dst_width, dst_height}};
}

[[nodiscard]] vk::ImageBlit MakeImageBlitFit(s32 frame_width, s32 frame_height, s32 swapchain_width,
s32 swapchain_height) {
const auto& dst_rect = FitImage(frame_width, frame_height, swapchain_width, swapchain_height);

return MakeImageBlit(frame_width, frame_height, dst_width, dst_height, offset_x, offset_y);
return MakeImageBlit(frame_width, frame_height, dst_rect.extent.width, dst_rect.extent.height,
dst_rect.offset.x, dst_rect.offset.y);
}

static vk::Format FormatToUnorm(vk::Format fmt) {
Expand Down Expand Up @@ -552,25 +560,22 @@ Frame* Presenter::PrepareFrameInternal(VideoCore::ImageId image_id, bool is_eop)

cmdbuf.bindPipeline(vk::PipelineBindPoint::eGraphics, *pp_pipeline);

const auto& dst_rect =
FitImage(image.info.size.width, image.info.size.height, frame->width, frame->height);

const std::array viewports = {
vk::Viewport{
.x = 0.0f,
.y = 0.0f,
.width = 1.0f * frame->width,
.height = 1.0f * frame->height,
.x = 1.0f * dst_rect.offset.x,
.y = 1.0f * dst_rect.offset.y,
.width = 1.0f * dst_rect.extent.width,
.height = 1.0f * dst_rect.extent.height,
.minDepth = 0.0f,
.maxDepth = 1.0f,
},
};

const std::array scissors = {
vk::Rect2D{
.offset = {0, 0},
.extent = {frame->width, frame->height},
},
};
cmdbuf.setViewport(0, viewports);
cmdbuf.setScissor(0, scissors);
cmdbuf.setScissor(0, {dst_rect});

cmdbuf.pushDescriptorSetKHR(vk::PipelineBindPoint::eGraphics, *pp_pipeline_layout, 0,
set_writes);
Expand All @@ -580,7 +585,7 @@ Frame* Presenter::PrepareFrameInternal(VideoCore::ImageId image_id, bool is_eop)
const std::array attachments = {vk::RenderingAttachmentInfo{
.imageView = frame->image_view,
.imageLayout = vk::ImageLayout::eColorAttachmentOptimal,
.loadOp = vk::AttachmentLoadOp::eDontCare,
.loadOp = vk::AttachmentLoadOp::eClear,
.storeOp = vk::AttachmentStoreOp::eStore,
}};

Expand Down

0 comments on commit d7d28aa

Please sign in to comment.