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