Skip to content

Commit

Permalink
Fixes, tweaks and updates to work with MSVS 2019 and HoloLens 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jerstlouis committed May 10, 2020
1 parent a7d1de9 commit a2e3cab
Show file tree
Hide file tree
Showing 30 changed files with 1,452 additions and 337 deletions.
2 changes: 1 addition & 1 deletion src/common/mathutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ inline unsigned int unorm(float x)

inline bool supportsSSE2()
{
#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM)
#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) && !defined(_M_ARM64)
static bool checked = false;
static bool supports = false;

Expand Down
2 changes: 1 addition & 1 deletion src/common/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
# undef far
#endif

#if !defined(_M_ARM) && !defined(ANGLE_PLATFORM_ANDROID)
#if !defined(_M_ARM) && !defined(ANGLE_PLATFORM_ANDROID) && !defined(_M_ARM64)
# define ANGLE_USE_SSE
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/libANGLE/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ std::vector<const Config*> ConfigSet::filter(const AttributeMap &attributeMap) c
}

// Sort the result
std::sort(result.begin(), result.end(), ConfigSorter(attributeMap));
// TOCHECK: Was this crashing?
//std::sort(result.begin(), result.end(), ConfigSorter(attributeMap));

return result;
}
Expand Down
16 changes: 8 additions & 8 deletions src/libANGLE/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void Shader::compile(Compiler *compiler)
#ifdef ANGLE_ENABLE_WINDOWS_HOLOGRAPHIC
if (rx::HolographicNativeWindow::IsInitialized() && rx::HolographicSwapChain11::getIsAutomaticStereoRenderingEnabled())
{
// On Windows Holographic, update the shader version to 3, if it is less than that, and
// On Windows Holographic, update the shader version to 3, if it is less than that, and
// apply our stereo instancing modification - which requires gl_InstanceID, which is only
// available on shader version 3 or higher.
bool isGlslesVersion3 = false;
Expand Down Expand Up @@ -294,14 +294,14 @@ void Shader::compile(Compiler *compiler)
}
sourceString = modifiedSourceString;
}

std::string firstStringAlwaysStart = "#version 3";
std::string firstStringAlwaysEnd = "\n";
size_t index0 = sourceString.find(firstStringAlwaysStart);
size_t index1 = sourceString.find(firstStringAlwaysEnd, index0 + 1) + firstStringAlwaysEnd.size();
size_t index2 = sourceString.find_last_of('}');
std::string modifiedSourceString =
sourceString.substr(0, index1) +
std::string modifiedSourceString =
sourceString.substr(0, index1) +
"uniform mat4 uHolographicViewMatrix[2];\n uniform mat4 uHolographicProjectionMatrix[2];\n uniform mat4 uHolographicViewProjectionMatrix[2];\n uniform mat4 uUndoMidViewMatrix;\n out float vRenderTargetArrayIndex;\n " +
sourceString.substr(index1, index2-index1) +
" int index = gl_InstanceIDUnmodified - (gl_InstanceID*2);\n vRenderTargetArrayIndex = float(index);\n gl_Position = uHolographicProjectionMatrix[index] * uHolographicViewMatrix[index] * uUndoMidViewMatrix * gl_Position;\n " +
Expand All @@ -315,8 +315,8 @@ void Shader::compile(Compiler *compiler)
if (!isGlslesVersion3)
{
// Translate the shader to GLSL version 300 syntax.
std::string modifiedSourceString =
std::string("#version 300 es\n ") +
std::string modifiedSourceString =
std::string("#version 300 es\n ") +
"precision mediump float;\n " +
sourceString;
size_t varyingPos = 0;
Expand Down Expand Up @@ -345,8 +345,8 @@ void Shader::compile(Compiler *compiler)

size_t index1 = sourceString.find("void");
size_t index2 = sourceString.find_last_of('}');
std::string modifiedSourceString =
sourceString.substr(0, index1) +
std::string modifiedSourceString =
sourceString.substr(0, index1) +
(!isGlslesVersion3 ? "out vec4 fragColor;\n " : "") +
"in float vRenderTargetArrayIndex;\n " +
sourceString.substr(index1, index2-index1) +
Expand Down
12 changes: 6 additions & 6 deletions src/libANGLE/renderer/d3d/SurfaceD3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ egl::Error SurfaceD3D::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
#ifdef ANGLE_ENABLE_WINDOWS_HOLOGRAPHIC
if (mNativeWindow.isHolographic())
{
// An error was encountered. In this case, we don't have a swap chain to
// An error was encountered. In this case, we don't have a swap chain to
// present, and that is normally where the holographic native window would
// be reset in preparation of acquiring a new holographic frame next time
// the holographic FBO is cleared. So, we reset it here instead to ensure
// the holographic FBO is cleared. So, we reset it here instead to ensure
// that the next frame is still going to be acquired.
HolographicNativeWindow* holographicNativeWindow = reinterpret_cast<HolographicNativeWindow*>(mNativeWindow.GetImpl());
holographicNativeWindow->ResetFrame();
}
#endif
return egl::Error(EGL_SUCCESS);
//return egl::Error(EGL_SUCCESS);
}

