diff options
Diffstat (limited to 'src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp')
-rw-r--r-- | src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp | 152 |
1 files changed, 69 insertions, 83 deletions
diff --git a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp index 2f47ec0a67..9bc5b1d2d1 100644 --- a/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp +++ b/src/3rdparty/angle/src/libGLESv2/renderer/d3d/d3d11/VertexBuffer11.cpp @@ -1,4 +1,3 @@ -#include "precompiled.h" // // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -9,11 +8,10 @@ #include "libGLESv2/renderer/d3d/d3d11/VertexBuffer11.h" #include "libGLESv2/renderer/d3d/d3d11/Buffer11.h" - -#include "libGLESv2/Buffer.h" #include "libGLESv2/renderer/d3d/d3d11/Renderer11.h" -#include "libGLESv2/VertexAttribute.h" #include "libGLESv2/renderer/d3d/d3d11/formatutils11.h" +#include "libGLESv2/Buffer.h" +#include "libGLESv2/VertexAttribute.h" namespace rx { @@ -30,7 +28,7 @@ VertexBuffer11::~VertexBuffer11() SafeRelease(mBuffer); } -bool VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) +gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) { SafeRelease(mBuffer); @@ -51,13 +49,14 @@ bool VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) HRESULT result = dxDevice->CreateBuffer(&bufferDesc, NULL, &mBuffer); if (FAILED(result)) { - return false; + return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate internal vertex buffer of size, %lu.", size); } } mBufferSize = size; mDynamicUsage = dynamicUsage; - return true; + + return gl::Error(GL_NO_ERROR); } VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer) @@ -66,66 +65,62 @@ VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer) return static_cast<VertexBuffer11*>(vetexBuffer); } -bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue, - GLint start, GLsizei count, GLsizei instances, unsigned int offset) +gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData ¤tValue, + GLint start, GLsizei count, GLsizei instances, unsigned int offset) { - if (mBuffer) + if (!mBuffer) { - gl::Buffer *buffer = attrib.buffer.get(); - int inputStride = ComputeVertexAttributeStride(attrib); - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); + return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized."); + } - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource); - if (FAILED(result)) - { - ERR("Vertex buffer map failed with error 0x%08x", result); - return false; - } + gl::Buffer *buffer = attrib.buffer.get(); + int inputStride = ComputeVertexAttributeStride(attrib); + ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - char* output = reinterpret_cast<char*>(mappedResource.pData) + offset; + D3D11_MAPPED_SUBRESOURCE mappedResource; + HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource); + if (FAILED(result)) + { + return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal vertex buffer, HRESULT: 0x%08x.", result); + } - const char *input = NULL; - if (attrib.enabled) + uint8_t *output = reinterpret_cast<uint8_t*>(mappedResource.pData) + offset; + + const uint8_t *input = NULL; + if (attrib.enabled) + { + if (buffer) { - if (buffer) - { - Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation()); - input = static_cast<const char*>(storage->getData()) + static_cast<int>(attrib.offset); - } - else - { - input = static_cast<const char*>(attrib.pointer); - } + Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation()); + input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset); } else { - input = reinterpret_cast<const char*>(currentValue.FloatValues); - } - - if (instances == 0 || attrib.divisor == 0) - { - input += inputStride * start; + input = static_cast<const uint8_t*>(attrib.pointer); } - - gl::VertexFormat vertexFormat(attrib, currentValue.Type); - VertexCopyFunction conversionFunc = gl_d3d11::GetVertexCopyFunction(vertexFormat); - ASSERT(conversionFunc != NULL); - conversionFunc(input, inputStride, count, output); - - dxContext->Unmap(mBuffer, 0); - - return true; } else { - ERR("Vertex buffer not initialized."); - return false; + input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues); + } + + if (instances == 0 || attrib.divisor == 0) + { + input += inputStride * start; } + + gl::VertexFormat vertexFormat(attrib, currentValue.Type); + const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat); + ASSERT(vertexFormatInfo.copyFunction != NULL); + vertexFormatInfo.copyFunction(input, inputStride, count, output); + + dxContext->Unmap(mBuffer, 0); + + return gl::Error(GL_NO_ERROR); } -bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, - GLsizei instances, unsigned int *outSpaceRequired) const +gl::Error VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, + GLsizei instances, unsigned int *outSpaceRequired) const { unsigned int elementCount = 0; if (attrib.enabled) @@ -136,30 +131,25 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei } else { - if (static_cast<unsigned int>(instances) < std::numeric_limits<unsigned int>::max() - (attrib.divisor - 1)) - { - // Round up - elementCount = rx::roundUp(static_cast<unsigned int>(instances), attrib.divisor); - } - else - { - elementCount = instances / attrib.divisor; - } + // Round up to divisor, if possible + elementCount = rx::UnsignedCeilDivide(static_cast<unsigned int>(instances), attrib.divisor); } gl::VertexFormat vertexFormat(attrib); - unsigned int elementSize = static_cast<unsigned int>(gl_d3d11::GetVertexElementSize(vertexFormat)); + const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat); + const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(vertexFormatInfo.nativeFormat); + unsigned int elementSize = dxgiFormatInfo.pixelBytes; if (elementSize <= std::numeric_limits<unsigned int>::max() / elementCount) { if (outSpaceRequired) { *outSpaceRequired = elementSize * elementCount; } - return true; + return gl::Error(GL_NO_ERROR); } else { - return false; + return gl::Error(GL_OUT_OF_MEMORY, "New vertex buffer size would result in an overflow."); } } else @@ -169,7 +159,7 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei { *outSpaceRequired = elementSize * 4; } - return true; + return gl::Error(GL_NO_ERROR); } } @@ -178,7 +168,7 @@ unsigned int VertexBuffer11::getBufferSize() const return mBufferSize; } -bool VertexBuffer11::setBufferSize(unsigned int size) +gl::Error VertexBuffer11::setBufferSize(unsigned int size) { if (size > mBufferSize) { @@ -186,33 +176,29 @@ bool VertexBuffer11::setBufferSize(unsigned int size) } else { - return true; + return gl::Error(GL_NO_ERROR); } } -bool VertexBuffer11::discard() +gl::Error VertexBuffer11::discard() { - if (mBuffer) + if (!mBuffer) { - ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - if (FAILED(result)) - { - ERR("Vertex buffer map failed with error 0x%08x", result); - return false; - } + return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized."); + } - dxContext->Unmap(mBuffer, 0); + ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); - return true; - } - else + D3D11_MAPPED_SUBRESOURCE mappedResource; + HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); + if (FAILED(result)) { - ERR("Vertex buffer not initialized."); - return false; + return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer for discarding, HRESULT: 0x%08x", result); } + + dxContext->Unmap(mBuffer, 0); + + return gl::Error(GL_NO_ERROR); } ID3D11Buffer *VertexBuffer11::getBuffer() const |