Member rename: src/backend/d3d12
This commit is contained in:
parent
903c563b43
commit
e00385af73
|
@ -25,22 +25,22 @@ namespace backend {
|
|||
namespace d3d12 {
|
||||
|
||||
BindGroup::BindGroup(Device* device, BindGroupBuilder* builder)
|
||||
: BindGroupBase(builder), device(device) {
|
||||
: BindGroupBase(builder), mDevice(device) {
|
||||
}
|
||||
|
||||
void BindGroup::RecordDescriptors(const DescriptorHeapHandle &cbvUavSrvHeapStart, uint32_t* cbvUavSrvHeapOffset, const DescriptorHeapHandle &samplerHeapStart, uint32_t* samplerHeapOffset, uint64_t serial) {
|
||||
heapSerial = serial;
|
||||
mHeapSerial = serial;
|
||||
|
||||
const auto* bgl = ToBackend(GetLayout());
|
||||
const auto& layout = bgl->GetBindingInfo();
|
||||
|
||||
// Save the offset to the start of the descriptor table in the heap
|
||||
this->cbvUavSrvHeapOffset = *cbvUavSrvHeapOffset;
|
||||
this->samplerHeapOffset = *samplerHeapOffset;
|
||||
mCbvUavSrvHeapOffset = *cbvUavSrvHeapOffset;
|
||||
mSamplerHeapOffset = *samplerHeapOffset;
|
||||
|
||||
const auto& bindingOffsets = bgl->GetBindingOffsets();
|
||||
|
||||
auto d3d12Device = device->GetD3D12Device();
|
||||
auto d3d12Device = mDevice->GetD3D12Device();
|
||||
for (uint32_t binding : IterateBitSet(layout.mask)) {
|
||||
switch (layout.types[binding]) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
|
@ -80,15 +80,15 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
uint32_t BindGroup::GetCbvUavSrvHeapOffset() const {
|
||||
return cbvUavSrvHeapOffset;
|
||||
return mCbvUavSrvHeapOffset;
|
||||
}
|
||||
|
||||
uint32_t BindGroup::GetSamplerHeapOffset() const {
|
||||
return samplerHeapOffset;
|
||||
return mSamplerHeapOffset;
|
||||
}
|
||||
|
||||
uint64_t BindGroup::GetHeapSerial() const {
|
||||
return heapSerial;
|
||||
return mHeapSerial;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,12 +36,12 @@ namespace d3d12 {
|
|||
uint64_t GetHeapSerial() const;
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
uint32_t cbvUavSrvHeapOffset;
|
||||
uint32_t samplerHeapOffset;
|
||||
uint32_t cbvUavSrvCount = 0;
|
||||
uint32_t samplerCount = 0;
|
||||
uint64_t heapSerial = 0;
|
||||
Device* mDevice;
|
||||
uint32_t mCbvUavSrvHeapOffset;
|
||||
uint32_t mSamplerHeapOffset;
|
||||
uint32_t mCbvUavSrvCount = 0;
|
||||
uint32_t mSamplerCount = 0;
|
||||
uint64_t mHeapSerial = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,23 +21,23 @@ namespace backend {
|
|||
namespace d3d12 {
|
||||
|
||||
BindGroupLayout::BindGroupLayout(Device* device, BindGroupLayoutBuilder* builder)
|
||||
: BindGroupLayoutBase(builder), device(device), descriptorCounts {} {
|
||||
: BindGroupLayoutBase(builder), mDevice(device), mDescriptorCounts {} {
|
||||
|
||||
const auto& groupInfo = GetBindingInfo();
|
||||
|
||||
for (uint32_t binding : IterateBitSet(groupInfo.mask)) {
|
||||
switch (groupInfo.types[binding]) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
bindingOffsets[binding] = descriptorCounts[CBV]++;
|
||||
mBindingOffsets[binding] = mDescriptorCounts[CBV]++;
|
||||
break;
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
bindingOffsets[binding] = descriptorCounts[UAV]++;
|
||||
mBindingOffsets[binding] = mDescriptorCounts[UAV]++;
|
||||
break;
|
||||
case nxt::BindingType::SampledTexture:
|
||||
bindingOffsets[binding] = descriptorCounts[SRV]++;
|
||||
mBindingOffsets[binding] = mDescriptorCounts[SRV]++;
|
||||
break;
|
||||
case nxt::BindingType::Sampler:
|
||||
bindingOffsets[binding] = descriptorCounts[Sampler]++;
|
||||
mBindingOffsets[binding] = mDescriptorCounts[Sampler]++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace d3d12 {
|
|||
return false;
|
||||
}
|
||||
|
||||
auto& range = ranges[index];
|
||||
auto& range = mRanges[index];
|
||||
range.RangeType = type;
|
||||
range.NumDescriptors = count;
|
||||
range.RegisterSpace = 0;
|
||||
|
@ -60,72 +60,72 @@ namespace d3d12 {
|
|||
|
||||
// Ranges 0-2 contain the CBV, UAV, and SRV ranges, if they exist, tightly packed
|
||||
// Range 3 contains the Sampler range, if there is one
|
||||
if (SetDescriptorRange(rangeIndex, descriptorCounts[CBV], D3D12_DESCRIPTOR_RANGE_TYPE_CBV)) {
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[CBV], D3D12_DESCRIPTOR_RANGE_TYPE_CBV)) {
|
||||
rangeIndex++;
|
||||
}
|
||||
if (SetDescriptorRange(rangeIndex, descriptorCounts[UAV], D3D12_DESCRIPTOR_RANGE_TYPE_UAV)) {
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[UAV], D3D12_DESCRIPTOR_RANGE_TYPE_UAV)) {
|
||||
rangeIndex++;
|
||||
}
|
||||
if (SetDescriptorRange(rangeIndex, descriptorCounts[SRV], D3D12_DESCRIPTOR_RANGE_TYPE_SRV)) {
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[SRV], D3D12_DESCRIPTOR_RANGE_TYPE_SRV)) {
|
||||
rangeIndex++;
|
||||
}
|
||||
SetDescriptorRange(Sampler, descriptorCounts[Sampler], D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER);
|
||||
SetDescriptorRange(Sampler, mDescriptorCounts[Sampler], D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER);
|
||||
|
||||
// descriptors ranges are offset by the offset + size of the previous range
|
||||
std::array<uint32_t, DescriptorType::Count> descriptorOffsets;
|
||||
descriptorOffsets[CBV] = 0;
|
||||
descriptorOffsets[UAV] = descriptorOffsets[CBV] + descriptorCounts[CBV];
|
||||
descriptorOffsets[SRV] = descriptorOffsets[UAV] + descriptorCounts[UAV];
|
||||
descriptorOffsets[UAV] = descriptorOffsets[CBV] + mDescriptorCounts[CBV];
|
||||
descriptorOffsets[SRV] = descriptorOffsets[UAV] + mDescriptorCounts[UAV];
|
||||
descriptorOffsets[Sampler] = 0; // samplers are in a different heap
|
||||
|
||||
for (uint32_t binding : IterateBitSet(groupInfo.mask)) {
|
||||
switch (groupInfo.types[binding]) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
bindingOffsets[binding] += descriptorOffsets[CBV];
|
||||
mBindingOffsets[binding] += descriptorOffsets[CBV];
|
||||
break;
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
bindingOffsets[binding] += descriptorOffsets[UAV];
|
||||
mBindingOffsets[binding] += descriptorOffsets[UAV];
|
||||
break;
|
||||
case nxt::BindingType::SampledTexture:
|
||||
bindingOffsets[binding] += descriptorOffsets[SRV];
|
||||
mBindingOffsets[binding] += descriptorOffsets[SRV];
|
||||
break;
|
||||
case nxt::BindingType::Sampler:
|
||||
bindingOffsets[binding] += descriptorOffsets[Sampler];
|
||||
mBindingOffsets[binding] += descriptorOffsets[Sampler];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::array<uint32_t, kMaxBindingsPerGroup>& BindGroupLayout::GetBindingOffsets() const {
|
||||
return bindingOffsets;
|
||||
return mBindingOffsets;
|
||||
}
|
||||
|
||||
uint32_t BindGroupLayout::GetCbvUavSrvDescriptorTableSize() const {
|
||||
return (
|
||||
static_cast<uint32_t>(descriptorCounts[CBV] > 0) +
|
||||
static_cast<uint32_t>(descriptorCounts[UAV] > 0) +
|
||||
static_cast<uint32_t>(descriptorCounts[SRV] > 0)
|
||||
static_cast<uint32_t>(mDescriptorCounts[CBV] > 0) +
|
||||
static_cast<uint32_t>(mDescriptorCounts[UAV] > 0) +
|
||||
static_cast<uint32_t>(mDescriptorCounts[SRV] > 0)
|
||||
);
|
||||
}
|
||||
|
||||
uint32_t BindGroupLayout::GetSamplerDescriptorTableSize() const {
|
||||
return descriptorCounts[Sampler] > 0;
|
||||
return mDescriptorCounts[Sampler] > 0;
|
||||
}
|
||||
|
||||
uint32_t BindGroupLayout::GetCbvUavSrvDescriptorCount() const {
|
||||
return descriptorCounts[CBV] + descriptorCounts[UAV] + descriptorCounts[SRV];
|
||||
return mDescriptorCounts[CBV] + mDescriptorCounts[UAV] + mDescriptorCounts[SRV];
|
||||
}
|
||||
|
||||
uint32_t BindGroupLayout::GetSamplerDescriptorCount() const {
|
||||
return descriptorCounts[Sampler];
|
||||
return mDescriptorCounts[Sampler];
|
||||
}
|
||||
|
||||
const D3D12_DESCRIPTOR_RANGE* BindGroupLayout::GetCbvUavSrvDescriptorRanges() const {
|
||||
return ranges;
|
||||
return mRanges;
|
||||
}
|
||||
|
||||
const D3D12_DESCRIPTOR_RANGE* BindGroupLayout::GetSamplerDescriptorRanges() const {
|
||||
return &ranges[Sampler];
|
||||
return &mRanges[Sampler];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,10 +45,10 @@ namespace d3d12 {
|
|||
const D3D12_DESCRIPTOR_RANGE* GetSamplerDescriptorRanges() const;
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
std::array<uint32_t, kMaxBindingsPerGroup> bindingOffsets;
|
||||
std::array<uint32_t, DescriptorType::Count> descriptorCounts;
|
||||
D3D12_DESCRIPTOR_RANGE ranges[DescriptorType::Count];
|
||||
Device* mDevice;
|
||||
std::array<uint32_t, kMaxBindingsPerGroup> mBindingOffsets;
|
||||
std::array<uint32_t, DescriptorType::Count> mDescriptorCounts;
|
||||
D3D12_DESCRIPTOR_RANGE mRanges[DescriptorType::Count];
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -82,20 +82,20 @@ namespace d3d12 {
|
|||
|
||||
BlendState::BlendState(BlendStateBuilder* builder) : BlendStateBase(builder) {
|
||||
auto& info = GetBlendInfo();
|
||||
blendDesc.BlendEnable = info.blendEnabled;
|
||||
blendDesc.SrcBlend = D3D12Blend(info.colorBlend.srcFactor);
|
||||
blendDesc.DestBlend = D3D12Blend(info.colorBlend.dstFactor);
|
||||
blendDesc.BlendOp = D3D12BlendOperation(info.colorBlend.operation);
|
||||
blendDesc.SrcBlendAlpha = D3D12Blend(info.alphaBlend.srcFactor);
|
||||
blendDesc.DestBlendAlpha = D3D12Blend(info.alphaBlend.dstFactor);
|
||||
blendDesc.BlendOpAlpha = D3D12BlendOperation(info.alphaBlend.operation);
|
||||
blendDesc.RenderTargetWriteMask = D3D12RenderTargetWriteMask(info.colorWriteMask);
|
||||
blendDesc.LogicOpEnable = false;
|
||||
blendDesc.LogicOp = D3D12_LOGIC_OP_NOOP;
|
||||
mBlendDesc.BlendEnable = info.blendEnabled;
|
||||
mBlendDesc.SrcBlend = D3D12Blend(info.colorBlend.srcFactor);
|
||||
mBlendDesc.DestBlend = D3D12Blend(info.colorBlend.dstFactor);
|
||||
mBlendDesc.BlendOp = D3D12BlendOperation(info.colorBlend.operation);
|
||||
mBlendDesc.SrcBlendAlpha = D3D12Blend(info.alphaBlend.srcFactor);
|
||||
mBlendDesc.DestBlendAlpha = D3D12Blend(info.alphaBlend.dstFactor);
|
||||
mBlendDesc.BlendOpAlpha = D3D12BlendOperation(info.alphaBlend.operation);
|
||||
mBlendDesc.RenderTargetWriteMask = D3D12RenderTargetWriteMask(info.colorWriteMask);
|
||||
mBlendDesc.LogicOpEnable = false;
|
||||
mBlendDesc.LogicOp = D3D12_LOGIC_OP_NOOP;
|
||||
}
|
||||
|
||||
const D3D12_RENDER_TARGET_BLEND_DESC& BlendState::GetD3D12BlendDesc() const {
|
||||
return blendDesc;
|
||||
return mBlendDesc;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace d3d12 {
|
|||
const D3D12_RENDER_TARGET_BLEND_DESC& GetD3D12BlendDesc() const;
|
||||
|
||||
private:
|
||||
D3D12_RENDER_TARGET_BLEND_DESC blendDesc;
|
||||
D3D12_RENDER_TARGET_BLEND_DESC mBlendDesc;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
Buffer::Buffer(Device* device, BufferBuilder* builder)
|
||||
: BufferBase(builder), device(device) {
|
||||
: BufferBase(builder), mDevice(device) {
|
||||
|
||||
D3D12_RESOURCE_DESC resourceDescriptor;
|
||||
resourceDescriptor.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
|
@ -97,11 +97,11 @@ namespace d3d12 {
|
|||
bufferUsage |= D3D12_RESOURCE_STATE_GENERIC_READ;
|
||||
}
|
||||
|
||||
resource = device->GetResourceAllocator()->Allocate(heapType, resourceDescriptor, bufferUsage);
|
||||
mResource = device->GetResourceAllocator()->Allocate(heapType, resourceDescriptor, bufferUsage);
|
||||
}
|
||||
|
||||
Buffer::~Buffer() {
|
||||
device->GetResourceAllocator()->Release(resource);
|
||||
mDevice->GetResourceAllocator()->Release(mResource);
|
||||
}
|
||||
|
||||
uint32_t Buffer::GetD3D12Size() const {
|
||||
|
@ -110,7 +110,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
ComPtr<ID3D12Resource> Buffer::GetD3D12Resource() {
|
||||
return resource;
|
||||
return mResource;
|
||||
}
|
||||
|
||||
bool Buffer::GetResourceTransitionBarrier(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage, D3D12_RESOURCE_BARRIER* barrier) {
|
||||
|
@ -129,7 +129,7 @@ namespace d3d12 {
|
|||
|
||||
barrier->Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
barrier->Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
||||
barrier->Transition.pResource = resource.Get();
|
||||
barrier->Transition.pResource = mResource.Get();
|
||||
barrier->Transition.StateBefore = stateBefore;
|
||||
barrier->Transition.StateAfter = stateAfter;
|
||||
barrier->Transition.Subresource = 0;
|
||||
|
@ -138,7 +138,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
D3D12_GPU_VIRTUAL_ADDRESS Buffer::GetVA() const {
|
||||
return resource->GetGPUVirtualAddress();
|
||||
return mResource->GetGPUVirtualAddress();
|
||||
}
|
||||
|
||||
void Buffer::OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data) {
|
||||
|
@ -146,13 +146,13 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
||||
device->GetResourceUploader()->BufferSubData(resource, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
||||
mDevice->GetResourceUploader()->BufferSubData(mResource, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
D3D12_RANGE readRange = { start, start + count };
|
||||
char* data = nullptr;
|
||||
ASSERT_SUCCESS(resource->Map(0, &readRange, reinterpret_cast<void**>(&data)));
|
||||
ASSERT_SUCCESS(mResource->Map(0, &readRange, reinterpret_cast<void**>(&data)));
|
||||
|
||||
MapReadRequestTracker* tracker = ToBackend(GetDevice())->GetMapReadRequestTracker();
|
||||
tracker->Track(this, serial, data + start);
|
||||
|
@ -161,30 +161,30 @@ namespace d3d12 {
|
|||
void Buffer::UnmapImpl() {
|
||||
// TODO(enga@google.com): When MapWrite is implemented, this should state the range that was modified
|
||||
D3D12_RANGE writeRange = {};
|
||||
resource->Unmap(0, &writeRange);
|
||||
device->GetResourceAllocator()->Release(resource);
|
||||
mResource->Unmap(0, &writeRange);
|
||||
mDevice->GetResourceAllocator()->Release(mResource);
|
||||
}
|
||||
|
||||
void Buffer::TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) {
|
||||
D3D12_RESOURCE_BARRIER barrier;
|
||||
if (GetResourceTransitionBarrier(currentUsage, targetUsage, &barrier)) {
|
||||
device->GetPendingCommandList()->ResourceBarrier(1, &barrier);
|
||||
mDevice->GetPendingCommandList()->ResourceBarrier(1, &barrier);
|
||||
}
|
||||
}
|
||||
|
||||
BufferView::BufferView(BufferViewBuilder* builder)
|
||||
: BufferViewBase(builder) {
|
||||
|
||||
cbvDesc.BufferLocation = ToBackend(GetBuffer())->GetVA() + GetOffset();
|
||||
cbvDesc.SizeInBytes = GetD3D12Size();
|
||||
mCbvDesc.BufferLocation = ToBackend(GetBuffer())->GetVA() + GetOffset();
|
||||
mCbvDesc.SizeInBytes = GetD3D12Size();
|
||||
|
||||
uavDesc.Format = DXGI_FORMAT_UNKNOWN;
|
||||
uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
|
||||
uavDesc.Buffer.FirstElement = GetOffset();
|
||||
uavDesc.Buffer.NumElements = GetD3D12Size();
|
||||
uavDesc.Buffer.StructureByteStride = 1;
|
||||
uavDesc.Buffer.CounterOffsetInBytes = 0;
|
||||
uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
|
||||
mUavDesc.Format = DXGI_FORMAT_UNKNOWN;
|
||||
mUavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
|
||||
mUavDesc.Buffer.FirstElement = GetOffset();
|
||||
mUavDesc.Buffer.NumElements = GetD3D12Size();
|
||||
mUavDesc.Buffer.StructureByteStride = 1;
|
||||
mUavDesc.Buffer.CounterOffsetInBytes = 0;
|
||||
mUavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
|
||||
}
|
||||
|
||||
uint32_t BufferView::GetD3D12Size() const {
|
||||
|
@ -193,19 +193,19 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
const D3D12_CONSTANT_BUFFER_VIEW_DESC& BufferView::GetCBVDescriptor() const {
|
||||
return cbvDesc;
|
||||
return mCbvDesc;
|
||||
}
|
||||
|
||||
const D3D12_UNORDERED_ACCESS_VIEW_DESC& BufferView::GetUAVDescriptor() const {
|
||||
return uavDesc;
|
||||
return mUavDesc;
|
||||
}
|
||||
|
||||
MapReadRequestTracker::MapReadRequestTracker(Device* device)
|
||||
: device(device) {
|
||||
: mDevice(device) {
|
||||
}
|
||||
|
||||
MapReadRequestTracker::~MapReadRequestTracker() {
|
||||
ASSERT(inflightRequests.Empty());
|
||||
ASSERT(mInflightRequests.Empty());
|
||||
}
|
||||
|
||||
void MapReadRequestTracker::Track(Buffer* buffer, uint32_t mapSerial, const void* data) {
|
||||
|
@ -214,14 +214,14 @@ namespace d3d12 {
|
|||
request.mapSerial = mapSerial;
|
||||
request.data = data;
|
||||
|
||||
inflightRequests.Enqueue(std::move(request), device->GetSerial());
|
||||
mInflightRequests.Enqueue(std::move(request), mDevice->GetSerial());
|
||||
}
|
||||
|
||||
void MapReadRequestTracker::Tick(Serial finishedSerial) {
|
||||
for (auto& request : inflightRequests.IterateUpTo(finishedSerial)) {
|
||||
for (auto& request : mInflightRequests.IterateUpTo(finishedSerial)) {
|
||||
request.buffer->OnMapReadCommandSerialFinished(request.mapSerial, request.data);
|
||||
}
|
||||
inflightRequests.ClearUpTo(finishedSerial);
|
||||
mInflightRequests.ClearUpTo(finishedSerial);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ namespace d3d12 {
|
|||
void OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
ComPtr<ID3D12Resource> resource;
|
||||
Device* mDevice;
|
||||
ComPtr<ID3D12Resource> mResource;
|
||||
|
||||
// NXT API
|
||||
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
|
||||
|
@ -57,8 +57,8 @@ namespace d3d12 {
|
|||
const D3D12_UNORDERED_ACCESS_VIEW_DESC& GetUAVDescriptor() const;
|
||||
|
||||
private:
|
||||
D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc;
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc;
|
||||
D3D12_CONSTANT_BUFFER_VIEW_DESC mCbvDesc;
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC mUavDesc;
|
||||
};
|
||||
|
||||
class MapReadRequestTracker {
|
||||
|
@ -70,14 +70,14 @@ namespace d3d12 {
|
|||
void Tick(Serial finishedSerial);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
|
||||
struct Request {
|
||||
Ref<Buffer> buffer;
|
||||
uint32_t mapSerial;
|
||||
const void* data;
|
||||
};
|
||||
SerialQueue<Request> inflightRequests;
|
||||
SerialQueue<Request> mInflightRequests;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -22,45 +22,45 @@
|
|||
namespace backend {
|
||||
namespace d3d12 {
|
||||
|
||||
CommandAllocatorManager::CommandAllocatorManager(Device* device) : device(device), allocatorCount(0) {
|
||||
freeAllocators.set();
|
||||
CommandAllocatorManager::CommandAllocatorManager(Device* device) : device(device), mAllocatorCount(0) {
|
||||
mFreeAllocators.set();
|
||||
}
|
||||
|
||||
ComPtr<ID3D12CommandAllocator> CommandAllocatorManager::ReserveCommandAllocator() {
|
||||
// If there are no free allocators, get the oldest serial in flight and wait on it
|
||||
if (freeAllocators.none()) {
|
||||
const uint64_t firstSerial = inFlightCommandAllocators.FirstSerial();
|
||||
if (mFreeAllocators.none()) {
|
||||
const uint64_t firstSerial = mInFlightCommandAllocators.FirstSerial();
|
||||
device->WaitForSerial(firstSerial);
|
||||
Tick(firstSerial);
|
||||
}
|
||||
|
||||
ASSERT(freeAllocators.any());
|
||||
ASSERT(mFreeAllocators.any());
|
||||
|
||||
// Get the index of the first free allocator from the bitset
|
||||
unsigned int firstFreeIndex = *(IterateBitSet(freeAllocators).begin());
|
||||
unsigned int firstFreeIndex = *(IterateBitSet(mFreeAllocators).begin());
|
||||
|
||||
if (firstFreeIndex >= allocatorCount) {
|
||||
ASSERT(firstFreeIndex == allocatorCount);
|
||||
allocatorCount++;
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&commandAllocators[firstFreeIndex])));
|
||||
if (firstFreeIndex >= mAllocatorCount) {
|
||||
ASSERT(firstFreeIndex == mAllocatorCount);
|
||||
mAllocatorCount++;
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&mCommandAllocators[firstFreeIndex])));
|
||||
}
|
||||
|
||||
// Mark the command allocator as used
|
||||
freeAllocators.reset(firstFreeIndex);
|
||||
mFreeAllocators.reset(firstFreeIndex);
|
||||
|
||||
// Enqueue the command allocator. It will be scheduled for reset after the next ExecuteCommandLists
|
||||
inFlightCommandAllocators.Enqueue({commandAllocators[firstFreeIndex], firstFreeIndex}, device->GetSerial());
|
||||
mInFlightCommandAllocators.Enqueue({mCommandAllocators[firstFreeIndex], firstFreeIndex}, device->GetSerial());
|
||||
|
||||
return commandAllocators[firstFreeIndex];
|
||||
return mCommandAllocators[firstFreeIndex];
|
||||
}
|
||||
|
||||
void CommandAllocatorManager::Tick(uint64_t lastCompletedSerial) {
|
||||
// Reset all command allocators that are no longer in flight
|
||||
for (auto it : inFlightCommandAllocators.IterateUpTo(lastCompletedSerial)) {
|
||||
for (auto it : mInFlightCommandAllocators.IterateUpTo(lastCompletedSerial)) {
|
||||
ASSERT_SUCCESS(it.commandAllocator->Reset());
|
||||
freeAllocators.set(it.index);
|
||||
mFreeAllocators.set(it.index);
|
||||
}
|
||||
inFlightCommandAllocators.ClearUpTo(lastCompletedSerial);
|
||||
mInFlightCommandAllocators.ClearUpTo(lastCompletedSerial);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,16 +40,16 @@ namespace d3d12 {
|
|||
|
||||
// This must be at least 2 because the Device and Queue use separate command allocators
|
||||
static constexpr unsigned int kMaxCommandAllocators = 32;
|
||||
unsigned int allocatorCount;
|
||||
unsigned int mAllocatorCount;
|
||||
|
||||
struct IndexedCommandAllocator {
|
||||
ComPtr<ID3D12CommandAllocator> commandAllocator;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
ComPtr<ID3D12CommandAllocator> commandAllocators[kMaxCommandAllocators];
|
||||
std::bitset<kMaxCommandAllocators> freeAllocators;
|
||||
SerialQueue<IndexedCommandAllocator> inFlightCommandAllocators;
|
||||
ComPtr<ID3D12CommandAllocator> mCommandAllocators[kMaxCommandAllocators];
|
||||
std::bitset<kMaxCommandAllocators> mFreeAllocators;
|
||||
SerialQueue<IndexedCommandAllocator> mInFlightCommandAllocators;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ namespace d3d12 {
|
|||
BindGroupStateTracker(Device* device) : device(device) {
|
||||
}
|
||||
|
||||
void SetInComputePass(bool inCompute) {
|
||||
this->inCompute = inCompute;
|
||||
void SetInComputePass(bool inCompute_) {
|
||||
inCompute = inCompute_;
|
||||
}
|
||||
|
||||
void TrackSetBindGroup(BindGroup* group, uint32_t index) {
|
||||
|
@ -205,16 +205,16 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
CommandBuffer::CommandBuffer(Device* device, CommandBufferBuilder* builder)
|
||||
: CommandBufferBase(builder), device(device), commands(builder->AcquireCommands()) {
|
||||
: CommandBufferBase(builder), mDevice(device), mCommands(builder->AcquireCommands()) {
|
||||
}
|
||||
|
||||
CommandBuffer::~CommandBuffer() {
|
||||
FreeCommands(&commands);
|
||||
FreeCommands(&mCommands);
|
||||
}
|
||||
|
||||
void CommandBuffer::FillCommands(ComPtr<ID3D12GraphicsCommandList> commandList) {
|
||||
BindGroupStateTracker bindingTracker(device);
|
||||
AllocateAndSetDescriptorHeaps(device, &bindingTracker, &commands);
|
||||
BindGroupStateTracker bindingTracker(mDevice);
|
||||
AllocateAndSetDescriptorHeaps(mDevice, &bindingTracker, &mCommands);
|
||||
bindingTracker.Reset();
|
||||
|
||||
ID3D12DescriptorHeap* descriptorHeaps[2] = { bindingTracker.cbvSrvUavGPUDescriptorHeap.Get(), bindingTracker.samplerGPUDescriptorHeap.Get() };
|
||||
|
@ -234,18 +234,18 @@ namespace d3d12 {
|
|||
Framebuffer* currentFramebuffer = nullptr;
|
||||
uint32_t currentSubpass = 0;
|
||||
|
||||
while(commands.NextCommandId(&type)) {
|
||||
while(mCommands.NextCommandId(&type)) {
|
||||
switch (type) {
|
||||
case Command::BeginComputePass:
|
||||
{
|
||||
commands.NextCommand<BeginComputePassCmd>();
|
||||
mCommands.NextCommand<BeginComputePassCmd>();
|
||||
bindingTracker.SetInComputePass(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::BeginRenderPass:
|
||||
{
|
||||
BeginRenderPassCmd* beginRenderPassCmd = commands.NextCommand<BeginRenderPassCmd>();
|
||||
BeginRenderPassCmd* beginRenderPassCmd = mCommands.NextCommand<BeginRenderPassCmd>();
|
||||
currentRenderPass = ToBackend(beginRenderPassCmd->renderPass.Get());
|
||||
currentFramebuffer = ToBackend(beginRenderPassCmd->framebuffer.Get());
|
||||
currentSubpass = 0;
|
||||
|
@ -261,7 +261,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::BeginRenderSubpass:
|
||||
{
|
||||
commands.NextCommand<BeginRenderSubpassCmd>();
|
||||
mCommands.NextCommand<BeginRenderSubpassCmd>();
|
||||
const auto& subpass = currentRenderPass->GetSubpassInfo(currentSubpass);
|
||||
|
||||
Framebuffer::OMSetRenderTargetArgs args = currentFramebuffer->GetSubpassOMSetRenderTargetArgs(currentSubpass);
|
||||
|
@ -332,7 +332,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::CopyBufferToBuffer:
|
||||
{
|
||||
CopyBufferToBufferCmd* copy = commands.NextCommand<CopyBufferToBufferCmd>();
|
||||
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
|
||||
auto src = ToBackend(copy->source.buffer.Get())->GetD3D12Resource();
|
||||
auto dst = ToBackend(copy->destination.buffer.Get())->GetD3D12Resource();
|
||||
commandList->CopyBufferRegion(dst.Get(), copy->destination.offset, src.Get(), copy->source.offset, copy->size);
|
||||
|
@ -341,7 +341,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::CopyBufferToTexture:
|
||||
{
|
||||
CopyBufferToTextureCmd* copy = commands.NextCommand<CopyBufferToTextureCmd>();
|
||||
CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
|
||||
Buffer* buffer = ToBackend(copy->source.buffer.Get());
|
||||
Texture* texture = ToBackend(copy->destination.texture.Get());
|
||||
|
||||
|
@ -390,7 +390,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
CopyTextureToBufferCmd* copy = commands.NextCommand<CopyTextureToBufferCmd>();
|
||||
CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
|
||||
Texture* texture = ToBackend(copy->source.texture.Get());
|
||||
Buffer* buffer = ToBackend(copy->destination.buffer.Get());
|
||||
|
||||
|
@ -439,14 +439,14 @@ namespace d3d12 {
|
|||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
DispatchCmd* dispatch = commands.NextCommand<DispatchCmd>();
|
||||
DispatchCmd* dispatch = mCommands.NextCommand<DispatchCmd>();
|
||||
commandList->Dispatch(dispatch->x, dispatch->y, dispatch->z);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::DrawArrays:
|
||||
{
|
||||
DrawArraysCmd* draw = commands.NextCommand<DrawArraysCmd>();
|
||||
DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
|
||||
commandList->DrawInstanced(
|
||||
draw->vertexCount,
|
||||
draw->instanceCount,
|
||||
|
@ -458,7 +458,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::DrawElements:
|
||||
{
|
||||
DrawElementsCmd* draw = commands.NextCommand<DrawElementsCmd>();
|
||||
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
||||
|
||||
commandList->DrawIndexedInstanced(
|
||||
draw->indexCount,
|
||||
|
@ -472,27 +472,27 @@ namespace d3d12 {
|
|||
|
||||
case Command::EndComputePass:
|
||||
{
|
||||
commands.NextCommand<EndComputePassCmd>();
|
||||
mCommands.NextCommand<EndComputePassCmd>();
|
||||
bindingTracker.SetInComputePass(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderPass:
|
||||
{
|
||||
commands.NextCommand<EndRenderPassCmd>();
|
||||
mCommands.NextCommand<EndRenderPassCmd>();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::EndRenderSubpass:
|
||||
{
|
||||
commands.NextCommand<EndRenderSubpassCmd>();
|
||||
mCommands.NextCommand<EndRenderSubpassCmd>();
|
||||
currentSubpass += 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::SetComputePipeline:
|
||||
{
|
||||
SetComputePipelineCmd* cmd = commands.NextCommand<SetComputePipelineCmd>();
|
||||
SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
|
||||
ComputePipeline* pipeline = ToBackend(cmd->pipeline).Get();
|
||||
PipelineLayout* layout = ToBackend(pipeline->GetLayout());
|
||||
|
||||
|
@ -507,7 +507,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::SetRenderPipeline:
|
||||
{
|
||||
SetRenderPipelineCmd* cmd = commands.NextCommand<SetRenderPipelineCmd>();
|
||||
SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
|
||||
RenderPipeline* pipeline = ToBackend(cmd->pipeline).Get();
|
||||
PipelineLayout* layout = ToBackend(pipeline->GetLayout());
|
||||
|
||||
|
@ -524,13 +524,13 @@ namespace d3d12 {
|
|||
|
||||
case Command::SetPushConstants:
|
||||
{
|
||||
commands.NextCommand<SetPushConstantsCmd>();
|
||||
mCommands.NextCommand<SetPushConstantsCmd>();
|
||||
}
|
||||
break;
|
||||
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd *cmd = commands.NextCommand<SetStencilReferenceCmd>();
|
||||
SetStencilReferenceCmd *cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||
|
||||
commandList->OMSetStencilRef(cmd->reference);
|
||||
}
|
||||
|
@ -538,7 +538,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::SetBlendColor:
|
||||
{
|
||||
SetBlendColorCmd* cmd = commands.NextCommand<SetBlendColorCmd>();
|
||||
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
|
||||
ASSERT(lastRenderPipeline);
|
||||
commandList->OMSetBlendFactor(static_cast<const FLOAT*>(&cmd->r));
|
||||
}
|
||||
|
@ -546,7 +546,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::SetBindGroup:
|
||||
{
|
||||
SetBindGroupCmd* cmd = commands.NextCommand<SetBindGroupCmd>();
|
||||
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||
BindGroup* group = ToBackend(cmd->group.Get());
|
||||
bindingTracker.SetBindGroup(commandList, lastLayout, group, cmd->index);
|
||||
}
|
||||
|
@ -554,7 +554,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::SetIndexBuffer:
|
||||
{
|
||||
SetIndexBufferCmd* cmd = commands.NextCommand<SetIndexBufferCmd>();
|
||||
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||
|
||||
Buffer* buffer = ToBackend(cmd->buffer.Get());
|
||||
D3D12_INDEX_BUFFER_VIEW bufferView;
|
||||
|
@ -571,9 +571,9 @@ namespace d3d12 {
|
|||
|
||||
case Command::SetVertexBuffers:
|
||||
{
|
||||
SetVertexBuffersCmd* cmd = commands.NextCommand<SetVertexBuffersCmd>();
|
||||
auto buffers = commands.NextData<Ref<BufferBase>>(cmd->count);
|
||||
auto offsets = commands.NextData<uint32_t>(cmd->count);
|
||||
SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
|
||||
auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);
|
||||
auto offsets = mCommands.NextData<uint32_t>(cmd->count);
|
||||
|
||||
auto inputState = ToBackend(lastRenderPipeline->GetInputState());
|
||||
|
||||
|
@ -592,7 +592,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::TransitionBufferUsage:
|
||||
{
|
||||
TransitionBufferUsageCmd* cmd = commands.NextCommand<TransitionBufferUsageCmd>();
|
||||
TransitionBufferUsageCmd* cmd = mCommands.NextCommand<TransitionBufferUsageCmd>();
|
||||
|
||||
Buffer* buffer = ToBackend(cmd->buffer.Get());
|
||||
|
||||
|
@ -607,7 +607,7 @@ namespace d3d12 {
|
|||
|
||||
case Command::TransitionTextureUsage:
|
||||
{
|
||||
TransitionTextureUsageCmd* cmd = commands.NextCommand<TransitionTextureUsageCmd>();
|
||||
TransitionTextureUsageCmd* cmd = mCommands.NextCommand<TransitionTextureUsageCmd>();
|
||||
|
||||
Texture* texture = ToBackend(cmd->texture.Get());
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace d3d12 {
|
|||
void FillCommands(ComPtr<ID3D12GraphicsCommandList> commandList);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
CommandIterator commands;
|
||||
Device* mDevice;
|
||||
CommandIterator mCommands;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,11 +64,11 @@ namespace d3d12 {
|
|||
descriptor.CS.BytecodeLength = compiledShader->GetBufferSize();
|
||||
|
||||
Device* device = ToBackend(builder->GetDevice());
|
||||
device->GetD3D12Device()->CreateComputePipelineState(&descriptor, IID_PPV_ARGS(&pipelineState));
|
||||
device->GetD3D12Device()->CreateComputePipelineState(&descriptor, IID_PPV_ARGS(&mPipelineState));
|
||||
}
|
||||
|
||||
ComPtr<ID3D12PipelineState> ComputePipeline::GetPipelineState() {
|
||||
return pipelineState;
|
||||
return mPipelineState;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace backend {
|
|||
ComPtr<ID3D12PipelineState> GetPipelineState();
|
||||
|
||||
private:
|
||||
ComPtr<ID3D12PipelineState> pipelineState;
|
||||
ComPtr<ID3D12PipelineState> mPipelineState;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -83,21 +83,21 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
Device::Device(ComPtr<ID3D12Device> d3d12Device)
|
||||
: d3d12Device(d3d12Device),
|
||||
commandAllocatorManager(new CommandAllocatorManager(this)),
|
||||
descriptorHeapAllocator(new DescriptorHeapAllocator(this)),
|
||||
mapReadRequestTracker(new MapReadRequestTracker(this)),
|
||||
resourceAllocator(new ResourceAllocator(this)),
|
||||
resourceUploader(new ResourceUploader(this)) {
|
||||
: mD3d12Device(d3d12Device),
|
||||
mCommandAllocatorManager(new CommandAllocatorManager(this)),
|
||||
mDescriptorHeapAllocator(new DescriptorHeapAllocator(this)),
|
||||
mMapReadRequestTracker(new MapReadRequestTracker(this)),
|
||||
mResourceAllocator(new ResourceAllocator(this)),
|
||||
mResourceUploader(new ResourceUploader(this)) {
|
||||
|
||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
ASSERT_SUCCESS(d3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&commandQueue)));
|
||||
ASSERT_SUCCESS(d3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue)));
|
||||
|
||||
ASSERT_SUCCESS(d3d12Device->CreateFence(serial, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)));
|
||||
fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
ASSERT(fenceEvent != nullptr);
|
||||
ASSERT_SUCCESS(d3d12Device->CreateFence(mSerial, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&mFence)));
|
||||
mFenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
ASSERT(mFenceEvent != nullptr);
|
||||
|
||||
NextSerial();
|
||||
}
|
||||
|
@ -107,100 +107,100 @@ namespace d3d12 {
|
|||
NextSerial();
|
||||
WaitForSerial(currentSerial); // Wait for all in-flight commands to finish executing
|
||||
TickImpl(); // Call tick one last time so resources are cleaned up
|
||||
delete commandAllocatorManager;
|
||||
delete descriptorHeapAllocator;
|
||||
delete mapReadRequestTracker;
|
||||
delete resourceAllocator;
|
||||
delete resourceUploader;
|
||||
delete mCommandAllocatorManager;
|
||||
delete mDescriptorHeapAllocator;
|
||||
delete mMapReadRequestTracker;
|
||||
delete mResourceAllocator;
|
||||
delete mResourceUploader;
|
||||
}
|
||||
|
||||
ComPtr<ID3D12Device> Device::GetD3D12Device() {
|
||||
return d3d12Device;
|
||||
return mD3d12Device;
|
||||
}
|
||||
|
||||
ComPtr<ID3D12CommandQueue> Device::GetCommandQueue() {
|
||||
return commandQueue;
|
||||
return mCommandQueue;
|
||||
}
|
||||
|
||||
DescriptorHeapAllocator* Device::GetDescriptorHeapAllocator() {
|
||||
return descriptorHeapAllocator;
|
||||
return mDescriptorHeapAllocator;
|
||||
}
|
||||
|
||||
MapReadRequestTracker* Device::GetMapReadRequestTracker() const {
|
||||
return mapReadRequestTracker;
|
||||
return mMapReadRequestTracker;
|
||||
}
|
||||
|
||||
ResourceAllocator* Device::GetResourceAllocator() {
|
||||
return resourceAllocator;
|
||||
return mResourceAllocator;
|
||||
}
|
||||
|
||||
ResourceUploader* Device::GetResourceUploader() {
|
||||
return resourceUploader;
|
||||
return mResourceUploader;
|
||||
}
|
||||
|
||||
void Device::OpenCommandList(ComPtr<ID3D12GraphicsCommandList>* commandList) {
|
||||
ComPtr<ID3D12GraphicsCommandList> &cmdList = *commandList;
|
||||
if (!cmdList) {
|
||||
ASSERT_SUCCESS(d3d12Device->CreateCommandList(
|
||||
ASSERT_SUCCESS(mD3d12Device->CreateCommandList(
|
||||
0,
|
||||
D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
commandAllocatorManager->ReserveCommandAllocator().Get(),
|
||||
mCommandAllocatorManager->ReserveCommandAllocator().Get(),
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&cmdList)
|
||||
));
|
||||
} else {
|
||||
ASSERT_SUCCESS(cmdList->Reset(commandAllocatorManager->ReserveCommandAllocator().Get(), nullptr));
|
||||
ASSERT_SUCCESS(cmdList->Reset(mCommandAllocatorManager->ReserveCommandAllocator().Get(), nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
ComPtr<ID3D12GraphicsCommandList> Device::GetPendingCommandList() {
|
||||
// Callers of GetPendingCommandList do so to record commands. Only reserve a command allocator when it is needed so we don't submit empty command lists
|
||||
if (!pendingCommands.open) {
|
||||
OpenCommandList(&pendingCommands.commandList);
|
||||
pendingCommands.open = true;
|
||||
if (!mPendingCommands.open) {
|
||||
OpenCommandList(&mPendingCommands.commandList);
|
||||
mPendingCommands.open = true;
|
||||
}
|
||||
return pendingCommands.commandList;
|
||||
return mPendingCommands.commandList;
|
||||
}
|
||||
|
||||
void Device::TickImpl() {
|
||||
// Perform cleanup operations to free unused objects
|
||||
const uint64_t lastCompletedSerial = fence->GetCompletedValue();
|
||||
resourceAllocator->Tick(lastCompletedSerial);
|
||||
commandAllocatorManager->Tick(lastCompletedSerial);
|
||||
descriptorHeapAllocator->Tick(lastCompletedSerial);
|
||||
mapReadRequestTracker->Tick(lastCompletedSerial);
|
||||
const uint64_t lastCompletedSerial = mFence->GetCompletedValue();
|
||||
mResourceAllocator->Tick(lastCompletedSerial);
|
||||
mCommandAllocatorManager->Tick(lastCompletedSerial);
|
||||
mDescriptorHeapAllocator->Tick(lastCompletedSerial);
|
||||
mMapReadRequestTracker->Tick(lastCompletedSerial);
|
||||
ExecuteCommandLists({});
|
||||
NextSerial();
|
||||
}
|
||||
|
||||
uint64_t Device::GetSerial() const {
|
||||
return serial;
|
||||
return mSerial;
|
||||
}
|
||||
|
||||
void Device::NextSerial() {
|
||||
ASSERT_SUCCESS(commandQueue->Signal(fence.Get(), serial++));
|
||||
ASSERT_SUCCESS(mCommandQueue->Signal(mFence.Get(), mSerial++));
|
||||
}
|
||||
|
||||
void Device::WaitForSerial(uint64_t serial) {
|
||||
const uint64_t lastCompletedSerial = fence->GetCompletedValue();
|
||||
const uint64_t lastCompletedSerial = mFence->GetCompletedValue();
|
||||
if (lastCompletedSerial < serial) {
|
||||
ASSERT_SUCCESS(fence->SetEventOnCompletion(serial, fenceEvent));
|
||||
WaitForSingleObject(fenceEvent, INFINITE);
|
||||
ASSERT_SUCCESS(mFence->SetEventOnCompletion(serial, mFenceEvent));
|
||||
WaitForSingleObject(mFenceEvent, INFINITE);
|
||||
}
|
||||
}
|
||||
|
||||
void Device::ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists) {
|
||||
// If there are pending commands, prepend them to ExecuteCommandLists
|
||||
if (pendingCommands.open) {
|
||||
if (mPendingCommands.open) {
|
||||
std::vector<ID3D12CommandList*> lists(commandLists.size() + 1);
|
||||
pendingCommands.commandList->Close();
|
||||
pendingCommands.open = false;
|
||||
lists[0] = pendingCommands.commandList.Get();
|
||||
mPendingCommands.commandList->Close();
|
||||
mPendingCommands.open = false;
|
||||
lists[0] = mPendingCommands.commandList.Get();
|
||||
std::copy(commandLists.begin(), commandLists.end(), lists.begin() + 1);
|
||||
commandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size() + 1), lists.data());
|
||||
mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size() + 1), lists.data());
|
||||
} else {
|
||||
std::vector<ID3D12CommandList*> lists(commandLists);
|
||||
commandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size()), lists.data());
|
||||
mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size()), lists.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ namespace d3d12 {
|
|||
// RenderPass
|
||||
|
||||
RenderPass::RenderPass(Device* device, RenderPassBuilder* builder)
|
||||
: RenderPassBase(builder), device(device) {
|
||||
: RenderPassBase(builder), mDevice(device) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -130,23 +130,23 @@ namespace d3d12 {
|
|||
void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
|
||||
|
||||
private:
|
||||
uint64_t serial = 0;
|
||||
ComPtr<ID3D12Fence> fence;
|
||||
HANDLE fenceEvent;
|
||||
uint64_t mSerial = 0;
|
||||
ComPtr<ID3D12Fence> mFence;
|
||||
HANDLE mFenceEvent;
|
||||
|
||||
ComPtr<ID3D12Device> d3d12Device;
|
||||
ComPtr<ID3D12CommandQueue> commandQueue;
|
||||
ComPtr<ID3D12Device> mD3d12Device;
|
||||
ComPtr<ID3D12CommandQueue> mCommandQueue;
|
||||
|
||||
CommandAllocatorManager* commandAllocatorManager;
|
||||
DescriptorHeapAllocator* descriptorHeapAllocator;
|
||||
MapReadRequestTracker* mapReadRequestTracker;
|
||||
ResourceAllocator* resourceAllocator;
|
||||
ResourceUploader* resourceUploader;
|
||||
CommandAllocatorManager* mCommandAllocatorManager;
|
||||
DescriptorHeapAllocator* mDescriptorHeapAllocator;
|
||||
MapReadRequestTracker* mMapReadRequestTracker;
|
||||
ResourceAllocator* mResourceAllocator;
|
||||
ResourceUploader* mResourceUploader;
|
||||
|
||||
struct PendingCommandList {
|
||||
ComPtr<ID3D12GraphicsCommandList> commandList;
|
||||
bool open = false;
|
||||
} pendingCommands;
|
||||
} mPendingCommands;
|
||||
};
|
||||
|
||||
class RenderPass : public RenderPassBase {
|
||||
|
@ -154,7 +154,7 @@ namespace d3d12 {
|
|||
RenderPass(Device* device, RenderPassBuilder* builder);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -78,22 +78,22 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||
: DepthStencilStateBase(builder), device(device) {
|
||||
: DepthStencilStateBase(builder), mDevice(device) {
|
||||
|
||||
depthStencilDescriptor.DepthEnable = TRUE;
|
||||
depthStencilDescriptor.DepthWriteMask = GetDepth().depthWriteEnabled ? D3D12_DEPTH_WRITE_MASK_ALL : D3D12_DEPTH_WRITE_MASK_ZERO;
|
||||
depthStencilDescriptor.DepthFunc = ComparisonFunc(GetDepth().compareFunction);
|
||||
mDepthStencilDescriptor.DepthEnable = TRUE;
|
||||
mDepthStencilDescriptor.DepthWriteMask = GetDepth().depthWriteEnabled ? D3D12_DEPTH_WRITE_MASK_ALL : D3D12_DEPTH_WRITE_MASK_ZERO;
|
||||
mDepthStencilDescriptor.DepthFunc = ComparisonFunc(GetDepth().compareFunction);
|
||||
|
||||
depthStencilDescriptor.StencilEnable = StencilTestEnabled() ? TRUE : FALSE;
|
||||
depthStencilDescriptor.StencilReadMask = static_cast<UINT8>(GetStencil().readMask);
|
||||
depthStencilDescriptor.StencilWriteMask = static_cast<UINT8>(GetStencil().writeMask);
|
||||
mDepthStencilDescriptor.StencilEnable = StencilTestEnabled() ? TRUE : FALSE;
|
||||
mDepthStencilDescriptor.StencilReadMask = static_cast<UINT8>(GetStencil().readMask);
|
||||
mDepthStencilDescriptor.StencilWriteMask = static_cast<UINT8>(GetStencil().writeMask);
|
||||
|
||||
depthStencilDescriptor.FrontFace = StencilOpDesc(GetStencil().front);
|
||||
depthStencilDescriptor.BackFace = StencilOpDesc(GetStencil().back);
|
||||
mDepthStencilDescriptor.FrontFace = StencilOpDesc(GetStencil().front);
|
||||
mDepthStencilDescriptor.BackFace = StencilOpDesc(GetStencil().back);
|
||||
}
|
||||
|
||||
const D3D12_DEPTH_STENCIL_DESC& DepthStencilState::GetD3D12DepthStencilDescriptor() const {
|
||||
return depthStencilDescriptor;
|
||||
return mDepthStencilDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace d3d12 {
|
|||
const D3D12_DEPTH_STENCIL_DESC& GetD3D12DepthStencilDescriptor() const;
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
D3D12_DEPTH_STENCIL_DESC depthStencilDescriptor;
|
||||
Device* mDevice;
|
||||
D3D12_DEPTH_STENCIL_DESC mDepthStencilDescriptor;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,35 +21,35 @@ namespace backend {
|
|||
namespace d3d12 {
|
||||
|
||||
DescriptorHeapHandle::DescriptorHeapHandle()
|
||||
: descriptorHeap(nullptr), sizeIncrement(0), offset(0) {
|
||||
: mDescriptorHeap(nullptr), mSizeIncrement(0), mOffset(0) {
|
||||
}
|
||||
|
||||
DescriptorHeapHandle::DescriptorHeapHandle(ComPtr<ID3D12DescriptorHeap> descriptorHeap, uint32_t sizeIncrement, uint32_t offset)
|
||||
: descriptorHeap(descriptorHeap), sizeIncrement(sizeIncrement), offset(offset) {
|
||||
: mDescriptorHeap(descriptorHeap), mSizeIncrement(sizeIncrement), mOffset(offset) {
|
||||
}
|
||||
|
||||
ID3D12DescriptorHeap* DescriptorHeapHandle::Get() const {
|
||||
return descriptorHeap.Get();
|
||||
return mDescriptorHeap.Get();
|
||||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE DescriptorHeapHandle::GetCPUHandle(uint32_t index) const {
|
||||
ASSERT(descriptorHeap);
|
||||
auto handle = descriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += sizeIncrement * (index + offset);
|
||||
ASSERT(mDescriptorHeap);
|
||||
auto handle = mDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += mSizeIncrement * (index + mOffset);
|
||||
return handle;
|
||||
}
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE DescriptorHeapHandle::GetGPUHandle(uint32_t index) const {
|
||||
ASSERT(descriptorHeap);
|
||||
auto handle = descriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += sizeIncrement * (index + offset);
|
||||
ASSERT(mDescriptorHeap);
|
||||
auto handle = mDescriptorHeap->GetGPUDescriptorHandleForHeapStart();
|
||||
handle.ptr += mSizeIncrement * (index + mOffset);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
DescriptorHeapAllocator::DescriptorHeapAllocator(Device* device)
|
||||
: device(device),
|
||||
sizeIncrements {
|
||||
: mDevice(device),
|
||||
mSizeIncrements {
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV),
|
||||
|
@ -68,7 +68,7 @@ namespace d3d12 {
|
|||
// If the current pool for this type has space, linearly allocate count bytes in the pool
|
||||
auto& allocationInfo = heapInfo->second;
|
||||
if (allocationInfo.remaining >= count) {
|
||||
DescriptorHeapHandle handle(heapInfo->first, sizeIncrements[type], allocationInfo.size - allocationInfo.remaining);
|
||||
DescriptorHeapHandle handle(heapInfo->first, mSizeIncrements[type], allocationInfo.size - allocationInfo.remaining);
|
||||
allocationInfo.remaining -= count;
|
||||
Release(handle);
|
||||
return handle;
|
||||
|
@ -83,32 +83,32 @@ namespace d3d12 {
|
|||
heapDescriptor.Flags = flags;
|
||||
heapDescriptor.NodeMask = 0;
|
||||
ComPtr<ID3D12DescriptorHeap> heap;
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateDescriptorHeap(&heapDescriptor, IID_PPV_ARGS(&heap)));
|
||||
ASSERT_SUCCESS(mDevice->GetD3D12Device()->CreateDescriptorHeap(&heapDescriptor, IID_PPV_ARGS(&heap)));
|
||||
|
||||
AllocationInfo allocationInfo = { allocationSize, allocationSize - count };
|
||||
*heapInfo = std::make_pair(heap, allocationInfo);
|
||||
|
||||
DescriptorHeapHandle handle(heap, sizeIncrements[type], 0);
|
||||
DescriptorHeapHandle handle(heap, mSizeIncrements[type], 0);
|
||||
Release(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count) {
|
||||
return Allocate(type, count, count, &cpuDescriptorHeapInfos[type], D3D12_DESCRIPTOR_HEAP_FLAG_NONE);
|
||||
return Allocate(type, count, count, &mCpuDescriptorHeapInfos[type], D3D12_DESCRIPTOR_HEAP_FLAG_NONE);
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count) {
|
||||
ASSERT(type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV || type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
unsigned int heapSize = (type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ? kMaxCbvUavSrvHeapSize : kMaxSamplerHeapSize);
|
||||
return Allocate(type, count, heapSize, &gpuDescriptorHeapInfos[type], D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE);
|
||||
return Allocate(type, count, heapSize, &mGpuDescriptorHeapInfos[type], D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE);
|
||||
}
|
||||
|
||||
void DescriptorHeapAllocator::Tick(uint64_t lastCompletedSerial) {
|
||||
releasedHandles.ClearUpTo(lastCompletedSerial);
|
||||
mReleasedHandles.ClearUpTo(lastCompletedSerial);
|
||||
}
|
||||
|
||||
void DescriptorHeapAllocator::Release(DescriptorHeapHandle handle) {
|
||||
releasedHandles.Enqueue(handle, device->GetSerial());
|
||||
mReleasedHandles.Enqueue(handle, mDevice->GetSerial());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,9 @@ namespace d3d12 {
|
|||
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUHandle(uint32_t index) const;
|
||||
|
||||
private:
|
||||
ComPtr<ID3D12DescriptorHeap> descriptorHeap;
|
||||
uint32_t sizeIncrement;
|
||||
uint32_t offset;
|
||||
ComPtr<ID3D12DescriptorHeap> mDescriptorHeap;
|
||||
uint32_t mSizeIncrement;
|
||||
uint32_t mOffset;
|
||||
};
|
||||
|
||||
class DescriptorHeapAllocator {
|
||||
|
@ -65,12 +65,12 @@ namespace d3d12 {
|
|||
DescriptorHeapHandle Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count, uint32_t allocationSize, DescriptorHeapInfo* heapInfo, D3D12_DESCRIPTOR_HEAP_FLAGS flags);
|
||||
void Release(DescriptorHeapHandle handle);
|
||||
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
|
||||
std::array<uint32_t, kDescriptorHeapTypes> sizeIncrements;
|
||||
std::array<DescriptorHeapInfo, kDescriptorHeapTypes> cpuDescriptorHeapInfos;
|
||||
std::array<DescriptorHeapInfo, kDescriptorHeapTypes> gpuDescriptorHeapInfos;
|
||||
SerialQueue<DescriptorHeapHandle> releasedHandles;
|
||||
std::array<uint32_t, kDescriptorHeapTypes> mSizeIncrements;
|
||||
std::array<DescriptorHeapInfo, kDescriptorHeapTypes> mCpuDescriptorHeapInfos;
|
||||
std::array<DescriptorHeapInfo, kDescriptorHeapTypes> mGpuDescriptorHeapInfos;
|
||||
SerialQueue<DescriptorHeapHandle> mReleasedHandles;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -22,42 +22,42 @@ namespace backend {
|
|||
namespace d3d12 {
|
||||
|
||||
Framebuffer::Framebuffer(Device* device, FramebufferBuilder* builder)
|
||||
: FramebufferBase(builder), device(device) {
|
||||
: FramebufferBase(builder), mDevice(device) {
|
||||
RenderPass* renderPass = ToBackend(GetRenderPass());
|
||||
|
||||
uint32_t rtvCount = 0, dsvCount = 0;
|
||||
attachmentHeapIndices.resize(renderPass->GetAttachmentCount());
|
||||
mAttachmentHeapIndices.resize(renderPass->GetAttachmentCount());
|
||||
for (uint32_t attachment = 0; attachment < renderPass->GetAttachmentCount(); ++attachment) {
|
||||
auto* textureView = GetTextureView(attachment);
|
||||
auto format = textureView->GetTexture()->GetFormat();
|
||||
if (TextureFormatHasDepth(format) || TextureFormatHasStencil(format)) {
|
||||
attachmentHeapIndices[attachment] = dsvCount++;
|
||||
mAttachmentHeapIndices[attachment] = dsvCount++;
|
||||
} else {
|
||||
attachmentHeapIndices[attachment] = rtvCount++;
|
||||
mAttachmentHeapIndices[attachment] = rtvCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (rtvCount) {
|
||||
rtvHeap = device->GetDescriptorHeapAllocator()->AllocateCPUHeap(
|
||||
mRtvHeap = device->GetDescriptorHeapAllocator()->AllocateCPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_RTV, rtvCount);
|
||||
}
|
||||
if (dsvCount) {
|
||||
dsvHeap = device->GetDescriptorHeapAllocator()->AllocateCPUHeap(
|
||||
mDsvHeap = device->GetDescriptorHeapAllocator()->AllocateCPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_DSV, dsvCount);
|
||||
}
|
||||
|
||||
for (uint32_t attachment = 0; attachment < renderPass->GetAttachmentCount(); ++attachment) {
|
||||
uint32_t heapIndex = attachmentHeapIndices[attachment];
|
||||
uint32_t heapIndex = mAttachmentHeapIndices[attachment];
|
||||
auto* textureView = GetTextureView(attachment);
|
||||
|
||||
ComPtr<ID3D12Resource> texture = ToBackend(textureView->GetTexture())->GetD3D12Resource();
|
||||
auto format = textureView->GetTexture()->GetFormat();
|
||||
if (TextureFormatHasDepth(format) || TextureFormatHasStencil(format)) {
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = dsvHeap.GetCPUHandle(heapIndex);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = mDsvHeap.GetCPUHandle(heapIndex);
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = ToBackend(textureView)->GetDSVDescriptor();
|
||||
device->GetD3D12Device()->CreateDepthStencilView(texture.Get(), &dsvDesc, dsvHandle);
|
||||
} else {
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = rtvHeap.GetCPUHandle(heapIndex);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = mRtvHeap.GetCPUHandle(heapIndex);
|
||||
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = ToBackend(textureView)->GetRTVDescriptor();
|
||||
device->GetD3D12Device()->CreateRenderTargetView(texture.Get(), &rtvDesc, rtvHandle);
|
||||
}
|
||||
|
@ -82,11 +82,11 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE Framebuffer::GetRTVDescriptor(uint32_t attachmentSlot) {
|
||||
return rtvHeap.GetCPUHandle(attachmentHeapIndices[attachmentSlot]);
|
||||
return mRtvHeap.GetCPUHandle(mAttachmentHeapIndices[attachmentSlot]);
|
||||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE Framebuffer::GetDSVDescriptor(uint32_t attachmentSlot) {
|
||||
return dsvHeap.GetCPUHandle(attachmentHeapIndices[attachmentSlot]);
|
||||
return mDsvHeap.GetCPUHandle(mAttachmentHeapIndices[attachmentSlot]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,12 +43,12 @@ namespace d3d12 {
|
|||
D3D12_CPU_DESCRIPTOR_HANDLE GetDSVDescriptor(uint32_t attachmentSlot);
|
||||
|
||||
private:
|
||||
Device* device = nullptr;
|
||||
DescriptorHeapHandle rtvHeap = {};
|
||||
DescriptorHeapHandle dsvHeap = {};
|
||||
Device* mDevice = nullptr;
|
||||
DescriptorHeapHandle mRtvHeap = {};
|
||||
DescriptorHeapHandle mDsvHeap = {};
|
||||
|
||||
// Indices into either the RTV or DSV heap, depending on texture format.
|
||||
std::vector<uint32_t> attachmentHeapIndices;
|
||||
std::vector<uint32_t> mAttachmentHeapIndices;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
InputState::InputState(Device* device, InputStateBuilder* builder)
|
||||
: InputStateBase(builder), device(device) {
|
||||
: InputStateBase(builder), mDevice(device) {
|
||||
|
||||
const auto& attributesSetMask = GetAttributesSetMask();
|
||||
|
||||
|
@ -56,7 +56,7 @@ namespace d3d12 {
|
|||
continue;
|
||||
}
|
||||
|
||||
D3D12_INPUT_ELEMENT_DESC& inputElementDescriptor = inputElementDescriptors[count++];
|
||||
D3D12_INPUT_ELEMENT_DESC& inputElementDescriptor = mInputElementDescriptors[count++];
|
||||
|
||||
const AttributeInfo& attribute = GetAttribute(i);
|
||||
|
||||
|
@ -77,13 +77,13 @@ namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
inputLayoutDescriptor.pInputElementDescs = inputElementDescriptors;
|
||||
inputLayoutDescriptor.NumElements = count;
|
||||
mInputLayoutDescriptor.pInputElementDescs = mInputElementDescriptors;
|
||||
mInputLayoutDescriptor.NumElements = count;
|
||||
|
||||
}
|
||||
|
||||
const D3D12_INPUT_LAYOUT_DESC& InputState::GetD3D12InputLayoutDescriptor() const {
|
||||
return inputLayoutDescriptor;
|
||||
return mInputLayoutDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ namespace d3d12 {
|
|||
const D3D12_INPUT_LAYOUT_DESC& GetD3D12InputLayoutDescriptor() const;
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
D3D12_INPUT_LAYOUT_DESC inputLayoutDescriptor;
|
||||
D3D12_INPUT_ELEMENT_DESC inputElementDescriptors[kMaxVertexAttributes];
|
||||
Device* mDevice;
|
||||
D3D12_INPUT_LAYOUT_DESC mInputLayoutDescriptor;
|
||||
D3D12_INPUT_ELEMENT_DESC mInputElementDescriptors[kMaxVertexAttributes];
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace backend {
|
|||
namespace d3d12 {
|
||||
|
||||
PipelineLayout::PipelineLayout(Device* device, PipelineLayoutBuilder* builder)
|
||||
: PipelineLayoutBase(builder), device(device) {
|
||||
: PipelineLayoutBase(builder), mDevice(device) {
|
||||
|
||||
D3D12_ROOT_PARAMETER rootParameters[kMaxBindGroups * 2];
|
||||
|
||||
|
@ -70,11 +70,11 @@ namespace d3d12 {
|
|||
};
|
||||
|
||||
if (SetRootDescriptorTable(bindGroupLayout->GetCbvUavSrvDescriptorTableSize(), bindGroupLayout->GetCbvUavSrvDescriptorRanges())) {
|
||||
cbvUavSrvRootParameterInfo[group] = parameterIndex++;
|
||||
mCbvUavSrvRootParameterInfo[group] = parameterIndex++;
|
||||
}
|
||||
|
||||
if (SetRootDescriptorTable(bindGroupLayout->GetSamplerDescriptorTableSize(), bindGroupLayout->GetSamplerDescriptorRanges())) {
|
||||
samplerRootParameterInfo[group] = parameterIndex++;
|
||||
mSamplerRootParameterInfo[group] = parameterIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,22 +88,22 @@ namespace d3d12 {
|
|||
ComPtr<ID3DBlob> signature;
|
||||
ComPtr<ID3DBlob> error;
|
||||
ASSERT_SUCCESS(D3D12SerializeRootSignature(&rootSignatureDescriptor, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature)));
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&mRootSignature)));
|
||||
}
|
||||
|
||||
|
||||
uint32_t PipelineLayout::GetCbvUavSrvRootParameterIndex(uint32_t group) const {
|
||||
ASSERT(group < kMaxBindGroups);
|
||||
return cbvUavSrvRootParameterInfo[group];
|
||||
return mCbvUavSrvRootParameterInfo[group];
|
||||
}
|
||||
|
||||
uint32_t PipelineLayout::GetSamplerRootParameterIndex(uint32_t group) const {
|
||||
ASSERT(group < kMaxBindGroups);
|
||||
return samplerRootParameterInfo[group];
|
||||
return mSamplerRootParameterInfo[group];
|
||||
}
|
||||
|
||||
ComPtr<ID3D12RootSignature> PipelineLayout::GetRootSignature() {
|
||||
return rootSignature;
|
||||
return mRootSignature;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ namespace d3d12 {
|
|||
ComPtr<ID3D12RootSignature> GetRootSignature();
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
|
||||
std::array<uint32_t, kMaxBindGroups> cbvUavSrvRootParameterInfo;
|
||||
std::array<uint32_t, kMaxBindGroups> samplerRootParameterInfo;
|
||||
std::array<uint32_t, kMaxBindGroups> mCbvUavSrvRootParameterInfo;
|
||||
std::array<uint32_t, kMaxBindGroups> mSamplerRootParameterInfo;
|
||||
|
||||
ComPtr<ID3D12RootSignature> rootSignature;
|
||||
ComPtr<ID3D12RootSignature> mRootSignature;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,21 +21,21 @@ namespace backend {
|
|||
namespace d3d12 {
|
||||
|
||||
Queue::Queue(Device* device, QueueBuilder* builder)
|
||||
: QueueBase(builder), device(device) {
|
||||
: QueueBase(builder), mDevice(device) {
|
||||
}
|
||||
|
||||
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) {
|
||||
device->Tick();
|
||||
mDevice->Tick();
|
||||
|
||||
device->OpenCommandList(&commandList);
|
||||
mDevice->OpenCommandList(&mCommandList);
|
||||
for (uint32_t i = 0; i < numCommands; ++i) {
|
||||
commands[i]->FillCommands(commandList);
|
||||
commands[i]->FillCommands(mCommandList);
|
||||
}
|
||||
ASSERT_SUCCESS(commandList->Close());
|
||||
ASSERT_SUCCESS(mCommandList->Close());
|
||||
|
||||
device->ExecuteCommandLists({ commandList.Get() });
|
||||
mDevice->ExecuteCommandLists({ mCommandList.Get() });
|
||||
|
||||
device->NextSerial();
|
||||
mDevice->NextSerial();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,9 +33,9 @@ namespace d3d12 {
|
|||
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
|
||||
ComPtr<ID3D12GraphicsCommandList> commandList;
|
||||
ComPtr<ID3D12GraphicsCommandList> mCommandList;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
|
||||
: RenderPipelineBase(builder), d3d12PrimitiveTopology(D3D12PrimitiveTopology(GetPrimitiveTopology())) {
|
||||
: RenderPipelineBase(builder), mD3d12PrimitiveTopology(D3D12PrimitiveTopology(GetPrimitiveTopology())) {
|
||||
uint32_t compileFlags = 0;
|
||||
#if defined(_DEBUG)
|
||||
// Enable better shader debugging with the graphics debugging tools.
|
||||
|
@ -174,15 +174,15 @@ namespace d3d12 {
|
|||
descriptor.SampleDesc.Count = 1;
|
||||
|
||||
Device* device = ToBackend(builder->GetDevice());
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateGraphicsPipelineState(&descriptor, IID_PPV_ARGS(&pipelineState)));
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateGraphicsPipelineState(&descriptor, IID_PPV_ARGS(&mPipelineState)));
|
||||
}
|
||||
|
||||
D3D12_PRIMITIVE_TOPOLOGY RenderPipeline::GetD3D12PrimitiveTopology() const {
|
||||
return d3d12PrimitiveTopology;
|
||||
return mD3d12PrimitiveTopology;
|
||||
}
|
||||
|
||||
ComPtr<ID3D12PipelineState> RenderPipeline::GetPipelineState() {
|
||||
return pipelineState;
|
||||
return mPipelineState;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace d3d12 {
|
|||
ComPtr<ID3D12PipelineState> GetPipelineState();
|
||||
|
||||
private:
|
||||
D3D12_PRIMITIVE_TOPOLOGY d3d12PrimitiveTopology;
|
||||
ComPtr<ID3D12PipelineState> pipelineState;
|
||||
D3D12_PRIMITIVE_TOPOLOGY mD3d12PrimitiveTopology;
|
||||
ComPtr<ID3D12PipelineState> mPipelineState;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace d3d12 {
|
|||
};
|
||||
}
|
||||
|
||||
ResourceAllocator::ResourceAllocator(Device* device) : device(device) {
|
||||
ResourceAllocator::ResourceAllocator(Device* device) : mDevice(device) {
|
||||
}
|
||||
|
||||
ComPtr<ID3D12Resource> ResourceAllocator::Allocate(D3D12_HEAP_TYPE heapType, const D3D12_RESOURCE_DESC &resourceDescriptor, D3D12_RESOURCE_STATES initialUsage) {
|
||||
|
@ -67,7 +67,7 @@ namespace d3d12 {
|
|||
ComPtr<ID3D12Resource> resource;
|
||||
|
||||
// TODO(enga@google.com): Use CreatePlacedResource
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateCommittedResource(
|
||||
ASSERT_SUCCESS(mDevice->GetD3D12Device()->CreateCommittedResource(
|
||||
heapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&resourceDescriptor,
|
||||
|
@ -81,11 +81,11 @@ namespace d3d12 {
|
|||
|
||||
void ResourceAllocator::Release(ComPtr<ID3D12Resource> resource) {
|
||||
// Resources may still be in use on the GPU. Enqueue them so that we hold onto them until GPU execution has completed
|
||||
releasedResources.Enqueue(resource, device->GetSerial());
|
||||
mReleasedResources.Enqueue(resource, mDevice->GetSerial());
|
||||
}
|
||||
|
||||
void ResourceAllocator::Tick(uint64_t lastCompletedSerial) {
|
||||
releasedResources.ClearUpTo(lastCompletedSerial);
|
||||
mReleasedResources.ClearUpTo(lastCompletedSerial);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ namespace d3d12 {
|
|||
void Tick(uint64_t lastCompletedSerial);
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
|
||||
SerialQueue<ComPtr<ID3D12Resource>> releasedResources;
|
||||
SerialQueue<ComPtr<ID3D12Resource>> mReleasedResources;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
namespace backend {
|
||||
namespace d3d12 {
|
||||
|
||||
ResourceUploader::ResourceUploader(Device* device) : device(device) {
|
||||
ResourceUploader::ResourceUploader(Device* device) : mDevice(device) {
|
||||
}
|
||||
|
||||
void ResourceUploader::BufferSubData(ComPtr<ID3D12Resource> resource, uint32_t start, uint32_t count, const void* data) {
|
||||
|
@ -28,7 +28,7 @@ namespace d3d12 {
|
|||
// Alternatively, the SerialQueue could be used to track which last point of the ringbuffer is in use, and start reusing chunks of it that aren't in flight.
|
||||
UploadHandle uploadHandle = GetUploadBuffer(count);
|
||||
memcpy(uploadHandle.mappedBuffer, data, count);
|
||||
device->GetPendingCommandList()->CopyBufferRegion(resource.Get(), start, uploadHandle.resource.Get(), 0, count);
|
||||
mDevice->GetPendingCommandList()->CopyBufferRegion(resource.Get(), start, uploadHandle.resource.Get(), 0, count);
|
||||
Release(uploadHandle);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ namespace d3d12 {
|
|||
resourceDescriptor.Flags = D3D12_RESOURCE_FLAG_NONE;
|
||||
|
||||
UploadHandle uploadHandle;
|
||||
uploadHandle.resource = device->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor, D3D12_RESOURCE_STATE_GENERIC_READ);
|
||||
uploadHandle.resource = mDevice->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor, D3D12_RESOURCE_STATE_GENERIC_READ);
|
||||
D3D12_RANGE readRange;
|
||||
readRange.Begin = 0;
|
||||
readRange.End = 0;
|
||||
|
@ -59,7 +59,7 @@ namespace d3d12 {
|
|||
|
||||
void ResourceUploader::Release(UploadHandle uploadHandle) {
|
||||
uploadHandle.resource->Unmap(0, nullptr);
|
||||
device->GetResourceAllocator()->Release(uploadHandle.resource);
|
||||
mDevice->GetResourceAllocator()->Release(uploadHandle.resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace d3d12 {
|
|||
UploadHandle GetUploadBuffer(uint32_t requiredSize);
|
||||
void Release(UploadHandle uploadHandle);
|
||||
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,21 +62,21 @@ namespace d3d12 {
|
|||
break;
|
||||
}
|
||||
|
||||
samplerDesc.Filter = static_cast<D3D12_FILTER>(mode);
|
||||
samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
samplerDesc.MipLODBias = 0.f;
|
||||
samplerDesc.MaxAnisotropy = 1;
|
||||
samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
||||
samplerDesc.BorderColor[0] = samplerDesc.BorderColor[1] = samplerDesc.BorderColor[2] = samplerDesc.BorderColor[3] = 0;
|
||||
samplerDesc.MinLOD = 0;
|
||||
samplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
|
||||
mSamplerDesc.Filter = static_cast<D3D12_FILTER>(mode);
|
||||
mSamplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
mSamplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
mSamplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
|
||||
mSamplerDesc.MipLODBias = 0.f;
|
||||
mSamplerDesc.MaxAnisotropy = 1;
|
||||
mSamplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
||||
mSamplerDesc.BorderColor[0] = mSamplerDesc.BorderColor[1] = mSamplerDesc.BorderColor[2] = mSamplerDesc.BorderColor[3] = 0;
|
||||
mSamplerDesc.MinLOD = 0;
|
||||
mSamplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
|
||||
|
||||
}
|
||||
|
||||
const D3D12_SAMPLER_DESC& Sampler::GetSamplerDescriptor() const {
|
||||
return samplerDesc;
|
||||
return mSamplerDesc;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace d3d12 {
|
|||
const D3D12_SAMPLER_DESC& GetSamplerDescriptor() const;
|
||||
|
||||
private:
|
||||
D3D12_SAMPLER_DESC samplerDesc;
|
||||
D3D12_SAMPLER_DESC mSamplerDesc;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace backend {
|
|||
namespace d3d12 {
|
||||
|
||||
ShaderModule::ShaderModule(Device* device, ShaderModuleBuilder* builder)
|
||||
: ShaderModuleBase(builder), device(device) {
|
||||
: ShaderModuleBase(builder), mDevice(device) {
|
||||
spirv_cross::CompilerHLSL compiler(builder->AcquireSpirv());
|
||||
|
||||
spirv_cross::CompilerGLSL::Options options_glsl;
|
||||
|
@ -52,11 +52,11 @@ namespace d3d12 {
|
|||
RenumberBindings(resources.separate_images); // t
|
||||
RenumberBindings(resources.separate_samplers); // s
|
||||
|
||||
hlslSource = compiler.compile();
|
||||
mHlslSource = compiler.compile();
|
||||
}
|
||||
|
||||
const std::string& ShaderModule::GetHLSLSource() const {
|
||||
return hlslSource;
|
||||
return mHlslSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ namespace d3d12 {
|
|||
const std::string& GetHLSLSource() const;
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
Device* mDevice;
|
||||
|
||||
std::string hlslSource;
|
||||
std::string mHlslSource;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
Texture::Texture(TextureBuilder* builder)
|
||||
: TextureBase(builder), device(ToBackend(builder->GetDevice())) {
|
||||
: TextureBase(builder), mDevice(ToBackend(builder->GetDevice())) {
|
||||
|
||||
D3D12_RESOURCE_DESC resourceDescriptor;
|
||||
resourceDescriptor.Dimension = D3D12TextureDimension(GetDimension());
|
||||
|
@ -108,20 +108,20 @@ namespace d3d12 {
|
|||
resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||
resourceDescriptor.Flags = D3D12ResourceFlags(GetAllowedUsage(), GetFormat());
|
||||
|
||||
resource = device->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, D3D12TextureUsage(GetUsage(), GetFormat()));
|
||||
resourcePtr = resource.Get();
|
||||
mResource = mDevice->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, D3D12TextureUsage(GetUsage(), GetFormat()));
|
||||
mResourcePtr = mResource.Get();
|
||||
}
|
||||
|
||||
// With this constructor, the lifetime of the ID3D12Resource is externally managed.
|
||||
Texture::Texture(TextureBuilder* builder, ID3D12Resource* nativeTexture)
|
||||
: TextureBase(builder), device(ToBackend(builder->GetDevice())),
|
||||
resourcePtr(nativeTexture) {
|
||||
: TextureBase(builder), mDevice(ToBackend(builder->GetDevice())),
|
||||
mResourcePtr(nativeTexture) {
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
if (resource) {
|
||||
if (mResource) {
|
||||
// If we own the resource, release it.
|
||||
device->GetResourceAllocator()->Release(resource);
|
||||
mDevice->GetResourceAllocator()->Release(mResource);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
ID3D12Resource* Texture::GetD3D12Resource() {
|
||||
return resourcePtr;
|
||||
return mResourcePtr;
|
||||
}
|
||||
|
||||
bool Texture::GetResourceTransitionBarrier(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage, D3D12_RESOURCE_BARRIER* barrier) {
|
||||
|
@ -143,7 +143,7 @@ namespace d3d12 {
|
|||
|
||||
barrier->Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||
barrier->Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
||||
barrier->Transition.pResource = resourcePtr;
|
||||
barrier->Transition.pResource = mResourcePtr;
|
||||
barrier->Transition.StateBefore = stateBefore;
|
||||
barrier->Transition.StateAfter = stateAfter;
|
||||
barrier->Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
|
@ -154,28 +154,28 @@ namespace d3d12 {
|
|||
void Texture::TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) {
|
||||
D3D12_RESOURCE_BARRIER barrier;
|
||||
if (GetResourceTransitionBarrier(currentUsage, targetUsage, &barrier)) {
|
||||
device->GetPendingCommandList()->ResourceBarrier(1, &barrier);
|
||||
mDevice->GetPendingCommandList()->ResourceBarrier(1, &barrier);
|
||||
}
|
||||
}
|
||||
|
||||
TextureView::TextureView(TextureViewBuilder* builder)
|
||||
: TextureViewBase(builder) {
|
||||
|
||||
srvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat());
|
||||
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat());
|
||||
mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
switch (GetTexture()->GetDimension()) {
|
||||
case nxt::TextureDimension::e2D:
|
||||
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||
srvDesc.Texture2D.MipLevels = GetTexture()->GetNumMipLevels();
|
||||
srvDesc.Texture2D.PlaneSlice = 0;
|
||||
srvDesc.Texture2D.ResourceMinLODClamp = 0;
|
||||
mSrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||
mSrvDesc.Texture2D.MostDetailedMip = 0;
|
||||
mSrvDesc.Texture2D.MipLevels = GetTexture()->GetNumMipLevels();
|
||||
mSrvDesc.Texture2D.PlaneSlice = 0;
|
||||
mSrvDesc.Texture2D.ResourceMinLODClamp = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const D3D12_SHADER_RESOURCE_VIEW_DESC& TextureView::GetSRVDescriptor() const {
|
||||
return srvDesc;
|
||||
return mSrvDesc;
|
||||
}
|
||||
|
||||
D3D12_RENDER_TARGET_VIEW_DESC TextureView::GetRTVDescriptor() {
|
||||
|
|
|
@ -39,9 +39,9 @@ namespace d3d12 {
|
|||
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
|
||||
|
||||
private:
|
||||
Device* device;
|
||||
ComPtr<ID3D12Resource> resource = {};
|
||||
ID3D12Resource* resourcePtr = nullptr;
|
||||
Device* mDevice;
|
||||
ComPtr<ID3D12Resource> mResource = {};
|
||||
ID3D12Resource* mResourcePtr = nullptr;
|
||||
};
|
||||
|
||||
class TextureView : public TextureViewBase {
|
||||
|
@ -53,7 +53,7 @@ namespace d3d12 {
|
|||
D3D12_DEPTH_STENCIL_VIEW_DESC GetDSVDescriptor();
|
||||
|
||||
private:
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC mSrvDesc;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue