Skip to content

Commit

Permalink
Properly deal with flipped textures
Browse files Browse the repository at this point in the history
  • Loading branch information
fholger committed Jan 18, 2022
1 parent 62875fc commit 6f6b08a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/oculus/oculus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ namespace vrperfkit {
void OculusManager::PostProcessD3D11(ovrLayerEyeFovDepth &eyeLayer) {
auto projCenters = CalculateProjectionCenter(eyeLayer.Fov);
bool successfulPostprocessing = false;
bool isFlippedY = eyeLayer.Header.Flags & ovrLayerFlag_TextureOriginAtBottomLeft;

for (int eye = 0; eye < 2; ++eye) {
int index;
Expand Down Expand Up @@ -311,6 +312,11 @@ namespace vrperfkit {
input.inputViewport.height = eyeLayer.Viewport[eye].Size.h;
input.eye = eye;
input.projectionCenter = projCenters.eyeCenter[eye];

if (isFlippedY) {
input.projectionCenter.y = 1.f - input.projectionCenter.y;
}

if (submittedEyeChains[1] == nullptr || submittedEyeChains[1] == submittedEyeChains[0]) {
if (d3d11Res->usingArrayTex) {
input.mode = TextureMode::ARRAY;
Expand All @@ -333,7 +339,11 @@ namespace vrperfkit {

D3D11_TEXTURE2D_DESC td;
input.inputTexture->GetDesc(&td);
d3d11Res->variableRateShading->UpdateTargetInformation(td.Width, td.Height, input.mode, projCenters.eyeCenter[0].x, projCenters.eyeCenter[0].y, projCenters.eyeCenter[1].x, projCenters.eyeCenter[1].y);
float projLX = projCenters.eyeCenter[0].x;
float projLY = isFlippedY ? 1.f - projCenters.eyeCenter[0].y : projCenters.eyeCenter[0].y;
float projRX = projCenters.eyeCenter[1].x;
float projRY = isFlippedY ? 1.f - projCenters.eyeCenter[1].y : projCenters.eyeCenter[1].y;
d3d11Res->variableRateShading->UpdateTargetInformation(td.Width, td.Height, input.mode, projLX, projLY, projRX, projRY);
}

if (successfulPostprocessing) {
Expand Down
4 changes: 2 additions & 2 deletions src/openvr/openvr_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace vrperfkit {
g_openVr.PreCompositorWorkCall(true);
auto error = hooks::CallOriginal(IVRCompositor009Hook_Submit)(self, info.eye, info.texture, info.bounds, info.submitFlags);
if (error != vr::VRCompositorError_None) {
LOG_ERROR << "OpenVR submit failed: " << error;
LOG_DEBUG << "OpenVR submit failed: " << error;
}
g_openVr.PostCompositorWorkCall(true);
return error;
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace vrperfkit {
auto error = hooks::CallOriginal(IVRCompositorHook_WaitGetPoses)(self, pRenderPoseArray, unRenderPoseArrayCount, pGamePoseArray, unGamePoseArrayCount);
g_openVr.PostCompositorWorkCall();
if (error != vr::VRCompositorError_None) {
LOG_ERROR << "OpenVR WaitGetPoses failed: " << error;
LOG_DEBUG << "OpenVR WaitGetPoses failed: " << error;
}
return error;
}
Expand Down
22 changes: 21 additions & 1 deletion src/openvr/openvr_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ namespace vrperfkit {
inputTexture->GetDesc(&itd);
d3d11Res->outputTexture->GetDesc(&otd);

bool isFlippedX = info.bounds->uMin > info.bounds->uMax;
bool isFlippedY = info.bounds->vMin > info.bounds->vMax;

bool inputIsSrgb = info.texture->eColorSpace == ColorSpace_Gamma || (info.texture->eColorSpace == ColorSpace_Auto && IsConsideredSrgbByOpenVR(itd.Format));
bool isCombinedTex = float(itd.Width) / itd.Height >= 1.5f * aspectRatio && std::abs(info.bounds->uMax - info.bounds->uMin) <= 0.5f;

Expand All @@ -378,12 +381,25 @@ namespace vrperfkit {
input.projectionCenter = projCenters.eyeCenter[info.eye];
input.mode = d3d11Res->usingArrayTex ? TextureMode::ARRAY : (isCombinedTex ? TextureMode::COMBINED : TextureMode::SINGLE);

if (isFlippedX) {
input.projectionCenter.x = 1.f - input.projectionCenter.x;
}
if (isFlippedY) {
input.projectionCenter.y = 1.f - input.projectionCenter.y;
}

Viewport outputViewport;
if (d3d11Res->postProcessor->Apply(input, outputViewport)) {
outputBounds.uMin = float(outputViewport.x) / otd.Width;
outputBounds.vMin = float(outputViewport.y) / otd.Height;
outputBounds.uMax = float(outputViewport.width + outputViewport.x) / otd.Width;
outputBounds.vMax = float(outputViewport.height + outputViewport.y) / otd.Height;
if (info.bounds->uMin > info.bounds->uMax) {
std::swap(outputBounds.uMin, outputBounds.uMax);
}
if (info.bounds->vMin > info.bounds->vMax) {
std::swap(outputBounds.vMin, outputBounds.vMax);
}
info.bounds = &outputBounds;

PrepareOutputTexInfo(info.texture, info.submitFlags);
Expand All @@ -392,7 +408,11 @@ namespace vrperfkit {
info.texture = outputTexInfo.get();
}

d3d11Res->variableRateShading->UpdateTargetInformation(itd.Width, itd.Height, input.mode, projCenters.eyeCenter[0].x, projCenters.eyeCenter[0].y, projCenters.eyeCenter[1].x, projCenters.eyeCenter[1].y);
float projLX = isFlippedX ? 1.f - projCenters.eyeCenter[0].x : projCenters.eyeCenter[0].x;
float projLY = isFlippedY ? 1.f - projCenters.eyeCenter[0].y : projCenters.eyeCenter[0].y;
float projRX = isFlippedX ? 1.f - projCenters.eyeCenter[1].x : projCenters.eyeCenter[1].x;
float projRY = isFlippedY ? 1.f - projCenters.eyeCenter[1].y : projCenters.eyeCenter[1].y;
d3d11Res->variableRateShading->UpdateTargetInformation(itd.Width, itd.Height, input.mode, projLX, projLY, projRX, projRY);
}

void OpenVrManager::PatchDxvkSubmit(OpenVrSubmitInfo &info) {
Expand Down

0 comments on commit 6f6b08a

Please sign in to comment.