Rename nxt:: to dawn:: in the backends

This commit is contained in:
Corentin Wallez 2018-07-18 11:38:11 +02:00 committed by Corentin Wallez
parent 141c0be317
commit 226110f958
120 changed files with 1056 additions and 1056 deletions

View File

@ -35,29 +35,29 @@ namespace backend {
return mLayout.Get(); return mLayout.Get();
} }
nxt::BindGroupUsage BindGroupBase::GetUsage() const { dawn::BindGroupUsage BindGroupBase::GetUsage() const {
return mUsage; return mUsage;
} }
BufferViewBase* BindGroupBase::GetBindingAsBufferView(size_t binding) { BufferViewBase* BindGroupBase::GetBindingAsBufferView(size_t binding) {
ASSERT(binding < kMaxBindingsPerGroup); ASSERT(binding < kMaxBindingsPerGroup);
ASSERT(mLayout->GetBindingInfo().mask[binding]); ASSERT(mLayout->GetBindingInfo().mask[binding]);
ASSERT(mLayout->GetBindingInfo().types[binding] == nxt::BindingType::UniformBuffer || ASSERT(mLayout->GetBindingInfo().types[binding] == dawn::BindingType::UniformBuffer ||
mLayout->GetBindingInfo().types[binding] == nxt::BindingType::StorageBuffer); mLayout->GetBindingInfo().types[binding] == dawn::BindingType::StorageBuffer);
return reinterpret_cast<BufferViewBase*>(mBindings[binding].Get()); return reinterpret_cast<BufferViewBase*>(mBindings[binding].Get());
} }
SamplerBase* BindGroupBase::GetBindingAsSampler(size_t binding) { SamplerBase* BindGroupBase::GetBindingAsSampler(size_t binding) {
ASSERT(binding < kMaxBindingsPerGroup); ASSERT(binding < kMaxBindingsPerGroup);
ASSERT(mLayout->GetBindingInfo().mask[binding]); ASSERT(mLayout->GetBindingInfo().mask[binding]);
ASSERT(mLayout->GetBindingInfo().types[binding] == nxt::BindingType::Sampler); ASSERT(mLayout->GetBindingInfo().types[binding] == dawn::BindingType::Sampler);
return reinterpret_cast<SamplerBase*>(mBindings[binding].Get()); return reinterpret_cast<SamplerBase*>(mBindings[binding].Get());
} }
TextureViewBase* BindGroupBase::GetBindingAsTextureView(size_t binding) { TextureViewBase* BindGroupBase::GetBindingAsTextureView(size_t binding) {
ASSERT(binding < kMaxBindingsPerGroup); ASSERT(binding < kMaxBindingsPerGroup);
ASSERT(mLayout->GetBindingInfo().mask[binding]); ASSERT(mLayout->GetBindingInfo().mask[binding]);
ASSERT(mLayout->GetBindingInfo().types[binding] == nxt::BindingType::SampledTexture); ASSERT(mLayout->GetBindingInfo().types[binding] == dawn::BindingType::SampledTexture);
return reinterpret_cast<TextureViewBase*>(mBindings[binding].Get()); return reinterpret_cast<TextureViewBase*>(mBindings[binding].Get());
} }
@ -100,7 +100,7 @@ namespace backend {
mPropertiesSet |= BINDGROUP_PROPERTY_LAYOUT; mPropertiesSet |= BINDGROUP_PROPERTY_LAYOUT;
} }
void BindGroupBuilder::SetUsage(nxt::BindGroupUsage usage) { void BindGroupBuilder::SetUsage(dawn::BindGroupUsage usage) {
if ((mPropertiesSet & BINDGROUP_PROPERTY_USAGE) != 0) { if ((mPropertiesSet & BINDGROUP_PROPERTY_USAGE) != 0) {
HandleError("Bindgroup usage property set multiple times"); HandleError("Bindgroup usage property set multiple times");
return; return;
@ -119,18 +119,18 @@ namespace backend {
const auto& layoutInfo = mLayout->GetBindingInfo(); const auto& layoutInfo = mLayout->GetBindingInfo();
for (size_t i = start, j = 0; i < start + count; ++i, ++j) { for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
nxt::BufferUsageBit requiredBit = nxt::BufferUsageBit::None; dawn::BufferUsageBit requiredBit = dawn::BufferUsageBit::None;
switch (layoutInfo.types[i]) { switch (layoutInfo.types[i]) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
requiredBit = nxt::BufferUsageBit::Uniform; requiredBit = dawn::BufferUsageBit::Uniform;
break; break;
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
requiredBit = nxt::BufferUsageBit::Storage; requiredBit = dawn::BufferUsageBit::Storage;
break; break;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
HandleError("Setting buffer for a wrong binding type"); HandleError("Setting buffer for a wrong binding type");
return; return;
} }
@ -158,7 +158,7 @@ namespace backend {
const auto& layoutInfo = mLayout->GetBindingInfo(); const auto& layoutInfo = mLayout->GetBindingInfo();
for (size_t i = start, j = 0; i < start + count; ++i, ++j) { for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
if (layoutInfo.types[i] != nxt::BindingType::Sampler) { if (layoutInfo.types[i] != dawn::BindingType::Sampler) {
HandleError("Setting binding for a wrong layout binding type"); HandleError("Setting binding for a wrong layout binding type");
return; return;
} }
@ -176,13 +176,13 @@ namespace backend {
const auto& layoutInfo = mLayout->GetBindingInfo(); const auto& layoutInfo = mLayout->GetBindingInfo();
for (size_t i = start, j = 0; i < start + count; ++i, ++j) { for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
if (layoutInfo.types[i] != nxt::BindingType::SampledTexture) { if (layoutInfo.types[i] != dawn::BindingType::SampledTexture) {
HandleError("Setting binding for a wrong layout binding type"); HandleError("Setting binding for a wrong layout binding type");
return; return;
} }
if (!(textureViews[j]->GetTexture()->GetAllowedUsage() & if (!(textureViews[j]->GetTexture()->GetAllowedUsage() &
nxt::TextureUsageBit::Sampled)) { dawn::TextureUsageBit::Sampled)) {
HandleError("Texture needs to allow the sampled usage bit"); HandleError("Texture needs to allow the sampled usage bit");
return; return;
} }

View File

@ -34,7 +34,7 @@ namespace backend {
BindGroupBase(BindGroupBuilder* builder); BindGroupBase(BindGroupBuilder* builder);
const BindGroupLayoutBase* GetLayout() const; const BindGroupLayoutBase* GetLayout() const;
nxt::BindGroupUsage GetUsage() const; dawn::BindGroupUsage GetUsage() const;
BufferViewBase* GetBindingAsBufferView(size_t binding); BufferViewBase* GetBindingAsBufferView(size_t binding);
SamplerBase* GetBindingAsSampler(size_t binding); SamplerBase* GetBindingAsSampler(size_t binding);
TextureViewBase* GetBindingAsTextureView(size_t binding); TextureViewBase* GetBindingAsTextureView(size_t binding);
@ -43,7 +43,7 @@ namespace backend {
private: private:
Ref<BindGroupLayoutBase> mLayout; Ref<BindGroupLayoutBase> mLayout;
nxt::BindGroupUsage mUsage; dawn::BindGroupUsage mUsage;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings; std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
}; };
@ -53,7 +53,7 @@ namespace backend {
// NXT API // NXT API
void SetLayout(BindGroupLayoutBase* layout); void SetLayout(BindGroupLayoutBase* layout);
void SetUsage(nxt::BindGroupUsage usage); void SetUsage(dawn::BindGroupUsage usage);
template <typename T> template <typename T>
void SetBufferViews(uint32_t start, uint32_t count, T* const* bufferViews) { void SetBufferViews(uint32_t start, uint32_t count, T* const* bufferViews) {
@ -87,7 +87,7 @@ namespace backend {
int mPropertiesSet = 0; int mPropertiesSet = 0;
Ref<BindGroupLayoutBase> mLayout; Ref<BindGroupLayoutBase> mLayout;
nxt::BindGroupUsage mUsage; dawn::BindGroupUsage mUsage;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings; std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
}; };

View File

@ -23,8 +23,9 @@
namespace backend { namespace backend {
MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase*, MaybeError ValidateBindGroupLayoutDescriptor(
const nxt::BindGroupLayoutDescriptor* descriptor) { DeviceBase*,
const dawn::BindGroupLayoutDescriptor* descriptor) {
NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr"); NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
std::bitset<kMaxBindingsPerGroup> bindingsSet; std::bitset<kMaxBindingsPerGroup> bindingsSet;
@ -72,7 +73,7 @@ namespace backend {
// BindGroupLayoutBase // BindGroupLayoutBase
BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device,
const nxt::BindGroupLayoutDescriptor* descriptor, const dawn::BindGroupLayoutDescriptor* descriptor,
bool blueprint) bool blueprint)
: mDevice(device), mIsBlueprint(blueprint) { : mDevice(device), mIsBlueprint(blueprint) {
for (uint32_t i = 0; i < descriptor->numBindings; ++i) { for (uint32_t i = 0; i < descriptor->numBindings; ++i) {

View File

@ -28,18 +28,18 @@
namespace backend { namespace backend {
MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase*, MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase*,
const nxt::BindGroupLayoutDescriptor* descriptor); const dawn::BindGroupLayoutDescriptor* descriptor);
class BindGroupLayoutBase : public RefCounted { class BindGroupLayoutBase : public RefCounted {
public: public:
BindGroupLayoutBase(DeviceBase* device, BindGroupLayoutBase(DeviceBase* device,
const nxt::BindGroupLayoutDescriptor* descriptor, const dawn::BindGroupLayoutDescriptor* descriptor,
bool blueprint = false); bool blueprint = false);
~BindGroupLayoutBase() override; ~BindGroupLayoutBase() override;
struct LayoutBindingInfo { struct LayoutBindingInfo {
std::array<nxt::ShaderStageBit, kMaxBindingsPerGroup> visibilities; std::array<dawn::ShaderStageBit, kMaxBindingsPerGroup> visibilities;
std::array<nxt::BindingType, kMaxBindingsPerGroup> types; std::array<dawn::BindingType, kMaxBindingsPerGroup> types;
std::bitset<kMaxBindingsPerGroup> mask; std::bitset<kMaxBindingsPerGroup> mask;
}; };
const LayoutBindingInfo& GetBindingInfo() const; const LayoutBindingInfo& GetBindingInfo() const;

View File

@ -54,9 +54,9 @@ namespace backend {
mBlendInfo.blendEnabled = blendEnabled; mBlendInfo.blendEnabled = blendEnabled;
} }
void BlendStateBuilder::SetAlphaBlend(nxt::BlendOperation blendOperation, void BlendStateBuilder::SetAlphaBlend(dawn::BlendOperation blendOperation,
nxt::BlendFactor srcFactor, dawn::BlendFactor srcFactor,
nxt::BlendFactor dstFactor) { dawn::BlendFactor dstFactor) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) { if ((mPropertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) {
HandleError("Alpha blend property set multiple times"); HandleError("Alpha blend property set multiple times");
return; return;
@ -67,9 +67,9 @@ namespace backend {
mBlendInfo.alphaBlend = {blendOperation, srcFactor, dstFactor}; mBlendInfo.alphaBlend = {blendOperation, srcFactor, dstFactor};
} }
void BlendStateBuilder::SetColorBlend(nxt::BlendOperation blendOperation, void BlendStateBuilder::SetColorBlend(dawn::BlendOperation blendOperation,
nxt::BlendFactor srcFactor, dawn::BlendFactor srcFactor,
nxt::BlendFactor dstFactor) { dawn::BlendFactor dstFactor) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) { if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) {
HandleError("Color blend property set multiple times"); HandleError("Color blend property set multiple times");
return; return;
@ -80,7 +80,7 @@ namespace backend {
mBlendInfo.colorBlend = {blendOperation, srcFactor, dstFactor}; mBlendInfo.colorBlend = {blendOperation, srcFactor, dstFactor};
} }
void BlendStateBuilder::SetColorWriteMask(nxt::ColorWriteMask colorWriteMask) { void BlendStateBuilder::SetColorWriteMask(dawn::ColorWriteMask colorWriteMask) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_WRITE_MASK) != 0) { if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_WRITE_MASK) != 0) {
HandleError("Color write mask property set multiple times"); HandleError("Color write mask property set multiple times");
return; return;

View File

@ -29,15 +29,15 @@ namespace backend {
struct BlendInfo { struct BlendInfo {
struct BlendOpFactor { struct BlendOpFactor {
nxt::BlendOperation operation = nxt::BlendOperation::Add; dawn::BlendOperation operation = dawn::BlendOperation::Add;
nxt::BlendFactor srcFactor = nxt::BlendFactor::One; dawn::BlendFactor srcFactor = dawn::BlendFactor::One;
nxt::BlendFactor dstFactor = nxt::BlendFactor::Zero; dawn::BlendFactor dstFactor = dawn::BlendFactor::Zero;
}; };
bool blendEnabled = false; bool blendEnabled = false;
BlendOpFactor alphaBlend; BlendOpFactor alphaBlend;
BlendOpFactor colorBlend; BlendOpFactor colorBlend;
nxt::ColorWriteMask colorWriteMask = nxt::ColorWriteMask::All; dawn::ColorWriteMask colorWriteMask = dawn::ColorWriteMask::All;
}; };
const BlendInfo& GetBlendInfo() const; const BlendInfo& GetBlendInfo() const;
@ -52,13 +52,13 @@ namespace backend {
// NXT API // NXT API
void SetBlendEnabled(bool blendEnabled); void SetBlendEnabled(bool blendEnabled);
void SetAlphaBlend(nxt::BlendOperation blendOperation, void SetAlphaBlend(dawn::BlendOperation blendOperation,
nxt::BlendFactor srcFactor, dawn::BlendFactor srcFactor,
nxt::BlendFactor dstFactor); dawn::BlendFactor dstFactor);
void SetColorBlend(nxt::BlendOperation blendOperation, void SetColorBlend(dawn::BlendOperation blendOperation,
nxt::BlendFactor srcFactor, dawn::BlendFactor srcFactor,
nxt::BlendFactor dstFactor); dawn::BlendFactor dstFactor);
void SetColorWriteMask(nxt::ColorWriteMask colorWriteMask); void SetColorWriteMask(dawn::ColorWriteMask colorWriteMask);
private: private:
friend class BlendStateBase; friend class BlendStateBase;

View File

@ -47,7 +47,7 @@ namespace backend {
return mSize; return mSize;
} }
nxt::BufferUsageBit BufferBase::GetAllowedUsage() const { dawn::BufferUsageBit BufferBase::GetAllowedUsage() const {
return mAllowedUsage; return mAllowedUsage;
} }
@ -83,7 +83,7 @@ namespace backend {
return; return;
} }
if (!(mAllowedUsage & nxt::BufferUsageBit::TransferDst)) { if (!(mAllowedUsage & dawn::BufferUsageBit::TransferDst)) {
mDevice->HandleError("Buffer needs the transfer dst usage bit"); mDevice->HandleError("Buffer needs the transfer dst usage bit");
return; return;
} }
@ -95,7 +95,7 @@ namespace backend {
uint32_t size, uint32_t size,
nxtBufferMapReadCallback callback, nxtBufferMapReadCallback callback,
nxtCallbackUserdata userdata) { nxtCallbackUserdata userdata) {
if (!ValidateMapBase(start, size, nxt::BufferUsageBit::MapRead)) { if (!ValidateMapBase(start, size, dawn::BufferUsageBit::MapRead)) {
callback(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata); callback(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return; return;
} }
@ -115,7 +115,7 @@ namespace backend {
uint32_t size, uint32_t size,
nxtBufferMapWriteCallback callback, nxtBufferMapWriteCallback callback,
nxtCallbackUserdata userdata) { nxtCallbackUserdata userdata) {
if (!ValidateMapBase(start, size, nxt::BufferUsageBit::MapWrite)) { if (!ValidateMapBase(start, size, dawn::BufferUsageBit::MapWrite)) {
callback(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata); callback(NXT_BUFFER_MAP_ASYNC_STATUS_ERROR, nullptr, userdata);
return; return;
} }
@ -150,7 +150,7 @@ namespace backend {
bool BufferBase::ValidateMapBase(uint32_t start, bool BufferBase::ValidateMapBase(uint32_t start,
uint32_t size, uint32_t size,
nxt::BufferUsageBit requiredUsage) { dawn::BufferUsageBit requiredUsage) {
// TODO(cwallez@chromium.org): check for overflows. // TODO(cwallez@chromium.org): check for overflows.
if (start + size > GetSize()) { if (start + size > GetSize()) {
mDevice->HandleError("Buffer map read out of range"); mDevice->HandleError("Buffer map read out of range");
@ -187,17 +187,17 @@ namespace backend {
return nullptr; return nullptr;
} }
const nxt::BufferUsageBit kMapWriteAllowedUsages = const dawn::BufferUsageBit kMapWriteAllowedUsages =
nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc; dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferSrc;
if (mAllowedUsage & nxt::BufferUsageBit::MapWrite && if (mAllowedUsage & dawn::BufferUsageBit::MapWrite &&
(mAllowedUsage & kMapWriteAllowedUsages) != mAllowedUsage) { (mAllowedUsage & kMapWriteAllowedUsages) != mAllowedUsage) {
HandleError("Only TransferSrc is allowed with MapWrite"); HandleError("Only TransferSrc is allowed with MapWrite");
return nullptr; return nullptr;
} }
const nxt::BufferUsageBit kMapReadAllowedUsages = const dawn::BufferUsageBit kMapReadAllowedUsages =
nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst; dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
if (mAllowedUsage & nxt::BufferUsageBit::MapRead && if (mAllowedUsage & dawn::BufferUsageBit::MapRead &&
(mAllowedUsage & kMapReadAllowedUsages) != mAllowedUsage) { (mAllowedUsage & kMapReadAllowedUsages) != mAllowedUsage) {
HandleError("Only TransferDst is allowed with MapRead"); HandleError("Only TransferDst is allowed with MapRead");
return nullptr; return nullptr;
@ -206,7 +206,7 @@ namespace backend {
return mDevice->CreateBuffer(this); return mDevice->CreateBuffer(this);
} }
void BufferBuilder::SetAllowedUsage(nxt::BufferUsageBit usage) { void BufferBuilder::SetAllowedUsage(dawn::BufferUsageBit usage) {
if ((mPropertiesSet & BUFFER_PROPERTY_ALLOWED_USAGE) != 0) { if ((mPropertiesSet & BUFFER_PROPERTY_ALLOWED_USAGE) != 0) {
HandleError("Buffer allowedUsage property set multiple times"); HandleError("Buffer allowedUsage property set multiple times");
return; return;

View File

@ -23,13 +23,13 @@
namespace backend { namespace backend {
static constexpr nxt::BufferUsageBit kReadOnlyBufferUsages = static constexpr dawn::BufferUsageBit kReadOnlyBufferUsages =
nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferSrc |
nxt::BufferUsageBit::Index | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Uniform; dawn::BufferUsageBit::Index | dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Uniform;
static constexpr nxt::BufferUsageBit kWritableBufferUsages = nxt::BufferUsageBit::MapWrite | static constexpr dawn::BufferUsageBit kWritableBufferUsages =
nxt::BufferUsageBit::TransferDst | dawn::BufferUsageBit::MapWrite | dawn::BufferUsageBit::TransferDst |
nxt::BufferUsageBit::Storage; dawn::BufferUsageBit::Storage;
class BufferBase : public RefCounted { class BufferBase : public RefCounted {
public: public:
@ -37,7 +37,7 @@ namespace backend {
~BufferBase(); ~BufferBase();
uint32_t GetSize() const; uint32_t GetSize() const;
nxt::BufferUsageBit GetAllowedUsage() const; dawn::BufferUsageBit GetAllowedUsage() const;
DeviceBase* GetDevice() const; DeviceBase* GetDevice() const;
@ -66,11 +66,11 @@ namespace backend {
virtual void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0; virtual void MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
virtual void UnmapImpl() = 0; virtual void UnmapImpl() = 0;
bool ValidateMapBase(uint32_t start, uint32_t size, nxt::BufferUsageBit requiredUsage); bool ValidateMapBase(uint32_t start, uint32_t size, dawn::BufferUsageBit requiredUsage);
DeviceBase* mDevice; DeviceBase* mDevice;
uint32_t mSize; uint32_t mSize;
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None; dawn::BufferUsageBit mAllowedUsage = dawn::BufferUsageBit::None;
nxtBufferMapReadCallback mMapReadCallback = nullptr; nxtBufferMapReadCallback mMapReadCallback = nullptr;
nxtBufferMapWriteCallback mMapWriteCallback = nullptr; nxtBufferMapWriteCallback mMapWriteCallback = nullptr;
@ -85,8 +85,8 @@ namespace backend {
BufferBuilder(DeviceBase* device); BufferBuilder(DeviceBase* device);
// NXT API // NXT API
void SetAllowedUsage(nxt::BufferUsageBit usage); void SetAllowedUsage(dawn::BufferUsageBit usage);
void SetInitialUsage(nxt::BufferUsageBit usage); void SetInitialUsage(dawn::BufferUsageBit usage);
void SetSize(uint32_t size); void SetSize(uint32_t size);
private: private:
@ -95,8 +95,8 @@ namespace backend {
BufferBase* GetResultImpl() override; BufferBase* GetResultImpl() override;
uint32_t mSize; uint32_t mSize;
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None; dawn::BufferUsageBit mAllowedUsage = dawn::BufferUsageBit::None;
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None; dawn::BufferUsageBit mCurrentUsage = dawn::BufferUsageBit::None;
int mPropertiesSet = 0; int mPropertiesSet = 0;
}; };

View File

@ -28,12 +28,12 @@ namespace backend {
} }
void BuilderBase::HandleError(const char* message) { void BuilderBase::HandleError(const char* message) {
SetStatus(nxt::BuilderErrorStatus::Error, message); SetStatus(dawn::BuilderErrorStatus::Error, message);
} }
void BuilderBase::SetErrorCallback(nxt::BuilderErrorCallback callback, void BuilderBase::SetErrorCallback(dawn::BuilderErrorCallback callback,
nxt::CallbackUserdata userdata1, dawn::CallbackUserdata userdata1,
nxt::CallbackUserdata userdata2) { dawn::CallbackUserdata userdata2) {
mCallback = callback; mCallback = callback;
mUserdata1 = userdata1; mUserdata1 = userdata1;
mUserdata2 = userdata2; mUserdata2 = userdata2;
@ -49,9 +49,9 @@ namespace backend {
} }
} }
void BuilderBase::SetStatus(nxt::BuilderErrorStatus status, const char* message) { void BuilderBase::SetStatus(dawn::BuilderErrorStatus status, const char* message) {
ASSERT(status != nxt::BuilderErrorStatus::Success); ASSERT(status != dawn::BuilderErrorStatus::Success);
ASSERT(status != nxt::BuilderErrorStatus::Unknown); ASSERT(status != dawn::BuilderErrorStatus::Unknown);
ASSERT(!mGotStatus); // This is not strictly necessary but something to strive for. ASSERT(!mGotStatus); // This is not strictly necessary but something to strive for.
mGotStatus = true; mGotStatus = true;
@ -69,7 +69,7 @@ namespace backend {
// If we have any error, then we have to return nullptr // If we have any error, then we have to return nullptr
if (mGotStatus) { if (mGotStatus) {
ASSERT(mStoredStatus != nxt::BuilderErrorStatus::Success); ASSERT(mStoredStatus != dawn::BuilderErrorStatus::Success);
// The application will never see "result" so we need to remove the // The application will never see "result" so we need to remove the
// external ref here. // external ref here.
@ -82,7 +82,7 @@ namespace backend {
if (!mCallback) if (!mCallback)
mDevice->HandleError(("Unhandled builder error: " + mStoredMessage).c_str()); mDevice->HandleError(("Unhandled builder error: " + mStoredMessage).c_str());
} else { } else {
ASSERT(mStoredStatus == nxt::BuilderErrorStatus::Success); ASSERT(mStoredStatus == dawn::BuilderErrorStatus::Success);
ASSERT(mStoredMessage.empty()); ASSERT(mStoredMessage.empty());
} }

View File

@ -50,9 +50,9 @@ namespace backend {
bool HandleResult(RefCounted* result); bool HandleResult(RefCounted* result);
// NXT API // NXT API
void SetErrorCallback(nxt::BuilderErrorCallback callback, void SetErrorCallback(dawn::BuilderErrorCallback callback,
nxt::CallbackUserdata userdata1, dawn::CallbackUserdata userdata1,
nxt::CallbackUserdata userdata2); dawn::CallbackUserdata userdata2);
protected: protected:
BuilderBase(DeviceBase* device); BuilderBase(DeviceBase* device);
@ -62,13 +62,13 @@ namespace backend {
bool mGotStatus = false; bool mGotStatus = false;
private: private:
void SetStatus(nxt::BuilderErrorStatus status, const char* message); void SetStatus(dawn::BuilderErrorStatus status, const char* message);
nxt::BuilderErrorCallback mCallback = nullptr; dawn::BuilderErrorCallback mCallback = nullptr;
nxt::CallbackUserdata mUserdata1 = 0; dawn::CallbackUserdata mUserdata1 = 0;
nxt::CallbackUserdata mUserdata2 = 0; dawn::CallbackUserdata mUserdata2 = 0;
nxt::BuilderErrorStatus mStoredStatus = nxt::BuilderErrorStatus::Success; dawn::BuilderErrorStatus mStoredStatus = dawn::BuilderErrorStatus::Success;
std::string mStoredMessage; std::string mStoredMessage;
bool mIsConsumed = false; bool mIsConsumed = false;

View File

@ -109,7 +109,7 @@ namespace backend {
return {}; return {};
} }
MaybeError ValidateCanUseAs(BufferBase* buffer, nxt::BufferUsageBit usage) { MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsageBit usage) {
ASSERT(HasZeroOrOneBits(usage)); ASSERT(HasZeroOrOneBits(usage));
if (!(buffer->GetAllowedUsage() & usage)) { if (!(buffer->GetAllowedUsage() & usage)) {
NXT_RETURN_ERROR("buffer doesn't have the required usage."); NXT_RETURN_ERROR("buffer doesn't have the required usage.");
@ -118,7 +118,7 @@ namespace backend {
return {}; return {};
} }
MaybeError ValidateCanUseAs(TextureBase* texture, nxt::TextureUsageBit usage) { MaybeError ValidateCanUseAs(TextureBase* texture, dawn::TextureUsageBit usage) {
ASSERT(HasZeroOrOneBits(usage)); ASSERT(HasZeroOrOneBits(usage));
if (!(texture->GetAllowedUsage() & usage)) { if (!(texture->GetAllowedUsage() & usage)) {
NXT_RETURN_ERROR("texture doesn't have the required usage."); NXT_RETURN_ERROR("texture doesn't have the required usage.");
@ -138,26 +138,26 @@ namespace backend {
// information. // information.
class PassResourceUsageTracker { class PassResourceUsageTracker {
public: public:
void BufferUsedAs(BufferBase* buffer, nxt::BufferUsageBit usage) { void BufferUsedAs(BufferBase* buffer, dawn::BufferUsageBit usage) {
// std::map's operator[] will create the key and return 0 if the key didn't exist // std::map's operator[] will create the key and return 0 if the key didn't exist
// before. // before.
nxt::BufferUsageBit& storedUsage = mBufferUsages[buffer]; dawn::BufferUsageBit& storedUsage = mBufferUsages[buffer];
if (usage == nxt::BufferUsageBit::Storage && if (usage == dawn::BufferUsageBit::Storage &&
storedUsage & nxt::BufferUsageBit::Storage) { storedUsage & dawn::BufferUsageBit::Storage) {
mStorageUsedMultipleTimes = true; mStorageUsedMultipleTimes = true;
} }
storedUsage |= usage; storedUsage |= usage;
} }
void TextureUsedAs(TextureBase* texture, nxt::TextureUsageBit usage) { void TextureUsedAs(TextureBase* texture, dawn::TextureUsageBit usage) {
// std::map's operator[] will create the key and return 0 if the key didn't exist // std::map's operator[] will create the key and return 0 if the key didn't exist
// before. // before.
nxt::TextureUsageBit& storedUsage = mTextureUsages[texture]; dawn::TextureUsageBit& storedUsage = mTextureUsages[texture];
if (usage == nxt::TextureUsageBit::Storage && if (usage == dawn::TextureUsageBit::Storage &&
storedUsage & nxt::TextureUsageBit::Storage) { storedUsage & dawn::TextureUsageBit::Storage) {
mStorageUsedMultipleTimes = true; mStorageUsedMultipleTimes = true;
} }
@ -174,14 +174,14 @@ namespace backend {
// Buffers can only be used as single-write or multiple read. // Buffers can only be used as single-write or multiple read.
for (auto& it : mBufferUsages) { for (auto& it : mBufferUsages) {
BufferBase* buffer = it.first; BufferBase* buffer = it.first;
nxt::BufferUsageBit usage = it.second; dawn::BufferUsageBit usage = it.second;
if (usage & ~buffer->GetAllowedUsage()) { if (usage & ~buffer->GetAllowedUsage()) {
NXT_RETURN_ERROR("Buffer missing usage for the pass"); NXT_RETURN_ERROR("Buffer missing usage for the pass");
} }
bool readOnly = (usage & kReadOnlyBufferUsages) == usage; bool readOnly = (usage & kReadOnlyBufferUsages) == usage;
bool singleUse = nxt::HasZeroOrOneBits(usage); bool singleUse = dawn::HasZeroOrOneBits(usage);
if (!readOnly && !singleUse) { if (!readOnly && !singleUse) {
NXT_RETURN_ERROR( NXT_RETURN_ERROR(
@ -193,7 +193,7 @@ namespace backend {
// TODO(cwallez@chromium.org): implement per-subresource tracking // TODO(cwallez@chromium.org): implement per-subresource tracking
for (auto& it : mTextureUsages) { for (auto& it : mTextureUsages) {
TextureBase* texture = it.first; TextureBase* texture = it.first;
nxt::TextureUsageBit usage = it.second; dawn::TextureUsageBit usage = it.second;
if (usage & ~texture->GetAllowedUsage()) { if (usage & ~texture->GetAllowedUsage()) {
NXT_RETURN_ERROR("Texture missing usage for the pass"); NXT_RETURN_ERROR("Texture missing usage for the pass");
@ -201,7 +201,7 @@ namespace backend {
// For textures the only read-only usage in a pass is Sampled, so checking the // For textures the only read-only usage in a pass is Sampled, so checking the
// usage constraint simplifies to checking a single usage bit is set. // usage constraint simplifies to checking a single usage bit is set.
if (!nxt::HasZeroOrOneBits(it.second)) { if (!dawn::HasZeroOrOneBits(it.second)) {
NXT_RETURN_ERROR("Texture used with more than one usage in pass"); NXT_RETURN_ERROR("Texture used with more than one usage in pass");
} }
} }
@ -231,8 +231,8 @@ namespace backend {
} }
private: private:
std::map<BufferBase*, nxt::BufferUsageBit> mBufferUsages; std::map<BufferBase*, dawn::BufferUsageBit> mBufferUsages;
std::map<TextureBase*, nxt::TextureUsageBit> mTextureUsages; std::map<TextureBase*, dawn::TextureUsageBit> mTextureUsages;
bool mStorageUsedMultipleTimes = false; bool mStorageUsedMultipleTimes = false;
}; };
@ -240,25 +240,25 @@ namespace backend {
const auto& layoutInfo = group->GetLayout()->GetBindingInfo(); const auto& layoutInfo = group->GetLayout()->GetBindingInfo();
for (uint32_t i : IterateBitSet(layoutInfo.mask)) { for (uint32_t i : IterateBitSet(layoutInfo.mask)) {
nxt::BindingType type = layoutInfo.types[i]; dawn::BindingType type = layoutInfo.types[i];
switch (type) { switch (type) {
case nxt::BindingType::UniformBuffer: { case dawn::BindingType::UniformBuffer: {
BufferBase* buffer = group->GetBindingAsBufferView(i)->GetBuffer(); BufferBase* buffer = group->GetBindingAsBufferView(i)->GetBuffer();
tracker->BufferUsedAs(buffer, nxt::BufferUsageBit::Uniform); tracker->BufferUsedAs(buffer, dawn::BufferUsageBit::Uniform);
} break; } break;
case nxt::BindingType::StorageBuffer: { case dawn::BindingType::StorageBuffer: {
BufferBase* buffer = group->GetBindingAsBufferView(i)->GetBuffer(); BufferBase* buffer = group->GetBindingAsBufferView(i)->GetBuffer();
tracker->BufferUsedAs(buffer, nxt::BufferUsageBit::Storage); tracker->BufferUsedAs(buffer, dawn::BufferUsageBit::Storage);
} break; } break;
case nxt::BindingType::SampledTexture: { case dawn::BindingType::SampledTexture: {
TextureBase* texture = group->GetBindingAsTextureView(i)->GetTexture(); TextureBase* texture = group->GetBindingAsTextureView(i)->GetTexture();
tracker->TextureUsedAs(texture, nxt::TextureUsageBit::Sampled); tracker->TextureUsedAs(texture, dawn::TextureUsageBit::Sampled);
} break; } break;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
break; break;
} }
} }
@ -339,9 +339,9 @@ namespace backend {
NXT_TRY(ValidateCopySizeFitsInBuffer(copy->destination, copy->size)); NXT_TRY(ValidateCopySizeFitsInBuffer(copy->destination, copy->size));
NXT_TRY(ValidateCanUseAs(copy->source.buffer.Get(), NXT_TRY(ValidateCanUseAs(copy->source.buffer.Get(),
nxt::BufferUsageBit::TransferSrc)); dawn::BufferUsageBit::TransferSrc));
NXT_TRY(ValidateCanUseAs(copy->destination.buffer.Get(), NXT_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
nxt::BufferUsageBit::TransferDst)); dawn::BufferUsageBit::TransferDst));
} break; } break;
case Command::CopyBufferToTexture: { case Command::CopyBufferToTexture: {
@ -358,9 +358,9 @@ namespace backend {
ValidateTexelBufferOffset(copy->destination.texture.Get(), copy->source)); ValidateTexelBufferOffset(copy->destination.texture.Get(), copy->source));
NXT_TRY(ValidateCanUseAs(copy->source.buffer.Get(), NXT_TRY(ValidateCanUseAs(copy->source.buffer.Get(),
nxt::BufferUsageBit::TransferSrc)); dawn::BufferUsageBit::TransferSrc));
NXT_TRY(ValidateCanUseAs(copy->destination.texture.Get(), NXT_TRY(ValidateCanUseAs(copy->destination.texture.Get(),
nxt::TextureUsageBit::TransferDst)); dawn::TextureUsageBit::TransferDst));
} break; } break;
case Command::CopyTextureToBuffer: { case Command::CopyTextureToBuffer: {
@ -377,9 +377,9 @@ namespace backend {
ValidateTexelBufferOffset(copy->source.texture.Get(), copy->destination)); ValidateTexelBufferOffset(copy->source.texture.Get(), copy->destination));
NXT_TRY(ValidateCanUseAs(copy->source.texture.Get(), NXT_TRY(ValidateCanUseAs(copy->source.texture.Get(),
nxt::TextureUsageBit::TransferSrc)); dawn::TextureUsageBit::TransferSrc));
NXT_TRY(ValidateCanUseAs(copy->destination.buffer.Get(), NXT_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
nxt::BufferUsageBit::TransferDst)); dawn::BufferUsageBit::TransferDst));
} break; } break;
default: default:
@ -423,7 +423,7 @@ namespace backend {
// Validation of count and offset has already been done when the command was // Validation of count and offset has already been done when the command was
// recorded because it impacts the size of an allocation in the // recorded because it impacts the size of an allocation in the
// CommandAllocator. // CommandAllocator.
if (cmd->stages & ~nxt::ShaderStageBit::Compute) { if (cmd->stages & ~dawn::ShaderStageBit::Compute) {
NXT_RETURN_ERROR( NXT_RETURN_ERROR(
"SetPushConstants stage must be compute or 0 in compute passes"); "SetPushConstants stage must be compute or 0 in compute passes");
} }
@ -450,12 +450,12 @@ namespace backend {
// Track usage of the render pass attachments // Track usage of the render pass attachments
for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) { for (uint32_t i : IterateBitSet(renderPass->GetColorAttachmentMask())) {
TextureBase* texture = renderPass->GetColorAttachment(i).view->GetTexture(); TextureBase* texture = renderPass->GetColorAttachment(i).view->GetTexture();
usageTracker.TextureUsedAs(texture, nxt::TextureUsageBit::OutputAttachment); usageTracker.TextureUsedAs(texture, dawn::TextureUsageBit::OutputAttachment);
} }
if (renderPass->HasDepthStencilAttachment()) { if (renderPass->HasDepthStencilAttachment()) {
TextureBase* texture = renderPass->GetDepthStencilAttachment().view->GetTexture(); TextureBase* texture = renderPass->GetDepthStencilAttachment().view->GetTexture();
usageTracker.TextureUsedAs(texture, nxt::TextureUsageBit::OutputAttachment); usageTracker.TextureUsedAs(texture, dawn::TextureUsageBit::OutputAttachment);
} }
Command type; Command type;
@ -499,7 +499,7 @@ namespace backend {
// recorded because it impacts the size of an allocation in the // recorded because it impacts the size of an allocation in the
// CommandAllocator. // CommandAllocator.
if (cmd->stages & if (cmd->stages &
~(nxt::ShaderStageBit::Vertex | nxt::ShaderStageBit::Fragment)) { ~(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment)) {
NXT_RETURN_ERROR( NXT_RETURN_ERROR(
"SetPushConstants stage must be a subset of (vertex|fragment) in " "SetPushConstants stage must be a subset of (vertex|fragment) in "
"render passes"); "render passes");
@ -528,7 +528,7 @@ namespace backend {
case Command::SetIndexBuffer: { case Command::SetIndexBuffer: {
SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>(); SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>();
usageTracker.BufferUsedAs(cmd->buffer.Get(), nxt::BufferUsageBit::Index); usageTracker.BufferUsedAs(cmd->buffer.Get(), dawn::BufferUsageBit::Index);
NXT_TRY(mState->SetIndexBuffer()); NXT_TRY(mState->SetIndexBuffer());
} break; } break;
@ -538,7 +538,7 @@ namespace backend {
mIterator.NextData<uint32_t>(cmd->count); mIterator.NextData<uint32_t>(cmd->count);
for (uint32_t i = 0; i < cmd->count; ++i) { for (uint32_t i = 0; i < cmd->count; ++i) {
usageTracker.BufferUsedAs(buffers[i].Get(), nxt::BufferUsageBit::Vertex); usageTracker.BufferUsedAs(buffers[i].Get(), dawn::BufferUsageBit::Vertex);
NXT_TRY(mState->SetVertexBuffer(cmd->startSlot + i)); NXT_TRY(mState->SetVertexBuffer(cmd->startSlot + i));
} }
} break; } break;
@ -692,7 +692,7 @@ namespace backend {
cmd->pipeline = pipeline; cmd->pipeline = pipeline;
} }
void CommandBufferBuilder::SetPushConstants(nxt::ShaderStageBit stages, void CommandBufferBuilder::SetPushConstants(dawn::ShaderStageBit stages,
uint32_t offset, uint32_t offset,
uint32_t count, uint32_t count,
const void* data) { const void* data) {

View File

@ -101,7 +101,7 @@ namespace backend {
uint32_t firstInstance); uint32_t firstInstance);
void EndComputePass(); void EndComputePass();
void EndRenderPass(); void EndRenderPass();
void SetPushConstants(nxt::ShaderStageBit stages, void SetPushConstants(dawn::ShaderStageBit stages,
uint32_t offset, uint32_t offset,
uint32_t count, uint32_t count,
const void* data); const void* data);
@ -127,7 +127,7 @@ namespace backend {
BufferBase* const* buffers, BufferBase* const* buffers,
uint32_t const* offsets); uint32_t const* offsets);
void TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage); void TransitionBufferUsage(BufferBase* buffer, dawn::BufferUsageBit usage);
private: private:
friend class CommandBufferBase; friend class CommandBufferBase;

View File

@ -117,7 +117,7 @@ namespace backend {
}; };
struct SetPushConstantsCmd { struct SetPushConstantsCmd {
nxt::ShaderStageBit stages; dawn::ShaderStageBit stages;
uint32_t offset; uint32_t offset;
uint32_t count; uint32_t count;
}; };

View File

@ -22,7 +22,7 @@ namespace backend {
ComputePipelineBase::ComputePipelineBase(ComputePipelineBuilder* builder) ComputePipelineBase::ComputePipelineBase(ComputePipelineBuilder* builder)
: PipelineBase(builder) { : PipelineBase(builder) {
if (GetStageMask() != nxt::ShaderStageBit::Compute) { if (GetStageMask() != dawn::ShaderStageBit::Compute) {
builder->HandleError("Compute pipeline should have exactly a compute stage"); builder->HandleError("Compute pipeline should have exactly a compute stage");
return; return;
} }

View File

@ -25,14 +25,14 @@ namespace backend {
} }
bool DepthStencilStateBase::StencilTestEnabled() const { bool DepthStencilStateBase::StencilTestEnabled() const {
return mStencilInfo.back.compareFunction != nxt::CompareFunction::Always || return mStencilInfo.back.compareFunction != dawn::CompareFunction::Always ||
mStencilInfo.back.stencilFail != nxt::StencilOperation::Keep || mStencilInfo.back.stencilFail != dawn::StencilOperation::Keep ||
mStencilInfo.back.depthFail != nxt::StencilOperation::Keep || mStencilInfo.back.depthFail != dawn::StencilOperation::Keep ||
mStencilInfo.back.depthStencilPass != nxt::StencilOperation::Keep || mStencilInfo.back.depthStencilPass != dawn::StencilOperation::Keep ||
mStencilInfo.front.compareFunction != nxt::CompareFunction::Always || mStencilInfo.front.compareFunction != dawn::CompareFunction::Always ||
mStencilInfo.front.stencilFail != nxt::StencilOperation::Keep || mStencilInfo.front.stencilFail != dawn::StencilOperation::Keep ||
mStencilInfo.front.depthFail != nxt::StencilOperation::Keep || mStencilInfo.front.depthFail != dawn::StencilOperation::Keep ||
mStencilInfo.front.depthStencilPass != nxt::StencilOperation::Keep; mStencilInfo.front.depthStencilPass != dawn::StencilOperation::Keep;
} }
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const { const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
@ -61,7 +61,7 @@ namespace backend {
} }
void DepthStencilStateBuilder::SetDepthCompareFunction( void DepthStencilStateBuilder::SetDepthCompareFunction(
nxt::CompareFunction depthCompareFunction) { dawn::CompareFunction depthCompareFunction) {
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_DEPTH_COMPARE_FUNCTION) != 0) { if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_DEPTH_COMPARE_FUNCTION) != 0) {
HandleError("Depth compare property set multiple times"); HandleError("Depth compare property set multiple times");
return; return;
@ -83,17 +83,17 @@ namespace backend {
mDepthInfo.depthWriteEnabled = enabled; mDepthInfo.depthWriteEnabled = enabled;
} }
void DepthStencilStateBuilder::SetStencilFunction(nxt::Face face, void DepthStencilStateBuilder::SetStencilFunction(dawn::Face face,
nxt::CompareFunction stencilCompareFunction, dawn::CompareFunction stencilCompareFunction,
nxt::StencilOperation stencilFail, dawn::StencilOperation stencilFail,
nxt::StencilOperation depthFail, dawn::StencilOperation depthFail,
nxt::StencilOperation depthStencilPass) { dawn::StencilOperation depthStencilPass) {
if (face == nxt::Face::None) { if (face == dawn::Face::None) {
HandleError("Can't set stencil function of None face"); HandleError("Can't set stencil function of None face");
return; return;
} }
if (face & nxt::Face::Back) { if (face & dawn::Face::Back) {
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_BACK_FUNCTION) != 0) { if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_BACK_FUNCTION) != 0) {
HandleError("Stencil back function property set multiple times"); HandleError("Stencil back function property set multiple times");
return; return;
@ -106,7 +106,7 @@ namespace backend {
mStencilInfo.back.depthFail = depthFail; mStencilInfo.back.depthFail = depthFail;
mStencilInfo.back.depthStencilPass = depthStencilPass; mStencilInfo.back.depthStencilPass = depthStencilPass;
} }
if (face & nxt::Face::Front) { if (face & dawn::Face::Front) {
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_FRONT_FUNCTION) != 0) { if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_FRONT_FUNCTION) != 0) {
HandleError("Stencil front function property set multiple times"); HandleError("Stencil front function property set multiple times");
return; return;

View File

@ -28,15 +28,15 @@ namespace backend {
DepthStencilStateBase(DepthStencilStateBuilder* builder); DepthStencilStateBase(DepthStencilStateBuilder* builder);
struct DepthInfo { struct DepthInfo {
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always; dawn::CompareFunction compareFunction = dawn::CompareFunction::Always;
bool depthWriteEnabled = false; bool depthWriteEnabled = false;
}; };
struct StencilFaceInfo { struct StencilFaceInfo {
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always; dawn::CompareFunction compareFunction = dawn::CompareFunction::Always;
nxt::StencilOperation stencilFail = nxt::StencilOperation::Keep; dawn::StencilOperation stencilFail = dawn::StencilOperation::Keep;
nxt::StencilOperation depthFail = nxt::StencilOperation::Keep; dawn::StencilOperation depthFail = dawn::StencilOperation::Keep;
nxt::StencilOperation depthStencilPass = nxt::StencilOperation::Keep; dawn::StencilOperation depthStencilPass = dawn::StencilOperation::Keep;
}; };
struct StencilInfo { struct StencilInfo {
@ -60,13 +60,13 @@ namespace backend {
DepthStencilStateBuilder(DeviceBase* device); DepthStencilStateBuilder(DeviceBase* device);
// NXT API // NXT API
void SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction); void SetDepthCompareFunction(dawn::CompareFunction depthCompareFunction);
void SetDepthWriteEnabled(bool enabled); void SetDepthWriteEnabled(bool enabled);
void SetStencilFunction(nxt::Face face, void SetStencilFunction(dawn::Face face,
nxt::CompareFunction stencilCompareFunction, dawn::CompareFunction stencilCompareFunction,
nxt::StencilOperation stencilFail, dawn::StencilOperation stencilFail,
nxt::StencilOperation depthFail, dawn::StencilOperation depthFail,
nxt::StencilOperation depthStencilPass); dawn::StencilOperation depthStencilPass);
void SetStencilMask(uint32_t readMask, uint32_t writeMask); void SetStencilMask(uint32_t readMask, uint32_t writeMask);
private: private:

View File

@ -63,8 +63,8 @@ namespace backend {
} }
} }
void DeviceBase::SetErrorCallback(nxt::DeviceErrorCallback callback, void DeviceBase::SetErrorCallback(dawn::DeviceErrorCallback callback,
nxt::CallbackUserdata userdata) { dawn::CallbackUserdata userdata) {
mErrorCallback = callback; mErrorCallback = callback;
mErrorUserdata = userdata; mErrorUserdata = userdata;
} }
@ -74,7 +74,7 @@ namespace backend {
} }
ResultOrError<BindGroupLayoutBase*> DeviceBase::GetOrCreateBindGroupLayout( ResultOrError<BindGroupLayoutBase*> DeviceBase::GetOrCreateBindGroupLayout(
const nxt::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
BindGroupLayoutBase blueprint(this, descriptor, true); BindGroupLayoutBase blueprint(this, descriptor, true);
auto iter = mCaches->bindGroupLayouts.find(&blueprint); auto iter = mCaches->bindGroupLayouts.find(&blueprint);
@ -99,7 +99,7 @@ namespace backend {
return new BindGroupBuilder(this); return new BindGroupBuilder(this);
} }
BindGroupLayoutBase* DeviceBase::CreateBindGroupLayout( BindGroupLayoutBase* DeviceBase::CreateBindGroupLayout(
const nxt::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
BindGroupLayoutBase* result = nullptr; BindGroupLayoutBase* result = nullptr;
if (ConsumedError(CreateBindGroupLayoutInternal(&result, descriptor))) { if (ConsumedError(CreateBindGroupLayoutInternal(&result, descriptor))) {
@ -127,7 +127,7 @@ namespace backend {
return new InputStateBuilder(this); return new InputStateBuilder(this);
} }
PipelineLayoutBase* DeviceBase::CreatePipelineLayout( PipelineLayoutBase* DeviceBase::CreatePipelineLayout(
const nxt::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
PipelineLayoutBase* result = nullptr; PipelineLayoutBase* result = nullptr;
if (ConsumedError(CreatePipelineLayoutInternal(&result, descriptor))) { if (ConsumedError(CreatePipelineLayoutInternal(&result, descriptor))) {
@ -151,7 +151,7 @@ namespace backend {
RenderPipelineBuilder* DeviceBase::CreateRenderPipelineBuilder() { RenderPipelineBuilder* DeviceBase::CreateRenderPipelineBuilder() {
return new RenderPipelineBuilder(this); return new RenderPipelineBuilder(this);
} }
SamplerBase* DeviceBase::CreateSampler(const nxt::SamplerDescriptor* descriptor) { SamplerBase* DeviceBase::CreateSampler(const dawn::SamplerDescriptor* descriptor) {
SamplerBase* result = nullptr; SamplerBase* result = nullptr;
if (ConsumedError(CreateSamplerInternal(&result, descriptor))) { if (ConsumedError(CreateSamplerInternal(&result, descriptor))) {
@ -193,7 +193,7 @@ namespace backend {
MaybeError DeviceBase::CreateBindGroupLayoutInternal( MaybeError DeviceBase::CreateBindGroupLayoutInternal(
BindGroupLayoutBase** result, BindGroupLayoutBase** result,
const nxt::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
NXT_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor)); NXT_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor));
NXT_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(descriptor)); NXT_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(descriptor));
return {}; return {};
@ -201,7 +201,7 @@ namespace backend {
MaybeError DeviceBase::CreatePipelineLayoutInternal( MaybeError DeviceBase::CreatePipelineLayoutInternal(
PipelineLayoutBase** result, PipelineLayoutBase** result,
const nxt::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
NXT_TRY(ValidatePipelineLayoutDescriptor(this, descriptor)); NXT_TRY(ValidatePipelineLayoutDescriptor(this, descriptor));
NXT_TRY_ASSIGN(*result, CreatePipelineLayoutImpl(descriptor)); NXT_TRY_ASSIGN(*result, CreatePipelineLayoutImpl(descriptor));
return {}; return {};
@ -213,7 +213,7 @@ namespace backend {
} }
MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result, MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result,
const nxt::SamplerDescriptor* descriptor) { const dawn::SamplerDescriptor* descriptor) {
NXT_TRY(ValidateSamplerDescriptor(this, descriptor)); NXT_TRY(ValidateSamplerDescriptor(this, descriptor));
NXT_TRY_ASSIGN(*result, CreateSamplerImpl(descriptor)); NXT_TRY_ASSIGN(*result, CreateSamplerImpl(descriptor));
return {}; return {};

View File

@ -77,49 +77,49 @@ namespace backend {
// instead of a backend Foo object. If the blueprint doesn't match an object in the // instead of a backend Foo object. If the blueprint doesn't match an object in the
// cache, then the builder is used to make a new object. // cache, then the builder is used to make a new object.
ResultOrError<BindGroupLayoutBase*> GetOrCreateBindGroupLayout( ResultOrError<BindGroupLayoutBase*> GetOrCreateBindGroupLayout(
const nxt::BindGroupLayoutDescriptor* descriptor); const dawn::BindGroupLayoutDescriptor* descriptor);
void UncacheBindGroupLayout(BindGroupLayoutBase* obj); void UncacheBindGroupLayout(BindGroupLayoutBase* obj);
// NXT API // NXT API
BindGroupBuilder* CreateBindGroupBuilder(); BindGroupBuilder* CreateBindGroupBuilder();
BindGroupLayoutBase* CreateBindGroupLayout( BindGroupLayoutBase* CreateBindGroupLayout(
const nxt::BindGroupLayoutDescriptor* descriptor); const dawn::BindGroupLayoutDescriptor* descriptor);
BlendStateBuilder* CreateBlendStateBuilder(); BlendStateBuilder* CreateBlendStateBuilder();
BufferBuilder* CreateBufferBuilder(); BufferBuilder* CreateBufferBuilder();
CommandBufferBuilder* CreateCommandBufferBuilder(); CommandBufferBuilder* CreateCommandBufferBuilder();
ComputePipelineBuilder* CreateComputePipelineBuilder(); ComputePipelineBuilder* CreateComputePipelineBuilder();
DepthStencilStateBuilder* CreateDepthStencilStateBuilder(); DepthStencilStateBuilder* CreateDepthStencilStateBuilder();
InputStateBuilder* CreateInputStateBuilder(); InputStateBuilder* CreateInputStateBuilder();
PipelineLayoutBase* CreatePipelineLayout(const nxt::PipelineLayoutDescriptor* descriptor); PipelineLayoutBase* CreatePipelineLayout(const dawn::PipelineLayoutDescriptor* descriptor);
QueueBase* CreateQueue(); QueueBase* CreateQueue();
RenderPassDescriptorBuilder* CreateRenderPassDescriptorBuilder(); RenderPassDescriptorBuilder* CreateRenderPassDescriptorBuilder();
RenderPipelineBuilder* CreateRenderPipelineBuilder(); RenderPipelineBuilder* CreateRenderPipelineBuilder();
SamplerBase* CreateSampler(const nxt::SamplerDescriptor* descriptor); SamplerBase* CreateSampler(const dawn::SamplerDescriptor* descriptor);
ShaderModuleBuilder* CreateShaderModuleBuilder(); ShaderModuleBuilder* CreateShaderModuleBuilder();
SwapChainBuilder* CreateSwapChainBuilder(); SwapChainBuilder* CreateSwapChainBuilder();
TextureBuilder* CreateTextureBuilder(); TextureBuilder* CreateTextureBuilder();
void Tick(); void Tick();
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata); void SetErrorCallback(dawn::DeviceErrorCallback callback, dawn::CallbackUserdata userdata);
void Reference(); void Reference();
void Release(); void Release();
private: private:
virtual ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl( virtual ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) = 0; const dawn::BindGroupLayoutDescriptor* descriptor) = 0;
virtual ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl( virtual ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) = 0; const dawn::PipelineLayoutDescriptor* descriptor) = 0;
virtual ResultOrError<QueueBase*> CreateQueueImpl() = 0; virtual ResultOrError<QueueBase*> CreateQueueImpl() = 0;
virtual ResultOrError<SamplerBase*> CreateSamplerImpl( virtual ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) = 0; const dawn::SamplerDescriptor* descriptor) = 0;
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result, MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
const nxt::BindGroupLayoutDescriptor* descriptor); const dawn::BindGroupLayoutDescriptor* descriptor);
MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result, MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result,
const nxt::PipelineLayoutDescriptor* descriptor); const dawn::PipelineLayoutDescriptor* descriptor);
MaybeError CreateQueueInternal(QueueBase** result); MaybeError CreateQueueInternal(QueueBase** result);
MaybeError CreateSamplerInternal(SamplerBase** result, MaybeError CreateSamplerInternal(SamplerBase** result,
const nxt::SamplerDescriptor* descriptor); const dawn::SamplerDescriptor* descriptor);
void ConsumeError(ErrorData* error); void ConsumeError(ErrorData* error);
@ -128,8 +128,8 @@ namespace backend {
struct Caches; struct Caches;
Caches* mCaches = nullptr; Caches* mCaches = nullptr;
nxt::DeviceErrorCallback mErrorCallback = nullptr; dawn::DeviceErrorCallback mErrorCallback = nullptr;
nxt::CallbackUserdata mErrorUserdata = 0; dawn::CallbackUserdata mErrorUserdata = 0;
uint32_t mRefCount = 1; uint32_t mRefCount = 1;
}; };

View File

@ -21,64 +21,64 @@ namespace backend {
// InputState helpers // InputState helpers
size_t IndexFormatSize(nxt::IndexFormat format) { size_t IndexFormatSize(dawn::IndexFormat format) {
switch (format) { switch (format) {
case nxt::IndexFormat::Uint16: case dawn::IndexFormat::Uint16:
return sizeof(uint16_t); return sizeof(uint16_t);
case nxt::IndexFormat::Uint32: case dawn::IndexFormat::Uint32:
return sizeof(uint32_t); return sizeof(uint32_t);
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
uint32_t VertexFormatNumComponents(nxt::VertexFormat format) { uint32_t VertexFormatNumComponents(dawn::VertexFormat format) {
switch (format) { switch (format) {
case nxt::VertexFormat::FloatR32G32B32A32: case dawn::VertexFormat::FloatR32G32B32A32:
case nxt::VertexFormat::IntR32G32B32A32: case dawn::VertexFormat::IntR32G32B32A32:
case nxt::VertexFormat::UshortR16G16B16A16: case dawn::VertexFormat::UshortR16G16B16A16:
case nxt::VertexFormat::UnormR8G8B8A8: case dawn::VertexFormat::UnormR8G8B8A8:
return 4; return 4;
case nxt::VertexFormat::FloatR32G32B32: case dawn::VertexFormat::FloatR32G32B32:
case nxt::VertexFormat::IntR32G32B32: case dawn::VertexFormat::IntR32G32B32:
return 3; return 3;
case nxt::VertexFormat::FloatR32G32: case dawn::VertexFormat::FloatR32G32:
case nxt::VertexFormat::IntR32G32: case dawn::VertexFormat::IntR32G32:
case nxt::VertexFormat::UshortR16G16: case dawn::VertexFormat::UshortR16G16:
case nxt::VertexFormat::UnormR8G8: case dawn::VertexFormat::UnormR8G8:
return 2; return 2;
case nxt::VertexFormat::FloatR32: case dawn::VertexFormat::FloatR32:
case nxt::VertexFormat::IntR32: case dawn::VertexFormat::IntR32:
return 1; return 1;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
size_t VertexFormatComponentSize(nxt::VertexFormat format) { size_t VertexFormatComponentSize(dawn::VertexFormat format) {
switch (format) { switch (format) {
case nxt::VertexFormat::FloatR32G32B32A32: case dawn::VertexFormat::FloatR32G32B32A32:
case nxt::VertexFormat::FloatR32G32B32: case dawn::VertexFormat::FloatR32G32B32:
case nxt::VertexFormat::FloatR32G32: case dawn::VertexFormat::FloatR32G32:
case nxt::VertexFormat::FloatR32: case dawn::VertexFormat::FloatR32:
return sizeof(float); return sizeof(float);
case nxt::VertexFormat::IntR32G32B32A32: case dawn::VertexFormat::IntR32G32B32A32:
case nxt::VertexFormat::IntR32G32B32: case dawn::VertexFormat::IntR32G32B32:
case nxt::VertexFormat::IntR32G32: case dawn::VertexFormat::IntR32G32:
case nxt::VertexFormat::IntR32: case dawn::VertexFormat::IntR32:
return sizeof(int32_t); return sizeof(int32_t);
case nxt::VertexFormat::UshortR16G16B16A16: case dawn::VertexFormat::UshortR16G16B16A16:
case nxt::VertexFormat::UshortR16G16: case dawn::VertexFormat::UshortR16G16:
return sizeof(uint16_t); return sizeof(uint16_t);
case nxt::VertexFormat::UnormR8G8B8A8: case dawn::VertexFormat::UnormR8G8B8A8:
case nxt::VertexFormat::UnormR8G8: case dawn::VertexFormat::UnormR8G8:
return sizeof(uint8_t); return sizeof(uint8_t);
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
size_t VertexFormatSize(nxt::VertexFormat format) { size_t VertexFormatSize(dawn::VertexFormat format) {
return VertexFormatNumComponents(format) * VertexFormatComponentSize(format); return VertexFormatNumComponents(format) * VertexFormatComponentSize(format);
} }
@ -128,7 +128,7 @@ namespace backend {
void InputStateBuilder::SetAttribute(uint32_t shaderLocation, void InputStateBuilder::SetAttribute(uint32_t shaderLocation,
uint32_t bindingSlot, uint32_t bindingSlot,
nxt::VertexFormat format, dawn::VertexFormat format,
uint32_t offset) { uint32_t offset) {
if (shaderLocation >= kMaxVertexAttributes) { if (shaderLocation >= kMaxVertexAttributes) {
HandleError("Setting attribute out of bounds"); HandleError("Setting attribute out of bounds");
@ -152,7 +152,7 @@ namespace backend {
void InputStateBuilder::SetInput(uint32_t bindingSlot, void InputStateBuilder::SetInput(uint32_t bindingSlot,
uint32_t stride, uint32_t stride,
nxt::InputStepMode stepMode) { dawn::InputStepMode stepMode) {
if (bindingSlot >= kMaxVertexInputs) { if (bindingSlot >= kMaxVertexInputs) {
HandleError("Setting input out of bounds"); HandleError("Setting input out of bounds");
return; return;

View File

@ -27,10 +27,10 @@
namespace backend { namespace backend {
size_t IndexFormatSize(nxt::IndexFormat format); size_t IndexFormatSize(dawn::IndexFormat format);
uint32_t VertexFormatNumComponents(nxt::VertexFormat format); uint32_t VertexFormatNumComponents(dawn::VertexFormat format);
size_t VertexFormatComponentSize(nxt::VertexFormat format); size_t VertexFormatComponentSize(dawn::VertexFormat format);
size_t VertexFormatSize(nxt::VertexFormat format); size_t VertexFormatSize(dawn::VertexFormat format);
class InputStateBase : public RefCounted { class InputStateBase : public RefCounted {
public: public:
@ -38,13 +38,13 @@ namespace backend {
struct AttributeInfo { struct AttributeInfo {
uint32_t bindingSlot; uint32_t bindingSlot;
nxt::VertexFormat format; dawn::VertexFormat format;
uint32_t offset; uint32_t offset;
}; };
struct InputInfo { struct InputInfo {
uint32_t stride; uint32_t stride;
nxt::InputStepMode stepMode; dawn::InputStepMode stepMode;
}; };
const std::bitset<kMaxVertexAttributes>& GetAttributesSetMask() const; const std::bitset<kMaxVertexAttributes>& GetAttributesSetMask() const;
@ -66,9 +66,9 @@ namespace backend {
// NXT API // NXT API
void SetAttribute(uint32_t shaderLocation, void SetAttribute(uint32_t shaderLocation,
uint32_t bindingSlot, uint32_t bindingSlot,
nxt::VertexFormat format, dawn::VertexFormat format,
uint32_t offset); uint32_t offset);
void SetInput(uint32_t bindingSlot, uint32_t stride, nxt::InputStepMode stepMode); void SetInput(uint32_t bindingSlot, uint32_t stride, dawn::InputStepMode stepMode);
private: private:
friend class InputStateBase; friend class InputStateBase;

View File

@ -29,10 +29,10 @@ namespace backend {
// re-compute it. // re-compute it.
struct PassResourceUsage { struct PassResourceUsage {
std::vector<BufferBase*> buffers; std::vector<BufferBase*> buffers;
std::vector<nxt::BufferUsageBit> bufferUsages; std::vector<dawn::BufferUsageBit> bufferUsages;
std::vector<TextureBase*> textures; std::vector<TextureBase*> textures;
std::vector<nxt::TextureUsageBit> textureUsages; std::vector<dawn::TextureUsageBit> textureUsages;
}; };
} // namespace backend } // namespace backend

View File

@ -16,14 +16,14 @@
namespace backend { namespace backend {
BitSetIterator<kNumStages, nxt::ShaderStage> IterateStages(nxt::ShaderStageBit stages) { BitSetIterator<kNumStages, dawn::ShaderStage> IterateStages(dawn::ShaderStageBit stages) {
std::bitset<kNumStages> bits(static_cast<uint32_t>(stages)); std::bitset<kNumStages> bits(static_cast<uint32_t>(stages));
return BitSetIterator<kNumStages, nxt::ShaderStage>(bits); return BitSetIterator<kNumStages, dawn::ShaderStage>(bits);
} }
nxt::ShaderStageBit StageBit(nxt::ShaderStage stage) { dawn::ShaderStageBit StageBit(dawn::ShaderStage stage) {
ASSERT(static_cast<uint32_t>(stage) < kNumStages); ASSERT(static_cast<uint32_t>(stage) < kNumStages);
return static_cast<nxt::ShaderStageBit>(1 << static_cast<uint32_t>(stage)); return static_cast<dawn::ShaderStageBit>(1 << static_cast<uint32_t>(stage));
} }
} // namespace backend } // namespace backend

View File

@ -25,44 +25,44 @@
namespace backend { namespace backend {
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Vertex) < kNumStages, ""); static_assert(static_cast<uint32_t>(dawn::ShaderStage::Vertex) < kNumStages, "");
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Fragment) < kNumStages, ""); static_assert(static_cast<uint32_t>(dawn::ShaderStage::Fragment) < kNumStages, "");
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Compute) < kNumStages, ""); static_assert(static_cast<uint32_t>(dawn::ShaderStage::Compute) < kNumStages, "");
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Vertex) == static_assert(static_cast<uint32_t>(dawn::ShaderStageBit::Vertex) ==
(1 << static_cast<uint32_t>(nxt::ShaderStage::Vertex)), (1 << static_cast<uint32_t>(dawn::ShaderStage::Vertex)),
""); "");
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Fragment) == static_assert(static_cast<uint32_t>(dawn::ShaderStageBit::Fragment) ==
(1 << static_cast<uint32_t>(nxt::ShaderStage::Fragment)), (1 << static_cast<uint32_t>(dawn::ShaderStage::Fragment)),
""); "");
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Compute) == static_assert(static_cast<uint32_t>(dawn::ShaderStageBit::Compute) ==
(1 << static_cast<uint32_t>(nxt::ShaderStage::Compute)), (1 << static_cast<uint32_t>(dawn::ShaderStage::Compute)),
""); "");
BitSetIterator<kNumStages, nxt::ShaderStage> IterateStages(nxt::ShaderStageBit stages); BitSetIterator<kNumStages, dawn::ShaderStage> IterateStages(dawn::ShaderStageBit stages);
nxt::ShaderStageBit StageBit(nxt::ShaderStage stage); dawn::ShaderStageBit StageBit(dawn::ShaderStage stage);
static constexpr nxt::ShaderStageBit kAllStages = static constexpr dawn::ShaderStageBit kAllStages =
static_cast<nxt::ShaderStageBit>((1 << kNumStages) - 1); static_cast<dawn::ShaderStageBit>((1 << kNumStages) - 1);
template <typename T> template <typename T>
class PerStage { class PerStage {
public: public:
T& operator[](nxt::ShaderStage stage) { T& operator[](dawn::ShaderStage stage) {
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages); NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
return mData[static_cast<uint32_t>(stage)]; return mData[static_cast<uint32_t>(stage)];
} }
const T& operator[](nxt::ShaderStage stage) const { const T& operator[](dawn::ShaderStage stage) const {
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages); NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
return mData[static_cast<uint32_t>(stage)]; return mData[static_cast<uint32_t>(stage)];
} }
T& operator[](nxt::ShaderStageBit stageBit) { T& operator[](dawn::ShaderStageBit stageBit) {
uint32_t bit = static_cast<uint32_t>(stageBit); uint32_t bit = static_cast<uint32_t>(stageBit);
NXT_ASSERT(bit != 0 && IsPowerOfTwo(bit) && bit <= (1 << kNumStages)); NXT_ASSERT(bit != 0 && IsPowerOfTwo(bit) && bit <= (1 << kNumStages));
return mData[Log2(bit)]; return mData[Log2(bit)];
} }
const T& operator[](nxt::ShaderStageBit stageBit) const { const T& operator[](dawn::ShaderStageBit stageBit) const {
uint32_t bit = static_cast<uint32_t>(stageBit); uint32_t bit = static_cast<uint32_t>(stageBit);
NXT_ASSERT(bit != 0 && IsPowerOfTwo(bit) && bit <= (1 << kNumStages)); NXT_ASSERT(bit != 0 && IsPowerOfTwo(bit) && bit <= (1 << kNumStages));
return mData[Log2(bit)]; return mData[Log2(bit)];

View File

@ -27,7 +27,7 @@ namespace backend {
PipelineBase::PipelineBase(PipelineBuilder* builder) PipelineBase::PipelineBase(PipelineBuilder* builder)
: mStageMask(builder->mStageMask), mLayout(std::move(builder->mLayout)) { : mStageMask(builder->mStageMask), mLayout(std::move(builder->mLayout)) {
if (!mLayout) { if (!mLayout) {
nxt::PipelineLayoutDescriptor descriptor; dawn::PipelineLayoutDescriptor descriptor;
descriptor.numBindGroupLayouts = 0; descriptor.numBindGroupLayouts = 0;
descriptor.bindGroupLayouts = nullptr; descriptor.bindGroupLayouts = nullptr;
mLayout = builder->GetParentBuilder()->GetDevice()->CreatePipelineLayout(&descriptor); mLayout = builder->GetParentBuilder()->GetDevice()->CreatePipelineLayout(&descriptor);
@ -63,11 +63,11 @@ namespace backend {
} }
const PipelineBase::PushConstantInfo& PipelineBase::GetPushConstants( const PipelineBase::PushConstantInfo& PipelineBase::GetPushConstants(
nxt::ShaderStage stage) const { dawn::ShaderStage stage) const {
return mPushConstants[stage]; return mPushConstants[stage];
} }
nxt::ShaderStageBit PipelineBase::GetStageMask() const { dawn::ShaderStageBit PipelineBase::GetStageMask() const {
return mStageMask; return mStageMask;
} }
@ -78,10 +78,10 @@ namespace backend {
// PipelineBuilder // PipelineBuilder
PipelineBuilder::PipelineBuilder(BuilderBase* parentBuilder) PipelineBuilder::PipelineBuilder(BuilderBase* parentBuilder)
: mParentBuilder(parentBuilder), mStageMask(static_cast<nxt::ShaderStageBit>(0)) { : mParentBuilder(parentBuilder), mStageMask(static_cast<dawn::ShaderStageBit>(0)) {
} }
const PipelineBuilder::StageInfo& PipelineBuilder::GetStageInfo(nxt::ShaderStage stage) const { const PipelineBuilder::StageInfo& PipelineBuilder::GetStageInfo(dawn::ShaderStage stage) const {
ASSERT(mStageMask & StageBit(stage)); ASSERT(mStageMask & StageBit(stage));
return mStages[stage]; return mStages[stage];
} }
@ -94,7 +94,7 @@ namespace backend {
mLayout = layout; mLayout = layout;
} }
void PipelineBuilder::SetStage(nxt::ShaderStage stage, void PipelineBuilder::SetStage(dawn::ShaderStage stage,
ShaderModuleBase* module, ShaderModuleBase* module,
const char* entryPoint) { const char* entryPoint) {
if (entryPoint != std::string("main")) { if (entryPoint != std::string("main")) {
@ -107,7 +107,7 @@ namespace backend {
return; return;
} }
nxt::ShaderStageBit bit = StageBit(stage); dawn::ShaderStageBit bit = StageBit(stage);
if (mStageMask & bit) { if (mStageMask & bit) {
mParentBuilder->HandleError("Setting already set stage"); mParentBuilder->HandleError("Setting already set stage");
return; return;

View File

@ -45,13 +45,13 @@ namespace backend {
std::bitset<kMaxPushConstants> mask; std::bitset<kMaxPushConstants> mask;
std::array<PushConstantType, kMaxPushConstants> types; std::array<PushConstantType, kMaxPushConstants> types;
}; };
const PushConstantInfo& GetPushConstants(nxt::ShaderStage stage) const; const PushConstantInfo& GetPushConstants(dawn::ShaderStage stage) const;
nxt::ShaderStageBit GetStageMask() const; dawn::ShaderStageBit GetStageMask() const;
PipelineLayoutBase* GetLayout(); PipelineLayoutBase* GetLayout();
private: private:
nxt::ShaderStageBit mStageMask; dawn::ShaderStageBit mStageMask;
Ref<PipelineLayoutBase> mLayout; Ref<PipelineLayoutBase> mLayout;
PerStage<PushConstantInfo> mPushConstants; PerStage<PushConstantInfo> mPushConstants;
}; };
@ -64,19 +64,19 @@ namespace backend {
std::string entryPoint; std::string entryPoint;
Ref<ShaderModuleBase> module; Ref<ShaderModuleBase> module;
}; };
const StageInfo& GetStageInfo(nxt::ShaderStage stage) const; const StageInfo& GetStageInfo(dawn::ShaderStage stage) const;
BuilderBase* GetParentBuilder() const; BuilderBase* GetParentBuilder() const;
// NXT API // NXT API
void SetLayout(PipelineLayoutBase* layout); void SetLayout(PipelineLayoutBase* layout);
void SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint); void SetStage(dawn::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint);
private: private:
friend class PipelineBase; friend class PipelineBase;
BuilderBase* mParentBuilder; BuilderBase* mParentBuilder;
Ref<PipelineLayoutBase> mLayout; Ref<PipelineLayoutBase> mLayout;
nxt::ShaderStageBit mStageMask; dawn::ShaderStageBit mStageMask;
PerStage<StageInfo> mStages; PerStage<StageInfo> mStages;
}; };

View File

@ -21,7 +21,7 @@
namespace backend { namespace backend {
MaybeError ValidatePipelineLayoutDescriptor(DeviceBase*, MaybeError ValidatePipelineLayoutDescriptor(DeviceBase*,
const nxt::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr"); NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
NXT_TRY_ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups, NXT_TRY_ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups,
"too many bind group layouts"); "too many bind group layouts");
@ -35,7 +35,7 @@ namespace backend {
// PipelineLayoutBase // PipelineLayoutBase
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device,
const nxt::PipelineLayoutDescriptor* descriptor) const dawn::PipelineLayoutDescriptor* descriptor)
: mDevice(device) { : mDevice(device) {
ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups); ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups);
for (uint32_t group = 0; group < descriptor->numBindGroupLayouts; ++group) { for (uint32_t group = 0; group < descriptor->numBindGroupLayouts; ++group) {

View File

@ -28,13 +28,13 @@
namespace backend { namespace backend {
MaybeError ValidatePipelineLayoutDescriptor(DeviceBase*, MaybeError ValidatePipelineLayoutDescriptor(DeviceBase*,
const nxt::PipelineLayoutDescriptor* descriptor); const dawn::PipelineLayoutDescriptor* descriptor);
using BindGroupLayoutArray = std::array<Ref<BindGroupLayoutBase>, kMaxBindGroups>; using BindGroupLayoutArray = std::array<Ref<BindGroupLayoutBase>, kMaxBindGroups>;
class PipelineLayoutBase : public RefCounted { class PipelineLayoutBase : public RefCounted {
public: public:
PipelineLayoutBase(DeviceBase* device, const nxt::PipelineLayoutDescriptor* descriptor); PipelineLayoutBase(DeviceBase* device, const dawn::PipelineLayoutDescriptor* descriptor);
const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const; const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const;
const std::bitset<kMaxBindGroups> GetBindGroupLayoutsMask() const; const std::bitset<kMaxBindGroups> GetBindGroupLayoutsMask() const;

View File

@ -126,7 +126,7 @@ namespace backend {
void RenderPassDescriptorBuilder::SetColorAttachment(uint32_t attachment, void RenderPassDescriptorBuilder::SetColorAttachment(uint32_t attachment,
TextureViewBase* textureView, TextureViewBase* textureView,
nxt::LoadOp loadOp) { dawn::LoadOp loadOp) {
if (attachment >= kMaxColorAttachments) { if (attachment >= kMaxColorAttachments) {
HandleError("Setting color attachment out of bounds"); HandleError("Setting color attachment out of bounds");
return; return;
@ -159,8 +159,8 @@ namespace backend {
} }
void RenderPassDescriptorBuilder::SetDepthStencilAttachment(TextureViewBase* textureView, void RenderPassDescriptorBuilder::SetDepthStencilAttachment(TextureViewBase* textureView,
nxt::LoadOp depthLoadOp, dawn::LoadOp depthLoadOp,
nxt::LoadOp stencilLoadOp) { dawn::LoadOp stencilLoadOp) {
if (!TextureFormatHasDepthOrStencil(textureView->GetTexture()->GetFormat())) { if (!TextureFormatHasDepthOrStencil(textureView->GetTexture()->GetFormat())) {
HandleError("Using color texture as depth stencil attachment"); HandleError("Using color texture as depth stencil attachment");
return; return;

View File

@ -29,14 +29,14 @@
namespace backend { namespace backend {
struct RenderPassColorAttachmentInfo { struct RenderPassColorAttachmentInfo {
nxt::LoadOp loadOp; dawn::LoadOp loadOp;
std::array<float, 4> clearColor = {{0.0f, 0.0f, 0.0f, 0.0f}}; std::array<float, 4> clearColor = {{0.0f, 0.0f, 0.0f, 0.0f}};
Ref<TextureViewBase> view; Ref<TextureViewBase> view;
}; };
struct RenderPassDepthStencilAttachmentInfo { struct RenderPassDepthStencilAttachmentInfo {
nxt::LoadOp depthLoadOp; dawn::LoadOp depthLoadOp;
nxt::LoadOp stencilLoadOp; dawn::LoadOp stencilLoadOp;
float clearDepth = 1.0f; float clearDepth = 1.0f;
uint32_t clearStencil = 0; uint32_t clearStencil = 0;
Ref<TextureViewBase> view; Ref<TextureViewBase> view;
@ -80,15 +80,15 @@ namespace backend {
RenderPassDescriptorBase* GetResultImpl() override; RenderPassDescriptorBase* GetResultImpl() override;
void SetColorAttachment(uint32_t attachment, void SetColorAttachment(uint32_t attachment,
TextureViewBase* textureView, TextureViewBase* textureView,
nxt::LoadOp loadOp); dawn::LoadOp loadOp);
void SetColorAttachmentClearColor(uint32_t attachment, void SetColorAttachmentClearColor(uint32_t attachment,
float clearR, float clearR,
float clearG, float clearG,
float clearB, float clearB,
float clearA); float clearA);
void SetDepthStencilAttachment(TextureViewBase* textureView, void SetDepthStencilAttachment(TextureViewBase* textureView,
nxt::LoadOp depthLoadOp, dawn::LoadOp depthLoadOp,
nxt::LoadOp stencilLoadOp); dawn::LoadOp stencilLoadOp);
void SetDepthStencilAttachmentClearValue(float clearDepth, uint32_t clearStencil); void SetDepthStencilAttachmentClearValue(float clearDepth, uint32_t clearStencil);
private: private:

View File

@ -37,14 +37,14 @@ namespace backend {
mColorAttachmentFormats(builder->mColorAttachmentFormats), mColorAttachmentFormats(builder->mColorAttachmentFormats),
mDepthStencilFormatSet(builder->mDepthStencilFormatSet), mDepthStencilFormatSet(builder->mDepthStencilFormatSet),
mDepthStencilFormat(builder->mDepthStencilFormat) { mDepthStencilFormat(builder->mDepthStencilFormat) {
if (GetStageMask() != (nxt::ShaderStageBit::Vertex | nxt::ShaderStageBit::Fragment)) { if (GetStageMask() != (dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment)) {
builder->HandleError("Render pipeline should have exactly a vertex and fragment stage"); builder->HandleError("Render pipeline should have exactly a vertex and fragment stage");
return; return;
} }
// TODO(kainino@chromium.org): Need to verify the pipeline against its render subpass. // TODO(kainino@chromium.org): Need to verify the pipeline against its render subpass.
if ((builder->GetStageInfo(nxt::ShaderStage::Vertex).module->GetUsedVertexAttributes() & if ((builder->GetStageInfo(dawn::ShaderStage::Vertex).module->GetUsedVertexAttributes() &
~mInputState->GetAttributesSetMask()) ~mInputState->GetAttributesSetMask())
.any()) { .any()) {
builder->HandleError("Pipeline vertex stage uses inputs not in the input state"); builder->HandleError("Pipeline vertex stage uses inputs not in the input state");
@ -74,7 +74,7 @@ namespace backend {
return mDepthStencilState.Get(); return mDepthStencilState.Get();
} }
nxt::IndexFormat RenderPipelineBase::GetIndexFormat() const { dawn::IndexFormat RenderPipelineBase::GetIndexFormat() const {
return mIndexFormat; return mIndexFormat;
} }
@ -82,7 +82,7 @@ namespace backend {
return mInputState.Get(); return mInputState.Get();
} }
nxt::PrimitiveTopology RenderPipelineBase::GetPrimitiveTopology() const { dawn::PrimitiveTopology RenderPipelineBase::GetPrimitiveTopology() const {
return mPrimitiveTopology; return mPrimitiveTopology;
} }
@ -94,11 +94,11 @@ namespace backend {
return mDepthStencilFormatSet; return mDepthStencilFormatSet;
} }
nxt::TextureFormat RenderPipelineBase::GetColorAttachmentFormat(uint32_t attachment) const { dawn::TextureFormat RenderPipelineBase::GetColorAttachmentFormat(uint32_t attachment) const {
return mColorAttachmentFormats[attachment]; return mColorAttachmentFormats[attachment];
} }
nxt::TextureFormat RenderPipelineBase::GetDepthStencilFormat() const { dawn::TextureFormat RenderPipelineBase::GetDepthStencilFormat() const {
return mDepthStencilFormat; return mDepthStencilFormat;
} }
@ -172,7 +172,7 @@ namespace backend {
} }
void RenderPipelineBuilder::SetColorAttachmentFormat(uint32_t attachmentSlot, void RenderPipelineBuilder::SetColorAttachmentFormat(uint32_t attachmentSlot,
nxt::TextureFormat format) { dawn::TextureFormat format) {
if (attachmentSlot >= kMaxColorAttachments) { if (attachmentSlot >= kMaxColorAttachments) {
HandleError("Attachment index out of bounds"); HandleError("Attachment index out of bounds");
return; return;
@ -201,12 +201,12 @@ namespace backend {
mDepthStencilState = depthStencilState; mDepthStencilState = depthStencilState;
} }
void RenderPipelineBuilder::SetDepthStencilAttachmentFormat(nxt::TextureFormat format) { void RenderPipelineBuilder::SetDepthStencilAttachmentFormat(dawn::TextureFormat format) {
mDepthStencilFormatSet = true; mDepthStencilFormatSet = true;
mDepthStencilFormat = format; mDepthStencilFormat = format;
} }
void RenderPipelineBuilder::SetIndexFormat(nxt::IndexFormat format) { void RenderPipelineBuilder::SetIndexFormat(dawn::IndexFormat format) {
mIndexFormat = format; mIndexFormat = format;
} }
@ -214,7 +214,7 @@ namespace backend {
mInputState = inputState; mInputState = inputState;
} }
void RenderPipelineBuilder::SetPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) { void RenderPipelineBuilder::SetPrimitiveTopology(dawn::PrimitiveTopology primitiveTopology) {
mPrimitiveTopology = primitiveTopology; mPrimitiveTopology = primitiveTopology;
} }

View File

@ -33,14 +33,14 @@ namespace backend {
BlendStateBase* GetBlendState(uint32_t attachmentSlot); BlendStateBase* GetBlendState(uint32_t attachmentSlot);
DepthStencilStateBase* GetDepthStencilState(); DepthStencilStateBase* GetDepthStencilState();
nxt::IndexFormat GetIndexFormat() const; dawn::IndexFormat GetIndexFormat() const;
InputStateBase* GetInputState(); InputStateBase* GetInputState();
nxt::PrimitiveTopology GetPrimitiveTopology() const; dawn::PrimitiveTopology GetPrimitiveTopology() const;
std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const; std::bitset<kMaxColorAttachments> GetColorAttachmentsMask() const;
bool HasDepthStencilAttachment() const; bool HasDepthStencilAttachment() const;
nxt::TextureFormat GetColorAttachmentFormat(uint32_t attachment) const; dawn::TextureFormat GetColorAttachmentFormat(uint32_t attachment) const;
nxt::TextureFormat GetDepthStencilFormat() const; dawn::TextureFormat GetDepthStencilFormat() const;
// A pipeline can be used in a render pass if its attachment info matches the actual // A pipeline can be used in a render pass if its attachment info matches the actual
// attachments in the render pass. This returns whether it is the case. // attachments in the render pass. This returns whether it is the case.
@ -48,15 +48,15 @@ namespace backend {
private: private:
Ref<DepthStencilStateBase> mDepthStencilState; Ref<DepthStencilStateBase> mDepthStencilState;
nxt::IndexFormat mIndexFormat; dawn::IndexFormat mIndexFormat;
Ref<InputStateBase> mInputState; Ref<InputStateBase> mInputState;
nxt::PrimitiveTopology mPrimitiveTopology; dawn::PrimitiveTopology mPrimitiveTopology;
std::array<Ref<BlendStateBase>, kMaxColorAttachments> mBlendStates; std::array<Ref<BlendStateBase>, kMaxColorAttachments> mBlendStates;
std::bitset<kMaxColorAttachments> mColorAttachmentsSet; std::bitset<kMaxColorAttachments> mColorAttachmentsSet;
std::array<nxt::TextureFormat, kMaxColorAttachments> mColorAttachmentFormats; std::array<dawn::TextureFormat, kMaxColorAttachments> mColorAttachmentFormats;
bool mDepthStencilFormatSet = false; bool mDepthStencilFormatSet = false;
nxt::TextureFormat mDepthStencilFormat; dawn::TextureFormat mDepthStencilFormat;
}; };
class RenderPipelineBuilder : public Builder<RenderPipelineBase>, public PipelineBuilder { class RenderPipelineBuilder : public Builder<RenderPipelineBase>, public PipelineBuilder {
@ -64,12 +64,12 @@ namespace backend {
RenderPipelineBuilder(DeviceBase* device); RenderPipelineBuilder(DeviceBase* device);
// NXT API // NXT API
void SetColorAttachmentFormat(uint32_t attachmentSlot, nxt::TextureFormat format); void SetColorAttachmentFormat(uint32_t attachmentSlot, dawn::TextureFormat format);
void SetColorAttachmentBlendState(uint32_t attachmentSlot, BlendStateBase* blendState); void SetColorAttachmentBlendState(uint32_t attachmentSlot, BlendStateBase* blendState);
void SetDepthStencilAttachmentFormat(nxt::TextureFormat format); void SetDepthStencilAttachmentFormat(dawn::TextureFormat format);
void SetDepthStencilState(DepthStencilStateBase* depthStencilState); void SetDepthStencilState(DepthStencilStateBase* depthStencilState);
void SetPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology); void SetPrimitiveTopology(dawn::PrimitiveTopology primitiveTopology);
void SetIndexFormat(nxt::IndexFormat format); void SetIndexFormat(dawn::IndexFormat format);
void SetInputState(InputStateBase* inputState); void SetInputState(InputStateBase* inputState);
private: private:
@ -81,14 +81,14 @@ namespace backend {
Ref<InputStateBase> mInputState; Ref<InputStateBase> mInputState;
// TODO(enga@google.com): Remove default when we validate that all required properties are // TODO(enga@google.com): Remove default when we validate that all required properties are
// set // set
nxt::PrimitiveTopology mPrimitiveTopology = nxt::PrimitiveTopology::TriangleList; dawn::PrimitiveTopology mPrimitiveTopology = dawn::PrimitiveTopology::TriangleList;
nxt::IndexFormat mIndexFormat = nxt::IndexFormat::Uint32; dawn::IndexFormat mIndexFormat = dawn::IndexFormat::Uint32;
std::bitset<kMaxColorAttachments> mBlendStatesSet; std::bitset<kMaxColorAttachments> mBlendStatesSet;
std::array<Ref<BlendStateBase>, kMaxColorAttachments> mBlendStates; std::array<Ref<BlendStateBase>, kMaxColorAttachments> mBlendStates;
std::bitset<kMaxColorAttachments> mColorAttachmentsSet; std::bitset<kMaxColorAttachments> mColorAttachmentsSet;
std::array<nxt::TextureFormat, kMaxColorAttachments> mColorAttachmentFormats; std::array<dawn::TextureFormat, kMaxColorAttachments> mColorAttachmentFormats;
bool mDepthStencilFormatSet = false; bool mDepthStencilFormatSet = false;
nxt::TextureFormat mDepthStencilFormat; dawn::TextureFormat mDepthStencilFormat;
}; };
} // namespace backend } // namespace backend

View File

@ -19,7 +19,7 @@
namespace backend { namespace backend {
MaybeError ValidateSamplerDescriptor(DeviceBase*, const nxt::SamplerDescriptor* descriptor) { MaybeError ValidateSamplerDescriptor(DeviceBase*, const dawn::SamplerDescriptor* descriptor) {
NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr"); NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
NXT_TRY(ValidateFilterMode(descriptor->minFilter)); NXT_TRY(ValidateFilterMode(descriptor->minFilter));
NXT_TRY(ValidateFilterMode(descriptor->magFilter)); NXT_TRY(ValidateFilterMode(descriptor->magFilter));
@ -32,7 +32,7 @@ namespace backend {
// SamplerBase // SamplerBase
SamplerBase::SamplerBase(DeviceBase*, const nxt::SamplerDescriptor*) { SamplerBase::SamplerBase(DeviceBase*, const dawn::SamplerDescriptor*) {
} }
} // namespace backend } // namespace backend

View File

@ -25,11 +25,11 @@ namespace backend {
class DeviceBase; class DeviceBase;
MaybeError ValidateSamplerDescriptor(DeviceBase* device, MaybeError ValidateSamplerDescriptor(DeviceBase* device,
const nxt::SamplerDescriptor* descriptor); const dawn::SamplerDescriptor* descriptor);
class SamplerBase : public RefCounted { class SamplerBase : public RefCounted {
public: public:
SamplerBase(DeviceBase* device, const nxt::SamplerDescriptor* descriptor); SamplerBase(DeviceBase* device, const dawn::SamplerDescriptor* descriptor);
}; };
} // namespace backend } // namespace backend

View File

@ -37,13 +37,13 @@ namespace backend {
switch (compiler.get_execution_model()) { switch (compiler.get_execution_model()) {
case spv::ExecutionModelVertex: case spv::ExecutionModelVertex:
mExecutionModel = nxt::ShaderStage::Vertex; mExecutionModel = dawn::ShaderStage::Vertex;
break; break;
case spv::ExecutionModelFragment: case spv::ExecutionModelFragment:
mExecutionModel = nxt::ShaderStage::Fragment; mExecutionModel = dawn::ShaderStage::Fragment;
break; break;
case spv::ExecutionModelGLCompute: case spv::ExecutionModelGLCompute:
mExecutionModel = nxt::ShaderStage::Compute; mExecutionModel = dawn::ShaderStage::Compute;
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -103,7 +103,7 @@ namespace backend {
// Fill in bindingInfo with the SPIRV bindings // Fill in bindingInfo with the SPIRV bindings
auto ExtractResourcesBinding = [this](const std::vector<spirv_cross::Resource>& resources, auto ExtractResourcesBinding = [this](const std::vector<spirv_cross::Resource>& resources,
const spirv_cross::Compiler& compiler, const spirv_cross::Compiler& compiler,
nxt::BindingType bindingType) { dawn::BindingType bindingType) {
constexpr uint64_t requiredBindingDecorationMask = constexpr uint64_t requiredBindingDecorationMask =
(1ull << spv::DecorationBinding) | (1ull << spv::DecorationDescriptorSet); (1ull << spv::DecorationBinding) | (1ull << spv::DecorationDescriptorSet);
@ -127,15 +127,15 @@ namespace backend {
}; };
ExtractResourcesBinding(resources.uniform_buffers, compiler, ExtractResourcesBinding(resources.uniform_buffers, compiler,
nxt::BindingType::UniformBuffer); dawn::BindingType::UniformBuffer);
ExtractResourcesBinding(resources.separate_images, compiler, ExtractResourcesBinding(resources.separate_images, compiler,
nxt::BindingType::SampledTexture); dawn::BindingType::SampledTexture);
ExtractResourcesBinding(resources.separate_samplers, compiler, nxt::BindingType::Sampler); ExtractResourcesBinding(resources.separate_samplers, compiler, dawn::BindingType::Sampler);
ExtractResourcesBinding(resources.storage_buffers, compiler, ExtractResourcesBinding(resources.storage_buffers, compiler,
nxt::BindingType::StorageBuffer); dawn::BindingType::StorageBuffer);
// Extract the vertex attributes // Extract the vertex attributes
if (mExecutionModel == nxt::ShaderStage::Vertex) { if (mExecutionModel == dawn::ShaderStage::Vertex) {
for (const auto& attrib : resources.stage_inputs) { for (const auto& attrib : resources.stage_inputs) {
ASSERT(compiler.get_decoration_mask(attrib.id) & (1ull << spv::DecorationLocation)); ASSERT(compiler.get_decoration_mask(attrib.id) & (1ull << spv::DecorationLocation));
uint32_t location = compiler.get_decoration(attrib.id, spv::DecorationLocation); uint32_t location = compiler.get_decoration(attrib.id, spv::DecorationLocation);
@ -159,7 +159,7 @@ namespace backend {
} }
} }
if (mExecutionModel == nxt::ShaderStage::Fragment) { if (mExecutionModel == dawn::ShaderStage::Fragment) {
// Without a location qualifier on vertex inputs, spirv_cross::CompilerMSL gives them // Without a location qualifier on vertex inputs, spirv_cross::CompilerMSL gives them
// all the location 0, causing a compile error. // all the location 0, causing a compile error.
for (const auto& attrib : resources.stage_inputs) { for (const auto& attrib : resources.stage_inputs) {
@ -184,7 +184,7 @@ namespace backend {
return mUsedVertexAttributes; return mUsedVertexAttributes;
} }
nxt::ShaderStage ShaderModuleBase::GetExecutionModel() const { dawn::ShaderStage ShaderModuleBase::GetExecutionModel() const {
return mExecutionModel; return mExecutionModel;
} }

View File

@ -52,7 +52,7 @@ namespace backend {
// The SPIRV ID of the resource. // The SPIRV ID of the resource.
uint32_t id; uint32_t id;
uint32_t base_type_id; uint32_t base_type_id;
nxt::BindingType type; dawn::BindingType type;
bool used = false; bool used = false;
}; };
using ModuleBindingInfo = using ModuleBindingInfo =
@ -61,7 +61,7 @@ namespace backend {
const PushConstantInfo& GetPushConstants() const; const PushConstantInfo& GetPushConstants() const;
const ModuleBindingInfo& GetBindingInfo() const; const ModuleBindingInfo& GetBindingInfo() const;
const std::bitset<kMaxVertexAttributes>& GetUsedVertexAttributes() const; const std::bitset<kMaxVertexAttributes>& GetUsedVertexAttributes() const;
nxt::ShaderStage GetExecutionModel() const; dawn::ShaderStage GetExecutionModel() const;
bool IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout); bool IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout);
@ -72,7 +72,7 @@ namespace backend {
PushConstantInfo mPushConstants = {}; PushConstantInfo mPushConstants = {};
ModuleBindingInfo mBindingInfo; ModuleBindingInfo mBindingInfo;
std::bitset<kMaxVertexAttributes> mUsedVertexAttributes; std::bitset<kMaxVertexAttributes> mUsedVertexAttributes;
nxt::ShaderStage mExecutionModel; dawn::ShaderStage mExecutionModel;
}; };
class ShaderModuleBuilder : public Builder<ShaderModuleBase> { class ShaderModuleBuilder : public Builder<ShaderModuleBase> {

View File

@ -34,15 +34,15 @@ namespace backend {
return mDevice; return mDevice;
} }
void SwapChainBase::Configure(nxt::TextureFormat format, void SwapChainBase::Configure(dawn::TextureFormat format,
nxt::TextureUsageBit allowedUsage, dawn::TextureUsageBit allowedUsage,
uint32_t width, uint32_t width,
uint32_t height) { uint32_t height) {
if (width == 0 || height == 0) { if (width == 0 || height == 0) {
mDevice->HandleError("Swap chain cannot be configured to zero size"); mDevice->HandleError("Swap chain cannot be configured to zero size");
return; return;
} }
allowedUsage |= nxt::TextureUsageBit::Present; allowedUsage |= dawn::TextureUsageBit::Present;
mFormat = format; mFormat = format;
mAllowedUsage = allowedUsage; mAllowedUsage = allowedUsage;
@ -60,7 +60,7 @@ namespace backend {
} }
auto* builder = mDevice->CreateTextureBuilder(); auto* builder = mDevice->CreateTextureBuilder();
builder->SetDimension(nxt::TextureDimension::e2D); builder->SetDimension(dawn::TextureDimension::e2D);
builder->SetExtent(mWidth, mHeight, 1); builder->SetExtent(mWidth, mHeight, 1);
builder->SetFormat(mFormat); builder->SetFormat(mFormat);
builder->SetMipLevels(1); builder->SetMipLevels(1);

View File

@ -32,8 +32,8 @@ namespace backend {
DeviceBase* GetDevice(); DeviceBase* GetDevice();
// NXT API // NXT API
void Configure(nxt::TextureFormat format, void Configure(dawn::TextureFormat format,
nxt::TextureUsageBit allowedUsage, dawn::TextureUsageBit allowedUsage,
uint32_t width, uint32_t width,
uint32_t height); uint32_t height);
TextureBase* GetNextTexture(); TextureBase* GetNextTexture();
@ -47,8 +47,8 @@ namespace backend {
private: private:
DeviceBase* mDevice = nullptr; DeviceBase* mDevice = nullptr;
nxtSwapChainImplementation mImplementation = {}; nxtSwapChainImplementation mImplementation = {};
nxt::TextureFormat mFormat = {}; dawn::TextureFormat mFormat = {};
nxt::TextureUsageBit mAllowedUsage; dawn::TextureUsageBit mAllowedUsage;
uint32_t mWidth = 0; uint32_t mWidth = 0;
uint32_t mHeight = 0; uint32_t mHeight = 0;
TextureBase* mLastNextTexture = nullptr; TextureBase* mLastNextTexture = nullptr;

View File

@ -19,46 +19,46 @@
namespace backend { namespace backend {
uint32_t TextureFormatPixelSize(nxt::TextureFormat format) { uint32_t TextureFormatPixelSize(dawn::TextureFormat format) {
switch (format) { switch (format) {
case nxt::TextureFormat::R8Unorm: case dawn::TextureFormat::R8Unorm:
case nxt::TextureFormat::R8Uint: case dawn::TextureFormat::R8Uint:
return 1; return 1;
case nxt::TextureFormat::R8G8Unorm: case dawn::TextureFormat::R8G8Unorm:
case nxt::TextureFormat::R8G8Uint: case dawn::TextureFormat::R8G8Uint:
return 2; return 2;
case nxt::TextureFormat::R8G8B8A8Unorm: case dawn::TextureFormat::R8G8B8A8Unorm:
case nxt::TextureFormat::R8G8B8A8Uint: case dawn::TextureFormat::R8G8B8A8Uint:
case nxt::TextureFormat::B8G8R8A8Unorm: case dawn::TextureFormat::B8G8R8A8Unorm:
return 4; return 4;
case nxt::TextureFormat::D32FloatS8Uint: case dawn::TextureFormat::D32FloatS8Uint:
return 8; return 8;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
bool TextureFormatHasDepth(nxt::TextureFormat format) { bool TextureFormatHasDepth(dawn::TextureFormat format) {
switch (format) { switch (format) {
case nxt::TextureFormat::D32FloatS8Uint: case dawn::TextureFormat::D32FloatS8Uint:
return true; return true;
default: default:
return false; return false;
} }
} }
bool TextureFormatHasStencil(nxt::TextureFormat format) { bool TextureFormatHasStencil(dawn::TextureFormat format) {
switch (format) { switch (format) {
case nxt::TextureFormat::D32FloatS8Uint: case dawn::TextureFormat::D32FloatS8Uint:
return true; return true;
default: default:
return false; return false;
} }
} }
bool TextureFormatHasDepthOrStencil(nxt::TextureFormat format) { bool TextureFormatHasDepthOrStencil(dawn::TextureFormat format) {
switch (format) { switch (format) {
case nxt::TextureFormat::D32FloatS8Uint: case dawn::TextureFormat::D32FloatS8Uint:
return true; return true;
default: default:
return false; return false;
@ -82,10 +82,10 @@ namespace backend {
return mDevice; return mDevice;
} }
nxt::TextureDimension TextureBase::GetDimension() const { dawn::TextureDimension TextureBase::GetDimension() const {
return mDimension; return mDimension;
} }
nxt::TextureFormat TextureBase::GetFormat() const { dawn::TextureFormat TextureBase::GetFormat() const {
return mFormat; return mFormat;
} }
uint32_t TextureBase::GetWidth() const { uint32_t TextureBase::GetWidth() const {
@ -100,7 +100,7 @@ namespace backend {
uint32_t TextureBase::GetNumMipLevels() const { uint32_t TextureBase::GetNumMipLevels() const {
return mNumMipLevels; return mNumMipLevels;
} }
nxt::TextureUsageBit TextureBase::GetAllowedUsage() const { dawn::TextureUsageBit TextureBase::GetAllowedUsage() const {
return mAllowedUsage; return mAllowedUsage;
} }
@ -135,7 +135,7 @@ namespace backend {
return mDevice->CreateTexture(this); return mDevice->CreateTexture(this);
} }
void TextureBuilder::SetDimension(nxt::TextureDimension dimension) { void TextureBuilder::SetDimension(dawn::TextureDimension dimension) {
if ((mPropertiesSet & TEXTURE_PROPERTY_DIMENSION) != 0) { if ((mPropertiesSet & TEXTURE_PROPERTY_DIMENSION) != 0) {
HandleError("Texture dimension property set multiple times"); HandleError("Texture dimension property set multiple times");
return; return;
@ -162,7 +162,7 @@ namespace backend {
mDepth = depth; mDepth = depth;
} }
void TextureBuilder::SetFormat(nxt::TextureFormat format) { void TextureBuilder::SetFormat(dawn::TextureFormat format) {
if ((mPropertiesSet & TEXTURE_PROPERTY_FORMAT) != 0) { if ((mPropertiesSet & TEXTURE_PROPERTY_FORMAT) != 0) {
HandleError("Texture format property set multiple times"); HandleError("Texture format property set multiple times");
return; return;
@ -182,7 +182,7 @@ namespace backend {
mNumMipLevels = numMipLevels; mNumMipLevels = numMipLevels;
} }
void TextureBuilder::SetAllowedUsage(nxt::TextureUsageBit usage) { void TextureBuilder::SetAllowedUsage(dawn::TextureUsageBit usage) {
if ((mPropertiesSet & TEXTURE_PROPERTY_ALLOWED_USAGE) != 0) { if ((mPropertiesSet & TEXTURE_PROPERTY_ALLOWED_USAGE) != 0) {
HandleError("Texture allowed usage property set multiple times"); HandleError("Texture allowed usage property set multiple times");
return; return;

View File

@ -23,30 +23,30 @@
namespace backend { namespace backend {
uint32_t TextureFormatPixelSize(nxt::TextureFormat format); uint32_t TextureFormatPixelSize(dawn::TextureFormat format);
bool TextureFormatHasDepth(nxt::TextureFormat format); bool TextureFormatHasDepth(dawn::TextureFormat format);
bool TextureFormatHasStencil(nxt::TextureFormat format); bool TextureFormatHasStencil(dawn::TextureFormat format);
bool TextureFormatHasDepthOrStencil(nxt::TextureFormat format); bool TextureFormatHasDepthOrStencil(dawn::TextureFormat format);
static constexpr nxt::TextureUsageBit kReadOnlyTextureUsages = static constexpr dawn::TextureUsageBit kReadOnlyTextureUsages =
nxt::TextureUsageBit::TransferSrc | nxt::TextureUsageBit::Sampled | dawn::TextureUsageBit::TransferSrc | dawn::TextureUsageBit::Sampled |
nxt::TextureUsageBit::Present; dawn::TextureUsageBit::Present;
static constexpr nxt::TextureUsageBit kWritableTextureUsages = static constexpr dawn::TextureUsageBit kWritableTextureUsages =
nxt::TextureUsageBit::TransferDst | nxt::TextureUsageBit::Storage | dawn::TextureUsageBit::TransferDst | dawn::TextureUsageBit::Storage |
nxt::TextureUsageBit::OutputAttachment; dawn::TextureUsageBit::OutputAttachment;
class TextureBase : public RefCounted { class TextureBase : public RefCounted {
public: public:
TextureBase(TextureBuilder* builder); TextureBase(TextureBuilder* builder);
nxt::TextureDimension GetDimension() const; dawn::TextureDimension GetDimension() const;
nxt::TextureFormat GetFormat() const; dawn::TextureFormat GetFormat() const;
uint32_t GetWidth() const; uint32_t GetWidth() const;
uint32_t GetHeight() const; uint32_t GetHeight() const;
uint32_t GetDepth() const; uint32_t GetDepth() const;
uint32_t GetNumMipLevels() const; uint32_t GetNumMipLevels() const;
nxt::TextureUsageBit GetAllowedUsage() const; dawn::TextureUsageBit GetAllowedUsage() const;
DeviceBase* GetDevice() const; DeviceBase* GetDevice() const;
// NXT API // NXT API
@ -55,11 +55,11 @@ namespace backend {
private: private:
DeviceBase* mDevice; DeviceBase* mDevice;
nxt::TextureDimension mDimension; dawn::TextureDimension mDimension;
nxt::TextureFormat mFormat; dawn::TextureFormat mFormat;
uint32_t mWidth, mHeight, mDepth; uint32_t mWidth, mHeight, mDepth;
uint32_t mNumMipLevels; uint32_t mNumMipLevels;
nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None; dawn::TextureUsageBit mAllowedUsage = dawn::TextureUsageBit::None;
}; };
class TextureBuilder : public Builder<TextureBase> { class TextureBuilder : public Builder<TextureBase> {
@ -67,12 +67,12 @@ namespace backend {
TextureBuilder(DeviceBase* device); TextureBuilder(DeviceBase* device);
// NXT API // NXT API
void SetDimension(nxt::TextureDimension dimension); void SetDimension(dawn::TextureDimension dimension);
void SetExtent(uint32_t width, uint32_t height, uint32_t depth); void SetExtent(uint32_t width, uint32_t height, uint32_t depth);
void SetFormat(nxt::TextureFormat format); void SetFormat(dawn::TextureFormat format);
void SetMipLevels(uint32_t numMipLevels); void SetMipLevels(uint32_t numMipLevels);
void SetAllowedUsage(nxt::TextureUsageBit usage); void SetAllowedUsage(dawn::TextureUsageBit usage);
void SetInitialUsage(nxt::TextureUsageBit usage); void SetInitialUsage(dawn::TextureUsageBit usage);
private: private:
friend class TextureBase; friend class TextureBase;
@ -81,11 +81,11 @@ namespace backend {
int mPropertiesSet = 0; int mPropertiesSet = 0;
nxt::TextureDimension mDimension; dawn::TextureDimension mDimension;
uint32_t mWidth, mHeight, mDepth; uint32_t mWidth, mHeight, mDepth;
nxt::TextureFormat mFormat; dawn::TextureFormat mFormat;
uint32_t mNumMipLevels; uint32_t mNumMipLevels;
nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None; dawn::TextureUsageBit mAllowedUsage = dawn::TextureUsageBit::None;
}; };
class TextureViewBase : public RefCounted { class TextureViewBase : public RefCounted {

View File

@ -46,14 +46,14 @@ namespace backend { namespace d3d12 {
auto d3d12Device = mDevice->GetD3D12Device(); auto d3d12Device = mDevice->GetD3D12Device();
for (uint32_t binding : IterateBitSet(layout.mask)) { for (uint32_t binding : IterateBitSet(layout.mask)) {
switch (layout.types[binding]) { switch (layout.types[binding]) {
case nxt::BindingType::UniformBuffer: { case dawn::BindingType::UniformBuffer: {
auto* view = ToBackend(GetBindingAsBufferView(binding)); auto* view = ToBackend(GetBindingAsBufferView(binding));
auto& cbv = view->GetCBVDescriptor(); auto& cbv = view->GetCBVDescriptor();
d3d12Device->CreateConstantBufferView( d3d12Device->CreateConstantBufferView(
&cbv, cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset + &cbv, cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset +
bindingOffsets[binding])); bindingOffsets[binding]));
} break; } break;
case nxt::BindingType::StorageBuffer: { case dawn::BindingType::StorageBuffer: {
auto* view = ToBackend(GetBindingAsBufferView(binding)); auto* view = ToBackend(GetBindingAsBufferView(binding));
auto& uav = view->GetUAVDescriptor(); auto& uav = view->GetUAVDescriptor();
d3d12Device->CreateUnorderedAccessView( d3d12Device->CreateUnorderedAccessView(
@ -61,7 +61,7 @@ namespace backend { namespace d3d12 {
cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset + cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset +
bindingOffsets[binding])); bindingOffsets[binding]));
} break; } break;
case nxt::BindingType::SampledTexture: { case dawn::BindingType::SampledTexture: {
auto* view = ToBackend(GetBindingAsTextureView(binding)); auto* view = ToBackend(GetBindingAsTextureView(binding));
auto& srv = view->GetSRVDescriptor(); auto& srv = view->GetSRVDescriptor();
d3d12Device->CreateShaderResourceView( d3d12Device->CreateShaderResourceView(
@ -69,7 +69,7 @@ namespace backend { namespace d3d12 {
cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset + cbvUavSrvHeapStart.GetCPUHandle(*cbvUavSrvHeapOffset +
bindingOffsets[binding])); bindingOffsets[binding]));
} break; } break;
case nxt::BindingType::Sampler: { case dawn::BindingType::Sampler: {
auto* sampler = ToBackend(GetBindingAsSampler(binding)); auto* sampler = ToBackend(GetBindingAsSampler(binding));
auto& samplerDesc = sampler->GetSamplerDescriptor(); auto& samplerDesc = sampler->GetSamplerDescriptor();
d3d12Device->CreateSampler( d3d12Device->CreateSampler(

View File

@ -20,22 +20,22 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
BindGroupLayout::BindGroupLayout(Device* device, BindGroupLayout::BindGroupLayout(Device* device,
const nxt::BindGroupLayoutDescriptor* descriptor) const dawn::BindGroupLayoutDescriptor* descriptor)
: BindGroupLayoutBase(device, descriptor), mDescriptorCounts{} { : BindGroupLayoutBase(device, descriptor), mDescriptorCounts{} {
const auto& groupInfo = GetBindingInfo(); const auto& groupInfo = GetBindingInfo();
for (uint32_t binding : IterateBitSet(groupInfo.mask)) { for (uint32_t binding : IterateBitSet(groupInfo.mask)) {
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
mBindingOffsets[binding] = mDescriptorCounts[CBV]++; mBindingOffsets[binding] = mDescriptorCounts[CBV]++;
break; break;
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
mBindingOffsets[binding] = mDescriptorCounts[UAV]++; mBindingOffsets[binding] = mDescriptorCounts[UAV]++;
break; break;
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
mBindingOffsets[binding] = mDescriptorCounts[SRV]++; mBindingOffsets[binding] = mDescriptorCounts[SRV]++;
break; break;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
mBindingOffsets[binding] = mDescriptorCounts[Sampler]++; mBindingOffsets[binding] = mDescriptorCounts[Sampler]++;
break; break;
} }
@ -85,16 +85,16 @@ namespace backend { namespace d3d12 {
for (uint32_t binding : IterateBitSet(groupInfo.mask)) { for (uint32_t binding : IterateBitSet(groupInfo.mask)) {
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
mBindingOffsets[binding] += descriptorOffsets[CBV]; mBindingOffsets[binding] += descriptorOffsets[CBV];
break; break;
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
mBindingOffsets[binding] += descriptorOffsets[UAV]; mBindingOffsets[binding] += descriptorOffsets[UAV];
break; break;
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
mBindingOffsets[binding] += descriptorOffsets[SRV]; mBindingOffsets[binding] += descriptorOffsets[SRV];
break; break;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
mBindingOffsets[binding] += descriptorOffsets[Sampler]; mBindingOffsets[binding] += descriptorOffsets[Sampler];
break; break;
} }

View File

@ -25,7 +25,7 @@ namespace backend { namespace d3d12 {
class BindGroupLayout : public BindGroupLayoutBase { class BindGroupLayout : public BindGroupLayoutBase {
public: public:
BindGroupLayout(Device* device, const nxt::BindGroupLayoutDescriptor* descriptor); BindGroupLayout(Device* device, const dawn::BindGroupLayoutDescriptor* descriptor);
enum DescriptorType { enum DescriptorType {
CBV, CBV,

View File

@ -20,67 +20,67 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
namespace { namespace {
D3D12_BLEND D3D12Blend(nxt::BlendFactor factor) { D3D12_BLEND D3D12Blend(dawn::BlendFactor factor) {
switch (factor) { switch (factor) {
case nxt::BlendFactor::Zero: case dawn::BlendFactor::Zero:
return D3D12_BLEND_ZERO; return D3D12_BLEND_ZERO;
case nxt::BlendFactor::One: case dawn::BlendFactor::One:
return D3D12_BLEND_ONE; return D3D12_BLEND_ONE;
case nxt::BlendFactor::SrcColor: case dawn::BlendFactor::SrcColor:
return D3D12_BLEND_SRC_COLOR; return D3D12_BLEND_SRC_COLOR;
case nxt::BlendFactor::OneMinusSrcColor: case dawn::BlendFactor::OneMinusSrcColor:
return D3D12_BLEND_INV_SRC_COLOR; return D3D12_BLEND_INV_SRC_COLOR;
case nxt::BlendFactor::SrcAlpha: case dawn::BlendFactor::SrcAlpha:
return D3D12_BLEND_SRC_ALPHA; return D3D12_BLEND_SRC_ALPHA;
case nxt::BlendFactor::OneMinusSrcAlpha: case dawn::BlendFactor::OneMinusSrcAlpha:
return D3D12_BLEND_INV_SRC_ALPHA; return D3D12_BLEND_INV_SRC_ALPHA;
case nxt::BlendFactor::DstColor: case dawn::BlendFactor::DstColor:
return D3D12_BLEND_DEST_COLOR; return D3D12_BLEND_DEST_COLOR;
case nxt::BlendFactor::OneMinusDstColor: case dawn::BlendFactor::OneMinusDstColor:
return D3D12_BLEND_INV_DEST_COLOR; return D3D12_BLEND_INV_DEST_COLOR;
case nxt::BlendFactor::DstAlpha: case dawn::BlendFactor::DstAlpha:
return D3D12_BLEND_DEST_ALPHA; return D3D12_BLEND_DEST_ALPHA;
case nxt::BlendFactor::OneMinusDstAlpha: case dawn::BlendFactor::OneMinusDstAlpha:
return D3D12_BLEND_INV_DEST_ALPHA; return D3D12_BLEND_INV_DEST_ALPHA;
case nxt::BlendFactor::SrcAlphaSaturated: case dawn::BlendFactor::SrcAlphaSaturated:
return D3D12_BLEND_SRC_ALPHA_SAT; return D3D12_BLEND_SRC_ALPHA_SAT;
case nxt::BlendFactor::BlendColor: case dawn::BlendFactor::BlendColor:
return D3D12_BLEND_BLEND_FACTOR; return D3D12_BLEND_BLEND_FACTOR;
case nxt::BlendFactor::OneMinusBlendColor: case dawn::BlendFactor::OneMinusBlendColor:
return D3D12_BLEND_INV_BLEND_FACTOR; return D3D12_BLEND_INV_BLEND_FACTOR;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
D3D12_BLEND_OP D3D12BlendOperation(nxt::BlendOperation operation) { D3D12_BLEND_OP D3D12BlendOperation(dawn::BlendOperation operation) {
switch (operation) { switch (operation) {
case nxt::BlendOperation::Add: case dawn::BlendOperation::Add:
return D3D12_BLEND_OP_ADD; return D3D12_BLEND_OP_ADD;
case nxt::BlendOperation::Subtract: case dawn::BlendOperation::Subtract:
return D3D12_BLEND_OP_SUBTRACT; return D3D12_BLEND_OP_SUBTRACT;
case nxt::BlendOperation::ReverseSubtract: case dawn::BlendOperation::ReverseSubtract:
return D3D12_BLEND_OP_REV_SUBTRACT; return D3D12_BLEND_OP_REV_SUBTRACT;
case nxt::BlendOperation::Min: case dawn::BlendOperation::Min:
return D3D12_BLEND_OP_MIN; return D3D12_BLEND_OP_MIN;
case nxt::BlendOperation::Max: case dawn::BlendOperation::Max:
return D3D12_BLEND_OP_MAX; return D3D12_BLEND_OP_MAX;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
uint8_t D3D12RenderTargetWriteMask(nxt::ColorWriteMask colorWriteMask) { uint8_t D3D12RenderTargetWriteMask(dawn::ColorWriteMask colorWriteMask) {
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Red) == static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(dawn::ColorWriteMask::Red) ==
D3D12_COLOR_WRITE_ENABLE_RED, D3D12_COLOR_WRITE_ENABLE_RED,
"ColorWriteMask values must match"); "ColorWriteMask values must match");
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Green) == static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(dawn::ColorWriteMask::Green) ==
D3D12_COLOR_WRITE_ENABLE_GREEN, D3D12_COLOR_WRITE_ENABLE_GREEN,
"ColorWriteMask values must match"); "ColorWriteMask values must match");
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Blue) == static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(dawn::ColorWriteMask::Blue) ==
D3D12_COLOR_WRITE_ENABLE_BLUE, D3D12_COLOR_WRITE_ENABLE_BLUE,
"ColorWriteMask values must match"); "ColorWriteMask values must match");
static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(nxt::ColorWriteMask::Alpha) == static_assert(static_cast<D3D12_COLOR_WRITE_ENABLE>(dawn::ColorWriteMask::Alpha) ==
D3D12_COLOR_WRITE_ENABLE_ALPHA, D3D12_COLOR_WRITE_ENABLE_ALPHA,
"ColorWriteMask values must match"); "ColorWriteMask values must match");
return static_cast<uint8_t>(colorWriteMask); return static_cast<uint8_t>(colorWriteMask);

View File

@ -24,42 +24,42 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
namespace { namespace {
D3D12_RESOURCE_FLAGS D3D12ResourceFlags(nxt::BufferUsageBit usage) { D3D12_RESOURCE_FLAGS D3D12ResourceFlags(dawn::BufferUsageBit usage) {
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE; D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE;
if (usage & nxt::BufferUsageBit::Storage) { if (usage & dawn::BufferUsageBit::Storage) {
flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
} }
return flags; return flags;
} }
D3D12_RESOURCE_STATES D3D12BufferUsage(nxt::BufferUsageBit usage) { D3D12_RESOURCE_STATES D3D12BufferUsage(dawn::BufferUsageBit usage) {
D3D12_RESOURCE_STATES resourceState = D3D12_RESOURCE_STATE_COMMON; D3D12_RESOURCE_STATES resourceState = D3D12_RESOURCE_STATE_COMMON;
if (usage & nxt::BufferUsageBit::TransferSrc) { if (usage & dawn::BufferUsageBit::TransferSrc) {
resourceState |= D3D12_RESOURCE_STATE_COPY_SOURCE; resourceState |= D3D12_RESOURCE_STATE_COPY_SOURCE;
} }
if (usage & nxt::BufferUsageBit::TransferDst) { if (usage & dawn::BufferUsageBit::TransferDst) {
resourceState |= D3D12_RESOURCE_STATE_COPY_DEST; resourceState |= D3D12_RESOURCE_STATE_COPY_DEST;
} }
if (usage & (nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Uniform)) { if (usage & (dawn::BufferUsageBit::Vertex | dawn::BufferUsageBit::Uniform)) {
resourceState |= D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER; resourceState |= D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER;
} }
if (usage & nxt::BufferUsageBit::Index) { if (usage & dawn::BufferUsageBit::Index) {
resourceState |= D3D12_RESOURCE_STATE_INDEX_BUFFER; resourceState |= D3D12_RESOURCE_STATE_INDEX_BUFFER;
} }
if (usage & nxt::BufferUsageBit::Storage) { if (usage & dawn::BufferUsageBit::Storage) {
resourceState |= D3D12_RESOURCE_STATE_UNORDERED_ACCESS; resourceState |= D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
} }
return resourceState; return resourceState;
} }
D3D12_HEAP_TYPE D3D12HeapType(nxt::BufferUsageBit allowedUsage) { D3D12_HEAP_TYPE D3D12HeapType(dawn::BufferUsageBit allowedUsage) {
if (allowedUsage & nxt::BufferUsageBit::MapRead) { if (allowedUsage & dawn::BufferUsageBit::MapRead) {
return D3D12_HEAP_TYPE_READBACK; return D3D12_HEAP_TYPE_READBACK;
} else if (allowedUsage & nxt::BufferUsageBit::MapWrite) { } else if (allowedUsage & dawn::BufferUsageBit::MapWrite) {
return D3D12_HEAP_TYPE_UPLOAD; return D3D12_HEAP_TYPE_UPLOAD;
} else { } else {
return D3D12_HEAP_TYPE_DEFAULT; return D3D12_HEAP_TYPE_DEFAULT;
@ -89,7 +89,7 @@ namespace backend { namespace d3d12 {
if (heapType == D3D12_HEAP_TYPE_READBACK) { if (heapType == D3D12_HEAP_TYPE_READBACK) {
bufferUsage |= D3D12_RESOURCE_STATE_COPY_DEST; bufferUsage |= D3D12_RESOURCE_STATE_COPY_DEST;
mFixedResourceState = true; mFixedResourceState = true;
mLastUsage = nxt::BufferUsageBit::TransferDst; mLastUsage = dawn::BufferUsageBit::TransferDst;
} }
// D3D12 requires buffers on the UPLOAD heap to have the D3D12_RESOURCE_STATE_GENERIC_READ // D3D12 requires buffers on the UPLOAD heap to have the D3D12_RESOURCE_STATE_GENERIC_READ
@ -97,7 +97,7 @@ namespace backend { namespace d3d12 {
if (heapType == D3D12_HEAP_TYPE_UPLOAD) { if (heapType == D3D12_HEAP_TYPE_UPLOAD) {
bufferUsage |= D3D12_RESOURCE_STATE_GENERIC_READ; bufferUsage |= D3D12_RESOURCE_STATE_GENERIC_READ;
mFixedResourceState = true; mFixedResourceState = true;
mLastUsage = nxt::BufferUsageBit::TransferSrc; mLastUsage = dawn::BufferUsageBit::TransferSrc;
} }
mResource = ToBackend(GetDevice()) mResource = ToBackend(GetDevice())
@ -119,7 +119,7 @@ namespace backend { namespace d3d12 {
} }
void Buffer::TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList, void Buffer::TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList,
nxt::BufferUsageBit usage) { dawn::BufferUsageBit usage) {
// Resources in upload and readback heaps must be kept in the COPY_SOURCE/DEST state // Resources in upload and readback heaps must be kept in the COPY_SOURCE/DEST state
if (mFixedResourceState) { if (mFixedResourceState) {
ASSERT(usage == mLastUsage); ASSERT(usage == mLastUsage);
@ -164,7 +164,7 @@ namespace backend { namespace d3d12 {
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) { void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
TransitionUsageNow(device->GetPendingCommandList(), nxt::BufferUsageBit::TransferDst); TransitionUsageNow(device->GetPendingCommandList(), dawn::BufferUsageBit::TransferDst);
device->GetResourceUploader()->BufferSubData(mResource, start, count, data); device->GetResourceUploader()->BufferSubData(mResource, start, count, data);
} }

View File

@ -35,7 +35,7 @@ namespace backend { namespace d3d12 {
void OnMapCommandSerialFinished(uint32_t mapSerial, void* data, bool isWrite); void OnMapCommandSerialFinished(uint32_t mapSerial, void* data, bool isWrite);
void TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList, void TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList,
nxt::BufferUsageBit usage); dawn::BufferUsageBit usage);
private: private:
// NXT API // NXT API
@ -46,7 +46,7 @@ namespace backend { namespace d3d12 {
ComPtr<ID3D12Resource> mResource; ComPtr<ID3D12Resource> mResource;
bool mFixedResourceState = false; bool mFixedResourceState = false;
nxt::BufferUsageBit mLastUsage = nxt::BufferUsageBit::None; dawn::BufferUsageBit mLastUsage = dawn::BufferUsageBit::None;
}; };
class BufferView : public BufferViewBase { class BufferView : public BufferViewBase {

View File

@ -34,11 +34,11 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
namespace { namespace {
DXGI_FORMAT DXGIIndexFormat(nxt::IndexFormat format) { DXGI_FORMAT DXGIIndexFormat(dawn::IndexFormat format) {
switch (format) { switch (format) {
case nxt::IndexFormat::Uint16: case dawn::IndexFormat::Uint16:
return DXGI_FORMAT_R16_UINT; return DXGI_FORMAT_R16_UINT;
case nxt::IndexFormat::Uint32: case dawn::IndexFormat::Uint32:
return DXGI_FORMAT_R32_UINT; return DXGI_FORMAT_R32_UINT;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -308,8 +308,8 @@ namespace backend { namespace d3d12 {
Buffer* srcBuffer = ToBackend(copy->source.buffer.Get()); Buffer* srcBuffer = ToBackend(copy->source.buffer.Get());
Buffer* dstBuffer = ToBackend(copy->destination.buffer.Get()); Buffer* dstBuffer = ToBackend(copy->destination.buffer.Get());
srcBuffer->TransitionUsageNow(commandList, nxt::BufferUsageBit::TransferSrc); srcBuffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferSrc);
dstBuffer->TransitionUsageNow(commandList, nxt::BufferUsageBit::TransferDst); dstBuffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferDst);
commandList->CopyBufferRegion( commandList->CopyBufferRegion(
dstBuffer->GetD3D12Resource().Get(), copy->destination.offset, dstBuffer->GetD3D12Resource().Get(), copy->destination.offset,
@ -321,8 +321,8 @@ namespace backend { namespace d3d12 {
Buffer* buffer = ToBackend(copy->source.buffer.Get()); Buffer* buffer = ToBackend(copy->source.buffer.Get());
Texture* texture = ToBackend(copy->destination.texture.Get()); Texture* texture = ToBackend(copy->destination.texture.Get());
buffer->TransitionUsageNow(commandList, nxt::BufferUsageBit::TransferSrc); buffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferSrc);
texture->TransitionUsageNow(commandList, nxt::TextureUsageBit::TransferDst); texture->TransitionUsageNow(commandList, dawn::TextureUsageBit::TransferDst);
auto copySplit = ComputeTextureCopySplit( auto copySplit = ComputeTextureCopySplit(
copy->destination.x, copy->destination.y, copy->destination.z, copy->destination.x, copy->destination.y, copy->destination.z,
@ -367,8 +367,8 @@ namespace backend { namespace d3d12 {
Texture* texture = ToBackend(copy->source.texture.Get()); Texture* texture = ToBackend(copy->source.texture.Get());
Buffer* buffer = ToBackend(copy->destination.buffer.Get()); Buffer* buffer = ToBackend(copy->destination.buffer.Get());
texture->TransitionUsageNow(commandList, nxt::TextureUsageBit::TransferSrc); texture->TransitionUsageNow(commandList, dawn::TextureUsageBit::TransferSrc);
buffer->TransitionUsageNow(commandList, nxt::BufferUsageBit::TransferDst); buffer->TransitionUsageNow(commandList, dawn::BufferUsageBit::TransferDst);
auto copySplit = ComputeTextureCopySplit( auto copySplit = ComputeTextureCopySplit(
copy->source.x, copy->source.y, copy->source.z, copy->source.width, copy->source.x, copy->source.y, copy->source.z, copy->source.width,
@ -462,7 +462,7 @@ namespace backend { namespace d3d12 {
auto& attachmentInfo = renderPass->GetColorAttachment(i); auto& attachmentInfo = renderPass->GetColorAttachment(i);
// Load op - color // Load op - color
if (attachmentInfo.loadOp == nxt::LoadOp::Clear) { if (attachmentInfo.loadOp == dawn::LoadOp::Clear) {
D3D12_CPU_DESCRIPTOR_HANDLE handle = renderPass->GetRTVDescriptor(i); D3D12_CPU_DESCRIPTOR_HANDLE handle = renderPass->GetRTVDescriptor(i);
commandList->ClearRenderTargetView(handle, attachmentInfo.clearColor.data(), 0, commandList->ClearRenderTargetView(handle, attachmentInfo.clearColor.data(), 0,
nullptr); nullptr);
@ -475,9 +475,9 @@ namespace backend { namespace d3d12 {
// Load op - depth/stencil // Load op - depth/stencil
bool doDepthClear = TextureFormatHasDepth(texture->GetFormat()) && bool doDepthClear = TextureFormatHasDepth(texture->GetFormat()) &&
(attachmentInfo.depthLoadOp == nxt::LoadOp::Clear); (attachmentInfo.depthLoadOp == dawn::LoadOp::Clear);
bool doStencilClear = TextureFormatHasStencil(texture->GetFormat()) && bool doStencilClear = TextureFormatHasStencil(texture->GetFormat()) &&
(attachmentInfo.stencilLoadOp == nxt::LoadOp::Clear); (attachmentInfo.stencilLoadOp == dawn::LoadOp::Clear);
D3D12_CLEAR_FLAGS clearFlags = {}; D3D12_CLEAR_FLAGS clearFlags = {};
if (doDepthClear) { if (doDepthClear) {

View File

@ -33,8 +33,8 @@ namespace backend { namespace d3d12 {
// SPRIV-cross does matrix multiplication expecting row major matrices // SPRIV-cross does matrix multiplication expecting row major matrices
compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR; compileFlags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR;
const auto& module = ToBackend(builder->GetStageInfo(nxt::ShaderStage::Compute).module); const auto& module = ToBackend(builder->GetStageInfo(dawn::ShaderStage::Compute).module);
const auto& entryPoint = builder->GetStageInfo(nxt::ShaderStage::Compute).entryPoint; const auto& entryPoint = builder->GetStageInfo(dawn::ShaderStage::Compute).entryPoint;
const auto& hlslSource = module->GetHLSLSource(); const auto& hlslSource = module->GetHLSLSource();
ComPtr<ID3DBlob> compiledShader; ComPtr<ID3DBlob> compiledShader;

View File

@ -18,46 +18,46 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
static D3D12_STENCIL_OP StencilOp(nxt::StencilOperation op) { static D3D12_STENCIL_OP StencilOp(dawn::StencilOperation op) {
switch (op) { switch (op) {
case nxt::StencilOperation::Keep: case dawn::StencilOperation::Keep:
return D3D12_STENCIL_OP_KEEP; return D3D12_STENCIL_OP_KEEP;
case nxt::StencilOperation::Zero: case dawn::StencilOperation::Zero:
return D3D12_STENCIL_OP_ZERO; return D3D12_STENCIL_OP_ZERO;
case nxt::StencilOperation::Replace: case dawn::StencilOperation::Replace:
return D3D12_STENCIL_OP_REPLACE; return D3D12_STENCIL_OP_REPLACE;
case nxt::StencilOperation::IncrementClamp: case dawn::StencilOperation::IncrementClamp:
return D3D12_STENCIL_OP_INCR_SAT; return D3D12_STENCIL_OP_INCR_SAT;
case nxt::StencilOperation::DecrementClamp: case dawn::StencilOperation::DecrementClamp:
return D3D12_STENCIL_OP_DECR_SAT; return D3D12_STENCIL_OP_DECR_SAT;
case nxt::StencilOperation::Invert: case dawn::StencilOperation::Invert:
return D3D12_STENCIL_OP_INVERT; return D3D12_STENCIL_OP_INVERT;
case nxt::StencilOperation::IncrementWrap: case dawn::StencilOperation::IncrementWrap:
return D3D12_STENCIL_OP_INCR; return D3D12_STENCIL_OP_INCR;
case nxt::StencilOperation::DecrementWrap: case dawn::StencilOperation::DecrementWrap:
return D3D12_STENCIL_OP_DECR; return D3D12_STENCIL_OP_DECR;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
static D3D12_COMPARISON_FUNC ComparisonFunc(nxt::CompareFunction func) { static D3D12_COMPARISON_FUNC ComparisonFunc(dawn::CompareFunction func) {
switch (func) { switch (func) {
case nxt::CompareFunction::Always: case dawn::CompareFunction::Always:
return D3D12_COMPARISON_FUNC_ALWAYS; return D3D12_COMPARISON_FUNC_ALWAYS;
case nxt::CompareFunction::Equal: case dawn::CompareFunction::Equal:
return D3D12_COMPARISON_FUNC_EQUAL; return D3D12_COMPARISON_FUNC_EQUAL;
case nxt::CompareFunction::Greater: case dawn::CompareFunction::Greater:
return D3D12_COMPARISON_FUNC_GREATER; return D3D12_COMPARISON_FUNC_GREATER;
case nxt::CompareFunction::GreaterEqual: case dawn::CompareFunction::GreaterEqual:
return D3D12_COMPARISON_FUNC_GREATER_EQUAL; return D3D12_COMPARISON_FUNC_GREATER_EQUAL;
case nxt::CompareFunction::Less: case dawn::CompareFunction::Less:
return D3D12_COMPARISON_FUNC_LESS; return D3D12_COMPARISON_FUNC_LESS;
case nxt::CompareFunction::LessEqual: case dawn::CompareFunction::LessEqual:
return D3D12_COMPARISON_FUNC_LESS_EQUAL; return D3D12_COMPARISON_FUNC_LESS_EQUAL;
case nxt::CompareFunction::Never: case dawn::CompareFunction::Never:
return D3D12_COMPARISON_FUNC_NEVER; return D3D12_COMPARISON_FUNC_NEVER;
case nxt::CompareFunction::NotEqual: case dawn::CompareFunction::NotEqual:
return D3D12_COMPARISON_FUNC_NOT_EQUAL; return D3D12_COMPARISON_FUNC_NOT_EQUAL;
default: default:
UNREACHABLE(); UNREACHABLE();

View File

@ -267,7 +267,7 @@ namespace backend { namespace d3d12 {
return new BindGroup(this, builder); return new BindGroup(this, builder);
} }
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor); return new BindGroupLayout(this, descriptor);
} }
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) { BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
@ -292,7 +292,7 @@ namespace backend { namespace d3d12 {
return new InputState(this, builder); return new InputState(this, builder);
} }
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor); return new PipelineLayout(this, descriptor);
} }
ResultOrError<QueueBase*> Device::CreateQueueImpl() { ResultOrError<QueueBase*> Device::CreateQueueImpl() {
@ -306,7 +306,7 @@ namespace backend { namespace d3d12 {
return new RenderPipeline(builder); return new RenderPipeline(builder);
} }
ResultOrError<SamplerBase*> Device::CreateSamplerImpl( ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) { const dawn::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor); return new Sampler(this, descriptor);
} }
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) { ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -78,12 +78,12 @@ namespace backend { namespace d3d12 {
private: private:
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) override; const dawn::BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) override; const dawn::PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QueueBase*> CreateQueueImpl() override; ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl( ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override; const dawn::SamplerDescriptor* descriptor) override;
uint64_t mSerial = 0; uint64_t mSerial = 0;
ComPtr<ID3D12Fence> mFence; ComPtr<ID3D12Fence> mFence;

View File

@ -18,42 +18,42 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
static DXGI_FORMAT VertexFormatType(nxt::VertexFormat format) { static DXGI_FORMAT VertexFormatType(dawn::VertexFormat format) {
switch (format) { switch (format) {
case nxt::VertexFormat::FloatR32G32B32A32: case dawn::VertexFormat::FloatR32G32B32A32:
return DXGI_FORMAT_R32G32B32A32_FLOAT; return DXGI_FORMAT_R32G32B32A32_FLOAT;
case nxt::VertexFormat::FloatR32G32B32: case dawn::VertexFormat::FloatR32G32B32:
return DXGI_FORMAT_R32G32B32_FLOAT; return DXGI_FORMAT_R32G32B32_FLOAT;
case nxt::VertexFormat::FloatR32G32: case dawn::VertexFormat::FloatR32G32:
return DXGI_FORMAT_R32G32_FLOAT; return DXGI_FORMAT_R32G32_FLOAT;
case nxt::VertexFormat::FloatR32: case dawn::VertexFormat::FloatR32:
return DXGI_FORMAT_R32_FLOAT; return DXGI_FORMAT_R32_FLOAT;
case nxt::VertexFormat::IntR32G32B32A32: case dawn::VertexFormat::IntR32G32B32A32:
return DXGI_FORMAT_R32G32B32A32_SINT; return DXGI_FORMAT_R32G32B32A32_SINT;
case nxt::VertexFormat::IntR32G32B32: case dawn::VertexFormat::IntR32G32B32:
return DXGI_FORMAT_R32G32B32_SINT; return DXGI_FORMAT_R32G32B32_SINT;
case nxt::VertexFormat::IntR32G32: case dawn::VertexFormat::IntR32G32:
return DXGI_FORMAT_R32G32_SINT; return DXGI_FORMAT_R32G32_SINT;
case nxt::VertexFormat::IntR32: case dawn::VertexFormat::IntR32:
return DXGI_FORMAT_R32_SINT; return DXGI_FORMAT_R32_SINT;
case nxt::VertexFormat::UshortR16G16B16A16: case dawn::VertexFormat::UshortR16G16B16A16:
return DXGI_FORMAT_R16G16B16A16_UINT; return DXGI_FORMAT_R16G16B16A16_UINT;
case nxt::VertexFormat::UshortR16G16: case dawn::VertexFormat::UshortR16G16:
return DXGI_FORMAT_R16G16_UINT; return DXGI_FORMAT_R16G16_UINT;
case nxt::VertexFormat::UnormR8G8B8A8: case dawn::VertexFormat::UnormR8G8B8A8:
return DXGI_FORMAT_R8G8B8A8_UNORM; return DXGI_FORMAT_R8G8B8A8_UNORM;
case nxt::VertexFormat::UnormR8G8: case dawn::VertexFormat::UnormR8G8:
return DXGI_FORMAT_R8G8_UNORM; return DXGI_FORMAT_R8G8_UNORM;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
static D3D12_INPUT_CLASSIFICATION InputStepModeFunction(nxt::InputStepMode mode) { static D3D12_INPUT_CLASSIFICATION InputStepModeFunction(dawn::InputStepMode mode) {
switch (mode) { switch (mode) {
case nxt::InputStepMode::Vertex: case dawn::InputStepMode::Vertex:
return D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA; return D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
case nxt::InputStepMode::Instance: case dawn::InputStepMode::Instance:
return D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA; return D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA;
default: default:
UNREACHABLE(); UNREACHABLE();

View File

@ -111,8 +111,8 @@ namespace backend { namespace d3d12 {
return NXT_SWAP_CHAIN_NO_ERROR; return NXT_SWAP_CHAIN_NO_ERROR;
} }
nxt::TextureFormat NativeSwapChainImpl::GetPreferredFormat() const { dawn::TextureFormat NativeSwapChainImpl::GetPreferredFormat() const {
return nxt::TextureFormat::R8G8B8A8Unorm; return dawn::TextureFormat::R8G8B8A8Unorm;
} }
}} // namespace backend::d3d12 }} // namespace backend::d3d12

View File

@ -41,7 +41,7 @@ namespace backend { namespace d3d12 {
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture); nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture);
nxtSwapChainError Present(); nxtSwapChainError Present();
nxt::TextureFormat GetPreferredFormat() const; dawn::TextureFormat GetPreferredFormat() const;
private: private:
HWND mWindow = nullptr; HWND mWindow = nullptr;

View File

@ -23,7 +23,7 @@ using Microsoft::WRL::ComPtr;
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
PipelineLayout::PipelineLayout(Device* device, const nxt::PipelineLayoutDescriptor* descriptor) PipelineLayout::PipelineLayout(Device* device, const dawn::PipelineLayoutDescriptor* descriptor)
: PipelineLayoutBase(device, descriptor) { : PipelineLayoutBase(device, descriptor) {
D3D12_ROOT_PARAMETER rootParameters[kMaxBindGroups * 2]; D3D12_ROOT_PARAMETER rootParameters[kMaxBindGroups * 2];

View File

@ -25,7 +25,7 @@ namespace backend { namespace d3d12 {
class PipelineLayout : public PipelineLayoutBase { class PipelineLayout : public PipelineLayoutBase {
public: public:
PipelineLayout(Device* device, const nxt::PipelineLayoutDescriptor* descriptor); PipelineLayout(Device* device, const dawn::PipelineLayoutDescriptor* descriptor);
uint32_t GetCbvUavSrvRootParameterIndex(uint32_t group) const; uint32_t GetCbvUavSrvRootParameterIndex(uint32_t group) const;
uint32_t GetSamplerRootParameterIndex(uint32_t group) const; uint32_t GetSamplerRootParameterIndex(uint32_t group) const;

View File

@ -28,17 +28,17 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
namespace { namespace {
D3D12_PRIMITIVE_TOPOLOGY D3D12PrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) { D3D12_PRIMITIVE_TOPOLOGY D3D12PrimitiveTopology(dawn::PrimitiveTopology primitiveTopology) {
switch (primitiveTopology) { switch (primitiveTopology) {
case nxt::PrimitiveTopology::PointList: case dawn::PrimitiveTopology::PointList:
return D3D_PRIMITIVE_TOPOLOGY_POINTLIST; return D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
case nxt::PrimitiveTopology::LineList: case dawn::PrimitiveTopology::LineList:
return D3D_PRIMITIVE_TOPOLOGY_LINELIST; return D3D_PRIMITIVE_TOPOLOGY_LINELIST;
case nxt::PrimitiveTopology::LineStrip: case dawn::PrimitiveTopology::LineStrip:
return D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; return D3D_PRIMITIVE_TOPOLOGY_LINESTRIP;
case nxt::PrimitiveTopology::TriangleList: case dawn::PrimitiveTopology::TriangleList:
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
case nxt::PrimitiveTopology::TriangleStrip: case dawn::PrimitiveTopology::TriangleStrip:
return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -46,15 +46,15 @@ namespace backend { namespace d3d12 {
} }
D3D12_PRIMITIVE_TOPOLOGY_TYPE D3D12PrimitiveTopologyType( D3D12_PRIMITIVE_TOPOLOGY_TYPE D3D12PrimitiveTopologyType(
nxt::PrimitiveTopology primitiveTopology) { dawn::PrimitiveTopology primitiveTopology) {
switch (primitiveTopology) { switch (primitiveTopology) {
case nxt::PrimitiveTopology::PointList: case dawn::PrimitiveTopology::PointList:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT; return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT;
case nxt::PrimitiveTopology::LineList: case dawn::PrimitiveTopology::LineList:
case nxt::PrimitiveTopology::LineStrip: case dawn::PrimitiveTopology::LineStrip:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE; return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE;
case nxt::PrimitiveTopology::TriangleList: case dawn::PrimitiveTopology::TriangleList:
case nxt::PrimitiveTopology::TriangleStrip: case dawn::PrimitiveTopology::TriangleStrip:
return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -88,15 +88,15 @@ namespace backend { namespace d3d12 {
D3D12_SHADER_BYTECODE* shader = nullptr; D3D12_SHADER_BYTECODE* shader = nullptr;
switch (stage) { switch (stage) {
case nxt::ShaderStage::Vertex: case dawn::ShaderStage::Vertex:
shader = &descriptor.VS; shader = &descriptor.VS;
compileTarget = "vs_5_1"; compileTarget = "vs_5_1";
break; break;
case nxt::ShaderStage::Fragment: case dawn::ShaderStage::Fragment:
shader = &descriptor.PS; shader = &descriptor.PS;
compileTarget = "ps_5_1"; compileTarget = "ps_5_1";
break; break;
case nxt::ShaderStage::Compute: case dawn::ShaderStage::Compute:
UNREACHABLE(); UNREACHABLE();
break; break;
} }

View File

@ -19,13 +19,13 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
namespace { namespace {
D3D12_TEXTURE_ADDRESS_MODE AddressMode(nxt::AddressMode mode) { D3D12_TEXTURE_ADDRESS_MODE AddressMode(dawn::AddressMode mode) {
switch (mode) { switch (mode) {
case nxt::AddressMode::Repeat: case dawn::AddressMode::Repeat:
return D3D12_TEXTURE_ADDRESS_MODE_WRAP; return D3D12_TEXTURE_ADDRESS_MODE_WRAP;
case nxt::AddressMode::MirroredRepeat: case dawn::AddressMode::MirroredRepeat:
return D3D12_TEXTURE_ADDRESS_MODE_MIRROR; return D3D12_TEXTURE_ADDRESS_MODE_MIRROR;
case nxt::AddressMode::ClampToEdge: case dawn::AddressMode::ClampToEdge:
return D3D12_TEXTURE_ADDRESS_MODE_CLAMP; return D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -33,7 +33,7 @@ namespace backend { namespace d3d12 {
} }
} // namespace } // namespace
Sampler::Sampler(Device* device, const nxt::SamplerDescriptor* descriptor) Sampler::Sampler(Device* device, const dawn::SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) { : SamplerBase(device, descriptor) {
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn770367(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/dn770367(v=vs.85).aspx
// hex value, decimal value, min linear, mag linear, mip linear // hex value, decimal value, min linear, mag linear, mip linear
@ -53,25 +53,25 @@ namespace backend { namespace d3d12 {
uint8_t mode = 0; uint8_t mode = 0;
switch (descriptor->minFilter) { switch (descriptor->minFilter) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
break; break;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
mode += 16; mode += 16;
break; break;
} }
switch (descriptor->magFilter) { switch (descriptor->magFilter) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
break; break;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
mode += 4; mode += 4;
break; break;
} }
switch (descriptor->mipmapFilter) { switch (descriptor->mipmapFilter) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
break; break;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
mode += 1; mode += 1;
break; break;
} }

View File

@ -25,7 +25,7 @@ namespace backend { namespace d3d12 {
class Sampler : public SamplerBase { class Sampler : public SamplerBase {
public: public:
Sampler(Device* device, const nxt::SamplerDescriptor* descriptor); Sampler(Device* device, const dawn::SamplerDescriptor* descriptor);
const D3D12_SAMPLER_DESC& GetSamplerDescriptor() const; const D3D12_SAMPLER_DESC& GetSamplerDescriptor() const;

View File

@ -24,15 +24,15 @@ namespace backend { namespace d3d12 {
template <typename T> template <typename T>
class BindingTypeMap { class BindingTypeMap {
public: public:
T& operator[](nxt::BindingType type) { T& operator[](dawn::BindingType type) {
switch (type) { switch (type) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
return mMap[0]; return mMap[0];
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
return mMap[1]; return mMap[1];
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
return mMap[2]; return mMap[2];
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
return mMap[3]; return mMap[3];
default: default:
NXT_UNREACHABLE(); NXT_UNREACHABLE();

View File

@ -28,7 +28,7 @@ namespace backend { namespace d3d12 {
im.Init(im.userData, &wsiContext); im.Init(im.userData, &wsiContext);
ASSERT(im.textureUsage != NXT_TEXTURE_USAGE_BIT_NONE); ASSERT(im.textureUsage != NXT_TEXTURE_USAGE_BIT_NONE);
mTextureUsage = static_cast<nxt::TextureUsageBit>(im.textureUsage); mTextureUsage = static_cast<dawn::TextureUsageBit>(im.textureUsage);
} }
SwapChain::~SwapChain() { SwapChain::~SwapChain() {

View File

@ -28,7 +28,7 @@ namespace backend { namespace d3d12 {
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override; TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
void OnBeforePresent(TextureBase* texture) override; void OnBeforePresent(TextureBase* texture) override;
nxt::TextureUsageBit mTextureUsage; dawn::TextureUsageBit mTextureUsage;
}; };
}} // namespace backend::d3d12 }} // namespace backend::d3d12

View File

@ -20,29 +20,29 @@
namespace backend { namespace d3d12 { namespace backend { namespace d3d12 {
namespace { namespace {
D3D12_RESOURCE_STATES D3D12TextureUsage(nxt::TextureUsageBit usage, D3D12_RESOURCE_STATES D3D12TextureUsage(dawn::TextureUsageBit usage,
nxt::TextureFormat format) { dawn::TextureFormat format) {
D3D12_RESOURCE_STATES resourceState = D3D12_RESOURCE_STATE_COMMON; D3D12_RESOURCE_STATES resourceState = D3D12_RESOURCE_STATE_COMMON;
// Present is an exclusive flag. // Present is an exclusive flag.
if (usage & nxt::TextureUsageBit::Present) { if (usage & dawn::TextureUsageBit::Present) {
return D3D12_RESOURCE_STATE_PRESENT; return D3D12_RESOURCE_STATE_PRESENT;
} }
if (usage & nxt::TextureUsageBit::TransferSrc) { if (usage & dawn::TextureUsageBit::TransferSrc) {
resourceState |= D3D12_RESOURCE_STATE_COPY_SOURCE; resourceState |= D3D12_RESOURCE_STATE_COPY_SOURCE;
} }
if (usage & nxt::TextureUsageBit::TransferDst) { if (usage & dawn::TextureUsageBit::TransferDst) {
resourceState |= D3D12_RESOURCE_STATE_COPY_DEST; resourceState |= D3D12_RESOURCE_STATE_COPY_DEST;
} }
if (usage & nxt::TextureUsageBit::Sampled) { if (usage & dawn::TextureUsageBit::Sampled) {
resourceState |= (D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | resourceState |= (D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE |
D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
} }
if (usage & nxt::TextureUsageBit::Storage) { if (usage & dawn::TextureUsageBit::Storage) {
resourceState |= D3D12_RESOURCE_STATE_UNORDERED_ACCESS; resourceState |= D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
} }
if (usage & nxt::TextureUsageBit::OutputAttachment) { if (usage & dawn::TextureUsageBit::OutputAttachment) {
if (TextureFormatHasDepth(format) || TextureFormatHasStencil(format)) { if (TextureFormatHasDepth(format) || TextureFormatHasStencil(format)) {
resourceState |= D3D12_RESOURCE_STATE_DEPTH_WRITE; resourceState |= D3D12_RESOURCE_STATE_DEPTH_WRITE;
} else { } else {
@ -53,14 +53,14 @@ namespace backend { namespace d3d12 {
return resourceState; return resourceState;
} }
D3D12_RESOURCE_FLAGS D3D12ResourceFlags(nxt::TextureUsageBit usage, D3D12_RESOURCE_FLAGS D3D12ResourceFlags(dawn::TextureUsageBit usage,
nxt::TextureFormat format) { dawn::TextureFormat format) {
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE; D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE;
if (usage & nxt::TextureUsageBit::Storage) { if (usage & dawn::TextureUsageBit::Storage) {
flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
} }
if (usage & nxt::TextureUsageBit::OutputAttachment) { if (usage & dawn::TextureUsageBit::OutputAttachment) {
if (TextureFormatHasDepth(format) || TextureFormatHasStencil(format)) { if (TextureFormatHasDepth(format) || TextureFormatHasStencil(format)) {
flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
} else { } else {
@ -73,9 +73,9 @@ namespace backend { namespace d3d12 {
return flags; return flags;
} }
D3D12_RESOURCE_DIMENSION D3D12TextureDimension(nxt::TextureDimension dimension) { D3D12_RESOURCE_DIMENSION D3D12TextureDimension(dawn::TextureDimension dimension) {
switch (dimension) { switch (dimension) {
case nxt::TextureDimension::e2D: case dawn::TextureDimension::e2D:
return D3D12_RESOURCE_DIMENSION_TEXTURE2D; return D3D12_RESOURCE_DIMENSION_TEXTURE2D;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -84,23 +84,23 @@ namespace backend { namespace d3d12 {
} // namespace } // namespace
DXGI_FORMAT D3D12TextureFormat(nxt::TextureFormat format) { DXGI_FORMAT D3D12TextureFormat(dawn::TextureFormat format) {
switch (format) { switch (format) {
case nxt::TextureFormat::R8G8B8A8Unorm: case dawn::TextureFormat::R8G8B8A8Unorm:
return DXGI_FORMAT_R8G8B8A8_UNORM; return DXGI_FORMAT_R8G8B8A8_UNORM;
case nxt::TextureFormat::R8G8Unorm: case dawn::TextureFormat::R8G8Unorm:
return DXGI_FORMAT_R8G8_UNORM; return DXGI_FORMAT_R8G8_UNORM;
case nxt::TextureFormat::R8Unorm: case dawn::TextureFormat::R8Unorm:
return DXGI_FORMAT_R8_UNORM; return DXGI_FORMAT_R8_UNORM;
case nxt::TextureFormat::R8G8B8A8Uint: case dawn::TextureFormat::R8G8B8A8Uint:
return DXGI_FORMAT_R8G8B8A8_UINT; return DXGI_FORMAT_R8G8B8A8_UINT;
case nxt::TextureFormat::R8G8Uint: case dawn::TextureFormat::R8G8Uint:
return DXGI_FORMAT_R8G8_UINT; return DXGI_FORMAT_R8G8_UINT;
case nxt::TextureFormat::R8Uint: case dawn::TextureFormat::R8Uint:
return DXGI_FORMAT_R8_UINT; return DXGI_FORMAT_R8_UINT;
case nxt::TextureFormat::B8G8R8A8Unorm: case dawn::TextureFormat::B8G8R8A8Unorm:
return DXGI_FORMAT_B8G8R8A8_UNORM; return DXGI_FORMAT_B8G8R8A8_UNORM;
case nxt::TextureFormat::D32FloatS8Uint: case dawn::TextureFormat::D32FloatS8Uint:
return DXGI_FORMAT_D32_FLOAT_S8X24_UINT; return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -150,7 +150,7 @@ namespace backend { namespace d3d12 {
} }
void Texture::TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList, void Texture::TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList,
nxt::TextureUsageBit usage) { dawn::TextureUsageBit usage) {
// Avoid transitioning the texture when it isn't needed. // Avoid transitioning the texture when it isn't needed.
// TODO(cwallez@chromium.org): Need some form of UAV barriers at some point. // TODO(cwallez@chromium.org): Need some form of UAV barriers at some point.
if (usage == mLastUsage) { if (usage == mLastUsage) {
@ -177,7 +177,7 @@ namespace backend { namespace d3d12 {
mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat()); mSrvDesc.Format = D3D12TextureFormat(GetTexture()->GetFormat());
mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; mSrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
switch (GetTexture()->GetDimension()) { switch (GetTexture()->GetDimension()) {
case nxt::TextureDimension::e2D: case dawn::TextureDimension::e2D:
mSrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; mSrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
mSrvDesc.Texture2D.MostDetailedMip = 0; mSrvDesc.Texture2D.MostDetailedMip = 0;
mSrvDesc.Texture2D.MipLevels = GetTexture()->GetNumMipLevels(); mSrvDesc.Texture2D.MipLevels = GetTexture()->GetNumMipLevels();

View File

@ -23,7 +23,7 @@ namespace backend { namespace d3d12 {
class Device; class Device;
DXGI_FORMAT D3D12TextureFormat(nxt::TextureFormat format); DXGI_FORMAT D3D12TextureFormat(dawn::TextureFormat format);
class Texture : public TextureBase { class Texture : public TextureBase {
public: public:
@ -35,13 +35,13 @@ namespace backend { namespace d3d12 {
ID3D12Resource* GetD3D12Resource(); ID3D12Resource* GetD3D12Resource();
void TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList, void TransitionUsageNow(ComPtr<ID3D12GraphicsCommandList> commandList,
nxt::TextureUsageBit usage); dawn::TextureUsageBit usage);
private: private:
Device* mDevice; Device* mDevice;
ComPtr<ID3D12Resource> mResource = {}; ComPtr<ID3D12Resource> mResource = {};
ID3D12Resource* mResourcePtr = nullptr; ID3D12Resource* mResourcePtr = nullptr;
nxt::TextureUsageBit mLastUsage = nxt::TextureUsageBit::None; dawn::TextureUsageBit mLastUsage = dawn::TextureUsageBit::None;
}; };
class TextureView : public TextureViewBase { class TextureView : public TextureViewBase {

View File

@ -18,64 +18,64 @@ namespace backend { namespace metal {
namespace { namespace {
MTLBlendFactor MetalBlendFactor(nxt::BlendFactor factor, bool alpha) { MTLBlendFactor MetalBlendFactor(dawn::BlendFactor factor, bool alpha) {
switch (factor) { switch (factor) {
case nxt::BlendFactor::Zero: case dawn::BlendFactor::Zero:
return MTLBlendFactorZero; return MTLBlendFactorZero;
case nxt::BlendFactor::One: case dawn::BlendFactor::One:
return MTLBlendFactorOne; return MTLBlendFactorOne;
case nxt::BlendFactor::SrcColor: case dawn::BlendFactor::SrcColor:
return MTLBlendFactorSourceColor; return MTLBlendFactorSourceColor;
case nxt::BlendFactor::OneMinusSrcColor: case dawn::BlendFactor::OneMinusSrcColor:
return MTLBlendFactorOneMinusSourceColor; return MTLBlendFactorOneMinusSourceColor;
case nxt::BlendFactor::SrcAlpha: case dawn::BlendFactor::SrcAlpha:
return MTLBlendFactorSourceAlpha; return MTLBlendFactorSourceAlpha;
case nxt::BlendFactor::OneMinusSrcAlpha: case dawn::BlendFactor::OneMinusSrcAlpha:
return MTLBlendFactorOneMinusSourceAlpha; return MTLBlendFactorOneMinusSourceAlpha;
case nxt::BlendFactor::DstColor: case dawn::BlendFactor::DstColor:
return MTLBlendFactorDestinationColor; return MTLBlendFactorDestinationColor;
case nxt::BlendFactor::OneMinusDstColor: case dawn::BlendFactor::OneMinusDstColor:
return MTLBlendFactorOneMinusDestinationColor; return MTLBlendFactorOneMinusDestinationColor;
case nxt::BlendFactor::DstAlpha: case dawn::BlendFactor::DstAlpha:
return MTLBlendFactorDestinationAlpha; return MTLBlendFactorDestinationAlpha;
case nxt::BlendFactor::OneMinusDstAlpha: case dawn::BlendFactor::OneMinusDstAlpha:
return MTLBlendFactorOneMinusDestinationAlpha; return MTLBlendFactorOneMinusDestinationAlpha;
case nxt::BlendFactor::SrcAlphaSaturated: case dawn::BlendFactor::SrcAlphaSaturated:
return MTLBlendFactorSourceAlphaSaturated; return MTLBlendFactorSourceAlphaSaturated;
case nxt::BlendFactor::BlendColor: case dawn::BlendFactor::BlendColor:
return alpha ? MTLBlendFactorBlendAlpha : MTLBlendFactorBlendColor; return alpha ? MTLBlendFactorBlendAlpha : MTLBlendFactorBlendColor;
case nxt::BlendFactor::OneMinusBlendColor: case dawn::BlendFactor::OneMinusBlendColor:
return alpha ? MTLBlendFactorOneMinusBlendAlpha return alpha ? MTLBlendFactorOneMinusBlendAlpha
: MTLBlendFactorOneMinusBlendColor; : MTLBlendFactorOneMinusBlendColor;
} }
} }
MTLBlendOperation MetalBlendOperation(nxt::BlendOperation operation) { MTLBlendOperation MetalBlendOperation(dawn::BlendOperation operation) {
switch (operation) { switch (operation) {
case nxt::BlendOperation::Add: case dawn::BlendOperation::Add:
return MTLBlendOperationAdd; return MTLBlendOperationAdd;
case nxt::BlendOperation::Subtract: case dawn::BlendOperation::Subtract:
return MTLBlendOperationSubtract; return MTLBlendOperationSubtract;
case nxt::BlendOperation::ReverseSubtract: case dawn::BlendOperation::ReverseSubtract:
return MTLBlendOperationReverseSubtract; return MTLBlendOperationReverseSubtract;
case nxt::BlendOperation::Min: case dawn::BlendOperation::Min:
return MTLBlendOperationMin; return MTLBlendOperationMin;
case nxt::BlendOperation::Max: case dawn::BlendOperation::Max:
return MTLBlendOperationMax; return MTLBlendOperationMax;
} }
} }
MTLColorWriteMask MetalColorWriteMask(nxt::ColorWriteMask colorWriteMask) { MTLColorWriteMask MetalColorWriteMask(dawn::ColorWriteMask colorWriteMask) {
return (((colorWriteMask & nxt::ColorWriteMask::Red) != nxt::ColorWriteMask::None return (((colorWriteMask & dawn::ColorWriteMask::Red) != dawn::ColorWriteMask::None
? MTLColorWriteMaskRed ? MTLColorWriteMaskRed
: MTLColorWriteMaskNone) | : MTLColorWriteMaskNone) |
((colorWriteMask & nxt::ColorWriteMask::Green) != nxt::ColorWriteMask::None ((colorWriteMask & dawn::ColorWriteMask::Green) != dawn::ColorWriteMask::None
? MTLColorWriteMaskGreen ? MTLColorWriteMaskGreen
: MTLColorWriteMaskNone) | : MTLColorWriteMaskNone) |
((colorWriteMask & nxt::ColorWriteMask::Blue) != nxt::ColorWriteMask::None ((colorWriteMask & dawn::ColorWriteMask::Blue) != dawn::ColorWriteMask::None
? MTLColorWriteMaskBlue ? MTLColorWriteMaskBlue
: MTLColorWriteMaskNone) | : MTLColorWriteMaskNone) |
((colorWriteMask & nxt::ColorWriteMask::Alpha) != nxt::ColorWriteMask::None ((colorWriteMask & dawn::ColorWriteMask::Alpha) != dawn::ColorWriteMask::None
? MTLColorWriteMaskAlpha ? MTLColorWriteMaskAlpha
: MTLColorWriteMaskNone)); : MTLColorWriteMaskNone));
} }

View File

@ -21,7 +21,7 @@ namespace backend { namespace metal {
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) { Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
MTLResourceOptions storageMode; MTLResourceOptions storageMode;
if (GetAllowedUsage() & (nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::MapWrite)) { if (GetAllowedUsage() & (dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::MapWrite)) {
storageMode = MTLResourceStorageModeShared; storageMode = MTLResourceStorageModeShared;
} else { } else {
storageMode = MTLResourceStorageModePrivate; storageMode = MTLResourceStorageModePrivate;

View File

@ -54,7 +54,7 @@ namespace backend { namespace metal {
for (uint32_t i : IterateBitSet(desc->GetColorAttachmentMask())) { for (uint32_t i : IterateBitSet(desc->GetColorAttachmentMask())) {
auto& attachmentInfo = desc->GetColorAttachment(i); auto& attachmentInfo = desc->GetColorAttachment(i);
if (attachmentInfo.loadOp == nxt::LoadOp::Clear) { if (attachmentInfo.loadOp == dawn::LoadOp::Clear) {
descriptor.colorAttachments[i].loadAction = MTLLoadActionClear; descriptor.colorAttachments[i].loadAction = MTLLoadActionClear;
descriptor.colorAttachments[i].clearColor = MTLClearColorMake( descriptor.colorAttachments[i].clearColor = MTLClearColorMake(
attachmentInfo.clearColor[0], attachmentInfo.clearColor[1], attachmentInfo.clearColor[0], attachmentInfo.clearColor[1],
@ -73,13 +73,13 @@ namespace backend { namespace metal {
id<MTLTexture> texture = id<MTLTexture> texture =
ToBackend(attachmentInfo.view->GetTexture())->GetMTLTexture(); ToBackend(attachmentInfo.view->GetTexture())->GetMTLTexture();
nxt::TextureFormat format = attachmentInfo.view->GetTexture()->GetFormat(); dawn::TextureFormat format = attachmentInfo.view->GetTexture()->GetFormat();
if (TextureFormatHasDepth(format)) { if (TextureFormatHasDepth(format)) {
descriptor.depthAttachment.texture = texture; descriptor.depthAttachment.texture = texture;
descriptor.depthAttachment.storeAction = MTLStoreActionStore; descriptor.depthAttachment.storeAction = MTLStoreActionStore;
if (attachmentInfo.depthLoadOp == nxt::LoadOp::Clear) { if (attachmentInfo.depthLoadOp == dawn::LoadOp::Clear) {
descriptor.depthAttachment.loadAction = MTLLoadActionClear; descriptor.depthAttachment.loadAction = MTLLoadActionClear;
descriptor.depthAttachment.clearDepth = attachmentInfo.clearDepth; descriptor.depthAttachment.clearDepth = attachmentInfo.clearDepth;
} else { } else {
@ -91,7 +91,7 @@ namespace backend { namespace metal {
descriptor.stencilAttachment.texture = texture; descriptor.stencilAttachment.texture = texture;
descriptor.stencilAttachment.storeAction = MTLStoreActionStore; descriptor.stencilAttachment.storeAction = MTLStoreActionStore;
if (attachmentInfo.stencilLoadOp == nxt::LoadOp::Clear) { if (attachmentInfo.stencilLoadOp == dawn::LoadOp::Clear) {
descriptor.stencilAttachment.loadAction = MTLLoadActionClear; descriptor.stencilAttachment.loadAction = MTLLoadActionClear;
descriptor.stencilAttachment.clearStencil = attachmentInfo.clearStencil; descriptor.stencilAttachment.clearStencil = attachmentInfo.clearStencil;
} else { } else {
@ -123,9 +123,9 @@ namespace backend { namespace metal {
} }
auto stage = layout.visibilities[binding]; auto stage = layout.visibilities[binding];
bool hasVertStage = stage & nxt::ShaderStageBit::Vertex && render != nil; bool hasVertStage = stage & dawn::ShaderStageBit::Vertex && render != nil;
bool hasFragStage = stage & nxt::ShaderStageBit::Fragment && render != nil; bool hasFragStage = stage & dawn::ShaderStageBit::Fragment && render != nil;
bool hasComputeStage = stage & nxt::ShaderStageBit::Compute && compute != nil; bool hasComputeStage = stage & dawn::ShaderStageBit::Compute && compute != nil;
uint32_t vertIndex = 0; uint32_t vertIndex = 0;
uint32_t fragIndex = 0; uint32_t fragIndex = 0;
@ -133,20 +133,20 @@ namespace backend { namespace metal {
if (hasVertStage) { if (hasVertStage) {
vertIndex = pipelineLayout->GetBindingIndexInfo( vertIndex = pipelineLayout->GetBindingIndexInfo(
nxt::ShaderStage::Vertex)[index][binding]; dawn::ShaderStage::Vertex)[index][binding];
} }
if (hasFragStage) { if (hasFragStage) {
fragIndex = pipelineLayout->GetBindingIndexInfo( fragIndex = pipelineLayout->GetBindingIndexInfo(
nxt::ShaderStage::Fragment)[index][binding]; dawn::ShaderStage::Fragment)[index][binding];
} }
if (hasComputeStage) { if (hasComputeStage) {
computeIndex = pipelineLayout->GetBindingIndexInfo( computeIndex = pipelineLayout->GetBindingIndexInfo(
nxt::ShaderStage::Compute)[index][binding]; dawn::ShaderStage::Compute)[index][binding];
} }
switch (layout.types[binding]) { switch (layout.types[binding]) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
case nxt::BindingType::StorageBuffer: { case dawn::BindingType::StorageBuffer: {
BufferView* view = ToBackend(group->GetBindingAsBufferView(binding)); BufferView* view = ToBackend(group->GetBindingAsBufferView(binding));
auto b = ToBackend(view->GetBuffer()); auto b = ToBackend(view->GetBuffer());
const id<MTLBuffer> buffer = b->GetMTLBuffer(); const id<MTLBuffer> buffer = b->GetMTLBuffer();
@ -170,7 +170,7 @@ namespace backend { namespace metal {
} break; } break;
case nxt::BindingType::Sampler: { case dawn::BindingType::Sampler: {
auto sampler = ToBackend(group->GetBindingAsSampler(binding)); auto sampler = ToBackend(group->GetBindingAsSampler(binding));
if (hasVertStage) { if (hasVertStage) {
[render setVertexSamplerState:sampler->GetMTLSamplerState() [render setVertexSamplerState:sampler->GetMTLSamplerState()
@ -186,7 +186,7 @@ namespace backend { namespace metal {
} }
} break; } break;
case nxt::BindingType::SampledTexture: { case dawn::BindingType::SampledTexture: {
auto texture = auto texture =
ToBackend(group->GetBindingAsTextureView(binding)->GetTexture()); ToBackend(group->GetBindingAsTextureView(binding)->GetTexture());
if (hasVertStage) { if (hasVertStage) {
@ -348,7 +348,7 @@ namespace backend { namespace metal {
SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>(); SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
uint32_t* values = mCommands.NextData<uint32_t>(cmd->count); uint32_t* values = mCommands.NextData<uint32_t>(cmd->count);
if (cmd->stages & nxt::ShaderStageBit::Compute) { if (cmd->stages & dawn::ShaderStageBit::Compute) {
memcpy(&pushConstants[cmd->offset], values, cmd->count * sizeof(uint32_t)); memcpy(&pushConstants[cmd->offset], values, cmd->count * sizeof(uint32_t));
[encoder setBytes:&pushConstants [encoder setBytes:&pushConstants
@ -443,7 +443,7 @@ namespace backend { namespace metal {
SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>(); SetPushConstantsCmd* cmd = mCommands.NextCommand<SetPushConstantsCmd>();
uint32_t* values = mCommands.NextData<uint32_t>(cmd->count); uint32_t* values = mCommands.NextData<uint32_t>(cmd->count);
if (cmd->stages & nxt::ShaderStageBit::Vertex) { if (cmd->stages & dawn::ShaderStageBit::Vertex) {
memcpy(&vertexPushConstants[cmd->offset], values, memcpy(&vertexPushConstants[cmd->offset], values,
cmd->count * sizeof(uint32_t)); cmd->count * sizeof(uint32_t));
[encoder setVertexBytes:&vertexPushConstants [encoder setVertexBytes:&vertexPushConstants
@ -451,7 +451,7 @@ namespace backend { namespace metal {
atIndex:0]; atIndex:0];
} }
if (cmd->stages & nxt::ShaderStageBit::Fragment) { if (cmd->stages & dawn::ShaderStageBit::Fragment) {
memcpy(&fragmentPushConstants[cmd->offset], values, memcpy(&fragmentPushConstants[cmd->offset], values,
cmd->count * sizeof(uint32_t)); cmd->count * sizeof(uint32_t));
[encoder setFragmentBytes:&fragmentPushConstants [encoder setFragmentBytes:&fragmentPushConstants

View File

@ -23,8 +23,8 @@ namespace backend { namespace metal {
: ComputePipelineBase(builder) { : ComputePipelineBase(builder) {
auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice(); auto mtlDevice = ToBackend(builder->GetDevice())->GetMTLDevice();
const auto& module = ToBackend(builder->GetStageInfo(nxt::ShaderStage::Compute).module); const auto& module = ToBackend(builder->GetStageInfo(dawn::ShaderStage::Compute).module);
const auto& entryPoint = builder->GetStageInfo(nxt::ShaderStage::Compute).entryPoint; const auto& entryPoint = builder->GetStageInfo(dawn::ShaderStage::Compute).entryPoint;
auto compilationData = module->GetFunction(entryPoint.c_str(), ToBackend(GetLayout())); auto compilationData = module->GetFunction(entryPoint.c_str(), ToBackend(GetLayout()));

View File

@ -19,44 +19,44 @@
namespace backend { namespace metal { namespace backend { namespace metal {
namespace { namespace {
MTLCompareFunction MetalDepthStencilCompareFunction(nxt::CompareFunction compareFunction) { MTLCompareFunction MetalDepthStencilCompareFunction(dawn::CompareFunction compareFunction) {
switch (compareFunction) { switch (compareFunction) {
case nxt::CompareFunction::Never: case dawn::CompareFunction::Never:
return MTLCompareFunctionNever; return MTLCompareFunctionNever;
case nxt::CompareFunction::Less: case dawn::CompareFunction::Less:
return MTLCompareFunctionLess; return MTLCompareFunctionLess;
case nxt::CompareFunction::LessEqual: case dawn::CompareFunction::LessEqual:
return MTLCompareFunctionLessEqual; return MTLCompareFunctionLessEqual;
case nxt::CompareFunction::Greater: case dawn::CompareFunction::Greater:
return MTLCompareFunctionGreater; return MTLCompareFunctionGreater;
case nxt::CompareFunction::GreaterEqual: case dawn::CompareFunction::GreaterEqual:
return MTLCompareFunctionGreaterEqual; return MTLCompareFunctionGreaterEqual;
case nxt::CompareFunction::NotEqual: case dawn::CompareFunction::NotEqual:
return MTLCompareFunctionNotEqual; return MTLCompareFunctionNotEqual;
case nxt::CompareFunction::Equal: case dawn::CompareFunction::Equal:
return MTLCompareFunctionEqual; return MTLCompareFunctionEqual;
case nxt::CompareFunction::Always: case dawn::CompareFunction::Always:
return MTLCompareFunctionAlways; return MTLCompareFunctionAlways;
} }
} }
MTLStencilOperation MetalStencilOperation(nxt::StencilOperation stencilOperation) { MTLStencilOperation MetalStencilOperation(dawn::StencilOperation stencilOperation) {
switch (stencilOperation) { switch (stencilOperation) {
case nxt::StencilOperation::Keep: case dawn::StencilOperation::Keep:
return MTLStencilOperationKeep; return MTLStencilOperationKeep;
case nxt::StencilOperation::Zero: case dawn::StencilOperation::Zero:
return MTLStencilOperationZero; return MTLStencilOperationZero;
case nxt::StencilOperation::Replace: case dawn::StencilOperation::Replace:
return MTLStencilOperationReplace; return MTLStencilOperationReplace;
case nxt::StencilOperation::Invert: case dawn::StencilOperation::Invert:
return MTLStencilOperationInvert; return MTLStencilOperationInvert;
case nxt::StencilOperation::IncrementClamp: case dawn::StencilOperation::IncrementClamp:
return MTLStencilOperationIncrementClamp; return MTLStencilOperationIncrementClamp;
case nxt::StencilOperation::DecrementClamp: case dawn::StencilOperation::DecrementClamp:
return MTLStencilOperationDecrementClamp; return MTLStencilOperationDecrementClamp;
case nxt::StencilOperation::IncrementWrap: case dawn::StencilOperation::IncrementWrap:
return MTLStencilOperationIncrementWrap; return MTLStencilOperationIncrementWrap;
case nxt::StencilOperation::DecrementWrap: case dawn::StencilOperation::DecrementWrap:
return MTLStencilOperationDecrementWrap; return MTLStencilOperationDecrementWrap;
} }
} }

View File

@ -64,12 +64,12 @@ namespace backend { namespace metal {
private: private:
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) override; const dawn::BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) override; const dawn::PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QueueBase*> CreateQueueImpl() override; ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl( ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override; const dawn::SamplerDescriptor* descriptor) override;
void OnCompletedHandler(); void OnCompletedHandler();

View File

@ -86,7 +86,7 @@ namespace backend { namespace metal {
return new BindGroup(builder); return new BindGroup(builder);
} }
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor); return new BindGroupLayout(this, descriptor);
} }
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) { BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
@ -111,7 +111,7 @@ namespace backend { namespace metal {
return new InputState(builder); return new InputState(builder);
} }
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor); return new PipelineLayout(this, descriptor);
} }
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor( RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
@ -125,7 +125,7 @@ namespace backend { namespace metal {
return new Queue(this); return new Queue(this);
} }
ResultOrError<SamplerBase*> Device::CreateSamplerImpl( ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) { const dawn::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor); return new Sampler(this, descriptor);
} }
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) { ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -19,40 +19,40 @@
namespace backend { namespace metal { namespace backend { namespace metal {
namespace { namespace {
MTLVertexFormat VertexFormatType(nxt::VertexFormat format) { MTLVertexFormat VertexFormatType(dawn::VertexFormat format) {
switch (format) { switch (format) {
case nxt::VertexFormat::FloatR32G32B32A32: case dawn::VertexFormat::FloatR32G32B32A32:
return MTLVertexFormatFloat4; return MTLVertexFormatFloat4;
case nxt::VertexFormat::FloatR32G32B32: case dawn::VertexFormat::FloatR32G32B32:
return MTLVertexFormatFloat3; return MTLVertexFormatFloat3;
case nxt::VertexFormat::FloatR32G32: case dawn::VertexFormat::FloatR32G32:
return MTLVertexFormatFloat2; return MTLVertexFormatFloat2;
case nxt::VertexFormat::FloatR32: case dawn::VertexFormat::FloatR32:
return MTLVertexFormatFloat; return MTLVertexFormatFloat;
case nxt::VertexFormat::IntR32G32B32A32: case dawn::VertexFormat::IntR32G32B32A32:
return MTLVertexFormatInt4; return MTLVertexFormatInt4;
case nxt::VertexFormat::IntR32G32B32: case dawn::VertexFormat::IntR32G32B32:
return MTLVertexFormatInt3; return MTLVertexFormatInt3;
case nxt::VertexFormat::IntR32G32: case dawn::VertexFormat::IntR32G32:
return MTLVertexFormatInt2; return MTLVertexFormatInt2;
case nxt::VertexFormat::IntR32: case dawn::VertexFormat::IntR32:
return MTLVertexFormatInt; return MTLVertexFormatInt;
case nxt::VertexFormat::UshortR16G16B16A16: case dawn::VertexFormat::UshortR16G16B16A16:
return MTLVertexFormatUShort4; return MTLVertexFormatUShort4;
case nxt::VertexFormat::UshortR16G16: case dawn::VertexFormat::UshortR16G16:
return MTLVertexFormatUShort2; return MTLVertexFormatUShort2;
case nxt::VertexFormat::UnormR8G8B8A8: case dawn::VertexFormat::UnormR8G8B8A8:
return MTLVertexFormatUChar4Normalized; return MTLVertexFormatUChar4Normalized;
case nxt::VertexFormat::UnormR8G8: case dawn::VertexFormat::UnormR8G8:
return MTLVertexFormatUChar2Normalized; return MTLVertexFormatUChar2Normalized;
} }
} }
MTLVertexStepFunction InputStepModeFunction(nxt::InputStepMode mode) { MTLVertexStepFunction InputStepModeFunction(dawn::InputStepMode mode) {
switch (mode) { switch (mode) {
case nxt::InputStepMode::Vertex: case dawn::InputStepMode::Vertex:
return MTLVertexStepFunctionPerVertex; return MTLVertexStepFunctionPerVertex;
case nxt::InputStepMode::Instance: case dawn::InputStepMode::Instance:
return MTLVertexStepFunctionPerInstance; return MTLVertexStepFunctionPerInstance;
} }
} }

View File

@ -31,11 +31,11 @@ namespace backend { namespace metal {
class PipelineLayout : public PipelineLayoutBase { class PipelineLayout : public PipelineLayoutBase {
public: public:
PipelineLayout(Device* device, const nxt::PipelineLayoutDescriptor* descriptor); PipelineLayout(Device* device, const dawn::PipelineLayoutDescriptor* descriptor);
using BindingIndexInfo = using BindingIndexInfo =
std::array<std::array<uint32_t, kMaxBindingsPerGroup>, kMaxBindGroups>; std::array<std::array<uint32_t, kMaxBindingsPerGroup>, kMaxBindGroups>;
const BindingIndexInfo& GetBindingIndexInfo(nxt::ShaderStage stage) const; const BindingIndexInfo& GetBindingIndexInfo(dawn::ShaderStage stage) const;
private: private:
PerStage<BindingIndexInfo> mIndexInfo; PerStage<BindingIndexInfo> mIndexInfo;

View File

@ -20,7 +20,7 @@
namespace backend { namespace metal { namespace backend { namespace metal {
PipelineLayout::PipelineLayout(Device* device, const nxt::PipelineLayoutDescriptor* descriptor) PipelineLayout::PipelineLayout(Device* device, const dawn::PipelineLayoutDescriptor* descriptor)
: PipelineLayoutBase(device, descriptor) { : PipelineLayoutBase(device, descriptor) {
// Each stage has its own numbering namespace in CompilerMSL. // Each stage has its own numbering namespace in CompilerMSL.
for (auto stage : IterateStages(kAllStages)) { for (auto stage : IterateStages(kAllStages)) {
@ -40,16 +40,16 @@ namespace backend { namespace metal {
} }
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
mIndexInfo[stage][group][binding] = bufferIndex; mIndexInfo[stage][group][binding] = bufferIndex;
bufferIndex++; bufferIndex++;
break; break;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
mIndexInfo[stage][group][binding] = samplerIndex; mIndexInfo[stage][group][binding] = samplerIndex;
samplerIndex++; samplerIndex++;
break; break;
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
mIndexInfo[stage][group][binding] = textureIndex; mIndexInfo[stage][group][binding] = textureIndex;
textureIndex++; textureIndex++;
break; break;
@ -60,7 +60,7 @@ namespace backend { namespace metal {
} }
const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo( const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo(
nxt::ShaderStage stage) const { dawn::ShaderStage stage) const {
return mIndexInfo[stage]; return mIndexInfo[stage];
} }

View File

@ -25,40 +25,40 @@
namespace backend { namespace metal { namespace backend { namespace metal {
namespace { namespace {
MTLPrimitiveType MTLPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) { MTLPrimitiveType MTLPrimitiveTopology(dawn::PrimitiveTopology primitiveTopology) {
switch (primitiveTopology) { switch (primitiveTopology) {
case nxt::PrimitiveTopology::PointList: case dawn::PrimitiveTopology::PointList:
return MTLPrimitiveTypePoint; return MTLPrimitiveTypePoint;
case nxt::PrimitiveTopology::LineList: case dawn::PrimitiveTopology::LineList:
return MTLPrimitiveTypeLine; return MTLPrimitiveTypeLine;
case nxt::PrimitiveTopology::LineStrip: case dawn::PrimitiveTopology::LineStrip:
return MTLPrimitiveTypeLineStrip; return MTLPrimitiveTypeLineStrip;
case nxt::PrimitiveTopology::TriangleList: case dawn::PrimitiveTopology::TriangleList:
return MTLPrimitiveTypeTriangle; return MTLPrimitiveTypeTriangle;
case nxt::PrimitiveTopology::TriangleStrip: case dawn::PrimitiveTopology::TriangleStrip:
return MTLPrimitiveTypeTriangleStrip; return MTLPrimitiveTypeTriangleStrip;
} }
} }
MTLPrimitiveTopologyClass MTLInputPrimitiveTopology( MTLPrimitiveTopologyClass MTLInputPrimitiveTopology(
nxt::PrimitiveTopology primitiveTopology) { dawn::PrimitiveTopology primitiveTopology) {
switch (primitiveTopology) { switch (primitiveTopology) {
case nxt::PrimitiveTopology::PointList: case dawn::PrimitiveTopology::PointList:
return MTLPrimitiveTopologyClassPoint; return MTLPrimitiveTopologyClassPoint;
case nxt::PrimitiveTopology::LineList: case dawn::PrimitiveTopology::LineList:
case nxt::PrimitiveTopology::LineStrip: case dawn::PrimitiveTopology::LineStrip:
return MTLPrimitiveTopologyClassLine; return MTLPrimitiveTopologyClassLine;
case nxt::PrimitiveTopology::TriangleList: case dawn::PrimitiveTopology::TriangleList:
case nxt::PrimitiveTopology::TriangleStrip: case dawn::PrimitiveTopology::TriangleStrip:
return MTLPrimitiveTopologyClassTriangle; return MTLPrimitiveTopologyClassTriangle;
} }
} }
MTLIndexType MTLIndexFormat(nxt::IndexFormat format) { MTLIndexType MTLIndexFormat(dawn::IndexFormat format) {
switch (format) { switch (format) {
case nxt::IndexFormat::Uint16: case dawn::IndexFormat::Uint16:
return MTLIndexTypeUInt16; return MTLIndexTypeUInt16;
case nxt::IndexFormat::Uint32: case dawn::IndexFormat::Uint32:
return MTLIndexTypeUInt32; return MTLIndexTypeUInt32;
} }
} }
@ -81,20 +81,20 @@ namespace backend { namespace metal {
id<MTLFunction> function = data.function; id<MTLFunction> function = data.function;
switch (stage) { switch (stage) {
case nxt::ShaderStage::Vertex: case dawn::ShaderStage::Vertex:
descriptor.vertexFunction = function; descriptor.vertexFunction = function;
break; break;
case nxt::ShaderStage::Fragment: case dawn::ShaderStage::Fragment:
descriptor.fragmentFunction = function; descriptor.fragmentFunction = function;
break; break;
case nxt::ShaderStage::Compute: case dawn::ShaderStage::Compute:
UNREACHABLE(); UNREACHABLE();
} }
} }
if (HasDepthStencilAttachment()) { if (HasDepthStencilAttachment()) {
// TODO(kainino@chromium.org): Handle depth-only and stencil-only formats. // TODO(kainino@chromium.org): Handle depth-only and stencil-only formats.
nxt::TextureFormat depthStencilFormat = GetDepthStencilFormat(); dawn::TextureFormat depthStencilFormat = GetDepthStencilFormat();
descriptor.depthAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat); descriptor.depthAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat);
descriptor.stencilAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat); descriptor.stencilAttachmentPixelFormat = MetalPixelFormat(depthStencilFormat);
} }

View File

@ -25,7 +25,7 @@ namespace backend { namespace metal {
class Sampler : public SamplerBase { class Sampler : public SamplerBase {
public: public:
Sampler(Device* device, const nxt::SamplerDescriptor* descriptor); Sampler(Device* device, const dawn::SamplerDescriptor* descriptor);
~Sampler(); ~Sampler();
id<MTLSamplerState> GetMTLSamplerState(); id<MTLSamplerState> GetMTLSamplerState();

View File

@ -19,37 +19,37 @@
namespace backend { namespace metal { namespace backend { namespace metal {
namespace { namespace {
MTLSamplerMinMagFilter FilterModeToMinMagFilter(nxt::FilterMode mode) { MTLSamplerMinMagFilter FilterModeToMinMagFilter(dawn::FilterMode mode) {
switch (mode) { switch (mode) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
return MTLSamplerMinMagFilterNearest; return MTLSamplerMinMagFilterNearest;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
return MTLSamplerMinMagFilterLinear; return MTLSamplerMinMagFilterLinear;
} }
} }
MTLSamplerMipFilter FilterModeToMipFilter(nxt::FilterMode mode) { MTLSamplerMipFilter FilterModeToMipFilter(dawn::FilterMode mode) {
switch (mode) { switch (mode) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
return MTLSamplerMipFilterNearest; return MTLSamplerMipFilterNearest;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
return MTLSamplerMipFilterLinear; return MTLSamplerMipFilterLinear;
} }
} }
MTLSamplerAddressMode AddressMode(nxt::AddressMode mode) { MTLSamplerAddressMode AddressMode(dawn::AddressMode mode) {
switch (mode) { switch (mode) {
case nxt::AddressMode::Repeat: case dawn::AddressMode::Repeat:
return MTLSamplerAddressModeRepeat; return MTLSamplerAddressModeRepeat;
case nxt::AddressMode::MirroredRepeat: case dawn::AddressMode::MirroredRepeat:
return MTLSamplerAddressModeMirrorRepeat; return MTLSamplerAddressModeMirrorRepeat;
case nxt::AddressMode::ClampToEdge: case dawn::AddressMode::ClampToEdge:
return MTLSamplerAddressModeClampToEdge; return MTLSamplerAddressModeClampToEdge;
} }
} }
} }
Sampler::Sampler(Device* device, const nxt::SamplerDescriptor* descriptor) Sampler::Sampler(Device* device, const dawn::SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) { : SamplerBase(device, descriptor) {
MTLSamplerDescriptor* mtlDesc = [MTLSamplerDescriptor new]; MTLSamplerDescriptor* mtlDesc = [MTLSamplerDescriptor new];
[mtlDesc autorelease]; [mtlDesc autorelease];

View File

@ -26,13 +26,13 @@ namespace backend { namespace metal {
namespace { namespace {
spv::ExecutionModel SpirvExecutionModelForStage(nxt::ShaderStage stage) { spv::ExecutionModel SpirvExecutionModelForStage(dawn::ShaderStage stage) {
switch (stage) { switch (stage) {
case nxt::ShaderStage::Vertex: case dawn::ShaderStage::Vertex:
return spv::ExecutionModelVertex; return spv::ExecutionModelVertex;
case nxt::ShaderStage::Fragment: case dawn::ShaderStage::Fragment:
return spv::ExecutionModelFragment; return spv::ExecutionModelFragment;
case nxt::ShaderStage::Compute: case dawn::ShaderStage::Compute:
return spv::ExecutionModelGLCompute; return spv::ExecutionModelGLCompute;
default: default:
UNREACHABLE(); UNREACHABLE();

View File

@ -21,7 +21,7 @@
namespace backend { namespace metal { namespace backend { namespace metal {
MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format); MTLPixelFormat MetalPixelFormat(dawn::TextureFormat format);
class Texture : public TextureBase { class Texture : public TextureBase {
public: public:

View File

@ -18,49 +18,49 @@
namespace backend { namespace metal { namespace backend { namespace metal {
MTLPixelFormat MetalPixelFormat(nxt::TextureFormat format) { MTLPixelFormat MetalPixelFormat(dawn::TextureFormat format) {
switch (format) { switch (format) {
case nxt::TextureFormat::R8G8B8A8Unorm: case dawn::TextureFormat::R8G8B8A8Unorm:
return MTLPixelFormatRGBA8Unorm; return MTLPixelFormatRGBA8Unorm;
case nxt::TextureFormat::R8G8Unorm: case dawn::TextureFormat::R8G8Unorm:
return MTLPixelFormatRG8Unorm; return MTLPixelFormatRG8Unorm;
case nxt::TextureFormat::R8Unorm: case dawn::TextureFormat::R8Unorm:
return MTLPixelFormatR8Unorm; return MTLPixelFormatR8Unorm;
case nxt::TextureFormat::R8G8B8A8Uint: case dawn::TextureFormat::R8G8B8A8Uint:
return MTLPixelFormatRGBA8Uint; return MTLPixelFormatRGBA8Uint;
case nxt::TextureFormat::R8G8Uint: case dawn::TextureFormat::R8G8Uint:
return MTLPixelFormatRG8Uint; return MTLPixelFormatRG8Uint;
case nxt::TextureFormat::R8Uint: case dawn::TextureFormat::R8Uint:
return MTLPixelFormatR8Uint; return MTLPixelFormatR8Uint;
case nxt::TextureFormat::B8G8R8A8Unorm: case dawn::TextureFormat::B8G8R8A8Unorm:
return MTLPixelFormatBGRA8Unorm; return MTLPixelFormatBGRA8Unorm;
case nxt::TextureFormat::D32FloatS8Uint: case dawn::TextureFormat::D32FloatS8Uint:
return MTLPixelFormatDepth32Float_Stencil8; return MTLPixelFormatDepth32Float_Stencil8;
} }
} }
namespace { namespace {
MTLTextureUsage MetalTextureUsage(nxt::TextureUsageBit usage) { MTLTextureUsage MetalTextureUsage(dawn::TextureUsageBit usage) {
MTLTextureUsage result = MTLTextureUsageUnknown; // This is 0 MTLTextureUsage result = MTLTextureUsageUnknown; // This is 0
if (usage & (nxt::TextureUsageBit::Storage)) { if (usage & (dawn::TextureUsageBit::Storage)) {
result |= MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead; result |= MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead;
} }
if (usage & (nxt::TextureUsageBit::Sampled)) { if (usage & (dawn::TextureUsageBit::Sampled)) {
result |= MTLTextureUsageShaderRead; result |= MTLTextureUsageShaderRead;
} }
if (usage & (nxt::TextureUsageBit::OutputAttachment)) { if (usage & (dawn::TextureUsageBit::OutputAttachment)) {
result |= MTLTextureUsageRenderTarget; result |= MTLTextureUsageRenderTarget;
} }
return result; return result;
} }
MTLTextureType MetalTextureType(nxt::TextureDimension dimension) { MTLTextureType MetalTextureType(dawn::TextureDimension dimension) {
switch (dimension) { switch (dimension) {
case nxt::TextureDimension::e2D: case dawn::TextureDimension::e2D:
return MTLTextureType2D; return MTLTextureType2D;
} }
} }

View File

@ -40,7 +40,7 @@ namespace backend { namespace null {
return new BindGroup(builder); return new BindGroup(builder);
} }
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor); return new BindGroupLayout(this, descriptor);
} }
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) { BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
@ -65,7 +65,7 @@ namespace backend { namespace null {
return new InputState(builder); return new InputState(builder);
} }
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor); return new PipelineLayout(this, descriptor);
} }
ResultOrError<QueueBase*> Device::CreateQueueImpl() { ResultOrError<QueueBase*> Device::CreateQueueImpl() {
@ -79,7 +79,7 @@ namespace backend { namespace null {
return new RenderPipeline(builder); return new RenderPipeline(builder);
} }
ResultOrError<SamplerBase*> Device::CreateSamplerImpl( ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) { const dawn::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor); return new Sampler(this, descriptor);
} }
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) { ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
@ -124,8 +124,8 @@ namespace backend { namespace null {
}; };
Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) { Buffer::Buffer(BufferBuilder* builder) : BufferBase(builder) {
if (GetAllowedUsage() & (nxt::BufferUsageBit::TransferDst | nxt::BufferUsageBit::MapRead | if (GetAllowedUsage() & (dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::MapRead |
nxt::BufferUsageBit::MapWrite)) { dawn::BufferUsageBit::MapWrite)) {
mBackingData = std::unique_ptr<char[]>(new char[GetSize()]); mBackingData = std::unique_ptr<char[]>(new char[GetSize()]);
} }
} }

View File

@ -118,12 +118,12 @@ namespace backend { namespace null {
private: private:
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) override; const dawn::BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) override; const dawn::PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QueueBase*> CreateQueueImpl() override; ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl( ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override; const dawn::SamplerDescriptor* descriptor) override;
std::vector<std::unique_ptr<PendingOperation>> mPendingOperations; std::vector<std::unique_ptr<PendingOperation>> mPendingOperations;
}; };

View File

@ -19,50 +19,50 @@
namespace backend { namespace opengl { namespace backend { namespace opengl {
namespace { namespace {
GLenum GLBlendFactor(nxt::BlendFactor factor, bool alpha) { GLenum GLBlendFactor(dawn::BlendFactor factor, bool alpha) {
switch (factor) { switch (factor) {
case nxt::BlendFactor::Zero: case dawn::BlendFactor::Zero:
return GL_ZERO; return GL_ZERO;
case nxt::BlendFactor::One: case dawn::BlendFactor::One:
return GL_ONE; return GL_ONE;
case nxt::BlendFactor::SrcColor: case dawn::BlendFactor::SrcColor:
return GL_SRC_COLOR; return GL_SRC_COLOR;
case nxt::BlendFactor::OneMinusSrcColor: case dawn::BlendFactor::OneMinusSrcColor:
return GL_ONE_MINUS_SRC_COLOR; return GL_ONE_MINUS_SRC_COLOR;
case nxt::BlendFactor::SrcAlpha: case dawn::BlendFactor::SrcAlpha:
return GL_SRC_ALPHA; return GL_SRC_ALPHA;
case nxt::BlendFactor::OneMinusSrcAlpha: case dawn::BlendFactor::OneMinusSrcAlpha:
return GL_ONE_MINUS_SRC_ALPHA; return GL_ONE_MINUS_SRC_ALPHA;
case nxt::BlendFactor::DstColor: case dawn::BlendFactor::DstColor:
return GL_DST_COLOR; return GL_DST_COLOR;
case nxt::BlendFactor::OneMinusDstColor: case dawn::BlendFactor::OneMinusDstColor:
return GL_ONE_MINUS_DST_COLOR; return GL_ONE_MINUS_DST_COLOR;
case nxt::BlendFactor::DstAlpha: case dawn::BlendFactor::DstAlpha:
return GL_DST_ALPHA; return GL_DST_ALPHA;
case nxt::BlendFactor::OneMinusDstAlpha: case dawn::BlendFactor::OneMinusDstAlpha:
return GL_ONE_MINUS_DST_ALPHA; return GL_ONE_MINUS_DST_ALPHA;
case nxt::BlendFactor::SrcAlphaSaturated: case dawn::BlendFactor::SrcAlphaSaturated:
return GL_SRC_ALPHA_SATURATE; return GL_SRC_ALPHA_SATURATE;
case nxt::BlendFactor::BlendColor: case dawn::BlendFactor::BlendColor:
return alpha ? GL_CONSTANT_ALPHA : GL_CONSTANT_COLOR; return alpha ? GL_CONSTANT_ALPHA : GL_CONSTANT_COLOR;
case nxt::BlendFactor::OneMinusBlendColor: case dawn::BlendFactor::OneMinusBlendColor:
return alpha ? GL_ONE_MINUS_CONSTANT_ALPHA : GL_ONE_MINUS_CONSTANT_COLOR; return alpha ? GL_ONE_MINUS_CONSTANT_ALPHA : GL_ONE_MINUS_CONSTANT_COLOR;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
GLenum GLBlendMode(nxt::BlendOperation operation) { GLenum GLBlendMode(dawn::BlendOperation operation) {
switch (operation) { switch (operation) {
case nxt::BlendOperation::Add: case dawn::BlendOperation::Add:
return GL_FUNC_ADD; return GL_FUNC_ADD;
case nxt::BlendOperation::Subtract: case dawn::BlendOperation::Subtract:
return GL_FUNC_SUBTRACT; return GL_FUNC_SUBTRACT;
case nxt::BlendOperation::ReverseSubtract: case dawn::BlendOperation::ReverseSubtract:
return GL_FUNC_REVERSE_SUBTRACT; return GL_FUNC_REVERSE_SUBTRACT;
case nxt::BlendOperation::Min: case dawn::BlendOperation::Min:
return GL_MIN; return GL_MIN;
case nxt::BlendOperation::Max: case dawn::BlendOperation::Max:
return GL_MAX; return GL_MAX;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -87,10 +87,10 @@ namespace backend { namespace opengl {
} else { } else {
glDisablei(GL_BLEND, attachment); glDisablei(GL_BLEND, attachment);
} }
glColorMaski(attachment, info.colorWriteMask & nxt::ColorWriteMask::Red, glColorMaski(attachment, info.colorWriteMask & dawn::ColorWriteMask::Red,
info.colorWriteMask & nxt::ColorWriteMask::Green, info.colorWriteMask & dawn::ColorWriteMask::Green,
info.colorWriteMask & nxt::ColorWriteMask::Blue, info.colorWriteMask & dawn::ColorWriteMask::Blue,
info.colorWriteMask & nxt::ColorWriteMask::Alpha); info.colorWriteMask & dawn::ColorWriteMask::Alpha);
} }
}} // namespace backend::opengl }} // namespace backend::opengl

View File

@ -32,44 +32,44 @@ namespace backend { namespace opengl {
namespace { namespace {
GLenum IndexFormatType(nxt::IndexFormat format) { GLenum IndexFormatType(dawn::IndexFormat format) {
switch (format) { switch (format) {
case nxt::IndexFormat::Uint16: case dawn::IndexFormat::Uint16:
return GL_UNSIGNED_SHORT; return GL_UNSIGNED_SHORT;
case nxt::IndexFormat::Uint32: case dawn::IndexFormat::Uint32:
return GL_UNSIGNED_INT; return GL_UNSIGNED_INT;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
GLenum VertexFormatType(nxt::VertexFormat format) { GLenum VertexFormatType(dawn::VertexFormat format) {
switch (format) { switch (format) {
case nxt::VertexFormat::FloatR32G32B32A32: case dawn::VertexFormat::FloatR32G32B32A32:
case nxt::VertexFormat::FloatR32G32B32: case dawn::VertexFormat::FloatR32G32B32:
case nxt::VertexFormat::FloatR32G32: case dawn::VertexFormat::FloatR32G32:
case nxt::VertexFormat::FloatR32: case dawn::VertexFormat::FloatR32:
return GL_FLOAT; return GL_FLOAT;
case nxt::VertexFormat::IntR32G32B32A32: case dawn::VertexFormat::IntR32G32B32A32:
case nxt::VertexFormat::IntR32G32B32: case dawn::VertexFormat::IntR32G32B32:
case nxt::VertexFormat::IntR32G32: case dawn::VertexFormat::IntR32G32:
case nxt::VertexFormat::IntR32: case dawn::VertexFormat::IntR32:
return GL_INT; return GL_INT;
case nxt::VertexFormat::UshortR16G16B16A16: case dawn::VertexFormat::UshortR16G16B16A16:
case nxt::VertexFormat::UshortR16G16: case dawn::VertexFormat::UshortR16G16:
return GL_UNSIGNED_SHORT; return GL_UNSIGNED_SHORT;
case nxt::VertexFormat::UnormR8G8B8A8: case dawn::VertexFormat::UnormR8G8B8A8:
case nxt::VertexFormat::UnormR8G8: case dawn::VertexFormat::UnormR8G8:
return GL_UNSIGNED_BYTE; return GL_UNSIGNED_BYTE;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
GLboolean VertexFormatIsNormalized(nxt::VertexFormat format) { GLboolean VertexFormatIsNormalized(dawn::VertexFormat format) {
switch (format) { switch (format) {
case nxt::VertexFormat::UnormR8G8B8A8: case dawn::VertexFormat::UnormR8G8B8A8:
case nxt::VertexFormat::UnormR8G8: case dawn::VertexFormat::UnormR8G8:
return GL_TRUE; return GL_TRUE;
default: default:
return GL_FALSE; return GL_FALSE;
@ -92,7 +92,7 @@ namespace backend { namespace opengl {
} }
} }
void OnSetPushConstants(nxt::ShaderStageBit stages, void OnSetPushConstants(dawn::ShaderStageBit stages,
uint32_t count, uint32_t count,
uint32_t offset, uint32_t offset,
const uint32_t* data) { const uint32_t* data) {
@ -237,7 +237,7 @@ namespace backend { namespace opengl {
for (uint32_t binding : IterateBitSet(layout.mask)) { for (uint32_t binding : IterateBitSet(layout.mask)) {
switch (layout.types[binding]) { switch (layout.types[binding]) {
case nxt::BindingType::UniformBuffer: { case dawn::BindingType::UniformBuffer: {
BufferView* view = ToBackend(group->GetBindingAsBufferView(binding)); BufferView* view = ToBackend(group->GetBindingAsBufferView(binding));
GLuint buffer = ToBackend(view->GetBuffer())->GetHandle(); GLuint buffer = ToBackend(view->GetBuffer())->GetHandle();
GLuint uboIndex = indices[binding]; GLuint uboIndex = indices[binding];
@ -246,7 +246,7 @@ namespace backend { namespace opengl {
view->GetSize()); view->GetSize());
} break; } break;
case nxt::BindingType::Sampler: { case dawn::BindingType::Sampler: {
GLuint sampler = GLuint sampler =
ToBackend(group->GetBindingAsSampler(binding))->GetHandle(); ToBackend(group->GetBindingAsSampler(binding))->GetHandle();
GLuint samplerIndex = indices[binding]; GLuint samplerIndex = indices[binding];
@ -256,7 +256,7 @@ namespace backend { namespace opengl {
} }
} break; } break;
case nxt::BindingType::SampledTexture: { case dawn::BindingType::SampledTexture: {
TextureView* view = ToBackend(group->GetBindingAsTextureView(binding)); TextureView* view = ToBackend(group->GetBindingAsTextureView(binding));
Texture* texture = ToBackend(view->GetTexture()); Texture* texture = ToBackend(view->GetTexture());
GLuint handle = texture->GetHandle(); GLuint handle = texture->GetHandle();
@ -269,7 +269,7 @@ namespace backend { namespace opengl {
} }
} break; } break;
case nxt::BindingType::StorageBuffer: { case dawn::BindingType::StorageBuffer: {
BufferView* view = ToBackend(group->GetBindingAsBufferView(binding)); BufferView* view = ToBackend(group->GetBindingAsBufferView(binding));
GLuint buffer = ToBackend(view->GetBuffer())->GetHandle(); GLuint buffer = ToBackend(view->GetBuffer())->GetHandle();
GLuint ssboIndex = indices[binding]; GLuint ssboIndex = indices[binding];
@ -331,7 +331,7 @@ namespace backend { namespace opengl {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(target, texture->GetHandle()); glBindTexture(target, texture->GetHandle());
ASSERT(texture->GetDimension() == nxt::TextureDimension::e2D); ASSERT(texture->GetDimension() == dawn::TextureDimension::e2D);
glPixelStorei(GL_UNPACK_ROW_LENGTH, glPixelStorei(GL_UNPACK_ROW_LENGTH,
copy->rowPitch / TextureFormatPixelSize(texture->GetFormat())); copy->rowPitch / TextureFormatPixelSize(texture->GetFormat()));
glTexSubImage2D(target, dst.level, dst.x, dst.y, dst.width, dst.height, glTexSubImage2D(target, dst.level, dst.x, dst.y, dst.width, dst.height,
@ -351,7 +351,7 @@ namespace backend { namespace opengl {
// The only way to move data from a texture to a buffer in GL is via // The only way to move data from a texture to a buffer in GL is via
// glReadPixels with a pack buffer. Create a temporary FBO for the copy. // glReadPixels with a pack buffer. Create a temporary FBO for the copy.
ASSERT(texture->GetDimension() == nxt::TextureDimension::e2D); ASSERT(texture->GetDimension() == dawn::TextureDimension::e2D);
glBindTexture(GL_TEXTURE_2D, texture->GetHandle()); glBindTexture(GL_TEXTURE_2D, texture->GetHandle());
GLuint readFBO = 0; GLuint readFBO = 0;
@ -462,18 +462,18 @@ namespace backend { namespace opengl {
// TODO(kainino@chromium.org): the color clears (later in // TODO(kainino@chromium.org): the color clears (later in
// this function) may be undefined for non-normalized integer formats. // this function) may be undefined for non-normalized integer formats.
nxt::TextureFormat format = textureView->GetTexture()->GetFormat(); dawn::TextureFormat format = textureView->GetTexture()->GetFormat();
ASSERT(format == nxt::TextureFormat::R8G8B8A8Unorm || ASSERT(format == dawn::TextureFormat::R8G8B8A8Unorm ||
format == nxt::TextureFormat::R8G8Unorm || format == dawn::TextureFormat::R8G8Unorm ||
format == nxt::TextureFormat::R8Unorm || format == dawn::TextureFormat::R8Unorm ||
format == nxt::TextureFormat::B8G8R8A8Unorm); format == dawn::TextureFormat::B8G8R8A8Unorm);
} }
glDrawBuffers(attachmentCount, drawBuffers.data()); glDrawBuffers(attachmentCount, drawBuffers.data());
if (renderPass->HasDepthStencilAttachment()) { if (renderPass->HasDepthStencilAttachment()) {
TextureViewBase* textureView = renderPass->GetDepthStencilAttachment().view.Get(); TextureViewBase* textureView = renderPass->GetDepthStencilAttachment().view.Get();
GLuint texture = ToBackend(textureView->GetTexture())->GetHandle(); GLuint texture = ToBackend(textureView->GetTexture())->GetHandle();
nxt::TextureFormat format = textureView->GetTexture()->GetFormat(); dawn::TextureFormat format = textureView->GetTexture()->GetFormat();
// Attach depth/stencil buffer. // Attach depth/stencil buffer.
GLenum glAttachment = 0; GLenum glAttachment = 0;
@ -494,7 +494,7 @@ namespace backend { namespace opengl {
// TODO(kainino@chromium.org): the depth/stencil clears (later in // TODO(kainino@chromium.org): the depth/stencil clears (later in
// this function) may be undefined for other texture formats. // this function) may be undefined for other texture formats.
ASSERT(format == nxt::TextureFormat::D32FloatS8Uint); ASSERT(format == dawn::TextureFormat::D32FloatS8Uint);
} }
} }
@ -504,21 +504,21 @@ namespace backend { namespace opengl {
const auto& attachmentInfo = renderPass->GetColorAttachment(i); const auto& attachmentInfo = renderPass->GetColorAttachment(i);
// Load op - color // Load op - color
if (attachmentInfo.loadOp == nxt::LoadOp::Clear) { if (attachmentInfo.loadOp == dawn::LoadOp::Clear) {
glClearBufferfv(GL_COLOR, i, attachmentInfo.clearColor.data()); glClearBufferfv(GL_COLOR, i, attachmentInfo.clearColor.data());
} }
} }
if (renderPass->HasDepthStencilAttachment()) { if (renderPass->HasDepthStencilAttachment()) {
const auto& attachmentInfo = renderPass->GetDepthStencilAttachment(); const auto& attachmentInfo = renderPass->GetDepthStencilAttachment();
nxt::TextureFormat attachmentFormat = dawn::TextureFormat attachmentFormat =
attachmentInfo.view->GetTexture()->GetFormat(); attachmentInfo.view->GetTexture()->GetFormat();
// Load op - depth/stencil // Load op - depth/stencil
bool doDepthClear = TextureFormatHasDepth(attachmentFormat) && bool doDepthClear = TextureFormatHasDepth(attachmentFormat) &&
(attachmentInfo.depthLoadOp == nxt::LoadOp::Clear); (attachmentInfo.depthLoadOp == dawn::LoadOp::Clear);
bool doStencilClear = TextureFormatHasStencil(attachmentFormat) && bool doStencilClear = TextureFormatHasStencil(attachmentFormat) &&
(attachmentInfo.stencilLoadOp == nxt::LoadOp::Clear); (attachmentInfo.stencilLoadOp == dawn::LoadOp::Clear);
if (doDepthClear && doStencilClear) { if (doDepthClear && doStencilClear) {
glClearBufferfi(GL_DEPTH_STENCIL, 0, attachmentInfo.clearDepth, glClearBufferfi(GL_DEPTH_STENCIL, 0, attachmentInfo.clearDepth,
attachmentInfo.clearStencil); attachmentInfo.clearStencil);
@ -576,7 +576,7 @@ namespace backend { namespace opengl {
pushConstants.Apply(lastPipeline, lastPipeline); pushConstants.Apply(lastPipeline, lastPipeline);
inputBuffers.Apply(); inputBuffers.Apply();
nxt::IndexFormat indexFormat = lastPipeline->GetIndexFormat(); dawn::IndexFormat indexFormat = lastPipeline->GetIndexFormat();
size_t formatSize = IndexFormatSize(indexFormat); size_t formatSize = IndexFormatSize(indexFormat);
GLenum formatType = IndexFormatType(indexFormat); GLenum formatType = IndexFormatType(indexFormat);

View File

@ -20,46 +20,46 @@
namespace backend { namespace opengl { namespace backend { namespace opengl {
namespace { namespace {
GLuint OpenGLCompareFunction(nxt::CompareFunction compareFunction) { GLuint OpenGLCompareFunction(dawn::CompareFunction compareFunction) {
switch (compareFunction) { switch (compareFunction) {
case nxt::CompareFunction::Never: case dawn::CompareFunction::Never:
return GL_NEVER; return GL_NEVER;
case nxt::CompareFunction::Less: case dawn::CompareFunction::Less:
return GL_LESS; return GL_LESS;
case nxt::CompareFunction::LessEqual: case dawn::CompareFunction::LessEqual:
return GL_LEQUAL; return GL_LEQUAL;
case nxt::CompareFunction::Greater: case dawn::CompareFunction::Greater:
return GL_GREATER; return GL_GREATER;
case nxt::CompareFunction::GreaterEqual: case dawn::CompareFunction::GreaterEqual:
return GL_GEQUAL; return GL_GEQUAL;
case nxt::CompareFunction::NotEqual: case dawn::CompareFunction::NotEqual:
return GL_NOTEQUAL; return GL_NOTEQUAL;
case nxt::CompareFunction::Equal: case dawn::CompareFunction::Equal:
return GL_EQUAL; return GL_EQUAL;
case nxt::CompareFunction::Always: case dawn::CompareFunction::Always:
return GL_ALWAYS; return GL_ALWAYS;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
GLuint OpenGLStencilOperation(nxt::StencilOperation stencilOperation) { GLuint OpenGLStencilOperation(dawn::StencilOperation stencilOperation) {
switch (stencilOperation) { switch (stencilOperation) {
case nxt::StencilOperation::Keep: case dawn::StencilOperation::Keep:
return GL_KEEP; return GL_KEEP;
case nxt::StencilOperation::Zero: case dawn::StencilOperation::Zero:
return GL_ZERO; return GL_ZERO;
case nxt::StencilOperation::Replace: case dawn::StencilOperation::Replace:
return GL_REPLACE; return GL_REPLACE;
case nxt::StencilOperation::Invert: case dawn::StencilOperation::Invert:
return GL_INVERT; return GL_INVERT;
case nxt::StencilOperation::IncrementClamp: case dawn::StencilOperation::IncrementClamp:
return GL_INCR; return GL_INCR;
case nxt::StencilOperation::DecrementClamp: case dawn::StencilOperation::DecrementClamp:
return GL_DECR; return GL_DECR;
case nxt::StencilOperation::IncrementWrap: case dawn::StencilOperation::IncrementWrap:
return GL_INCR_WRAP; return GL_INCR_WRAP;
case nxt::StencilOperation::DecrementWrap: case dawn::StencilOperation::DecrementWrap:
return GL_DECR_WRAP; return GL_DECR_WRAP;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -75,7 +75,7 @@ namespace backend { namespace opengl {
auto& depthInfo = GetDepth(); auto& depthInfo = GetDepth();
// Depth writes only occur if depth is enabled // Depth writes only occur if depth is enabled
if (depthInfo.compareFunction == nxt::CompareFunction::Always && if (depthInfo.compareFunction == dawn::CompareFunction::Always &&
!depthInfo.depthWriteEnabled) { !depthInfo.depthWriteEnabled) {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
} else { } else {

View File

@ -54,7 +54,7 @@ namespace backend { namespace opengl {
return new BindGroup(builder); return new BindGroup(builder);
} }
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor); return new BindGroupLayout(this, descriptor);
} }
BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) { BlendStateBase* Device::CreateBlendState(BlendStateBuilder* builder) {
@ -79,7 +79,7 @@ namespace backend { namespace opengl {
return new InputState(builder); return new InputState(builder);
} }
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor); return new PipelineLayout(this, descriptor);
} }
ResultOrError<QueueBase*> Device::CreateQueueImpl() { ResultOrError<QueueBase*> Device::CreateQueueImpl() {
@ -93,7 +93,7 @@ namespace backend { namespace opengl {
return new RenderPipeline(builder); return new RenderPipeline(builder);
} }
ResultOrError<SamplerBase*> Device::CreateSamplerImpl( ResultOrError<SamplerBase*> Device::CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) { const dawn::SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor); return new Sampler(this, descriptor);
} }
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) { ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {

View File

@ -52,12 +52,12 @@ namespace backend { namespace opengl {
private: private:
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl( ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
const nxt::BindGroupLayoutDescriptor* descriptor) override; const dawn::BindGroupLayoutDescriptor* descriptor) override;
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl( ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
const nxt::PipelineLayoutDescriptor* descriptor) override; const dawn::PipelineLayoutDescriptor* descriptor) override;
ResultOrError<QueueBase*> CreateQueueImpl() override; ResultOrError<QueueBase*> CreateQueueImpl() override;
ResultOrError<SamplerBase*> CreateSamplerImpl( ResultOrError<SamplerBase*> CreateSamplerImpl(
const nxt::SamplerDescriptor* descriptor) override; const dawn::SamplerDescriptor* descriptor) override;
}; };
}} // namespace backend::opengl }} // namespace backend::opengl

View File

@ -38,9 +38,9 @@ namespace backend { namespace opengl {
glVertexAttribDivisor(location, 0xffffffff); glVertexAttribDivisor(location, 0xffffffff);
} else { } else {
switch (input.stepMode) { switch (input.stepMode) {
case nxt::InputStepMode::Vertex: case dawn::InputStepMode::Vertex:
break; break;
case nxt::InputStepMode::Instance: case dawn::InputStepMode::Instance:
glVertexAttribDivisor(location, 1); glVertexAttribDivisor(location, 1);
break; break;
default: default:

View File

@ -28,13 +28,13 @@ namespace backend { namespace opengl {
namespace { namespace {
GLenum GLShaderType(nxt::ShaderStage stage) { GLenum GLShaderType(dawn::ShaderStage stage) {
switch (stage) { switch (stage) {
case nxt::ShaderStage::Vertex: case dawn::ShaderStage::Vertex:
return GL_VERTEX_SHADER; return GL_VERTEX_SHADER;
case nxt::ShaderStage::Fragment: case dawn::ShaderStage::Fragment:
return GL_FRAGMENT_SHADER; return GL_FRAGMENT_SHADER;
case nxt::ShaderStage::Compute: case dawn::ShaderStage::Compute:
return GL_COMPUTE_SHADER; return GL_COMPUTE_SHADER;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -136,19 +136,19 @@ namespace backend { namespace opengl {
std::string name = GetBindingName(group, binding); std::string name = GetBindingName(group, binding);
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: { case dawn::BindingType::UniformBuffer: {
GLint location = glGetUniformBlockIndex(mProgram, name.c_str()); GLint location = glGetUniformBlockIndex(mProgram, name.c_str());
glUniformBlockBinding(mProgram, location, indices[group][binding]); glUniformBlockBinding(mProgram, location, indices[group][binding]);
} break; } break;
case nxt::BindingType::StorageBuffer: { case dawn::BindingType::StorageBuffer: {
GLuint location = glGetProgramResourceIndex( GLuint location = glGetProgramResourceIndex(
mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str()); mProgram, GL_SHADER_STORAGE_BLOCK, name.c_str());
glShaderStorageBlockBinding(mProgram, location, indices[group][binding]); glShaderStorageBlockBinding(mProgram, location, indices[group][binding]);
} break; } break;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
// These binding types are handled in the separate sampler and texture // These binding types are handled in the separate sampler and texture
// emulation // emulation
break; break;
@ -190,7 +190,7 @@ namespace backend { namespace opengl {
} }
const PipelineGL::GLPushConstantInfo& PipelineGL::GetGLPushConstants( const PipelineGL::GLPushConstantInfo& PipelineGL::GetGLPushConstants(
nxt::ShaderStage stage) const { dawn::ShaderStage stage) const {
return mGlPushConstants[stage]; return mGlPushConstants[stage];
} }

View File

@ -35,7 +35,7 @@ namespace backend { namespace opengl {
using BindingLocations = using BindingLocations =
std::array<std::array<GLint, kMaxBindingsPerGroup>, kMaxBindGroups>; std::array<std::array<GLint, kMaxBindingsPerGroup>, kMaxBindGroups>;
const GLPushConstantInfo& GetGLPushConstants(nxt::ShaderStage stage) const; const GLPushConstantInfo& GetGLPushConstants(dawn::ShaderStage stage) const;
const std::vector<GLuint>& GetTextureUnitsForSampler(GLuint index) const; const std::vector<GLuint>& GetTextureUnitsForSampler(GLuint index) const;
const std::vector<GLuint>& GetTextureUnitsForTexture(GLuint index) const; const std::vector<GLuint>& GetTextureUnitsForTexture(GLuint index) const;
GLuint GetProgramHandle() const; GLuint GetProgramHandle() const;

View File

@ -20,7 +20,7 @@
namespace backend { namespace opengl { namespace backend { namespace opengl {
PipelineLayout::PipelineLayout(Device* device, const nxt::PipelineLayoutDescriptor* descriptor) PipelineLayout::PipelineLayout(Device* device, const dawn::PipelineLayoutDescriptor* descriptor)
: PipelineLayoutBase(device, descriptor) { : PipelineLayoutBase(device, descriptor) {
GLuint uboIndex = 0; GLuint uboIndex = 0;
GLuint samplerIndex = 0; GLuint samplerIndex = 0;
@ -36,20 +36,20 @@ namespace backend { namespace opengl {
} }
switch (groupInfo.types[binding]) { switch (groupInfo.types[binding]) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
mIndexInfo[group][binding] = uboIndex; mIndexInfo[group][binding] = uboIndex;
uboIndex++; uboIndex++;
break; break;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
mIndexInfo[group][binding] = samplerIndex; mIndexInfo[group][binding] = samplerIndex;
samplerIndex++; samplerIndex++;
break; break;
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
mIndexInfo[group][binding] = sampledTextureIndex; mIndexInfo[group][binding] = sampledTextureIndex;
sampledTextureIndex++; sampledTextureIndex++;
break; break;
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
mIndexInfo[group][binding] = ssboIndex; mIndexInfo[group][binding] = ssboIndex;
ssboIndex++; ssboIndex++;
break; break;

View File

@ -25,7 +25,7 @@ namespace backend { namespace opengl {
class PipelineLayout : public PipelineLayoutBase { class PipelineLayout : public PipelineLayoutBase {
public: public:
PipelineLayout(Device* device, const nxt::PipelineLayoutDescriptor* descriptor); PipelineLayout(Device* device, const dawn::PipelineLayoutDescriptor* descriptor);
using BindingIndexInfo = using BindingIndexInfo =
std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>; std::array<std::array<GLuint, kMaxBindingsPerGroup>, kMaxBindGroups>;

View File

@ -23,17 +23,17 @@
namespace backend { namespace opengl { namespace backend { namespace opengl {
namespace { namespace {
GLenum GLPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) { GLenum GLPrimitiveTopology(dawn::PrimitiveTopology primitiveTopology) {
switch (primitiveTopology) { switch (primitiveTopology) {
case nxt::PrimitiveTopology::PointList: case dawn::PrimitiveTopology::PointList:
return GL_POINTS; return GL_POINTS;
case nxt::PrimitiveTopology::LineList: case dawn::PrimitiveTopology::LineList:
return GL_LINES; return GL_LINES;
case nxt::PrimitiveTopology::LineStrip: case dawn::PrimitiveTopology::LineStrip:
return GL_LINE_STRIP; return GL_LINE_STRIP;
case nxt::PrimitiveTopology::TriangleList: case dawn::PrimitiveTopology::TriangleList:
return GL_TRIANGLES; return GL_TRIANGLES;
case nxt::PrimitiveTopology::TriangleStrip: case dawn::PrimitiveTopology::TriangleStrip:
return GL_TRIANGLE_STRIP; return GL_TRIANGLE_STRIP;
default: default:
UNREACHABLE(); UNREACHABLE();

View File

@ -20,33 +20,33 @@
namespace backend { namespace opengl { namespace backend { namespace opengl {
namespace { namespace {
GLenum MagFilterMode(nxt::FilterMode filter) { GLenum MagFilterMode(dawn::FilterMode filter) {
switch (filter) { switch (filter) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
return GL_NEAREST; return GL_NEAREST;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
return GL_LINEAR; return GL_LINEAR;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
GLenum MinFilterMode(nxt::FilterMode minFilter, nxt::FilterMode mipMapFilter) { GLenum MinFilterMode(dawn::FilterMode minFilter, dawn::FilterMode mipMapFilter) {
switch (minFilter) { switch (minFilter) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
switch (mipMapFilter) { switch (mipMapFilter) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
return GL_NEAREST_MIPMAP_NEAREST; return GL_NEAREST_MIPMAP_NEAREST;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
return GL_NEAREST_MIPMAP_LINEAR; return GL_NEAREST_MIPMAP_LINEAR;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
switch (mipMapFilter) { switch (mipMapFilter) {
case nxt::FilterMode::Nearest: case dawn::FilterMode::Nearest:
return GL_LINEAR_MIPMAP_NEAREST; return GL_LINEAR_MIPMAP_NEAREST;
case nxt::FilterMode::Linear: case dawn::FilterMode::Linear:
return GL_LINEAR_MIPMAP_LINEAR; return GL_LINEAR_MIPMAP_LINEAR;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -56,13 +56,13 @@ namespace backend { namespace opengl {
} }
} }
GLenum WrapMode(nxt::AddressMode mode) { GLenum WrapMode(dawn::AddressMode mode) {
switch (mode) { switch (mode) {
case nxt::AddressMode::Repeat: case dawn::AddressMode::Repeat:
return GL_REPEAT; return GL_REPEAT;
case nxt::AddressMode::MirroredRepeat: case dawn::AddressMode::MirroredRepeat:
return GL_MIRRORED_REPEAT; return GL_MIRRORED_REPEAT;
case nxt::AddressMode::ClampToEdge: case dawn::AddressMode::ClampToEdge:
return GL_CLAMP_TO_EDGE; return GL_CLAMP_TO_EDGE;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -71,7 +71,7 @@ namespace backend { namespace opengl {
} // namespace } // namespace
Sampler::Sampler(Device* device, const nxt::SamplerDescriptor* descriptor) Sampler::Sampler(Device* device, const dawn::SamplerDescriptor* descriptor)
: SamplerBase(device, descriptor) { : SamplerBase(device, descriptor) {
glGenSamplers(1, &mHandle); glGenSamplers(1, &mHandle);
glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(descriptor->magFilter)); glSamplerParameteri(mHandle, GL_TEXTURE_MAG_FILTER, MagFilterMode(descriptor->magFilter));

View File

@ -25,7 +25,7 @@ namespace backend { namespace opengl {
class Sampler : public SamplerBase { class Sampler : public SamplerBase {
public: public:
Sampler(Device* device, const nxt::SamplerDescriptor* descriptor); Sampler(Device* device, const dawn::SamplerDescriptor* descriptor);
GLuint GetHandle() const; GLuint GetHandle() const;

View File

@ -23,33 +23,33 @@ namespace backend { namespace opengl {
namespace { namespace {
GLenum TargetForDimension(nxt::TextureDimension dimension) { GLenum TargetForDimension(dawn::TextureDimension dimension) {
switch (dimension) { switch (dimension) {
case nxt::TextureDimension::e2D: case dawn::TextureDimension::e2D:
return GL_TEXTURE_2D; return GL_TEXTURE_2D;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
TextureFormatInfo GetGLFormatInfo(nxt::TextureFormat format) { TextureFormatInfo GetGLFormatInfo(dawn::TextureFormat format) {
switch (format) { switch (format) {
case nxt::TextureFormat::R8G8B8A8Unorm: case dawn::TextureFormat::R8G8B8A8Unorm:
return {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}; return {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE};
case nxt::TextureFormat::R8G8Unorm: case dawn::TextureFormat::R8G8Unorm:
return {GL_RG8, GL_RG, GL_UNSIGNED_BYTE}; return {GL_RG8, GL_RG, GL_UNSIGNED_BYTE};
case nxt::TextureFormat::R8Unorm: case dawn::TextureFormat::R8Unorm:
return {GL_R8, GL_RED, GL_UNSIGNED_BYTE}; return {GL_R8, GL_RED, GL_UNSIGNED_BYTE};
case nxt::TextureFormat::R8G8B8A8Uint: case dawn::TextureFormat::R8G8B8A8Uint:
return {GL_RGBA8UI, GL_RGBA, GL_UNSIGNED_INT}; return {GL_RGBA8UI, GL_RGBA, GL_UNSIGNED_INT};
case nxt::TextureFormat::R8G8Uint: case dawn::TextureFormat::R8G8Uint:
return {GL_RG8UI, GL_RG, GL_UNSIGNED_INT}; return {GL_RG8UI, GL_RG, GL_UNSIGNED_INT};
case nxt::TextureFormat::R8Uint: case dawn::TextureFormat::R8Uint:
return {GL_R8UI, GL_RED, GL_UNSIGNED_INT}; return {GL_R8UI, GL_RED, GL_UNSIGNED_INT};
case nxt::TextureFormat::B8G8R8A8Unorm: case dawn::TextureFormat::B8G8R8A8Unorm:
// This doesn't have an enum for the internal format in OpenGL, so use RGBA8. // This doesn't have an enum for the internal format in OpenGL, so use RGBA8.
return {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}; return {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE};
case nxt::TextureFormat::D32FloatS8Uint: case dawn::TextureFormat::D32FloatS8Uint:
return {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, return {GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL,
GL_FLOAT_32_UNSIGNED_INT_24_8_REV}; GL_FLOAT_32_UNSIGNED_INT_24_8_REV};
default: default:

View File

@ -21,16 +21,16 @@ namespace backend { namespace vulkan {
namespace { namespace {
VkShaderStageFlags VulkanShaderStageFlags(nxt::ShaderStageBit stages) { VkShaderStageFlags VulkanShaderStageFlags(dawn::ShaderStageBit stages) {
VkShaderStageFlags flags = 0; VkShaderStageFlags flags = 0;
if (stages & nxt::ShaderStageBit::Vertex) { if (stages & dawn::ShaderStageBit::Vertex) {
flags |= VK_SHADER_STAGE_VERTEX_BIT; flags |= VK_SHADER_STAGE_VERTEX_BIT;
} }
if (stages & nxt::ShaderStageBit::Fragment) { if (stages & dawn::ShaderStageBit::Fragment) {
flags |= VK_SHADER_STAGE_FRAGMENT_BIT; flags |= VK_SHADER_STAGE_FRAGMENT_BIT;
} }
if (stages & nxt::ShaderStageBit::Compute) { if (stages & dawn::ShaderStageBit::Compute) {
flags |= VK_SHADER_STAGE_COMPUTE_BIT; flags |= VK_SHADER_STAGE_COMPUTE_BIT;
} }
@ -39,15 +39,15 @@ namespace backend { namespace vulkan {
} // anonymous namespace } // anonymous namespace
VkDescriptorType VulkanDescriptorType(nxt::BindingType type) { VkDescriptorType VulkanDescriptorType(dawn::BindingType type) {
switch (type) { switch (type) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
return VK_DESCRIPTOR_TYPE_SAMPLER; return VK_DESCRIPTOR_TYPE_SAMPLER;
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
default: default:
UNREACHABLE(); UNREACHABLE();
@ -55,7 +55,7 @@ namespace backend { namespace vulkan {
} }
BindGroupLayout::BindGroupLayout(Device* device, BindGroupLayout::BindGroupLayout(Device* device,
const nxt::BindGroupLayoutDescriptor* descriptor) const dawn::BindGroupLayoutDescriptor* descriptor)
: BindGroupLayoutBase(device, descriptor) { : BindGroupLayoutBase(device, descriptor) {
const auto& info = GetBindingInfo(); const auto& info = GetBindingInfo();
@ -116,15 +116,15 @@ namespace backend { namespace vulkan {
MAX_TYPE, MAX_TYPE,
}; };
static_assert(MAX_TYPE == kMaxPoolSizesNeeded, ""); static_assert(MAX_TYPE == kMaxPoolSizesNeeded, "");
auto ToDescriptorType = [](nxt::BindingType type) -> DescriptorType { auto ToDescriptorType = [](dawn::BindingType type) -> DescriptorType {
switch (type) { switch (type) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
return UNIFORM_BUFFER; return UNIFORM_BUFFER;
case nxt::BindingType::Sampler: case dawn::BindingType::Sampler:
return SAMPLER; return SAMPLER;
case nxt::BindingType::SampledTexture: case dawn::BindingType::SampledTexture:
return SAMPLED_IMAGE; return SAMPLED_IMAGE;
case nxt::BindingType::StorageBuffer: case dawn::BindingType::StorageBuffer:
return STORAGE_BUFFER; return STORAGE_BUFFER;
default: default:
UNREACHABLE(); UNREACHABLE();

View File

@ -23,11 +23,11 @@ namespace backend { namespace vulkan {
class Device; class Device;
VkDescriptorType VulkanDescriptorType(nxt::BindingType type); VkDescriptorType VulkanDescriptorType(dawn::BindingType type);
class BindGroupLayout : public BindGroupLayoutBase { class BindGroupLayout : public BindGroupLayoutBase {
public: public:
BindGroupLayout(Device* device, const nxt::BindGroupLayoutDescriptor* descriptor); BindGroupLayout(Device* device, const dawn::BindGroupLayoutDescriptor* descriptor);
~BindGroupLayout(); ~BindGroupLayout();
VkDescriptorSetLayout GetHandle() const; VkDescriptorSetLayout GetHandle() const;

View File

@ -80,8 +80,8 @@ namespace backend { namespace vulkan {
write.descriptorType = VulkanDescriptorType(layoutInfo.types[bindingIndex]); write.descriptorType = VulkanDescriptorType(layoutInfo.types[bindingIndex]);
switch (layoutInfo.types[bindingIndex]) { switch (layoutInfo.types[bindingIndex]) {
case nxt::BindingType::UniformBuffer: case dawn::BindingType::UniformBuffer:
case nxt::BindingType::StorageBuffer: { case dawn::BindingType::StorageBuffer: {
BufferViewBase* view = GetBindingAsBufferView(bindingIndex); BufferViewBase* view = GetBindingAsBufferView(bindingIndex);
Buffer* buffer = ToBackend(view->GetBuffer()); Buffer* buffer = ToBackend(view->GetBuffer());
@ -92,13 +92,13 @@ namespace backend { namespace vulkan {
write.pBufferInfo = &writeBufferInfo[numWrites]; write.pBufferInfo = &writeBufferInfo[numWrites];
} break; } break;
case nxt::BindingType::Sampler: { case dawn::BindingType::Sampler: {
Sampler* sampler = ToBackend(GetBindingAsSampler(bindingIndex)); Sampler* sampler = ToBackend(GetBindingAsSampler(bindingIndex));
writeImageInfo[numWrites].sampler = sampler->GetHandle(); writeImageInfo[numWrites].sampler = sampler->GetHandle();
write.pImageInfo = &writeImageInfo[numWrites]; write.pImageInfo = &writeImageInfo[numWrites];
} break; } break;
case nxt::BindingType::SampledTexture: { case dawn::BindingType::SampledTexture: {
TextureView* view = ToBackend(GetBindingAsTextureView(bindingIndex)); TextureView* view = ToBackend(GetBindingAsTextureView(bindingIndex));
writeImageInfo[numWrites].imageView = view->GetHandle(); writeImageInfo[numWrites].imageView = view->GetHandle();

View File

@ -19,68 +19,68 @@
namespace backend { namespace vulkan { namespace backend { namespace vulkan {
namespace { namespace {
VkBlendFactor VulkanBlendFactor(nxt::BlendFactor factor) { VkBlendFactor VulkanBlendFactor(dawn::BlendFactor factor) {
switch (factor) { switch (factor) {
case nxt::BlendFactor::Zero: case dawn::BlendFactor::Zero:
return VK_BLEND_FACTOR_ZERO; return VK_BLEND_FACTOR_ZERO;
case nxt::BlendFactor::One: case dawn::BlendFactor::One:
return VK_BLEND_FACTOR_ONE; return VK_BLEND_FACTOR_ONE;
case nxt::BlendFactor::SrcColor: case dawn::BlendFactor::SrcColor:
return VK_BLEND_FACTOR_SRC_COLOR; return VK_BLEND_FACTOR_SRC_COLOR;
case nxt::BlendFactor::OneMinusSrcColor: case dawn::BlendFactor::OneMinusSrcColor:
return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR; return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
case nxt::BlendFactor::SrcAlpha: case dawn::BlendFactor::SrcAlpha:
return VK_BLEND_FACTOR_SRC_ALPHA; return VK_BLEND_FACTOR_SRC_ALPHA;
case nxt::BlendFactor::OneMinusSrcAlpha: case dawn::BlendFactor::OneMinusSrcAlpha:
return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
case nxt::BlendFactor::DstColor: case dawn::BlendFactor::DstColor:
return VK_BLEND_FACTOR_DST_COLOR; return VK_BLEND_FACTOR_DST_COLOR;
case nxt::BlendFactor::OneMinusDstColor: case dawn::BlendFactor::OneMinusDstColor:
return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR; return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
case nxt::BlendFactor::DstAlpha: case dawn::BlendFactor::DstAlpha:
return VK_BLEND_FACTOR_DST_ALPHA; return VK_BLEND_FACTOR_DST_ALPHA;
case nxt::BlendFactor::OneMinusDstAlpha: case dawn::BlendFactor::OneMinusDstAlpha:
return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA; return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
case nxt::BlendFactor::SrcAlphaSaturated: case dawn::BlendFactor::SrcAlphaSaturated:
return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE; return VK_BLEND_FACTOR_SRC_ALPHA_SATURATE;
case nxt::BlendFactor::BlendColor: case dawn::BlendFactor::BlendColor:
return VK_BLEND_FACTOR_CONSTANT_COLOR; return VK_BLEND_FACTOR_CONSTANT_COLOR;
case nxt::BlendFactor::OneMinusBlendColor: case dawn::BlendFactor::OneMinusBlendColor:
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR; return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
VkBlendOp VulkanBlendOperation(nxt::BlendOperation operation) { VkBlendOp VulkanBlendOperation(dawn::BlendOperation operation) {
switch (operation) { switch (operation) {
case nxt::BlendOperation::Add: case dawn::BlendOperation::Add:
return VK_BLEND_OP_ADD; return VK_BLEND_OP_ADD;
case nxt::BlendOperation::Subtract: case dawn::BlendOperation::Subtract:
return VK_BLEND_OP_SUBTRACT; return VK_BLEND_OP_SUBTRACT;
case nxt::BlendOperation::ReverseSubtract: case dawn::BlendOperation::ReverseSubtract:
return VK_BLEND_OP_REVERSE_SUBTRACT; return VK_BLEND_OP_REVERSE_SUBTRACT;
case nxt::BlendOperation::Min: case dawn::BlendOperation::Min:
return VK_BLEND_OP_MIN; return VK_BLEND_OP_MIN;
case nxt::BlendOperation::Max: case dawn::BlendOperation::Max:
return VK_BLEND_OP_MAX; return VK_BLEND_OP_MAX;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
} }
VkColorComponentFlagBits VulkanColorWriteMask(nxt::ColorWriteMask mask) { VkColorComponentFlagBits VulkanColorWriteMask(dawn::ColorWriteMask mask) {
// Vulkan and NXT color write masks match, static assert it and return the mask // Vulkan and NXT color write masks match, static assert it and return the mask
static_assert(static_cast<VkColorComponentFlagBits>(nxt::ColorWriteMask::Red) == static_assert(static_cast<VkColorComponentFlagBits>(dawn::ColorWriteMask::Red) ==
VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_R_BIT,
""); "");
static_assert(static_cast<VkColorComponentFlagBits>(nxt::ColorWriteMask::Green) == static_assert(static_cast<VkColorComponentFlagBits>(dawn::ColorWriteMask::Green) ==
VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_G_BIT,
""); "");
static_assert(static_cast<VkColorComponentFlagBits>(nxt::ColorWriteMask::Blue) == static_assert(static_cast<VkColorComponentFlagBits>(dawn::ColorWriteMask::Blue) ==
VK_COLOR_COMPONENT_B_BIT, VK_COLOR_COMPONENT_B_BIT,
""); "");
static_assert(static_cast<VkColorComponentFlagBits>(nxt::ColorWriteMask::Alpha) == static_assert(static_cast<VkColorComponentFlagBits>(dawn::ColorWriteMask::Alpha) ==
VK_COLOR_COMPONENT_A_BIT, VK_COLOR_COMPONENT_A_BIT,
""); "");

View File

@ -24,44 +24,44 @@ namespace backend { namespace vulkan {
namespace { namespace {
VkBufferUsageFlags VulkanBufferUsage(nxt::BufferUsageBit usage) { VkBufferUsageFlags VulkanBufferUsage(dawn::BufferUsageBit usage) {
VkBufferUsageFlags flags = 0; VkBufferUsageFlags flags = 0;
if (usage & nxt::BufferUsageBit::TransferSrc) { if (usage & dawn::BufferUsageBit::TransferSrc) {
flags |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT; flags |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
} }
if (usage & nxt::BufferUsageBit::TransferDst) { if (usage & dawn::BufferUsageBit::TransferDst) {
flags |= VK_BUFFER_USAGE_TRANSFER_DST_BIT; flags |= VK_BUFFER_USAGE_TRANSFER_DST_BIT;
} }
if (usage & nxt::BufferUsageBit::Index) { if (usage & dawn::BufferUsageBit::Index) {
flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT; flags |= VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
} }
if (usage & nxt::BufferUsageBit::Vertex) { if (usage & dawn::BufferUsageBit::Vertex) {
flags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; flags |= VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
} }
if (usage & nxt::BufferUsageBit::Uniform) { if (usage & dawn::BufferUsageBit::Uniform) {
flags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; flags |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
} }
if (usage & nxt::BufferUsageBit::Storage) { if (usage & dawn::BufferUsageBit::Storage) {
flags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; flags |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
} }
return flags; return flags;
} }
VkPipelineStageFlags VulkanPipelineStage(nxt::BufferUsageBit usage) { VkPipelineStageFlags VulkanPipelineStage(dawn::BufferUsageBit usage) {
VkPipelineStageFlags flags = 0; VkPipelineStageFlags flags = 0;
if (usage & (nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::MapWrite)) { if (usage & (dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::MapWrite)) {
flags |= VK_PIPELINE_STAGE_HOST_BIT; flags |= VK_PIPELINE_STAGE_HOST_BIT;
} }
if (usage & (nxt::BufferUsageBit::TransferSrc | nxt::BufferUsageBit::TransferDst)) { if (usage & (dawn::BufferUsageBit::TransferSrc | dawn::BufferUsageBit::TransferDst)) {
flags |= VK_PIPELINE_STAGE_TRANSFER_BIT; flags |= VK_PIPELINE_STAGE_TRANSFER_BIT;
} }
if (usage & (nxt::BufferUsageBit::Index | nxt::BufferUsageBit::Vertex)) { if (usage & (dawn::BufferUsageBit::Index | dawn::BufferUsageBit::Vertex)) {
flags |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT; flags |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
} }
if (usage & (nxt::BufferUsageBit::Uniform | nxt::BufferUsageBit::Storage)) { if (usage & (dawn::BufferUsageBit::Uniform | dawn::BufferUsageBit::Storage)) {
flags |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | flags |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT |
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT |
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
@ -70,31 +70,31 @@ namespace backend { namespace vulkan {
return flags; return flags;
} }
VkAccessFlags VulkanAccessFlags(nxt::BufferUsageBit usage) { VkAccessFlags VulkanAccessFlags(dawn::BufferUsageBit usage) {
VkAccessFlags flags = 0; VkAccessFlags flags = 0;
if (usage & nxt::BufferUsageBit::MapRead) { if (usage & dawn::BufferUsageBit::MapRead) {
flags |= VK_ACCESS_HOST_READ_BIT; flags |= VK_ACCESS_HOST_READ_BIT;
} }
if (usage & nxt::BufferUsageBit::MapWrite) { if (usage & dawn::BufferUsageBit::MapWrite) {
flags |= VK_ACCESS_HOST_WRITE_BIT; flags |= VK_ACCESS_HOST_WRITE_BIT;
} }
if (usage & nxt::BufferUsageBit::TransferSrc) { if (usage & dawn::BufferUsageBit::TransferSrc) {
flags |= VK_ACCESS_TRANSFER_READ_BIT; flags |= VK_ACCESS_TRANSFER_READ_BIT;
} }
if (usage & nxt::BufferUsageBit::TransferDst) { if (usage & dawn::BufferUsageBit::TransferDst) {
flags |= VK_ACCESS_TRANSFER_WRITE_BIT; flags |= VK_ACCESS_TRANSFER_WRITE_BIT;
} }
if (usage & nxt::BufferUsageBit::Index) { if (usage & dawn::BufferUsageBit::Index) {
flags |= VK_ACCESS_INDEX_READ_BIT; flags |= VK_ACCESS_INDEX_READ_BIT;
} }
if (usage & nxt::BufferUsageBit::Vertex) { if (usage & dawn::BufferUsageBit::Vertex) {
flags |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT; flags |= VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
} }
if (usage & nxt::BufferUsageBit::Uniform) { if (usage & dawn::BufferUsageBit::Uniform) {
flags |= VK_ACCESS_UNIFORM_READ_BIT; flags |= VK_ACCESS_UNIFORM_READ_BIT;
} }
if (usage & nxt::BufferUsageBit::Storage) { if (usage & dawn::BufferUsageBit::Storage) {
flags |= VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; flags |= VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
} }
@ -124,9 +124,8 @@ namespace backend { namespace vulkan {
VkMemoryRequirements requirements; VkMemoryRequirements requirements;
device->fn.GetBufferMemoryRequirements(device->GetVkDevice(), mHandle, &requirements); device->fn.GetBufferMemoryRequirements(device->GetVkDevice(), mHandle, &requirements);
bool requestMappable = bool requestMappable = (GetAllowedUsage() & (dawn::BufferUsageBit::MapRead |
(GetAllowedUsage() & (nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::MapWrite)) != dawn::BufferUsageBit::MapWrite)) != 0;
0;
if (!device->GetMemoryAllocator()->Allocate(requirements, requestMappable, if (!device->GetMemoryAllocator()->Allocate(requirements, requestMappable,
&mMemoryAllocation)) { &mMemoryAllocation)) {
ASSERT(false); ASSERT(false);
@ -162,7 +161,7 @@ namespace backend { namespace vulkan {
return mHandle; return mHandle;
} }
void Buffer::TransitionUsageNow(VkCommandBuffer commands, nxt::BufferUsageBit usage) { void Buffer::TransitionUsageNow(VkCommandBuffer commands, dawn::BufferUsageBit usage) {
bool lastIncludesTarget = (mLastUsage & usage) == usage; bool lastIncludesTarget = (mLastUsage & usage) == usage;
bool lastReadOnly = (mLastUsage & kReadOnlyBufferUsages) == mLastUsage; bool lastReadOnly = (mLastUsage & kReadOnlyBufferUsages) == mLastUsage;
@ -172,7 +171,7 @@ namespace backend { namespace vulkan {
} }
// Special-case for the initial transition: Vulkan doesn't allow access flags to be 0. // Special-case for the initial transition: Vulkan doesn't allow access flags to be 0.
if (mLastUsage == nxt::BufferUsageBit::None) { if (mLastUsage == dawn::BufferUsageBit::None) {
mLastUsage = usage; mLastUsage = usage;
return; return;
} }
@ -202,7 +201,7 @@ namespace backend { namespace vulkan {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
VkCommandBuffer commands = device->GetPendingCommandBuffer(); VkCommandBuffer commands = device->GetPendingCommandBuffer();
TransitionUsageNow(commands, nxt::BufferUsageBit::TransferDst); TransitionUsageNow(commands, dawn::BufferUsageBit::TransferDst);
BufferUploader* uploader = device->GetBufferUploader(); BufferUploader* uploader = device->GetBufferUploader();
uploader->BufferSubData(mHandle, start, count, data); uploader->BufferSubData(mHandle, start, count, data);
@ -212,7 +211,7 @@ namespace backend { namespace vulkan {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
VkCommandBuffer commands = device->GetPendingCommandBuffer(); VkCommandBuffer commands = device->GetPendingCommandBuffer();
TransitionUsageNow(commands, nxt::BufferUsageBit::MapRead); TransitionUsageNow(commands, dawn::BufferUsageBit::MapRead);
uint8_t* memory = mMemoryAllocation.GetMappedPointer(); uint8_t* memory = mMemoryAllocation.GetMappedPointer();
ASSERT(memory != nullptr); ASSERT(memory != nullptr);
@ -225,7 +224,7 @@ namespace backend { namespace vulkan {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
VkCommandBuffer commands = device->GetPendingCommandBuffer(); VkCommandBuffer commands = device->GetPendingCommandBuffer();
TransitionUsageNow(commands, nxt::BufferUsageBit::MapWrite); TransitionUsageNow(commands, dawn::BufferUsageBit::MapWrite);
uint8_t* memory = mMemoryAllocation.GetMappedPointer(); uint8_t* memory = mMemoryAllocation.GetMappedPointer();
ASSERT(memory != nullptr); ASSERT(memory != nullptr);

Some files were not shown because too many files have changed in this diff Show More