Format: src/backend/d3d12
This commit is contained in:
parent
c1400f0d14
commit
2d62a371ee
|
@ -12,23 +12,26 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "common/BitSetIterator.h"
|
||||
#include "backend/d3d12/BindGroupD3D12.h"
|
||||
#include "backend/d3d12/BindGroupLayoutD3D12.h"
|
||||
#include "backend/d3d12/BufferD3D12.h"
|
||||
#include "backend/d3d12/SamplerD3D12.h"
|
||||
#include "backend/d3d12/TextureD3D12.h"
|
||||
#include "common/BitSetIterator.h"
|
||||
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
BindGroup::BindGroup(Device* device, BindGroupBuilder* builder)
|
||||
: 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) {
|
||||
mHeapSerial = serial;
|
||||
|
||||
const auto* bgl = ToBackend(GetLayout());
|
||||
|
@ -43,34 +46,36 @@ namespace d3d12 {
|
|||
auto d3d12Device = mDevice->GetD3D12Device();
|
||||
for (uint32_t binding : IterateBitSet(layout.mask)) {
|
||||
switch (layout.types[binding]) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
{
|
||||
case nxt::BindingType::UniformBuffer: {
|
||||
auto* view = ToBackend(GetBindingAsBufferView(binding));
|
||||
auto& cbv = view->GetCBVDescriptor();
|
||||
d3d12Device->CreateConstantBufferView(&cbv, cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset + bindingOffsets[binding]));
|
||||
}
|
||||
break;
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
{
|
||||
d3d12Device->CreateConstantBufferView(
|
||||
&cbv, cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset +
|
||||
bindingOffsets[binding]));
|
||||
} break;
|
||||
case nxt::BindingType::StorageBuffer: {
|
||||
auto* view = ToBackend(GetBindingAsBufferView(binding));
|
||||
auto& uav = view->GetUAVDescriptor();
|
||||
d3d12Device->CreateUnorderedAccessView(ToBackend(view->GetBuffer())->GetD3D12Resource().Get(), nullptr, &uav, cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset + bindingOffsets[binding]));
|
||||
}
|
||||
break;
|
||||
case nxt::BindingType::SampledTexture:
|
||||
{
|
||||
d3d12Device->CreateUnorderedAccessView(
|
||||
ToBackend(view->GetBuffer())->GetD3D12Resource().Get(), nullptr, &uav,
|
||||
cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset +
|
||||
bindingOffsets[binding]));
|
||||
} break;
|
||||
case nxt::BindingType::SampledTexture: {
|
||||
auto* view = ToBackend(GetBindingAsTextureView(binding));
|
||||
auto& srv = view->GetSRVDescriptor();
|
||||
d3d12Device->CreateShaderResourceView(ToBackend(view->GetTexture())->GetD3D12Resource(), &srv, cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset + bindingOffsets[binding]));
|
||||
}
|
||||
break;
|
||||
case nxt::BindingType::Sampler:
|
||||
{
|
||||
d3d12Device->CreateShaderResourceView(
|
||||
ToBackend(view->GetTexture())->GetD3D12Resource(), &srv,
|
||||
cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset +
|
||||
bindingOffsets[binding]));
|
||||
} break;
|
||||
case nxt::BindingType::Sampler: {
|
||||
auto* sampler = ToBackend(GetBindingAsSampler(binding));
|
||||
auto& samplerDesc = sampler->GetSamplerDescriptor();
|
||||
d3d12Device->CreateSampler(&samplerDesc, samplerHeapStart.GetCPUHandle(*samplerHeapOffset + bindingOffsets[binding]));
|
||||
}
|
||||
break;
|
||||
d3d12Device->CreateSampler(
|
||||
&samplerDesc, samplerHeapStart.GetCPUHandle(*samplerHeapOffset +
|
||||
bindingOffsets[binding]));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,5 +96,4 @@ namespace d3d12 {
|
|||
return mHeapSerial;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
|
||||
#include "backend/d3d12/DescriptorHeapAllocator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -30,7 +29,11 @@ namespace d3d12 {
|
|||
public:
|
||||
BindGroup(Device* device, BindGroupBuilder* builder);
|
||||
|
||||
void RecordDescriptors(const DescriptorHeapHandle &cbvSrvUavHeapStart, uint32_t* cbvUavSrvHeapOffset, const DescriptorHeapHandle &samplerHeapStart, uint32_t* samplerHeapOffset, uint64_t serial);
|
||||
void RecordDescriptors(const DescriptorHeapHandle& cbvSrvUavHeapStart,
|
||||
uint32_t* cbvUavSrvHeapOffset,
|
||||
const DescriptorHeapHandle& samplerHeapStart,
|
||||
uint32_t* samplerHeapOffset,
|
||||
uint64_t serial);
|
||||
uint32_t GetCbvUavSrvHeapOffset() const;
|
||||
uint32_t GetSamplerHeapOffset() const;
|
||||
uint64_t GetHeapSerial() const;
|
||||
|
@ -44,7 +47,6 @@ namespace d3d12 {
|
|||
uint64_t mHeapSerial = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_BINDGROUPD3D12_H_
|
||||
|
|
|
@ -14,15 +14,13 @@
|
|||
|
||||
#include "backend/d3d12/BindGroupLayoutD3D12.h"
|
||||
|
||||
#include "common/BitSetIterator.h"
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "common/BitSetIterator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
BindGroupLayout::BindGroupLayout(Device* device, BindGroupLayoutBuilder* builder)
|
||||
: BindGroupLayoutBase(builder), mDevice(device), mDescriptorCounts {} {
|
||||
|
||||
: BindGroupLayoutBase(builder), mDevice(device), mDescriptorCounts{} {
|
||||
const auto& groupInfo = GetBindingInfo();
|
||||
|
||||
for (uint32_t binding : IterateBitSet(groupInfo.mask)) {
|
||||
|
@ -42,7 +40,8 @@ namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
auto SetDescriptorRange = [&](uint32_t index, uint32_t count, D3D12_DESCRIPTOR_RANGE_TYPE type) -> bool {
|
||||
auto SetDescriptorRange = [&](uint32_t index, uint32_t count,
|
||||
D3D12_DESCRIPTOR_RANGE_TYPE type) -> bool {
|
||||
if (count == 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -52,7 +51,8 @@ namespace d3d12 {
|
|||
range.NumDescriptors = count;
|
||||
range.RegisterSpace = 0;
|
||||
range.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
|
||||
// These ranges will be copied and range.BaseShaderRegister will be set in d3d12::PipelineLayout to account for bind group register offsets
|
||||
// These ranges will be copied and range.BaseShaderRegister will be set in
|
||||
// d3d12::PipelineLayout to account for bind group register offsets
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -60,16 +60,20 @@ namespace d3d12 {
|
|||
|
||||
// Ranges 0-2 contain the CBV, UAV, and SRV ranges, if they exist, tightly packed
|
||||
// Range 3 contains the Sampler range, if there is one
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[CBV], D3D12_DESCRIPTOR_RANGE_TYPE_CBV)) {
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[CBV],
|
||||
D3D12_DESCRIPTOR_RANGE_TYPE_CBV)) {
|
||||
rangeIndex++;
|
||||
}
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[UAV], D3D12_DESCRIPTOR_RANGE_TYPE_UAV)) {
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[UAV],
|
||||
D3D12_DESCRIPTOR_RANGE_TYPE_UAV)) {
|
||||
rangeIndex++;
|
||||
}
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[SRV], D3D12_DESCRIPTOR_RANGE_TYPE_SRV)) {
|
||||
if (SetDescriptorRange(rangeIndex, mDescriptorCounts[SRV],
|
||||
D3D12_DESCRIPTOR_RANGE_TYPE_SRV)) {
|
||||
rangeIndex++;
|
||||
}
|
||||
SetDescriptorRange(Sampler, mDescriptorCounts[Sampler], D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER);
|
||||
SetDescriptorRange(Sampler, mDescriptorCounts[Sampler],
|
||||
D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER);
|
||||
|
||||
// descriptors ranges are offset by the offset + size of the previous range
|
||||
std::array<uint32_t, DescriptorType::Count> descriptorOffsets;
|
||||
|
@ -101,11 +105,9 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
uint32_t BindGroupLayout::GetCbvUavSrvDescriptorTableSize() const {
|
||||
return (
|
||||
static_cast<uint32_t>(mDescriptorCounts[CBV] > 0) +
|
||||
return (static_cast<uint32_t>(mDescriptorCounts[CBV] > 0) +
|
||||
static_cast<uint32_t>(mDescriptorCounts[UAV] > 0) +
|
||||
static_cast<uint32_t>(mDescriptorCounts[SRV] > 0)
|
||||
);
|
||||
static_cast<uint32_t>(mDescriptorCounts[SRV] > 0));
|
||||
}
|
||||
|
||||
uint32_t BindGroupLayout::GetSamplerDescriptorTableSize() const {
|
||||
|
@ -128,5 +130,4 @@ namespace d3d12 {
|
|||
return &mRanges[Sampler];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -51,7 +50,6 @@ namespace d3d12 {
|
|||
D3D12_DESCRIPTOR_RANGE mRanges[DescriptorType::Count];
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_BINDGROUPLAYOUTD3D12_H_
|
||||
|
|
|
@ -17,12 +17,11 @@
|
|||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
namespace {
|
||||
D3D12_BLEND D3D12Blend(nxt::BlendFactor factor) {
|
||||
switch(factor) {
|
||||
switch (factor) {
|
||||
case nxt::BlendFactor::Zero:
|
||||
return D3D12_BLEND_ZERO;
|
||||
case nxt::BlendFactor::One:
|
||||
|
@ -55,7 +54,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
D3D12_BLEND_OP D3D12BlendOperation(nxt::BlendOperation operation) {
|
||||
switch(operation) {
|
||||
switch (operation) {
|
||||
case nxt::BlendOperation::Add:
|
||||
return D3D12_BLEND_OP_ADD;
|
||||
case nxt::BlendOperation::Subtract:
|
||||
|
@ -72,13 +71,21 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
uint8_t D3D12RenderTargetWriteMask(nxt::ColorWriteMask colorWriteMask) {
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Red) == D3D12_COLOR_WRITE_ENABLE_RED, "ColorWriteMask values must match");
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Green) == D3D12_COLOR_WRITE_ENABLE_GREEN, "ColorWriteMask values must match");
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Blue) == D3D12_COLOR_WRITE_ENABLE_BLUE, "ColorWriteMask values must match");
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Alpha) == D3D12_COLOR_WRITE_ENABLE_ALPHA, "ColorWriteMask values must match");
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Red) ==
|
||||
D3D12_COLOR_WRITE_ENABLE_RED,
|
||||
"ColorWriteMask values must match");
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Green) ==
|
||||
D3D12_COLOR_WRITE_ENABLE_GREEN,
|
||||
"ColorWriteMask values must match");
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Blue) ==
|
||||
D3D12_COLOR_WRITE_ENABLE_BLUE,
|
||||
"ColorWriteMask values must match");
|
||||
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Alpha) ==
|
||||
D3D12_COLOR_WRITE_ENABLE_ALPHA,
|
||||
"ColorWriteMask values must match");
|
||||
return static_cast<uint8_t>(colorWriteMask);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
BlendState::BlendState(BlendStateBuilder* builder) : BlendStateBase(builder) {
|
||||
auto& info = GetBlendInfo();
|
||||
|
@ -98,5 +105,4 @@ namespace d3d12 {
|
|||
return mBlendDesc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class BlendState : public BlendStateBase {
|
||||
public:
|
||||
|
@ -32,7 +31,6 @@ namespace d3d12 {
|
|||
D3D12_RENDER_TARGET_BLEND_DESC mBlendDesc;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_BLENDSTATED3D12_H_
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
#include "common/Constants.h"
|
||||
#include "common/Math.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
namespace {
|
||||
D3D12_RESOURCE_FLAGS D3D12ResourceFlags(nxt::BufferUsageBit usage) {
|
||||
|
@ -66,11 +65,9 @@ namespace d3d12 {
|
|||
return D3D12_HEAP_TYPE_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::Buffer(Device* device, BufferBuilder* builder)
|
||||
: BufferBase(builder), mDevice(device) {
|
||||
} // namespace
|
||||
|
||||
Buffer::Buffer(Device* device, BufferBuilder* builder) : BufferBase(builder), mDevice(device) {
|
||||
D3D12_RESOURCE_DESC resourceDescriptor;
|
||||
resourceDescriptor.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
resourceDescriptor.Alignment = 0;
|
||||
|
@ -87,17 +84,20 @@ namespace d3d12 {
|
|||
auto heapType = D3D12HeapType(GetAllowedUsage());
|
||||
auto bufferUsage = D3D12BufferUsage(GetUsage());
|
||||
|
||||
// D3D12 requires buffers on the READBACK heap to have the D3D12_RESOURCE_STATE_COPY_DEST state
|
||||
// D3D12 requires buffers on the READBACK heap to have the D3D12_RESOURCE_STATE_COPY_DEST
|
||||
// state
|
||||
if (heapType == D3D12_HEAP_TYPE_READBACK) {
|
||||
bufferUsage |= D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
}
|
||||
|
||||
// D3D12 requires buffers on the UPLOAD heap to have the D3D12_RESOURCE_STATE_GENERIC_READ state
|
||||
// D3D12 requires buffers on the UPLOAD heap to have the D3D12_RESOURCE_STATE_GENERIC_READ
|
||||
// state
|
||||
if (heapType == D3D12_HEAP_TYPE_UPLOAD) {
|
||||
bufferUsage |= D3D12_RESOURCE_STATE_GENERIC_READ;
|
||||
}
|
||||
|
||||
mResource = device->GetResourceAllocator()->Allocate(heapType, resourceDescriptor, bufferUsage);
|
||||
mResource =
|
||||
device->GetResourceAllocator()->Allocate(heapType, resourceDescriptor, bufferUsage);
|
||||
}
|
||||
|
||||
Buffer::~Buffer() {
|
||||
|
@ -113,10 +113,13 @@ namespace d3d12 {
|
|||
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) {
|
||||
if (GetAllowedUsage() & (nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::MapWrite)) {
|
||||
// Transitions are never needed for mapped buffers because they are created with and always need the Transfer(Dst|Src) state.
|
||||
// Mapped buffers cannot have states outside of (MapRead|TransferDst) and (MapWrite|TransferSrc)
|
||||
// Transitions are never needed for mapped buffers because they are created with and
|
||||
// always need the Transfer(Dst|Src) state. Mapped buffers cannot have states outside of
|
||||
// (MapRead|TransferDst) and (MapWrite|TransferSrc)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -146,11 +149,12 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
||||
mDevice->GetResourceUploader()->BufferSubData(mResource, start * sizeof(uint32_t), count * sizeof(uint32_t), data);
|
||||
mDevice->GetResourceUploader()->BufferSubData(mResource, start * sizeof(uint32_t),
|
||||
count * sizeof(uint32_t), data);
|
||||
}
|
||||
|
||||
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
|
||||
D3D12_RANGE readRange = { start, start + count };
|
||||
D3D12_RANGE readRange = {start, start + count};
|
||||
char* data = nullptr;
|
||||
ASSERT_SUCCESS(mResource->Map(0, &readRange, reinterpret_cast<void**>(&data)));
|
||||
|
||||
|
@ -159,22 +163,22 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
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 = {};
|
||||
mResource->Unmap(0, &writeRange);
|
||||
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;
|
||||
if (GetResourceTransitionBarrier(currentUsage, targetUsage, &barrier)) {
|
||||
mDevice->GetPendingCommandList()->ResourceBarrier(1, &barrier);
|
||||
}
|
||||
}
|
||||
|
||||
BufferView::BufferView(BufferViewBuilder* builder)
|
||||
: BufferViewBase(builder) {
|
||||
|
||||
BufferView::BufferView(BufferViewBuilder* builder) : BufferViewBase(builder) {
|
||||
mCbvDesc.BufferLocation = ToBackend(GetBuffer())->GetVA() + GetOffset();
|
||||
mCbvDesc.SizeInBytes = GetD3D12Size();
|
||||
|
||||
|
@ -200,8 +204,7 @@ namespace d3d12 {
|
|||
return mUavDesc;
|
||||
}
|
||||
|
||||
MapReadRequestTracker::MapReadRequestTracker(Device* device)
|
||||
: mDevice(device) {
|
||||
MapReadRequestTracker::MapReadRequestTracker(Device* device) : mDevice(device) {
|
||||
}
|
||||
|
||||
MapReadRequestTracker::~MapReadRequestTracker() {
|
||||
|
@ -224,5 +227,4 @@ namespace d3d12 {
|
|||
mInflightRequests.ClearUpTo(finishedSerial);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -33,7 +32,9 @@ namespace d3d12 {
|
|||
uint32_t GetD3D12Size() const;
|
||||
ComPtr<ID3D12Resource> GetD3D12Resource();
|
||||
D3D12_GPU_VIRTUAL_ADDRESS GetVA() const;
|
||||
bool GetResourceTransitionBarrier(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage, D3D12_RESOURCE_BARRIER* barrier);
|
||||
bool GetResourceTransitionBarrier(nxt::BufferUsageBit currentUsage,
|
||||
nxt::BufferUsageBit targetUsage,
|
||||
D3D12_RESOURCE_BARRIER* barrier);
|
||||
void OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data);
|
||||
|
||||
private:
|
||||
|
@ -44,8 +45,8 @@ namespace d3d12 {
|
|||
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
|
||||
void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) override;
|
||||
void UnmapImpl() override;
|
||||
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) override;
|
||||
|
||||
void TransitionUsageImpl(nxt::BufferUsageBit currentUsage,
|
||||
nxt::BufferUsageBit targetUsage) override;
|
||||
};
|
||||
|
||||
class BufferView : public BufferViewBase {
|
||||
|
@ -80,7 +81,6 @@ namespace d3d12 {
|
|||
SerialQueue<Request> mInflightRequests;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_BUFFERD3D12_H_
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
#include "common/Assert.h"
|
||||
#include "common/BitSetIterator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
CommandAllocatorManager::CommandAllocatorManager(Device* device) : device(device), mAllocatorCount(0) {
|
||||
CommandAllocatorManager::CommandAllocatorManager(Device* device)
|
||||
: device(device), mAllocatorCount(0) {
|
||||
mFreeAllocators.set();
|
||||
}
|
||||
|
||||
|
@ -42,14 +42,17 @@ namespace d3d12 {
|
|||
if (firstFreeIndex >= mAllocatorCount) {
|
||||
ASSERT(firstFreeIndex == mAllocatorCount);
|
||||
mAllocatorCount++;
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&mCommandAllocators[firstFreeIndex])));
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateCommandAllocator(
|
||||
D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&mCommandAllocators[firstFreeIndex])));
|
||||
}
|
||||
|
||||
// Mark the command allocator as used
|
||||
mFreeAllocators.reset(firstFreeIndex);
|
||||
|
||||
// Enqueue the command allocator. It will be scheduled for reset after the next ExecuteCommandLists
|
||||
mInFlightCommandAllocators.Enqueue({mCommandAllocators[firstFreeIndex], firstFreeIndex}, device->GetSerial());
|
||||
// Enqueue the command allocator. It will be scheduled for reset after the next
|
||||
// ExecuteCommandLists
|
||||
mInFlightCommandAllocators.Enqueue({mCommandAllocators[firstFreeIndex], firstFreeIndex},
|
||||
device->GetSerial());
|
||||
|
||||
return mCommandAllocators[firstFreeIndex];
|
||||
}
|
||||
|
@ -63,5 +66,4 @@ namespace d3d12 {
|
|||
mInFlightCommandAllocators.ClearUpTo(lastCompletedSerial);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
|
||||
#include <bitset>
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -52,7 +51,6 @@ namespace d3d12 {
|
|||
SerialQueue<IndexedCommandAllocator> mInFlightCommandAllocators;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_COMMANDALLOCATORMANAGER_H_
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
#include "backend/d3d12/CommandBufferD3D12.h"
|
||||
|
||||
#include "backend/Commands.h"
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/BindGroupD3D12.h"
|
||||
#include "backend/d3d12/BindGroupLayoutD3D12.h"
|
||||
#include "backend/d3d12/BufferD3D12.h"
|
||||
#include "backend/d3d12/ComputePipelineD3D12.h"
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/DescriptorHeapAllocator.h"
|
||||
#include "backend/d3d12/FramebufferD3D12.h"
|
||||
#include "backend/d3d12/InputStateD3D12.h"
|
||||
|
@ -31,8 +31,7 @@
|
|||
#include "backend/d3d12/TextureD3D12.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
namespace {
|
||||
DXGI_FORMAT DXGIIndexFormat(nxt::IndexFormat format) {
|
||||
|
@ -69,10 +68,13 @@ namespace d3d12 {
|
|||
if (bindGroups[index] != group) {
|
||||
bindGroups[index] = group;
|
||||
|
||||
// Descriptors don't need to be recorded if they have already been recorded in the heap. Indices are only updated when descriptors are recorded
|
||||
// Descriptors don't need to be recorded if they have already been recorded in
|
||||
// the heap. Indices are only updated when descriptors are recorded
|
||||
const uint64_t serial = device->GetSerial();
|
||||
if (group->GetHeapSerial() != serial) {
|
||||
group->RecordDescriptors(cbvSrvUavCPUDescriptorHeap, &cbvSrvUavDescriptorIndex, samplerCPUDescriptorHeap, &samplerDescriptorIndex, serial);
|
||||
group->RecordDescriptors(
|
||||
cbvSrvUavCPUDescriptorHeap, &cbvSrvUavDescriptorIndex,
|
||||
samplerCPUDescriptorHeap, &samplerDescriptorIndex, serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,37 +90,54 @@ namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
void SetBindGroup(ComPtr<ID3D12GraphicsCommandList> commandList, PipelineLayout* pipelineLayout, BindGroup* group,
|
||||
uint32_t index, bool force = false) {
|
||||
void SetBindGroup(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
PipelineLayout* pipelineLayout,
|
||||
BindGroup* group,
|
||||
uint32_t index,
|
||||
bool force = false) {
|
||||
if (bindGroups[index] != group || force) {
|
||||
bindGroups[index] = group;
|
||||
|
||||
uint32_t cbvUavSrvCount = ToBackend(group->GetLayout())->GetCbvUavSrvDescriptorCount();
|
||||
uint32_t samplerCount = ToBackend(group->GetLayout())->GetSamplerDescriptorCount();
|
||||
uint32_t cbvUavSrvCount =
|
||||
ToBackend(group->GetLayout())->GetCbvUavSrvDescriptorCount();
|
||||
uint32_t samplerCount =
|
||||
ToBackend(group->GetLayout())->GetSamplerDescriptorCount();
|
||||
|
||||
if (cbvUavSrvCount > 0) {
|
||||
uint32_t parameterIndex = pipelineLayout->GetCbvUavSrvRootParameterIndex(index);
|
||||
uint32_t parameterIndex =
|
||||
pipelineLayout->GetCbvUavSrvRootParameterIndex(index);
|
||||
|
||||
if (inCompute) {
|
||||
commandList->SetComputeRootDescriptorTable(parameterIndex, cbvSrvUavGPUDescriptorHeap.GetGPUHandle(group->GetCbvUavSrvHeapOffset()));
|
||||
commandList->SetComputeRootDescriptorTable(
|
||||
parameterIndex, cbvSrvUavGPUDescriptorHeap.GetGPUHandle(
|
||||
group->GetCbvUavSrvHeapOffset()));
|
||||
} else {
|
||||
commandList->SetGraphicsRootDescriptorTable(parameterIndex, cbvSrvUavGPUDescriptorHeap.GetGPUHandle(group->GetCbvUavSrvHeapOffset()));
|
||||
commandList->SetGraphicsRootDescriptorTable(
|
||||
parameterIndex, cbvSrvUavGPUDescriptorHeap.GetGPUHandle(
|
||||
group->GetCbvUavSrvHeapOffset()));
|
||||
}
|
||||
}
|
||||
|
||||
if (samplerCount > 0) {
|
||||
uint32_t parameterIndex = pipelineLayout->GetSamplerRootParameterIndex(index);
|
||||
uint32_t parameterIndex =
|
||||
pipelineLayout->GetSamplerRootParameterIndex(index);
|
||||
|
||||
if (inCompute) {
|
||||
commandList->SetComputeRootDescriptorTable(parameterIndex, samplerGPUDescriptorHeap.GetGPUHandle(group->GetSamplerHeapOffset()));
|
||||
commandList->SetComputeRootDescriptorTable(
|
||||
parameterIndex, samplerGPUDescriptorHeap.GetGPUHandle(
|
||||
group->GetSamplerHeapOffset()));
|
||||
} else {
|
||||
commandList->SetGraphicsRootDescriptorTable(parameterIndex, samplerGPUDescriptorHeap.GetGPUHandle(group->GetSamplerHeapOffset()));
|
||||
commandList->SetGraphicsRootDescriptorTable(
|
||||
parameterIndex, samplerGPUDescriptorHeap.GetGPUHandle(
|
||||
group->GetSamplerHeapOffset()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetInheritedBindGroups(ComPtr<ID3D12GraphicsCommandList> commandList, PipelineLayout* oldLayout, PipelineLayout* newLayout) {
|
||||
void SetInheritedBindGroups(ComPtr<ID3D12GraphicsCommandList> commandList,
|
||||
PipelineLayout* oldLayout,
|
||||
PipelineLayout* newLayout) {
|
||||
if (oldLayout == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
@ -136,13 +155,17 @@ namespace d3d12 {
|
|||
}
|
||||
};
|
||||
|
||||
void AllocateAndSetDescriptorHeaps(Device* device, BindGroupStateTracker* bindingTracker, CommandIterator* commands) {
|
||||
void AllocateAndSetDescriptorHeaps(Device* device,
|
||||
BindGroupStateTracker* bindingTracker,
|
||||
CommandIterator* commands) {
|
||||
auto* descriptorHeapAllocator = device->GetDescriptorHeapAllocator();
|
||||
|
||||
// TODO(enga@google.com): This currently allocates CPU heaps of arbitrarily chosen sizes
|
||||
// This will not work if there are too many descriptors
|
||||
bindingTracker->cbvSrvUavCPUDescriptorHeap = descriptorHeapAllocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 8192);
|
||||
bindingTracker->samplerCPUDescriptorHeap = descriptorHeapAllocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, 2048);
|
||||
bindingTracker->cbvSrvUavCPUDescriptorHeap = descriptorHeapAllocator->AllocateCPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 8192);
|
||||
bindingTracker->samplerCPUDescriptorHeap =
|
||||
descriptorHeapAllocator->AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, 2048);
|
||||
|
||||
{
|
||||
Command type;
|
||||
|
@ -150,31 +173,27 @@ namespace d3d12 {
|
|||
|
||||
while (commands->NextCommandId(&type)) {
|
||||
switch (type) {
|
||||
case Command::SetComputePipeline:
|
||||
{
|
||||
SetComputePipelineCmd* cmd = commands->NextCommand<SetComputePipelineCmd>();
|
||||
case Command::SetComputePipeline: {
|
||||
SetComputePipelineCmd* cmd =
|
||||
commands->NextCommand<SetComputePipelineCmd>();
|
||||
PipelineLayout* layout = ToBackend(cmd->pipeline->GetLayout());
|
||||
bindingTracker->TrackInheritedGroups(lastLayout, layout);
|
||||
lastLayout = layout;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetRenderPipeline:
|
||||
{
|
||||
SetRenderPipelineCmd* cmd = commands->NextCommand<SetRenderPipelineCmd>();
|
||||
case Command::SetRenderPipeline: {
|
||||
SetRenderPipelineCmd* cmd =
|
||||
commands->NextCommand<SetRenderPipelineCmd>();
|
||||
PipelineLayout* layout = ToBackend(cmd->pipeline->GetLayout());
|
||||
bindingTracker->TrackInheritedGroups(lastLayout, layout);
|
||||
lastLayout = layout;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetBindGroup:
|
||||
{
|
||||
case Command::SetBindGroup: {
|
||||
SetBindGroupCmd* cmd = commands->NextCommand<SetBindGroupCmd>();
|
||||
BindGroup* group = ToBackend(cmd->group.Get());
|
||||
bindingTracker->TrackSetBindGroup(group, cmd->index);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
SkipCommand(commands, type);
|
||||
}
|
||||
|
@ -184,8 +203,12 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
if (bindingTracker->cbvSrvUavDescriptorIndex > 0) {
|
||||
// Allocate a GPU-visible heap and copy from the CPU-only heap to the GPU-visible heap
|
||||
bindingTracker->cbvSrvUavGPUDescriptorHeap = descriptorHeapAllocator->AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, bindingTracker->cbvSrvUavDescriptorIndex);
|
||||
// Allocate a GPU-visible heap and copy from the CPU-only heap to the GPU-visible
|
||||
// heap
|
||||
bindingTracker->cbvSrvUavGPUDescriptorHeap =
|
||||
descriptorHeapAllocator->AllocateGPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV,
|
||||
bindingTracker->cbvSrvUavDescriptorIndex);
|
||||
device->GetD3D12Device()->CopyDescriptorsSimple(
|
||||
bindingTracker->cbvSrvUavDescriptorIndex,
|
||||
bindingTracker->cbvSrvUavGPUDescriptorHeap.GetCPUHandle(0),
|
||||
|
@ -194,7 +217,8 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
if (bindingTracker->samplerDescriptorIndex > 0) {
|
||||
bindingTracker->samplerGPUDescriptorHeap = descriptorHeapAllocator->AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, bindingTracker->samplerDescriptorIndex);
|
||||
bindingTracker->samplerGPUDescriptorHeap = descriptorHeapAllocator->AllocateGPUHeap(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, bindingTracker->samplerDescriptorIndex);
|
||||
device->GetD3D12Device()->CopyDescriptorsSimple(
|
||||
bindingTracker->samplerDescriptorIndex,
|
||||
bindingTracker->samplerGPUDescriptorHeap.GetCPUHandle(0),
|
||||
|
@ -202,7 +226,7 @@ namespace d3d12 {
|
|||
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CommandBuffer::CommandBuffer(Device* device, CommandBufferBuilder* builder)
|
||||
: CommandBufferBase(builder), mDevice(device), mCommands(builder->AcquireCommands()) {
|
||||
|
@ -217,7 +241,8 @@ namespace d3d12 {
|
|||
AllocateAndSetDescriptorHeaps(mDevice, &bindingTracker, &mCommands);
|
||||
bindingTracker.Reset();
|
||||
|
||||
ID3D12DescriptorHeap* descriptorHeaps[2] = { bindingTracker.cbvSrvUavGPUDescriptorHeap.Get(), bindingTracker.samplerGPUDescriptorHeap.Get() };
|
||||
ID3D12DescriptorHeap* descriptorHeaps[2] = {bindingTracker.cbvSrvUavGPUDescriptorHeap.Get(),
|
||||
bindingTracker.samplerGPUDescriptorHeap.Get()};
|
||||
if (descriptorHeaps[0] && descriptorHeaps[1]) {
|
||||
commandList->SetDescriptorHeaps(2, descriptorHeaps);
|
||||
} else if (descriptorHeaps[0]) {
|
||||
|
@ -234,52 +259,56 @@ namespace d3d12 {
|
|||
Framebuffer* currentFramebuffer = nullptr;
|
||||
uint32_t currentSubpass = 0;
|
||||
|
||||
while(mCommands.NextCommandId(&type)) {
|
||||
while (mCommands.NextCommandId(&type)) {
|
||||
switch (type) {
|
||||
case Command::BeginComputePass:
|
||||
{
|
||||
case Command::BeginComputePass: {
|
||||
mCommands.NextCommand<BeginComputePassCmd>();
|
||||
bindingTracker.SetInComputePass(true);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::BeginRenderPass:
|
||||
{
|
||||
BeginRenderPassCmd* beginRenderPassCmd = mCommands.NextCommand<BeginRenderPassCmd>();
|
||||
case Command::BeginRenderPass: {
|
||||
BeginRenderPassCmd* beginRenderPassCmd =
|
||||
mCommands.NextCommand<BeginRenderPassCmd>();
|
||||
currentRenderPass = ToBackend(beginRenderPassCmd->renderPass.Get());
|
||||
currentFramebuffer = ToBackend(beginRenderPassCmd->framebuffer.Get());
|
||||
currentSubpass = 0;
|
||||
|
||||
uint32_t width = currentFramebuffer->GetWidth();
|
||||
uint32_t height = currentFramebuffer->GetHeight();
|
||||
D3D12_VIEWPORT viewport = { 0.f, 0.f, static_cast<float>(width), static_cast<float>(height), 0.f, 1.f };
|
||||
D3D12_RECT scissorRect = { 0, 0, static_cast<long>(width), static_cast<long>(height) };
|
||||
D3D12_VIEWPORT viewport = {
|
||||
0.f, 0.f, static_cast<float>(width), static_cast<float>(height), 0.f, 1.f};
|
||||
D3D12_RECT scissorRect = {0, 0, static_cast<long>(width),
|
||||
static_cast<long>(height)};
|
||||
commandList->RSSetViewports(1, &viewport);
|
||||
commandList->RSSetScissorRects(1, &scissorRect);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::BeginRenderSubpass:
|
||||
{
|
||||
case Command::BeginRenderSubpass: {
|
||||
mCommands.NextCommand<BeginRenderSubpassCmd>();
|
||||
const auto& subpass = currentRenderPass->GetSubpassInfo(currentSubpass);
|
||||
|
||||
Framebuffer::OMSetRenderTargetArgs args = currentFramebuffer->GetSubpassOMSetRenderTargetArgs(currentSubpass);
|
||||
Framebuffer::OMSetRenderTargetArgs args =
|
||||
currentFramebuffer->GetSubpassOMSetRenderTargetArgs(currentSubpass);
|
||||
if (args.dsv.ptr) {
|
||||
commandList->OMSetRenderTargets(args.numRTVs, args.RTVs.data(), FALSE, &args.dsv);
|
||||
commandList->OMSetRenderTargets(args.numRTVs, args.RTVs.data(), FALSE,
|
||||
&args.dsv);
|
||||
} else {
|
||||
commandList->OMSetRenderTargets(args.numRTVs, args.RTVs.data(), FALSE, nullptr);
|
||||
commandList->OMSetRenderTargets(args.numRTVs, args.RTVs.data(), FALSE,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
// Clear framebuffer attachments as needed
|
||||
|
||||
for (unsigned int location : IterateBitSet(subpass.colorAttachmentsSet)) {
|
||||
uint32_t attachmentSlot = subpass.colorAttachments[location];
|
||||
const auto& attachmentInfo = currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
||||
const auto& attachmentInfo =
|
||||
currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
||||
|
||||
Texture* texture = ToBackend(currentFramebuffer->GetTextureView(attachmentSlot)->GetTexture());
|
||||
Texture* texture = ToBackend(
|
||||
currentFramebuffer->GetTextureView(attachmentSlot)->GetTexture());
|
||||
constexpr auto usage = nxt::TextureUsageBit::OutputAttachment;
|
||||
// It's already validated that this texture is either frozen to the correct usage, or not frozen.
|
||||
// It's already validated that this texture is either frozen to the correct
|
||||
// usage, or not frozen.
|
||||
if (!texture->IsFrozen()) {
|
||||
texture->TransitionUsageImpl(texture->GetUsage(), usage);
|
||||
texture->UpdateUsageInternal(usage);
|
||||
|
@ -290,7 +319,8 @@ namespace d3d12 {
|
|||
// Load op - color
|
||||
if (attachmentInfo.colorLoadOp == nxt::LoadOp::Clear) {
|
||||
auto handle = currentFramebuffer->GetRTVDescriptor(attachmentSlot);
|
||||
const auto& clear = currentFramebuffer->GetClearColor(attachmentSlot);
|
||||
const auto& clear =
|
||||
currentFramebuffer->GetClearColor(attachmentSlot);
|
||||
commandList->ClearRenderTargetView(handle, clear.color, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -298,14 +328,16 @@ namespace d3d12 {
|
|||
|
||||
if (subpass.depthStencilAttachmentSet) {
|
||||
uint32_t attachmentSlot = subpass.depthStencilAttachment;
|
||||
const auto& attachmentInfo = currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
||||
const auto& attachmentInfo =
|
||||
currentRenderPass->GetAttachmentInfo(attachmentSlot);
|
||||
|
||||
// Only perform load op on first use
|
||||
if (attachmentInfo.firstSubpass == currentSubpass) {
|
||||
// Load op - depth/stencil
|
||||
bool doDepthClear = TextureFormatHasDepth(attachmentInfo.format) &&
|
||||
(attachmentInfo.depthLoadOp == nxt::LoadOp::Clear);
|
||||
bool doStencilClear = TextureFormatHasStencil(attachmentInfo.format) &&
|
||||
bool doStencilClear =
|
||||
TextureFormatHasStencil(attachmentInfo.format) &&
|
||||
(attachmentInfo.stencilLoadOp == nxt::LoadOp::Clear);
|
||||
|
||||
D3D12_CLEAR_FLAGS clearFlags = {};
|
||||
|
@ -317,45 +349,39 @@ namespace d3d12 {
|
|||
}
|
||||
if (clearFlags) {
|
||||
auto handle = currentFramebuffer->GetDSVDescriptor(attachmentSlot);
|
||||
const auto& clear = currentFramebuffer->GetClearDepthStencil(attachmentSlot);
|
||||
// TODO(kainino@chromium.org): investigate: should the NXT clear stencil type be uint8_t?
|
||||
const auto& clear =
|
||||
currentFramebuffer->GetClearDepthStencil(attachmentSlot);
|
||||
// TODO(kainino@chromium.org): investigate: should the NXT clear
|
||||
// stencil type be uint8_t?
|
||||
uint8_t clearStencil = static_cast<uint8_t>(clear.stencil);
|
||||
commandList->ClearDepthStencilView(handle, clearFlags, clear.depth, clearStencil, 0, nullptr);
|
||||
commandList->ClearDepthStencilView(handle, clearFlags, clear.depth,
|
||||
clearStencil, 0, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr std::array<float, 4> defaultBlendFactor = { 0, 0, 0, 0 };
|
||||
static constexpr std::array<float, 4> defaultBlendFactor = {0, 0, 0, 0};
|
||||
commandList->OMSetBlendFactor(&defaultBlendFactor[0]);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::CopyBufferToBuffer:
|
||||
{
|
||||
case Command::CopyBufferToBuffer: {
|
||||
CopyBufferToBufferCmd* copy = mCommands.NextCommand<CopyBufferToBufferCmd>();
|
||||
auto src = ToBackend(copy->source.buffer.Get())->GetD3D12Resource();
|
||||
auto dst = ToBackend(copy->destination.buffer.Get())->GetD3D12Resource();
|
||||
commandList->CopyBufferRegion(dst.Get(), copy->destination.offset, src.Get(), copy->source.offset, copy->size);
|
||||
}
|
||||
break;
|
||||
commandList->CopyBufferRegion(dst.Get(), copy->destination.offset, src.Get(),
|
||||
copy->source.offset, copy->size);
|
||||
} break;
|
||||
|
||||
case Command::CopyBufferToTexture:
|
||||
{
|
||||
case Command::CopyBufferToTexture: {
|
||||
CopyBufferToTextureCmd* copy = mCommands.NextCommand<CopyBufferToTextureCmd>();
|
||||
Buffer* buffer = ToBackend(copy->source.buffer.Get());
|
||||
Texture* texture = ToBackend(copy->destination.texture.Get());
|
||||
|
||||
auto copySplit = ComputeTextureCopySplit(
|
||||
copy->destination.x,
|
||||
copy->destination.y,
|
||||
copy->destination.z,
|
||||
copy->destination.width,
|
||||
copy->destination.height,
|
||||
copy->destination.depth,
|
||||
copy->destination.x, copy->destination.y, copy->destination.z,
|
||||
copy->destination.width, copy->destination.height, copy->destination.depth,
|
||||
static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat())),
|
||||
copy->source.offset,
|
||||
copy->rowPitch
|
||||
);
|
||||
copy->source.offset, copy->rowPitch);
|
||||
|
||||
D3D12_TEXTURE_COPY_LOCATION textureLocation;
|
||||
textureLocation.pResource = texture->GetD3D12Resource();
|
||||
|
@ -383,28 +409,22 @@ namespace d3d12 {
|
|||
sourceRegion.bottom = info.bufferOffset.y + info.copySize.height;
|
||||
sourceRegion.back = info.bufferOffset.z + info.copySize.depth;
|
||||
|
||||
commandList->CopyTextureRegion(&textureLocation, info.textureOffset.x, info.textureOffset.y, info.textureOffset.z, &bufferLocation, &sourceRegion);
|
||||
commandList->CopyTextureRegion(&textureLocation, info.textureOffset.x,
|
||||
info.textureOffset.y, info.textureOffset.z,
|
||||
&bufferLocation, &sourceRegion);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::CopyTextureToBuffer:
|
||||
{
|
||||
case Command::CopyTextureToBuffer: {
|
||||
CopyTextureToBufferCmd* copy = mCommands.NextCommand<CopyTextureToBufferCmd>();
|
||||
Texture* texture = ToBackend(copy->source.texture.Get());
|
||||
Buffer* buffer = ToBackend(copy->destination.buffer.Get());
|
||||
|
||||
auto copySplit = ComputeTextureCopySplit(
|
||||
copy->source.x,
|
||||
copy->source.y,
|
||||
copy->source.z,
|
||||
copy->source.width,
|
||||
copy->source.height,
|
||||
copy->source.depth,
|
||||
copy->source.x, copy->source.y, copy->source.z, copy->source.width,
|
||||
copy->source.height, copy->source.depth,
|
||||
static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat())),
|
||||
copy->destination.offset,
|
||||
copy->rowPitch
|
||||
);
|
||||
copy->destination.offset, copy->rowPitch);
|
||||
|
||||
D3D12_TEXTURE_COPY_LOCATION textureLocation;
|
||||
textureLocation.pResource = texture->GetD3D12Resource();
|
||||
|
@ -432,66 +452,45 @@ namespace d3d12 {
|
|||
sourceRegion.bottom = info.textureOffset.y + info.copySize.height;
|
||||
sourceRegion.back = info.textureOffset.z + info.copySize.depth;
|
||||
|
||||
commandList->CopyTextureRegion(&bufferLocation, info.bufferOffset.x, info.bufferOffset.y, info.bufferOffset.z, &textureLocation, &sourceRegion);
|
||||
commandList->CopyTextureRegion(&bufferLocation, info.bufferOffset.x,
|
||||
info.bufferOffset.y, info.bufferOffset.z,
|
||||
&textureLocation, &sourceRegion);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::Dispatch:
|
||||
{
|
||||
case Command::Dispatch: {
|
||||
DispatchCmd* dispatch = mCommands.NextCommand<DispatchCmd>();
|
||||
commandList->Dispatch(dispatch->x, dispatch->y, dispatch->z);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::DrawArrays:
|
||||
{
|
||||
case Command::DrawArrays: {
|
||||
DrawArraysCmd* draw = mCommands.NextCommand<DrawArraysCmd>();
|
||||
commandList->DrawInstanced(
|
||||
draw->vertexCount,
|
||||
draw->instanceCount,
|
||||
draw->firstVertex,
|
||||
draw->firstInstance
|
||||
);
|
||||
}
|
||||
break;
|
||||
commandList->DrawInstanced(draw->vertexCount, draw->instanceCount,
|
||||
draw->firstVertex, draw->firstInstance);
|
||||
} break;
|
||||
|
||||
case Command::DrawElements:
|
||||
{
|
||||
case Command::DrawElements: {
|
||||
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
||||
|
||||
commandList->DrawIndexedInstanced(
|
||||
draw->indexCount,
|
||||
draw->instanceCount,
|
||||
draw->firstIndex,
|
||||
0,
|
||||
draw->firstInstance
|
||||
);
|
||||
}
|
||||
break;
|
||||
commandList->DrawIndexedInstanced(draw->indexCount, draw->instanceCount,
|
||||
draw->firstIndex, 0, draw->firstInstance);
|
||||
} break;
|
||||
|
||||
case Command::EndComputePass:
|
||||
{
|
||||
case Command::EndComputePass: {
|
||||
mCommands.NextCommand<EndComputePassCmd>();
|
||||
bindingTracker.SetInComputePass(false);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::EndRenderPass:
|
||||
{
|
||||
case Command::EndRenderPass: {
|
||||
mCommands.NextCommand<EndRenderPassCmd>();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::EndRenderSubpass:
|
||||
{
|
||||
case Command::EndRenderSubpass: {
|
||||
mCommands.NextCommand<EndRenderSubpassCmd>();
|
||||
currentSubpass += 1;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetComputePipeline:
|
||||
{
|
||||
case Command::SetComputePipeline: {
|
||||
SetComputePipelineCmd* cmd = mCommands.NextCommand<SetComputePipelineCmd>();
|
||||
ComputePipeline* pipeline = ToBackend(cmd->pipeline).Get();
|
||||
PipelineLayout* layout = ToBackend(pipeline->GetLayout());
|
||||
|
@ -502,11 +501,9 @@ namespace d3d12 {
|
|||
// TODO(enga@google.com): Implement compute pipelines
|
||||
bindingTracker.SetInheritedBindGroups(commandList, lastLayout, layout);
|
||||
lastLayout = layout;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetRenderPipeline:
|
||||
{
|
||||
case Command::SetRenderPipeline: {
|
||||
SetRenderPipelineCmd* cmd = mCommands.NextCommand<SetRenderPipelineCmd>();
|
||||
RenderPipeline* pipeline = ToBackend(cmd->pipeline).Get();
|
||||
PipelineLayout* layout = ToBackend(pipeline->GetLayout());
|
||||
|
@ -519,58 +516,46 @@ namespace d3d12 {
|
|||
|
||||
lastRenderPipeline = pipeline;
|
||||
lastLayout = layout;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetPushConstants:
|
||||
{
|
||||
case Command::SetPushConstants: {
|
||||
mCommands.NextCommand<SetPushConstantsCmd>();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetStencilReference:
|
||||
{
|
||||
SetStencilReferenceCmd *cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||
case Command::SetStencilReference: {
|
||||
SetStencilReferenceCmd* cmd = mCommands.NextCommand<SetStencilReferenceCmd>();
|
||||
|
||||
commandList->OMSetStencilRef(cmd->reference);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetBlendColor:
|
||||
{
|
||||
case Command::SetBlendColor: {
|
||||
SetBlendColorCmd* cmd = mCommands.NextCommand<SetBlendColorCmd>();
|
||||
ASSERT(lastRenderPipeline);
|
||||
commandList->OMSetBlendFactor(static_cast<const FLOAT*>(&cmd->r));
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetBindGroup:
|
||||
{
|
||||
case Command::SetBindGroup: {
|
||||
SetBindGroupCmd* cmd = mCommands.NextCommand<SetBindGroupCmd>();
|
||||
BindGroup* group = ToBackend(cmd->group.Get());
|
||||
bindingTracker.SetBindGroup(commandList, lastLayout, group, cmd->index);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetIndexBuffer:
|
||||
{
|
||||
case Command::SetIndexBuffer: {
|
||||
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||
|
||||
Buffer* buffer = ToBackend(cmd->buffer.Get());
|
||||
D3D12_INDEX_BUFFER_VIEW bufferView;
|
||||
bufferView.BufferLocation = buffer->GetVA() + cmd->offset;
|
||||
bufferView.SizeInBytes = buffer->GetSize() - cmd->offset;
|
||||
//TODO(cwallez@chromium.org): Make index buffers lazily applied, right now
|
||||
//this will break if the pipeline is changed for one with a different index
|
||||
//format after SetIndexBuffer
|
||||
// TODO(cwallez@chromium.org): Make index buffers lazily applied, right now
|
||||
// this will break if the pipeline is changed for one with a different index
|
||||
// format after SetIndexBuffer
|
||||
bufferView.Format = DXGIIndexFormat(lastRenderPipeline->GetIndexFormat());
|
||||
|
||||
commandList->IASetIndexBuffer(&bufferView);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::SetVertexBuffers:
|
||||
{
|
||||
case Command::SetVertexBuffers: {
|
||||
SetVertexBuffersCmd* cmd = mCommands.NextCommand<SetVertexBuffersCmd>();
|
||||
auto buffers = mCommands.NextData<Ref<BufferBase>>(cmd->count);
|
||||
auto offsets = mCommands.NextData<uint32_t>(cmd->count);
|
||||
|
@ -586,41 +571,40 @@ namespace d3d12 {
|
|||
d3d12BufferViews[i].SizeInBytes = buffer->GetSize() - offsets[i];
|
||||
}
|
||||
|
||||
commandList->IASetVertexBuffers(cmd->startSlot, cmd->count, d3d12BufferViews.data());
|
||||
}
|
||||
break;
|
||||
commandList->IASetVertexBuffers(cmd->startSlot, cmd->count,
|
||||
d3d12BufferViews.data());
|
||||
} break;
|
||||
|
||||
case Command::TransitionBufferUsage:
|
||||
{
|
||||
TransitionBufferUsageCmd* cmd = mCommands.NextCommand<TransitionBufferUsageCmd>();
|
||||
case Command::TransitionBufferUsage: {
|
||||
TransitionBufferUsageCmd* cmd =
|
||||
mCommands.NextCommand<TransitionBufferUsageCmd>();
|
||||
|
||||
Buffer* buffer = ToBackend(cmd->buffer.Get());
|
||||
|
||||
D3D12_RESOURCE_BARRIER barrier;
|
||||
if (buffer->GetResourceTransitionBarrier(buffer->GetUsage(), cmd->usage, &barrier)) {
|
||||
if (buffer->GetResourceTransitionBarrier(buffer->GetUsage(), cmd->usage,
|
||||
&barrier)) {
|
||||
commandList->ResourceBarrier(1, &barrier);
|
||||
}
|
||||
|
||||
buffer->UpdateUsageInternal(cmd->usage);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case Command::TransitionTextureUsage:
|
||||
{
|
||||
TransitionTextureUsageCmd* cmd = mCommands.NextCommand<TransitionTextureUsageCmd>();
|
||||
case Command::TransitionTextureUsage: {
|
||||
TransitionTextureUsageCmd* cmd =
|
||||
mCommands.NextCommand<TransitionTextureUsageCmd>();
|
||||
|
||||
Texture* texture = ToBackend(cmd->texture.Get());
|
||||
|
||||
D3D12_RESOURCE_BARRIER barrier;
|
||||
if (texture->GetResourceTransitionBarrier(texture->GetUsage(), cmd->usage, &barrier)) {
|
||||
if (texture->GetResourceTransitionBarrier(texture->GetUsage(), cmd->usage,
|
||||
&barrier)) {
|
||||
commandList->ResourceBarrier(1, &barrier);
|
||||
}
|
||||
|
||||
texture->UpdateUsageInternal(cmd->usage);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -36,7 +35,6 @@ namespace d3d12 {
|
|||
Device* mDevice;
|
||||
CommandIterator mCommands;
|
||||
};
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_COMMANDBUFFERD3D12_H_
|
||||
|
|
|
@ -15,14 +15,13 @@
|
|||
#include "backend/d3d12/ComputePipelineD3D12.h"
|
||||
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/ShaderModuleD3D12.h"
|
||||
#include "backend/d3d12/PipelineLayoutD3D12.h"
|
||||
#include "backend/d3d12/ShaderModuleD3D12.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
#include <d3dcompiler.h>
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
ComputePipeline::ComputePipeline(ComputePipelineBuilder* builder)
|
||||
: ComputePipelineBase(builder) {
|
||||
|
@ -41,19 +40,9 @@ namespace d3d12 {
|
|||
ComPtr<ID3DBlob> compiledShader;
|
||||
ComPtr<ID3DBlob> errors;
|
||||
|
||||
if (FAILED(D3DCompile(
|
||||
hlslSource.c_str(),
|
||||
hlslSource.length(),
|
||||
nullptr,
|
||||
{ nullptr },
|
||||
nullptr,
|
||||
entryPoint.c_str(),
|
||||
"cs_5_1",
|
||||
compileFlags,
|
||||
0,
|
||||
&compiledShader,
|
||||
&errors
|
||||
))) {
|
||||
if (FAILED(D3DCompile(hlslSource.c_str(), hlslSource.length(), nullptr, {nullptr}, nullptr,
|
||||
entryPoint.c_str(), "cs_5_1", compileFlags, 0, &compiledShader,
|
||||
&errors))) {
|
||||
printf("%s\n", reinterpret_cast<char*>(errors->GetBufferPointer()));
|
||||
ASSERT(false);
|
||||
}
|
||||
|
@ -64,12 +53,12 @@ namespace d3d12 {
|
|||
descriptor.CS.BytecodeLength = compiledShader->GetBufferSize();
|
||||
|
||||
Device* device = ToBackend(builder->GetDevice());
|
||||
device->GetD3D12Device()->CreateComputePipelineState(&descriptor, IID_PPV_ARGS(&mPipelineState));
|
||||
device->GetD3D12Device()->CreateComputePipelineState(&descriptor,
|
||||
IID_PPV_ARGS(&mPipelineState));
|
||||
}
|
||||
|
||||
ComPtr<ID3D12PipelineState> ComputePipeline::GetPipelineState() {
|
||||
return mPipelineState;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class ComputePipeline : public ComputePipelineBase {
|
||||
public:
|
||||
|
@ -32,7 +31,6 @@ namespace backend {
|
|||
ComPtr<ID3D12PipelineState> mPipelineState;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_COMPUTEPIPELINED3D12_H_
|
||||
|
|
|
@ -36,8 +36,7 @@
|
|||
#include "backend/d3d12/TextureD3D12.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
nxtProcTable GetNonValidatingProcs();
|
||||
nxtProcTable GetValidatingProcs();
|
||||
|
@ -63,7 +62,8 @@ namespace d3d12 {
|
|||
backendDevice->NextSerial();
|
||||
}
|
||||
|
||||
void ExecuteCommandLists(nxtDevice device, std::initializer_list<ID3D12CommandList*> commandLists) {
|
||||
void ExecuteCommandLists(nxtDevice device,
|
||||
std::initializer_list<ID3D12CommandList*> commandLists) {
|
||||
Device* backendDevice = reinterpret_cast<Device*>(device);
|
||||
backendDevice->ExecuteCommandLists(commandLists);
|
||||
}
|
||||
|
@ -89,13 +89,13 @@ namespace d3d12 {
|
|||
mMapReadRequestTracker(new MapReadRequestTracker(this)),
|
||||
mResourceAllocator(new ResourceAllocator(this)),
|
||||
mResourceUploader(new ResourceUploader(this)) {
|
||||
|
||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
ASSERT_SUCCESS(d3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&mCommandQueue)));
|
||||
|
||||
ASSERT_SUCCESS(d3d12Device->CreateFence(mSerial, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&mFence)));
|
||||
ASSERT_SUCCESS(
|
||||
d3d12Device->CreateFence(mSerial, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&mFence)));
|
||||
mFenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
ASSERT(mFenceEvent != nullptr);
|
||||
|
||||
|
@ -139,22 +139,21 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
void Device::OpenCommandList(ComPtr<ID3D12GraphicsCommandList>* commandList) {
|
||||
ComPtr<ID3D12GraphicsCommandList> &cmdList = *commandList;
|
||||
ComPtr<ID3D12GraphicsCommandList>& cmdList = *commandList;
|
||||
if (!cmdList) {
|
||||
ASSERT_SUCCESS(mD3d12Device->CreateCommandList(
|
||||
0,
|
||||
D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
mCommandAllocatorManager->ReserveCommandAllocator().Get(),
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&cmdList)
|
||||
));
|
||||
0, D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
mCommandAllocatorManager->ReserveCommandAllocator().Get(), nullptr,
|
||||
IID_PPV_ARGS(&cmdList)));
|
||||
} else {
|
||||
ASSERT_SUCCESS(cmdList->Reset(mCommandAllocatorManager->ReserveCommandAllocator().Get(), nullptr));
|
||||
ASSERT_SUCCESS(
|
||||
cmdList->Reset(mCommandAllocatorManager->ReserveCommandAllocator().Get(), nullptr));
|
||||
}
|
||||
}
|
||||
|
||||
ComPtr<ID3D12GraphicsCommandList> Device::GetPendingCommandList() {
|
||||
// Callers of GetPendingCommandList do so to record commands. Only reserve a command allocator when it is needed so we don't submit empty command lists
|
||||
// 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 (!mPendingCommands.open) {
|
||||
OpenCommandList(&mPendingCommands.commandList);
|
||||
mPendingCommands.open = true;
|
||||
|
@ -197,10 +196,12 @@ namespace d3d12 {
|
|||
mPendingCommands.open = false;
|
||||
lists[0] = mPendingCommands.commandList.Get();
|
||||
std::copy(commandLists.begin(), commandLists.end(), lists.begin() + 1);
|
||||
mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size() + 1), lists.data());
|
||||
mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size() + 1),
|
||||
lists.data());
|
||||
} else {
|
||||
std::vector<ID3D12CommandList*> lists(commandLists);
|
||||
mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size()), lists.data());
|
||||
mCommandQueue->ExecuteCommandLists(static_cast<UINT>(commandLists.size()),
|
||||
lists.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,5 +269,4 @@ namespace d3d12 {
|
|||
: RenderPassBase(builder), mDevice(device) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class BindGroup;
|
||||
class BindGroupLayout;
|
||||
|
@ -77,7 +76,7 @@ namespace d3d12 {
|
|||
using TextureViewType = TextureView;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
auto ToBackend(T&& common) -> decltype(ToBackendBase<D3D12BackendTraits>(common)) {
|
||||
return ToBackendBase<D3D12BackendTraits>(common);
|
||||
}
|
||||
|
@ -157,7 +156,6 @@ namespace d3d12 {
|
|||
Device* mDevice;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_D3D12BACKEND_H_
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
#include "common/BitSetIterator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
static D3D12_STENCIL_OP StencilOp(nxt::StencilOperation op) {
|
||||
switch (op) {
|
||||
|
@ -43,8 +42,7 @@ namespace d3d12 {
|
|||
}
|
||||
|
||||
static D3D12_COMPARISON_FUNC ComparisonFunc(nxt::CompareFunction func) {
|
||||
switch (func)
|
||||
{
|
||||
switch (func) {
|
||||
case nxt::CompareFunction::Always:
|
||||
return D3D12_COMPARISON_FUNC_ALWAYS;
|
||||
case nxt::CompareFunction::Equal:
|
||||
|
@ -66,7 +64,8 @@ namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
static D3D12_DEPTH_STENCILOP_DESC StencilOpDesc(backend::DepthStencilStateBase::StencilFaceInfo faceInfo) {
|
||||
static D3D12_DEPTH_STENCILOP_DESC StencilOpDesc(
|
||||
backend::DepthStencilStateBase::StencilFaceInfo faceInfo) {
|
||||
D3D12_DEPTH_STENCILOP_DESC desc;
|
||||
|
||||
desc.StencilFailOp = StencilOp(faceInfo.stencilFail);
|
||||
|
@ -79,9 +78,9 @@ namespace d3d12 {
|
|||
|
||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||
: DepthStencilStateBase(builder), mDevice(device) {
|
||||
|
||||
mDepthStencilDescriptor.DepthEnable = TRUE;
|
||||
mDepthStencilDescriptor.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;
|
||||
mDepthStencilDescriptor.DepthFunc = ComparisonFunc(GetDepth().compareFunction);
|
||||
|
||||
mDepthStencilDescriptor.StencilEnable = StencilTestEnabled() ? TRUE : FALSE;
|
||||
|
@ -96,5 +95,4 @@ namespace d3d12 {
|
|||
return mDepthStencilDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -35,7 +34,6 @@ namespace d3d12 {
|
|||
D3D12_DEPTH_STENCIL_DESC mDepthStencilDescriptor;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_DEPTHSTENCILSTATED3D12_H_
|
||||
|
|
|
@ -17,14 +17,15 @@
|
|||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
DescriptorHeapHandle::DescriptorHeapHandle()
|
||||
: 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)
|
||||
: mDescriptorHeap(descriptorHeap), mSizeIncrement(sizeIncrement), mOffset(offset) {
|
||||
}
|
||||
|
||||
|
@ -46,29 +47,39 @@ namespace d3d12 {
|
|||
return handle;
|
||||
}
|
||||
|
||||
|
||||
DescriptorHeapAllocator::DescriptorHeapAllocator(Device* device)
|
||||
: mDevice(device),
|
||||
mSizeIncrements {
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV),
|
||||
mSizeIncrements{
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_RTV),
|
||||
device->GetD3D12Device()->GetDescriptorHandleIncrementSize(
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE_DSV),
|
||||
} {
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count, uint32_t allocationSize, DescriptorHeapInfo* heapInfo, D3D12_DESCRIPTOR_HEAP_FLAGS flags) {
|
||||
// TODO(enga@google.com): This is just a linear allocator so the heap will quickly run out of space causing a new one to be allocated
|
||||
// We should reuse heap subranges that have been released
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::Allocate(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count,
|
||||
uint32_t allocationSize,
|
||||
DescriptorHeapInfo* heapInfo,
|
||||
D3D12_DESCRIPTOR_HEAP_FLAGS flags) {
|
||||
// TODO(enga@google.com): This is just a linear allocator so the heap will quickly run out
|
||||
// of space causing a new one to be allocated We should reuse heap subranges that have been
|
||||
// released
|
||||
if (count == 0) {
|
||||
return DescriptorHeapHandle();
|
||||
}
|
||||
|
||||
{
|
||||
// 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;
|
||||
if (allocationInfo.remaining >= count) {
|
||||
DescriptorHeapHandle handle(heapInfo->first, mSizeIncrements[type], allocationInfo.size - allocationInfo.remaining);
|
||||
DescriptorHeapHandle handle(heapInfo->first, mSizeIncrements[type],
|
||||
allocationInfo.size - allocationInfo.remaining);
|
||||
allocationInfo.remaining -= count;
|
||||
Release(handle);
|
||||
return handle;
|
||||
|
@ -83,9 +94,10 @@ namespace d3d12 {
|
|||
heapDescriptor.Flags = flags;
|
||||
heapDescriptor.NodeMask = 0;
|
||||
ComPtr<ID3D12DescriptorHeap> heap;
|
||||
ASSERT_SUCCESS(mDevice->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);
|
||||
|
||||
DescriptorHeapHandle handle(heap, mSizeIncrements[type], 0);
|
||||
|
@ -93,14 +105,21 @@ namespace d3d12 {
|
|||
return handle;
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count) {
|
||||
return Allocate(type, count, count, &mCpuDescriptorHeapInfos[type], D3D12_DESCRIPTOR_HEAP_FLAG_NONE);
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateCPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count) {
|
||||
return Allocate(type, count, count, &mCpuDescriptorHeapInfos[type],
|
||||
D3D12_DESCRIPTOR_HEAP_FLAG_NONE);
|
||||
}
|
||||
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type, uint32_t count) {
|
||||
ASSERT(type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV || type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
unsigned int heapSize = (type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ? kMaxCbvUavSrvHeapSize : kMaxSamplerHeapSize);
|
||||
return Allocate(type, count, heapSize, &mGpuDescriptorHeapInfos[type], D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE);
|
||||
DescriptorHeapHandle DescriptorHeapAllocator::AllocateGPUHeap(D3D12_DESCRIPTOR_HEAP_TYPE type,
|
||||
uint32_t count) {
|
||||
ASSERT(type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ||
|
||||
type == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
|
||||
unsigned int heapSize =
|
||||
(type == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ? kMaxCbvUavSrvHeapSize
|
||||
: kMaxSamplerHeapSize);
|
||||
return Allocate(type, count, heapSize, &mGpuDescriptorHeapInfos[type],
|
||||
D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE);
|
||||
}
|
||||
|
||||
void DescriptorHeapAllocator::Tick(uint64_t lastCompletedSerial) {
|
||||
|
@ -110,5 +129,4 @@ namespace d3d12 {
|
|||
void DescriptorHeapAllocator::Release(DescriptorHeapHandle handle) {
|
||||
mReleasedHandles.Enqueue(handle, mDevice->GetSerial());
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -17,20 +17,20 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
#include "common/SerialQueue.h"
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include "common/SerialQueue.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
class DescriptorHeapHandle {
|
||||
|
||||
public:
|
||||
DescriptorHeapHandle();
|
||||
DescriptorHeapHandle(ComPtr<ID3D12DescriptorHeap> descriptorHeap, uint32_t sizeIncrement, uint32_t offset);
|
||||
DescriptorHeapHandle(ComPtr<ID3D12DescriptorHeap> descriptorHeap,
|
||||
uint32_t sizeIncrement,
|
||||
uint32_t offset);
|
||||
|
||||
ID3D12DescriptorHeap* Get() const;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUHandle(uint32_t index) const;
|
||||
|
@ -53,7 +53,8 @@ namespace d3d12 {
|
|||
private:
|
||||
static constexpr unsigned int kMaxCbvUavSrvHeapSize = 1000000;
|
||||
static constexpr unsigned int kMaxSamplerHeapSize = 2048;
|
||||
static constexpr unsigned int kDescriptorHeapTypes = D3D12_DESCRIPTOR_HEAP_TYPE::D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES;
|
||||
static constexpr unsigned int kDescriptorHeapTypes =
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE::D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES;
|
||||
|
||||
struct AllocationInfo {
|
||||
uint32_t size = 0;
|
||||
|
@ -62,7 +63,11 @@ namespace d3d12 {
|
|||
|
||||
using DescriptorHeapInfo = std::pair<ComPtr<ID3D12DescriptorHeap>, AllocationInfo>;
|
||||
|
||||
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);
|
||||
|
||||
Device* mDevice;
|
||||
|
@ -73,7 +78,6 @@ namespace d3d12 {
|
|||
SerialQueue<DescriptorHeapHandle> mReleasedHandles;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_DESCRIPTORHEAPALLOCATOR_H_
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
|
||||
#include "backend/d3d12/FramebufferD3D12.h"
|
||||
|
||||
#include "common/BitSetIterator.h"
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/TextureD3D12.h"
|
||||
#include "common/BitSetIterator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
Framebuffer::Framebuffer(Device* device, FramebufferBuilder* builder)
|
||||
: FramebufferBase(builder), mDevice(device) {
|
||||
|
@ -50,21 +49,25 @@ namespace d3d12 {
|
|||
uint32_t heapIndex = mAttachmentHeapIndices[attachment];
|
||||
auto* textureView = GetTextureView(attachment);
|
||||
|
||||
ComPtr<ID3D12Resource> texture = ToBackend(textureView->GetTexture())->GetD3D12Resource();
|
||||
ComPtr<ID3D12Resource> texture =
|
||||
ToBackend(textureView->GetTexture())->GetD3D12Resource();
|
||||
auto format = textureView->GetTexture()->GetFormat();
|
||||
if (TextureFormatHasDepth(format) || TextureFormatHasStencil(format)) {
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = mDsvHeap.GetCPUHandle(heapIndex);
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = ToBackend(textureView)->GetDSVDescriptor();
|
||||
device->GetD3D12Device()->CreateDepthStencilView(texture.Get(), &dsvDesc, dsvHandle);
|
||||
device->GetD3D12Device()->CreateDepthStencilView(texture.Get(), &dsvDesc,
|
||||
dsvHandle);
|
||||
} else {
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = mRtvHeap.GetCPUHandle(heapIndex);
|
||||
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = ToBackend(textureView)->GetRTVDescriptor();
|
||||
device->GetD3D12Device()->CreateRenderTargetView(texture.Get(), &rtvDesc, rtvHandle);
|
||||
device->GetD3D12Device()->CreateRenderTargetView(texture.Get(), &rtvDesc,
|
||||
rtvHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Framebuffer::OMSetRenderTargetArgs Framebuffer::GetSubpassOMSetRenderTargetArgs(uint32_t subpassIndex) {
|
||||
Framebuffer::OMSetRenderTargetArgs Framebuffer::GetSubpassOMSetRenderTargetArgs(
|
||||
uint32_t subpassIndex) {
|
||||
const auto& subpassInfo = GetRenderPass()->GetSubpassInfo(subpassIndex);
|
||||
OMSetRenderTargetArgs args = {};
|
||||
|
||||
|
@ -89,5 +92,4 @@ namespace d3d12 {
|
|||
return mDsvHeap.GetCPUHandle(mAttachmentHeapIndices[attachmentSlot]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
#include "backend/Framebuffer.h"
|
||||
|
||||
#include "common/Constants.h"
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
#include "backend/d3d12/DescriptorHeapAllocator.h"
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -51,7 +50,6 @@ namespace d3d12 {
|
|||
std::vector<uint32_t> mAttachmentHeapIndices;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_FRAMEBUFFERD3D12_H_
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/BindGroupD3D12.h"
|
||||
#include "backend/d3d12/BindGroupLayoutD3D12.h"
|
||||
#include "backend/d3d12/BlendStateD3D12.h"
|
||||
#include "backend/d3d12/BufferD3D12.h"
|
||||
#include "backend/d3d12/CommandBufferD3D12.h"
|
||||
#include "backend/d3d12/ComputePipelineD3D12.h"
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/DepthStencilStateD3D12.h"
|
||||
#include "backend/d3d12/FramebufferD3D12.h"
|
||||
#include "backend/d3d12/InputStateD3D12.h"
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
#include "common/BitSetIterator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
static DXGI_FORMAT VertexFormatType(nxt::VertexFormat format) {
|
||||
switch (format) {
|
||||
|
@ -47,7 +46,6 @@ namespace d3d12 {
|
|||
|
||||
InputState::InputState(Device* device, InputStateBuilder* builder)
|
||||
: InputStateBase(builder), mDevice(device) {
|
||||
|
||||
const auto& attributesSetMask = GetAttributesSetMask();
|
||||
|
||||
unsigned int count = 0;
|
||||
|
@ -60,7 +58,8 @@ namespace d3d12 {
|
|||
|
||||
const AttributeInfo& attribute = GetAttribute(i);
|
||||
|
||||
// If the HLSL semantic is TEXCOORDN the SemanticName should be "TEXCOORD" and the SemanticIndex N
|
||||
// If the HLSL semantic is TEXCOORDN the SemanticName should be "TEXCOORD" and the
|
||||
// SemanticIndex N
|
||||
inputElementDescriptor.SemanticName = "TEXCOORD";
|
||||
inputElementDescriptor.SemanticIndex = static_cast<uint32_t>(i);
|
||||
inputElementDescriptor.Format = VertexFormatType(attribute.format);
|
||||
|
@ -70,7 +69,8 @@ namespace d3d12 {
|
|||
|
||||
inputElementDescriptor.AlignedByteOffset = attribute.offset;
|
||||
inputElementDescriptor.InputSlotClass = InputStepModeFunction(input.stepMode);
|
||||
if (inputElementDescriptor.InputSlotClass == D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA) {
|
||||
if (inputElementDescriptor.InputSlotClass ==
|
||||
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA) {
|
||||
inputElementDescriptor.InstanceDataStepRate = 0;
|
||||
} else {
|
||||
inputElementDescriptor.InstanceDataStepRate = 1;
|
||||
|
@ -79,12 +79,10 @@ namespace d3d12 {
|
|||
|
||||
mInputLayoutDescriptor.pInputElementDescs = mInputElementDescriptors;
|
||||
mInputLayoutDescriptor.NumElements = count;
|
||||
|
||||
}
|
||||
|
||||
const D3D12_INPUT_LAYOUT_DESC& InputState::GetD3D12InputLayoutDescriptor() const {
|
||||
return mInputLayoutDescriptor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -36,7 +35,6 @@ namespace d3d12 {
|
|||
D3D12_INPUT_ELEMENT_DESC mInputElementDescriptors[kMaxVertexAttributes];
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_INPUTSTATED3D12_H_
|
||||
|
|
|
@ -14,18 +14,16 @@
|
|||
|
||||
#include "backend/d3d12/PipelineLayoutD3D12.h"
|
||||
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/BindGroupLayoutD3D12.h"
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
PipelineLayout::PipelineLayout(Device* device, PipelineLayoutBuilder* builder)
|
||||
: PipelineLayoutBase(builder), mDevice(device) {
|
||||
|
||||
D3D12_ROOT_PARAMETER rootParameters[kMaxBindGroups * 2];
|
||||
|
||||
// A root parameter is one of these types
|
||||
|
@ -34,7 +32,8 @@ namespace d3d12 {
|
|||
D3D12_ROOT_CONSTANTS Constants;
|
||||
D3D12_ROOT_DESCRIPTOR Descriptor;
|
||||
} rootParameterValues[kMaxBindGroups * 2];
|
||||
// samplers must be in a separate descriptor table so we need at most twice as many tables as bind groups
|
||||
// samplers must be in a separate descriptor table so we need at most twice as many tables
|
||||
// as bind groups
|
||||
|
||||
// Ranges are D3D12_DESCRIPTOR_RANGE_TYPE_(SRV|UAV|CBV|SAMPLER)
|
||||
// They are grouped together so each bind group has at most 4 ranges
|
||||
|
@ -46,9 +45,11 @@ namespace d3d12 {
|
|||
for (uint32_t group = 0; group < kMaxBindGroups; ++group) {
|
||||
const BindGroupLayout* bindGroupLayout = ToBackend(GetBindGroupLayout(group));
|
||||
|
||||
// Set the root descriptor table parameter and copy ranges. Ranges are offset by the bind group index
|
||||
// Returns whether or not the parameter was set. A root parameter is not set if the number of ranges is 0
|
||||
auto SetRootDescriptorTable = [&](uint32_t rangeCount, const D3D12_DESCRIPTOR_RANGE* descriptorRanges) -> bool {
|
||||
// Set the root descriptor table parameter and copy ranges. Ranges are offset by the
|
||||
// bind group index Returns whether or not the parameter was set. A root parameter is
|
||||
// not set if the number of ranges is 0
|
||||
auto SetRootDescriptorTable =
|
||||
[&](uint32_t rangeCount, const D3D12_DESCRIPTOR_RANGE* descriptorRanges) -> bool {
|
||||
if (rangeCount == 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -69,11 +70,13 @@ namespace d3d12 {
|
|||
return true;
|
||||
};
|
||||
|
||||
if (SetRootDescriptorTable(bindGroupLayout->GetCbvUavSrvDescriptorTableSize(), bindGroupLayout->GetCbvUavSrvDescriptorRanges())) {
|
||||
if (SetRootDescriptorTable(bindGroupLayout->GetCbvUavSrvDescriptorTableSize(),
|
||||
bindGroupLayout->GetCbvUavSrvDescriptorRanges())) {
|
||||
mCbvUavSrvRootParameterInfo[group] = parameterIndex++;
|
||||
}
|
||||
|
||||
if (SetRootDescriptorTable(bindGroupLayout->GetSamplerDescriptorTableSize(), bindGroupLayout->GetSamplerDescriptorRanges())) {
|
||||
if (SetRootDescriptorTable(bindGroupLayout->GetSamplerDescriptorTableSize(),
|
||||
bindGroupLayout->GetSamplerDescriptorRanges())) {
|
||||
mSamplerRootParameterInfo[group] = parameterIndex++;
|
||||
}
|
||||
}
|
||||
|
@ -83,15 +86,18 @@ namespace d3d12 {
|
|||
rootSignatureDescriptor.pParameters = rootParameters;
|
||||
rootSignatureDescriptor.NumStaticSamplers = 0;
|
||||
rootSignatureDescriptor.pStaticSamplers = nullptr;
|
||||
rootSignatureDescriptor.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
|
||||
rootSignatureDescriptor.Flags =
|
||||
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
|
||||
|
||||
ComPtr<ID3DBlob> signature;
|
||||
ComPtr<ID3DBlob> error;
|
||||
ASSERT_SUCCESS(D3D12SerializeRootSignature(&rootSignatureDescriptor, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&mRootSignature)));
|
||||
ASSERT_SUCCESS(D3D12SerializeRootSignature(
|
||||
&rootSignatureDescriptor, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateRootSignature(
|
||||
0, signature->GetBufferPointer(), signature->GetBufferSize(),
|
||||
IID_PPV_ARGS(&mRootSignature)));
|
||||
}
|
||||
|
||||
|
||||
uint32_t PipelineLayout::GetCbvUavSrvRootParameterIndex(uint32_t group) const {
|
||||
ASSERT(group < kMaxBindGroups);
|
||||
return mCbvUavSrvRootParameterInfo[group];
|
||||
|
@ -105,5 +111,4 @@ namespace d3d12 {
|
|||
ComPtr<ID3D12RootSignature> PipelineLayout::GetRootSignature() {
|
||||
return mRootSignature;
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -42,7 +41,6 @@ namespace d3d12 {
|
|||
ComPtr<ID3D12RootSignature> mRootSignature;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_PIPELINELAYOUTD3D12_H_
|
||||
|
|
|
@ -14,17 +14,15 @@
|
|||
|
||||
#include "backend/d3d12/QueueD3D12.h"
|
||||
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/CommandBufferD3D12.h"
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
Queue::Queue(Device* device, QueueBuilder* builder)
|
||||
: QueueBase(builder), mDevice(device) {
|
||||
Queue::Queue(Device* device, QueueBuilder* builder) : QueueBase(builder), mDevice(device) {
|
||||
}
|
||||
|
||||
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) {
|
||||
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {
|
||||
mDevice->Tick();
|
||||
|
||||
mDevice->OpenCommandList(&mCommandList);
|
||||
|
@ -33,10 +31,9 @@ namespace d3d12 {
|
|||
}
|
||||
ASSERT_SUCCESS(mCommandList->Close());
|
||||
|
||||
mDevice->ExecuteCommandLists({ mCommandList.Get() });
|
||||
mDevice->ExecuteCommandLists({mCommandList.Get()});
|
||||
|
||||
mDevice->NextSerial();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
class CommandBuffer;
|
||||
|
@ -30,7 +29,7 @@ namespace d3d12 {
|
|||
Queue(Device* device, QueueBuilder* builder);
|
||||
|
||||
// NXT API
|
||||
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
|
||||
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
|
||||
|
||||
private:
|
||||
Device* mDevice;
|
||||
|
@ -38,7 +37,6 @@ namespace d3d12 {
|
|||
ComPtr<ID3D12GraphicsCommandList> mCommandList;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_QUEUED3D12_H_
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/DepthStencilStateD3D12.h"
|
||||
#include "backend/d3d12/InputStateD3D12.h"
|
||||
#include "backend/d3d12/PipelineLayoutD3D12.h"
|
||||
#include "backend/d3d12/ShaderModuleD3D12.h"
|
||||
#include "backend/d3d12/TextureD3D12.h"
|
||||
#include "backend/d3d12/PipelineLayoutD3D12.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
#include <d3dcompiler.h>
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
namespace {
|
||||
D3D12_PRIMITIVE_TOPOLOGY D3D12PrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) {
|
||||
|
@ -46,7 +45,8 @@ namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
D3D12_PRIMITIVE_TOPOLOGY_TYPE D3D12PrimitiveTopologyType(nxt::PrimitiveTopology primitiveTopology) {
|
||||
D3D12_PRIMITIVE_TOPOLOGY_TYPE D3D12PrimitiveTopologyType(
|
||||
nxt::PrimitiveTopology primitiveTopology) {
|
||||
switch (primitiveTopology) {
|
||||
case nxt::PrimitiveTopology::PointList:
|
||||
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
|
||||
|
@ -60,10 +60,11 @@ namespace d3d12 {
|
|||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
RenderPipeline::RenderPipeline(RenderPipelineBuilder* builder)
|
||||
: RenderPipelineBase(builder), mD3d12PrimitiveTopology(D3D12PrimitiveTopology(GetPrimitiveTopology())) {
|
||||
: RenderPipelineBase(builder),
|
||||
mD3d12PrimitiveTopology(D3D12PrimitiveTopology(GetPrimitiveTopology())) {
|
||||
uint32_t compileFlags = 0;
|
||||
#if defined(_DEBUG)
|
||||
// Enable better shader debugging with the graphics debugging tools.
|
||||
|
@ -99,19 +100,9 @@ namespace d3d12 {
|
|||
break;
|
||||
}
|
||||
|
||||
if(FAILED(D3DCompile(
|
||||
hlslSource.c_str(),
|
||||
hlslSource.length(),
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
entryPoint.c_str(),
|
||||
compileTarget,
|
||||
compileFlags,
|
||||
0,
|
||||
&compiledShader[stage],
|
||||
&errors
|
||||
))) {
|
||||
if (FAILED(D3DCompile(hlslSource.c_str(), hlslSource.length(), nullptr, nullptr,
|
||||
nullptr, entryPoint.c_str(), compileTarget, compileFlags, 0,
|
||||
&compiledShader[stage], &errors))) {
|
||||
printf("%s\n", reinterpret_cast<char*>(errors->GetBufferPointer()));
|
||||
ASSERT(false);
|
||||
}
|
||||
|
@ -148,7 +139,8 @@ namespace d3d12 {
|
|||
auto& subpassInfo = renderPass->GetSubpassInfo(GetSubPass());
|
||||
|
||||
if (subpassInfo.depthStencilAttachmentSet) {
|
||||
const auto& attachmentInfo = renderPass->GetAttachmentInfo(subpassInfo.depthStencilAttachment);
|
||||
const auto& attachmentInfo =
|
||||
renderPass->GetAttachmentInfo(subpassInfo.depthStencilAttachment);
|
||||
descriptor.DSVFormat = D3D12TextureFormat(attachmentInfo.format);
|
||||
}
|
||||
|
||||
|
@ -158,7 +150,8 @@ namespace d3d12 {
|
|||
const auto& attachmentInfo = renderPass->GetAttachmentInfo(attachment);
|
||||
|
||||
descriptor.RTVFormats[attachmentSlot] = D3D12TextureFormat(attachmentInfo.format);
|
||||
descriptor.BlendState.RenderTarget[attachmentSlot] = ToBackend(GetBlendState(attachmentSlot))->GetD3D12BlendDesc();
|
||||
descriptor.BlendState.RenderTarget[attachmentSlot] =
|
||||
ToBackend(GetBlendState(attachmentSlot))->GetD3D12BlendDesc();
|
||||
attachmentCount = attachmentSlot + 1;
|
||||
}
|
||||
descriptor.NumRenderTargets = attachmentCount;
|
||||
|
@ -174,7 +167,8 @@ namespace d3d12 {
|
|||
descriptor.SampleDesc.Count = 1;
|
||||
|
||||
Device* device = ToBackend(builder->GetDevice());
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateGraphicsPipelineState(&descriptor, IID_PPV_ARGS(&mPipelineState)));
|
||||
ASSERT_SUCCESS(device->GetD3D12Device()->CreateGraphicsPipelineState(
|
||||
&descriptor, IID_PPV_ARGS(&mPipelineState)));
|
||||
}
|
||||
|
||||
D3D12_PRIMITIVE_TOPOLOGY RenderPipeline::GetD3D12PrimitiveTopology() const {
|
||||
|
@ -185,5 +179,4 @@ namespace d3d12 {
|
|||
return mPipelineState;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class RenderPipeline : public RenderPipelineBase {
|
||||
public:
|
||||
|
@ -34,7 +33,6 @@ namespace d3d12 {
|
|||
ComPtr<ID3D12PipelineState> mPipelineState;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_RENDERPIPELINED3D12_H_
|
||||
|
|
|
@ -16,41 +16,31 @@
|
|||
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
namespace {
|
||||
static constexpr D3D12_HEAP_PROPERTIES kDefaultHeapProperties = {
|
||||
D3D12_HEAP_TYPE_DEFAULT,
|
||||
D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
|
||||
D3D12_MEMORY_POOL_UNKNOWN,
|
||||
0,
|
||||
0
|
||||
};
|
||||
D3D12_HEAP_TYPE_DEFAULT, D3D12_CPU_PAGE_PROPERTY_UNKNOWN, D3D12_MEMORY_POOL_UNKNOWN, 0,
|
||||
0};
|
||||
|
||||
static constexpr D3D12_HEAP_PROPERTIES kUploadHeapProperties = {
|
||||
D3D12_HEAP_TYPE_UPLOAD,
|
||||
D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
|
||||
D3D12_MEMORY_POOL_UNKNOWN,
|
||||
0,
|
||||
0
|
||||
};
|
||||
D3D12_HEAP_TYPE_UPLOAD, D3D12_CPU_PAGE_PROPERTY_UNKNOWN, D3D12_MEMORY_POOL_UNKNOWN, 0,
|
||||
0};
|
||||
|
||||
static constexpr D3D12_HEAP_PROPERTIES kReadbackHeapProperties = {
|
||||
D3D12_HEAP_TYPE_READBACK,
|
||||
D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
|
||||
D3D12_MEMORY_POOL_UNKNOWN,
|
||||
0,
|
||||
0
|
||||
};
|
||||
}
|
||||
D3D12_HEAP_TYPE_READBACK, D3D12_CPU_PAGE_PROPERTY_UNKNOWN, D3D12_MEMORY_POOL_UNKNOWN, 0,
|
||||
0};
|
||||
} // namespace
|
||||
|
||||
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) {
|
||||
const D3D12_HEAP_PROPERTIES* heapProperties = nullptr;
|
||||
switch(heapType) {
|
||||
switch (heapType) {
|
||||
case D3D12_HEAP_TYPE_DEFAULT:
|
||||
heapProperties = &kDefaultHeapProperties;
|
||||
break;
|
||||
|
@ -68,19 +58,15 @@ namespace d3d12 {
|
|||
|
||||
// TODO(enga@google.com): Use CreatePlacedResource
|
||||
ASSERT_SUCCESS(mDevice->GetD3D12Device()->CreateCommittedResource(
|
||||
heapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&resourceDescriptor,
|
||||
initialUsage,
|
||||
nullptr,
|
||||
IID_PPV_ARGS(&resource)
|
||||
));
|
||||
heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDescriptor, initialUsage, nullptr,
|
||||
IID_PPV_ARGS(&resource)));
|
||||
|
||||
return 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
|
||||
mReleasedResources.Enqueue(resource, mDevice->GetSerial());
|
||||
}
|
||||
|
||||
|
@ -88,5 +74,4 @@ namespace d3d12 {
|
|||
mReleasedResources.ClearUpTo(lastCompletedSerial);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,17 +19,17 @@
|
|||
|
||||
#include "common/SerialQueue.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
class ResourceAllocator {
|
||||
|
||||
public:
|
||||
ResourceAllocator(Device* device);
|
||||
|
||||
ComPtr<ID3D12Resource> Allocate(D3D12_HEAP_TYPE heapType, const D3D12_RESOURCE_DESC &resourceDescriptor, D3D12_RESOURCE_STATES initialUsage);
|
||||
ComPtr<ID3D12Resource> Allocate(D3D12_HEAP_TYPE heapType,
|
||||
const D3D12_RESOURCE_DESC& resourceDescriptor,
|
||||
D3D12_RESOURCE_STATES initialUsage);
|
||||
void Release(ComPtr<ID3D12Resource> resource);
|
||||
void Tick(uint64_t lastCompletedSerial);
|
||||
|
||||
|
@ -39,7 +39,6 @@ namespace d3d12 {
|
|||
SerialQueue<ComPtr<ID3D12Resource>> mReleasedResources;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_RESOURCEALLOCATIONMANAGER_H_
|
||||
|
|
|
@ -17,23 +17,29 @@
|
|||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/ResourceAllocator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
ResourceUploader::ResourceUploader(Device* device) : mDevice(device) {
|
||||
}
|
||||
|
||||
void ResourceUploader::BufferSubData(ComPtr<ID3D12Resource> resource, uint32_t start, uint32_t count, const void* data) {
|
||||
// TODO(enga@google.com): Use a handle to a subset of a large ring buffer. On Release, decrease reference count on the ring buffer and free when 0.
|
||||
// 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.
|
||||
void ResourceUploader::BufferSubData(ComPtr<ID3D12Resource> resource,
|
||||
uint32_t start,
|
||||
uint32_t count,
|
||||
const void* data) {
|
||||
// TODO(enga@google.com): Use a handle to a subset of a large ring buffer. On Release,
|
||||
// decrease reference count on the ring buffer and free when 0. Alternatively, the
|
||||
// SerialQueue could be used to track which last point of the ringbuffer is in use, and
|
||||
// start reusing chunks of it that aren't in flight.
|
||||
UploadHandle uploadHandle = GetUploadBuffer(count);
|
||||
memcpy(uploadHandle.mappedBuffer, data, count);
|
||||
mDevice->GetPendingCommandList()->CopyBufferRegion(resource.Get(), start, uploadHandle.resource.Get(), 0, count);
|
||||
mDevice->GetPendingCommandList()->CopyBufferRegion(resource.Get(), start,
|
||||
uploadHandle.resource.Get(), 0, count);
|
||||
Release(uploadHandle);
|
||||
}
|
||||
|
||||
ResourceUploader::UploadHandle ResourceUploader::GetUploadBuffer(uint32_t requiredSize) {
|
||||
// TODO(enga@google.com): This will find or create a mapped buffer of sufficient size and return a handle to a mapped range
|
||||
// TODO(enga@google.com): This will find or create a mapped buffer of sufficient size and
|
||||
// return a handle to a mapped range
|
||||
D3D12_RESOURCE_DESC resourceDescriptor;
|
||||
resourceDescriptor.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
||||
resourceDescriptor.Alignment = 0;
|
||||
|
@ -48,12 +54,14 @@ namespace d3d12 {
|
|||
resourceDescriptor.Flags = D3D12_RESOURCE_FLAG_NONE;
|
||||
|
||||
UploadHandle uploadHandle;
|
||||
uploadHandle.resource = mDevice->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor, D3D12_RESOURCE_STATE_GENERIC_READ);
|
||||
uploadHandle.resource = mDevice->GetResourceAllocator()->Allocate(
|
||||
D3D12_HEAP_TYPE_UPLOAD, resourceDescriptor, D3D12_RESOURCE_STATE_GENERIC_READ);
|
||||
D3D12_RANGE readRange;
|
||||
readRange.Begin = 0;
|
||||
readRange.End = 0;
|
||||
|
||||
uploadHandle.resource->Map(0, &readRange, reinterpret_cast<void**>(&uploadHandle.mappedBuffer));
|
||||
uploadHandle.resource->Map(0, &readRange,
|
||||
reinterpret_cast<void**>(&uploadHandle.mappedBuffer));
|
||||
return uploadHandle;
|
||||
}
|
||||
|
||||
|
@ -62,5 +70,4 @@ namespace d3d12 {
|
|||
mDevice->GetResourceAllocator()->Release(uploadHandle.resource);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/Forward.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -28,7 +27,10 @@ namespace d3d12 {
|
|||
public:
|
||||
ResourceUploader(Device* device);
|
||||
|
||||
void BufferSubData(ComPtr<ID3D12Resource> resource, uint32_t start, uint32_t count, const void* data);
|
||||
void BufferSubData(ComPtr<ID3D12Resource> resource,
|
||||
uint32_t start,
|
||||
uint32_t count,
|
||||
const void* data);
|
||||
|
||||
private:
|
||||
struct UploadHandle {
|
||||
|
@ -41,7 +43,6 @@ namespace d3d12 {
|
|||
|
||||
Device* mDevice;
|
||||
};
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_RESOURCEUPLOADER_H_
|
||||
|
|
|
@ -16,14 +16,12 @@
|
|||
|
||||
#include "backend/d3d12/D3D12Backend.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
|
||||
Sampler::Sampler(SamplerBuilder* builder)
|
||||
: SamplerBase(builder) {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
Sampler::Sampler(SamplerBuilder* builder) : SamplerBase(builder) {
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn770367(v=vs.85).aspx
|
||||
// D3D12_FILTER_MIN_MAG_MIP_POINT = 0 0 0 0 0 // hex value, decimal value, min linear, mag linear, mip linear
|
||||
// hex value, decimal value, min linear, mag linear, mip linear
|
||||
// D3D12_FILTER_MIN_MAG_MIP_POINT = 0 0 0 0 0
|
||||
// D3D12_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x1 1 0 0 1
|
||||
// D3D12_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x4 4 0 1 0
|
||||
// D3D12_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x5 5 0 1 1
|
||||
|
@ -69,15 +67,14 @@ namespace d3d12 {
|
|||
mSamplerDesc.MipLODBias = 0.f;
|
||||
mSamplerDesc.MaxAnisotropy = 1;
|
||||
mSamplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
||||
mSamplerDesc.BorderColor[0] = mSamplerDesc.BorderColor[1] = mSamplerDesc.BorderColor[2] = mSamplerDesc.BorderColor[3] = 0;
|
||||
mSamplerDesc.BorderColor[0] = mSamplerDesc.BorderColor[1] = mSamplerDesc.BorderColor[2] =
|
||||
mSamplerDesc.BorderColor[3] = 0;
|
||||
mSamplerDesc.MinLOD = 0;
|
||||
mSamplerDesc.MaxLOD = D3D12_FLOAT32_MAX;
|
||||
|
||||
}
|
||||
|
||||
const D3D12_SAMPLER_DESC& Sampler::GetSamplerDescriptor() const {
|
||||
return mSamplerDesc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Sampler : public SamplerBase {
|
||||
public:
|
||||
|
@ -32,7 +31,6 @@ namespace d3d12 {
|
|||
D3D12_SAMPLER_DESC mSamplerDesc;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_SAMPLERD3D12_H_
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
|
||||
#include <spirv-cross/spirv_hlsl.hpp>
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
ShaderModule::ShaderModule(Device* device, ShaderModuleBuilder* builder)
|
||||
: ShaderModuleBase(builder), mDevice(device) {
|
||||
|
@ -34,15 +33,18 @@ namespace d3d12 {
|
|||
|
||||
ExtractSpirvInfo(compiler);
|
||||
|
||||
// rename bindings so that each register type b/u/t/s starts at 0 and then offset by kMaxBindingsPerGroup * bindGroupIndex
|
||||
// rename bindings so that each register type b/u/t/s starts at 0 and then offset by
|
||||
// kMaxBindingsPerGroup * bindGroupIndex
|
||||
auto RenumberBindings = [&](std::vector<spirv_cross::Resource> resources) {
|
||||
std::array<uint32_t, kMaxBindGroups> baseRegisters = {};
|
||||
|
||||
for (const auto& resource : resources) {
|
||||
auto bindGroupIndex = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet);
|
||||
auto bindGroupIndex =
|
||||
compiler.get_decoration(resource.id, spv::DecorationDescriptorSet);
|
||||
auto& baseRegister = baseRegisters[bindGroupIndex];
|
||||
auto bindGroupOffset = bindGroupIndex * kMaxBindingsPerGroup;
|
||||
compiler.set_decoration(resource.id, spv::DecorationBinding, bindGroupOffset + baseRegister++);
|
||||
compiler.set_decoration(resource.id, spv::DecorationBinding,
|
||||
bindGroupOffset + baseRegister++);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -59,5 +61,4 @@ namespace d3d12 {
|
|||
return mHlslSource;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
#include "backend/ShaderModule.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -34,7 +33,6 @@ namespace d3d12 {
|
|||
std::string mHlslSource;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_SHADERMODULED3D12_H_
|
||||
|
|
|
@ -19,11 +19,9 @@
|
|||
|
||||
#include <nxt/nxt_wsi.h>
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
SwapChain::SwapChain(SwapChainBuilder* builder)
|
||||
: SwapChainBase(builder) {
|
||||
SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {
|
||||
const auto& im = GetImplementation();
|
||||
nxtWSIContextD3D12 wsiContext = {};
|
||||
wsiContext.device = reinterpret_cast<nxtDevice>(GetDevice());
|
||||
|
@ -46,6 +44,4 @@ namespace d3d12 {
|
|||
return new Texture(builder, nativeTexture);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
#include "backend/SwapChain.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class SwapChain : public SwapChainBase {
|
||||
public:
|
||||
|
@ -29,7 +28,6 @@ namespace d3d12 {
|
|||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_SWAPCHAIN_D3D12_H_
|
||||
|
|
|
@ -17,11 +17,16 @@
|
|||
#include "backend/d3d12/d3d12_platform.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
namespace {
|
||||
void ComputeTexelOffsets(uint32_t offset, uint32_t rowPitch, uint32_t slicePitch, uint32_t texelSize, uint32_t* texelOffsetX, uint32_t* texelOffsetY, uint32_t* texelOffsetZ) {
|
||||
void ComputeTexelOffsets(uint32_t offset,
|
||||
uint32_t rowPitch,
|
||||
uint32_t slicePitch,
|
||||
uint32_t texelSize,
|
||||
uint32_t* texelOffsetX,
|
||||
uint32_t* texelOffsetY,
|
||||
uint32_t* texelOffsetZ) {
|
||||
uint32_t byteOffsetX = offset % rowPitch;
|
||||
offset -= byteOffsetX;
|
||||
uint32_t byteOffsetY = offset % slicePitch;
|
||||
|
@ -31,10 +36,17 @@ namespace d3d12 {
|
|||
*texelOffsetY = byteOffsetY / rowPitch;
|
||||
*texelOffsetZ = byteOffsetZ / slicePitch;
|
||||
}
|
||||
}
|
||||
|
||||
TextureCopySplit ComputeTextureCopySplit(uint32_t x, uint32_t y, uint32_t z, uint32_t width, uint32_t height, uint32_t depth, uint32_t texelSize, uint32_t offset, uint32_t rowPitch) {
|
||||
} // namespace
|
||||
|
||||
TextureCopySplit ComputeTextureCopySplit(uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t z,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t depth,
|
||||
uint32_t texelSize,
|
||||
uint32_t offset,
|
||||
uint32_t rowPitch) {
|
||||
TextureCopySplit copy;
|
||||
|
||||
if (z != 0 || depth > 1) {
|
||||
|
@ -66,19 +78,22 @@ namespace d3d12 {
|
|||
copy.copies[0].bufferSize.height = height;
|
||||
copy.copies[0].bufferSize.depth = depth;
|
||||
|
||||
// Return early. There is only one copy needed because the offset is already 512-byte aligned
|
||||
// Return early. There is only one copy needed because the offset is already 512-byte
|
||||
// aligned
|
||||
return copy;
|
||||
}
|
||||
|
||||
ASSERT(alignedOffset < offset);
|
||||
|
||||
uint32_t texelOffsetX, texelOffsetY, texelOffsetZ;
|
||||
ComputeTexelOffsets(offset - alignedOffset, rowPitch, rowPitch * height, texelSize, &texelOffsetX, &texelOffsetY, &texelOffsetZ);
|
||||
ComputeTexelOffsets(offset - alignedOffset, rowPitch, rowPitch * height, texelSize,
|
||||
&texelOffsetX, &texelOffsetY, &texelOffsetZ);
|
||||
|
||||
uint32_t rowPitchInTexels = rowPitch / texelSize;
|
||||
|
||||
if (width + texelOffsetX <= rowPitchInTexels) {
|
||||
// The region's rows fit inside the row pitch. In this case, extend the width of the PlacedFootprint and copy the buffer with an offset location
|
||||
// The region's rows fit inside the row pitch. In this case, extend the width of the
|
||||
// PlacedFootprint and copy the buffer with an offset location
|
||||
// |<--------------- row pitch --------------->|
|
||||
//
|
||||
// |-------------------------------------------|
|
||||
|
@ -133,7 +148,6 @@ namespace d3d12 {
|
|||
// |+++++++++ |
|
||||
// |-------------------------------------------|
|
||||
|
||||
|
||||
// Copy 0:
|
||||
// |-------------------------------------------|
|
||||
// | |
|
||||
|
@ -173,7 +187,6 @@ namespace d3d12 {
|
|||
copy.copies[0].bufferSize.height = height + texelOffsetY;
|
||||
copy.copies[0].bufferSize.depth = depth + texelOffsetZ;
|
||||
|
||||
|
||||
copy.copies[1].textureOffset.x = x + copy.copies[0].copySize.width;
|
||||
copy.copies[1].textureOffset.y = y;
|
||||
copy.copies[1].textureOffset.z = z;
|
||||
|
@ -190,10 +203,7 @@ namespace d3d12 {
|
|||
copy.copies[1].bufferSize.height = height + texelOffsetY + 1;
|
||||
copy.copies[1].bufferSize.depth = depth + texelOffsetZ;
|
||||
|
||||
|
||||
return copy;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,12 +19,9 @@
|
|||
|
||||
#include <array>
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
struct TextureCopySplit {
|
||||
|
||||
static constexpr unsigned int kMaxTextureCopyRegions = 2;
|
||||
|
||||
struct Extent {
|
||||
|
@ -52,9 +49,16 @@ namespace d3d12 {
|
|||
std::array<CopyInfo, kMaxTextureCopyRegions> copies;
|
||||
};
|
||||
|
||||
TextureCopySplit ComputeTextureCopySplit(uint32_t x, uint32_t y, uint32_t z, uint32_t width, uint32_t height, uint32_t depth, uint32_t texelSize, uint32_t offset, uint32_t rowPitch);
|
||||
TextureCopySplit ComputeTextureCopySplit(uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t z,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t depth,
|
||||
uint32_t texelSize,
|
||||
uint32_t offset,
|
||||
uint32_t rowPitch);
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_TEXTURECOPYSPLITTER_H_
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
#include "backend/d3d12/D3D12Backend.h"
|
||||
#include "backend/d3d12/ResourceAllocator.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
namespace {
|
||||
D3D12_RESOURCE_STATES D3D12TextureUsage(nxt::TextureUsageBit usage, nxt::TextureFormat format) {
|
||||
D3D12_RESOURCE_STATES D3D12TextureUsage(nxt::TextureUsageBit usage,
|
||||
nxt::TextureFormat format) {
|
||||
D3D12_RESOURCE_STATES resourceState = D3D12_RESOURCE_STATE_COMMON;
|
||||
|
||||
if (usage & nxt::TextureUsageBit::TransferSrc) {
|
||||
|
@ -31,7 +31,8 @@ namespace d3d12 {
|
|||
resourceState |= D3D12_RESOURCE_STATE_COPY_DEST;
|
||||
}
|
||||
if (usage & nxt::TextureUsageBit::Sampled) {
|
||||
resourceState |= (D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
resourceState |= (D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE |
|
||||
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
|
||||
}
|
||||
if (usage & nxt::TextureUsageBit::Storage) {
|
||||
resourceState |= D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
|
||||
|
@ -47,7 +48,8 @@ namespace d3d12 {
|
|||
return resourceState;
|
||||
}
|
||||
|
||||
D3D12_RESOURCE_FLAGS D3D12ResourceFlags(nxt::TextureUsageBit usage, nxt::TextureFormat format) {
|
||||
D3D12_RESOURCE_FLAGS D3D12ResourceFlags(nxt::TextureUsageBit usage,
|
||||
nxt::TextureFormat format) {
|
||||
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE;
|
||||
|
||||
if (usage & nxt::TextureUsageBit::Storage) {
|
||||
|
@ -75,7 +77,7 @@ namespace d3d12 {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DXGI_FORMAT D3D12TextureFormat(nxt::TextureFormat format) {
|
||||
switch (format) {
|
||||
|
@ -94,7 +96,6 @@ namespace d3d12 {
|
|||
|
||||
Texture::Texture(TextureBuilder* builder)
|
||||
: TextureBase(builder), mDevice(ToBackend(builder->GetDevice())) {
|
||||
|
||||
D3D12_RESOURCE_DESC resourceDescriptor;
|
||||
resourceDescriptor.Dimension = D3D12TextureDimension(GetDimension());
|
||||
resourceDescriptor.Alignment = 0;
|
||||
|
@ -108,13 +109,16 @@ namespace d3d12 {
|
|||
resourceDescriptor.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||
resourceDescriptor.Flags = D3D12ResourceFlags(GetAllowedUsage(), GetFormat());
|
||||
|
||||
mResource = mDevice->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor, D3D12TextureUsage(GetUsage(), GetFormat()));
|
||||
mResource =
|
||||
mDevice->GetResourceAllocator()->Allocate(D3D12_HEAP_TYPE_DEFAULT, resourceDescriptor,
|
||||
D3D12TextureUsage(GetUsage(), GetFormat()));
|
||||
mResourcePtr = mResource.Get();
|
||||
}
|
||||
|
||||
// With this constructor, the lifetime of the ID3D12Resource is externally managed.
|
||||
Texture::Texture(TextureBuilder* builder, ID3D12Resource* nativeTexture)
|
||||
: TextureBase(builder), mDevice(ToBackend(builder->GetDevice())),
|
||||
: TextureBase(builder),
|
||||
mDevice(ToBackend(builder->GetDevice())),
|
||||
mResourcePtr(nativeTexture) {
|
||||
}
|
||||
|
||||
|
@ -133,7 +137,9 @@ namespace d3d12 {
|
|||
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) {
|
||||
D3D12_RESOURCE_STATES stateBefore = D3D12TextureUsage(currentUsage, GetFormat());
|
||||
D3D12_RESOURCE_STATES stateAfter = D3D12TextureUsage(targetUsage, GetFormat());
|
||||
|
||||
|
@ -151,16 +157,15 @@ namespace d3d12 {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Texture::TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) {
|
||||
void Texture::TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
|
||||
nxt::TextureUsageBit targetUsage) {
|
||||
D3D12_RESOURCE_BARRIER barrier;
|
||||
if (GetResourceTransitionBarrier(currentUsage, targetUsage, &barrier)) {
|
||||
mDevice->GetPendingCommandList()->ResourceBarrier(1, &barrier);
|
||||
}
|
||||
}
|
||||
|
||||
TextureView::TextureView(TextureViewBuilder* builder)
|
||||
: TextureViewBase(builder) {
|
||||
|
||||
TextureView::TextureView(TextureViewBuilder* builder) : TextureViewBase(builder) {
|
||||
mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat());
|
||||
mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
switch (GetTexture()->GetDimension()) {
|
||||
|
@ -196,5 +201,4 @@ namespace d3d12 {
|
|||
return dsvDesc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "backend/d3d12/d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
namespace backend { namespace d3d12 {
|
||||
|
||||
class Device;
|
||||
|
||||
|
@ -34,9 +33,12 @@ namespace d3d12 {
|
|||
|
||||
DXGI_FORMAT GetD3D12Format() const;
|
||||
ID3D12Resource* GetD3D12Resource();
|
||||
bool GetResourceTransitionBarrier(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage, D3D12_RESOURCE_BARRIER* barrier);
|
||||
bool GetResourceTransitionBarrier(nxt::TextureUsageBit currentUsage,
|
||||
nxt::TextureUsageBit targetUsage,
|
||||
D3D12_RESOURCE_BARRIER* barrier);
|
||||
|
||||
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) override;
|
||||
void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
|
||||
nxt::TextureUsageBit targetUsage) override;
|
||||
|
||||
private:
|
||||
Device* mDevice;
|
||||
|
@ -55,7 +57,6 @@ namespace d3d12 {
|
|||
private:
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC mSrvDesc;
|
||||
};
|
||||
}
|
||||
}
|
||||
}} // namespace backend::d3d12
|
||||
|
||||
#endif // BACKEND_D3D12_TEXTURED3D12_H_
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
#ifndef BACKEND_D3D12_D3D12PLATFORM_H_
|
||||
#define BACKEND_D3D12_D3D12PLATFORM_H_
|
||||
|
||||
#include <wrl.h>
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_4.h>
|
||||
#include <wrl.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
|
|
Loading…
Reference in New Issue