Member rename: src/backend

This commit is contained in:
Corentin Wallez 2017-11-23 10:32:51 -08:00 committed by Corentin Wallez
parent b325f4d0af
commit fbecc28ac4
46 changed files with 986 additions and 988 deletions

View File

@ -26,37 +26,37 @@ namespace backend {
// BindGroup
BindGroupBase::BindGroupBase(BindGroupBuilder* builder)
: layout(std::move(builder->layout)), usage(builder->usage), bindings(std::move(builder->bindings)) {
: mLayout(std::move(builder->mLayout)), mUsage(builder->mUsage), mBindings(std::move(builder->mBindings)) {
}
const BindGroupLayoutBase* BindGroupBase::GetLayout() const {
return layout.Get();
return mLayout.Get();
}
nxt::BindGroupUsage BindGroupBase::GetUsage() const {
return usage;
return mUsage;
}
BufferViewBase* BindGroupBase::GetBindingAsBufferView(size_t binding) {
ASSERT(binding < kMaxBindingsPerGroup);
ASSERT(layout->GetBindingInfo().mask[binding]);
ASSERT(layout->GetBindingInfo().types[binding] == nxt::BindingType::UniformBuffer ||
layout->GetBindingInfo().types[binding] == nxt::BindingType::StorageBuffer);
return reinterpret_cast<BufferViewBase*>(bindings[binding].Get());
ASSERT(mLayout->GetBindingInfo().mask[binding]);
ASSERT(mLayout->GetBindingInfo().types[binding] == nxt::BindingType::UniformBuffer ||
mLayout->GetBindingInfo().types[binding] == nxt::BindingType::StorageBuffer);
return reinterpret_cast<BufferViewBase*>(mBindings[binding].Get());
}
SamplerBase* BindGroupBase::GetBindingAsSampler(size_t binding) {
ASSERT(binding < kMaxBindingsPerGroup);
ASSERT(layout->GetBindingInfo().mask[binding]);
ASSERT(layout->GetBindingInfo().types[binding] == nxt::BindingType::Sampler);
return reinterpret_cast<SamplerBase*>(bindings[binding].Get());
ASSERT(mLayout->GetBindingInfo().mask[binding]);
ASSERT(mLayout->GetBindingInfo().types[binding] == nxt::BindingType::Sampler);
return reinterpret_cast<SamplerBase*>(mBindings[binding].Get());
}
TextureViewBase* BindGroupBase::GetBindingAsTextureView(size_t binding) {
ASSERT(binding < kMaxBindingsPerGroup);
ASSERT(layout->GetBindingInfo().mask[binding]);
ASSERT(layout->GetBindingInfo().types[binding] == nxt::BindingType::SampledTexture);
return reinterpret_cast<TextureViewBase*>(bindings[binding].Get());
ASSERT(mLayout->GetBindingInfo().mask[binding]);
ASSERT(mLayout->GetBindingInfo().types[binding] == nxt::BindingType::SampledTexture);
return reinterpret_cast<TextureViewBase*>(mBindings[binding].Get());
}
// BindGroupBuilder
@ -71,37 +71,37 @@ namespace backend {
BindGroupBase* BindGroupBuilder::GetResultImpl() {
constexpr int allProperties = BINDGROUP_PROPERTY_USAGE | BINDGROUP_PROPERTY_LAYOUT;
if ((propertiesSet & allProperties) != allProperties) {
if ((mPropertiesSet & allProperties) != allProperties) {
HandleError("Bindgroup missing properties");
return nullptr;
}
if (setMask != layout->GetBindingInfo().mask) {
if (mSetMask != mLayout->GetBindingInfo().mask) {
HandleError("Bindgroup missing bindings");
return nullptr;
}
return device->CreateBindGroup(this);
return mDevice->CreateBindGroup(this);
}
void BindGroupBuilder::SetLayout(BindGroupLayoutBase* layout) {
if ((propertiesSet & BINDGROUP_PROPERTY_LAYOUT) != 0) {
if ((mPropertiesSet & BINDGROUP_PROPERTY_LAYOUT) != 0) {
HandleError("Bindgroup layout property set multiple times");
return;
}
this->layout = layout;
propertiesSet |= BINDGROUP_PROPERTY_LAYOUT;
mLayout = layout;
mPropertiesSet |= BINDGROUP_PROPERTY_LAYOUT;
}
void BindGroupBuilder::SetUsage(nxt::BindGroupUsage usage) {
if ((propertiesSet & BINDGROUP_PROPERTY_USAGE) != 0) {
if ((mPropertiesSet & BINDGROUP_PROPERTY_USAGE) != 0) {
HandleError("Bindgroup usage property set multiple times");
return;
}
this->usage = usage;
propertiesSet |= BINDGROUP_PROPERTY_USAGE;
mUsage = usage;
mPropertiesSet |= BINDGROUP_PROPERTY_USAGE;
}
void BindGroupBuilder::SetBufferViews(uint32_t start, uint32_t count, BufferViewBase* const * bufferViews) {
@ -109,7 +109,7 @@ namespace backend {
return;
}
const auto& layoutInfo = layout->GetBindingInfo();
const auto& layoutInfo = mLayout->GetBindingInfo();
for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
nxt::BufferUsageBit requiredBit = nxt::BufferUsageBit::None;
switch (layoutInfo.types[i]) {
@ -146,7 +146,7 @@ namespace backend {
return;
}
const auto& layoutInfo = layout->GetBindingInfo();
const auto& layoutInfo = mLayout->GetBindingInfo();
for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
if (layoutInfo.types[i] != nxt::BindingType::Sampler) {
HandleError("Setting binding for a wrong layout binding type");
@ -162,7 +162,7 @@ namespace backend {
return;
}
const auto& layoutInfo = layout->GetBindingInfo();
const auto& layoutInfo = mLayout->GetBindingInfo();
for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
if (layoutInfo.types[i] != nxt::BindingType::SampledTexture) {
HandleError("Setting binding for a wrong layout binding type");
@ -180,8 +180,8 @@ namespace backend {
void BindGroupBuilder::SetBindingsBase(uint32_t start, uint32_t count, RefCounted* const * objects) {
for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
setMask.set(i);
bindings[i] = objects[j];
mSetMask.set(i);
mBindings[i] = objects[j];
}
}
@ -191,14 +191,14 @@ namespace backend {
return false;
}
if ((propertiesSet & BINDGROUP_PROPERTY_LAYOUT) == 0) {
if ((mPropertiesSet & BINDGROUP_PROPERTY_LAYOUT) == 0) {
HandleError("Bindgroup layout must be set before views");
return false;
}
const auto& layoutInfo = layout->GetBindingInfo();
const auto& layoutInfo = mLayout->GetBindingInfo();
for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
if (setMask[i]) {
if (mSetMask[i]) {
HandleError("Setting already set binding");
return false;
}

View File

@ -39,9 +39,9 @@ namespace backend {
TextureViewBase* GetBindingAsTextureView(size_t binding);
private:
Ref<BindGroupLayoutBase> layout;
nxt::BindGroupUsage usage;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> bindings;
Ref<BindGroupLayoutBase> mLayout;
nxt::BindGroupUsage mUsage;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
};
class BindGroupBuilder : public Builder<BindGroupBase> {
@ -80,12 +80,12 @@ namespace backend {
void SetBindingsBase(uint32_t start, uint32_t count, RefCounted* const * objects);
bool SetBindingsValidationBase(uint32_t start, uint32_t count);
std::bitset<kMaxBindingsPerGroup> setMask;
int propertiesSet = 0;
std::bitset<kMaxBindingsPerGroup> mSetMask;
int mPropertiesSet = 0;
Ref<BindGroupLayoutBase> layout;
nxt::BindGroupUsage usage;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> bindings;
Ref<BindGroupLayoutBase> mLayout;
nxt::BindGroupUsage mUsage;
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
};
}

View File

@ -77,18 +77,18 @@ namespace backend {
// BindGroupLayoutBase
BindGroupLayoutBase::BindGroupLayoutBase(BindGroupLayoutBuilder* builder, bool blueprint)
: device(builder->device), bindingInfo(builder->bindingInfo), blueprint(blueprint) {
: mDevice(builder->mDevice), mBindingInfo(builder->mBindingInfo), mIsBlueprint(blueprint) {
}
BindGroupLayoutBase::~BindGroupLayoutBase() {
// Do not register the actual cached object if we are a blueprint
if (!blueprint) {
device->UncacheBindGroupLayout(this);
if (!mIsBlueprint) {
mDevice->UncacheBindGroupLayout(this);
}
}
const BindGroupLayoutBase::LayoutBindingInfo& BindGroupLayoutBase::GetBindingInfo() const {
return bindingInfo;
return mBindingInfo;
}
// BindGroupLayoutBuilder
@ -97,13 +97,13 @@ namespace backend {
}
const BindGroupLayoutBase::LayoutBindingInfo& BindGroupLayoutBuilder::GetBindingInfo() const {
return bindingInfo;
return mBindingInfo;
}
BindGroupLayoutBase* BindGroupLayoutBuilder::GetResultImpl() {
BindGroupLayoutBase blueprint(this, true);
auto* result = device->GetOrCreateBindGroupLayout(&blueprint, this);
auto* result = mDevice->GetOrCreateBindGroupLayout(&blueprint, this);
result->Reference();
return result;
}
@ -114,16 +114,16 @@ namespace backend {
return;
}
for (size_t i = start; i < start + count; i++) {
if (bindingInfo.mask[i]) {
if (mBindingInfo.mask[i]) {
HandleError("Setting already set binding type");
return;
}
}
for (size_t i = start; i < start + count; i++) {
bindingInfo.mask.set(i);
bindingInfo.visibilities[i] = visibility;
bindingInfo.types[i] = bindingType;
mBindingInfo.mask.set(i);
mBindingInfo.visibilities[i] = visibility;
mBindingInfo.types[i] = bindingType;
}
}

View File

@ -40,9 +40,9 @@ namespace backend {
const LayoutBindingInfo& GetBindingInfo() const;
private:
DeviceBase* device;
LayoutBindingInfo bindingInfo;
bool blueprint = false;
DeviceBase* mDevice;
LayoutBindingInfo mBindingInfo;
bool mIsBlueprint = false;
};
class BindGroupLayoutBuilder : public Builder<BindGroupLayoutBase> {
@ -59,7 +59,7 @@ namespace backend {
BindGroupLayoutBase* GetResultImpl() override;
BindGroupLayoutBase::LayoutBindingInfo bindingInfo;
BindGroupLayoutBase::LayoutBindingInfo mBindingInfo;
};
// Implements the functors necessary for the unordered_set<BGL*>-based cache.

View File

@ -20,11 +20,11 @@ namespace backend {
// BlendStateBase
BlendStateBase::BlendStateBase(BlendStateBuilder* builder) : blendInfo(builder->blendInfo) {
BlendStateBase::BlendStateBase(BlendStateBuilder* builder) : mBlendInfo(builder->mBlendInfo) {
}
const BlendStateBase::BlendInfo& BlendStateBase::GetBlendInfo() const {
return blendInfo;
return mBlendInfo;
}
// BlendStateBuilder
@ -40,50 +40,50 @@ namespace backend {
}
BlendStateBase* BlendStateBuilder::GetResultImpl() {
return device->CreateBlendState(this);
return mDevice->CreateBlendState(this);
}
void BlendStateBuilder::SetBlendEnabled(bool blendEnabled) {
if ((propertiesSet & BLEND_STATE_PROPERTY_BLEND_ENABLED) != 0) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_BLEND_ENABLED) != 0) {
HandleError("Blend enabled property set multiple times");
return;
}
propertiesSet |= BLEND_STATE_PROPERTY_BLEND_ENABLED;
mPropertiesSet |= BLEND_STATE_PROPERTY_BLEND_ENABLED;
blendInfo.blendEnabled = blendEnabled;
mBlendInfo.blendEnabled = blendEnabled;
}
void BlendStateBuilder::SetAlphaBlend(nxt::BlendOperation blendOperation, nxt::BlendFactor srcFactor, nxt::BlendFactor dstFactor) {
if ((propertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) {
HandleError("Alpha blend property set multiple times");
return;
}
propertiesSet |= BLEND_STATE_PROPERTY_ALPHA_BLEND;
mPropertiesSet |= BLEND_STATE_PROPERTY_ALPHA_BLEND;
blendInfo.alphaBlend = { blendOperation, srcFactor, dstFactor };
mBlendInfo.alphaBlend = { blendOperation, srcFactor, dstFactor };
}
void BlendStateBuilder::SetColorBlend(nxt::BlendOperation blendOperation, nxt::BlendFactor srcFactor, nxt::BlendFactor dstFactor) {
if ((propertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) {
HandleError("Color blend property set multiple times");
return;
}
propertiesSet |= BLEND_STATE_PROPERTY_COLOR_BLEND;
mPropertiesSet |= BLEND_STATE_PROPERTY_COLOR_BLEND;
blendInfo.colorBlend = { blendOperation, srcFactor, dstFactor };
mBlendInfo.colorBlend = { blendOperation, srcFactor, dstFactor };
}
void BlendStateBuilder::SetColorWriteMask(nxt::ColorWriteMask colorWriteMask) {
if ((propertiesSet & BLEND_STATE_PROPERTY_COLOR_WRITE_MASK) != 0) {
if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_WRITE_MASK) != 0) {
HandleError("Color write mask property set multiple times");
return;
}
propertiesSet |= BLEND_STATE_PROPERTY_COLOR_WRITE_MASK;
mPropertiesSet |= BLEND_STATE_PROPERTY_COLOR_WRITE_MASK;
blendInfo.colorWriteMask = colorWriteMask;
mBlendInfo.colorWriteMask = colorWriteMask;
}
}

View File

@ -43,7 +43,7 @@ namespace backend {
const BlendInfo& GetBlendInfo() const;
private:
BlendInfo blendInfo;
BlendInfo mBlendInfo;
};
@ -62,9 +62,9 @@ namespace backend {
BlendStateBase* GetResultImpl() override;
int propertiesSet = 0;
int mPropertiesSet = 0;
BlendStateBase::BlendInfo blendInfo;
BlendStateBase::BlendInfo mBlendInfo;
};
}

View File

@ -25,53 +25,53 @@ namespace backend {
// Buffer
BufferBase::BufferBase(BufferBuilder* builder)
: device(builder->device),
size(builder->size),
allowedUsage(builder->allowedUsage),
currentUsage(builder->currentUsage) {
: mDevice(builder->mDevice),
mSize(builder->mSize),
mAllowedUsage(builder->mAllowedUsage),
mCurrentUsage(builder->mCurrentUsage) {
}
BufferBase::~BufferBase() {
if (mapped) {
CallMapReadCallback(mapReadSerial, NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr);
if (mIsMapped) {
CallMapReadCallback(mMapReadSerial, NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr);
}
}
BufferViewBuilder* BufferBase::CreateBufferViewBuilder() {
return new BufferViewBuilder(device, this);
return new BufferViewBuilder(mDevice, this);
}
DeviceBase* BufferBase::GetDevice() {
return device;
return mDevice;
}
uint32_t BufferBase::GetSize() const {
return size;
return mSize;
}
nxt::BufferUsageBit BufferBase::GetAllowedUsage() const {
return allowedUsage;
return mAllowedUsage;
}
nxt::BufferUsageBit BufferBase::GetUsage() const {
return currentUsage;
return mCurrentUsage;
}
void BufferBase::CallMapReadCallback(uint32_t serial, nxtBufferMapReadStatus status, const void* pointer) {
if (mapReadCallback && serial == mapReadSerial) {
mapReadCallback(status, pointer, mapReadUserdata);
mapReadCallback = nullptr;
if (mMapReadCallback && serial == mMapReadSerial) {
mMapReadCallback(status, pointer, mMapReadUserdata);
mMapReadCallback = nullptr;
}
}
void BufferBase::SetSubData(uint32_t start, uint32_t count, const uint32_t* data) {
if ((start + count) * sizeof(uint32_t) > GetSize()) {
device->HandleError("Buffer subdata out of range");
mDevice->HandleError("Buffer subdata out of range");
return;
}
if (!(currentUsage & nxt::BufferUsageBit::TransferDst)) {
device->HandleError("Buffer needs the transfer dst usage bit");
if (!(mCurrentUsage & nxt::BufferUsageBit::TransferDst)) {
mDevice->HandleError("Buffer needs the transfer dst usage bit");
return;
}
@ -80,50 +80,50 @@ namespace backend {
void BufferBase::MapReadAsync(uint32_t start, uint32_t size, nxtBufferMapReadCallback callback, nxtCallbackUserdata userdata) {
if (start + size > GetSize()) {
device->HandleError("Buffer map read out of range");
mDevice->HandleError("Buffer map read out of range");
callback(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
return;
}
if (!(currentUsage & nxt::BufferUsageBit::MapRead)) {
device->HandleError("Buffer needs the map read usage bit");
if (!(mCurrentUsage & nxt::BufferUsageBit::MapRead)) {
mDevice->HandleError("Buffer needs the map read usage bit");
callback(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
return;
}
if (mapped) {
device->HandleError("Buffer already mapped");
if (mIsMapped) {
mDevice->HandleError("Buffer already mapped");
callback(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
return;
}
// TODO(cwallez@chromium.org): what to do on wraparound? Could cause crashes.
mapReadSerial ++;
mapReadCallback = callback;
mapReadUserdata = userdata;
MapReadAsyncImpl(mapReadSerial, start, size);
mapped = true;
mMapReadSerial ++;
mMapReadCallback = callback;
mMapReadUserdata = userdata;
MapReadAsyncImpl(mMapReadSerial, start, size);
mIsMapped = true;
}
void BufferBase::Unmap() {
if (!mapped) {
device->HandleError("Buffer wasn't mapped");
if (!mIsMapped) {
mDevice->HandleError("Buffer wasn't mapped");
return;
}
// A map request can only be called once, so this will fire only if the request wasn't
// completed before the Unmap
CallMapReadCallback(mapReadSerial, NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr);
CallMapReadCallback(mMapReadSerial, NXT_BUFFER_MAP_READ_STATUS_UNKNOWN, nullptr);
UnmapImpl();
mapped = false;
mIsMapped = false;
}
bool BufferBase::IsFrozen() const {
return frozen;
return mIsFrozen;
}
bool BufferBase::HasFrozenUsage(nxt::BufferUsageBit usage) const {
return frozen && (usage & allowedUsage);
return mIsFrozen && (usage & mAllowedUsage);
}
bool BufferBase::IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage) {
@ -140,35 +140,35 @@ namespace backend {
}
bool BufferBase::IsTransitionPossible(nxt::BufferUsageBit usage) const {
if (frozen || mapped) {
if (mIsFrozen || mIsMapped) {
return false;
}
return IsUsagePossible(allowedUsage, usage);
return IsUsagePossible(mAllowedUsage, usage);
}
void BufferBase::UpdateUsageInternal(nxt::BufferUsageBit usage) {
ASSERT(IsTransitionPossible(usage));
currentUsage = usage;
mCurrentUsage = usage;
}
void BufferBase::TransitionUsage(nxt::BufferUsageBit usage) {
if (!IsTransitionPossible(usage)) {
device->HandleError("Buffer frozen or usage not allowed");
mDevice->HandleError("Buffer frozen or usage not allowed");
return;
}
TransitionUsageImpl(currentUsage, usage);
currentUsage = usage;
TransitionUsageImpl(mCurrentUsage, usage);
mCurrentUsage = usage;
}
void BufferBase::FreezeUsage(nxt::BufferUsageBit usage) {
if (!IsTransitionPossible(usage)) {
device->HandleError("Buffer frozen or usage not allowed");
mDevice->HandleError("Buffer frozen or usage not allowed");
return;
}
allowedUsage = usage;
TransitionUsageImpl(currentUsage, usage);
currentUsage = usage;
frozen = true;
mAllowedUsage = usage;
TransitionUsageImpl(mCurrentUsage, usage);
mCurrentUsage = usage;
mIsFrozen = true;
}
// BufferBuilder
@ -184,79 +184,79 @@ namespace backend {
BufferBase* BufferBuilder::GetResultImpl() {
constexpr int allProperties = BUFFER_PROPERTY_ALLOWED_USAGE | BUFFER_PROPERTY_SIZE;
if ((propertiesSet & allProperties) != allProperties) {
if ((mPropertiesSet & allProperties) != allProperties) {
HandleError("Buffer missing properties");
return nullptr;
}
const nxt::BufferUsageBit kMapWriteAllowedUsages = nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc;
if (allowedUsage & nxt::BufferUsageBit::MapWrite &&
(allowedUsage & kMapWriteAllowedUsages) != allowedUsage) {
if (mAllowedUsage & nxt::BufferUsageBit::MapWrite &&
(mAllowedUsage & kMapWriteAllowedUsages) != mAllowedUsage) {
HandleError("Only TransferSrc is allowed with MapWrite");
return nullptr;
}
const nxt::BufferUsageBit kMapReadAllowedUsages = nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst;
if (allowedUsage & nxt::BufferUsageBit::MapRead &&
(allowedUsage & kMapReadAllowedUsages) != allowedUsage) {
if (mAllowedUsage & nxt::BufferUsageBit::MapRead &&
(mAllowedUsage & kMapReadAllowedUsages) != mAllowedUsage) {
HandleError("Only TransferDst is allowed with MapRead");
return nullptr;
}
if (!BufferBase::IsUsagePossible(allowedUsage, currentUsage)) {
if (!BufferBase::IsUsagePossible(mAllowedUsage, mCurrentUsage)) {
HandleError("Initial buffer usage is not allowed");
return nullptr;
}
return device->CreateBuffer(this);
return mDevice->CreateBuffer(this);
}
void BufferBuilder::SetAllowedUsage(nxt::BufferUsageBit usage) {
if ((propertiesSet & BUFFER_PROPERTY_ALLOWED_USAGE) != 0) {
if ((mPropertiesSet & BUFFER_PROPERTY_ALLOWED_USAGE) != 0) {
HandleError("Buffer allowedUsage property set multiple times");
return;
}
this->allowedUsage = usage;
propertiesSet |= BUFFER_PROPERTY_ALLOWED_USAGE;
mAllowedUsage = usage;
mPropertiesSet |= BUFFER_PROPERTY_ALLOWED_USAGE;
}
void BufferBuilder::SetInitialUsage(nxt::BufferUsageBit usage) {
if ((propertiesSet & BUFFER_PROPERTY_INITIAL_USAGE) != 0) {
if ((mPropertiesSet & BUFFER_PROPERTY_INITIAL_USAGE) != 0) {
HandleError("Buffer initialUsage property set multiple times");
return;
}
this->currentUsage = usage;
propertiesSet |= BUFFER_PROPERTY_INITIAL_USAGE;
mCurrentUsage = usage;
mPropertiesSet |= BUFFER_PROPERTY_INITIAL_USAGE;
}
void BufferBuilder::SetSize(uint32_t size) {
if ((propertiesSet & BUFFER_PROPERTY_SIZE) != 0) {
if ((mPropertiesSet & BUFFER_PROPERTY_SIZE) != 0) {
HandleError("Buffer size property set multiple times");
return;
}
this->size = size;
propertiesSet |= BUFFER_PROPERTY_SIZE;
mSize = size;
mPropertiesSet |= BUFFER_PROPERTY_SIZE;
}
// BufferViewBase
BufferViewBase::BufferViewBase(BufferViewBuilder* builder)
: buffer(std::move(builder->buffer)), size(builder->size), offset(builder->offset) {
: mBuffer(std::move(builder->mBuffer)), mSize(builder->mSize), mOffset(builder->mOffset) {
}
BufferBase* BufferViewBase::GetBuffer() {
return buffer.Get();
return mBuffer.Get();
}
uint32_t BufferViewBase::GetSize() const {
return size;
return mSize;
}
uint32_t BufferViewBase::GetOffset() const {
return offset;
return mOffset;
}
// BufferViewBuilder
@ -266,34 +266,34 @@ namespace backend {
};
BufferViewBuilder::BufferViewBuilder(DeviceBase* device, BufferBase* buffer)
: Builder(device), buffer(buffer) {
: Builder(device), mBuffer(buffer) {
}
BufferViewBase* BufferViewBuilder::GetResultImpl() {
constexpr int allProperties = BUFFER_VIEW_PROPERTY_EXTENT;
if ((propertiesSet & allProperties) != allProperties) {
if ((mPropertiesSet & allProperties) != allProperties) {
HandleError("Buffer view missing properties");
return nullptr;
}
return device->CreateBufferView(this);
return mDevice->CreateBufferView(this);
}
void BufferViewBuilder::SetExtent(uint32_t offset, uint32_t size) {
if ((propertiesSet & BUFFER_VIEW_PROPERTY_EXTENT) != 0) {
if ((mPropertiesSet & BUFFER_VIEW_PROPERTY_EXTENT) != 0) {
HandleError("Buffer view extent property set multiple times");
return;
}
uint64_t viewEnd = static_cast<uint64_t>(offset) + static_cast<uint64_t>(size);
if (viewEnd > static_cast<uint64_t>(buffer->GetSize())) {
if (viewEnd > static_cast<uint64_t>(mBuffer->GetSize())) {
HandleError("Buffer view end is OOB");
return;
}
this->offset = offset;
this->size = size;
propertiesSet |= BUFFER_VIEW_PROPERTY_EXTENT;
mOffset = offset;
mSize = size;
mPropertiesSet |= BUFFER_VIEW_PROPERTY_EXTENT;
}
}

View File

@ -56,17 +56,17 @@ namespace backend {
virtual void UnmapImpl() = 0;
virtual void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) = 0;
DeviceBase* device;
uint32_t size;
nxt::BufferUsageBit allowedUsage = nxt::BufferUsageBit::None;
nxt::BufferUsageBit currentUsage = nxt::BufferUsageBit::None;
DeviceBase* mDevice;
uint32_t mSize;
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None;
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None;
nxtBufferMapReadCallback mapReadCallback = nullptr;
nxtCallbackUserdata mapReadUserdata = 0;
uint32_t mapReadSerial = 0;
nxtBufferMapReadCallback mMapReadCallback = nullptr;
nxtCallbackUserdata mMapReadUserdata = 0;
uint32_t mMapReadSerial = 0;
bool frozen = false;
bool mapped = false;
bool mIsFrozen = false;
bool mIsMapped = false;
};
class BufferBuilder : public Builder<BufferBase> {
@ -83,10 +83,10 @@ namespace backend {
BufferBase* GetResultImpl() override;
uint32_t size;
nxt::BufferUsageBit allowedUsage = nxt::BufferUsageBit::None;
nxt::BufferUsageBit currentUsage = nxt::BufferUsageBit::None;
int propertiesSet = 0;
uint32_t mSize;
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None;
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None;
int mPropertiesSet = 0;
};
class BufferViewBase : public RefCounted {
@ -98,9 +98,9 @@ namespace backend {
uint32_t GetOffset() const;
private:
Ref<BufferBase> buffer;
uint32_t size;
uint32_t offset;
Ref<BufferBase> mBuffer;
uint32_t mSize;
uint32_t mOffset;
};
class BufferViewBuilder : public Builder<BufferViewBase> {
@ -115,10 +115,10 @@ namespace backend {
BufferViewBase* GetResultImpl() override;
Ref<BufferBase> buffer;
uint32_t offset = 0;
uint32_t size = 0;
int propertiesSet = 0;
Ref<BufferBase> mBuffer;
uint32_t mOffset = 0;
uint32_t mSize = 0;
int mPropertiesSet = 0;
};
}

View File

@ -20,11 +20,11 @@
namespace backend {
bool BuilderBase::CanBeUsed() const {
return !consumed && !gotStatus;
return !mIsConsumed && !mGotStatus;
}
DeviceBase* BuilderBase::GetDevice() {
return device;
return mDevice;
}
void BuilderBase::HandleError(const char* message) {
@ -34,41 +34,41 @@ namespace backend {
void BuilderBase::SetErrorCallback(nxt::BuilderErrorCallback callback,
nxt::CallbackUserdata userdata1,
nxt::CallbackUserdata userdata2) {
this->callback = callback;
this->userdata1 = userdata1;
this->userdata2 = userdata2;
mCallback = callback;
mUserdata1 = userdata1;
mUserdata2 = userdata2;
}
BuilderBase::BuilderBase(DeviceBase* device) : device(device) {
BuilderBase::BuilderBase(DeviceBase* device) : mDevice(device) {
}
BuilderBase::~BuilderBase() {
if (!consumed && callback != nullptr) {
callback(NXT_BUILDER_ERROR_STATUS_UNKNOWN, "Builder destroyed before GetResult", userdata1, userdata2);
if (!mIsConsumed && mCallback != nullptr) {
mCallback(NXT_BUILDER_ERROR_STATUS_UNKNOWN, "Builder destroyed before GetResult", mUserdata1, mUserdata2);
}
}
void BuilderBase::SetStatus(nxt::BuilderErrorStatus status, const char* message) {
ASSERT(status != nxt::BuilderErrorStatus::Success);
ASSERT(status != nxt::BuilderErrorStatus::Unknown);
ASSERT(!gotStatus); // This is not strictly necessary but something to strive for.
gotStatus = true;
ASSERT(!mGotStatus); // This is not strictly necessary but something to strive for.
mGotStatus = true;
storedStatus = status;
storedMessage = message;
mStoredStatus = status;
mStoredMessage = message;
}
bool BuilderBase::HandleResult(RefCounted* result) {
// GetResult can only be called once.
ASSERT(!consumed);
consumed = true;
ASSERT(!mIsConsumed);
mIsConsumed = true;
// result == nullptr implies there was an error which implies we should have a status set.
ASSERT(result != nullptr || gotStatus);
ASSERT(result != nullptr || mGotStatus);
// If we have any error, then we have to return nullptr
if (gotStatus) {
ASSERT(storedStatus != nxt::BuilderErrorStatus::Success);
if (mGotStatus) {
ASSERT(mStoredStatus != nxt::BuilderErrorStatus::Success);
// The application will never see "result" so we need to remove the
// external ref here.
@ -78,14 +78,14 @@ namespace backend {
}
// Unhandled builder errors are promoted to device errors
if (!callback) device->HandleError(("Unhandled builder error: " + storedMessage).c_str());
if (!mCallback) mDevice->HandleError(("Unhandled builder error: " + mStoredMessage).c_str());
} else {
ASSERT(storedStatus == nxt::BuilderErrorStatus::Success);
ASSERT(storedMessage.empty());
ASSERT(mStoredStatus == nxt::BuilderErrorStatus::Success);
ASSERT(mStoredMessage.empty());
}
if (callback) {
callback(static_cast<nxtBuilderErrorStatus>(storedStatus), storedMessage.c_str(), userdata1, userdata2);
if (mCallback != nullptr) {
mCallback(static_cast<nxtBuilderErrorStatus>(mStoredStatus), mStoredMessage.c_str(), mUserdata1, mUserdata2);
}
return result != nullptr;

View File

@ -60,20 +60,20 @@ namespace backend {
BuilderBase(DeviceBase* device);
~BuilderBase();
DeviceBase* const device;
bool gotStatus = false;
DeviceBase* const mDevice;
bool mGotStatus = false;
private:
void SetStatus(nxt::BuilderErrorStatus status, const char* message);
nxt::BuilderErrorCallback callback = nullptr;
nxt::CallbackUserdata userdata1 = 0;
nxt::CallbackUserdata userdata2 = 0;
nxt::BuilderErrorCallback mCallback = nullptr;
nxt::CallbackUserdata mUserdata1 = 0;
nxt::CallbackUserdata mUserdata2 = 0;
nxt::BuilderErrorStatus storedStatus = nxt::BuilderErrorStatus::Success;
std::string storedMessage;
nxt::BuilderErrorStatus mStoredStatus = nxt::BuilderErrorStatus::Success;
std::string mStoredMessage;
bool consumed = false;
bool mIsConsumed = false;
};
// This builder base class is used to capture the calls to GetResult and make sure

View File

@ -29,24 +29,24 @@ namespace backend {
// TODO(cwallez@chromium.org): figure out a way to have more type safety for the iterator
CommandIterator::CommandIterator()
: endOfBlock(EndOfBlock) {
: mEndOfBlock(EndOfBlock) {
Reset();
}
CommandIterator::~CommandIterator() {
ASSERT(dataWasDestroyed);
ASSERT(mDataWasDestroyed);
if (!IsEmpty()) {
for (auto& block : blocks) {
for (auto& block : mBlocks) {
free(block.block);
}
}
}
CommandIterator::CommandIterator(CommandIterator&& other)
: endOfBlock(EndOfBlock) {
: mEndOfBlock(EndOfBlock) {
if (!other.IsEmpty()) {
blocks = std::move(other.blocks);
mBlocks = std::move(other.mBlocks);
other.Reset();
}
other.DataWasDestroyed();
@ -55,10 +55,10 @@ namespace backend {
CommandIterator& CommandIterator::operator=(CommandIterator&& other) {
if (!other.IsEmpty()) {
blocks = std::move(other.blocks);
mBlocks = std::move(other.mBlocks);
other.Reset();
} else {
blocks.clear();
mBlocks.clear();
}
other.DataWasDestroyed();
Reset();
@ -66,67 +66,67 @@ namespace backend {
}
CommandIterator::CommandIterator(CommandAllocator&& allocator)
: blocks(allocator.AcquireBlocks()), endOfBlock(EndOfBlock) {
: mBlocks(allocator.AcquireBlocks()), mEndOfBlock(EndOfBlock) {
Reset();
}
CommandIterator& CommandIterator::operator=(CommandAllocator&& allocator) {
blocks = allocator.AcquireBlocks();
mBlocks = allocator.AcquireBlocks();
Reset();
return *this;
}
void CommandIterator::Reset() {
currentBlock = 0;
mCurrentBlock = 0;
if (blocks.empty()) {
if (mBlocks.empty()) {
// This will case the first NextCommandId call to try to move to the next
// block and stop the iteration immediately, without special casing the
// initialization.
currentPtr = reinterpret_cast<uint8_t*>(&endOfBlock);
blocks.emplace_back();
blocks[0].size = sizeof(endOfBlock);
blocks[0].block = currentPtr;
mCurrentPtr = reinterpret_cast<uint8_t*>(&mEndOfBlock);
mBlocks.emplace_back();
mBlocks[0].size = sizeof(mEndOfBlock);
mBlocks[0].block = mCurrentPtr;
} else {
currentPtr = AlignPtr(blocks[0].block, alignof(uint32_t));
mCurrentPtr = AlignPtr(mBlocks[0].block, alignof(uint32_t));
}
}
void CommandIterator::DataWasDestroyed() {
dataWasDestroyed = true;
mDataWasDestroyed = true;
}
bool CommandIterator::IsEmpty() const {
return blocks[0].block == reinterpret_cast<const uint8_t*>(&endOfBlock);
return mBlocks[0].block == reinterpret_cast<const uint8_t*>(&mEndOfBlock);
}
bool CommandIterator::NextCommandId(uint32_t* commandId) {
uint8_t* idPtr = AlignPtr(currentPtr, alignof(uint32_t));
ASSERT(idPtr + sizeof(uint32_t) <= blocks[currentBlock].block + blocks[currentBlock].size);
uint8_t* idPtr = AlignPtr(mCurrentPtr, alignof(uint32_t));
ASSERT(idPtr + sizeof(uint32_t) <= mBlocks[mCurrentBlock].block + mBlocks[mCurrentBlock].size);
uint32_t id = *reinterpret_cast<uint32_t*>(idPtr);
if (id == EndOfBlock) {
currentBlock++;
if (currentBlock >= blocks.size()) {
mCurrentBlock++;
if (mCurrentBlock >= mBlocks.size()) {
Reset();
*commandId = EndOfBlock;
return false;
}
currentPtr = AlignPtr(blocks[currentBlock].block, alignof(uint32_t));
mCurrentPtr = AlignPtr(mBlocks[mCurrentBlock].block, alignof(uint32_t));
return NextCommandId(commandId);
}
currentPtr = idPtr + sizeof(uint32_t);
mCurrentPtr = idPtr + sizeof(uint32_t);
*commandId = id;
return true;
}
void* CommandIterator::NextCommand(size_t commandSize, size_t commandAlignment) {
uint8_t* commandPtr = AlignPtr(currentPtr, commandAlignment);
ASSERT(commandPtr + sizeof(commandSize) <= blocks[currentBlock].block + blocks[currentBlock].size);
uint8_t* commandPtr = AlignPtr(mCurrentPtr, commandAlignment);
ASSERT(commandPtr + sizeof(commandSize) <= mBlocks[mCurrentBlock].block + mBlocks[mCurrentBlock].size);
currentPtr = commandPtr + commandSize;
mCurrentPtr = commandPtr + commandSize;
return commandPtr;
}
@ -146,40 +146,40 @@ namespace backend {
// - Better block allocation, maybe have NXT API to say command buffer is going to have size close to another
CommandAllocator::CommandAllocator()
: currentPtr(reinterpret_cast<uint8_t*>(&dummyEnum[0])), endPtr(reinterpret_cast<uint8_t*>(&dummyEnum[1])) {
: mCurrentPtr(reinterpret_cast<uint8_t*>(&mDummyEnum[0])), mEndPtr(reinterpret_cast<uint8_t*>(&mDummyEnum[1])) {
}
CommandAllocator::~CommandAllocator() {
ASSERT(blocks.empty());
ASSERT(mBlocks.empty());
}
CommandBlocks&& CommandAllocator::AcquireBlocks() {
ASSERT(currentPtr != nullptr && endPtr != nullptr);
ASSERT(IsPtrAligned(currentPtr, alignof(uint32_t)));
ASSERT(currentPtr + sizeof(uint32_t) <= endPtr);
*reinterpret_cast<uint32_t*>(currentPtr) = EndOfBlock;
ASSERT(mCurrentPtr != nullptr && mEndPtr != nullptr);
ASSERT(IsPtrAligned(mCurrentPtr, alignof(uint32_t)));
ASSERT(mCurrentPtr + sizeof(uint32_t) <= mEndPtr);
*reinterpret_cast<uint32_t*>(mCurrentPtr) = EndOfBlock;
currentPtr = nullptr;
endPtr = nullptr;
return std::move(blocks);
mCurrentPtr = nullptr;
mEndPtr = nullptr;
return std::move(mBlocks);
}
uint8_t* CommandAllocator::Allocate(uint32_t commandId, size_t commandSize, size_t commandAlignment) {
ASSERT(currentPtr != nullptr);
ASSERT(endPtr != nullptr);
ASSERT(mCurrentPtr != nullptr);
ASSERT(mEndPtr != nullptr);
ASSERT(commandId != EndOfBlock);
// It should always be possible to allocate one id, for EndOfBlock tagging,
ASSERT(IsPtrAligned(currentPtr, alignof(uint32_t)));
ASSERT(currentPtr + sizeof(uint32_t) <= endPtr);
uint32_t* idAlloc = reinterpret_cast<uint32_t*>(currentPtr);
ASSERT(IsPtrAligned(mCurrentPtr, alignof(uint32_t)));
ASSERT(mCurrentPtr + sizeof(uint32_t) <= mEndPtr);
uint32_t* idAlloc = reinterpret_cast<uint32_t*>(mCurrentPtr);
uint8_t* commandAlloc = AlignPtr(currentPtr + sizeof(uint32_t), commandAlignment);
uint8_t* commandAlloc = AlignPtr(mCurrentPtr + sizeof(uint32_t), commandAlignment);
uint8_t* nextPtr = AlignPtr(commandAlloc + commandSize, alignof(uint32_t));
// When there is not enough space, we signal the EndOfBlock, so that the iterator nows to
// move to the next one. EndOfBlock on the last block means the end of the commands.
if (nextPtr + sizeof(uint32_t) > endPtr) {
if (nextPtr + sizeof(uint32_t) > mEndPtr) {
// Even if we are not able to get another block, the list of commands will be well-formed
// and iterable as this block will be that last one.
@ -187,15 +187,15 @@ namespace backend {
// Make sure we have space for current allocation, plus end of block and alignment padding
// for the first id.
ASSERT(nextPtr > currentPtr);
if (!GetNewBlock(static_cast<size_t>(nextPtr - currentPtr) + sizeof(uint32_t) + alignof(uint32_t))) {
ASSERT(nextPtr > mCurrentPtr);
if (!GetNewBlock(static_cast<size_t>(nextPtr - mCurrentPtr) + sizeof(uint32_t) + alignof(uint32_t))) {
return nullptr;
}
return Allocate(commandId, commandSize, commandAlignment);
}
*idAlloc = commandId;
currentPtr = nextPtr;
mCurrentPtr = nextPtr;
return commandAlloc;
}
@ -205,16 +205,16 @@ namespace backend {
bool CommandAllocator::GetNewBlock(size_t minimumSize) {
// Allocate blocks doubling sizes each time, to a maximum of 16k (or at least minimumSize).
lastAllocationSize = std::max(minimumSize, std::min(lastAllocationSize * 2, size_t(16384)));
mLastAllocationSize = std::max(minimumSize, std::min(mLastAllocationSize * 2, size_t(16384)));
uint8_t* block = reinterpret_cast<uint8_t*>(malloc(lastAllocationSize));
uint8_t* block = reinterpret_cast<uint8_t*>(malloc(mLastAllocationSize));
if (block == nullptr) {
return false;
}
blocks.push_back({lastAllocationSize, block});
currentPtr = AlignPtr(block, alignof(uint32_t));
endPtr = block + lastAllocationSize;
mBlocks.push_back({mLastAllocationSize, block});
mCurrentPtr = AlignPtr(block, alignof(uint32_t));
mEndPtr = block + mLastAllocationSize;
return true;
}

View File

@ -96,12 +96,12 @@ namespace backend {
void* NextCommand(size_t commandSize, size_t commandAlignment);
void* NextData(size_t dataSize, size_t dataAlignment);
CommandBlocks blocks;
uint8_t* currentPtr = nullptr;
size_t currentBlock = 0;
CommandBlocks mBlocks;
uint8_t* mCurrentPtr = nullptr;
size_t mCurrentBlock = 0;
// Used to avoid a special case for empty iterators.
uint32_t endOfBlock;
bool dataWasDestroyed = false;
uint32_t mEndOfBlock;
bool mDataWasDestroyed = false;
};
class CommandAllocator {
@ -129,20 +129,20 @@ namespace backend {
uint8_t* AllocateData(size_t dataSize, size_t dataAlignment);
bool GetNewBlock(size_t minimumSize);
CommandBlocks blocks;
size_t lastAllocationSize = 2048;
CommandBlocks mBlocks;
size_t mLastAllocationSize = 2048;
// Pointers to the current range of allocation in the block. Guaranteed to allow
// for at least one uint32_t is not nullptr, so that the special EndOfBlock command id
// can always be written.
// Nullptr iff the blocks were moved out.
uint8_t* currentPtr = nullptr;
uint8_t* endPtr = nullptr;
uint8_t* mCurrentPtr = nullptr;
uint8_t* mEndPtr = nullptr;
// Data used for the block range at initialization so that the first call to Allocate
// sees there is not enough space and calls GetNewBlock. This avoids having to special
// case the initialization in Allocate.
uint32_t dummyEnum[1] = {0};
uint32_t mDummyEnum[1] = {0};
};
}

View File

@ -110,21 +110,21 @@ namespace backend {
}
CommandBufferBase::CommandBufferBase(CommandBufferBuilder* builder)
: device(builder->device),
buffersTransitioned(std::move(builder->state->buffersTransitioned)),
texturesTransitioned(std::move(builder->state->texturesTransitioned)) {
: mDevice(builder->mDevice),
mBuffersTransitioned(std::move(builder->mState->mBuffersTransitioned)),
mTexturesTransitioned(std::move(builder->mState->mTexturesTransitioned)) {
}
bool CommandBufferBase::ValidateResourceUsagesImmediate() {
for (auto buffer : buffersTransitioned) {
for (auto buffer : mBuffersTransitioned) {
if (buffer->IsFrozen()) {
device->HandleError("Command buffer: cannot transition buffer with frozen usage");
mDevice->HandleError("Command buffer: cannot transition buffer with frozen usage");
return false;
}
}
for (auto texture : texturesTransitioned) {
for (auto texture : mTexturesTransitioned) {
if (texture->IsFrozen()) {
device->HandleError("Command buffer: cannot transition texture with frozen usage");
mDevice->HandleError("Command buffer: cannot transition texture with frozen usage");
return false;
}
}
@ -132,7 +132,7 @@ namespace backend {
}
DeviceBase* CommandBufferBase::GetDevice() {
return device;
return mDevice;
}
void FreeCommands(CommandIterator* commands) {
@ -381,13 +381,13 @@ namespace backend {
}
}
CommandBufferBuilder::CommandBufferBuilder(DeviceBase* device) : Builder(device), state(std::make_unique<CommandBufferStateTracker>(this)) {
CommandBufferBuilder::CommandBufferBuilder(DeviceBase* device) : Builder(device), mState(std::make_unique<CommandBufferStateTracker>(this)) {
}
CommandBufferBuilder::~CommandBufferBuilder() {
if (!commandsAcquired) {
if (!mWereCommandsAcquired) {
MoveToIterator();
FreeCommands(&iterator);
FreeCommands(&mIterator);
}
}
@ -395,12 +395,12 @@ namespace backend {
MoveToIterator();
Command type;
while (iterator.NextCommandId(&type)) {
while (mIterator.NextCommandId(&type)) {
switch (type) {
case Command::BeginComputePass:
{
iterator.NextCommand<BeginComputePassCmd>();
if (!state->BeginComputePass()) {
mIterator.NextCommand<BeginComputePassCmd>();
if (!mState->BeginComputePass()) {
return false;
}
}
@ -408,7 +408,7 @@ namespace backend {
case Command::BeginRenderPass:
{
BeginRenderPassCmd* cmd = iterator.NextCommand<BeginRenderPassCmd>();
BeginRenderPassCmd* cmd = mIterator.NextCommand<BeginRenderPassCmd>();
auto* renderPass = cmd->renderPass.Get();
auto* framebuffer = cmd->framebuffer.Get();
// TODO(kainino@chromium.org): null checks should not be necessary
@ -420,7 +420,7 @@ namespace backend {
HandleError("Framebuffer is invalid");
return false;
}
if (!state->BeginRenderPass(renderPass, framebuffer)) {
if (!mState->BeginRenderPass(renderPass, framebuffer)) {
return false;
}
}
@ -428,8 +428,8 @@ namespace backend {
case Command::BeginRenderSubpass:
{
iterator.NextCommand<BeginRenderSubpassCmd>();
if (!state->BeginSubpass()) {
mIterator.NextCommand<BeginRenderSubpassCmd>();
if (!mState->BeginSubpass()) {
return false;
}
}
@ -437,12 +437,12 @@ namespace backend {
case Command::CopyBufferToBuffer:
{
CopyBufferToBufferCmd* copy = iterator.NextCommand<CopyBufferToBufferCmd>();
CopyBufferToBufferCmd* copy = mIterator.NextCommand<CopyBufferToBufferCmd>();
if (!ValidateCopySizeFitsInBuffer(this, copy->source, copy->size) ||
!ValidateCopySizeFitsInBuffer(this, copy->destination, copy->size) ||
!state->ValidateCanCopy() ||
!state->ValidateCanUseBufferAs(copy->source.buffer.Get(), nxt::BufferUsageBit::TransferSrc) ||
!state->ValidateCanUseBufferAs(copy->destination.buffer.Get(), nxt::BufferUsageBit::TransferDst)) {
!mState->ValidateCanCopy() ||
!mState->ValidateCanUseBufferAs(copy->source.buffer.Get(), nxt::BufferUsageBit::TransferSrc) ||
!mState->ValidateCanUseBufferAs(copy->destination.buffer.Get(), nxt::BufferUsageBit::TransferDst)) {
return false;
}
}
@ -450,7 +450,7 @@ namespace backend {
case Command::CopyBufferToTexture:
{
CopyBufferToTextureCmd* copy = iterator.NextCommand<CopyBufferToTextureCmd>();
CopyBufferToTextureCmd* copy = mIterator.NextCommand<CopyBufferToTextureCmd>();
uint32_t bufferCopySize = 0;
if (!ValidateRowPitch(this, copy->destination, copy->rowPitch) ||
@ -458,9 +458,9 @@ namespace backend {
!ValidateCopyLocationFitsInTexture(this, copy->destination) ||
!ValidateCopySizeFitsInBuffer(this, copy->source, bufferCopySize) ||
!ValidateTexelBufferOffset(this, copy->destination.texture.Get(), copy->source) ||
!state->ValidateCanCopy() ||
!state->ValidateCanUseBufferAs(copy->source.buffer.Get(), nxt::BufferUsageBit::TransferSrc) ||
!state->ValidateCanUseTextureAs(copy->destination.texture.Get(), nxt::TextureUsageBit::TransferDst)) {
!mState->ValidateCanCopy() ||
!mState->ValidateCanUseBufferAs(copy->source.buffer.Get(), nxt::BufferUsageBit::TransferSrc) ||
!mState->ValidateCanUseTextureAs(copy->destination.texture.Get(), nxt::TextureUsageBit::TransferDst)) {
return false;
}
}
@ -468,7 +468,7 @@ namespace backend {
case Command::CopyTextureToBuffer:
{
CopyTextureToBufferCmd* copy = iterator.NextCommand<CopyTextureToBufferCmd>();
CopyTextureToBufferCmd* copy = mIterator.NextCommand<CopyTextureToBufferCmd>();
uint32_t bufferCopySize = 0;
if (!ValidateRowPitch(this, copy->source, copy->rowPitch) ||
@ -476,9 +476,9 @@ namespace backend {
!ValidateCopyLocationFitsInTexture(this, copy->source) ||
!ValidateCopySizeFitsInBuffer(this, copy->destination, bufferCopySize) ||
!ValidateTexelBufferOffset(this, copy->source.texture.Get(), copy->destination) ||
!state->ValidateCanCopy() ||
!state->ValidateCanUseTextureAs(copy->source.texture.Get(), nxt::TextureUsageBit::TransferSrc) ||
!state->ValidateCanUseBufferAs(copy->destination.buffer.Get(), nxt::BufferUsageBit::TransferDst)) {
!mState->ValidateCanCopy() ||
!mState->ValidateCanUseTextureAs(copy->source.texture.Get(), nxt::TextureUsageBit::TransferSrc) ||
!mState->ValidateCanUseBufferAs(copy->destination.buffer.Get(), nxt::BufferUsageBit::TransferDst)) {
return false;
}
}
@ -486,8 +486,8 @@ namespace backend {
case Command::Dispatch:
{
iterator.NextCommand<DispatchCmd>();
if (!state->ValidateCanDispatch()) {
mIterator.NextCommand<DispatchCmd>();
if (!mState->ValidateCanDispatch()) {
return false;
}
}
@ -495,8 +495,8 @@ namespace backend {
case Command::DrawArrays:
{
iterator.NextCommand<DrawArraysCmd>();
if (!state->ValidateCanDrawArrays()) {
mIterator.NextCommand<DrawArraysCmd>();
if (!mState->ValidateCanDrawArrays()) {
return false;
}
}
@ -504,8 +504,8 @@ namespace backend {
case Command::DrawElements:
{
iterator.NextCommand<DrawElementsCmd>();
if (!state->ValidateCanDrawElements()) {
mIterator.NextCommand<DrawElementsCmd>();
if (!mState->ValidateCanDrawElements()) {
return false;
}
}
@ -513,8 +513,8 @@ namespace backend {
case Command::EndComputePass:
{
iterator.NextCommand<EndComputePassCmd>();
if (!state->EndComputePass()) {
mIterator.NextCommand<EndComputePassCmd>();
if (!mState->EndComputePass()) {
return false;
}
}
@ -522,8 +522,8 @@ namespace backend {
case Command::EndRenderPass:
{
iterator.NextCommand<EndRenderPassCmd>();
if (!state->EndRenderPass()) {
mIterator.NextCommand<EndRenderPassCmd>();
if (!mState->EndRenderPass()) {
return false;
}
}
@ -531,8 +531,8 @@ namespace backend {
case Command::EndRenderSubpass:
{
iterator.NextCommand<EndRenderSubpassCmd>();
if (!state->EndSubpass()) {
mIterator.NextCommand<EndRenderSubpassCmd>();
if (!mState->EndSubpass()) {
return false;
}
}
@ -540,9 +540,9 @@ namespace backend {
case Command::SetComputePipeline:
{
SetComputePipelineCmd* cmd = iterator.NextCommand<SetComputePipelineCmd>();
SetComputePipelineCmd* cmd = mIterator.NextCommand<SetComputePipelineCmd>();
ComputePipelineBase* pipeline = cmd->pipeline.Get();
if (!state->SetComputePipeline(pipeline)) {
if (!mState->SetComputePipeline(pipeline)) {
return false;
}
}
@ -550,9 +550,9 @@ namespace backend {
case Command::SetRenderPipeline:
{
SetRenderPipelineCmd* cmd = iterator.NextCommand<SetRenderPipelineCmd>();
SetRenderPipelineCmd* cmd = mIterator.NextCommand<SetRenderPipelineCmd>();
RenderPipelineBase* pipeline = cmd->pipeline.Get();
if (!state->SetRenderPipeline(pipeline)) {
if (!mState->SetRenderPipeline(pipeline)) {
return false;
}
}
@ -560,11 +560,11 @@ namespace backend {
case Command::SetPushConstants:
{
SetPushConstantsCmd* cmd = iterator.NextCommand<SetPushConstantsCmd>();
iterator.NextData<uint32_t>(cmd->count);
SetPushConstantsCmd* cmd = mIterator.NextCommand<SetPushConstantsCmd>();
mIterator.NextData<uint32_t>(cmd->count);
// Validation of count and offset has already been done when the command was recorded
// because it impacts the size of an allocation in the CommandAllocator.
if (!state->ValidateSetPushConstants(cmd->stages)) {
if (!mState->ValidateSetPushConstants(cmd->stages)) {
return false;
}
}
@ -572,8 +572,8 @@ namespace backend {
case Command::SetStencilReference:
{
iterator.NextCommand<SetStencilReferenceCmd>();
if (!state->HaveRenderSubpass()) {
mIterator.NextCommand<SetStencilReferenceCmd>();
if (!mState->HaveRenderSubpass()) {
HandleError("Can't set stencil reference without an active render subpass");
return false;
}
@ -582,8 +582,8 @@ namespace backend {
case Command::SetBlendColor:
{
iterator.NextCommand<SetBlendColorCmd>();
if (!state->HaveRenderSubpass()) {
mIterator.NextCommand<SetBlendColorCmd>();
if (!mState->HaveRenderSubpass()) {
HandleError("Can't set blend color without an active render subpass");
return false;
}
@ -592,8 +592,8 @@ namespace backend {
case Command::SetBindGroup:
{
SetBindGroupCmd* cmd = iterator.NextCommand<SetBindGroupCmd>();
if (!state->SetBindGroup(cmd->index, cmd->group.Get())) {
SetBindGroupCmd* cmd = mIterator.NextCommand<SetBindGroupCmd>();
if (!mState->SetBindGroup(cmd->index, cmd->group.Get())) {
return false;
}
}
@ -601,8 +601,8 @@ namespace backend {
case Command::SetIndexBuffer:
{
SetIndexBufferCmd* cmd = iterator.NextCommand<SetIndexBufferCmd>();
if (!state->SetIndexBuffer(cmd->buffer.Get())) {
SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>();
if (!mState->SetIndexBuffer(cmd->buffer.Get())) {
return false;
}
}
@ -610,20 +610,20 @@ namespace backend {
case Command::SetVertexBuffers:
{
SetVertexBuffersCmd* cmd = iterator.NextCommand<SetVertexBuffersCmd>();
auto buffers = iterator.NextData<Ref<BufferBase>>(cmd->count);
iterator.NextData<uint32_t>(cmd->count);
SetVertexBuffersCmd* cmd = mIterator.NextCommand<SetVertexBuffersCmd>();
auto buffers = mIterator.NextData<Ref<BufferBase>>(cmd->count);
mIterator.NextData<uint32_t>(cmd->count);
for (uint32_t i = 0; i < cmd->count; ++i) {
state->SetVertexBuffer(cmd->startSlot + i, buffers[i].Get());
mState->SetVertexBuffer(cmd->startSlot + i, buffers[i].Get());
}
}
break;
case Command::TransitionBufferUsage:
{
TransitionBufferUsageCmd* cmd = iterator.NextCommand<TransitionBufferUsageCmd>();
if (!state->TransitionBufferUsage(cmd->buffer.Get(), cmd->usage)) {
TransitionBufferUsageCmd* cmd = mIterator.NextCommand<TransitionBufferUsageCmd>();
if (!mState->TransitionBufferUsage(cmd->buffer.Get(), cmd->usage)) {
return false;
}
}
@ -631,8 +631,8 @@ namespace backend {
case Command::TransitionTextureUsage:
{
TransitionTextureUsageCmd* cmd = iterator.NextCommand<TransitionTextureUsageCmd>();
if (!state->TransitionTextureUsage(cmd->texture.Get(), cmd->usage)) {
TransitionTextureUsageCmd* cmd = mIterator.NextCommand<TransitionTextureUsageCmd>();
if (!mState->TransitionTextureUsage(cmd->texture.Get(), cmd->usage)) {
return false;
}
@ -641,7 +641,7 @@ namespace backend {
}
}
if (!state->ValidateEndCommandBuffer()) {
if (!mState->ValidateEndCommandBuffer()) {
return false;
}
@ -649,33 +649,33 @@ namespace backend {
}
CommandIterator CommandBufferBuilder::AcquireCommands() {
ASSERT(!commandsAcquired);
commandsAcquired = true;
return std::move(iterator);
ASSERT(!mWereCommandsAcquired);
mWereCommandsAcquired = true;
return std::move(mIterator);
}
CommandBufferBase* CommandBufferBuilder::GetResultImpl() {
MoveToIterator();
return device->CreateCommandBuffer(this);
return mDevice->CreateCommandBuffer(this);
}
void CommandBufferBuilder::BeginComputePass() {
allocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
mAllocator.Allocate<BeginComputePassCmd>(Command::BeginComputePass);
}
void CommandBufferBuilder::BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer) {
BeginRenderPassCmd* cmd = allocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
BeginRenderPassCmd* cmd = mAllocator.Allocate<BeginRenderPassCmd>(Command::BeginRenderPass);
new(cmd) BeginRenderPassCmd;
cmd->renderPass = renderPass;
cmd->framebuffer = framebuffer;
}
void CommandBufferBuilder::BeginRenderSubpass() {
allocator.Allocate<BeginRenderSubpassCmd>(Command::BeginRenderSubpass);
mAllocator.Allocate<BeginRenderSubpassCmd>(Command::BeginRenderSubpass);
}
void CommandBufferBuilder::CopyBufferToBuffer(BufferBase* source, uint32_t sourceOffset, BufferBase* destination, uint32_t destinationOffset, uint32_t size) {
CopyBufferToBufferCmd* copy = allocator.Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
CopyBufferToBufferCmd* copy = mAllocator.Allocate<CopyBufferToBufferCmd>(Command::CopyBufferToBuffer);
new(copy) CopyBufferToBufferCmd;
copy->source.buffer = source;
copy->source.offset = sourceOffset;
@ -690,7 +690,7 @@ namespace backend {
if (rowPitch == 0) {
rowPitch = ComputeDefaultRowPitch(texture, width);
}
CopyBufferToTextureCmd* copy = allocator.Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
CopyBufferToTextureCmd* copy = mAllocator.Allocate<CopyBufferToTextureCmd>(Command::CopyBufferToTexture);
new(copy) CopyBufferToTextureCmd;
copy->source.buffer = buffer;
copy->source.offset = bufferOffset;
@ -711,7 +711,7 @@ namespace backend {
if (rowPitch == 0) {
rowPitch = ComputeDefaultRowPitch(texture, width);
}
CopyTextureToBufferCmd* copy = allocator.Allocate<CopyTextureToBufferCmd>(Command::CopyTextureToBuffer);
CopyTextureToBufferCmd* copy = mAllocator.Allocate<CopyTextureToBufferCmd>(Command::CopyTextureToBuffer);
new(copy) CopyTextureToBufferCmd;
copy->source.texture = texture;
copy->source.x = x;
@ -727,7 +727,7 @@ namespace backend {
}
void CommandBufferBuilder::Dispatch(uint32_t x, uint32_t y, uint32_t z) {
DispatchCmd* dispatch = allocator.Allocate<DispatchCmd>(Command::Dispatch);
DispatchCmd* dispatch = mAllocator.Allocate<DispatchCmd>(Command::Dispatch);
new(dispatch) DispatchCmd;
dispatch->x = x;
dispatch->y = y;
@ -735,7 +735,7 @@ namespace backend {
}
void CommandBufferBuilder::DrawArrays(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
DrawArraysCmd* draw = allocator.Allocate<DrawArraysCmd>(Command::DrawArrays);
DrawArraysCmd* draw = mAllocator.Allocate<DrawArraysCmd>(Command::DrawArrays);
new(draw) DrawArraysCmd;
draw->vertexCount = vertexCount;
draw->instanceCount = instanceCount;
@ -744,7 +744,7 @@ namespace backend {
}
void CommandBufferBuilder::DrawElements(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t firstInstance) {
DrawElementsCmd* draw = allocator.Allocate<DrawElementsCmd>(Command::DrawElements);
DrawElementsCmd* draw = mAllocator.Allocate<DrawElementsCmd>(Command::DrawElements);
new(draw) DrawElementsCmd;
draw->indexCount = indexCount;
draw->instanceCount = instanceCount;
@ -753,25 +753,25 @@ namespace backend {
}
void CommandBufferBuilder::EndComputePass() {
allocator.Allocate<EndComputePassCmd>(Command::EndComputePass);
mAllocator.Allocate<EndComputePassCmd>(Command::EndComputePass);
}
void CommandBufferBuilder::EndRenderPass() {
allocator.Allocate<EndRenderPassCmd>(Command::EndRenderPass);
mAllocator.Allocate<EndRenderPassCmd>(Command::EndRenderPass);
}
void CommandBufferBuilder::EndRenderSubpass() {
allocator.Allocate<EndRenderSubpassCmd>(Command::EndRenderSubpass);
mAllocator.Allocate<EndRenderSubpassCmd>(Command::EndRenderSubpass);
}
void CommandBufferBuilder::SetComputePipeline(ComputePipelineBase* pipeline) {
SetComputePipelineCmd* cmd = allocator.Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
SetComputePipelineCmd* cmd = mAllocator.Allocate<SetComputePipelineCmd>(Command::SetComputePipeline);
new(cmd) SetComputePipelineCmd;
cmd->pipeline = pipeline;
}
void CommandBufferBuilder::SetRenderPipeline(RenderPipelineBase* pipeline) {
SetRenderPipelineCmd* cmd = allocator.Allocate<SetRenderPipelineCmd>(Command::SetRenderPipeline);
SetRenderPipelineCmd* cmd = mAllocator.Allocate<SetRenderPipelineCmd>(Command::SetRenderPipeline);
new(cmd) SetRenderPipelineCmd;
cmd->pipeline = pipeline;
}
@ -783,24 +783,24 @@ namespace backend {
return;
}
SetPushConstantsCmd* cmd = allocator.Allocate<SetPushConstantsCmd>(Command::SetPushConstants);
SetPushConstantsCmd* cmd = mAllocator.Allocate<SetPushConstantsCmd>(Command::SetPushConstants);
new(cmd) SetPushConstantsCmd;
cmd->stages = stages;
cmd->offset = offset;
cmd->count = count;
uint32_t* values = allocator.AllocateData<uint32_t>(count);
uint32_t* values = mAllocator.AllocateData<uint32_t>(count);
memcpy(values, data, count * sizeof(uint32_t));
}
void CommandBufferBuilder::SetStencilReference(uint32_t reference) {
SetStencilReferenceCmd* cmd = allocator.Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
SetStencilReferenceCmd* cmd = mAllocator.Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
new(cmd) SetStencilReferenceCmd;
cmd->reference = reference;
}
void CommandBufferBuilder::SetBlendColor(float r, float g, float b, float a) {
SetBlendColorCmd* cmd = allocator.Allocate<SetBlendColorCmd>(Command::SetBlendColor);
SetBlendColorCmd* cmd = mAllocator.Allocate<SetBlendColorCmd>(Command::SetBlendColor);
new(cmd) SetBlendColorCmd;
cmd->r = r;
cmd->g = g;
@ -814,7 +814,7 @@ namespace backend {
return;
}
SetBindGroupCmd* cmd = allocator.Allocate<SetBindGroupCmd>(Command::SetBindGroup);
SetBindGroupCmd* cmd = mAllocator.Allocate<SetBindGroupCmd>(Command::SetBindGroup);
new(cmd) SetBindGroupCmd;
cmd->index = groupIndex;
cmd->group = group;
@ -823,7 +823,7 @@ namespace backend {
void CommandBufferBuilder::SetIndexBuffer(BufferBase* buffer, uint32_t offset) {
// TODO(kainino@chromium.org): validation
SetIndexBufferCmd* cmd = allocator.Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
SetIndexBufferCmd* cmd = mAllocator.Allocate<SetIndexBufferCmd>(Command::SetIndexBuffer);
new(cmd) SetIndexBufferCmd;
cmd->buffer = buffer;
cmd->offset = offset;
@ -832,38 +832,38 @@ namespace backend {
void CommandBufferBuilder::SetVertexBuffers(uint32_t startSlot, uint32_t count, BufferBase* const* buffers, uint32_t const* offsets){
// TODO(kainino@chromium.org): validation
SetVertexBuffersCmd* cmd = allocator.Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
SetVertexBuffersCmd* cmd = mAllocator.Allocate<SetVertexBuffersCmd>(Command::SetVertexBuffers);
new(cmd) SetVertexBuffersCmd;
cmd->startSlot = startSlot;
cmd->count = count;
Ref<BufferBase>* cmdBuffers = allocator.AllocateData<Ref<BufferBase>>(count);
Ref<BufferBase>* cmdBuffers = mAllocator.AllocateData<Ref<BufferBase>>(count);
for (size_t i = 0; i < count; ++i) {
new(&cmdBuffers[i]) Ref<BufferBase>(buffers[i]);
}
uint32_t* cmdOffsets = allocator.AllocateData<uint32_t>(count);
uint32_t* cmdOffsets = mAllocator.AllocateData<uint32_t>(count);
memcpy(cmdOffsets, offsets, count * sizeof(uint32_t));
}
void CommandBufferBuilder::TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage) {
TransitionBufferUsageCmd* cmd = allocator.Allocate<TransitionBufferUsageCmd>(Command::TransitionBufferUsage);
TransitionBufferUsageCmd* cmd = mAllocator.Allocate<TransitionBufferUsageCmd>(Command::TransitionBufferUsage);
new(cmd) TransitionBufferUsageCmd;
cmd->buffer = buffer;
cmd->usage = usage;
}
void CommandBufferBuilder::TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage) {
TransitionTextureUsageCmd* cmd = allocator.Allocate<TransitionTextureUsageCmd>(Command::TransitionTextureUsage);
TransitionTextureUsageCmd* cmd = mAllocator.Allocate<TransitionTextureUsageCmd>(Command::TransitionTextureUsage);
new(cmd) TransitionTextureUsageCmd;
cmd->texture = texture;
cmd->usage = usage;
}
void CommandBufferBuilder::MoveToIterator() {
if (!movedToIterator) {
iterator = std::move(allocator);
movedToIterator = true;
if (!mWasMovedToIterator) {
mIterator = std::move(mAllocator);
mWasMovedToIterator = true;
}
}

View File

@ -46,9 +46,9 @@ namespace backend {
DeviceBase* GetDevice();
private:
DeviceBase* device;
std::set<BufferBase*> buffersTransitioned;
std::set<TextureBase*> texturesTransitioned;
DeviceBase* mDevice;
std::set<BufferBase*> mBuffersTransitioned;
std::set<TextureBase*> mTexturesTransitioned;
};
class CommandBufferBuilder : public Builder<CommandBufferBase> {
@ -101,11 +101,11 @@ namespace backend {
CommandBufferBase* GetResultImpl() override;
void MoveToIterator();
std::unique_ptr<CommandBufferStateTracker> state;
CommandAllocator allocator;
CommandIterator iterator;
bool movedToIterator = false;
bool commandsAcquired = false;
std::unique_ptr<CommandBufferStateTracker> mState;
CommandAllocator mAllocator;
CommandIterator mIterator;
bool mWasMovedToIterator = false;
bool mWereCommandsAcquired = false;
};
}

View File

@ -29,21 +29,21 @@
#include "common/BitSetIterator.h"
namespace backend {
CommandBufferStateTracker::CommandBufferStateTracker(CommandBufferBuilder* builder)
: builder(builder) {
CommandBufferStateTracker::CommandBufferStateTracker(CommandBufferBuilder* mBuilder)
: mBuilder(mBuilder) {
}
bool CommandBufferStateTracker::HaveRenderPass() const {
return currentRenderPass != nullptr;
return mCurrentRenderPass != nullptr;
}
bool CommandBufferStateTracker::HaveRenderSubpass() const {
return aspects[VALIDATION_ASPECT_RENDER_SUBPASS];
return mAspects[VALIDATION_ASPECT_RENDER_SUBPASS];
}
bool CommandBufferStateTracker::ValidateCanCopy() const {
if (currentRenderPass) {
builder->HandleError("Copy cannot occur during a render pass");
if (mCurrentRenderPass) {
mBuilder->HandleError("Copy cannot occur during a render pass");
return false;
}
return true;
@ -51,7 +51,7 @@ namespace backend {
bool CommandBufferStateTracker::ValidateCanUseBufferAs(BufferBase* buffer, nxt::BufferUsageBit usage) const {
if (!BufferHasGuaranteedUsageBit(buffer, usage)) {
builder->HandleError("Buffer is not in the necessary usage");
mBuilder->HandleError("Buffer is not in the necessary usage");
return false;
}
return true;
@ -59,7 +59,7 @@ namespace backend {
bool CommandBufferStateTracker::ValidateCanUseTextureAs(TextureBase* texture, nxt::TextureUsageBit usage) const {
if (!TextureHasGuaranteedUsageBit(texture, usage)) {
builder->HandleError("Texture is not in the necessary usage");
mBuilder->HandleError("Texture is not in the necessary usage");
return false;
}
return true;
@ -69,18 +69,18 @@ namespace backend {
constexpr ValidationAspects requiredAspects =
1 << VALIDATION_ASPECT_COMPUTE_PIPELINE | // implicitly requires COMPUTE_PASS
1 << VALIDATION_ASPECT_BIND_GROUPS;
if ((requiredAspects & ~aspects).none()) {
if ((requiredAspects & ~mAspects).none()) {
// Fast return-true path if everything is good
return true;
}
if (!aspects[VALIDATION_ASPECT_COMPUTE_PIPELINE]) {
builder->HandleError("No active compute pipeline");
if (!mAspects[VALIDATION_ASPECT_COMPUTE_PIPELINE]) {
mBuilder->HandleError("No active compute pipeline");
return false;
}
// Compute the lazily computed aspects
// Compute the lazily computed mAspects
if (!RecomputeHaveAspectBindGroups()) {
builder->HandleError("Bind group state not valid");
mBuilder->HandleError("Bind group state not valid");
return false;
}
return true;
@ -92,7 +92,7 @@ namespace backend {
1 << VALIDATION_ASPECT_RENDER_PIPELINE | // implicitly requires RENDER_SUBPASS
1 << VALIDATION_ASPECT_BIND_GROUPS |
1 << VALIDATION_ASPECT_VERTEX_BUFFERS;
if ((requiredAspects & ~aspects).none()) {
if ((requiredAspects & ~mAspects).none()) {
// Fast return-true path if everything is good
return true;
}
@ -107,191 +107,191 @@ namespace backend {
1 << VALIDATION_ASPECT_BIND_GROUPS |
1 << VALIDATION_ASPECT_VERTEX_BUFFERS |
1 << VALIDATION_ASPECT_INDEX_BUFFER;
if ((requiredAspects & ~aspects).none()) {
if ((requiredAspects & ~mAspects).none()) {
// Fast return-true path if everything is good
return true;
}
if (!aspects[VALIDATION_ASPECT_INDEX_BUFFER]) {
builder->HandleError("Cannot DrawElements without index buffer set");
if (!mAspects[VALIDATION_ASPECT_INDEX_BUFFER]) {
mBuilder->HandleError("Cannot DrawElements without index buffer set");
return false;
}
return RevalidateCanDraw();
}
bool CommandBufferStateTracker::ValidateEndCommandBuffer() const {
if (currentRenderPass != nullptr) {
builder->HandleError("Can't end command buffer with an active render pass");
if (mCurrentRenderPass != nullptr) {
mBuilder->HandleError("Can't end command buffer with an active render pass");
return false;
}
if (aspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
builder->HandleError("Can't end command buffer with an active compute pass");
if (mAspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
mBuilder->HandleError("Can't end command buffer with an active compute pass");
return false;
}
return true;
}
bool CommandBufferStateTracker::ValidateSetPushConstants(nxt::ShaderStageBit stages) {
if (aspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
if (mAspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
if (stages & ~nxt::ShaderStageBit::Compute) {
builder->HandleError("SetPushConstants stage must be compute or 0 in compute passes");
mBuilder->HandleError("SetPushConstants stage must be compute or 0 in compute passes");
return false;
}
} else if (aspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
} else if (mAspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
if (stages & ~(nxt::ShaderStageBit::Vertex | nxt::ShaderStageBit::Fragment)) {
builder->HandleError("SetPushConstants stage must be a subset if (vertex|fragment) in subpasses");
mBuilder->HandleError("SetPushConstants stage must be a subset if (vertex|fragment) in subpasses");
return false;
}
} else {
builder->HandleError("PushConstants must be set in either compute passes or subpasses");
mBuilder->HandleError("PushConstants must be set in either compute passes or subpasses");
return false;
}
return true;
}
bool CommandBufferStateTracker::BeginComputePass() {
if (currentRenderPass != nullptr) {
builder->HandleError("Cannot begin a compute pass while a render pass is active");
if (mCurrentRenderPass != nullptr) {
mBuilder->HandleError("Cannot begin a compute pass while a render pass is active");
return false;
}
aspects.set(VALIDATION_ASPECT_COMPUTE_PASS);
mAspects.set(VALIDATION_ASPECT_COMPUTE_PASS);
return true;
}
bool CommandBufferStateTracker::EndComputePass() {
if (!aspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
builder->HandleError("Can't end a compute pass without beginning one");
if (!mAspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
mBuilder->HandleError("Can't end a compute pass without beginning one");
return false;
}
aspects.reset(VALIDATION_ASPECT_COMPUTE_PASS);
mAspects.reset(VALIDATION_ASPECT_COMPUTE_PASS);
UnsetPipeline();
return true;
}
bool CommandBufferStateTracker::BeginSubpass() {
if (currentRenderPass == nullptr) {
builder->HandleError("Can't begin a subpass without an active render pass");
if (mCurrentRenderPass == nullptr) {
mBuilder->HandleError("Can't begin a subpass without an active render pass");
return false;
}
if (aspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
builder->HandleError("Can't begin a subpass without ending the previous subpass");
if (mAspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
mBuilder->HandleError("Can't begin a subpass without ending the previous subpass");
return false;
}
if (currentSubpass >= currentRenderPass->GetSubpassCount()) {
builder->HandleError("Can't begin a subpass beyond the last subpass");
if (mCurrentSubpass >= mCurrentRenderPass->GetSubpassCount()) {
mBuilder->HandleError("Can't begin a subpass beyond the last subpass");
return false;
}
auto& subpassInfo = currentRenderPass->GetSubpassInfo(currentSubpass);
auto& subpassInfo = mCurrentRenderPass->GetSubpassInfo(mCurrentSubpass);
for (auto location : IterateBitSet(subpassInfo.colorAttachmentsSet)) {
auto attachmentSlot = subpassInfo.colorAttachments[location];
auto* tv = currentFramebuffer->GetTextureView(attachmentSlot);
auto* tv = mCurrentFramebuffer->GetTextureView(attachmentSlot);
auto* texture = tv->GetTexture();
if (!EnsureTextureUsage(texture, nxt::TextureUsageBit::OutputAttachment)) {
builder->HandleError("Unable to ensure texture has OutputAttachment usage");
mBuilder->HandleError("Unable to ensure texture has OutputAttachment usage");
return false;
}
texturesAttached.insert(texture);
mTexturesAttached.insert(texture);
}
aspects.set(VALIDATION_ASPECT_RENDER_SUBPASS);
mAspects.set(VALIDATION_ASPECT_RENDER_SUBPASS);
return true;
}
bool CommandBufferStateTracker::EndSubpass() {
if (!aspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
builder->HandleError("Can't end a subpass without beginning one");
if (!mAspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
mBuilder->HandleError("Can't end a subpass without beginning one");
return false;
}
ASSERT(currentRenderPass != nullptr);
ASSERT(mCurrentRenderPass != nullptr);
auto& subpassInfo = currentRenderPass->GetSubpassInfo(currentSubpass);
auto& subpassInfo = mCurrentRenderPass->GetSubpassInfo(mCurrentSubpass);
for (auto location : IterateBitSet(subpassInfo.colorAttachmentsSet)) {
auto attachmentSlot = subpassInfo.colorAttachments[location];
auto* tv = currentFramebuffer->GetTextureView(attachmentSlot);
auto* tv = mCurrentFramebuffer->GetTextureView(attachmentSlot);
auto* texture = tv->GetTexture();
if (texture->IsFrozen()) {
continue;
}
}
// Everything in texturesAttached should be for the current render subpass.
texturesAttached.clear();
// Everything in mTexturesAttached should be for the current render subpass.
mTexturesAttached.clear();
currentSubpass += 1;
inputsSet.reset();
aspects.reset(VALIDATION_ASPECT_RENDER_SUBPASS);
mCurrentSubpass += 1;
mInputsSet.reset();
mAspects.reset(VALIDATION_ASPECT_RENDER_SUBPASS);
UnsetPipeline();
return true;
}
bool CommandBufferStateTracker::BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer) {
if (aspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
builder->HandleError("Cannot begin a render pass while a compute pass is active");
if (mAspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
mBuilder->HandleError("Cannot begin a render pass while a compute pass is active");
return false;
}
if (currentRenderPass != nullptr) {
builder->HandleError("A render pass is already active");
if (mCurrentRenderPass != nullptr) {
mBuilder->HandleError("A render pass is already active");
return false;
}
ASSERT(!aspects[VALIDATION_ASPECT_RENDER_SUBPASS]);
ASSERT(!mAspects[VALIDATION_ASPECT_RENDER_SUBPASS]);
if (!framebuffer->GetRenderPass()->IsCompatibleWith(renderPass)) {
builder->HandleError("Framebuffer is incompatible with this render pass");
mBuilder->HandleError("Framebuffer is incompatible with this render pass");
return false;
}
currentRenderPass = renderPass;
currentFramebuffer = framebuffer;
currentSubpass = 0;
mCurrentRenderPass = renderPass;
mCurrentFramebuffer = framebuffer;
mCurrentSubpass = 0;
return true;
}
bool CommandBufferStateTracker::EndRenderPass() {
if (currentRenderPass == nullptr) {
builder->HandleError("No render pass is currently active");
if (mCurrentRenderPass == nullptr) {
mBuilder->HandleError("No render pass is currently active");
return false;
}
if (aspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
builder->HandleError("Can't end a render pass while a subpass is active");
if (mAspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
mBuilder->HandleError("Can't end a render pass while a subpass is active");
return false;
}
if (currentSubpass < currentRenderPass->GetSubpassCount() - 1) {
builder->HandleError("Can't end a render pass before the last subpass");
if (mCurrentSubpass < mCurrentRenderPass->GetSubpassCount() - 1) {
mBuilder->HandleError("Can't end a render pass before the last subpass");
return false;
}
currentRenderPass = nullptr;
currentFramebuffer = nullptr;
mCurrentRenderPass = nullptr;
mCurrentFramebuffer = nullptr;
return true;
}
bool CommandBufferStateTracker::SetComputePipeline(ComputePipelineBase* pipeline) {
if (!aspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
builder->HandleError("A compute pass must be active when a compute pipeline is set");
if (!mAspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
mBuilder->HandleError("A compute pass must be active when a compute pipeline is set");
return false;
}
if (currentRenderPass) {
builder->HandleError("Can't use a compute pipeline while a render pass is active");
if (mCurrentRenderPass) {
mBuilder->HandleError("Can't use a compute pipeline while a render pass is active");
return false;
}
aspects.set(VALIDATION_ASPECT_COMPUTE_PIPELINE);
mAspects.set(VALIDATION_ASPECT_COMPUTE_PIPELINE);
SetPipelineCommon(pipeline);
return true;
}
bool CommandBufferStateTracker::SetRenderPipeline(RenderPipelineBase* pipeline) {
if (!aspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
builder->HandleError("A render subpass must be active when a render pipeline is set");
if (!mAspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
mBuilder->HandleError("A render subpass must be active when a render pipeline is set");
return false;
}
if (!pipeline->GetRenderPass()->IsCompatibleWith(currentRenderPass)) {
builder->HandleError("Pipeline is incompatible with this render pass");
if (!pipeline->GetRenderPass()->IsCompatibleWith(mCurrentRenderPass)) {
mBuilder->HandleError("Pipeline is incompatible with this render pass");
return false;
}
aspects.set(VALIDATION_ASPECT_RENDER_PIPELINE);
lastRenderPipeline = pipeline;
mAspects.set(VALIDATION_ASPECT_RENDER_PIPELINE);
mLastRenderPipeline = pipeline;
SetPipelineCommon(pipeline);
return true;
}
@ -300,77 +300,77 @@ namespace backend {
if (!ValidateBindGroupUsages(bindgroup)) {
return false;
}
bindgroupsSet.set(index);
bindgroups[index] = bindgroup;
mBindgroupsSet.set(index);
mBindgroups[index] = bindgroup;
return true;
}
bool CommandBufferStateTracker::SetIndexBuffer(BufferBase* buffer) {
if (!HavePipeline()) {
builder->HandleError("Can't set the index buffer without a pipeline");
mBuilder->HandleError("Can't set the index buffer without a pipeline");
return false;
}
auto usage = nxt::BufferUsageBit::Index;
if (!BufferHasGuaranteedUsageBit(buffer, usage)) {
builder->HandleError("Buffer needs the index usage bit to be guaranteed");
mBuilder->HandleError("Buffer needs the index usage bit to be guaranteed");
return false;
}
aspects.set(VALIDATION_ASPECT_INDEX_BUFFER);
mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER);
return true;
}
bool CommandBufferStateTracker::SetVertexBuffer(uint32_t index, BufferBase* buffer) {
if (!HavePipeline()) {
builder->HandleError("Can't set vertex buffers without a pipeline");
mBuilder->HandleError("Can't set vertex buffers without a pipeline");
return false;
}
auto usage = nxt::BufferUsageBit::Vertex;
if (!BufferHasGuaranteedUsageBit(buffer, usage)) {
builder->HandleError("Buffer needs vertex usage bit to be guaranteed");
mBuilder->HandleError("Buffer needs vertex usage bit to be guaranteed");
return false;
}
inputsSet.set(index);
mInputsSet.set(index);
return true;
}
bool CommandBufferStateTracker::TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage) {
if (!buffer->IsTransitionPossible(usage)) {
if (buffer->IsFrozen()) {
builder->HandleError("Buffer transition not possible (usage is frozen)");
mBuilder->HandleError("Buffer transition not possible (usage is frozen)");
} else if (!BufferBase::IsUsagePossible(buffer->GetAllowedUsage(), usage)) {
builder->HandleError("Buffer transition not possible (usage not allowed)");
mBuilder->HandleError("Buffer transition not possible (usage not allowed)");
} else {
builder->HandleError("Buffer transition not possible");
mBuilder->HandleError("Buffer transition not possible");
}
return false;
}
mostRecentBufferUsages[buffer] = usage;
buffersTransitioned.insert(buffer);
mMostRecentBufferUsages[buffer] = usage;
mBuffersTransitioned.insert(buffer);
return true;
}
bool CommandBufferStateTracker::TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage) {
if (!IsExplicitTextureTransitionPossible(texture, usage)) {
if (texture->IsFrozen()) {
builder->HandleError("Texture transition not possible (usage is frozen)");
mBuilder->HandleError("Texture transition not possible (usage is frozen)");
} else if (!TextureBase::IsUsagePossible(texture->GetAllowedUsage(), usage)) {
builder->HandleError("Texture transition not possible (usage not allowed)");
} else if (texturesAttached.find(texture) != texturesAttached.end()) {
builder->HandleError("Texture transition not possible (texture is in use as a framebuffer attachment)");
mBuilder->HandleError("Texture transition not possible (usage not allowed)");
} else if (mTexturesAttached.find(texture) != mTexturesAttached.end()) {
mBuilder->HandleError("Texture transition not possible (texture is in use as a framebuffer attachment)");
} else {
builder->HandleError("Texture transition not possible");
mBuilder->HandleError("Texture transition not possible");
}
return false;
}
mostRecentTextureUsages[texture] = usage;
texturesTransitioned.insert(texture);
mMostRecentTextureUsages[texture] = usage;
mTexturesTransitioned.insert(texture);
return true;
}
@ -381,8 +381,8 @@ namespace backend {
if (!IsInternalTextureTransitionPossible(texture, usage)) {
return false;
}
mostRecentTextureUsages[texture] = usage;
texturesTransitioned.insert(texture);
mMostRecentTextureUsages[texture] = usage;
mTexturesTransitioned.insert(texture);
return true;
}
@ -391,8 +391,8 @@ namespace backend {
if (buffer->HasFrozenUsage(usage)) {
return true;
}
auto it = mostRecentBufferUsages.find(buffer);
return it != mostRecentBufferUsages.end() && (it->second & usage);
auto it = mMostRecentBufferUsages.find(buffer);
return it != mMostRecentBufferUsages.end() && (it->second & usage);
}
bool CommandBufferStateTracker::TextureHasGuaranteedUsageBit(TextureBase* texture, nxt::TextureUsageBit usage) const {
@ -400,13 +400,13 @@ namespace backend {
if (texture->HasFrozenUsage(usage)) {
return true;
}
auto it = mostRecentTextureUsages.find(texture);
return it != mostRecentTextureUsages.end() && (it->second & usage);
auto it = mMostRecentTextureUsages.find(texture);
return it != mMostRecentTextureUsages.end() && (it->second & usage);
}
bool CommandBufferStateTracker::IsInternalTextureTransitionPossible(TextureBase* texture, nxt::TextureUsageBit usage) const {
ASSERT(usage != nxt::TextureUsageBit::None && nxt::HasZeroOrOneBits(usage));
if (texturesAttached.find(texture) != texturesAttached.end()) {
if (mTexturesAttached.find(texture) != mTexturesAttached.end()) {
return false;
}
return texture->IsTransitionPossible(usage);
@ -422,33 +422,33 @@ namespace backend {
}
bool CommandBufferStateTracker::RecomputeHaveAspectBindGroups() {
if (aspects[VALIDATION_ASPECT_BIND_GROUPS]) {
if (mAspects[VALIDATION_ASPECT_BIND_GROUPS]) {
return true;
}
// Assumes we have a pipeline already
if (!bindgroupsSet.all()) {
if (!mBindgroupsSet.all()) {
return false;
}
for (size_t i = 0; i < bindgroups.size(); ++i) {
if (auto* bindgroup = bindgroups[i]) {
for (size_t i = 0; i < mBindgroups.size(); ++i) {
if (auto* bindgroup = mBindgroups[i]) {
// TODO(kainino@chromium.org): bind group compatibility
if (bindgroup->GetLayout() != lastPipeline->GetLayout()->GetBindGroupLayout(i)) {
if (bindgroup->GetLayout() != mLastPipeline->GetLayout()->GetBindGroupLayout(i)) {
return false;
}
}
}
aspects.set(VALIDATION_ASPECT_BIND_GROUPS);
mAspects.set(VALIDATION_ASPECT_BIND_GROUPS);
return true;
}
bool CommandBufferStateTracker::RecomputeHaveAspectVertexBuffers() {
if (aspects[VALIDATION_ASPECT_VERTEX_BUFFERS]) {
if (mAspects[VALIDATION_ASPECT_VERTEX_BUFFERS]) {
return true;
}
// Assumes we have a pipeline already
auto requiredInputs = lastRenderPipeline->GetInputState()->GetInputsSetMask();
if ((inputsSet & requiredInputs) == requiredInputs) {
aspects.set(VALIDATION_ASPECT_VERTEX_BUFFERS);
auto requiredInputs = mLastRenderPipeline->GetInputState()->GetInputsSetMask();
if ((mInputsSet & requiredInputs) == requiredInputs) {
mAspects.set(VALIDATION_ASPECT_VERTEX_BUFFERS);
return true;
}
return false;
@ -458,7 +458,7 @@ namespace backend {
constexpr ValidationAspects pipelineAspects =
1 << VALIDATION_ASPECT_COMPUTE_PIPELINE |
1 << VALIDATION_ASPECT_RENDER_PIPELINE;
return (aspects & pipelineAspects).any();
return (mAspects & pipelineAspects).any();
}
bool CommandBufferStateTracker::ValidateBindGroupUsages(BindGroupBase* group) const {
@ -489,7 +489,7 @@ namespace backend {
auto buffer = group->GetBindingAsBufferView(i)->GetBuffer();
if (!BufferHasGuaranteedUsageBit(buffer, requiredUsage)) {
builder->HandleError("Can't guarantee buffer usage needed by bind group");
mBuilder->HandleError("Can't guarantee buffer usage needed by bind group");
return false;
}
}
@ -500,7 +500,7 @@ namespace backend {
auto texture = group->GetBindingAsTextureView(i)->GetTexture();
if (!TextureHasGuaranteedUsageBit(texture, requiredUsage)) {
builder->HandleError("Can't guarantee texture usage needed by bind group");
mBuilder->HandleError("Can't guarantee texture usage needed by bind group");
return false;
}
}
@ -513,17 +513,17 @@ namespace backend {
}
bool CommandBufferStateTracker::RevalidateCanDraw() {
if (!aspects[VALIDATION_ASPECT_RENDER_PIPELINE]) {
builder->HandleError("No active render pipeline");
if (!mAspects[VALIDATION_ASPECT_RENDER_PIPELINE]) {
mBuilder->HandleError("No active render pipeline");
return false;
}
// Compute the lazily computed aspects
// Compute the lazily computed mAspects
if (!RecomputeHaveAspectBindGroups()) {
builder->HandleError("Bind group state not valid");
mBuilder->HandleError("Bind group state not valid");
return false;
}
if (!RecomputeHaveAspectVertexBuffers()) {
builder->HandleError("Some vertex buffers are not set");
mBuilder->HandleError("Some vertex buffers are not set");
return false;
}
return true;
@ -532,17 +532,17 @@ namespace backend {
void CommandBufferStateTracker::SetPipelineCommon(PipelineBase* pipeline) {
PipelineLayoutBase* layout = pipeline->GetLayout();
aspects.reset(VALIDATION_ASPECT_BIND_GROUPS);
aspects.reset(VALIDATION_ASPECT_VERTEX_BUFFERS);
mAspects.reset(VALIDATION_ASPECT_BIND_GROUPS);
mAspects.reset(VALIDATION_ASPECT_VERTEX_BUFFERS);
// Reset bindgroups but mark unused bindgroups as valid
bindgroupsSet = ~layout->GetBindGroupsLayoutMask();
mBindgroupsSet = ~layout->GetBindGroupsLayoutMask();
// Only bindgroups that were not the same layout in the last pipeline need to be set again.
if (lastPipeline) {
bindgroupsSet |= layout->InheritedGroupsMask(lastPipeline->GetLayout());
if (mLastPipeline) {
mBindgroupsSet |= layout->InheritedGroupsMask(mLastPipeline->GetLayout());
}
lastPipeline = pipeline;
mLastPipeline = pipeline;
}
void CommandBufferStateTracker::UnsetPipeline() {
@ -552,7 +552,7 @@ namespace backend {
1 << VALIDATION_ASPECT_BIND_GROUPS |
1 << VALIDATION_ASPECT_VERTEX_BUFFERS |
1 << VALIDATION_ASPECT_INDEX_BUFFER;
aspects &= ~pipelineDependentAspects;
bindgroups.fill(nullptr);
mAspects &= ~pipelineDependentAspects;
mBindgroups.fill(nullptr);
}
}

View File

@ -59,9 +59,9 @@ namespace backend {
// These collections are copied to the CommandBuffer at build time.
// These pointers will remain valid since they are referenced by
// the bind groups which are referenced by this command buffer.
std::set<BufferBase*> buffersTransitioned;
std::set<TextureBase*> texturesTransitioned;
std::set<TextureBase*> texturesAttached;
std::set<BufferBase*> mBuffersTransitioned;
std::set<TextureBase*> mTexturesTransitioned;
std::set<TextureBase*> mTexturesAttached;
private:
enum ValidationAspect {
@ -94,22 +94,22 @@ namespace backend {
void SetPipelineCommon(PipelineBase* pipeline);
void UnsetPipeline();
CommandBufferBuilder* builder;
CommandBufferBuilder* mBuilder;
ValidationAspects aspects;
ValidationAspects mAspects;
std::bitset<kMaxBindGroups> bindgroupsSet;
std::array<BindGroupBase*, kMaxBindGroups> bindgroups = {};
std::bitset<kMaxVertexInputs> inputsSet;
PipelineBase* lastPipeline = nullptr;
RenderPipelineBase* lastRenderPipeline = nullptr;
std::bitset<kMaxBindGroups> mBindgroupsSet;
std::array<BindGroupBase*, kMaxBindGroups> mBindgroups = {};
std::bitset<kMaxVertexInputs> mInputsSet;
PipelineBase* mLastPipeline = nullptr;
RenderPipelineBase* mLastRenderPipeline = nullptr;
std::map<BufferBase*, nxt::BufferUsageBit> mostRecentBufferUsages;
std::map<TextureBase*, nxt::TextureUsageBit> mostRecentTextureUsages;
std::map<BufferBase*, nxt::BufferUsageBit> mMostRecentBufferUsages;
std::map<TextureBase*, nxt::TextureUsageBit> mMostRecentTextureUsages;
RenderPassBase* currentRenderPass = nullptr;
FramebufferBase* currentFramebuffer = nullptr;
uint32_t currentSubpass = 0;
RenderPassBase* mCurrentRenderPass = nullptr;
FramebufferBase* mCurrentFramebuffer = nullptr;
uint32_t mCurrentSubpass = 0;
};
}

View File

@ -35,7 +35,7 @@ namespace backend {
}
ComputePipelineBase* ComputePipelineBuilder::GetResultImpl() {
return device->CreateComputePipeline(this);
return mDevice->CreateComputePipeline(this);
}
}

View File

@ -21,26 +21,26 @@ namespace backend {
// DepthStencilStateBase
DepthStencilStateBase::DepthStencilStateBase(DepthStencilStateBuilder* builder)
: depthInfo(builder->depthInfo), stencilInfo(builder->stencilInfo) {
: mDepthInfo(builder->mDepthInfo), mStencilInfo(builder->mStencilInfo) {
}
bool DepthStencilStateBase::StencilTestEnabled() const {
return stencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
stencilInfo.back.stencilFail != nxt::StencilOperation::Keep ||
stencilInfo.back.depthFail != nxt::StencilOperation::Keep ||
stencilInfo.back.depthStencilPass != nxt::StencilOperation::Keep ||
stencilInfo.front.compareFunction != nxt::CompareFunction::Always ||
stencilInfo.front.stencilFail != nxt::StencilOperation::Keep ||
stencilInfo.front.depthFail != nxt::StencilOperation::Keep ||
stencilInfo.front.depthStencilPass != nxt::StencilOperation::Keep;
return mStencilInfo.back.compareFunction != nxt::CompareFunction::Always ||
mStencilInfo.back.stencilFail != nxt::StencilOperation::Keep ||
mStencilInfo.back.depthFail != nxt::StencilOperation::Keep ||
mStencilInfo.back.depthStencilPass != nxt::StencilOperation::Keep ||
mStencilInfo.front.compareFunction != nxt::CompareFunction::Always ||
mStencilInfo.front.stencilFail != nxt::StencilOperation::Keep ||
mStencilInfo.front.depthFail != nxt::StencilOperation::Keep ||
mStencilInfo.front.depthStencilPass != nxt::StencilOperation::Keep;
}
const DepthStencilStateBase::DepthInfo& DepthStencilStateBase::GetDepth() const {
return depthInfo;
return mDepthInfo;
}
const DepthStencilStateBase::StencilInfo& DepthStencilStateBase::GetStencil() const {
return stencilInfo;
return mStencilInfo;
}
// DepthStencilStateBuilder
@ -57,29 +57,29 @@ namespace backend {
}
DepthStencilStateBase* DepthStencilStateBuilder::GetResultImpl() {
return device->CreateDepthStencilState(this);
return mDevice->CreateDepthStencilState(this);
}
void DepthStencilStateBuilder::SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction) {
if ((propertiesSet & 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");
return;
}
propertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_DEPTH_COMPARE_FUNCTION;
mPropertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_DEPTH_COMPARE_FUNCTION;
depthInfo.compareFunction = depthCompareFunction;
mDepthInfo.compareFunction = depthCompareFunction;
}
void DepthStencilStateBuilder::SetDepthWriteEnabled(bool enabled) {
if ((propertiesSet & DEPTH_STENCIL_STATE_PROPERTY_DEPTH_WRITE_ENABLED) != 0) {
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_DEPTH_WRITE_ENABLED) != 0) {
HandleError("Depth write enabled property set multiple times");
return;
}
propertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_DEPTH_WRITE_ENABLED;
mPropertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_DEPTH_WRITE_ENABLED;
depthInfo.depthWriteEnabled = enabled;
mDepthInfo.depthWriteEnabled = enabled;
}
void DepthStencilStateBuilder::SetStencilFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction,
@ -90,42 +90,42 @@ namespace backend {
}
if (face & nxt::Face::Back) {
if ((propertiesSet & 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");
return;
}
propertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_STENCIL_BACK_FUNCTION;
mPropertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_STENCIL_BACK_FUNCTION;
stencilInfo.back.compareFunction = stencilCompareFunction;
stencilInfo.back.stencilFail = stencilFail;
stencilInfo.back.depthFail = depthFail;
stencilInfo.back.depthStencilPass = depthStencilPass;
mStencilInfo.back.compareFunction = stencilCompareFunction;
mStencilInfo.back.stencilFail = stencilFail;
mStencilInfo.back.depthFail = depthFail;
mStencilInfo.back.depthStencilPass = depthStencilPass;
}
if (face & nxt::Face::Front) {
if ((propertiesSet & 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");
return;
}
propertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_STENCIL_FRONT_FUNCTION;
mPropertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_STENCIL_FRONT_FUNCTION;
stencilInfo.front.compareFunction = stencilCompareFunction;
stencilInfo.front.stencilFail = stencilFail;
stencilInfo.front.depthFail = depthFail;
stencilInfo.front.depthStencilPass = depthStencilPass;
mStencilInfo.front.compareFunction = stencilCompareFunction;
mStencilInfo.front.stencilFail = stencilFail;
mStencilInfo.front.depthFail = depthFail;
mStencilInfo.front.depthStencilPass = depthStencilPass;
}
}
void DepthStencilStateBuilder::SetStencilMask(uint32_t readMask, uint32_t writeMask) {
if ((propertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_MASK) != 0) {
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_MASK) != 0) {
HandleError("Stencilmask property set multiple times");
return;
}
propertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_STENCIL_MASK;
stencilInfo.readMask = readMask;
stencilInfo.writeMask = writeMask;
mPropertiesSet |= DEPTH_STENCIL_STATE_PROPERTY_STENCIL_MASK;
mStencilInfo.readMask = readMask;
mStencilInfo.writeMask = writeMask;
}
}

View File

@ -52,8 +52,8 @@ namespace backend {
const StencilInfo& GetStencil() const;
private:
DepthInfo depthInfo;
StencilInfo stencilInfo;
DepthInfo mDepthInfo;
StencilInfo mStencilInfo;
};
class DepthStencilStateBuilder : public Builder<DepthStencilStateBase> {
@ -72,10 +72,10 @@ namespace backend {
DepthStencilStateBase* GetResultImpl() override;
int propertiesSet = 0;
int mPropertiesSet = 0;
DepthStencilStateBase::DepthInfo depthInfo;
DepthStencilStateBase::StencilInfo stencilInfo;
DepthStencilStateBase::DepthInfo mDepthInfo;
DepthStencilStateBase::StencilInfo mStencilInfo;
};
}

View File

@ -49,22 +49,22 @@ namespace backend {
// DeviceBase
DeviceBase::DeviceBase() {
caches = new DeviceBase::Caches();
mCaches = new DeviceBase::Caches();
}
DeviceBase::~DeviceBase() {
delete caches;
delete mCaches;
}
void DeviceBase::HandleError(const char* message) {
if (errorCallback) {
errorCallback(message, errorUserdata);
if (mErrorCallback) {
mErrorCallback(message, mErrorUserdata);
}
}
void DeviceBase::SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata) {
this->errorCallback = callback;
this->errorUserdata = userdata;
mErrorCallback = callback;
mErrorUserdata = userdata;
}
DeviceBase* DeviceBase::GetDevice() {
@ -76,18 +76,18 @@ namespace backend {
// objects can be modified, and unordered_set cannot search for a const pointer in a non
// const pointer set. That's why we do a const_cast here, but the blueprint won't be
// modified.
auto iter = caches->bindGroupLayouts.find(const_cast<BindGroupLayoutBase*>(blueprint));
if (iter != caches->bindGroupLayouts.end()) {
auto iter = mCaches->bindGroupLayouts.find(const_cast<BindGroupLayoutBase*>(blueprint));
if (iter != mCaches->bindGroupLayouts.end()) {
return *iter;
}
BindGroupLayoutBase* backendObj = CreateBindGroupLayout(builder);
caches->bindGroupLayouts.insert(backendObj);
mCaches->bindGroupLayouts.insert(backendObj);
return backendObj;
}
void DeviceBase::UncacheBindGroupLayout(BindGroupLayoutBase* obj) {
caches->bindGroupLayouts.erase(obj);
mCaches->bindGroupLayouts.erase(obj);
}
BindGroupBuilder* DeviceBase::CreateBindGroupBuilder() {
@ -147,14 +147,14 @@ namespace backend {
}
void DeviceBase::Reference() {
ASSERT(refCount != 0);
refCount++;
ASSERT(mRefCount != 0);
mRefCount++;
}
void DeviceBase::Release() {
ASSERT(refCount != 0);
refCount--;
if (refCount == 0) {
ASSERT(mRefCount != 0);
mRefCount--;
if (mRefCount == 0) {
delete this;
}
}

View File

@ -78,7 +78,6 @@ namespace backend {
BindGroupLayoutBuilder* CreateBindGroupLayoutBuilder();
BlendStateBuilder* CreateBlendStateBuilder();
BufferBuilder* CreateBufferBuilder();
BufferViewBuilder* CreateBufferViewBuilder();
CommandBufferBuilder* CreateCommandBufferBuilder();
ComputePipelineBuilder* CreateComputePipelineBuilder();
DepthStencilStateBuilder* CreateDepthStencilStateBuilder();
@ -94,7 +93,6 @@ namespace backend {
TextureBuilder* CreateTextureBuilder();
void Tick();
void CopyBindGroups(uint32_t start, uint32_t count, BindGroupBase* source, BindGroupBase* target);
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata);
void Reference();
void Release();
@ -103,11 +101,11 @@ namespace backend {
// The object caches aren't exposed in the header as they would require a lot of
// additional includes.
struct Caches;
Caches* caches = nullptr;
Caches* mCaches = nullptr;
nxt::DeviceErrorCallback errorCallback = nullptr;
nxt::CallbackUserdata errorUserdata = 0;
uint32_t refCount = 1;
nxt::DeviceErrorCallback mErrorCallback = nullptr;
nxt::CallbackUserdata mErrorUserdata = 0;
uint32_t mRefCount = 1;
};
}

View File

@ -25,49 +25,49 @@ namespace backend {
// Framebuffer
FramebufferBase::FramebufferBase(FramebufferBuilder* builder)
: device(builder->device), renderPass(std::move(builder->renderPass)),
width(builder->width), height(builder->height), textureViews(std::move(builder->textureViews)),
clearColors(textureViews.size()), clearDepthStencils(textureViews.size()) {
: mDevice(builder->mDevice), mRenderPass(std::move(builder->mRenderPass)),
mWidth(builder->mWidth), mHeight(builder->mHeight), mTextureViews(std::move(builder->mTextureViews)),
mClearColors(mTextureViews.size()), mClearDepthStencils(mTextureViews.size()) {
}
DeviceBase* FramebufferBase::GetDevice() {
return device;
return mDevice;
}
RenderPassBase* FramebufferBase::GetRenderPass() {
return renderPass.Get();
return mRenderPass.Get();
}
TextureViewBase* FramebufferBase::GetTextureView(uint32_t attachmentSlot) {
ASSERT(attachmentSlot < textureViews.size());
return textureViews[attachmentSlot].Get();
ASSERT(attachmentSlot < mTextureViews.size());
return mTextureViews[attachmentSlot].Get();
}
FramebufferBase::ClearColor FramebufferBase::GetClearColor(uint32_t attachmentSlot) {
ASSERT(attachmentSlot < clearColors.size());
return clearColors[attachmentSlot];
ASSERT(attachmentSlot < mClearColors.size());
return mClearColors[attachmentSlot];
}
FramebufferBase::ClearDepthStencil FramebufferBase::GetClearDepthStencil(uint32_t attachmentSlot) {
ASSERT(attachmentSlot < clearDepthStencils.size());
return clearDepthStencils[attachmentSlot];
ASSERT(attachmentSlot < mClearDepthStencils.size());
return mClearDepthStencils[attachmentSlot];
}
uint32_t FramebufferBase::GetWidth() const {
return width;
return mWidth;
}
uint32_t FramebufferBase::GetHeight() const {
return height;
return mHeight;
}
void FramebufferBase::AttachmentSetClearColor(uint32_t attachmentSlot, float clearR, float clearG, float clearB, float clearA) {
if (attachmentSlot >= renderPass->GetAttachmentCount()) {
device->HandleError("Framebuffer attachment out of bounds");
if (attachmentSlot >= mRenderPass->GetAttachmentCount()) {
mDevice->HandleError("Framebuffer attachment out of bounds");
return;
}
ASSERT(attachmentSlot < clearColors.size());
auto& c = clearColors[attachmentSlot];
ASSERT(attachmentSlot < mClearColors.size());
auto& c = mClearColors[attachmentSlot];
c.color[0] = clearR;
c.color[1] = clearG;
c.color[2] = clearB;
@ -75,12 +75,12 @@ namespace backend {
}
void FramebufferBase::AttachmentSetClearDepthStencil(uint32_t attachmentSlot, float clearDepth, uint32_t clearStencil) {
if (attachmentSlot >= renderPass->GetAttachmentCount()) {
device->HandleError("Framebuffer attachment out of bounds");
if (attachmentSlot >= mRenderPass->GetAttachmentCount()) {
mDevice->HandleError("Framebuffer attachment out of bounds");
return;
}
ASSERT(attachmentSlot < clearDepthStencils.size());
auto& c = clearDepthStencils[attachmentSlot];
ASSERT(attachmentSlot < mClearDepthStencils.size());
auto& c = mClearDepthStencils[attachmentSlot];
c.depth = clearDepth;
c.stencil = clearStencil;
}
@ -98,30 +98,30 @@ namespace backend {
FramebufferBase* FramebufferBuilder::GetResultImpl() {
constexpr int requiredProperties = FRAMEBUFFER_PROPERTY_RENDER_PASS | FRAMEBUFFER_PROPERTY_DIMENSIONS;
if ((propertiesSet & requiredProperties) != requiredProperties) {
if ((mPropertiesSet & requiredProperties) != requiredProperties) {
HandleError("Framebuffer missing properties");
return nullptr;
}
for (auto& textureView : textureViews) {
for (auto& textureView : mTextureViews) {
if (!textureView) {
HandleError("Framebuffer attachment not set");
return nullptr;
}
// TODO(cwallez@chromium.org): Adjust for the mip-level once that is supported.
if (textureView->GetTexture()->GetWidth() != width ||
textureView->GetTexture()->GetHeight() != height) {
if (textureView->GetTexture()->GetWidth() != mWidth ||
textureView->GetTexture()->GetHeight() != mHeight) {
HandleError("Framebuffer size doesn't match attachment size");
return nullptr;
}
}
return device->CreateFramebuffer(this);
return mDevice->CreateFramebuffer(this);
}
void FramebufferBuilder::SetRenderPass(RenderPassBase* renderPass) {
if ((propertiesSet & FRAMEBUFFER_PROPERTY_RENDER_PASS) != 0) {
if ((mPropertiesSet & FRAMEBUFFER_PROPERTY_RENDER_PASS) != 0) {
HandleError("Framebuffer render pass property set multiple times");
return;
}
@ -131,36 +131,36 @@ namespace backend {
return;
}
this->renderPass = renderPass;
this->textureViews.resize(renderPass->GetAttachmentCount());
propertiesSet |= FRAMEBUFFER_PROPERTY_RENDER_PASS;
mRenderPass = renderPass;
mTextureViews.resize(renderPass->GetAttachmentCount());
mPropertiesSet |= FRAMEBUFFER_PROPERTY_RENDER_PASS;
}
void FramebufferBuilder::SetDimensions(uint32_t width, uint32_t height) {
if ((propertiesSet & FRAMEBUFFER_PROPERTY_DIMENSIONS) != 0) {
if ((mPropertiesSet & FRAMEBUFFER_PROPERTY_DIMENSIONS) != 0) {
HandleError("Framebuffer dimensions property set multiple times");
return;
}
this->width = width;
this->height = height;
propertiesSet |= FRAMEBUFFER_PROPERTY_DIMENSIONS;
mWidth = width;
mHeight = height;
mPropertiesSet |= FRAMEBUFFER_PROPERTY_DIMENSIONS;
}
void FramebufferBuilder::SetAttachment(uint32_t attachmentSlot, TextureViewBase* textureView) {
if ((propertiesSet & FRAMEBUFFER_PROPERTY_RENDER_PASS) == 0) {
if ((mPropertiesSet & FRAMEBUFFER_PROPERTY_RENDER_PASS) == 0) {
HandleError("Render pass must be set before framebuffer attachments");
return;
}
if (attachmentSlot >= textureViews.size()) {
if (attachmentSlot >= mTextureViews.size()) {
HandleError("Attachment slot out of bounds");
return;
}
if (textureViews[attachmentSlot]) {
if (mTextureViews[attachmentSlot]) {
HandleError("Framebuffer attachment[i] set multiple times");
return;
}
const auto& attachmentInfo = renderPass->GetAttachmentInfo(attachmentSlot);
const auto& attachmentInfo = mRenderPass->GetAttachmentInfo(attachmentSlot);
const auto* texture = textureView->GetTexture();
if (attachmentInfo.format != texture->GetFormat()) {
HandleError("Texture format does not match attachment format");
@ -168,6 +168,6 @@ namespace backend {
}
// TODO(kainino@chromium.org): also check attachment samples, etc.
textureViews[attachmentSlot] = textureView;
mTextureViews[attachmentSlot] = textureView;
}
}

View File

@ -52,13 +52,13 @@ namespace backend {
void AttachmentSetClearDepthStencil(uint32_t attachmentSlot, float clearDepth, uint32_t clearStencil);
private:
DeviceBase* device;
Ref<RenderPassBase> renderPass;
uint32_t width = 0;
uint32_t height = 0;
std::vector<Ref<TextureViewBase>> textureViews;
std::vector<ClearColor> clearColors;
std::vector<ClearDepthStencil> clearDepthStencils;
DeviceBase* mDevice;
Ref<RenderPassBase> mRenderPass;
uint32_t mWidth = 0;
uint32_t mHeight = 0;
std::vector<Ref<TextureViewBase>> mTextureViews;
std::vector<ClearColor> mClearColors;
std::vector<ClearDepthStencil> mClearDepthStencils;
};
class FramebufferBuilder : public Builder<FramebufferBase> {
@ -74,11 +74,11 @@ namespace backend {
private:
friend class FramebufferBase;
Ref<RenderPassBase> renderPass;
uint32_t width = 0;
uint32_t height = 0;
std::vector<Ref<TextureViewBase>> textureViews;
int propertiesSet = 0;
Ref<RenderPassBase> mRenderPass;
uint32_t mWidth = 0;
uint32_t mHeight = 0;
std::vector<Ref<TextureViewBase>> mTextureViews;
int mPropertiesSet = 0;
};
}

View File

@ -62,28 +62,28 @@ namespace backend {
// InputStateBase
InputStateBase::InputStateBase(InputStateBuilder* builder) {
attributesSetMask = builder->attributesSetMask;
attributeInfos = builder->attributeInfos;
inputsSetMask = builder->inputsSetMask;
inputInfos = builder->inputInfos;
mAttributesSetMask = builder->mAttributesSetMask;
mAttributeInfos = builder->mAttributeInfos;
mInputsSetMask = builder->mInputsSetMask;
mInputInfos = builder->mInputInfos;
}
const std::bitset<kMaxVertexAttributes>& InputStateBase::GetAttributesSetMask() const {
return attributesSetMask;
return mAttributesSetMask;
}
const InputStateBase::AttributeInfo& InputStateBase::GetAttribute(uint32_t location) const {
ASSERT(attributesSetMask[location]);
return attributeInfos[location];
ASSERT(mAttributesSetMask[location]);
return mAttributeInfos[location];
}
const std::bitset<kMaxVertexInputs>& InputStateBase::GetInputsSetMask() const {
return inputsSetMask;
return mInputsSetMask;
}
const InputStateBase::InputInfo& InputStateBase::GetInput(uint32_t slot) const {
ASSERT(inputsSetMask[slot]);
return inputInfos[slot];
ASSERT(mInputsSetMask[slot]);
return mInputInfos[slot];
}
// InputStateBuilder
@ -93,14 +93,14 @@ namespace backend {
InputStateBase* InputStateBuilder::GetResultImpl() {
for (uint32_t location = 0; location < kMaxVertexAttributes; ++location) {
if (attributesSetMask[location] &&
!inputsSetMask[attributeInfos[location].bindingSlot]) {
if (mAttributesSetMask[location] &&
!mInputsSetMask[mAttributeInfos[location].bindingSlot]) {
HandleError("Attribute uses unset input");
return nullptr;
}
}
return device->CreateInputState(this);
return mDevice->CreateInputState(this);
}
void InputStateBuilder::SetAttribute(uint32_t shaderLocation,
@ -113,13 +113,13 @@ namespace backend {
HandleError("Binding slot out of bounds");
return;
}
if (attributesSetMask[shaderLocation]) {
if (mAttributesSetMask[shaderLocation]) {
HandleError("Setting already set attribute");
return;
}
attributesSetMask.set(shaderLocation);
auto& info = attributeInfos[shaderLocation];
mAttributesSetMask.set(shaderLocation);
auto& info = mAttributeInfos[shaderLocation];
info.bindingSlot = bindingSlot;
info.format = format;
info.offset = offset;
@ -131,13 +131,13 @@ namespace backend {
HandleError("Setting input out of bounds");
return;
}
if (inputsSetMask[bindingSlot]) {
if (mInputsSetMask[bindingSlot]) {
HandleError("Setting already set input");
return;
}
inputsSetMask.set(bindingSlot);
auto& info = inputInfos[bindingSlot];
mInputsSetMask.set(bindingSlot);
auto& info = mInputInfos[bindingSlot];
info.stride = stride;
info.stepMode = stepMode;
}

View File

@ -52,10 +52,10 @@ namespace backend {
const InputInfo& GetInput(uint32_t slot) const;
private:
std::bitset<kMaxVertexAttributes> attributesSetMask;
std::array<AttributeInfo, kMaxVertexAttributes> attributeInfos;
std::bitset<kMaxVertexInputs> inputsSetMask;
std::array<InputInfo, kMaxVertexInputs> inputInfos;
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
std::array<AttributeInfo, kMaxVertexAttributes> mAttributeInfos;
std::bitset<kMaxVertexInputs> mInputsSetMask;
std::array<InputInfo, kMaxVertexInputs> mInputInfos;
};
class InputStateBuilder : public Builder<InputStateBase> {
@ -73,10 +73,10 @@ namespace backend {
InputStateBase* GetResultImpl() override;
std::bitset<kMaxVertexAttributes> attributesSetMask;
std::array<InputStateBase::AttributeInfo, kMaxVertexAttributes> attributeInfos;
std::bitset<kMaxVertexInputs> inputsSetMask;
std::array<InputStateBase::InputInfo, kMaxVertexInputs> inputInfos;
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
std::array<InputStateBase::AttributeInfo, kMaxVertexAttributes> mAttributeInfos;
std::bitset<kMaxVertexInputs> mInputsSetMask;
std::array<InputStateBase::InputInfo, kMaxVertexInputs> mInputInfos;
};
}

View File

@ -43,26 +43,26 @@ namespace backend {
public:
T& operator[](nxt::ShaderStage stage) {
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
return data[static_cast<uint32_t>(stage)];
return mData[static_cast<uint32_t>(stage)];
}
const T& operator[](nxt::ShaderStage stage) const {
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
return data[static_cast<uint32_t>(stage)];
return mData[static_cast<uint32_t>(stage)];
}
T& operator[](nxt::ShaderStageBit stageBit) {
uint32_t bit = static_cast<uint32_t>(stageBit);
NXT_ASSERT(bit != 0 && IsPowerOfTwo(bit) && bit <= (1 << kNumStages));
return data[Log2(bit)];
return mData[Log2(bit)];
}
const T& operator[](nxt::ShaderStageBit stageBit) const {
uint32_t bit = static_cast<uint32_t>(stageBit);
NXT_ASSERT(bit != 0 && IsPowerOfTwo(bit) && bit <= (1 << kNumStages));
return data[Log2(bit)];
return mData[Log2(bit)];
}
private:
std::array<T, kNumStages> data;
std::array<T, kNumStages> mData;
};
}

View File

@ -26,9 +26,9 @@ namespace backend {
// PipelineBase
PipelineBase::PipelineBase(PipelineBuilder* builder)
: stageMask(builder->stageMask), layout(std::move(builder->layout)) {
if (!layout) {
layout = builder->GetParentBuilder()->GetDevice()->CreatePipelineLayoutBuilder()->GetResult();
: mStageMask(builder->mStageMask), mLayout(std::move(builder->mLayout)) {
if (!mLayout) {
mLayout = builder->GetParentBuilder()->GetDevice()->CreatePipelineLayoutBuilder()->GetResult();
}
auto FillPushConstants = [](const ShaderModuleBase* module, PushConstantInfo* info) {
@ -48,67 +48,67 @@ namespace backend {
}
};
for (auto stageBit : IterateStages(builder->stageMask)) {
if (!builder->stages[stageBit].module->IsCompatibleWithPipelineLayout(layout.Get())) {
for (auto stageBit : IterateStages(builder->mStageMask)) {
if (!builder->mStages[stageBit].module->IsCompatibleWithPipelineLayout(mLayout.Get())) {
builder->GetParentBuilder()->HandleError("Stage not compatible with layout");
return;
}
FillPushConstants(builder->stages[stageBit].module.Get(), &pushConstants[stageBit]);
FillPushConstants(builder->mStages[stageBit].module.Get(), &mPushConstants[stageBit]);
}
}
const PipelineBase::PushConstantInfo& PipelineBase::GetPushConstants(nxt::ShaderStage stage) const {
return pushConstants[stage];
return mPushConstants[stage];
}
nxt::ShaderStageBit PipelineBase::GetStageMask() const {
return stageMask;
return mStageMask;
}
PipelineLayoutBase* PipelineBase::GetLayout() {
return layout.Get();
return mLayout.Get();
}
// PipelineBuilder
PipelineBuilder::PipelineBuilder(BuilderBase* parentBuilder)
: parentBuilder(parentBuilder), stageMask(static_cast<nxt::ShaderStageBit>(0)) {
: mParentBuilder(parentBuilder), mStageMask(static_cast<nxt::ShaderStageBit>(0)) {
}
const PipelineBuilder::StageInfo& PipelineBuilder::GetStageInfo(nxt::ShaderStage stage) const {
ASSERT(stageMask & StageBit(stage));
return stages[stage];
ASSERT(mStageMask & StageBit(stage));
return mStages[stage];
}
BuilderBase* PipelineBuilder::GetParentBuilder() const {
return parentBuilder;
return mParentBuilder;
}
void PipelineBuilder::SetLayout(PipelineLayoutBase* layout) {
this->layout = layout;
mLayout = layout;
}
void PipelineBuilder::SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint) {
if (entryPoint != std::string("main")) {
parentBuilder->HandleError("Currently the entry point has to be main()");
mParentBuilder->HandleError("Currently the entry point has to be main()");
return;
}
if (stage != module->GetExecutionModel()) {
parentBuilder->HandleError("Setting module with wrong execution model");
mParentBuilder->HandleError("Setting module with wrong execution model");
return;
}
nxt::ShaderStageBit bit = StageBit(stage);
if (stageMask & bit) {
parentBuilder->HandleError("Setting already set stage");
if (mStageMask & bit) {
mParentBuilder->HandleError("Setting already set stage");
return;
}
stageMask |= bit;
mStageMask |= bit;
stages[stage].module = module;
stages[stage].entryPoint = entryPoint;
mStages[stage].module = module;
mStages[stage].entryPoint = entryPoint;
}
}

View File

@ -51,9 +51,9 @@ namespace backend {
PipelineLayoutBase* GetLayout();
private:
nxt::ShaderStageBit stageMask;
Ref<PipelineLayoutBase> layout;
PerStage<PushConstantInfo> pushConstants;
nxt::ShaderStageBit mStageMask;
Ref<PipelineLayoutBase> mLayout;
PerStage<PushConstantInfo> mPushConstants;
};
class PipelineBuilder {
@ -74,10 +74,10 @@ namespace backend {
private:
friend class PipelineBase;
BuilderBase* parentBuilder;
Ref<PipelineLayoutBase> layout;
nxt::ShaderStageBit stageMask;
PerStage<StageInfo> stages;
BuilderBase* mParentBuilder;
Ref<PipelineLayoutBase> mLayout;
nxt::ShaderStageBit mStageMask;
PerStage<StageInfo> mStages;
};
}

View File

@ -23,16 +23,16 @@ namespace backend {
// PipelineLayoutBase
PipelineLayoutBase::PipelineLayoutBase(PipelineLayoutBuilder* builder)
: bindGroupLayouts(std::move(builder->bindGroupLayouts)), mask(builder->mask) {
: mBindGroupLayouts(std::move(builder->mBindGroupLayouts)), mMask(builder->mMask) {
}
const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(size_t group) const {
ASSERT(group < kMaxBindGroups);
return bindGroupLayouts[group].Get();
return mBindGroupLayouts[group].Get();
}
const std::bitset<kMaxBindGroups> PipelineLayoutBase::GetBindGroupsLayoutMask() const {
return mask;
return mMask;
}
std::bitset<kMaxBindGroups> PipelineLayoutBase::InheritedGroupsMask(const PipelineLayoutBase* other) const {
@ -41,7 +41,7 @@ namespace backend {
uint32_t PipelineLayoutBase::GroupsInheritUpTo(const PipelineLayoutBase* other) const {
for (uint32_t i = 0; i < kMaxBindGroups; ++i) {
if (!mask[i] || bindGroupLayouts[i].Get() != other->bindGroupLayouts[i].Get()) {
if (!mMask[i] || mBindGroupLayouts[i].Get() != other->mBindGroupLayouts[i].Get()) {
return i;
}
}
@ -57,12 +57,12 @@ namespace backend {
// TODO(cwallez@chromium.org): this is a hack, have the null bind group layout somewhere in the device
// once we have a cache of BGL
for (size_t group = 0; group < kMaxBindGroups; ++group) {
if (!bindGroupLayouts[group]) {
bindGroupLayouts[group] = device->CreateBindGroupLayoutBuilder()->GetResult();
if (!mBindGroupLayouts[group]) {
mBindGroupLayouts[group] = mDevice->CreateBindGroupLayoutBuilder()->GetResult();
}
}
return device->CreatePipelineLayout(this);
return mDevice->CreatePipelineLayout(this);
}
void PipelineLayoutBuilder::SetBindGroupLayout(uint32_t groupIndex, BindGroupLayoutBase* layout) {
@ -70,13 +70,13 @@ namespace backend {
HandleError("groupIndex is over the maximum allowed");
return;
}
if (mask[groupIndex]) {
if (mMask[groupIndex]) {
HandleError("Bind group layout already specified");
return;
}
bindGroupLayouts[groupIndex] = layout;
mask.set(groupIndex);
mBindGroupLayouts[groupIndex] = layout;
mMask.set(groupIndex);
}
}

View File

@ -44,8 +44,8 @@ namespace backend {
uint32_t GroupsInheritUpTo(const PipelineLayoutBase* other) const;
protected:
BindGroupLayoutArray bindGroupLayouts;
std::bitset<kMaxBindGroups> mask;
BindGroupLayoutArray mBindGroupLayouts;
std::bitset<kMaxBindGroups> mMask;
};
class PipelineLayoutBuilder : public Builder<PipelineLayoutBase> {
@ -60,8 +60,8 @@ namespace backend {
PipelineLayoutBase* GetResultImpl() override;
BindGroupLayoutArray bindGroupLayouts;
std::bitset<kMaxBindGroups> mask;
BindGroupLayoutArray mBindGroupLayouts;
std::bitset<kMaxBindGroups> mMask;
};
}

View File

@ -21,11 +21,11 @@ namespace backend {
// QueueBase
QueueBase::QueueBase(QueueBuilder* builder) : device(builder->device) {
QueueBase::QueueBase(QueueBuilder* builder) : mDevice(builder->mDevice) {
}
DeviceBase* QueueBase::GetDevice() {
return device;
return mDevice;
}
bool QueueBase::ValidateSubmitCommand(CommandBufferBase* command) {
@ -38,7 +38,7 @@ namespace backend {
}
QueueBase* QueueBuilder::GetResultImpl() {
return device->CreateQueue(this);
return mDevice->CreateQueue(this);
}
}

View File

@ -44,7 +44,7 @@ namespace backend {
private:
bool ValidateSubmitCommand(CommandBufferBase* command);
DeviceBase* device;
DeviceBase* mDevice;
};
class QueueBuilder : public Builder<QueueBase> {

View File

@ -25,39 +25,39 @@ namespace backend {
}
void RefCounted::ReferenceInternal() {
ASSERT(internalRefs != 0);
ASSERT(mInternalRefs != 0);
// TODO(cwallez@chromium.org): what to do on overflow?
internalRefs ++;
mInternalRefs ++;
}
void RefCounted::ReleaseInternal() {
ASSERT(internalRefs != 0);
internalRefs --;
if (internalRefs == 0) {
ASSERT(externalRefs == 0);
ASSERT(mInternalRefs != 0);
mInternalRefs --;
if (mInternalRefs == 0) {
ASSERT(mExternalRefs == 0);
// TODO(cwallez@chromium.org): would this work with custom allocators?
delete this;
}
}
uint32_t RefCounted::GetExternalRefs() const {
return externalRefs;
return mExternalRefs;
}
uint32_t RefCounted::GetInternalRefs() const {
return internalRefs;
return mInternalRefs;
}
void RefCounted::Reference() {
ASSERT(externalRefs != 0);
ASSERT(mExternalRefs != 0);
// TODO(cwallez@chromium.org): what to do on overflow?
externalRefs ++;
mExternalRefs ++;
}
void RefCounted::Release() {
ASSERT(externalRefs != 0);
externalRefs --;
if (externalRefs == 0) {
ASSERT(mExternalRefs != 0);
mExternalRefs --;
if (mExternalRefs == 0) {
ReleaseInternal();
}
}

View File

@ -35,8 +35,8 @@ namespace backend {
void Release();
protected:
uint32_t externalRefs = 1;
uint32_t internalRefs = 1;
uint32_t mExternalRefs = 1;
uint32_t mInternalRefs = 1;
};
template<typename T>
@ -44,11 +44,11 @@ namespace backend {
public:
Ref() {}
Ref(T* p): pointee(p) {
Ref(T* p): mPointee(p) {
Reference();
}
Ref(const Ref<T>& other): pointee(other.pointee) {
Ref(const Ref<T>& other): mPointee(other.mPointee) {
Reference();
}
Ref<T>& operator=(const Ref<T>& other) {
@ -56,69 +56,69 @@ namespace backend {
other.Reference();
Release();
pointee = other.pointee;
mPointee = other.mPointee;
return *this;
}
Ref(Ref<T>&& other) {
pointee = other.pointee;
other.pointee = nullptr;
mPointee = other.mPointee;
other.mPointee = nullptr;
}
Ref<T>& operator=(Ref<T>&& other) {
if (&other == this) return *this;
Release();
pointee = other.pointee;
other.pointee = nullptr;
mPointee = other.mPointee;
other.mPointee = nullptr;
return *this;
}
~Ref() {
Release();
pointee = nullptr;
mPointee = nullptr;
}
operator bool() {
return pointee != nullptr;
return mPointee != nullptr;
}
const T& operator*() const {
return *pointee;
return *mPointee;
}
T& operator*() {
return *pointee;
return *mPointee;
}
const T* operator->() const {
return pointee;
return mPointee;
}
T* operator->() {
return pointee;
return mPointee;
}
const T* Get() const {
return pointee;
return mPointee;
}
T* Get() {
return pointee;
return mPointee;
}
private:
void Reference() const {
if (pointee != nullptr) {
pointee->ReferenceInternal();
if (mPointee != nullptr) {
mPointee->ReferenceInternal();
}
}
void Release() const {
if (pointee != nullptr) {
pointee->ReleaseInternal();
if (mPointee != nullptr) {
mPointee->ReleaseInternal();
}
}
//static_assert(std::is_base_of<RefCounted, T>::value, "");
T* pointee = nullptr;
T* mPointee = nullptr;
};
}

View File

@ -25,19 +25,19 @@ namespace backend {
// RenderPass
RenderPassBase::RenderPassBase(RenderPassBuilder* builder)
: attachments(std::move(builder->attachments)), subpasses(std::move(builder->subpasses)) {
: mAttachments(std::move(builder->mAttachments)), mSubpasses(std::move(builder->mSubpasses)) {
for (uint32_t s = 0; s < GetSubpassCount(); ++s) {
const auto& subpass = GetSubpassInfo(s);
for (auto location : IterateBitSet(subpass.colorAttachmentsSet)) {
auto attachmentSlot = subpass.colorAttachments[location];
auto& firstSubpass = attachments[attachmentSlot].firstSubpass;
auto& firstSubpass = mAttachments[attachmentSlot].firstSubpass;
if (firstSubpass == UINT32_MAX) {
firstSubpass = s;
}
}
if (subpass.depthStencilAttachmentSet) {
auto attachmentSlot = subpass.depthStencilAttachment;
auto& firstSubpass = attachments[attachmentSlot].firstSubpass;
auto& firstSubpass = mAttachments[attachmentSlot].firstSubpass;
if (firstSubpass == UINT32_MAX) {
firstSubpass = s;
}
@ -46,21 +46,21 @@ namespace backend {
}
uint32_t RenderPassBase::GetAttachmentCount() const {
return static_cast<uint32_t>(attachments.size());
return static_cast<uint32_t>(mAttachments.size());
}
const RenderPassBase::AttachmentInfo& RenderPassBase::GetAttachmentInfo(uint32_t attachment) const {
ASSERT(attachment < attachments.size());
return attachments[attachment];
ASSERT(attachment < mAttachments.size());
return mAttachments[attachment];
}
uint32_t RenderPassBase::GetSubpassCount() const {
return static_cast<uint32_t>(subpasses.size());
return static_cast<uint32_t>(mSubpasses.size());
}
const RenderPassBase::SubpassInfo& RenderPassBase::GetSubpassInfo(uint32_t subpass) const {
ASSERT(subpass < subpasses.size());
return subpasses[subpass];
ASSERT(subpass < mSubpasses.size());
return mSubpasses[subpass];
}
bool RenderPassBase::IsCompatibleWith(const RenderPassBase* other) const {
@ -77,102 +77,102 @@ namespace backend {
};
RenderPassBuilder::RenderPassBuilder(DeviceBase* device)
: Builder(device), subpasses(1) {
: Builder(device), mSubpasses(1) {
}
RenderPassBase* RenderPassBuilder::GetResultImpl() {
constexpr int requiredProperties = RENDERPASS_PROPERTY_ATTACHMENT_COUNT | RENDERPASS_PROPERTY_SUBPASS_COUNT;
if ((propertiesSet & requiredProperties) != requiredProperties) {
if ((mPropertiesSet & requiredProperties) != requiredProperties) {
HandleError("Render pass missing properties");
return nullptr;
}
for (const auto& prop : attachmentProperties) {
for (const auto& prop : mAttachmentProperties) {
if (!prop.all()) {
HandleError("A render pass attachment is missing some property");
return nullptr;
}
}
for (const auto& subpass : subpasses) {
for (const auto& subpass : mSubpasses) {
for (unsigned int location : IterateBitSet(subpass.colorAttachmentsSet)) {
uint32_t slot = subpass.colorAttachments[location];
if (TextureFormatHasDepthOrStencil(attachments[slot].format)) {
if (TextureFormatHasDepthOrStencil(mAttachments[slot].format)) {
HandleError("Render pass color attachment is not of a color format");
return nullptr;
}
}
if (subpass.depthStencilAttachmentSet) {
uint32_t slot = subpass.depthStencilAttachment;
if (!TextureFormatHasDepthOrStencil(attachments[slot].format)) {
if (!TextureFormatHasDepthOrStencil(mAttachments[slot].format)) {
HandleError("Render pass depth/stencil attachment is not of a depth/stencil format");
return nullptr;
}
}
}
return device->CreateRenderPass(this);
return mDevice->CreateRenderPass(this);
}
void RenderPassBuilder::SetAttachmentCount(uint32_t attachmentCount) {
if ((propertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) != 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) != 0) {
HandleError("Render pass attachment count property set multiple times");
return;
}
attachmentProperties.resize(attachmentCount);
attachments.resize(attachmentCount);
propertiesSet |= RENDERPASS_PROPERTY_ATTACHMENT_COUNT;
mAttachmentProperties.resize(attachmentCount);
mAttachments.resize(attachmentCount);
mPropertiesSet |= RENDERPASS_PROPERTY_ATTACHMENT_COUNT;
}
void RenderPassBuilder::AttachmentSetFormat(uint32_t attachmentSlot, nxt::TextureFormat format) {
if ((propertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
HandleError("Render pass attachment count not set yet");
return;
}
if (attachmentSlot >= attachments.size()) {
if (attachmentSlot >= mAttachments.size()) {
HandleError("Render pass attachment slot out of bounds");
return;
}
if (attachmentProperties[attachmentSlot][ATTACHMENT_PROPERTY_FORMAT]) {
if (mAttachmentProperties[attachmentSlot][ATTACHMENT_PROPERTY_FORMAT]) {
HandleError("Render pass attachment format already set");
return;
}
attachments[attachmentSlot].format = format;
attachmentProperties[attachmentSlot].set(ATTACHMENT_PROPERTY_FORMAT);
mAttachments[attachmentSlot].format = format;
mAttachmentProperties[attachmentSlot].set(ATTACHMENT_PROPERTY_FORMAT);
}
void RenderPassBuilder::AttachmentSetColorLoadOp(uint32_t attachmentSlot, nxt::LoadOp op) {
if ((propertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
HandleError("Render pass attachment count not set yet");
return;
}
if (attachmentSlot >= attachments.size()) {
if (attachmentSlot >= mAttachments.size()) {
HandleError("Render pass attachment slot out of bounds");
return;
}
attachments[attachmentSlot].colorLoadOp = op;
mAttachments[attachmentSlot].colorLoadOp = op;
}
void RenderPassBuilder::AttachmentSetDepthStencilLoadOps(uint32_t attachmentSlot, nxt::LoadOp depthOp, nxt::LoadOp stencilOp) {
if ((propertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
HandleError("Render pass attachment count not set yet");
return;
}
if (attachmentSlot >= attachments.size()) {
if (attachmentSlot >= mAttachments.size()) {
HandleError("Render pass attachment slot out of bounds");
return;
}
attachments[attachmentSlot].depthLoadOp = depthOp;
attachments[attachmentSlot].stencilLoadOp = stencilOp;
mAttachments[attachmentSlot].depthLoadOp = depthOp;
mAttachments[attachmentSlot].stencilLoadOp = stencilOp;
}
void RenderPassBuilder::SetSubpassCount(uint32_t subpassCount) {
if ((propertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) != 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) != 0) {
HandleError("Render pass subpass count property set multiple times");
return;
}
@ -181,20 +181,20 @@ namespace backend {
return;
}
subpasses.resize(subpassCount);
propertiesSet |= RENDERPASS_PROPERTY_SUBPASS_COUNT;
mSubpasses.resize(subpassCount);
mPropertiesSet |= RENDERPASS_PROPERTY_SUBPASS_COUNT;
}
void RenderPassBuilder::SubpassSetColorAttachment(uint32_t subpass, uint32_t outputAttachmentLocation, uint32_t attachmentSlot) {
if ((propertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) == 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) == 0) {
HandleError("Render pass subpass count not set yet");
return;
}
if ((propertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
HandleError("Render pass attachment count not set yet");
return;
}
if (subpass >= subpasses.size()) {
if (subpass >= mSubpasses.size()) {
HandleError("Subpass index out of bounds");
return;
}
@ -202,43 +202,43 @@ namespace backend {
HandleError("Subpass output attachment location out of bounds");
return;
}
if (attachmentSlot >= attachments.size()) {
if (attachmentSlot >= mAttachments.size()) {
HandleError("Subpass attachment slot out of bounds");
return;
}
if (subpasses[subpass].colorAttachmentsSet[outputAttachmentLocation]) {
if (mSubpasses[subpass].colorAttachmentsSet[outputAttachmentLocation]) {
HandleError("Subpass color attachment already set");
return;
}
subpasses[subpass].colorAttachmentsSet.set(outputAttachmentLocation);
subpasses[subpass].colorAttachments[outputAttachmentLocation] = attachmentSlot;
mSubpasses[subpass].colorAttachmentsSet.set(outputAttachmentLocation);
mSubpasses[subpass].colorAttachments[outputAttachmentLocation] = attachmentSlot;
}
void RenderPassBuilder::SubpassSetDepthStencilAttachment(uint32_t subpass, uint32_t attachmentSlot) {
if ((propertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) == 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) == 0) {
HandleError("Render pass subpass count not set yet");
return;
}
if ((propertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
HandleError("Render pass attachment count not set yet");
return;
}
if (subpass >= subpasses.size()) {
if (subpass >= mSubpasses.size()) {
HandleError("Subpass index out of bounds");
return;
}
if (attachmentSlot >= attachments.size()) {
if (attachmentSlot >= mAttachments.size()) {
HandleError("Subpass attachment slot out of bounds");
return;
}
if (subpasses[subpass].depthStencilAttachmentSet) {
if (mSubpasses[subpass].depthStencilAttachmentSet) {
HandleError("Subpass depth-stencil attachment already set");
return;
}
subpasses[subpass].depthStencilAttachmentSet = true;
subpasses[subpass].depthStencilAttachment = attachmentSlot;
mSubpasses[subpass].depthStencilAttachmentSet = true;
mSubpasses[subpass].depthStencilAttachment = attachmentSlot;
}
}

View File

@ -59,8 +59,8 @@ namespace backend {
bool IsCompatibleWith(const RenderPassBase* other) const;
private:
std::vector<AttachmentInfo> attachments;
std::vector<SubpassInfo> subpasses;
std::vector<AttachmentInfo> mAttachments;
std::vector<SubpassInfo> mSubpasses;
};
class RenderPassBuilder : public Builder<RenderPassBase> {
@ -85,10 +85,10 @@ namespace backend {
ATTACHMENT_PROPERTY_COUNT
};
std::vector<std::bitset<ATTACHMENT_PROPERTY_COUNT>> attachmentProperties;
std::vector<RenderPassBase::AttachmentInfo> attachments;
std::vector<RenderPassBase::SubpassInfo> subpasses;
int propertiesSet = 0;
std::vector<std::bitset<ATTACHMENT_PROPERTY_COUNT>> mAttachmentProperties;
std::vector<RenderPassBase::AttachmentInfo> mAttachments;
std::vector<RenderPassBase::SubpassInfo> mSubpasses;
int mPropertiesSet = 0;
};
}

View File

@ -27,12 +27,12 @@ namespace backend {
RenderPipelineBase::RenderPipelineBase(RenderPipelineBuilder* builder)
: PipelineBase(builder),
depthStencilState(std::move(builder->depthStencilState)),
indexFormat(builder->indexFormat),
inputState(std::move(builder->inputState)),
primitiveTopology(builder->primitiveTopology),
blendStates(builder->blendStates),
renderPass(std::move(builder->renderPass)), subpass(builder->subpass) {
mDepthStencilState(std::move(builder->mDepthStencilState)),
mIndexFormat(builder->mIndexFormat),
mInputState(std::move(builder->mInputState)),
mPrimitiveTopology(builder->mPrimitiveTopology),
mBlendStates(builder->mBlendStates),
mRenderPass(std::move(builder->mRenderPass)), mSubpass(builder->mSubpass) {
if (GetStageMask() != (nxt::ShaderStageBit::Vertex | nxt::ShaderStageBit::Fragment)) {
builder->HandleError("Render pipeline should have exactly a vertex and fragment stage");
@ -41,39 +41,39 @@ namespace backend {
// TODO(kainino@chromium.org): Need to verify the pipeline against its render subpass.
if ((builder->GetStageInfo(nxt::ShaderStage::Vertex).module->GetUsedVertexAttributes() & ~inputState->GetAttributesSetMask()).any()) {
if ((builder->GetStageInfo(nxt::ShaderStage::Vertex).module->GetUsedVertexAttributes() & ~mInputState->GetAttributesSetMask()).any()) {
builder->HandleError("Pipeline vertex stage uses inputs not in the input state");
return;
}
}
BlendStateBase* RenderPipelineBase::GetBlendState(uint32_t attachmentSlot) {
ASSERT(attachmentSlot < blendStates.size());
return blendStates[attachmentSlot].Get();
ASSERT(attachmentSlot < mBlendStates.size());
return mBlendStates[attachmentSlot].Get();
}
DepthStencilStateBase* RenderPipelineBase::GetDepthStencilState() {
return depthStencilState.Get();
return mDepthStencilState.Get();
}
nxt::IndexFormat RenderPipelineBase::GetIndexFormat() const {
return indexFormat;
return mIndexFormat;
}
InputStateBase* RenderPipelineBase::GetInputState() {
return inputState.Get();
return mInputState.Get();
}
nxt::PrimitiveTopology RenderPipelineBase::GetPrimitiveTopology() const {
return primitiveTopology;
return mPrimitiveTopology;
}
RenderPassBase* RenderPipelineBase::GetRenderPass() {
return renderPass.Get();
return mRenderPass.Get();
}
uint32_t RenderPipelineBase::GetSubPass() {
return subpass;
return mSubpass;
}
// RenderPipelineBuilder
@ -84,64 +84,64 @@ namespace backend {
RenderPipelineBase* RenderPipelineBuilder::GetResultImpl() {
// TODO(cwallez@chromium.org): the layout should be required, and put the default objects in the device
if (!inputState) {
inputState = device->CreateInputStateBuilder()->GetResult();
if (!mInputState) {
mInputState = mDevice->CreateInputStateBuilder()->GetResult();
}
if (!depthStencilState) {
depthStencilState = device->CreateDepthStencilStateBuilder()->GetResult();
if (!mDepthStencilState) {
mDepthStencilState = mDevice->CreateDepthStencilStateBuilder()->GetResult();
}
if (!renderPass) {
if (!mRenderPass) {
HandleError("Pipeline render pass not set");
return nullptr;
}
const auto& subpassInfo = renderPass->GetSubpassInfo(subpass);
if ((blendStatesSet | subpassInfo.colorAttachmentsSet) != subpassInfo.colorAttachmentsSet) {
const auto& subpassInfo = mRenderPass->GetSubpassInfo(mSubpass);
if ((mBlendStatesSet | subpassInfo.colorAttachmentsSet) != subpassInfo.colorAttachmentsSet) {
HandleError("Blend state set on unset color attachment");
return nullptr;
}
// Assign all color attachments without a blend state the default state
// TODO(enga@google.com): Put the default objects in the device
for (uint32_t attachmentSlot : IterateBitSet(subpassInfo.colorAttachmentsSet & ~blendStatesSet)) {
blendStates[attachmentSlot] = device->CreateBlendStateBuilder()->GetResult();
for (uint32_t attachmentSlot : IterateBitSet(subpassInfo.colorAttachmentsSet & ~mBlendStatesSet)) {
mBlendStates[attachmentSlot] = mDevice->CreateBlendStateBuilder()->GetResult();
}
return device->CreateRenderPipeline(this);
return mDevice->CreateRenderPipeline(this);
}
void RenderPipelineBuilder::SetColorAttachmentBlendState(uint32_t attachmentSlot, BlendStateBase* blendState) {
if (attachmentSlot > blendStates.size()) {
if (attachmentSlot > mBlendStates.size()) {
HandleError("Attachment index out of bounds");
return;
}
if (blendStatesSet[attachmentSlot]) {
if (mBlendStatesSet[attachmentSlot]) {
HandleError("Attachment blend state already set");
return;
}
blendStatesSet.set(attachmentSlot);
blendStates[attachmentSlot] = blendState;
mBlendStatesSet.set(attachmentSlot);
mBlendStates[attachmentSlot] = blendState;
}
void RenderPipelineBuilder::SetDepthStencilState(DepthStencilStateBase* depthStencilState) {
this->depthStencilState = depthStencilState;
mDepthStencilState = depthStencilState;
}
void RenderPipelineBuilder::SetIndexFormat(nxt::IndexFormat format) {
this->indexFormat = format;
mIndexFormat = format;
}
void RenderPipelineBuilder::SetInputState(InputStateBase* inputState) {
this->inputState = inputState;
mInputState = inputState;
}
void RenderPipelineBuilder::SetPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology) {
this->primitiveTopology = primitiveTopology;
mPrimitiveTopology = primitiveTopology;
}
void RenderPipelineBuilder::SetSubpass(RenderPassBase* renderPass, uint32_t subpass) {
this->renderPass = renderPass;
this->subpass = subpass;
mRenderPass = renderPass;
mSubpass = subpass;
}
}

View File

@ -37,13 +37,13 @@ namespace backend {
uint32_t GetSubPass();
private:
Ref<DepthStencilStateBase> depthStencilState;
nxt::IndexFormat indexFormat;
Ref<InputStateBase> inputState;
nxt::PrimitiveTopology primitiveTopology;
std::array<Ref<BlendStateBase>, kMaxColorAttachments> blendStates;
Ref<RenderPassBase> renderPass;
uint32_t subpass;
Ref<DepthStencilStateBase> mDepthStencilState;
nxt::IndexFormat mIndexFormat;
Ref<InputStateBase> mInputState;
nxt::PrimitiveTopology mPrimitiveTopology;
std::array<Ref<BlendStateBase>, kMaxColorAttachments> mBlendStates;
Ref<RenderPassBase> mRenderPass;
uint32_t mSubpass;
};
class RenderPipelineBuilder : public Builder<RenderPipelineBase>, public PipelineBuilder {
@ -63,15 +63,15 @@ namespace backend {
RenderPipelineBase* GetResultImpl() override;
Ref<DepthStencilStateBase> depthStencilState;
Ref<InputStateBase> inputState;
Ref<DepthStencilStateBase> mDepthStencilState;
Ref<InputStateBase> mInputState;
// TODO(enga@google.com): Remove default when we validate that all required properties are set
nxt::PrimitiveTopology primitiveTopology = nxt::PrimitiveTopology::TriangleList;
nxt::IndexFormat indexFormat = nxt::IndexFormat::Uint32;
std::bitset<kMaxColorAttachments> blendStatesSet;
std::array<Ref<BlendStateBase>, kMaxColorAttachments> blendStates;
Ref<RenderPassBase> renderPass;
uint32_t subpass;
nxt::PrimitiveTopology mPrimitiveTopology = nxt::PrimitiveTopology::TriangleList;
nxt::IndexFormat mIndexFormat = nxt::IndexFormat::Uint32;
std::bitset<kMaxColorAttachments> mBlendStatesSet;
std::array<Ref<BlendStateBase>, kMaxColorAttachments> mBlendStates;
Ref<RenderPassBase> mRenderPass;
uint32_t mSubpass;
};
}

View File

@ -32,31 +32,31 @@ namespace backend {
}
nxt::FilterMode SamplerBuilder::GetMagFilter() const {
return magFilter;
return mMagFilter;
}
nxt::FilterMode SamplerBuilder::GetMinFilter() const {
return minFilter;
return mMinFilter;
}
nxt::FilterMode SamplerBuilder::GetMipMapFilter() const {
return mipMapFilter;
return mMipMapFilter;
}
void SamplerBuilder::SetFilterMode(nxt::FilterMode magFilter, nxt::FilterMode minFilter, nxt::FilterMode mipMapFilter) {
if ((propertiesSet & SAMPLER_PROPERTY_FILTER) != 0) {
if ((mPropertiesSet & SAMPLER_PROPERTY_FILTER) != 0) {
HandleError("Sampler filter property set multiple times");
return;
}
this->magFilter = magFilter;
this->minFilter = minFilter;
this->mipMapFilter = mipMapFilter;
propertiesSet |= SAMPLER_PROPERTY_FILTER;
mMagFilter = magFilter;
mMinFilter = minFilter;
mMipMapFilter = mipMapFilter;
mPropertiesSet |= SAMPLER_PROPERTY_FILTER;
}
SamplerBase* SamplerBuilder::GetResultImpl() {
return device->CreateSampler(this);
return mDevice->CreateSampler(this);
}
}

View File

@ -44,11 +44,11 @@ namespace backend {
SamplerBase* GetResultImpl() override;
int propertiesSet = 0;
int mPropertiesSet = 0;
nxt::FilterMode magFilter = nxt::FilterMode::Nearest;
nxt::FilterMode minFilter = nxt::FilterMode::Nearest;
nxt::FilterMode mipMapFilter = nxt::FilterMode::Nearest;
nxt::FilterMode mMagFilter = nxt::FilterMode::Nearest;
nxt::FilterMode mMinFilter = nxt::FilterMode::Nearest;
nxt::FilterMode mMipMapFilter = nxt::FilterMode::Nearest;
};
}

View File

@ -24,11 +24,11 @@
namespace backend {
ShaderModuleBase::ShaderModuleBase(ShaderModuleBuilder* builder)
: device(builder->device) {
: mDevice(builder->mDevice) {
}
DeviceBase* ShaderModuleBase::GetDevice() const {
return device;
return mDevice;
}
void ShaderModuleBase::ExtractSpirvInfo(const spirv_cross::Compiler& compiler) {
@ -38,22 +38,22 @@ namespace backend {
switch (compiler.get_execution_model()) {
case spv::ExecutionModelVertex:
executionModel = nxt::ShaderStage::Vertex;
mExecutionModel = nxt::ShaderStage::Vertex;
break;
case spv::ExecutionModelFragment:
executionModel = nxt::ShaderStage::Fragment;
mExecutionModel = nxt::ShaderStage::Fragment;
break;
case spv::ExecutionModelGLCompute:
executionModel = nxt::ShaderStage::Compute;
mExecutionModel = nxt::ShaderStage::Compute;
break;
default:
UNREACHABLE();
}
// Extract push constants
pushConstants.mask.reset();
pushConstants.sizes.fill(0);
pushConstants.types.fill(PushConstantType::Int);
mPushConstants.mask.reset();
mPushConstants.sizes.fill(0);
mPushConstants.types.fill(PushConstantType::Int);
if (resources.push_constant_buffers.size() > 0) {
auto interfaceBlock = resources.push_constant_buffers[0];
@ -87,14 +87,14 @@ namespace backend {
}
if (offset + size > kMaxPushConstants) {
device->HandleError("Push constant block too big in the SPIRV");
mDevice->HandleError("Push constant block too big in the SPIRV");
return;
}
pushConstants.mask.set(offset);
pushConstants.names[offset] = interfaceBlock.name + "." + compiler.get_member_name(blockType.self, i);
pushConstants.sizes[offset] = size;
pushConstants.types[offset] = constantType;
mPushConstants.mask.set(offset);
mPushConstants.names[offset] = interfaceBlock.name + "." + compiler.get_member_name(blockType.self, i);
mPushConstants.sizes[offset] = size;
mPushConstants.types[offset] = constantType;
}
}
@ -109,11 +109,11 @@ namespace backend {
uint32_t set = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet);
if (binding >= kMaxBindingsPerGroup || set >= kMaxBindGroups) {
device->HandleError("Binding over limits in the SPIRV");
mDevice->HandleError("Binding over limits in the SPIRV");
continue;
}
auto& info = bindingInfo[set][binding];
auto& info = mBindingInfo[set][binding];
info.used = true;
info.id = resource.id;
info.base_type_id = resource.base_type_id;
@ -127,35 +127,35 @@ namespace backend {
ExtractResourcesBinding(resources.storage_buffers, compiler, nxt::BindingType::StorageBuffer);
// Extract the vertex attributes
if (executionModel == nxt::ShaderStage::Vertex) {
if (mExecutionModel == nxt::ShaderStage::Vertex) {
for (const auto& attrib : resources.stage_inputs) {
ASSERT(compiler.get_decoration_mask(attrib.id) & (1ull << spv::DecorationLocation));
uint32_t location = compiler.get_decoration(attrib.id, spv::DecorationLocation);
if (location >= kMaxVertexAttributes) {
device->HandleError("Attribute location over limits in the SPIRV");
mDevice->HandleError("Attribute location over limits in the SPIRV");
return;
}
usedVertexAttributes.set(location);
mUsedVertexAttributes.set(location);
}
// Without a location qualifier on vertex outputs, spirv_cross::CompilerMSL gives them all
// the location 0, causing a compile error.
for (const auto& attrib : resources.stage_outputs) {
if (!(compiler.get_decoration_mask(attrib.id) & (1ull << spv::DecorationLocation))) {
device->HandleError("Need location qualifier on vertex output");
mDevice->HandleError("Need location qualifier on vertex output");
return;
}
}
}
if (executionModel == nxt::ShaderStage::Fragment) {
if (mExecutionModel == nxt::ShaderStage::Fragment) {
// Without a location qualifier on vertex inputs, spirv_cross::CompilerMSL gives them all
// the location 0, causing a compile error.
for (const auto& attrib : resources.stage_inputs) {
if (!(compiler.get_decoration_mask(attrib.id) & (1ull << spv::DecorationLocation))) {
device->HandleError("Need location qualifier on fragment input");
mDevice->HandleError("Need location qualifier on fragment input");
return;
}
}
@ -163,19 +163,19 @@ namespace backend {
}
const ShaderModuleBase::PushConstantInfo& ShaderModuleBase::GetPushConstants() const {
return pushConstants;
return mPushConstants;
}
const ShaderModuleBase::ModuleBindingInfo& ShaderModuleBase::GetBindingInfo() const {
return bindingInfo;
return mBindingInfo;
}
const std::bitset<kMaxVertexAttributes>& ShaderModuleBase::GetUsedVertexAttributes() const {
return usedVertexAttributes;
return mUsedVertexAttributes;
}
nxt::ShaderStage ShaderModuleBase::GetExecutionModel() const {
return executionModel;
return mExecutionModel;
}
bool ShaderModuleBase::IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout) {
@ -190,7 +190,7 @@ namespace backend {
bool ShaderModuleBase::IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout) {
const auto& layoutInfo = layout->GetBindingInfo();
for (size_t i = 0; i < kMaxBindingsPerGroup; ++i) {
const auto& moduleInfo = bindingInfo[group][i];
const auto& moduleInfo = mBindingInfo[group][i];
if (!moduleInfo.used) {
continue;
@ -199,7 +199,7 @@ namespace backend {
if (moduleInfo.type != layoutInfo.types[i]) {
return false;
}
if ((layoutInfo.visibilities[i] & StageBit(executionModel)) == 0) {
if ((layoutInfo.visibilities[i] & StageBit(mExecutionModel)) == 0) {
return false;
}
}
@ -211,20 +211,20 @@ namespace backend {
}
std::vector<uint32_t> ShaderModuleBuilder::AcquireSpirv() {
return std::move(spirv);
return std::move(mSpirv);
}
ShaderModuleBase* ShaderModuleBuilder::GetResultImpl() {
if (spirv.size() == 0) {
if (mSpirv.size() == 0) {
HandleError("Shader module needs to have the source set");
return nullptr;
}
return device->CreateShaderModule(this);
return mDevice->CreateShaderModule(this);
}
void ShaderModuleBuilder::SetSource(uint32_t codeSize, const uint32_t* code) {
spirv.assign(code, code + codeSize);
mSpirv.assign(code, code + codeSize);
}
}

View File

@ -67,11 +67,11 @@ namespace backend {
private:
bool IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout);
DeviceBase* device;
PushConstantInfo pushConstants = {};
ModuleBindingInfo bindingInfo;
std::bitset<kMaxVertexAttributes> usedVertexAttributes;
nxt::ShaderStage executionModel;
DeviceBase* mDevice;
PushConstantInfo mPushConstants = {};
ModuleBindingInfo mBindingInfo;
std::bitset<kMaxVertexAttributes> mUsedVertexAttributes;
nxt::ShaderStage mExecutionModel;
};
class ShaderModuleBuilder : public Builder<ShaderModuleBase> {
@ -88,7 +88,7 @@ namespace backend {
ShaderModuleBase* GetResultImpl() override;
std::vector<uint32_t> spirv;
std::vector<uint32_t> mSpirv;
};
}

View File

@ -22,7 +22,7 @@ namespace backend {
// SwapChain
SwapChainBase::SwapChainBase(SwapChainBuilder* builder)
: device(builder->device), implementation(builder->implementation) {
: mDevice(builder->mDevice), mImplementation(builder->mImplementation) {
}
SwapChainBase::~SwapChainBase() {
@ -31,58 +31,58 @@ namespace backend {
}
DeviceBase* SwapChainBase::GetDevice() {
return device;
return mDevice;
}
void SwapChainBase::Configure(nxt::TextureFormat format, nxt::TextureUsageBit allowedUsage, uint32_t width, uint32_t height) {
if (width == 0 || height == 0) {
device->HandleError("Swap chain cannot be configured to zero size");
mDevice->HandleError("Swap chain cannot be configured to zero size");
return;
}
allowedUsage |= nxt::TextureUsageBit::Present;
this->format = format;
this->allowedUsage = allowedUsage;
this->width = width;
this->height = height;
implementation.Configure(implementation.userData,
mFormat = format;
mAllowedUsage = allowedUsage;
mWidth = width;
mHeight = height;
mImplementation.Configure(mImplementation.userData,
static_cast<nxtTextureFormat>(format), static_cast<nxtTextureUsageBit>(allowedUsage), width, height);
}
TextureBase* SwapChainBase::GetNextTexture() {
if (width == 0) {
if (mWidth == 0) {
// If width is 0, it implies swap chain has never been configured
device->HandleError("Swap chain needs to be configured before GetNextTexture");
mDevice->HandleError("Swap chain needs to be configured before GetNextTexture");
return nullptr;
}
auto* builder = device->CreateTextureBuilder();
auto* builder = mDevice->CreateTextureBuilder();
builder->SetDimension(nxt::TextureDimension::e2D);
builder->SetExtent(width, height, 1);
builder->SetFormat(format);
builder->SetExtent(mWidth, mHeight, 1);
builder->SetFormat(mFormat);
builder->SetMipLevels(1);
builder->SetAllowedUsage(allowedUsage);
builder->SetAllowedUsage(mAllowedUsage);
auto* texture = GetNextTextureImpl(builder);
lastNextTexture = texture;
mLastNextTexture = texture;
return texture;
}
void SwapChainBase::Present(TextureBase* texture) {
if (texture != lastNextTexture) {
device->HandleError("Tried to present something other than the last NextTexture");
if (texture != mLastNextTexture) {
mDevice->HandleError("Tried to present something other than the last NextTexture");
return;
}
if (texture->GetUsage() != nxt::TextureUsageBit::Present) {
device->HandleError("Texture has not been transitioned to the Present usage");
mDevice->HandleError("Texture has not been transitioned to the Present usage");
return;
}
implementation.Present(implementation.userData);
mImplementation.Present(mImplementation.userData);
}
const nxtSwapChainImplementation& SwapChainBase::GetImplementation() {
return implementation;
return mImplementation;
}
// SwapChain Builder
@ -92,11 +92,11 @@ namespace backend {
}
SwapChainBase* SwapChainBuilder::GetResultImpl() {
if (!implementation.Init) {
if (!mImplementation.Init) {
HandleError("Implementation not set");
return nullptr;
}
return device->CreateSwapChain(this);
return mDevice->CreateSwapChain(this);
}
void SwapChainBuilder::SetImplementation(uint64_t implementation) {
@ -113,6 +113,6 @@ namespace backend {
return;
}
this->implementation = impl;
mImplementation = impl;
}
}

View File

@ -41,13 +41,13 @@ namespace backend {
virtual TextureBase* GetNextTextureImpl(TextureBuilder* builder) = 0;
private:
DeviceBase* device = nullptr;
nxtSwapChainImplementation implementation = {};
nxt::TextureFormat format = {};
nxt::TextureUsageBit allowedUsage;
uint32_t width = 0;
uint32_t height = 0;
TextureBase* lastNextTexture = nullptr;
DeviceBase* mDevice = nullptr;
nxtSwapChainImplementation mImplementation = {};
nxt::TextureFormat mFormat = {};
nxt::TextureUsageBit mAllowedUsage;
uint32_t mWidth = 0;
uint32_t mHeight = 0;
TextureBase* mLastNextTexture = nullptr;
};
class SwapChainBuilder : public Builder<SwapChainBase> {
@ -61,7 +61,7 @@ namespace backend {
private:
friend class SwapChainBase;
nxtSwapChainImplementation implementation = {};
nxtSwapChainImplementation mImplementation = {};
};
}

View File

@ -75,50 +75,50 @@ namespace backend {
// TextureBase
TextureBase::TextureBase(TextureBuilder* builder)
: device(builder->device), dimension(builder->dimension), format(builder->format), width(builder->width),
height(builder->height), depth(builder->depth), numMipLevels(builder->numMipLevels),
allowedUsage(builder->allowedUsage), currentUsage(builder->currentUsage) {
: mDevice(builder->mDevice), mDimension(builder->mDimension), mFormat(builder->mFormat), mWidth(builder->mWidth),
mHeight(builder->mHeight), mDepth(builder->mDepth), mNumMipLevels(builder->mNumMipLevels),
mAllowedUsage(builder->mAllowedUsage), mCurrentUsage(builder->mCurrentUsage) {
}
DeviceBase* TextureBase::GetDevice() {
return device;
return mDevice;
}
nxt::TextureDimension TextureBase::GetDimension() const {
return dimension;
return mDimension;
}
nxt::TextureFormat TextureBase::GetFormat() const {
return format;
return mFormat;
}
uint32_t TextureBase::GetWidth() const {
return width;
return mWidth;
}
uint32_t TextureBase::GetHeight() const {
return height;
return mHeight;
}
uint32_t TextureBase::GetDepth() const {
return depth;
return mDepth;
}
uint32_t TextureBase::GetNumMipLevels() const {
return numMipLevels;
return mNumMipLevels;
}
nxt::TextureUsageBit TextureBase::GetAllowedUsage() const {
return allowedUsage;
return mAllowedUsage;
}
nxt::TextureUsageBit TextureBase::GetUsage() const {
return currentUsage;
return mCurrentUsage;
}
TextureViewBuilder* TextureBase::CreateTextureViewBuilder() {
return new TextureViewBuilder(device, this);
return new TextureViewBuilder(mDevice, this);
}
bool TextureBase::IsFrozen() const {
return frozen;
return mIsFrozen;
}
bool TextureBase::HasFrozenUsage(nxt::TextureUsageBit usage) const {
return frozen && (usage & allowedUsage);
return mIsFrozen && (usage & mAllowedUsage);
}
bool TextureBase::IsUsagePossible(nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit usage) {
@ -128,38 +128,38 @@ namespace backend {
}
bool TextureBase::IsTransitionPossible(nxt::TextureUsageBit usage) const {
if (frozen) {
if (mIsFrozen) {
return false;
}
if (currentUsage == nxt::TextureUsageBit::Present) {
if (mCurrentUsage == nxt::TextureUsageBit::Present) {
return false;
}
return IsUsagePossible(allowedUsage, usage);
return IsUsagePossible(mAllowedUsage, usage);
}
void TextureBase::UpdateUsageInternal(nxt::TextureUsageBit usage) {
ASSERT(IsTransitionPossible(usage));
currentUsage = usage;
mCurrentUsage = usage;
}
void TextureBase::TransitionUsage(nxt::TextureUsageBit usage) {
if (!IsTransitionPossible(usage)) {
device->HandleError("Texture frozen or usage not allowed");
mDevice->HandleError("Texture frozen or usage not allowed");
return;
}
TransitionUsageImpl(currentUsage, usage);
TransitionUsageImpl(mCurrentUsage, usage);
UpdateUsageInternal(usage);
}
void TextureBase::FreezeUsage(nxt::TextureUsageBit usage) {
if (!IsTransitionPossible(usage)) {
device->HandleError("Texture frozen or usage not allowed");
mDevice->HandleError("Texture frozen or usage not allowed");
return;
}
allowedUsage = usage;
TransitionUsageImpl(currentUsage, usage);
mAllowedUsage = usage;
TransitionUsageImpl(mCurrentUsage, usage);
UpdateUsageInternal(usage);
frozen = true;
mIsFrozen = true;
}
// TextureBuilder
@ -180,33 +180,33 @@ namespace backend {
TextureBase* TextureBuilder::GetResultImpl() {
constexpr int allProperties = TEXTURE_PROPERTY_DIMENSION | TEXTURE_PROPERTY_EXTENT |
TEXTURE_PROPERTY_FORMAT | TEXTURE_PROPERTY_MIP_LEVELS | TEXTURE_PROPERTY_ALLOWED_USAGE;
if ((propertiesSet & allProperties) != allProperties) {
if ((mPropertiesSet & allProperties) != allProperties) {
HandleError("Texture missing properties");
return nullptr;
}
if (!TextureBase::IsUsagePossible(allowedUsage, currentUsage)) {
if (!TextureBase::IsUsagePossible(mAllowedUsage, mCurrentUsage)) {
HandleError("Initial texture usage is not allowed");
return nullptr;
}
// TODO(cwallez@chromium.org): check stuff based on the dimension
return device->CreateTexture(this);
return mDevice->CreateTexture(this);
}
void TextureBuilder::SetDimension(nxt::TextureDimension dimension) {
if ((propertiesSet & TEXTURE_PROPERTY_DIMENSION) != 0) {
if ((mPropertiesSet & TEXTURE_PROPERTY_DIMENSION) != 0) {
HandleError("Texture dimension property set multiple times");
return;
}
propertiesSet |= TEXTURE_PROPERTY_DIMENSION;
this->dimension = dimension;
mPropertiesSet |= TEXTURE_PROPERTY_DIMENSION;
mDimension = dimension;
}
void TextureBuilder::SetExtent(uint32_t width, uint32_t height, uint32_t depth) {
if ((propertiesSet & TEXTURE_PROPERTY_EXTENT) != 0) {
if ((mPropertiesSet & TEXTURE_PROPERTY_EXTENT) != 0) {
HandleError("Texture extent property set multiple times");
return;
}
@ -216,70 +216,70 @@ namespace backend {
return;
}
propertiesSet |= TEXTURE_PROPERTY_EXTENT;
this->width = width;
this->height = height;
this->depth = depth;
mPropertiesSet |= TEXTURE_PROPERTY_EXTENT;
mWidth = width;
mHeight = height;
mDepth = depth;
}
void TextureBuilder::SetFormat(nxt::TextureFormat format) {
if ((propertiesSet & TEXTURE_PROPERTY_FORMAT) != 0) {
if ((mPropertiesSet & TEXTURE_PROPERTY_FORMAT) != 0) {
HandleError("Texture format property set multiple times");
return;
}
propertiesSet |= TEXTURE_PROPERTY_FORMAT;
this->format = format;
mPropertiesSet |= TEXTURE_PROPERTY_FORMAT;
mFormat = format;
}
void TextureBuilder::SetMipLevels(uint32_t numMipLevels) {
if ((propertiesSet & TEXTURE_PROPERTY_MIP_LEVELS) != 0) {
if ((mPropertiesSet & TEXTURE_PROPERTY_MIP_LEVELS) != 0) {
HandleError("Texture mip levels property set multiple times");
return;
}
propertiesSet |= TEXTURE_PROPERTY_MIP_LEVELS;
this->numMipLevels = numMipLevels;
mPropertiesSet |= TEXTURE_PROPERTY_MIP_LEVELS;
mNumMipLevels = numMipLevels;
}
void TextureBuilder::SetAllowedUsage(nxt::TextureUsageBit usage) {
if ((propertiesSet & TEXTURE_PROPERTY_ALLOWED_USAGE) != 0) {
if ((mPropertiesSet & TEXTURE_PROPERTY_ALLOWED_USAGE) != 0) {
HandleError("Texture allowed usage property set multiple times");
return;
}
propertiesSet |= TEXTURE_PROPERTY_ALLOWED_USAGE;
this->allowedUsage = usage;
mPropertiesSet |= TEXTURE_PROPERTY_ALLOWED_USAGE;
mAllowedUsage = usage;
}
void TextureBuilder::SetInitialUsage(nxt::TextureUsageBit usage) {
if ((propertiesSet & TEXTURE_PROPERTY_INITIAL_USAGE) != 0) {
if ((mPropertiesSet & TEXTURE_PROPERTY_INITIAL_USAGE) != 0) {
HandleError("Texture initial usage property set multiple times");
return;
}
propertiesSet |= TEXTURE_PROPERTY_INITIAL_USAGE;
this->currentUsage = usage;
mPropertiesSet |= TEXTURE_PROPERTY_INITIAL_USAGE;
mCurrentUsage = usage;
}
// TextureViewBase
TextureViewBase::TextureViewBase(TextureViewBuilder* builder)
: texture(builder->texture) {
: mTexture(builder->mTexture) {
}
TextureBase* TextureViewBase::GetTexture() {
return texture.Get();
return mTexture.Get();
}
// TextureViewBuilder
TextureViewBuilder::TextureViewBuilder(DeviceBase* device, TextureBase* texture)
: Builder(device), texture(texture) {
: Builder(device), mTexture(texture) {
}
TextureViewBase* TextureViewBuilder::GetResultImpl() {
return device->CreateTextureView(this);
return mDevice->CreateTextureView(this);
}
}

View File

@ -56,15 +56,15 @@ namespace backend {
virtual void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) = 0;
private:
DeviceBase* device;
DeviceBase* mDevice;
nxt::TextureDimension dimension;
nxt::TextureFormat format;
uint32_t width, height, depth;
uint32_t numMipLevels;
nxt::TextureUsageBit allowedUsage = nxt::TextureUsageBit::None;
nxt::TextureUsageBit currentUsage = nxt::TextureUsageBit::None;
bool frozen = false;
nxt::TextureDimension mDimension;
nxt::TextureFormat mFormat;
uint32_t mWidth, mHeight, mDepth;
uint32_t mNumMipLevels;
nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None;
nxt::TextureUsageBit mCurrentUsage = nxt::TextureUsageBit::None;
bool mIsFrozen = false;
};
class TextureBuilder : public Builder<TextureBase> {
@ -84,14 +84,14 @@ namespace backend {
TextureBase* GetResultImpl() override;
int propertiesSet = 0;
int mPropertiesSet = 0;
nxt::TextureDimension dimension;
uint32_t width, height, depth;
nxt::TextureFormat format;
uint32_t numMipLevels;
nxt::TextureUsageBit allowedUsage = nxt::TextureUsageBit::None;
nxt::TextureUsageBit currentUsage = nxt::TextureUsageBit::None;
nxt::TextureDimension mDimension;
uint32_t mWidth, mHeight, mDepth;
nxt::TextureFormat mFormat;
uint32_t mNumMipLevels;
nxt::TextureUsageBit mAllowedUsage = nxt::TextureUsageBit::None;
nxt::TextureUsageBit mCurrentUsage = nxt::TextureUsageBit::None;
};
class TextureViewBase : public RefCounted {
@ -101,7 +101,7 @@ namespace backend {
TextureBase* GetTexture();
private:
Ref<TextureBase> texture;
Ref<TextureBase> mTexture;
};
class TextureViewBuilder : public Builder<TextureViewBase> {
@ -113,7 +113,7 @@ namespace backend {
TextureViewBase* GetResultImpl() override;
Ref<TextureBase> texture;
Ref<TextureBase> mTexture;
};
}