Skip to content

Commit

Permalink
make the feature optional, add error log, remove window offset
Browse files Browse the repository at this point in the history
  • Loading branch information
roamic committed Jan 14, 2025
1 parent 0dc2aa1 commit ac4583d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
7 changes: 6 additions & 1 deletion src/video_core/renderer_vulkan/vk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ std::string Instance::GetDriverVersionName() {
bool Instance::CreateDevice() {
const vk::StructureChain feature_chain = physical_device.getFeatures2<
vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT,
vk::PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT,
vk::PhysicalDeviceExtendedDynamicState2FeaturesEXT,
vk::PhysicalDeviceExtendedDynamicState3FeaturesEXT,
vk::PhysicalDeviceCustomBorderColorFeaturesEXT,
Expand Down Expand Up @@ -318,6 +319,9 @@ bool Instance::CreateDevice() {
.pQueuePriorities = queue_priorities.data(),
};

const auto topology_list_restart_features =
feature_chain.get<vk::PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>();

const auto vk12_features = feature_chain.get<vk::PhysicalDeviceVulkan12Features>();
vk::StructureChain device_chain = {
vk::DeviceCreateInfo{
Expand Down Expand Up @@ -407,7 +411,8 @@ bool Instance::CreateDevice() {
},
vk::PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT{
.primitiveTopologyListRestart = true,
.primitiveTopologyPatchListRestart = true,
.primitiveTopologyPatchListRestart =
topology_list_restart_features.primitiveTopologyPatchListRestart,
},
vk::PhysicalDeviceFragmentShaderBarycentricFeaturesKHR{
.fragmentShaderBarycentric = true,
Expand Down
41 changes: 23 additions & 18 deletions src/video_core/renderer_vulkan/vk_rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,36 +1061,25 @@ void Rasterizer::UpdateViewportScissorState(const GraphicsPipeline& pipeline) {
? 1.0f
: 0.0f;

if (regs.polygon_control.enable_window_offset) {
LOG_ERROR(Render_Vulkan,
"PA_SU_SC_MODE_CNTL.VTX_WINDOW_OFFSET_ENABLE support is not yet implemented.");
}

for (u32 i = 0; i < Liverpool::NumViewports; i++) {
const auto& vp = regs.viewports[i];
const auto& vp_d = regs.viewport_depths[i];
if (vp.xscale == 0) {
continue;
}

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[i].top_left_x.Value()));
vp_scsr.top_left_y =
std::max(vp_scsr.top_left_y, s16(regs.viewport_scissors[i].top_left_y.Value()));
vp_scsr.bottom_right_x =
std::min(vp_scsr.bottom_right_x, regs.viewport_scissors[i].bottom_right_x);
vp_scsr.bottom_right_y =
std::min(vp_scsr.bottom_right_y, regs.viewport_scissors[i].bottom_right_y);
}
scissors.push_back({
.offset = {vp_scsr.top_left_x, vp_scsr.top_left_y},
.extent = {vp_scsr.GetWidth(), vp_scsr.GetHeight()},
});

if (pipeline.IsClipDisabled()) {
// In case if clipping is disabled we patch the shader to convert vertex position
// from screen space coordinates to NDC by defining a render space as full hardware
// window range [0..16383, 0..16383] and setting the viewport to its size.
viewports.push_back({
.x = enable_offset ? float(regs.window_offset.window_x_offset) : 0.f,
.y = enable_offset ? float(regs.window_offset.window_y_offset) : 0.f,
.x = 0.f,
.y = 0.f,
.width = float(16_KB),
.height = float(16_KB),
.minDepth = 0.0,
Expand All @@ -1112,6 +1101,22 @@ void Rasterizer::UpdateViewportScissorState(const GraphicsPipeline& pipeline) {
.maxDepth = zscale + zoffset,
});
}

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[i].top_left_x.Value()));
vp_scsr.top_left_y =
std::max(vp_scsr.top_left_y, s16(regs.viewport_scissors[i].top_left_y.Value()));
vp_scsr.bottom_right_x =
std::min(vp_scsr.bottom_right_x, regs.viewport_scissors[i].bottom_right_x);
vp_scsr.bottom_right_y =
std::min(vp_scsr.bottom_right_y, regs.viewport_scissors[i].bottom_right_y);
}
scissors.push_back({
.offset = {vp_scsr.top_left_x, vp_scsr.top_left_y},
.extent = {vp_scsr.GetWidth(), vp_scsr.GetHeight()},
});
}

if (viewports.empty()) {
Expand Down

0 comments on commit ac4583d

Please sign in to comment.