Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer rework #1438

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions OgreMain/include/OgreDefaultHardwareBufferManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ namespace Ogre {
* @{
*/

/// Specialisation of Buffer using malloc e.g. for use as shadow buffer
class _OgreExport DefaultBuffer : public Buffer
{
protected:
unsigned char* mData;
void* lockImpl(size_t offset, size_t length, LockOptions options);
void unlockImpl(void);
public:
explicit DefaultBuffer(size_t sizeInBytes);
~DefaultBuffer();
void readData(size_t offset, size_t length, void* pDest);
void writeData(size_t offset, size_t length, const void* pSource, bool discardWholeBuffer = false);
void* lock(size_t offset, size_t length, LockOptions options);
void unlock(void);
};

/// Specialisation of HardwareVertexBuffer for emulation
class _OgreExport DefaultHardwareVertexBuffer : public HardwareVertexBuffer
{
Expand Down
293 changes: 152 additions & 141 deletions OgreMain/include/OgreHardwareBuffer.h

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions OgreMain/src/OgreDefaultHardwareBufferManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ THE SOFTWARE.
#include "OgreDefaultHardwareBufferManager.h"

namespace Ogre {
DefaultBuffer::DefaultBuffer(size_t sizeInBytes)
: Buffer(sizeInBytes, HBU_CPU_ONLY)
{
// Allocate aligned memory for better SIMD processing friendly.
mData = static_cast<unsigned char*>(AlignedMemory::allocate(mSizeInBytes));
}
//-----------------------------------------------------------------------
DefaultBuffer::~DefaultBuffer() { AlignedMemory::deallocate(mData); }
//-----------------------------------------------------------------------
void* DefaultBuffer::lockImpl(size_t offset, size_t length, LockOptions options) { return mData + offset; }
//-----------------------------------------------------------------------
void DefaultBuffer::unlockImpl() {}
//-----------------------------------------------------------------------
void* DefaultBuffer::lock(size_t offset, size_t length, LockOptions options)
{
mIsLocked = true;
return mData + offset;
}
void DefaultBuffer::unlock(void) { mIsLocked = false; }
//-----------------------------------------------------------------------
void DefaultBuffer::readData(size_t offset, size_t length, void* pDest)
{
assert((offset + length) <= mSizeInBytes);
memcpy(pDest, mData + offset, length);
}
//-----------------------------------------------------------------------
void DefaultBuffer::writeData(size_t offset, size_t length, const void* pSource, bool discardWholeBuffer)
{
assert((offset + length) <= mSizeInBytes);
// ignore discard, memory is not guaranteed to be zeroised
memcpy(mData + offset, pSource, length);
}


DefaultHardwareVertexBuffer::DefaultHardwareVertexBuffer(size_t vertexSize, size_t numVertices,
HardwareBuffer::Usage usage)
Expand Down
3 changes: 1 addition & 2 deletions OgreMain/src/OgreHardwareIndexBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ namespace Ogre {
// Create a shadow buffer if required
if (mUseShadowBuffer)
{
mShadowBuffer.reset(new DefaultHardwareIndexBuffer(mIndexType,
mNumIndexes, HardwareBuffer::HBU_DYNAMIC));
mShadowBuffer.reset(new DefaultBuffer(mSizeInBytes));
}


Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgreHardwareUniformBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Ogre {
// Create a shadow buffer if required
if (mUseShadowBuffer)
{
mShadowBuffer.reset(new DefaultHardwareUniformBuffer(mMgr, sizeBytes, HardwareBuffer::HBU_DYNAMIC, false));
mShadowBuffer.reset(new DefaultBuffer(sizeBytes));
}
}

Expand Down
3 changes: 1 addition & 2 deletions OgreMain/src/OgreHardwareVertexBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ namespace Ogre {
// Create a shadow buffer if required
if (mUseShadowBuffer)
{
mShadowBuffer.reset(new DefaultHardwareVertexBuffer(mMgr, mVertexSize,
mNumVertices, HardwareBuffer::HBU_DYNAMIC));
mShadowBuffer.reset(new DefaultBuffer(mSizeInBytes));
}

}
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Direct3D11/include/OgreD3D11HardwareBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Ogre {
/** See HardwareBuffer. We perform a hardware copy here. */
void copyData(HardwareBuffer& srcBuffer, size_t srcOffset,
size_t dstOffset, size_t length, bool discardWholeBuffer = false);
void copyDataImpl(HardwareBuffer& srcBuffer, size_t srcOffset,
void copyDataImpl(Buffer& srcBuffer, size_t srcOffset,
size_t dstOffset, size_t length, bool discardWholeBuffer = false);
/// Updates the real buffer from the shadow buffer, if required
virtual void _updateFromShadow(void);
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Direct3D11/src/OgreD3D11HardwareBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace Ogre {
copyDataImpl(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer);
}
//---------------------------------------------------------------------
void D3D11HardwareBuffer::copyDataImpl(HardwareBuffer& srcBuffer, size_t srcOffset,
void D3D11HardwareBuffer::copyDataImpl(Buffer& srcBuffer, size_t srcOffset,
size_t dstOffset, size_t length, bool discardWholeBuffer)
{
// If we're copying same-size buffers in their entirety...
Expand Down