Skip to content

Commit

Permalink
buffer align
Browse files Browse the repository at this point in the history
  • Loading branch information
hana-alice committed Sep 5, 2023
1 parent 5c021f2 commit 37fa034
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions native/cocos/renderer/gfx-wgpu/WGPUBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
#include "WGPUDevice.h"
#include "WGPUObject.h"
#include "WGPUUtils.h"
#include <boost/align/align_up.hpp>

namespace cc {
namespace gfx {

namespace {
CCWGPUBuffer *dftUniformBuffer = nullptr;
CCWGPUBuffer *dftStorageBuffer = nullptr;
static uint32_t BUFFER_ALIGNMENT = 16;
} // namespace

using namespace emscripten;
Expand All @@ -54,7 +56,7 @@ void CCWGPUBuffer::doInit(const BufferInfo &info) {
_gpuBufferObject->indirectObjs.resize(drawInfoCount);
}

_size = ceil(info.size / 16.0) * 16;
_size = boost::alignment::align_up(_size, BUFFER_ALIGNMENT);

WGPUBufferDescriptor descriptor = {
.nextInChain = nullptr,
Expand Down Expand Up @@ -113,7 +115,7 @@ void CCWGPUBuffer::doResize(uint32_t size, uint32_t count) {
_gpuBufferObject->indirectObjs.resize(drawInfoCount);
}

_size = ceil(size / 16.0) * 16;
_size = boost::alignment::align_up(_size, BUFFER_ALIGNMENT);

WGPUBufferDescriptor descriptor = {
.nextInChain = nullptr,
Expand Down Expand Up @@ -172,7 +174,7 @@ void CCWGPUBuffer::update(const void *buffer, uint32_t size) {
update(drawInfo, drawInfoCount);
} else {
size_t offset = _isBufferView ? _offset : 0;
uint32_t alignedSize = ceil(size / 16.0) * 16;
uint32_t alignedSize = boost::alignment::align_up(size, BUFFER_ALIGNMENT);
size_t buffSize = alignedSize;
wgpuQueueWriteBuffer(CCWGPUDevice::getInstance()->gpuDeviceObject()->wgpuQueue, _gpuBufferObject->wgpuBuffer, offset, buffer, buffSize);
}
Expand Down

0 comments on commit 37fa034

Please sign in to comment.