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 ...@@ -817,8 +817,12 @@ bool Buffer11::NativeStorage::copyFromStorage(BufferStorage *source, size_t sour
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT hr = context->Map(mNativeStorage, 0, D3D11_MAP_WRITE, 0, &mappedResource); HRESULT hr = context->Map(mNativeStorage, 0, D3D11_MAP_WRITE, 0, &mappedResource);
UNUSED_ASSERTION_VARIABLE(hr);
ASSERT(SUCCEEDED(hr)); ASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
source->unmap();
return false;
}
uint8_t *destPointer = static_cast<uint8_t *>(mappedResource.pData) + destOffset; 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 ...@@ -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); UINT d3dMapFlag = ((access & GL_MAP_UNSYNCHRONIZED_BIT) != 0 ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0);
HRESULT result = context->Map(mNativeStorage, 0, d3dMapType, d3dMapFlag, &mappedResource); HRESULT result = context->Map(mNativeStorage, 0, d3dMapType, d3dMapFlag, &mappedResource);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return nullptr;
}
return static_cast<uint8_t*>(mappedResource.pData) + offset; return static_cast<uint8_t*>(mappedResource.pData) + offset;
} }
......
...@@ -95,14 +95,15 @@ void DebugAnnotator11::initializeDevice() ...@@ -95,14 +95,15 @@ void DebugAnnotator11::initializeDevice()
// Create a D3D_DRIVER_TYPE_NULL device, which is much cheaper than other types of device. // 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); hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_NULL, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, &device, nullptr, &context);
ASSERT(SUCCEEDED(hr)); ASSERT(SUCCEEDED(hr));
if (SUCCEEDED(hr))
mUserDefinedAnnotation = d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context); {
ASSERT(mUserDefinedAnnotation != nullptr); mUserDefinedAnnotation = d3d11::DynamicCastComObject<ID3DUserDefinedAnnotation>(context);
ASSERT(mUserDefinedAnnotation != nullptr);
mInitialized = true;
}
SafeRelease(device); SafeRelease(device);
SafeRelease(context); SafeRelease(context);
mInitialized = true;
} }
} }
......
...@@ -236,6 +236,8 @@ Renderer11::Renderer11(egl::Display *display) ...@@ -236,6 +236,8 @@ Renderer11::Renderer11(egl::Display *display)
mAppliedNumXFBBindings = static_cast<size_t>(-1); mAppliedNumXFBBindings = static_cast<size_t>(-1);
ZeroMemory(&mAdapterDescription, sizeof(mAdapterDescription));
const auto &attributes = mDisplay->getAttributeMap(); const auto &attributes = mDisplay->getAttributeMap();
EGLint requestedMajorVersion = attributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, EGL_DONT_CARE); EGLint requestedMajorVersion = attributes.get(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, EGL_DONT_CARE);
...@@ -467,26 +469,35 @@ egl::Error Renderer11::initialize() ...@@ -467,26 +469,35 @@ egl::Error Renderer11::initialize()
if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3 && dxgiAdapter2 != NULL) if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3 && dxgiAdapter2 != NULL)
{ {
DXGI_ADAPTER_DESC2 adapterDesc2 = { 0 }; DXGI_ADAPTER_DESC2 adapterDesc2 = { 0 };
dxgiAdapter2->GetDesc2(&adapterDesc2); 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)); // Copy the contents of the DXGI_ADAPTER_DESC2 into mAdapterDescription (a DXGI_ADAPTER_DESC).
mAdapterDescription.VendorId = adapterDesc2.VendorId; memcpy(mAdapterDescription.Description, adapterDesc2.Description, sizeof(mAdapterDescription.Description));
mAdapterDescription.DeviceId = adapterDesc2.DeviceId; mAdapterDescription.VendorId = adapterDesc2.VendorId;
mAdapterDescription.SubSysId = adapterDesc2.SubSysId; mAdapterDescription.DeviceId = adapterDesc2.DeviceId;
mAdapterDescription.Revision = adapterDesc2.Revision; mAdapterDescription.SubSysId = adapterDesc2.SubSysId;
mAdapterDescription.DedicatedVideoMemory = adapterDesc2.DedicatedVideoMemory; mAdapterDescription.Revision = adapterDesc2.Revision;
mAdapterDescription.DedicatedSystemMemory = adapterDesc2.DedicatedSystemMemory; mAdapterDescription.DedicatedVideoMemory = adapterDesc2.DedicatedVideoMemory;
mAdapterDescription.SharedSystemMemory = adapterDesc2.SharedSystemMemory; mAdapterDescription.DedicatedSystemMemory = adapterDesc2.DedicatedSystemMemory;
mAdapterDescription.AdapterLuid = adapterDesc2.AdapterLuid; mAdapterDescription.SharedSystemMemory = adapterDesc2.SharedSystemMemory;
mAdapterDescription.AdapterLuid = adapterDesc2.AdapterLuid;
}
} }
else else
{ {
mDxgiAdapter->GetDesc(&mAdapterDescription); result = mDxgiAdapter->GetDesc(&mAdapterDescription);
} }
SafeRelease(dxgiAdapter2); 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)); memset(mDescription, 0, sizeof(mDescription));
wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1);
...@@ -2098,9 +2109,11 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto ...@@ -2098,9 +2109,11 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto
constantBufferDescription.StructureByteStride = 0; constantBufferDescription.StructureByteStride = 0;
HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferVS); HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferVS);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(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); mDeviceContext->VSSetConstantBuffers(1, 1, &mDriverConstantBufferVS);
} }
...@@ -2115,22 +2128,32 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto ...@@ -2115,22 +2128,32 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto
constantBufferDescription.StructureByteStride = 0; constantBufferDescription.StructureByteStride = 0;
HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferPS); HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &mDriverConstantBufferPS);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(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); mDeviceContext->PSSetConstantBuffers(1, 1, &mDriverConstantBufferPS);
} }
if (memcmp(&mVertexConstants, &mAppliedVertexConstants, sizeof(dx_VertexConstants)) != 0) if (memcmp(&mVertexConstants, &mAppliedVertexConstants, sizeof(dx_VertexConstants)) != 0)
{ {
mDeviceContext->UpdateSubresource(mDriverConstantBufferVS, 0, NULL, &mVertexConstants, 16, 0); ASSERT(mDriverConstantBufferVS != nullptr);
memcpy(&mAppliedVertexConstants, &mVertexConstants, sizeof(dx_VertexConstants)); if (mDriverConstantBufferVS)
{
mDeviceContext->UpdateSubresource(mDriverConstantBufferVS, 0, NULL, &mVertexConstants, 16, 0);
memcpy(&mAppliedVertexConstants, &mVertexConstants, sizeof(dx_VertexConstants));
}
} }
if (memcmp(&mPixelConstants, &mAppliedPixelConstants, sizeof(dx_PixelConstants)) != 0) if (memcmp(&mPixelConstants, &mAppliedPixelConstants, sizeof(dx_PixelConstants)) != 0)
{ {
mDeviceContext->UpdateSubresource(mDriverConstantBufferPS, 0, NULL, &mPixelConstants, 16, 0); ASSERT(mDriverConstantBufferPS != nullptr);
memcpy(&mAppliedPixelConstants, &mPixelConstants, sizeof(dx_PixelConstants)); 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 // 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 ...@@ -2139,8 +2162,12 @@ gl::Error Renderer11::applyUniforms(const ProgramImpl &program, const std::vecto
// needed for the point sprite geometry shader // needed for the point sprite geometry shader
if (mCurrentGeometryConstantBuffer != mDriverConstantBufferPS) if (mCurrentGeometryConstantBuffer != mDriverConstantBufferPS)
{ {
mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS); ASSERT(mDriverConstantBufferPS != nullptr);
mCurrentGeometryConstantBuffer = mDriverConstantBufferPS; if (mDriverConstantBufferPS)
{
mDeviceContext->GSSetConstantBuffers(0, 1, &mDriverConstantBufferPS);
mCurrentGeometryConstantBuffer = mDriverConstantBufferPS;
}
} }
} }
......
...@@ -350,9 +350,16 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight) ...@@ -350,9 +350,16 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
// Resize swap chain // Resize swap chain
DXGI_SWAP_CHAIN_DESC desc; 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()); 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)) if (FAILED(result))
{ {
...@@ -374,10 +381,10 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight) ...@@ -374,10 +381,10 @@ EGLint SwapChain11::resize(EGLint backbufferWidth, EGLint backbufferHeight)
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture"); 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)) if (SUCCEEDED(result))
{ {
d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target"); d3d11::SetDebugName(mBackBufferRTView, "Back buffer render target");
......
...@@ -137,12 +137,15 @@ inline bool isDeviceLostError(HRESULT errorCode) ...@@ -137,12 +137,15 @@ inline bool isDeviceLostError(HRESULT errorCode)
inline ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name) inline ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{ {
ID3D11VertexShader *vs = NULL; ID3D11VertexShader *vs = nullptr;
HRESULT result = device->CreateVertexShader(byteCode, N, NULL, &vs); HRESULT result = device->CreateVertexShader(byteCode, N, nullptr, &vs);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
SetDebugName(vs, name); if (SUCCEEDED(result))
return vs; {
SetDebugName(vs, name);
return vs;
}
return nullptr;
} }
template <unsigned int N> template <unsigned int N>
...@@ -153,12 +156,15 @@ ID3D11VertexShader *CompileVS(ID3D11Device *device, const BYTE (&byteCode)[N], c ...@@ -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) inline ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{ {
ID3D11GeometryShader *gs = NULL; ID3D11GeometryShader *gs = nullptr;
HRESULT result = device->CreateGeometryShader(byteCode, N, NULL, &gs); HRESULT result = device->CreateGeometryShader(byteCode, N, nullptr, &gs);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
SetDebugName(gs, name); if (SUCCEEDED(result))
return gs; {
SetDebugName(gs, name);
return gs;
}
return nullptr;
} }
template <unsigned int N> template <unsigned int N>
...@@ -169,12 +175,15 @@ ID3D11GeometryShader *CompileGS(ID3D11Device *device, const BYTE (&byteCode)[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) inline ID3D11PixelShader *CompilePS(ID3D11Device *device, const BYTE *byteCode, size_t N, const char *name)
{ {
ID3D11PixelShader *ps = NULL; ID3D11PixelShader *ps = nullptr;
HRESULT result = device->CreatePixelShader(byteCode, N, NULL, &ps); HRESULT result = device->CreatePixelShader(byteCode, N, nullptr, &ps);
UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
SetDebugName(ps, name); if (SUCCEEDED(result))
return ps; {
SetDebugName(ps, name);
return ps;
}
return nullptr;
} }
template <unsigned int N> template <unsigned int N>
...@@ -259,12 +268,14 @@ inline ID3D11PixelShader *DeferredShader<ID3D11PixelShader>::getShader(ID3D11Dev ...@@ -259,12 +268,14 @@ inline ID3D11PixelShader *DeferredShader<ID3D11PixelShader>::getShader(ID3D11Dev
template <class T> template <class T>
void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, const T &value) void SetBufferData(ID3D11DeviceContext *context, ID3D11Buffer *constantBuffer, const T &value)
{ {
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource = {};
context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); HRESULT result = context->Map(constantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
ASSERT(SUCCEEDED(result));
memcpy(mappedResource.pData, &value, sizeof(T)); if (SUCCEEDED(result))
{
context->Unmap(constantBuffer, 0); memcpy(mappedResource.pData, &value, sizeof(T));
context->Unmap(constantBuffer, 0);
}
} }
Workarounds GenerateWorkarounds(D3D_FEATURE_LEVEL featureLevel); Workarounds GenerateWorkarounds(D3D_FEATURE_LEVEL featureLevel);
......
...@@ -169,16 +169,18 @@ HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWind ...@@ -169,16 +169,18 @@ HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWind
static float GetLogicalDpi() static float GetLogicalDpi()
{ {
ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> displayProperties; ComPtr<ABI::Windows::Graphics::Display::IDisplayPropertiesStatics> displayProperties;
float dpi = 96.0f;
if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), displayProperties.GetAddressOf()))) if (SUCCEEDED(GetActivationFactory(HStringReference(RuntimeClass_Windows_Graphics_Display_DisplayProperties).Get(), displayProperties.GetAddressOf())))
{ {
float dpi = 96.0f;
if (SUCCEEDED(displayProperties->get_LogicalDpi(&dpi))) if (SUCCEEDED(displayProperties->get_LogicalDpi(&dpi)))
{ {
return dpi; return dpi;
} }
} }
return dpi;
// Return 96 dpi as a default if display properties cannot be obtained.
return 96.0f;
} }
long ConvertDipsToPixels(float dips) long ConvertDipsToPixels(float dips)
......
...@@ -221,7 +221,7 @@ HRESULT GetOptionalSizePropertyValue(const ComPtr<ABI::Windows::Foundation::Coll ...@@ -221,7 +221,7 @@ HRESULT GetOptionalSizePropertyValue(const ComPtr<ABI::Windows::Foundation::Coll
{ {
if (!propertyMap || !propertyName || !value || !valueExists) if (!propertyMap || !propertyName || !value || !valueExists)
{ {
return false; return E_INVALIDARG;
} }
// Assume that the value does not exist // 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