Commit ab4fd98f by Cooper Partin Committed by Geoff Lang

Small fixes for passing code analysis tools.

BUG=angleproject:1005 Change-Id: I8f2a6c0a5a6157303e436b96cc4c4ff1c29cfe18 Reviewed-on: https://chromium-review.googlesource.com/271600Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 3975ddec
......@@ -817,8 +817,12 @@ bool Buffer11::NativeStorage::copyFromStorage(BufferStorage *source, size_t sour
D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT hr = context->Map(mNativeStorage, 0, D3D11_MAP_WRITE, 0, &mappedResource);
UNUSED_ASSERTION_VARIABLE(hr);
ASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
source->unmap();
return false;
}
uint8_t *destPointer = static_cast<uint8_t *>(mappedResource.pData) + destOffset;
......@@ -955,9 +959,11 @@ uint8_t *Buffer11::NativeStorage::map(size_t offset, size_t length, GLbitfield a
UINT d3dMapFlag = ((access & GL_MAP_UNSYNCHRONIZED_BIT) != 0 ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0);
HRESULT result = context->Map(mNativeStorage, 0, d3dMapType, d3dMapFlag, &mappedResource);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return nullptr;
}
return static_cast<uint8_t*>(mappedResource.pData) + offset;
}
......
......@@ -95,14 +95,15 @@ void DebugAnnotator11::initializeDevice()
// Create a D3D_DRIVER_TYPE_NULL device, which is much cheaper than other types of device.
hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_NULL, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, &device, nullptr, &context);
ASSERT(SUCCEEDED(hr));
mUserDefinedAnnotation = d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context);
ASSERT(mUserDefinedAnnotation != nullptr);
if (SUCCEEDED(hr))
{
mUserDefinedAnnotation = d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context);
ASSERT(mUserDefinedAnnotation != nullptr);
mInitialized = true;
}
SafeRelease(device);
SafeRelease(context);
mInitialized = true;
}
}
......
......@@ -236,6 +236,8 @@ Renderer11::Renderer11(egl::Display *display)
mAppliedNumXFBBindings = static_cast<size_t>(-1);
ZeroMemory(&mAdapterDescription, sizeof(mAdapterDescription));
const auto &attributes = mDisplay->getAttributeMap();
EGLint requestedMajorVersion = attributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, EGL_DONT_CARE);
......@@ -467,26 +469,35 @@ egl::Error Renderer11::initialize()
if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3 && dxgiAdapter2 != NULL)
{
DXGI_ADAPTER_DESC2 adapterDesc2 = { 0 };
dxgiAdapter2->GetDesc2(&adapterDesc2);
// Copy the contents of the DXGI_ADAPTER_DESC2 into mAdapterDescription (a DXGI_ADAPTER_DESC).
memcpy(mAdapterDescription.Description, adapterDesc2.Description, sizeof(mAdapterDescription.Description));
mAdapterDescription.VendorId = adapterDesc2.VendorId;
mAdapterDescription.DeviceId = adapterDesc2.DeviceId;
mAdapterDescription.SubSysId = adapterDesc2.SubSysId;
mAdapterDescription.Revision = adapterDesc2.Revision;
mAdapterDescription.DedicatedVideoMemory = adapterDesc2.DedicatedVideoMemory;
mAdapterDescription.DedicatedSystemMemory = adapterDesc2.DedicatedSystemMemory;
mAdapterDescription.SharedSystemMemory = adapterDesc2.SharedSystemMemory;
mAdapterDescription.AdapterLuid = adapterDesc2.AdapterLuid;
result = dxgiAdapter2->GetDesc2(&adapterDesc2);
if (SUCCEEDED(result))
{
// Copy the contents of the DXGI_ADAPTER_DESC2 into mAdapterDescription (a DXGI_ADAPTER_DESC).
memcpy(mAdapterDescription.Description, adapterDesc2.Description, sizeof(mAdapterDescription.Description));
mAdapterDescription.VendorId = adapterDesc2.VendorId;
mAdapterDescription.DeviceId = adapterDesc2.DeviceId;
mAdapterDescription.SubSysId = adapterDesc2.SubSysId;
mAdapterDescription.Revision = adapterDesc2.Revision;
mAdapterDescription.DedicatedVideoMemory = adapterDesc2.DedicatedVideoMemory;
mAdapterDescription.DedicatedSystemMemory = adapterDesc2.DedicatedSystemMemory;
mAdapterDescription.SharedSystemMemory = adapterDesc2.SharedSystemMemory;
mAdapterDescription.AdapterLuid = adapterDesc2.AdapterLuid;
}
}
else
{
mDxgiAdapter->GetDesc(&mAdapterDescription);
result = mDxgiAdapter->GetDesc(&mAdapterDescription);
}
SafeRelease(dxgiAdapter2);
if (FAILED(result))
{
return egl::Error(EGL_NOT_INITIALIZED,
D3D11_INIT_OTHER_ERROR,
"Could not read DXGI adaptor description.");
}
memset(mDescription, 0, sizeof(mDescription));
wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1);
......@@ -2098,9 +2109,11 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto
constantBufferDescription.StructureByteStride = 0;
HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferVS);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create vertex shader constant buffer, result: 0x%X.", result);
}
mDeviceContext->VSSetConstantBuffers(1, 1, &mDriverConstantBufferVS);
}
......@@ -2115,22 +2128,32 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto
constantBufferDescription.StructureByteStride = 0;
HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferPS);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create pixel shader constant buffer, result: 0x%X.", result);
}
mDeviceContext->PSSetConstantBuffers(1, 1, &mDriverConstantBufferPS);
}
if (memcmp(&mVertexConstants, &mAppliedVertexConstants, sizeof(dx_VertexConstants)) != 0)
{
mDeviceContext->UpdateSubresource(mDriverConstantBufferVS, 0, NULL, &mVertexConstants, 16, 0);
memcpy(&mAppliedVertexConstants, &mVertexConstants, sizeof(dx_VertexConstants));
ASSERT(mDriverConstantBufferVS != nullptr);
if (mDriverConstantBufferVS)
{
mDeviceContext->UpdateSubresource(mDriverConstantBufferVS, 0, NULL, &mVertexConstants, 16, 0);
memcpy(&mAppliedVertexConstants, &mVertexConstants, sizeof(dx_VertexConstants));
}
}
if (memcmp(&mPixelConstants, &mAppliedPixelConstants, sizeof(dx_PixelConstants)) != 0)
{
mDeviceContext->UpdateSubresource(mDriverConstantBufferPS, 0, NULL, &mPixelConstants, 16, 0);
memcpy(&mAppliedPixelConstants, &mPixelConstants, sizeof(dx_PixelConstants));
ASSERT(mDriverConstantBufferPS != nullptr);
if (mDriverConstantBufferPS)
{
mDeviceContext->UpdateSubresource(mDriverConstantBufferPS, 0, NULL, &mPixelConstants, 16, 0);
memcpy(&mAppliedPixelConstants, &mPixelConstants, sizeof(dx_PixelConstants));
}
}
// GSSetConstantBuffers triggers device removal on 9_3, so we should only call it if necessary
......@@ -2139,8 +2162,12 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto
// needed for the point sprite geometry shader
if (mCurrentGeometryConstantBuffer != mDriverConstantBufferPS)
{
mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS);
mCurrentGeometryConstantBuffer = mDriverConstantBufferPS;
ASSERT(mDriverConstantBufferPS != nullptr);
if (mDriverConstantBufferPS)
{
mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS);
mCurrentGeometryConstantBuffer = mDriverConstantBufferPS;
}
}
}
......
......@@ -350,9 +350,16 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
// Resize swap chain
DXGI_SWAP_CHAIN_DESC desc;
mSwapChain->GetDesc(&desc);
HRESULT result = mSwapChain->GetDesc(&desc);
if (FAILED(result))
{
ERR("Error reading swap chain description: 0x%08X", result);
release();
return EGL_BAD_ALLOC;
}
const d3d11::TextureFormat &backbufferFormatInfo = d3d11::GetTextureFormatInfo(mBackBufferFormat, mRenderer->getRenderer11DeviceCaps());
HRESULT result = mSwapChain->ResizeBuffers(desc.BufferCount, backbufferWidth, backbufferHeight, backbufferFormatInfo.texFormat, 0);
result = mSwapChain->ResizeBuffers(desc.BufferCount, backbufferWidth, backbufferHeight, backbufferFormatInfo.texFormat, 0);
if (FAILED(result))
{
......@@ -374,10 +381,10 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
if (SUCCEEDED(result))
{
d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture");
result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView);
ASSERT(SUCCEEDED(result));
}
result = device->CreateRenderTargetView(mBackBufferTexture, NULL, &mBackBufferRTView);
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result))
{
d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target");
......
......@@ -137,12 +137,15 @@ inline bool isDeviceLostError(HRESULT errorCode)
inline ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{
ID3D11VertexShader *vs = NULL;
HRESULT result = device->CreateVertexShader(byteCode, N, NULL, &vs);
UNUSED_ASSERTION_VARIABLE(result);
ID3D11VertexShader *vs = nullptr;
HRESULT result = device->CreateVertexShader(byteCode, N, nullptr, &vs);
ASSERT(SUCCEEDED(result));
SetDebugName(vs, name);
return vs;
if (SUCCEEDED(result))
{
SetDebugName(vs, name);
return vs;
}
return nullptr;
}
template <unsigned int N>
......@@ -153,12 +156,15 @@ ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE (&byteCode)[N], c
inline ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{
ID3D11GeometryShader *gs = NULL;
HRESULT result = device->CreateGeometryShader(byteCode, N, NULL, &gs);
UNUSED_ASSERTION_VARIABLE(result);
ID3D11GeometryShader *gs = nullptr;
HRESULT result = device->CreateGeometryShader(byteCode, N, nullptr, &gs);
ASSERT(SUCCEEDED(result));
SetDebugName(gs, name);
return gs;
if (SUCCEEDED(result))
{
SetDebugName(gs, name);
return gs;
}
return nullptr;
}
template <unsigned int N>
......@@ -169,12 +175,15 @@ ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE (&byteCode)[N],
inline ID3D11PixelShader *CompilePS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{
ID3D11PixelShader *ps = NULL;
HRESULT result = device->CreatePixelShader(byteCode, N, NULL, &ps);
UNUSED_ASSERTION_VARIABLE(result);
ID3D11PixelShader *ps = nullptr;
HRESULT result = device->CreatePixelShader(byteCode, N, nullptr, &ps);
ASSERT(SUCCEEDED(result));
SetDebugName(ps, name);
return ps;
if (SUCCEEDED(result))
{
SetDebugName(ps, name);
return ps;
}
return nullptr;
}
template <unsigned int N>
......@@ -259,12 +268,14 @@ inline ID3D11PixelShader *DeferredShader<ID3D11PixelShader>::getShader(ID3D11Dev
template <class T>
void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, const T &value)
{
D3D11_MAPPED_SUBRESOURCE mappedResource;
context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
memcpy(mappedResource.pData, &value, sizeof(T));
context->Unmap(constantBuffer, 0);
D3D11_MAPPED_SUBRESOURCE mappedResource = {};
HRESULT result = context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result))
{
memcpy(mappedResource.pData, &value, sizeof(T));
context->Unmap(constantBuffer, 0);
}
}
Workarounds GenerateWorkarounds(D3D_FEATURE_LEVEL featureLevel);
......
......@@ -169,16 +169,18 @@ HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWind
static float GetLogicalDpi()
{
ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> displayProperties;
float dpi = 96.0f;
if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), displayProperties.GetAddressOf())))
{
float dpi = 96.0f;
if (SUCCEEDED(displayProperties->get_LogicalDpi(&dpi)))
{
return dpi;
}
}
return dpi;
// Return 96 dpi as a default if display properties cannot be obtained.
return 96.0f;
}
long ConvertDipsToPixels(float dips)
......
......@@ -221,7 +221,7 @@ HRESULT GetOptionalSizePropertyValue(const ComPtr<ABI::Windows::Foundation::Coll
{
if (!propertyMap || !propertyName || !value || !valueExists)
{
return false;
return E_INVALIDARG;
}
// Assume that the value does not exist
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment