Skip to content

Commit

Permalink
fix oparraylength for DX12
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Jun 4, 2023
1 parent 571ebe4 commit 9fc1cfe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Engine/gapi/directx12/dxallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ DxBuffer DxAllocator::alloc(const void* mem, size_t count, size_t size, size_t a
state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
}

DxBuffer ret(owner,UINT(resDesc.Width));
DxBuffer ret(owner,UINT(resDesc.Width), UINT(count*alignedSz));
ret.page = allocator.alloc(count*alignedSz, toAlignment(bufFlg),
uint32_t(bufFlg), uint32_t(bufFlg), (bufFlg!=BufferHeap::Device));
if(!ret.page.page)
Expand Down
8 changes: 5 additions & 3 deletions Engine/gapi/directx12/dxbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
using namespace Tempest;
using namespace Tempest::Detail;

DxBuffer::DxBuffer(DxDevice* dev, UINT sizeInBytes)
:dev(dev), sizeInBytes(sizeInBytes) {
DxBuffer::DxBuffer(DxDevice* dev, UINT sizeInBytes, UINT appSize)
:dev(dev), sizeInBytes(sizeInBytes), appSize(appSize) {
}

DxBuffer::DxBuffer(DxBuffer&& other)
:dev(other.dev), page(std::move(other.page)), impl(std::move(other.impl)), nonUniqId(other.nonUniqId), sizeInBytes(other.sizeInBytes) {
:dev(other.dev), page(std::move(other.page)), impl(std::move(other.impl)), nonUniqId(other.nonUniqId),
sizeInBytes(other.sizeInBytes), appSize(other.appSize) {
other.sizeInBytes = 0;
other.page.page = nullptr;
}
Expand All @@ -30,6 +31,7 @@ DxBuffer& DxBuffer::operator=(DxBuffer&& other) {
std::swap(impl, other.impl);
std::swap(nonUniqId, other.nonUniqId);
std::swap(sizeInBytes, other.sizeInBytes);
std::swap(appSize, other.appSize);
return *this;
}

Expand Down
3 changes: 2 additions & 1 deletion Engine/gapi/directx12/dxbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DxDevice;
class DxBuffer : public AbstractGraphicsApi::Buffer {
public:
DxBuffer() = default;
DxBuffer(DxDevice* dev, UINT sizeInBytes);
DxBuffer(DxDevice* dev, UINT sizeInBytes, UINT appSize);
DxBuffer(DxBuffer&& other);
~DxBuffer();

Expand All @@ -30,6 +30,7 @@ class DxBuffer : public AbstractGraphicsApi::Buffer {
ComPtr<ID3D12Resource> impl;
NonUniqResId nonUniqId = NonUniqResId::I_None;
UINT sizeInBytes = 0;
UINT appSize = 0;

protected:
void updateByStaging(DxBuffer* stage, const void* data, size_t offDst, size_t offSrc, size_t count, size_t sz, size_t alignedSz);
Expand Down
4 changes: 2 additions & 2 deletions Engine/gapi/directx12/dxdescriptorarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void DxDescriptorArray::placeInHeap(ID3D12Device& device, D3D12_DESCRIPTOR_RANGE
desc.Buffer.NumElements = UINT((byteSize+3)/4); // UAV size is required to be 4-byte aligned.
desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
if(desc.Buffer.NumElements==0)
desc.Buffer.NumElements = UINT(buf.sizeInBytes-bufOffset)/4;
desc.Buffer.NumElements = UINT(buf.appSize-bufOffset+3)/4;

auto gpu = at;
gpu.ptr += heapOffset;
Expand All @@ -583,7 +583,7 @@ void DxDescriptorArray::placeInHeap(ID3D12Device& device, D3D12_DESCRIPTOR_RANGE
desc.Buffer.NumElements = UINT((byteSize+3)/4); // SRV size is required to be 4-byte aligned.
desc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
if(desc.Buffer.NumElements==0)
desc.Buffer.NumElements = UINT(buf.sizeInBytes-bufOffset)/4;
desc.Buffer.NumElements = UINT(buf.appSize-bufOffset+3)/4;

auto gpu = at;
gpu.ptr += heapOffset;
Expand Down

0 comments on commit 9fc1cfe

Please sign in to comment.