Use correct scissor rects (#1146)

* WIP

* Proper combination of scissors

* convert static functions to lambdas
This commit is contained in:
Vladislav Mikhalin 2024-10-01 21:42:01 +03:00 committed by GitHub
parent 3dea1a9f81
commit 7d96c9d634
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 89 additions and 18 deletions

View file

@ -368,11 +368,55 @@ void Rasterizer::UpdateViewportScissorState() {
.maxDepth = vp.zscale + vp.zoffset,
});
}
const auto& sc = regs.screen_scissor;
scissors.push_back({
.offset = {sc.top_left_x, sc.top_left_y},
.extent = {sc.GetWidth(), sc.GetHeight()},
});
const bool enable_offset = !regs.window_scissor.window_offset_disable.Value();
Liverpool::Scissor scsr{};
const auto combined_scissor_value_tl = [](s16 scr, s16 win, s16 gen, s16 win_offset) {
return std::max({scr, s16(win + win_offset), s16(gen + win_offset)});
};
scsr.top_left_x = combined_scissor_value_tl(
regs.screen_scissor.top_left_x, s16(regs.window_scissor.top_left_x.Value()),
s16(regs.generic_scissor.top_left_x.Value()),
enable_offset ? regs.window_offset.window_x_offset : 0);
scsr.top_left_y = combined_scissor_value_tl(
regs.screen_scissor.top_left_y, s16(regs.window_scissor.top_left_y.Value()),
s16(regs.generic_scissor.top_left_y.Value()),
enable_offset ? regs.window_offset.window_y_offset : 0);
const auto combined_scissor_value_br = [](s16 scr, s16 win, s16 gen, s16 win_offset) {
return std::min({scr, s16(win + win_offset), s16(gen + win_offset)});
};
scsr.bottom_right_x = combined_scissor_value_br(
regs.screen_scissor.bottom_right_x, regs.window_scissor.bottom_right_x,
regs.generic_scissor.bottom_right_x,
enable_offset ? regs.window_offset.window_x_offset : 0);
scsr.bottom_right_y = combined_scissor_value_br(
regs.screen_scissor.bottom_right_y, regs.window_scissor.bottom_right_y,
regs.generic_scissor.bottom_right_y,
enable_offset ? regs.window_offset.window_y_offset : 0);
for (u32 idx = 0; idx < Liverpool::NumViewports; idx++) {
auto vp_scsr = scsr;
if (regs.mode_control.vport_scissor_enable) {
vp_scsr.top_left_x =
std::max(vp_scsr.top_left_x, s16(regs.viewport_scissors[idx].top_left_x.Value()));
vp_scsr.top_left_y =
std::max(vp_scsr.top_left_y, s16(regs.viewport_scissors[idx].top_left_y.Value()));
vp_scsr.bottom_right_x =
std::min(vp_scsr.bottom_right_x, regs.viewport_scissors[idx].bottom_right_x);
vp_scsr.bottom_right_y =
std::min(vp_scsr.bottom_right_y, regs.viewport_scissors[idx].bottom_right_y);
}
scissors.push_back({
.offset = {vp_scsr.top_left_x, vp_scsr.top_left_y},
.extent = {vp_scsr.GetWidth(), vp_scsr.GetHeight()},
});
}
const auto cmdbuf = scheduler.CommandBuffer();
cmdbuf.setViewport(0, viewports);
cmdbuf.setScissor(0, scissors);