-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferView.cpp
37 lines (31 loc) · 965 Bytes
/
BufferView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "D3D12FrameWork/BufferView.h"
#include "D3D12FrameWork/D3DDevice.h"
#include "D3D12FrameWork/Buffer.h"
namespace D3D12FrameWork{
ConstantBufferView* ConstantBufferView::m_pNullView = nullptr;
ConstantBufferView::ConstantBufferView()
:m_descInfo(){}
ConstantBufferView::~ConstantBufferView() {
Term();
}
bool
ConstantBufferView::Init(
D3DDevice const* _pDev,
Buffer const* _pBuff,
const size_t _offset,
const size_t _size
) {
if (_pDev == nullptr || _pBuff == nullptr) return false;
auto const buffSize = (_size == 0) ? _pBuff->GetSize() : _size;
auto const alignedSize= (buffSize + 0xff) & ~0xff;
m_descInfo = _pDev->GetCbvSrvUavHeap()->Allocate();
D3D12_CONSTANT_BUFFER_VIEW_DESC viewDesc = {};
viewDesc.BufferLocation = _pBuff->GetGPUVirtualAddress() + _offset;
viewDesc.SizeInBytes = alignedSize;
_pDev->GetDev()->CreateConstantBufferView(
&viewDesc,
m_descInfo.m_CpuHandle
);
return true;
}
}