From 27c840fa9135c9057602ed47820b27d34caedade Mon Sep 17 00:00:00 2001 From: DrChat Date: Mon, 16 Apr 2018 15:44:52 -0500 Subject: [PATCH] [Vulkan] Fixup window offset calculation --- src/xenia/gpu/spirv_shader_translator.cc | 16 ++++++++-------- src/xenia/gpu/vulkan/pipeline_cache.cc | 17 ++++++----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/xenia/gpu/spirv_shader_translator.cc b/src/xenia/gpu/spirv_shader_translator.cc index 384190124..0387ad5fe 100644 --- a/src/xenia/gpu/spirv_shader_translator.cc +++ b/src/xenia/gpu/spirv_shader_translator.cc @@ -528,20 +528,20 @@ std::vector SpirvShaderTranslator::CompleteTranslation() { // Reinsert w p = b.createCompositeInsert(p_w, p, vec4_float_type_, 3); - // Apply window scaling - // pos.xy *= window_scale.xy - auto p_scaled = - b.createBinOp(spv::Op::OpFMul, vec4_float_type_, p, window_scale); - // Apply window offset // pos.xy += window_scale.zw auto window_offset = b.createOp(spv::Op::OpVectorShuffle, vec4_float_type_, {window_scale, window_scale, 2, 3, 0, 1}); - auto p_offset = b.createBinOp(spv::Op::OpFAdd, vec4_float_type_, p_scaled, - window_offset); + auto p_offset = + b.createBinOp(spv::Op::OpFAdd, vec4_float_type_, p, window_offset); + + // Apply window scaling + // pos.xy *= window_scale.xy + auto p_scaled = b.createBinOp(spv::Op::OpFMul, vec4_float_type_, p_offset, + window_scale); p = b.createOp(spv::Op::OpVectorShuffle, vec4_float_type_, - {p, p_offset, 4, 5, 2, 3}); + {p, p_scaled, 4, 5, 2, 3}); b.createStore(p, pos_); } else { diff --git a/src/xenia/gpu/vulkan/pipeline_cache.cc b/src/xenia/gpu/vulkan/pipeline_cache.cc index b1eeec71e..e7c18f066 100644 --- a/src/xenia/gpu/vulkan/pipeline_cache.cc +++ b/src/xenia/gpu/vulkan/pipeline_cache.cc @@ -682,15 +682,10 @@ bool PipelineCache::SetDynamicState(VkCommandBuffer command_buffer, } if (viewport_state_dirty) { - // float texel_offset_x = regs.pa_su_sc_vtx_cntl & 0x01 ? 0.5f : 0.f; - // float texel_offset_y = regs.pa_su_sc_vtx_cntl & 0x01 ? 0.5f : 0.f; - float texel_offset_x = 0.f; - float texel_offset_y = 0.f; - VkViewport viewport_rect; std::memset(&viewport_rect, 0, sizeof(VkViewport)); - viewport_rect.x = vpx + texel_offset_x; - viewport_rect.y = vpy + texel_offset_y; + viewport_rect.x = vpx; + viewport_rect.y = vpy; viewport_rect.width = vpw; viewport_rect.height = vph; @@ -781,10 +776,10 @@ bool PipelineCache::SetDynamicState(VkCommandBuffer command_buffer, push_constants.window_scale[3] = 0.f; } else { // 1 / unscaled viewport w/h - push_constants.window_scale[0] = 1.0f / 2560.0f; - push_constants.window_scale[1] = 1.0f / 2560.0f; - push_constants.window_scale[2] = -1.f; - push_constants.window_scale[3] = -1.f; + push_constants.window_scale[0] = 1.0f / (1280.f * window_width_scalar); + push_constants.window_scale[1] = 1.0f / (1280.f * window_height_scalar); + push_constants.window_scale[2] = (-1280.f * window_width_scalar) + 0.5f; + push_constants.window_scale[3] = (-1280.f * window_height_scalar) + 0.5f; } // http://www.x.org/docs/AMD/old/evergreen_3D_registers_v2.pdf