if (x + width > mWidth)
Expand Down Expand Up @@ -378,7 +378,7 @@ bool SurfaceD3D::checkForOutOfDateSwapChain()
RECT client;
int clientWidth = getWidth();
int clientHeight = getHeight();
bool sizeDirty = false;
bool sizeDirty = false;
#ifndef ANGLE_ENABLE_WINDOWS_HOLOGRAPHIC
if (!mFixedSize && !mNativeWindow.isIconic())
#else
Expand Down Expand Up @@ -481,7 +481,7 @@ gl::Error SurfaceD3D::getAttachmentRenderTarget(const gl::FramebufferAttachment:
#ifdef ANGLE_ENABLE_WINDOWS_HOLOGRAPHIC
// In holographic mode, the swap chain is provided by the system via a HolographicCamera.
HRESULT hr = S_OK;

// Create/upkeep the holographic swap chain
if (mNativeWindow.isHolographic())
{
Expand All @@ -508,7 +508,7 @@ gl::Error SurfaceD3D::getAttachmentRenderTarget(const gl::FramebufferAttachment:
{
if (i++ == 0)
{
// For now, we make the first holographic camera the "primary"
// For now, we make the first holographic camera the "primary"
// swap chain.
mSwapChain = swapChain;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/d3d/SwapChainD3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SwapChainD3D : angle::NonCopyable
virtual ~SwapChainD3D() {};

virtual EGLint resize(EGLint backbufferWidth, EGLint backbufferSize) = 0;
virtual EGLint reset(EGLint backbufferWidth, EGLint backbufferHeight, EGLint swapInterval) = 0;
virtual EGLint reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval) = 0;
virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height) = 0;
virtual void recreate() = 0;

Expand Down
6 changes: 3 additions & 3 deletions src/libANGLE/renderer/d3d/d3d11/Clear11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
return gl::Error(GL_INVALID_OPERATION);
}

if (clearParams.scissorEnabled && (clearParams.scissor.x >= framebufferSize.width ||
if (clearParams.scissorEnabled && (clearParams.scissor.x >= framebufferSize.width ||
clearParams.scissor.y >= framebufferSize.height ||
clearParams.scissor.x + clearParams.scissor.width <= 0 ||
clearParams.scissor.y + clearParams.scissor.height <= 0))
Expand Down Expand Up @@ -320,7 +320,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
else
{
// ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView is possible

ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView();
if (!framebufferRTV)
{
Expand Down Expand Up @@ -420,7 +420,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, const gl
(clearParams.clearStencil ? D3D11_CLEAR_STENCIL : 0);
FLOAT depthClear = gl::clamp01(clearParams.depthClearValue);
UINT8 stencilClear = clearParams.stencilClearValue & 0xFF;

#ifdef ANGLE_ENABLE_WINDOWS_HOLOGRAPHIC
if (renderTarget->isHolographic())
{
Expand Down
22 changes: 11 additions & 11 deletions src/libANGLE/renderer/d3d/d3d11/Renderer11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ egl::Error Renderer11::initializeD3DDevice()
static_cast<unsigned int>(mAvailableFeatureLevels.size()),
D3D11_SDK_VERSION, &mDevice,
&(mRenderer11DeviceCaps.featureLevel), &mDeviceContext);

// Cleanup done by destructor
if (!mDevice || FAILED(result))
{
Expand Down Expand Up @@ -2013,11 +2013,11 @@ gl::Error Renderer11::drawInstancedToCamerasIfHolographic(
{
return gl::Error(GL_NO_ERROR);
}

#ifdef ANGLE_ENABLE_WINDOWS_HOLOGRAPHIC
if (renderTarget11->isHolographic())
{
// For Windows Holographic, we repeat the draw call for each of the holographic cameras that
// For Windows Holographic, we repeat the draw call for each of the holographic cameras that
// are provided by the system.

// Note that system view and projection matrices will be applied to each camera; the
Expand All @@ -2028,8 +2028,8 @@ gl::Error Renderer11::drawInstancedToCamerasIfHolographic(
// Acquire the holographic native window.
HolographicSwapChain11* holographicSwapChain11 = renderTarget11->getHolographicSwapChain11();
auto holographicNativeWindow = holographicSwapChain11->getHolographicNativeWindow();
// For each active camera ID, set the viewport, view and projection matrics, and render target

// For each active camera ID, set the viewport, view and projection matrics, and render target
// and draw in stereo using an instanced draw call.
for each (auto const& cameraId in holographicNativeWindow->GetCameraIds())
{
Expand All @@ -2056,7 +2056,7 @@ gl::Error Renderer11::drawInstancedToCamerasIfHolographic(
mDeviceContext->DrawIndexedInstanced(count, instances, 0, baseVertexLocation, 0);
}
}

// Note that the viewport in mStateManager cannot be read back, so we do not
// bother resetting it to what it was before we looped over the holographic
// cameras.
Expand Down Expand Up @@ -2352,7 +2352,7 @@ gl::Error Renderer11::applyShadersImpl(const gl::Data &data, GLenum drawMode)
#ifdef ANGLE_ENABLE_WINDOWS_HOLOGRAPHIC
// On devices that support setting the render target array index from any shader stage, we
// can use a more optimal shader pipeline.
// In this pipeline, we can eliminate the geometry shader stage - which is normally required
// In this pipeline, we can eliminate the geometry shader stage - which is normally required
// to set the render target array index. Avoiding the extra pipeline stage eliminates a step
// in the rendering pipeline, and it may also allow the graphics driver to better optimize for
// the draw call.
Expand Down Expand Up @@ -3477,9 +3477,9 @@ gl::Error Renderer11::loadExecutable(const void *function,
}
catch (_com_error /*err*/)
{
// The shader that uses the optional Direct3D 11.3 feature to set the render
// target array index from any shader stage will always fail to compile on
// machines that don't support the optional Direct3D 11.3 feature to set the
// The shader that uses the optional Direct3D 11.3 feature to set the render
// target array index from any shader stage will always fail to compile on
// machines that don't support the optional Direct3D 11.3 feature to set the
// render target array index.
// So, we do not assert here - instead, we catch a COM exception and return an
// error that indicates to the calling class that it should use the geometry
Expand All @@ -3489,7 +3489,7 @@ gl::Error Renderer11::loadExecutable(const void *function,
}
#else
HRESULT result = mDevice->CreateVertexShader(function, length, NULL, &vertexShader);
ASSERT(SUCCEEDED(result));
ASSERT(SUCCEEDED(result));
#endif
if (FAILED(result))
{
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/d3d/d3d11/SwapChain11.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SwapChain11 : public SwapChainD3D
virtual ~SwapChain11();

EGLint resize(EGLint backbufferWidth, EGLint backbufferHeight);
virtual EGLint reset(EGLint backbufferWidth, EGLint backbufferHeight, EGLint swapInterval);
virtual EGLint reset(int backbufferWidth, int backbufferHeight, EGLint swapInterval);
virtual EGLint swapRect(EGLint x, EGLint y, EGLint width, EGLint height);
virtual void recreate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWind

static float GetLogicalDpi()
{
/* FIXME:
ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> displayProperties;
if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), displayProperties.GetAddressOf())))
Expand All @@ -225,7 +226,7 @@ static float GetLogicalDpi()
return dpi;
}
}

*/
// Return 96 dpi as a default if display properties cannot be obtained.
return 96.0f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ namespace HolographicDepthBasedImageStabilization
double sumWeights = 0;
};
}

#if !defined(_M_ARM64)
inline float __vectorcall VectorHorizontalSum(__m128 x)
{
__m128 temp = _mm_hadd_ps(x, x);
return _mm_cvtss_f32(_mm_hadd_ps(temp, temp));
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace HolographicDepthBasedImageStabilization {
unsigned int const& outHeight,
unsigned short const& invalidDepthValue)
{
#if !defined(_M_ARM) && !defined(_M_ARM64)
using namespace DirectX;

uint16_t* depthRow = reinterpret_cast<uint16_t*>(pData);
Expand Down Expand Up @@ -124,5 +125,6 @@ namespace HolographicDepthBasedImageStabilization {

depthRow = reinterpret_cast<uint16_t*>(reinterpret_cast<byte*>(depthRow) + rowPitch);
}
#endif
}
}
28 changes: 14 additions & 14 deletions src/libANGLE/renderer/d3d/d3d11/winrt/HolographicNativeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

// HolographicNativeWindow.cpp: NativeWindow for managing windows based on Windows Holographic app views.
//
// This implementation uses the frame of reference provided by the app to render a stereo version of
// the scene. It can provide a view matrix midway between both eye positions of the holographic camera
// for the app to use, and in this case the app is expected to use a projection matrix that is the
// identity matrix (or no projection matrix at all). Internally to ANGLE, the stereo rendering will
// double the number of instances provided to the shader - which is hidden from the shader by halving
// the value set for gl_InstanceID - and apply the left and right view matrices to each eye, after
// This implementation uses the frame of reference provided by the app to render a stereo version of
// the scene. It can provide a view matrix midway between both eye positions of the holographic camera
// for the app to use, and in this case the app is expected to use a projection matrix that is the
// identity matrix (or no projection matrix at all). Internally to ANGLE, the stereo rendering will
// double the number of instances provided to the shader - which is hidden from the shader by halving
// the value set for gl_InstanceID - and apply the left and right view matrices to each eye, after
// undoing the midview matrix.
//
// Alternatively, the app can use its own instanced draw calls and access the holographic view/projection
// matrix provided by ANGLE by using odd and even instance IDs for left and right views. In this case, the
// Alternatively, the app can use its own instanced draw calls and access the holographic view/projection
// matrix provided by ANGLE by using odd and even instance IDs for left and right views. In this case, the
// shader program is not modified.
//
// This implementation can also use automatic depth-based image stabilization. This feature determines a
// best-fit plane for the scene geometry by processing geometry data from the depth buffer, and then sets
// the focus point and plane for Windows Holographic image stabilization. To take advantage of this
// This implementation can also use automatic depth-based image stabilization. This feature determines a
// best-fit plane for the scene geometry by processing geometry data from the depth buffer, and then sets
// the focus point and plane for Windows Holographic image stabilization. To take advantage of this
// feature, make sure to apply the following rules when drawing content:
// * All information in the depth buffer should be for hologram geometry that is visible
// to the user.
Expand Down Expand Up @@ -468,7 +468,7 @@ HRESULT HolographicNativeWindow::getPreferredDeviceFeatureSupport()
// Check for device support for the optional feature that allows setting the render target array index from the vertex shader stage.
D3D11_FEATURE_DATA_D3D11_OPTIONS3 options;
HRESULT hr = mPreferredD3DDevice->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS3, &options, sizeof(options));

if (SUCCEEDED(hr))
{
if (options.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer)
Expand Down Expand Up @@ -612,10 +612,10 @@ HRESULT HolographicNativeWindow::UpdateHolographicResources()
return E_UNEXPECTED;
}
}

ComPtr<ABI::Windows::Graphics::Holographic::IHolographicFrame> holographicFrame;
HRESULT hr = mHolographicSpace->CreateNextFrame(holographicFrame.GetAddressOf());

if (SUCCEEDED(hr))
{
mHolographicFrame = holographicFrame;
Expand Down
Loading

0 comments on commit a2e3cab

Please sign in to comment.