[Vulkan] Fixup window offset calculation

This commit is contained in:
DrChat 2018-04-16 15:44:52 -05:00
parent 18d9efc93b
commit 27c840fa91
2 changed files with 14 additions and 19 deletions

View File

@ -528,20 +528,20 @@ std::vector<uint8_t> 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 {

View File

@ -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