mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Common: Add alignment header
Gets rid of duplicated alignment code.
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "VideoBackends/D3D/D3DBase.h"
|
||||
#include "VideoBackends/D3D/D3DShader.h"
|
||||
#include "VideoBackends/D3D/D3DState.h"
|
||||
@ -22,7 +23,7 @@ namespace D3D
|
||||
class UtilVertexBuffer
|
||||
{
|
||||
public:
|
||||
UtilVertexBuffer(int size) : buf(nullptr), offset(0), max_size(size)
|
||||
UtilVertexBuffer(unsigned int size) : max_size(size)
|
||||
{
|
||||
D3D11_BUFFER_DESC desc = CD3D11_BUFFER_DESC(max_size, D3D11_BIND_VERTEX_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
@ -31,7 +32,7 @@ public:
|
||||
~UtilVertexBuffer() { buf->Release(); }
|
||||
int GetSize() const { return max_size; }
|
||||
// returns vertex offset to the new data
|
||||
int AppendData(void* data, int size, int vertex_size)
|
||||
int AppendData(void* data, unsigned int size, unsigned int vertex_size)
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
if (offset + size >= max_size)
|
||||
@ -47,8 +48,7 @@ public:
|
||||
{
|
||||
context->Map(buf, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map);
|
||||
}
|
||||
offset = ((offset + vertex_size - 1) / vertex_size) *
|
||||
vertex_size; // align offset to vertex_size bytes
|
||||
offset = Common::AlignUp(offset, vertex_size);
|
||||
memcpy((u8*)map.pData + offset, data, size);
|
||||
context->Unmap(buf, 0);
|
||||
|
||||
@ -56,13 +56,12 @@ public:
|
||||
return (offset - size) / vertex_size;
|
||||
}
|
||||
|
||||
int BeginAppendData(void** write_ptr, int size, int vertex_size)
|
||||
int BeginAppendData(void** write_ptr, unsigned int size, unsigned int vertex_size)
|
||||
{
|
||||
_dbg_assert_(VIDEO, size < max_size);
|
||||
|
||||
D3D11_MAPPED_SUBRESOURCE map;
|
||||
int aligned_offset = ((offset + vertex_size - 1) / vertex_size) *
|
||||
vertex_size; // align offset to vertex_size bytes
|
||||
unsigned int aligned_offset = Common::AlignUp(offset, vertex_size);
|
||||
if (aligned_offset + size > max_size)
|
||||
{
|
||||
// wrap buffer around and notify observers
|
||||
@ -87,9 +86,9 @@ public:
|
||||
void AddWrapObserver(bool* observer) { observers.push_back(observer); }
|
||||
inline ID3D11Buffer*& GetBuffer() { return buf; }
|
||||
private:
|
||||
ID3D11Buffer* buf;
|
||||
int offset;
|
||||
int max_size;
|
||||
ID3D11Buffer* buf = nullptr;
|
||||
unsigned int offset = 0;
|
||||
unsigned int max_size;
|
||||
|
||||
std::list<bool*> observers;
|
||||
};
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
#include "Common/StringUtil.h"
|
||||
@ -135,7 +136,8 @@ const char copy_shader_code[] = {
|
||||
|
||||
void GeometryShaderCache::Init()
|
||||
{
|
||||
unsigned int gbsize = ROUND_UP(sizeof(GeometryShaderConstants), 16); // must be a multiple of 16
|
||||
unsigned int gbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(GeometryShaderConstants)),
|
||||
16); // must be a multiple of 16
|
||||
D3D11_BUFFER_DESC gbdesc = CD3D11_BUFFER_DESC(gbsize, D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
HRESULT hr = D3D::device->CreateBuffer(&gbdesc, nullptr, &gscbuf);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
@ -457,7 +458,8 @@ public:
|
||||
|
||||
void PixelShaderCache::Init()
|
||||
{
|
||||
unsigned int cbsize = ROUND_UP(sizeof(PixelShaderConstants), 16); // must be a multiple of 16
|
||||
unsigned int cbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(PixelShaderConstants)),
|
||||
16); // must be a multiple of 16
|
||||
D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
D3D::device->CreateBuffer(&cbdesc, nullptr, &pscbuf);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common/Align.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/LinearDiskCache.h"
|
||||
@ -122,7 +123,8 @@ void VertexShaderCache::Init()
|
||||
{"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
|
||||
unsigned int cbsize = ROUND_UP(sizeof(VertexShaderConstants), 16); // must be a multiple of 16
|
||||
unsigned int cbsize = Common::AlignUp(static_cast<unsigned int>(sizeof(VertexShaderConstants)),
|
||||
16); // must be a multiple of 16
|
||||
D3D11_BUFFER_DESC cbdesc = CD3D11_BUFFER_DESC(cbsize, D3D11_BIND_CONSTANT_BUFFER,
|
||||
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||
HRESULT hr = D3D::device->CreateBuffer(&cbdesc, nullptr, &vscbuf);
|
||||
|
Reference in New Issue
Block a user