Invert y display for vulkan with negative viewport height. Closes #1971

This commit is contained in:
baldurk
2020-07-06 11:20:23 +01:00
parent 02c1669a4d
commit c10089c94b
8 changed files with 37 additions and 0 deletions
+7
View File
@@ -3811,11 +3811,18 @@ void BufferViewer::camGuess_changed(double value)
// use estimates from post vs data (calculated from vertex position data) if the user
// hasn't overridden the values
m_Config.position.nearPlane = 0.1f;
m_Config.position.flipY = false;
if(m_CurStage == MeshDataStage::VSOut)
{
m_Config.position.nearPlane = m_PostVS.nearPlane;
m_Config.position.flipY = m_PostVS.flipY;
}
else if(m_CurStage == MeshDataStage::GSOut)
{
m_Config.position.nearPlane = m_PostGS.nearPlane;
m_Config.position.flipY = m_PostGS.flipY;
}
if(ui->nearGuess->value() > 0.0)
m_Config.position.nearPlane = ui->nearGuess->value();
+3
View File
@@ -84,6 +84,9 @@ struct MeshFormat
DOCUMENT("``True`` if this mesh element contains post-projection positional data.");
bool unproject = false;
DOCUMENT("``True`` if there is an implicit Y-flip to account for in the projection.");
bool flipY = false;
DOCUMENT("``True`` if this mesh element comes from instanced data. See :data:`instStepRate`.");
bool instanced = false;
@@ -142,6 +142,11 @@ void D3D11Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
guessProj = Matrix4f::Orthographic(cfg.position.nearPlane, cfg.position.farPlane);
}
if(cfg.position.flipY)
{
guessProj[5] *= -1.0f;
}
guessProjInv = guessProj.Inverse();
vertexData.ModelViewProj = projMat.Mul(camMat.Mul(guessProjInv));
@@ -285,6 +285,11 @@ void D3D12Replay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secon
guessProj = Matrix4f::Orthographic(cfg.position.nearPlane, cfg.position.farPlane);
}
if(cfg.position.flipY)
{
guessProj[5] *= -1.0f;
}
guessProjInv = guessProj.Inverse();
vertexData.ModelViewProj = projMat.Mul(camMat.Mul(guessProjInv));
+5
View File
@@ -98,6 +98,11 @@ void GLReplay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &secondar
guessProj = Matrix4f::Orthographic(cfg.position.nearPlane, cfg.position.farPlane);
}
if(cfg.position.flipY)
{
guessProj[5] *= -1.0f;
}
guessProjInv = guessProj.Inverse();
ModelViewProj = projMat.Mul(camMat.Mul(guessProjInv));
+6
View File
@@ -1230,6 +1230,7 @@ void VulkanReplay::FetchVSOut(uint32_t eventId, VulkanRenderState &state)
m_PostVS.Data[eventId].vsout.farPlane = 0.0f;
m_PostVS.Data[eventId].vsout.useIndices = false;
m_PostVS.Data[eventId].vsout.hasPosOut = false;
m_PostVS.Data[eventId].vsout.flipY = false;
m_PostVS.Data[eventId].vsout.idxbuf = VK_NULL_HANDLE;
m_PostVS.Data[eventId].vsout.idxbufmem = VK_NULL_HANDLE;
@@ -2346,6 +2347,7 @@ void VulkanReplay::FetchVSOut(uint32_t eventId, VulkanRenderState &state)
m_PostVS.Data[eventId].vsout.hasPosOut =
refl->outputSignature[0].systemValue == ShaderBuiltin::Position;
m_PostVS.Data[eventId].vsout.flipY = state.views[0].height < 0.0f;
// delete descriptors. Technically we don't have to free the descriptor sets, but our tracking on
// replay doesn't handle destroying children of pooled objects so we do it explicitly anyway.
@@ -2386,6 +2388,7 @@ void VulkanReplay::FetchTessGSOut(uint32_t eventId, VulkanRenderState &state)
m_PostVS.Data[eventId].gsout.farPlane = 0.0f;
m_PostVS.Data[eventId].gsout.useIndices = false;
m_PostVS.Data[eventId].gsout.hasPosOut = false;
m_PostVS.Data[eventId].gsout.flipY = false;
m_PostVS.Data[eventId].gsout.idxbuf = VK_NULL_HANDLE;
m_PostVS.Data[eventId].gsout.idxbufmem = VK_NULL_HANDLE;
}
@@ -2447,6 +2450,7 @@ void VulkanReplay::FetchTessGSOut(uint32_t eventId, VulkanRenderState &state)
m_PostVS.Data[eventId].gsout.farPlane = 0.0f;
m_PostVS.Data[eventId].gsout.useIndices = false;
m_PostVS.Data[eventId].gsout.hasPosOut = false;
m_PostVS.Data[eventId].gsout.flipY = false;
m_PostVS.Data[eventId].gsout.idxbuf = VK_NULL_HANDLE;
m_PostVS.Data[eventId].gsout.idxbufmem = VK_NULL_HANDLE;
return;
@@ -2898,6 +2902,7 @@ void VulkanReplay::FetchTessGSOut(uint32_t eventId, VulkanRenderState &state)
m_PostVS.Data[eventId].gsout.idxbufmem = VK_NULL_HANDLE;
m_PostVS.Data[eventId].gsout.hasPosOut = true;
m_PostVS.Data[eventId].gsout.flipY = state.views[0].height < 0.0f;
// delete framebuffer and renderpass
m_pDriver->vkDestroyFramebuffer(dev, fb, NULL);
@@ -3089,6 +3094,7 @@ MeshFormat VulkanReplay::GetPostVSBuffers(uint32_t eventId, uint32_t instID, uin
ret.unproject = s.hasPosOut;
ret.nearPlane = s.nearPlane;
ret.farPlane = s.farPlane;
ret.flipY = s.flipY;
if(instID < s.instData.size())
{
@@ -498,6 +498,11 @@ void VulkanReplay::RenderMesh(uint32_t eventId, const rdcarray<MeshFormat> &seco
guessProj = Matrix4f::Orthographic(cfg.position.nearPlane, cfg.position.farPlane);
}
if(cfg.position.flipY)
{
guessProj[5] *= -1.0f;
}
guessProjInv = guessProj.Inverse();
ModelViewProj = projMat.Mul(camMat.Mul(guessProjInv));
+1
View File
@@ -172,6 +172,7 @@ struct VulkanPostVSData
VkIndexType idxFmt;
bool hasPosOut;
bool flipY;
float nearPlane;
float farPlane;