mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-13 08:36:08 +00:00
Format: src/backend
This commit is contained in:
parent
9d01c6c26d
commit
c1400f0d14
@ -26,7 +26,9 @@ namespace backend {
|
||||
// BindGroup
|
||||
|
||||
BindGroupBase::BindGroupBase(BindGroupBuilder* builder)
|
||||
: mLayout(std::move(builder->mLayout)), mUsage(builder->mUsage), mBindings(std::move(builder->mBindings)) {
|
||||
: mLayout(std::move(builder->mLayout)),
|
||||
mUsage(builder->mUsage),
|
||||
mBindings(std::move(builder->mBindings)) {
|
||||
}
|
||||
|
||||
const BindGroupLayoutBase* BindGroupBase::GetLayout() const {
|
||||
@ -41,7 +43,7 @@ namespace backend {
|
||||
ASSERT(binding < kMaxBindingsPerGroup);
|
||||
ASSERT(mLayout->GetBindingInfo().mask[binding]);
|
||||
ASSERT(mLayout->GetBindingInfo().types[binding] == nxt::BindingType::UniformBuffer ||
|
||||
mLayout->GetBindingInfo().types[binding] == nxt::BindingType::StorageBuffer);
|
||||
mLayout->GetBindingInfo().types[binding] == nxt::BindingType::StorageBuffer);
|
||||
return reinterpret_cast<BufferViewBase*>(mBindings[binding].Get());
|
||||
}
|
||||
|
||||
@ -104,7 +106,9 @@ namespace backend {
|
||||
mPropertiesSet |= BINDGROUP_PROPERTY_USAGE;
|
||||
}
|
||||
|
||||
void BindGroupBuilder::SetBufferViews(uint32_t start, uint32_t count, BufferViewBase* const * bufferViews) {
|
||||
void BindGroupBuilder::SetBufferViews(uint32_t start,
|
||||
uint32_t count,
|
||||
BufferViewBase* const* bufferViews) {
|
||||
if (!SetBindingsValidationBase(start, count)) {
|
||||
return;
|
||||
}
|
||||
@ -138,10 +142,12 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const *>(bufferViews));
|
||||
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const*>(bufferViews));
|
||||
}
|
||||
|
||||
void BindGroupBuilder::SetSamplers(uint32_t start, uint32_t count, SamplerBase* const * samplers) {
|
||||
void BindGroupBuilder::SetSamplers(uint32_t start,
|
||||
uint32_t count,
|
||||
SamplerBase* const* samplers) {
|
||||
if (!SetBindingsValidationBase(start, count)) {
|
||||
return;
|
||||
}
|
||||
@ -154,10 +160,12 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const *>(samplers));
|
||||
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const*>(samplers));
|
||||
}
|
||||
|
||||
void BindGroupBuilder::SetTextureViews(uint32_t start, uint32_t count, TextureViewBase* const * textureViews) {
|
||||
void BindGroupBuilder::SetTextureViews(uint32_t start,
|
||||
uint32_t count,
|
||||
TextureViewBase* const* textureViews) {
|
||||
if (!SetBindingsValidationBase(start, count)) {
|
||||
return;
|
||||
}
|
||||
@ -169,16 +177,19 @@ namespace backend {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(textureViews[j]->GetTexture()->GetAllowedUsage() & nxt::TextureUsageBit::Sampled)) {
|
||||
if (!(textureViews[j]->GetTexture()->GetAllowedUsage() &
|
||||
nxt::TextureUsageBit::Sampled)) {
|
||||
HandleError("Texture needs to allow the sampled usage bit");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const *>(textureViews));
|
||||
SetBindingsBase(start, count, reinterpret_cast<RefCounted* const*>(textureViews));
|
||||
}
|
||||
|
||||
void BindGroupBuilder::SetBindingsBase(uint32_t start, uint32_t count, RefCounted* const * objects) {
|
||||
void BindGroupBuilder::SetBindingsBase(uint32_t start,
|
||||
uint32_t count,
|
||||
RefCounted* const* objects) {
|
||||
for (size_t i = start, j = 0; i < start + count; ++i, ++j) {
|
||||
mSetMask.set(i);
|
||||
mBindings[i] = objects[j];
|
||||
@ -211,4 +222,4 @@ namespace backend {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -29,65 +29,65 @@
|
||||
namespace backend {
|
||||
|
||||
class BindGroupBase : public RefCounted {
|
||||
public:
|
||||
BindGroupBase(BindGroupBuilder* builder);
|
||||
public:
|
||||
BindGroupBase(BindGroupBuilder* builder);
|
||||
|
||||
const BindGroupLayoutBase* GetLayout() const;
|
||||
nxt::BindGroupUsage GetUsage() const;
|
||||
BufferViewBase* GetBindingAsBufferView(size_t binding);
|
||||
SamplerBase* GetBindingAsSampler(size_t binding);
|
||||
TextureViewBase* GetBindingAsTextureView(size_t binding);
|
||||
const BindGroupLayoutBase* GetLayout() const;
|
||||
nxt::BindGroupUsage GetUsage() const;
|
||||
BufferViewBase* GetBindingAsBufferView(size_t binding);
|
||||
SamplerBase* GetBindingAsSampler(size_t binding);
|
||||
TextureViewBase* GetBindingAsTextureView(size_t binding);
|
||||
|
||||
private:
|
||||
Ref<BindGroupLayoutBase> mLayout;
|
||||
nxt::BindGroupUsage mUsage;
|
||||
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
|
||||
private:
|
||||
Ref<BindGroupLayoutBase> mLayout;
|
||||
nxt::BindGroupUsage mUsage;
|
||||
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
|
||||
};
|
||||
|
||||
class BindGroupBuilder : public Builder<BindGroupBase> {
|
||||
public:
|
||||
BindGroupBuilder(DeviceBase* device);
|
||||
public:
|
||||
BindGroupBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetLayout(BindGroupLayoutBase* layout);
|
||||
void SetUsage(nxt::BindGroupUsage usage);
|
||||
// NXT API
|
||||
void SetLayout(BindGroupLayoutBase* layout);
|
||||
void SetUsage(nxt::BindGroupUsage usage);
|
||||
|
||||
template<typename T>
|
||||
void SetBufferViews(uint32_t start, uint32_t count, T* const* bufferViews) {
|
||||
static_assert(std::is_base_of<BufferViewBase, T>::value, "");
|
||||
SetBufferViews(start, count, reinterpret_cast<BufferViewBase* const*>(bufferViews));
|
||||
}
|
||||
void SetBufferViews(uint32_t start, uint32_t count, BufferViewBase* const * bufferViews);
|
||||
template <typename T>
|
||||
void SetBufferViews(uint32_t start, uint32_t count, T* const* bufferViews) {
|
||||
static_assert(std::is_base_of<BufferViewBase, T>::value, "");
|
||||
SetBufferViews(start, count, reinterpret_cast<BufferViewBase* const*>(bufferViews));
|
||||
}
|
||||
void SetBufferViews(uint32_t start, uint32_t count, BufferViewBase* const* bufferViews);
|
||||
|
||||
template<typename T>
|
||||
void SetSamplers(uint32_t start, uint32_t count, T* const* samplers) {
|
||||
static_assert(std::is_base_of<SamplerBase, T>::value, "");
|
||||
SetSamplers(start, count, reinterpret_cast<SamplerBase* const*>(samplers));
|
||||
}
|
||||
void SetSamplers(uint32_t start, uint32_t count, SamplerBase* const * samplers);
|
||||
template <typename T>
|
||||
void SetSamplers(uint32_t start, uint32_t count, T* const* samplers) {
|
||||
static_assert(std::is_base_of<SamplerBase, T>::value, "");
|
||||
SetSamplers(start, count, reinterpret_cast<SamplerBase* const*>(samplers));
|
||||
}
|
||||
void SetSamplers(uint32_t start, uint32_t count, SamplerBase* const* samplers);
|
||||
|
||||
template<typename T>
|
||||
void SetTextureViews(uint32_t start, uint32_t count, T* const* textureViews) {
|
||||
static_assert(std::is_base_of<TextureViewBase, T>::value, "");
|
||||
SetTextureViews(start, count, reinterpret_cast<TextureViewBase* const*>(textureViews));
|
||||
}
|
||||
void SetTextureViews(uint32_t start, uint32_t count, TextureViewBase* const * textureViews);
|
||||
template <typename T>
|
||||
void SetTextureViews(uint32_t start, uint32_t count, T* const* textureViews) {
|
||||
static_assert(std::is_base_of<TextureViewBase, T>::value, "");
|
||||
SetTextureViews(start, count, reinterpret_cast<TextureViewBase* const*>(textureViews));
|
||||
}
|
||||
void SetTextureViews(uint32_t start, uint32_t count, TextureViewBase* const* textureViews);
|
||||
|
||||
private:
|
||||
friend class BindGroupBase;
|
||||
private:
|
||||
friend class BindGroupBase;
|
||||
|
||||
BindGroupBase* GetResultImpl() override;
|
||||
void SetBindingsBase(uint32_t start, uint32_t count, RefCounted* const * objects);
|
||||
bool SetBindingsValidationBase(uint32_t start, uint32_t count);
|
||||
BindGroupBase* GetResultImpl() override;
|
||||
void SetBindingsBase(uint32_t start, uint32_t count, RefCounted* const* objects);
|
||||
bool SetBindingsValidationBase(uint32_t start, uint32_t count);
|
||||
|
||||
std::bitset<kMaxBindingsPerGroup> mSetMask;
|
||||
int mPropertiesSet = 0;
|
||||
std::bitset<kMaxBindingsPerGroup> mSetMask;
|
||||
int mPropertiesSet = 0;
|
||||
|
||||
Ref<BindGroupLayoutBase> mLayout;
|
||||
nxt::BindGroupUsage mUsage;
|
||||
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
|
||||
Ref<BindGroupLayoutBase> mLayout;
|
||||
nxt::BindGroupUsage mUsage;
|
||||
std::array<Ref<RefCounted>, kMaxBindingsPerGroup> mBindings;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_BINDGROUP_H_
|
||||
#endif // BACKEND_BINDGROUP_H_
|
||||
|
@ -23,13 +23,13 @@ namespace backend {
|
||||
namespace {
|
||||
|
||||
// Workaround for Chrome's stdlib having a broken std::hash for enums and bitsets
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_enum<T>::value, size_t>::type Hash(T value) {
|
||||
using Integral = typename nxt::UnderlyingType<T>::type;
|
||||
return std::hash<Integral>()(static_cast<Integral>(value));
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
template <size_t N>
|
||||
size_t Hash(const std::bitset<N>& value) {
|
||||
static_assert(N <= sizeof(unsigned long long) * 8, "");
|
||||
return std::hash<unsigned long long>()(value.to_ullong());
|
||||
@ -54,7 +54,8 @@ namespace backend {
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool operator== (const BindGroupLayoutBase::LayoutBindingInfo& a, const BindGroupLayoutBase::LayoutBindingInfo& b) {
|
||||
bool operator==(const BindGroupLayoutBase::LayoutBindingInfo& a,
|
||||
const BindGroupLayoutBase::LayoutBindingInfo& b) {
|
||||
if (a.mask != b.mask) {
|
||||
return false;
|
||||
}
|
||||
@ -72,7 +73,7 @@ namespace backend {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// BindGroupLayoutBase
|
||||
|
||||
@ -108,7 +109,10 @@ namespace backend {
|
||||
return result;
|
||||
}
|
||||
|
||||
void BindGroupLayoutBuilder::SetBindingsType(nxt::ShaderStageBit visibility, nxt::BindingType bindingType, uint32_t start, uint32_t count) {
|
||||
void BindGroupLayoutBuilder::SetBindingsType(nxt::ShaderStageBit visibility,
|
||||
nxt::BindingType bindingType,
|
||||
uint32_t start,
|
||||
uint32_t count) {
|
||||
if (start + count > kMaxBindingsPerGroup) {
|
||||
HandleError("Setting bindings type over maximum number of bindings");
|
||||
return;
|
||||
@ -129,12 +133,13 @@ namespace backend {
|
||||
|
||||
// BindGroupLayoutCacheFuncs
|
||||
|
||||
size_t BindGroupLayoutCacheFuncs::operator() (const BindGroupLayoutBase* bgl) const {
|
||||
size_t BindGroupLayoutCacheFuncs::operator()(const BindGroupLayoutBase* bgl) const {
|
||||
return HashBindingInfo(bgl->GetBindingInfo());
|
||||
}
|
||||
|
||||
bool BindGroupLayoutCacheFuncs::operator() (const BindGroupLayoutBase* a, const BindGroupLayoutBase* b) const {
|
||||
bool BindGroupLayoutCacheFuncs::operator()(const BindGroupLayoutBase* a,
|
||||
const BindGroupLayoutBase* b) const {
|
||||
return a->GetBindingInfo() == b->GetBindingInfo();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_BINDGROUPLAYOUT_H_
|
||||
#define BACKEND_BINDGROUPLAYOUT_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
@ -28,49 +28,52 @@
|
||||
namespace backend {
|
||||
|
||||
class BindGroupLayoutBase : public RefCounted {
|
||||
public:
|
||||
BindGroupLayoutBase(BindGroupLayoutBuilder* builder, bool blueprint = false);
|
||||
~BindGroupLayoutBase() override;
|
||||
public:
|
||||
BindGroupLayoutBase(BindGroupLayoutBuilder* builder, bool blueprint = false);
|
||||
~BindGroupLayoutBase() override;
|
||||
|
||||
struct LayoutBindingInfo {
|
||||
std::array<nxt::ShaderStageBit, kMaxBindingsPerGroup> visibilities;
|
||||
std::array<nxt::BindingType, kMaxBindingsPerGroup> types;
|
||||
std::bitset<kMaxBindingsPerGroup> mask;
|
||||
};
|
||||
const LayoutBindingInfo& GetBindingInfo() const;
|
||||
struct LayoutBindingInfo {
|
||||
std::array<nxt::ShaderStageBit, kMaxBindingsPerGroup> visibilities;
|
||||
std::array<nxt::BindingType, kMaxBindingsPerGroup> types;
|
||||
std::bitset<kMaxBindingsPerGroup> mask;
|
||||
};
|
||||
const LayoutBindingInfo& GetBindingInfo() const;
|
||||
|
||||
private:
|
||||
DeviceBase* mDevice;
|
||||
LayoutBindingInfo mBindingInfo;
|
||||
bool mIsBlueprint = false;
|
||||
private:
|
||||
DeviceBase* mDevice;
|
||||
LayoutBindingInfo mBindingInfo;
|
||||
bool mIsBlueprint = false;
|
||||
};
|
||||
|
||||
class BindGroupLayoutBuilder : public Builder<BindGroupLayoutBase> {
|
||||
public:
|
||||
BindGroupLayoutBuilder(DeviceBase* device);
|
||||
public:
|
||||
BindGroupLayoutBuilder(DeviceBase* device);
|
||||
|
||||
const BindGroupLayoutBase::LayoutBindingInfo& GetBindingInfo() const;
|
||||
const BindGroupLayoutBase::LayoutBindingInfo& GetBindingInfo() const;
|
||||
|
||||
// NXT API
|
||||
void SetBindingsType(nxt::ShaderStageBit visibility, nxt::BindingType bindingType, uint32_t start, uint32_t count);
|
||||
// NXT API
|
||||
void SetBindingsType(nxt::ShaderStageBit visibility,
|
||||
nxt::BindingType bindingType,
|
||||
uint32_t start,
|
||||
uint32_t count);
|
||||
|
||||
private:
|
||||
friend class BindGroupLayoutBase;
|
||||
private:
|
||||
friend class BindGroupLayoutBase;
|
||||
|
||||
BindGroupLayoutBase* GetResultImpl() override;
|
||||
BindGroupLayoutBase* GetResultImpl() override;
|
||||
|
||||
BindGroupLayoutBase::LayoutBindingInfo mBindingInfo;
|
||||
BindGroupLayoutBase::LayoutBindingInfo mBindingInfo;
|
||||
};
|
||||
|
||||
// Implements the functors necessary for the unordered_set<BGL*>-based cache.
|
||||
struct BindGroupLayoutCacheFuncs {
|
||||
// The hash function
|
||||
size_t operator() (const BindGroupLayoutBase* bgl) const;
|
||||
size_t operator()(const BindGroupLayoutBase* bgl) const;
|
||||
|
||||
// The equality predicate
|
||||
bool operator() (const BindGroupLayoutBase* a, const BindGroupLayoutBase* b) const;
|
||||
bool operator()(const BindGroupLayoutBase* a, const BindGroupLayoutBase* b) const;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_BINDGROUPLAYOUT_H_
|
||||
#endif // BACKEND_BINDGROUPLAYOUT_H_
|
||||
|
@ -54,7 +54,9 @@ namespace backend {
|
||||
mBlendInfo.blendEnabled = blendEnabled;
|
||||
}
|
||||
|
||||
void BlendStateBuilder::SetAlphaBlend(nxt::BlendOperation blendOperation, nxt::BlendFactor srcFactor, nxt::BlendFactor dstFactor) {
|
||||
void BlendStateBuilder::SetAlphaBlend(nxt::BlendOperation blendOperation,
|
||||
nxt::BlendFactor srcFactor,
|
||||
nxt::BlendFactor dstFactor) {
|
||||
if ((mPropertiesSet & BLEND_STATE_PROPERTY_ALPHA_BLEND) != 0) {
|
||||
HandleError("Alpha blend property set multiple times");
|
||||
return;
|
||||
@ -62,10 +64,12 @@ namespace backend {
|
||||
|
||||
mPropertiesSet |= BLEND_STATE_PROPERTY_ALPHA_BLEND;
|
||||
|
||||
mBlendInfo.alphaBlend = { blendOperation, srcFactor, dstFactor };
|
||||
mBlendInfo.alphaBlend = {blendOperation, srcFactor, dstFactor};
|
||||
}
|
||||
|
||||
void BlendStateBuilder::SetColorBlend(nxt::BlendOperation blendOperation, nxt::BlendFactor srcFactor, nxt::BlendFactor dstFactor) {
|
||||
void BlendStateBuilder::SetColorBlend(nxt::BlendOperation blendOperation,
|
||||
nxt::BlendFactor srcFactor,
|
||||
nxt::BlendFactor dstFactor) {
|
||||
if ((mPropertiesSet & BLEND_STATE_PROPERTY_COLOR_BLEND) != 0) {
|
||||
HandleError("Color blend property set multiple times");
|
||||
return;
|
||||
@ -73,7 +77,7 @@ namespace backend {
|
||||
|
||||
mPropertiesSet |= BLEND_STATE_PROPERTY_COLOR_BLEND;
|
||||
|
||||
mBlendInfo.colorBlend = { blendOperation, srcFactor, dstFactor };
|
||||
mBlendInfo.colorBlend = {blendOperation, srcFactor, dstFactor};
|
||||
}
|
||||
|
||||
void BlendStateBuilder::SetColorWriteMask(nxt::ColorWriteMask colorWriteMask) {
|
||||
@ -86,4 +90,4 @@ namespace backend {
|
||||
|
||||
mBlendInfo.colorWriteMask = colorWriteMask;
|
||||
}
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_BLENDSTATE_H_
|
||||
#define BACKEND_BLENDSTATE_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
@ -24,49 +24,52 @@
|
||||
namespace backend {
|
||||
|
||||
class BlendStateBase : public RefCounted {
|
||||
public:
|
||||
BlendStateBase(BlendStateBuilder* builder);
|
||||
public:
|
||||
BlendStateBase(BlendStateBuilder* builder);
|
||||
|
||||
struct BlendInfo {
|
||||
struct BlendOpFactor {
|
||||
nxt::BlendOperation operation = nxt::BlendOperation::Add;
|
||||
nxt::BlendFactor srcFactor = nxt::BlendFactor::One;
|
||||
nxt::BlendFactor dstFactor = nxt::BlendFactor::Zero;
|
||||
};
|
||||
|
||||
bool blendEnabled = false;
|
||||
BlendOpFactor alphaBlend;
|
||||
BlendOpFactor colorBlend;
|
||||
nxt::ColorWriteMask colorWriteMask = nxt::ColorWriteMask::All;
|
||||
struct BlendInfo {
|
||||
struct BlendOpFactor {
|
||||
nxt::BlendOperation operation = nxt::BlendOperation::Add;
|
||||
nxt::BlendFactor srcFactor = nxt::BlendFactor::One;
|
||||
nxt::BlendFactor dstFactor = nxt::BlendFactor::Zero;
|
||||
};
|
||||
|
||||
const BlendInfo& GetBlendInfo() const;
|
||||
bool blendEnabled = false;
|
||||
BlendOpFactor alphaBlend;
|
||||
BlendOpFactor colorBlend;
|
||||
nxt::ColorWriteMask colorWriteMask = nxt::ColorWriteMask::All;
|
||||
};
|
||||
|
||||
private:
|
||||
BlendInfo mBlendInfo;
|
||||
const BlendInfo& GetBlendInfo() const;
|
||||
|
||||
private:
|
||||
BlendInfo mBlendInfo;
|
||||
};
|
||||
|
||||
class BlendStateBuilder : public Builder<BlendStateBase> {
|
||||
public:
|
||||
BlendStateBuilder(DeviceBase* device);
|
||||
public:
|
||||
BlendStateBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetBlendEnabled(bool blendEnabled);
|
||||
void SetAlphaBlend(nxt::BlendOperation blendOperation, nxt::BlendFactor srcFactor, nxt::BlendFactor dstFactor);
|
||||
void SetColorBlend(nxt::BlendOperation blendOperation, nxt::BlendFactor srcFactor, nxt::BlendFactor dstFactor);
|
||||
void SetColorWriteMask(nxt::ColorWriteMask colorWriteMask);
|
||||
// NXT API
|
||||
void SetBlendEnabled(bool blendEnabled);
|
||||
void SetAlphaBlend(nxt::BlendOperation blendOperation,
|
||||
nxt::BlendFactor srcFactor,
|
||||
nxt::BlendFactor dstFactor);
|
||||
void SetColorBlend(nxt::BlendOperation blendOperation,
|
||||
nxt::BlendFactor srcFactor,
|
||||
nxt::BlendFactor dstFactor);
|
||||
void SetColorWriteMask(nxt::ColorWriteMask colorWriteMask);
|
||||
|
||||
private:
|
||||
friend class BlendStateBase;
|
||||
private:
|
||||
friend class BlendStateBase;
|
||||
|
||||
BlendStateBase* GetResultImpl() override;
|
||||
BlendStateBase* GetResultImpl() override;
|
||||
|
||||
int mPropertiesSet = 0;
|
||||
int mPropertiesSet = 0;
|
||||
|
||||
BlendStateBase::BlendInfo mBlendInfo;
|
||||
BlendStateBase::BlendInfo mBlendInfo;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_BLENDSTATE_H_
|
||||
#endif // BACKEND_BLENDSTATE_H_
|
||||
|
@ -17,8 +17,8 @@
|
||||
#include "backend/Device.h"
|
||||
#include "common/Assert.h"
|
||||
|
||||
#include <utility>
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
|
||||
namespace backend {
|
||||
|
||||
@ -57,7 +57,9 @@ namespace backend {
|
||||
return mCurrentUsage;
|
||||
}
|
||||
|
||||
void BufferBase::CallMapReadCallback(uint32_t serial, nxtBufferMapReadStatus status, const void* pointer) {
|
||||
void BufferBase::CallMapReadCallback(uint32_t serial,
|
||||
nxtBufferMapReadStatus status,
|
||||
const void* pointer) {
|
||||
if (mMapReadCallback && serial == mMapReadSerial) {
|
||||
mMapReadCallback(status, pointer, mMapReadUserdata);
|
||||
mMapReadCallback = nullptr;
|
||||
@ -78,7 +80,10 @@ namespace backend {
|
||||
SetSubDataImpl(start, count, data);
|
||||
}
|
||||
|
||||
void BufferBase::MapReadAsync(uint32_t start, uint32_t size, nxtBufferMapReadCallback callback, nxtCallbackUserdata userdata) {
|
||||
void BufferBase::MapReadAsync(uint32_t start,
|
||||
uint32_t size,
|
||||
nxtBufferMapReadCallback callback,
|
||||
nxtCallbackUserdata userdata) {
|
||||
if (start + size > GetSize()) {
|
||||
mDevice->HandleError("Buffer map read out of range");
|
||||
callback(NXT_BUFFER_MAP_READ_STATUS_ERROR, nullptr, userdata);
|
||||
@ -98,7 +103,7 @@ namespace backend {
|
||||
}
|
||||
|
||||
// TODO(cwallez@chromium.org): what to do on wraparound? Could cause crashes.
|
||||
mMapReadSerial ++;
|
||||
mMapReadSerial++;
|
||||
mMapReadCallback = callback;
|
||||
mMapReadUserdata = userdata;
|
||||
MapReadAsyncImpl(mMapReadSerial, start, size);
|
||||
@ -128,11 +133,8 @@ namespace backend {
|
||||
|
||||
bool BufferBase::IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage) {
|
||||
const nxt::BufferUsageBit allReadBits =
|
||||
nxt::BufferUsageBit::MapRead |
|
||||
nxt::BufferUsageBit::TransferSrc |
|
||||
nxt::BufferUsageBit::Index |
|
||||
nxt::BufferUsageBit::Vertex |
|
||||
nxt::BufferUsageBit::Uniform;
|
||||
nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferSrc |
|
||||
nxt::BufferUsageBit::Index | nxt::BufferUsageBit::Vertex | nxt::BufferUsageBit::Uniform;
|
||||
bool allowed = (usage & allowedUsage) == usage;
|
||||
bool readOnly = (usage & allReadBits) == usage;
|
||||
bool singleUse = nxt::HasZeroOrOneBits(usage);
|
||||
@ -189,14 +191,16 @@ namespace backend {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const nxt::BufferUsageBit kMapWriteAllowedUsages = nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc;
|
||||
const nxt::BufferUsageBit kMapWriteAllowedUsages =
|
||||
nxt::BufferUsageBit::MapWrite | nxt::BufferUsageBit::TransferSrc;
|
||||
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;
|
||||
const nxt::BufferUsageBit kMapReadAllowedUsages =
|
||||
nxt::BufferUsageBit::MapRead | nxt::BufferUsageBit::TransferDst;
|
||||
if (mAllowedUsage & nxt::BufferUsageBit::MapRead &&
|
||||
(mAllowedUsage & kMapReadAllowedUsages) != mAllowedUsage) {
|
||||
HandleError("Only TransferDst is allowed with MapRead");
|
||||
@ -296,4 +300,4 @@ namespace backend {
|
||||
mPropertiesSet |= BUFFER_VIEW_PROPERTY_EXTENT;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_BUFFER_H_
|
||||
#define BACKEND_BUFFER_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
@ -24,103 +24,109 @@
|
||||
namespace backend {
|
||||
|
||||
class BufferBase : public RefCounted {
|
||||
public:
|
||||
BufferBase(BufferBuilder* builder);
|
||||
~BufferBase();
|
||||
public:
|
||||
BufferBase(BufferBuilder* builder);
|
||||
~BufferBase();
|
||||
|
||||
uint32_t GetSize() const;
|
||||
nxt::BufferUsageBit GetAllowedUsage() const;
|
||||
nxt::BufferUsageBit GetUsage() const;
|
||||
static bool IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage);
|
||||
bool IsTransitionPossible(nxt::BufferUsageBit usage) const;
|
||||
bool IsFrozen() const;
|
||||
bool HasFrozenUsage(nxt::BufferUsageBit usage) const;
|
||||
void UpdateUsageInternal(nxt::BufferUsageBit usage);
|
||||
uint32_t GetSize() const;
|
||||
nxt::BufferUsageBit GetAllowedUsage() const;
|
||||
nxt::BufferUsageBit GetUsage() const;
|
||||
static bool IsUsagePossible(nxt::BufferUsageBit allowedUsage, nxt::BufferUsageBit usage);
|
||||
bool IsTransitionPossible(nxt::BufferUsageBit usage) const;
|
||||
bool IsFrozen() const;
|
||||
bool HasFrozenUsage(nxt::BufferUsageBit usage) const;
|
||||
void UpdateUsageInternal(nxt::BufferUsageBit usage);
|
||||
|
||||
DeviceBase* GetDevice();
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
// NXT API
|
||||
BufferViewBuilder* CreateBufferViewBuilder();
|
||||
void SetSubData(uint32_t start, uint32_t count, const uint32_t* data);
|
||||
void MapReadAsync(uint32_t start, uint32_t size, nxtBufferMapReadCallback callback, nxtCallbackUserdata userdata);
|
||||
void Unmap();
|
||||
void TransitionUsage(nxt::BufferUsageBit usage);
|
||||
void FreezeUsage(nxt::BufferUsageBit usage);
|
||||
// NXT API
|
||||
BufferViewBuilder* CreateBufferViewBuilder();
|
||||
void SetSubData(uint32_t start, uint32_t count, const uint32_t* data);
|
||||
void MapReadAsync(uint32_t start,
|
||||
uint32_t size,
|
||||
nxtBufferMapReadCallback callback,
|
||||
nxtCallbackUserdata userdata);
|
||||
void Unmap();
|
||||
void TransitionUsage(nxt::BufferUsageBit usage);
|
||||
void FreezeUsage(nxt::BufferUsageBit usage);
|
||||
|
||||
protected:
|
||||
void CallMapReadCallback(uint32_t serial, nxtBufferMapReadStatus status, const void* pointer);
|
||||
protected:
|
||||
void CallMapReadCallback(uint32_t serial,
|
||||
nxtBufferMapReadStatus status,
|
||||
const void* pointer);
|
||||
|
||||
private:
|
||||
virtual void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) = 0;
|
||||
virtual void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
|
||||
virtual void UnmapImpl() = 0;
|
||||
virtual void TransitionUsageImpl(nxt::BufferUsageBit currentUsage, nxt::BufferUsageBit targetUsage) = 0;
|
||||
private:
|
||||
virtual void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) = 0;
|
||||
virtual void MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t size) = 0;
|
||||
virtual void UnmapImpl() = 0;
|
||||
virtual void TransitionUsageImpl(nxt::BufferUsageBit currentUsage,
|
||||
nxt::BufferUsageBit targetUsage) = 0;
|
||||
|
||||
DeviceBase* mDevice;
|
||||
uint32_t mSize;
|
||||
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None;
|
||||
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None;
|
||||
DeviceBase* mDevice;
|
||||
uint32_t mSize;
|
||||
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None;
|
||||
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None;
|
||||
|
||||
nxtBufferMapReadCallback mMapReadCallback = nullptr;
|
||||
nxtCallbackUserdata mMapReadUserdata = 0;
|
||||
uint32_t mMapReadSerial = 0;
|
||||
nxtBufferMapReadCallback mMapReadCallback = nullptr;
|
||||
nxtCallbackUserdata mMapReadUserdata = 0;
|
||||
uint32_t mMapReadSerial = 0;
|
||||
|
||||
bool mIsFrozen = false;
|
||||
bool mIsMapped = false;
|
||||
bool mIsFrozen = false;
|
||||
bool mIsMapped = false;
|
||||
};
|
||||
|
||||
class BufferBuilder : public Builder<BufferBase> {
|
||||
public:
|
||||
BufferBuilder(DeviceBase* device);
|
||||
public:
|
||||
BufferBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetAllowedUsage(nxt::BufferUsageBit usage);
|
||||
void SetInitialUsage(nxt::BufferUsageBit usage);
|
||||
void SetSize(uint32_t size);
|
||||
// NXT API
|
||||
void SetAllowedUsage(nxt::BufferUsageBit usage);
|
||||
void SetInitialUsage(nxt::BufferUsageBit usage);
|
||||
void SetSize(uint32_t size);
|
||||
|
||||
private:
|
||||
friend class BufferBase;
|
||||
private:
|
||||
friend class BufferBase;
|
||||
|
||||
BufferBase* GetResultImpl() override;
|
||||
BufferBase* GetResultImpl() override;
|
||||
|
||||
uint32_t mSize;
|
||||
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None;
|
||||
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None;
|
||||
int mPropertiesSet = 0;
|
||||
uint32_t mSize;
|
||||
nxt::BufferUsageBit mAllowedUsage = nxt::BufferUsageBit::None;
|
||||
nxt::BufferUsageBit mCurrentUsage = nxt::BufferUsageBit::None;
|
||||
int mPropertiesSet = 0;
|
||||
};
|
||||
|
||||
class BufferViewBase : public RefCounted {
|
||||
public:
|
||||
BufferViewBase(BufferViewBuilder* builder);
|
||||
public:
|
||||
BufferViewBase(BufferViewBuilder* builder);
|
||||
|
||||
BufferBase* GetBuffer();
|
||||
uint32_t GetSize() const;
|
||||
uint32_t GetOffset() const;
|
||||
BufferBase* GetBuffer();
|
||||
uint32_t GetSize() const;
|
||||
uint32_t GetOffset() const;
|
||||
|
||||
private:
|
||||
Ref<BufferBase> mBuffer;
|
||||
uint32_t mSize;
|
||||
uint32_t mOffset;
|
||||
private:
|
||||
Ref<BufferBase> mBuffer;
|
||||
uint32_t mSize;
|
||||
uint32_t mOffset;
|
||||
};
|
||||
|
||||
class BufferViewBuilder : public Builder<BufferViewBase> {
|
||||
public:
|
||||
BufferViewBuilder(DeviceBase* device, BufferBase* buffer);
|
||||
public:
|
||||
BufferViewBuilder(DeviceBase* device, BufferBase* buffer);
|
||||
|
||||
// NXT API
|
||||
void SetExtent(uint32_t offset, uint32_t size);
|
||||
// NXT API
|
||||
void SetExtent(uint32_t offset, uint32_t size);
|
||||
|
||||
private:
|
||||
friend class BufferViewBase;
|
||||
private:
|
||||
friend class BufferViewBase;
|
||||
|
||||
BufferViewBase* GetResultImpl() override;
|
||||
BufferViewBase* GetResultImpl() override;
|
||||
|
||||
Ref<BufferBase> mBuffer;
|
||||
uint32_t mOffset = 0;
|
||||
uint32_t mSize = 0;
|
||||
int mPropertiesSet = 0;
|
||||
Ref<BufferBase> mBuffer;
|
||||
uint32_t mOffset = 0;
|
||||
uint32_t mSize = 0;
|
||||
int mPropertiesSet = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_BUFFER_H_
|
||||
#endif // BACKEND_BUFFER_H_
|
||||
|
@ -32,8 +32,8 @@ namespace backend {
|
||||
}
|
||||
|
||||
void BuilderBase::SetErrorCallback(nxt::BuilderErrorCallback callback,
|
||||
nxt::CallbackUserdata userdata1,
|
||||
nxt::CallbackUserdata userdata2) {
|
||||
nxt::CallbackUserdata userdata1,
|
||||
nxt::CallbackUserdata userdata2) {
|
||||
mCallback = callback;
|
||||
mUserdata1 = userdata1;
|
||||
mUserdata2 = userdata2;
|
||||
@ -44,14 +44,15 @@ namespace backend {
|
||||
|
||||
BuilderBase::~BuilderBase() {
|
||||
if (!mIsConsumed && mCallback != nullptr) {
|
||||
mCallback(NXT_BUILDER_ERROR_STATUS_UNKNOWN, "Builder destroyed before GetResult", mUserdata1, mUserdata2);
|
||||
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(!mGotStatus); // This is not strictly necessary but something to strive for.
|
||||
ASSERT(!mGotStatus); // This is not strictly necessary but something to strive for.
|
||||
mGotStatus = true;
|
||||
|
||||
mStoredStatus = status;
|
||||
@ -78,17 +79,19 @@ namespace backend {
|
||||
}
|
||||
|
||||
// Unhandled builder errors are promoted to device errors
|
||||
if (!mCallback) mDevice->HandleError(("Unhandled builder error: " + mStoredMessage).c_str());
|
||||
if (!mCallback)
|
||||
mDevice->HandleError(("Unhandled builder error: " + mStoredMessage).c_str());
|
||||
} else {
|
||||
ASSERT(mStoredStatus == nxt::BuilderErrorStatus::Success);
|
||||
ASSERT(mStoredMessage.empty());
|
||||
}
|
||||
|
||||
if (mCallback != nullptr) {
|
||||
mCallback(static_cast<nxtBuilderErrorStatus>(mStoredStatus), mStoredMessage.c_str(), mUserdata1, mUserdata2);
|
||||
mCallback(static_cast<nxtBuilderErrorStatus>(mStoredStatus), mStoredMessage.c_str(),
|
||||
mUserdata1, mUserdata2);
|
||||
}
|
||||
|
||||
return result != nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -25,79 +25,76 @@
|
||||
namespace backend {
|
||||
|
||||
// This class implements behavior shared by all builders:
|
||||
// - Tracking whether GetResult has been called already, needed by the
|
||||
// autogenerated code to prevent operations on "consumed" builders.
|
||||
// - The error status callback of the API. The callback is guaranteed to be
|
||||
// called exactly once with an error, a success, or "unknown" if the
|
||||
// builder is destroyed; also the builder callback cannot be called before
|
||||
// either the object is destroyed or GetResult is called.
|
||||
// - Tracking whether GetResult has been called already, needed by the autogenerated code to
|
||||
// prevent operations on "consumed" builders.
|
||||
// - The error status callback of the API. The callback is guaranteed to be called exactly once
|
||||
// with an error, a success, or "unknown" if the builder is destroyed; also the builder
|
||||
// callback cannot be called before either the object is destroyed or GetResult is called.
|
||||
//
|
||||
// It is possible for error to be generated before the error callback is
|
||||
// registered when a builder "set" function performance validation inline.
|
||||
// Because of this we have to store the status in the builder and defer
|
||||
// calling the callback to GetResult.
|
||||
// It is possible for error to be generated before the error callback is registered when a
|
||||
// builder "set" function performance validation inline. Because of this we have to store the
|
||||
// status in the builder and defer calling the callback to GetResult.
|
||||
|
||||
class BuilderBase : public RefCounted {
|
||||
public:
|
||||
// Used by the auto-generated validation to prevent usage of the builder
|
||||
// after GetResult or an error.
|
||||
bool CanBeUsed() const;
|
||||
DeviceBase* GetDevice();
|
||||
public:
|
||||
// Used by the auto-generated validation to prevent usage of the builder
|
||||
// after GetResult or an error.
|
||||
bool CanBeUsed() const;
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
// Set the status of the builder to an error.
|
||||
void HandleError(const char* message);
|
||||
// Set the status of the builder to an error.
|
||||
void HandleError(const char* message);
|
||||
|
||||
// Internal API, to be used by builder and BackendProcTable only.
|
||||
// rReturns true for success cases, and calls the callback with appropriate status.
|
||||
bool HandleResult(RefCounted* result);
|
||||
// Internal API, to be used by builder and BackendProcTable only.
|
||||
// Returns true for success cases, and calls the callback with appropriate status.
|
||||
bool HandleResult(RefCounted* result);
|
||||
|
||||
// NXT API
|
||||
void SetErrorCallback(nxt::BuilderErrorCallback callback,
|
||||
nxt::CallbackUserdata userdata1,
|
||||
nxt::CallbackUserdata userdata2);
|
||||
// NXT API
|
||||
void SetErrorCallback(nxt::BuilderErrorCallback callback,
|
||||
nxt::CallbackUserdata userdata1,
|
||||
nxt::CallbackUserdata userdata2);
|
||||
|
||||
protected:
|
||||
BuilderBase(DeviceBase* device);
|
||||
~BuilderBase();
|
||||
protected:
|
||||
BuilderBase(DeviceBase* device);
|
||||
~BuilderBase();
|
||||
|
||||
DeviceBase* const mDevice;
|
||||
bool mGotStatus = false;
|
||||
DeviceBase* const mDevice;
|
||||
bool mGotStatus = false;
|
||||
|
||||
private:
|
||||
void SetStatus(nxt::BuilderErrorStatus status, const char* message);
|
||||
private:
|
||||
void SetStatus(nxt::BuilderErrorStatus status, const char* message);
|
||||
|
||||
nxt::BuilderErrorCallback mCallback = nullptr;
|
||||
nxt::CallbackUserdata mUserdata1 = 0;
|
||||
nxt::CallbackUserdata mUserdata2 = 0;
|
||||
nxt::BuilderErrorCallback mCallback = nullptr;
|
||||
nxt::CallbackUserdata mUserdata1 = 0;
|
||||
nxt::CallbackUserdata mUserdata2 = 0;
|
||||
|
||||
nxt::BuilderErrorStatus mStoredStatus = nxt::BuilderErrorStatus::Success;
|
||||
std::string mStoredMessage;
|
||||
nxt::BuilderErrorStatus mStoredStatus = nxt::BuilderErrorStatus::Success;
|
||||
std::string mStoredMessage;
|
||||
|
||||
bool mIsConsumed = false;
|
||||
bool mIsConsumed = false;
|
||||
};
|
||||
|
||||
// This builder base class is used to capture the calls to GetResult and make sure
|
||||
// that either:
|
||||
// This builder base class is used to capture the calls to GetResult and make sure that either:
|
||||
// - There was an error, callback is called with an error and nullptr is returned.
|
||||
// - There was no error, callback is called with success and a non-null T* is returned.
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class Builder : public BuilderBase {
|
||||
public:
|
||||
// NXT API
|
||||
T* GetResult();
|
||||
public:
|
||||
// NXT API
|
||||
T* GetResult();
|
||||
|
||||
protected:
|
||||
using BuilderBase::BuilderBase;
|
||||
protected:
|
||||
using BuilderBase::BuilderBase;
|
||||
|
||||
private:
|
||||
virtual T* GetResultImpl() = 0;
|
||||
private:
|
||||
virtual T* GetResultImpl() = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T* Builder<T>::GetResult() {
|
||||
T* result = GetResultImpl();
|
||||
// An object can have been returned but failed its initialization, so if an error
|
||||
// happened, return nullptr instead of result.
|
||||
// An object can have been returned but failed its initialization, so if an error happened,
|
||||
// return nullptr instead of result.
|
||||
if (HandleResult(result)) {
|
||||
return result;
|
||||
} else {
|
||||
@ -105,6 +102,6 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_BUILDER_H_
|
||||
#endif // BACKEND_BUILDER_H_
|
||||
|
@ -23,13 +23,12 @@
|
||||
|
||||
namespace backend {
|
||||
|
||||
constexpr uint32_t EndOfBlock = UINT_MAX;//std::numeric_limits<uint32_t>::max();
|
||||
constexpr uint32_t AdditionalData = UINT_MAX - 1;//std::numeric_limits<uint32_t>::max();
|
||||
constexpr uint32_t EndOfBlock = UINT_MAX; // std::numeric_limits<uint32_t>::max();
|
||||
constexpr uint32_t AdditionalData = UINT_MAX - 1; // std::numeric_limits<uint32_t>::max() - 1;
|
||||
|
||||
// TODO(cwallez@chromium.org): figure out a way to have more type safety for the iterator
|
||||
|
||||
CommandIterator::CommandIterator()
|
||||
: mEndOfBlock(EndOfBlock) {
|
||||
CommandIterator::CommandIterator() : mEndOfBlock(EndOfBlock) {
|
||||
Reset();
|
||||
}
|
||||
|
||||
@ -43,8 +42,7 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
CommandIterator::CommandIterator(CommandIterator&& other)
|
||||
: mEndOfBlock(EndOfBlock) {
|
||||
CommandIterator::CommandIterator(CommandIterator&& other) : mEndOfBlock(EndOfBlock) {
|
||||
if (!other.IsEmpty()) {
|
||||
mBlocks = std::move(other.mBlocks);
|
||||
other.Reset();
|
||||
@ -80,9 +78,8 @@ namespace backend {
|
||||
mCurrentBlock = 0;
|
||||
|
||||
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.
|
||||
// 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.
|
||||
mCurrentPtr = reinterpret_cast<uint8_t*>(&mEndOfBlock);
|
||||
mBlocks.emplace_back();
|
||||
mBlocks[0].size = sizeof(mEndOfBlock);
|
||||
@ -102,7 +99,8 @@ namespace backend {
|
||||
|
||||
bool CommandIterator::NextCommandId(uint32_t* commandId) {
|
||||
uint8_t* idPtr = AlignPtr(mCurrentPtr, alignof(uint32_t));
|
||||
ASSERT(idPtr + sizeof(uint32_t) <= mBlocks[mCurrentBlock].block + mBlocks[mCurrentBlock].size);
|
||||
ASSERT(idPtr + sizeof(uint32_t) <=
|
||||
mBlocks[mCurrentBlock].block + mBlocks[mCurrentBlock].size);
|
||||
|
||||
uint32_t id = *reinterpret_cast<uint32_t*>(idPtr);
|
||||
|
||||
@ -124,7 +122,8 @@ namespace backend {
|
||||
|
||||
void* CommandIterator::NextCommand(size_t commandSize, size_t commandAlignment) {
|
||||
uint8_t* commandPtr = AlignPtr(mCurrentPtr, commandAlignment);
|
||||
ASSERT(commandPtr + sizeof(commandSize) <= mBlocks[mCurrentBlock].block + mBlocks[mCurrentBlock].size);
|
||||
ASSERT(commandPtr + sizeof(commandSize) <=
|
||||
mBlocks[mCurrentBlock].block + mBlocks[mCurrentBlock].size);
|
||||
|
||||
mCurrentPtr = commandPtr + commandSize;
|
||||
return commandPtr;
|
||||
@ -140,13 +139,18 @@ namespace backend {
|
||||
}
|
||||
|
||||
// Potential TODO(cwallez@chromium.org):
|
||||
// - Host the size and pointer to next block in the block itself to avoid having an allocation in the vector
|
||||
// - Assume T's alignof is, say 64bits, static assert it, and make commandAlignment a constant in Allocate
|
||||
// - Be able to optimize allocation to one block, for command buffers expected to live long to avoid cache misses
|
||||
// - Better block allocation, maybe have NXT API to say command buffer is going to have size close to another
|
||||
// - Host the size and pointer to next block in the block itself to avoid having an allocation
|
||||
// in the vector
|
||||
// - Assume T's alignof is, say 64bits, static assert it, and make commandAlignment a constant
|
||||
// in Allocate
|
||||
// - Be able to optimize allocation to one block, for command buffers expected to live long to
|
||||
// avoid cache misses
|
||||
// - Better block allocation, maybe have NXT API to say command buffer is going to have size
|
||||
// close to another
|
||||
|
||||
CommandAllocator::CommandAllocator()
|
||||
: mCurrentPtr(reinterpret_cast<uint8_t*>(&mDummyEnum[0])), mEndPtr(reinterpret_cast<uint8_t*>(&mDummyEnum[1])) {
|
||||
: mCurrentPtr(reinterpret_cast<uint8_t*>(&mDummyEnum[0])),
|
||||
mEndPtr(reinterpret_cast<uint8_t*>(&mDummyEnum[1])) {
|
||||
}
|
||||
|
||||
CommandAllocator::~CommandAllocator() {
|
||||
@ -164,7 +168,9 @@ namespace backend {
|
||||
return std::move(mBlocks);
|
||||
}
|
||||
|
||||
uint8_t* CommandAllocator::Allocate(uint32_t commandId, size_t commandSize, size_t commandAlignment) {
|
||||
uint8_t* CommandAllocator::Allocate(uint32_t commandId,
|
||||
size_t commandSize,
|
||||
size_t commandAlignment) {
|
||||
ASSERT(mCurrentPtr != nullptr);
|
||||
ASSERT(mEndPtr != nullptr);
|
||||
ASSERT(commandId != EndOfBlock);
|
||||
@ -180,15 +186,15 @@ namespace backend {
|
||||
// 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) > 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.
|
||||
// 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.
|
||||
*idAlloc = EndOfBlock;
|
||||
|
||||
// Make sure we have space for current allocation, plus end of block and alignment padding
|
||||
// for the first id.
|
||||
// Make sure we have space for current allocation, plus end of block and alignment
|
||||
// padding for the first id.
|
||||
ASSERT(nextPtr > mCurrentPtr);
|
||||
if (!GetNewBlock(static_cast<size_t>(nextPtr - mCurrentPtr) + sizeof(uint32_t) + alignof(uint32_t))) {
|
||||
if (!GetNewBlock(static_cast<size_t>(nextPtr - mCurrentPtr) + sizeof(uint32_t) +
|
||||
alignof(uint32_t))) {
|
||||
return nullptr;
|
||||
}
|
||||
return Allocate(commandId, commandSize, commandAlignment);
|
||||
@ -205,7 +211,8 @@ namespace backend {
|
||||
|
||||
bool CommandAllocator::GetNewBlock(size_t minimumSize) {
|
||||
// Allocate blocks doubling sizes each time, to a maximum of 16k (or at least minimumSize).
|
||||
mLastAllocationSize = std::max(minimumSize, std::min(mLastAllocationSize * 2, size_t(16384)));
|
||||
mLastAllocationSize =
|
||||
std::max(minimumSize, std::min(mLastAllocationSize * 2, size_t(16384)));
|
||||
|
||||
uint8_t* block = reinterpret_cast<uint8_t*>(malloc(mLastAllocationSize));
|
||||
if (block == nullptr) {
|
||||
@ -218,4 +225,4 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_COMMAND_ALLOCATOR_H_
|
||||
#define BACKEND_COMMAND_ALLOCATOR_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace backend {
|
||||
@ -61,90 +61,90 @@ namespace backend {
|
||||
|
||||
// TODO(cwallez@chromium.org): prevent copy for both iterator and allocator
|
||||
class CommandIterator {
|
||||
public:
|
||||
CommandIterator();
|
||||
~CommandIterator();
|
||||
public:
|
||||
CommandIterator();
|
||||
~CommandIterator();
|
||||
|
||||
CommandIterator(CommandIterator&& other);
|
||||
CommandIterator& operator=(CommandIterator&& other);
|
||||
CommandIterator(CommandIterator&& other);
|
||||
CommandIterator& operator=(CommandIterator&& other);
|
||||
|
||||
CommandIterator(CommandAllocator&& allocator);
|
||||
CommandIterator& operator=(CommandAllocator&& allocator);
|
||||
CommandIterator(CommandAllocator&& allocator);
|
||||
CommandIterator& operator=(CommandAllocator&& allocator);
|
||||
|
||||
template<typename E>
|
||||
bool NextCommandId(E* commandId) {
|
||||
return NextCommandId(reinterpret_cast<uint32_t*>(commandId));
|
||||
}
|
||||
template<typename T>
|
||||
T* NextCommand() {
|
||||
return reinterpret_cast<T*>(NextCommand(sizeof(T), alignof(T)));
|
||||
}
|
||||
template<typename T>
|
||||
T* NextData(size_t count) {
|
||||
return reinterpret_cast<T*>(NextData(sizeof(T) * count, alignof(T)));
|
||||
}
|
||||
template <typename E>
|
||||
bool NextCommandId(E* commandId) {
|
||||
return NextCommandId(reinterpret_cast<uint32_t*>(commandId));
|
||||
}
|
||||
template <typename T>
|
||||
T* NextCommand() {
|
||||
return reinterpret_cast<T*>(NextCommand(sizeof(T), alignof(T)));
|
||||
}
|
||||
template <typename T>
|
||||
T* NextData(size_t count) {
|
||||
return reinterpret_cast<T*>(NextData(sizeof(T) * count, alignof(T)));
|
||||
}
|
||||
|
||||
// Needs to be called if iteration was stopped early.
|
||||
void Reset();
|
||||
// Needs to be called if iteration was stopped early.
|
||||
void Reset();
|
||||
|
||||
void DataWasDestroyed();
|
||||
void DataWasDestroyed();
|
||||
|
||||
private:
|
||||
bool IsEmpty() const;
|
||||
private:
|
||||
bool IsEmpty() const;
|
||||
|
||||
bool NextCommandId(uint32_t* commandId);
|
||||
void* NextCommand(size_t commandSize, size_t commandAlignment);
|
||||
void* NextData(size_t dataSize, size_t dataAlignment);
|
||||
bool NextCommandId(uint32_t* commandId);
|
||||
void* NextCommand(size_t commandSize, size_t commandAlignment);
|
||||
void* NextData(size_t dataSize, size_t dataAlignment);
|
||||
|
||||
CommandBlocks mBlocks;
|
||||
uint8_t* mCurrentPtr = nullptr;
|
||||
size_t mCurrentBlock = 0;
|
||||
// Used to avoid a special case for empty iterators.
|
||||
uint32_t mEndOfBlock;
|
||||
bool mDataWasDestroyed = false;
|
||||
CommandBlocks mBlocks;
|
||||
uint8_t* mCurrentPtr = nullptr;
|
||||
size_t mCurrentBlock = 0;
|
||||
// Used to avoid a special case for empty iterators.
|
||||
uint32_t mEndOfBlock;
|
||||
bool mDataWasDestroyed = false;
|
||||
};
|
||||
|
||||
class CommandAllocator {
|
||||
public:
|
||||
CommandAllocator();
|
||||
~CommandAllocator();
|
||||
public:
|
||||
CommandAllocator();
|
||||
~CommandAllocator();
|
||||
|
||||
template<typename T, typename E>
|
||||
T* Allocate(E commandId) {
|
||||
static_assert(sizeof(E) == sizeof(uint32_t), "");
|
||||
static_assert(alignof(E) == alignof(uint32_t), "");
|
||||
return reinterpret_cast<T*>(Allocate(static_cast<uint32_t>(commandId), sizeof(T), alignof(T)));
|
||||
}
|
||||
template <typename T, typename E>
|
||||
T* Allocate(E commandId) {
|
||||
static_assert(sizeof(E) == sizeof(uint32_t), "");
|
||||
static_assert(alignof(E) == alignof(uint32_t), "");
|
||||
return reinterpret_cast<T*>(
|
||||
Allocate(static_cast<uint32_t>(commandId), sizeof(T), alignof(T)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* AllocateData(size_t count) {
|
||||
return reinterpret_cast<T*>(AllocateData(sizeof(T) * count, alignof(T)));
|
||||
}
|
||||
template <typename T>
|
||||
T* AllocateData(size_t count) {
|
||||
return reinterpret_cast<T*>(AllocateData(sizeof(T) * count, alignof(T)));
|
||||
}
|
||||
|
||||
private:
|
||||
friend CommandIterator;
|
||||
CommandBlocks&& AcquireBlocks();
|
||||
private:
|
||||
friend CommandIterator;
|
||||
CommandBlocks&& AcquireBlocks();
|
||||
|
||||
uint8_t* Allocate(uint32_t commandId, size_t commandSize, size_t commandAlignment);
|
||||
uint8_t* AllocateData(size_t dataSize, size_t dataAlignment);
|
||||
bool GetNewBlock(size_t minimumSize);
|
||||
uint8_t* Allocate(uint32_t commandId, size_t commandSize, size_t commandAlignment);
|
||||
uint8_t* AllocateData(size_t dataSize, size_t dataAlignment);
|
||||
bool GetNewBlock(size_t minimumSize);
|
||||
|
||||
CommandBlocks mBlocks;
|
||||
size_t mLastAllocationSize = 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* mCurrentPtr = nullptr;
|
||||
uint8_t* mEndPtr = nullptr;
|
||||
// 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* 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 mDummyEnum[1] = {0};
|
||||
// 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 mDummyEnum[1] = {0};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_COMMAND_ALLOCATOR_H_
|
||||
#endif // BACKEND_COMMAND_ALLOCATOR_H_
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,8 +17,8 @@
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
|
||||
#include "backend/CommandAllocator.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/CommandAllocator.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include <memory>
|
||||
@ -39,75 +39,111 @@ namespace backend {
|
||||
class CommandBufferBuilder;
|
||||
|
||||
class CommandBufferBase : public RefCounted {
|
||||
public:
|
||||
CommandBufferBase(CommandBufferBuilder* builder);
|
||||
bool ValidateResourceUsagesImmediate();
|
||||
public:
|
||||
CommandBufferBase(CommandBufferBuilder* builder);
|
||||
bool ValidateResourceUsagesImmediate();
|
||||
|
||||
DeviceBase* GetDevice();
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
private:
|
||||
DeviceBase* mDevice;
|
||||
std::set<BufferBase*> mBuffersTransitioned;
|
||||
std::set<TextureBase*> mTexturesTransitioned;
|
||||
private:
|
||||
DeviceBase* mDevice;
|
||||
std::set<BufferBase*> mBuffersTransitioned;
|
||||
std::set<TextureBase*> mTexturesTransitioned;
|
||||
};
|
||||
|
||||
class CommandBufferBuilder : public Builder<CommandBufferBase> {
|
||||
public:
|
||||
CommandBufferBuilder(DeviceBase* device);
|
||||
~CommandBufferBuilder();
|
||||
public:
|
||||
CommandBufferBuilder(DeviceBase* device);
|
||||
~CommandBufferBuilder();
|
||||
|
||||
bool ValidateGetResult();
|
||||
bool ValidateGetResult();
|
||||
|
||||
CommandIterator AcquireCommands();
|
||||
CommandIterator AcquireCommands();
|
||||
|
||||
// NXT API
|
||||
void BeginComputePass();
|
||||
void BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer);
|
||||
void BeginRenderSubpass();
|
||||
void CopyBufferToBuffer(BufferBase* source, uint32_t sourceOffset, BufferBase* destination, uint32_t destinationOffset, uint32_t size);
|
||||
void CopyBufferToTexture(BufferBase* buffer, uint32_t bufferOffset, uint32_t rowPitch,
|
||||
TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
|
||||
uint32_t width, uint32_t height, uint32_t depth, uint32_t level);
|
||||
void CopyTextureToBuffer(TextureBase* texture, uint32_t x, uint32_t y, uint32_t z,
|
||||
uint32_t width, uint32_t height, uint32_t depth, uint32_t level,
|
||||
BufferBase* buffer, uint32_t bufferOffset, uint32_t rowPitch);
|
||||
void Dispatch(uint32_t x, uint32_t y, uint32_t z);
|
||||
void DrawArrays(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance);
|
||||
void DrawElements(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t firstInstance);
|
||||
void EndComputePass();
|
||||
void EndRenderPass();
|
||||
void EndRenderSubpass();
|
||||
void SetPushConstants(nxt::ShaderStageBit stages, uint32_t offset, uint32_t count, const void* data);
|
||||
void SetComputePipeline(ComputePipelineBase* pipeline);
|
||||
void SetRenderPipeline(RenderPipelineBase* pipeline);
|
||||
void SetStencilReference(uint32_t reference);
|
||||
void SetBlendColor(float r, float g, float b, float a);
|
||||
void SetBindGroup(uint32_t groupIndex, BindGroupBase* group);
|
||||
void SetIndexBuffer(BufferBase* buffer, uint32_t offset);
|
||||
// NXT API
|
||||
void BeginComputePass();
|
||||
void BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer);
|
||||
void BeginRenderSubpass();
|
||||
void CopyBufferToBuffer(BufferBase* source,
|
||||
uint32_t sourceOffset,
|
||||
BufferBase* destination,
|
||||
uint32_t destinationOffset,
|
||||
uint32_t size);
|
||||
void CopyBufferToTexture(BufferBase* buffer,
|
||||
uint32_t bufferOffset,
|
||||
uint32_t rowPitch,
|
||||
TextureBase* texture,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t z,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t depth,
|
||||
uint32_t level);
|
||||
void CopyTextureToBuffer(TextureBase* texture,
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t z,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t depth,
|
||||
uint32_t level,
|
||||
BufferBase* buffer,
|
||||
uint32_t bufferOffset,
|
||||
uint32_t rowPitch);
|
||||
void Dispatch(uint32_t x, uint32_t y, uint32_t z);
|
||||
void DrawArrays(uint32_t vertexCount,
|
||||
uint32_t instanceCount,
|
||||
uint32_t firstVertex,
|
||||
uint32_t firstInstance);
|
||||
void DrawElements(uint32_t vertexCount,
|
||||
uint32_t instanceCount,
|
||||
uint32_t firstIndex,
|
||||
uint32_t firstInstance);
|
||||
void EndComputePass();
|
||||
void EndRenderPass();
|
||||
void EndRenderSubpass();
|
||||
void SetPushConstants(nxt::ShaderStageBit stages,
|
||||
uint32_t offset,
|
||||
uint32_t count,
|
||||
const void* data);
|
||||
void SetComputePipeline(ComputePipelineBase* pipeline);
|
||||
void SetRenderPipeline(RenderPipelineBase* pipeline);
|
||||
void SetStencilReference(uint32_t reference);
|
||||
void SetBlendColor(float r, float g, float b, float a);
|
||||
void SetBindGroup(uint32_t groupIndex, BindGroupBase* group);
|
||||
void SetIndexBuffer(BufferBase* buffer, uint32_t offset);
|
||||
|
||||
template<typename T>
|
||||
void SetVertexBuffers(uint32_t startSlot, uint32_t count, T* const* buffers, uint32_t const* offsets) {
|
||||
static_assert(std::is_base_of<BufferBase, T>::value, "");
|
||||
SetVertexBuffers(startSlot, count, reinterpret_cast<BufferBase* const*>(buffers), offsets);
|
||||
}
|
||||
void SetVertexBuffers(uint32_t startSlot, uint32_t count, BufferBase* const* buffers, uint32_t const* offsets);
|
||||
template <typename T>
|
||||
void SetVertexBuffers(uint32_t startSlot,
|
||||
uint32_t count,
|
||||
T* const* buffers,
|
||||
uint32_t const* offsets) {
|
||||
static_assert(std::is_base_of<BufferBase, T>::value, "");
|
||||
SetVertexBuffers(startSlot, count, reinterpret_cast<BufferBase* const*>(buffers),
|
||||
offsets);
|
||||
}
|
||||
void SetVertexBuffers(uint32_t startSlot,
|
||||
uint32_t count,
|
||||
BufferBase* const* buffers,
|
||||
uint32_t const* offsets);
|
||||
|
||||
void TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage);
|
||||
void TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage);
|
||||
void TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage);
|
||||
void TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage);
|
||||
|
||||
private:
|
||||
friend class CommandBufferBase;
|
||||
private:
|
||||
friend class CommandBufferBase;
|
||||
|
||||
CommandBufferBase* GetResultImpl() override;
|
||||
void MoveToIterator();
|
||||
CommandBufferBase* GetResultImpl() override;
|
||||
void MoveToIterator();
|
||||
|
||||
std::unique_ptr<CommandBufferStateTracker> mState;
|
||||
CommandAllocator mAllocator;
|
||||
CommandIterator mIterator;
|
||||
bool mWasMovedToIterator = false;
|
||||
bool mWereCommandsAcquired = false;
|
||||
std::unique_ptr<CommandBufferStateTracker> mState;
|
||||
CommandAllocator mAllocator;
|
||||
CommandIterator mIterator;
|
||||
bool mWasMovedToIterator = false;
|
||||
bool mWereCommandsAcquired = false;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_COMMANDBUFFER_H_
|
||||
#endif // BACKEND_COMMANDBUFFER_H_
|
||||
|
@ -14,11 +14,11 @@
|
||||
|
||||
#include "backend/CommandBufferStateTracker.h"
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/BindGroup.h"
|
||||
#include "backend/BindGroupLayout.h"
|
||||
#include "backend/Buffer.h"
|
||||
#include "backend/ComputePipeline.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Framebuffer.h"
|
||||
#include "backend/InputState.h"
|
||||
#include "backend/PipelineLayout.h"
|
||||
@ -49,7 +49,8 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::ValidateCanUseBufferAs(BufferBase* buffer, nxt::BufferUsageBit usage) const {
|
||||
bool CommandBufferStateTracker::ValidateCanUseBufferAs(BufferBase* buffer,
|
||||
nxt::BufferUsageBit usage) const {
|
||||
if (!BufferHasGuaranteedUsageBit(buffer, usage)) {
|
||||
mBuilder->HandleError("Buffer is not in the necessary usage");
|
||||
return false;
|
||||
@ -57,7 +58,8 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::ValidateCanUseTextureAs(TextureBase* texture, nxt::TextureUsageBit usage) const {
|
||||
bool CommandBufferStateTracker::ValidateCanUseTextureAs(TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) const {
|
||||
if (!TextureHasGuaranteedUsageBit(texture, usage)) {
|
||||
mBuilder->HandleError("Texture is not in the necessary usage");
|
||||
return false;
|
||||
@ -67,7 +69,7 @@ namespace backend {
|
||||
|
||||
bool CommandBufferStateTracker::ValidateCanDispatch() {
|
||||
constexpr ValidationAspects requiredAspects =
|
||||
1 << VALIDATION_ASPECT_COMPUTE_PIPELINE | // implicitly requires COMPUTE_PASS
|
||||
1 << VALIDATION_ASPECT_COMPUTE_PIPELINE | // implicitly requires COMPUTE_PASS
|
||||
1 << VALIDATION_ASPECT_BIND_GROUPS;
|
||||
if ((requiredAspects & ~mAspects).none()) {
|
||||
// Fast return-true path if everything is good
|
||||
@ -89,9 +91,8 @@ namespace backend {
|
||||
bool CommandBufferStateTracker::ValidateCanDrawArrays() {
|
||||
// TODO(kainino@chromium.org): Check for a current render pass
|
||||
constexpr ValidationAspects requiredAspects =
|
||||
1 << VALIDATION_ASPECT_RENDER_PIPELINE | // implicitly requires RENDER_SUBPASS
|
||||
1 << VALIDATION_ASPECT_BIND_GROUPS |
|
||||
1 << VALIDATION_ASPECT_VERTEX_BUFFERS;
|
||||
1 << VALIDATION_ASPECT_RENDER_PIPELINE | // implicitly requires RENDER_SUBPASS
|
||||
1 << VALIDATION_ASPECT_BIND_GROUPS | 1 << VALIDATION_ASPECT_VERTEX_BUFFERS;
|
||||
if ((requiredAspects & ~mAspects).none()) {
|
||||
// Fast return-true path if everything is good
|
||||
return true;
|
||||
@ -103,10 +104,8 @@ namespace backend {
|
||||
bool CommandBufferStateTracker::ValidateCanDrawElements() {
|
||||
// TODO(kainino@chromium.org): Check for a current render pass
|
||||
constexpr ValidationAspects requiredAspects =
|
||||
1 << VALIDATION_ASPECT_RENDER_PIPELINE |
|
||||
1 << VALIDATION_ASPECT_BIND_GROUPS |
|
||||
1 << VALIDATION_ASPECT_VERTEX_BUFFERS |
|
||||
1 << VALIDATION_ASPECT_INDEX_BUFFER;
|
||||
1 << VALIDATION_ASPECT_RENDER_PIPELINE | 1 << VALIDATION_ASPECT_BIND_GROUPS |
|
||||
1 << VALIDATION_ASPECT_VERTEX_BUFFERS | 1 << VALIDATION_ASPECT_INDEX_BUFFER;
|
||||
if ((requiredAspects & ~mAspects).none()) {
|
||||
// Fast return-true path if everything is good
|
||||
return true;
|
||||
@ -134,16 +133,19 @@ namespace backend {
|
||||
bool CommandBufferStateTracker::ValidateSetPushConstants(nxt::ShaderStageBit stages) {
|
||||
if (mAspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
|
||||
if (stages & ~nxt::ShaderStageBit::Compute) {
|
||||
mBuilder->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 (mAspects[VALIDATION_ASPECT_RENDER_SUBPASS]) {
|
||||
if (stages & ~(nxt::ShaderStageBit::Vertex | nxt::ShaderStageBit::Fragment)) {
|
||||
mBuilder->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 {
|
||||
mBuilder->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;
|
||||
@ -224,7 +226,8 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer) {
|
||||
bool CommandBufferStateTracker::BeginRenderPass(RenderPassBase* renderPass,
|
||||
FramebufferBase* framebuffer) {
|
||||
if (mAspects[VALIDATION_ASPECT_COMPUTE_PASS]) {
|
||||
mBuilder->HandleError("Cannot begin a render pass while a compute pass is active");
|
||||
return false;
|
||||
@ -338,7 +341,8 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage) {
|
||||
bool CommandBufferStateTracker::TransitionBufferUsage(BufferBase* buffer,
|
||||
nxt::BufferUsageBit usage) {
|
||||
if (!buffer->IsTransitionPossible(usage)) {
|
||||
if (buffer->IsFrozen()) {
|
||||
mBuilder->HandleError("Buffer transition not possible (usage is frozen)");
|
||||
@ -355,14 +359,17 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage) {
|
||||
bool CommandBufferStateTracker::TransitionTextureUsage(TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) {
|
||||
if (!IsExplicitTextureTransitionPossible(texture, usage)) {
|
||||
if (texture->IsFrozen()) {
|
||||
mBuilder->HandleError("Texture transition not possible (usage is frozen)");
|
||||
} else if (!TextureBase::IsUsagePossible(texture->GetAllowedUsage(), usage)) {
|
||||
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)");
|
||||
mBuilder->HandleError(
|
||||
"Texture transition not possible (texture is in use as a framebuffer "
|
||||
"attachment)");
|
||||
} else {
|
||||
mBuilder->HandleError("Texture transition not possible");
|
||||
}
|
||||
@ -374,7 +381,8 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::EnsureTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage) {
|
||||
bool CommandBufferStateTracker::EnsureTextureUsage(TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) {
|
||||
if (texture->HasFrozenUsage(usage)) {
|
||||
return true;
|
||||
}
|
||||
@ -386,7 +394,8 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::BufferHasGuaranteedUsageBit(BufferBase* buffer, nxt::BufferUsageBit usage) const {
|
||||
bool CommandBufferStateTracker::BufferHasGuaranteedUsageBit(BufferBase* buffer,
|
||||
nxt::BufferUsageBit usage) const {
|
||||
ASSERT(usage != nxt::BufferUsageBit::None && nxt::HasZeroOrOneBits(usage));
|
||||
if (buffer->HasFrozenUsage(usage)) {
|
||||
return true;
|
||||
@ -395,7 +404,8 @@ namespace backend {
|
||||
return it != mMostRecentBufferUsages.end() && (it->second & usage);
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::TextureHasGuaranteedUsageBit(TextureBase* texture, nxt::TextureUsageBit usage) const {
|
||||
bool CommandBufferStateTracker::TextureHasGuaranteedUsageBit(TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) const {
|
||||
ASSERT(usage != nxt::TextureUsageBit::None && nxt::HasZeroOrOneBits(usage));
|
||||
if (texture->HasFrozenUsage(usage)) {
|
||||
return true;
|
||||
@ -404,7 +414,9 @@ namespace backend {
|
||||
return it != mMostRecentTextureUsages.end() && (it->second & usage);
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::IsInternalTextureTransitionPossible(TextureBase* texture, nxt::TextureUsageBit usage) const {
|
||||
bool CommandBufferStateTracker::IsInternalTextureTransitionPossible(
|
||||
TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) const {
|
||||
ASSERT(usage != nxt::TextureUsageBit::None && nxt::HasZeroOrOneBits(usage));
|
||||
if (mTexturesAttached.find(texture) != mTexturesAttached.end()) {
|
||||
return false;
|
||||
@ -412,9 +424,10 @@ namespace backend {
|
||||
return texture->IsTransitionPossible(usage);
|
||||
}
|
||||
|
||||
bool CommandBufferStateTracker::IsExplicitTextureTransitionPossible(TextureBase* texture, nxt::TextureUsageBit usage) const {
|
||||
const nxt::TextureUsageBit attachmentUsages =
|
||||
nxt::TextureUsageBit::OutputAttachment;
|
||||
bool CommandBufferStateTracker::IsExplicitTextureTransitionPossible(
|
||||
TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) const {
|
||||
const nxt::TextureUsageBit attachmentUsages = nxt::TextureUsageBit::OutputAttachment;
|
||||
if (usage & attachmentUsages) {
|
||||
return false;
|
||||
}
|
||||
@ -456,8 +469,7 @@ namespace backend {
|
||||
|
||||
bool CommandBufferStateTracker::HavePipeline() const {
|
||||
constexpr ValidationAspects pipelineAspects =
|
||||
1 << VALIDATION_ASPECT_COMPUTE_PIPELINE |
|
||||
1 << VALIDATION_ASPECT_RENDER_PIPELINE;
|
||||
1 << VALIDATION_ASPECT_COMPUTE_PIPELINE | 1 << VALIDATION_ASPECT_RENDER_PIPELINE;
|
||||
return (mAspects & pipelineAspects).any();
|
||||
}
|
||||
|
||||
@ -471,40 +483,36 @@ namespace backend {
|
||||
nxt::BindingType type = layoutInfo.types[i];
|
||||
switch (type) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
{
|
||||
nxt::BufferUsageBit requiredUsage = nxt::BufferUsageBit::None;
|
||||
switch (type) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
requiredUsage = nxt::BufferUsageBit::Uniform;
|
||||
break;
|
||||
case nxt::BindingType::StorageBuffer: {
|
||||
nxt::BufferUsageBit requiredUsage = nxt::BufferUsageBit::None;
|
||||
switch (type) {
|
||||
case nxt::BindingType::UniformBuffer:
|
||||
requiredUsage = nxt::BufferUsageBit::Uniform;
|
||||
break;
|
||||
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
requiredUsage = nxt::BufferUsageBit::Storage;
|
||||
break;
|
||||
case nxt::BindingType::StorageBuffer:
|
||||
requiredUsage = nxt::BufferUsageBit::Storage;
|
||||
break;
|
||||
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
auto buffer = group->GetBindingAsBufferView(i)->GetBuffer();
|
||||
if (!BufferHasGuaranteedUsageBit(buffer, requiredUsage)) {
|
||||
mBuilder->HandleError("Can't guarantee buffer usage needed by bind group");
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
case nxt::BindingType::SampledTexture:
|
||||
{
|
||||
auto requiredUsage = nxt::TextureUsageBit::Sampled;
|
||||
|
||||
auto texture = group->GetBindingAsTextureView(i)->GetTexture();
|
||||
if (!TextureHasGuaranteedUsageBit(texture, requiredUsage)) {
|
||||
mBuilder->HandleError("Can't guarantee texture usage needed by bind group");
|
||||
return false;
|
||||
}
|
||||
auto buffer = group->GetBindingAsBufferView(i)->GetBuffer();
|
||||
if (!BufferHasGuaranteedUsageBit(buffer, requiredUsage)) {
|
||||
mBuilder->HandleError("Can't guarantee buffer usage needed by bind group");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case nxt::BindingType::SampledTexture: {
|
||||
auto requiredUsage = nxt::TextureUsageBit::Sampled;
|
||||
|
||||
auto texture = group->GetBindingAsTextureView(i)->GetTexture();
|
||||
if (!TextureHasGuaranteedUsageBit(texture, requiredUsage)) {
|
||||
mBuilder->HandleError("Can't guarantee texture usage needed by bind group");
|
||||
return false;
|
||||
}
|
||||
} break;
|
||||
case nxt::BindingType::Sampler:
|
||||
continue;
|
||||
}
|
||||
@ -547,12 +555,10 @@ namespace backend {
|
||||
|
||||
void CommandBufferStateTracker::UnsetPipeline() {
|
||||
constexpr ValidationAspects pipelineDependentAspects =
|
||||
1 << VALIDATION_ASPECT_RENDER_PIPELINE |
|
||||
1 << VALIDATION_ASPECT_COMPUTE_PIPELINE |
|
||||
1 << VALIDATION_ASPECT_BIND_GROUPS |
|
||||
1 << VALIDATION_ASPECT_VERTEX_BUFFERS |
|
||||
1 << VALIDATION_ASPECT_RENDER_PIPELINE | 1 << VALIDATION_ASPECT_COMPUTE_PIPELINE |
|
||||
1 << VALIDATION_ASPECT_BIND_GROUPS | 1 << VALIDATION_ASPECT_VERTEX_BUFFERS |
|
||||
1 << VALIDATION_ASPECT_INDEX_BUFFER;
|
||||
mAspects &= ~pipelineDependentAspects;
|
||||
mBindgroups.fill(nullptr);
|
||||
}
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -25,92 +25,94 @@
|
||||
|
||||
namespace backend {
|
||||
class CommandBufferStateTracker {
|
||||
public:
|
||||
explicit CommandBufferStateTracker(CommandBufferBuilder* builder);
|
||||
public:
|
||||
explicit CommandBufferStateTracker(CommandBufferBuilder* builder);
|
||||
|
||||
// Non-state-modifying validation functions
|
||||
bool HaveRenderPass() const;
|
||||
bool HaveRenderSubpass() const;
|
||||
bool ValidateCanCopy() const;
|
||||
bool ValidateCanUseBufferAs(BufferBase* buffer, nxt::BufferUsageBit usage) const;
|
||||
bool ValidateCanUseTextureAs(TextureBase* texture, nxt::TextureUsageBit usage) const;
|
||||
bool ValidateCanDispatch();
|
||||
bool ValidateCanDrawArrays();
|
||||
bool ValidateCanDrawElements();
|
||||
bool ValidateEndCommandBuffer() const;
|
||||
bool ValidateSetPushConstants(nxt::ShaderStageBit stages);
|
||||
// Non-state-modifying validation functions
|
||||
bool HaveRenderPass() const;
|
||||
bool HaveRenderSubpass() const;
|
||||
bool ValidateCanCopy() const;
|
||||
bool ValidateCanUseBufferAs(BufferBase* buffer, nxt::BufferUsageBit usage) const;
|
||||
bool ValidateCanUseTextureAs(TextureBase* texture, nxt::TextureUsageBit usage) const;
|
||||
bool ValidateCanDispatch();
|
||||
bool ValidateCanDrawArrays();
|
||||
bool ValidateCanDrawElements();
|
||||
bool ValidateEndCommandBuffer() const;
|
||||
bool ValidateSetPushConstants(nxt::ShaderStageBit stages);
|
||||
|
||||
// State-modifying methods
|
||||
bool BeginComputePass();
|
||||
bool EndComputePass();
|
||||
bool BeginSubpass();
|
||||
bool EndSubpass();
|
||||
bool BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer);
|
||||
bool EndRenderPass();
|
||||
bool SetComputePipeline(ComputePipelineBase* pipeline);
|
||||
bool SetRenderPipeline(RenderPipelineBase* pipeline);
|
||||
bool SetBindGroup(uint32_t index, BindGroupBase* bindgroup);
|
||||
bool SetIndexBuffer(BufferBase* buffer);
|
||||
bool SetVertexBuffer(uint32_t index, BufferBase* buffer);
|
||||
bool TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage);
|
||||
bool TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage);
|
||||
bool EnsureTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage);
|
||||
// State-modifying methods
|
||||
bool BeginComputePass();
|
||||
bool EndComputePass();
|
||||
bool BeginSubpass();
|
||||
bool EndSubpass();
|
||||
bool BeginRenderPass(RenderPassBase* renderPass, FramebufferBase* framebuffer);
|
||||
bool EndRenderPass();
|
||||
bool SetComputePipeline(ComputePipelineBase* pipeline);
|
||||
bool SetRenderPipeline(RenderPipelineBase* pipeline);
|
||||
bool SetBindGroup(uint32_t index, BindGroupBase* bindgroup);
|
||||
bool SetIndexBuffer(BufferBase* buffer);
|
||||
bool SetVertexBuffer(uint32_t index, BufferBase* buffer);
|
||||
bool TransitionBufferUsage(BufferBase* buffer, nxt::BufferUsageBit usage);
|
||||
bool TransitionTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage);
|
||||
bool EnsureTextureUsage(TextureBase* texture, nxt::TextureUsageBit usage);
|
||||
|
||||
// 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*> mBuffersTransitioned;
|
||||
std::set<TextureBase*> mTexturesTransitioned;
|
||||
std::set<TextureBase*> mTexturesAttached;
|
||||
// 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*> mBuffersTransitioned;
|
||||
std::set<TextureBase*> mTexturesTransitioned;
|
||||
std::set<TextureBase*> mTexturesAttached;
|
||||
|
||||
private:
|
||||
enum ValidationAspect {
|
||||
VALIDATION_ASPECT_RENDER_PIPELINE,
|
||||
VALIDATION_ASPECT_COMPUTE_PIPELINE,
|
||||
VALIDATION_ASPECT_BIND_GROUPS,
|
||||
VALIDATION_ASPECT_VERTEX_BUFFERS,
|
||||
VALIDATION_ASPECT_INDEX_BUFFER,
|
||||
VALIDATION_ASPECT_RENDER_SUBPASS,
|
||||
VALIDATION_ASPECT_COMPUTE_PASS,
|
||||
private:
|
||||
enum ValidationAspect {
|
||||
VALIDATION_ASPECT_RENDER_PIPELINE,
|
||||
VALIDATION_ASPECT_COMPUTE_PIPELINE,
|
||||
VALIDATION_ASPECT_BIND_GROUPS,
|
||||
VALIDATION_ASPECT_VERTEX_BUFFERS,
|
||||
VALIDATION_ASPECT_INDEX_BUFFER,
|
||||
VALIDATION_ASPECT_RENDER_SUBPASS,
|
||||
VALIDATION_ASPECT_COMPUTE_PASS,
|
||||
|
||||
VALIDATION_ASPECT_COUNT
|
||||
};
|
||||
using ValidationAspects = std::bitset<VALIDATION_ASPECT_COUNT>;
|
||||
VALIDATION_ASPECT_COUNT
|
||||
};
|
||||
using ValidationAspects = std::bitset<VALIDATION_ASPECT_COUNT>;
|
||||
|
||||
// Usage helper functions
|
||||
bool BufferHasGuaranteedUsageBit(BufferBase* buffer, nxt::BufferUsageBit usage) const;
|
||||
bool TextureHasGuaranteedUsageBit(TextureBase* texture, nxt::TextureUsageBit usage) const;
|
||||
bool IsInternalTextureTransitionPossible(TextureBase* texture, nxt::TextureUsageBit usage) const;
|
||||
bool IsExplicitTextureTransitionPossible(TextureBase* texture, nxt::TextureUsageBit usage) const;
|
||||
// Usage helper functions
|
||||
bool BufferHasGuaranteedUsageBit(BufferBase* buffer, nxt::BufferUsageBit usage) const;
|
||||
bool TextureHasGuaranteedUsageBit(TextureBase* texture, nxt::TextureUsageBit usage) const;
|
||||
bool IsInternalTextureTransitionPossible(TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) const;
|
||||
bool IsExplicitTextureTransitionPossible(TextureBase* texture,
|
||||
nxt::TextureUsageBit usage) const;
|
||||
|
||||
// Queries for lazily evaluated aspects
|
||||
bool RecomputeHaveAspectBindGroups();
|
||||
bool RecomputeHaveAspectVertexBuffers();
|
||||
// Queries for lazily evaluated aspects
|
||||
bool RecomputeHaveAspectBindGroups();
|
||||
bool RecomputeHaveAspectVertexBuffers();
|
||||
|
||||
bool HavePipeline() const;
|
||||
bool ValidateBindGroupUsages(BindGroupBase* group) const;
|
||||
bool RevalidateCanDraw();
|
||||
bool HavePipeline() const;
|
||||
bool ValidateBindGroupUsages(BindGroupBase* group) const;
|
||||
bool RevalidateCanDraw();
|
||||
|
||||
void SetPipelineCommon(PipelineBase* pipeline);
|
||||
void UnsetPipeline();
|
||||
void SetPipelineCommon(PipelineBase* pipeline);
|
||||
void UnsetPipeline();
|
||||
|
||||
CommandBufferBuilder* mBuilder;
|
||||
CommandBufferBuilder* mBuilder;
|
||||
|
||||
ValidationAspects mAspects;
|
||||
ValidationAspects mAspects;
|
||||
|
||||
std::bitset<kMaxBindGroups> mBindgroupsSet;
|
||||
std::array<BindGroupBase*, kMaxBindGroups> mBindgroups = {};
|
||||
std::bitset<kMaxVertexInputs> mInputsSet;
|
||||
PipelineBase* mLastPipeline = nullptr;
|
||||
RenderPipelineBase* mLastRenderPipeline = 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> mMostRecentBufferUsages;
|
||||
std::map<TextureBase*, nxt::TextureUsageBit> mMostRecentTextureUsages;
|
||||
std::map<BufferBase*, nxt::BufferUsageBit> mMostRecentBufferUsages;
|
||||
std::map<TextureBase*, nxt::TextureUsageBit> mMostRecentTextureUsages;
|
||||
|
||||
RenderPassBase* mCurrentRenderPass = nullptr;
|
||||
FramebufferBase* mCurrentFramebuffer = nullptr;
|
||||
uint32_t mCurrentSubpass = 0;
|
||||
RenderPassBase* mCurrentRenderPass = nullptr;
|
||||
FramebufferBase* mCurrentFramebuffer = nullptr;
|
||||
uint32_t mCurrentSubpass = 0;
|
||||
};
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_COMMANDBUFFERSTATETRACKER_H
|
||||
#endif // BACKEND_COMMANDBUFFERSTATETRACKER_H
|
||||
|
@ -52,16 +52,14 @@ namespace backend {
|
||||
TransitionTextureUsage,
|
||||
};
|
||||
|
||||
struct BeginComputePassCmd {
|
||||
};
|
||||
struct BeginComputePassCmd {};
|
||||
|
||||
struct BeginRenderPassCmd {
|
||||
Ref<RenderPassBase> renderPass;
|
||||
Ref<FramebufferBase> framebuffer;
|
||||
};
|
||||
|
||||
struct BeginRenderSubpassCmd {
|
||||
};
|
||||
struct BeginRenderSubpassCmd {};
|
||||
|
||||
struct BufferCopyLocation {
|
||||
Ref<BufferBase> buffer;
|
||||
@ -113,14 +111,11 @@ namespace backend {
|
||||
uint32_t firstInstance;
|
||||
};
|
||||
|
||||
struct EndComputePassCmd {
|
||||
};
|
||||
struct EndComputePassCmd {};
|
||||
|
||||
struct EndRenderPassCmd {
|
||||
};
|
||||
struct EndRenderPassCmd {};
|
||||
|
||||
struct EndRenderSubpassCmd {
|
||||
};
|
||||
struct EndRenderSubpassCmd {};
|
||||
|
||||
struct SetComputePipelineCmd {
|
||||
Ref<ComputePipelineBase> pipeline;
|
||||
@ -176,6 +171,6 @@ namespace backend {
|
||||
void FreeCommands(CommandIterator* commands);
|
||||
void SkipCommand(CommandIterator* commands, Command type);
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_COMMANDS_H_
|
||||
#endif // BACKEND_COMMANDS_H_
|
||||
|
@ -38,4 +38,4 @@ namespace backend {
|
||||
return mDevice->CreateComputePipeline(this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -20,19 +20,18 @@
|
||||
namespace backend {
|
||||
|
||||
class ComputePipelineBase : public RefCounted, public PipelineBase {
|
||||
public:
|
||||
ComputePipelineBase(ComputePipelineBuilder* builder);
|
||||
|
||||
public:
|
||||
ComputePipelineBase(ComputePipelineBuilder* builder);
|
||||
};
|
||||
|
||||
class ComputePipelineBuilder : public Builder<ComputePipelineBase>, public PipelineBuilder {
|
||||
public:
|
||||
ComputePipelineBuilder(DeviceBase* device);
|
||||
public:
|
||||
ComputePipelineBuilder(DeviceBase* device);
|
||||
|
||||
private:
|
||||
ComputePipelineBase* GetResultImpl() override;
|
||||
private:
|
||||
ComputePipelineBase* GetResultImpl() override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_COMPUTEPIPELINE_H_
|
||||
#endif // BACKEND_COMPUTEPIPELINE_H_
|
||||
|
@ -26,13 +26,13 @@ namespace backend {
|
||||
|
||||
bool DepthStencilStateBase::StencilTestEnabled() const {
|
||||
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;
|
||||
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 {
|
||||
@ -60,7 +60,8 @@ namespace backend {
|
||||
return mDevice->CreateDepthStencilState(this);
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction) {
|
||||
void DepthStencilStateBuilder::SetDepthCompareFunction(
|
||||
nxt::CompareFunction depthCompareFunction) {
|
||||
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_DEPTH_COMPARE_FUNCTION) != 0) {
|
||||
HandleError("Depth compare property set multiple times");
|
||||
return;
|
||||
@ -82,8 +83,11 @@ namespace backend {
|
||||
mDepthInfo.depthWriteEnabled = enabled;
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetStencilFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction,
|
||||
nxt::StencilOperation stencilFail, nxt::StencilOperation depthFail, nxt::StencilOperation depthStencilPass) {\
|
||||
void DepthStencilStateBuilder::SetStencilFunction(nxt::Face face,
|
||||
nxt::CompareFunction stencilCompareFunction,
|
||||
nxt::StencilOperation stencilFail,
|
||||
nxt::StencilOperation depthFail,
|
||||
nxt::StencilOperation depthStencilPass) {
|
||||
if (face == nxt::Face::None) {
|
||||
HandleError("Can't set stencil function of None face");
|
||||
return;
|
||||
@ -118,7 +122,7 @@ namespace backend {
|
||||
}
|
||||
|
||||
void DepthStencilStateBuilder::SetStencilMask(uint32_t readMask, uint32_t writeMask) {
|
||||
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_MASK) != 0) {
|
||||
if ((mPropertiesSet & DEPTH_STENCIL_STATE_PROPERTY_STENCIL_MASK) != 0) {
|
||||
HandleError("Stencilmask property set multiple times");
|
||||
return;
|
||||
}
|
||||
@ -128,4 +132,4 @@ namespace backend {
|
||||
mStencilInfo.writeMask = writeMask;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,69 +15,71 @@
|
||||
#ifndef BACKEND_DEPTHSTENCILSTATE_H_
|
||||
#define BACKEND_DEPTHSTENCILSTATE_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
|
||||
namespace backend {
|
||||
|
||||
|
||||
class DepthStencilStateBase : public RefCounted {
|
||||
public:
|
||||
DepthStencilStateBase(DepthStencilStateBuilder* builder);
|
||||
public:
|
||||
DepthStencilStateBase(DepthStencilStateBuilder* builder);
|
||||
|
||||
struct DepthInfo {
|
||||
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always;
|
||||
bool depthWriteEnabled = false;
|
||||
};
|
||||
struct DepthInfo {
|
||||
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always;
|
||||
bool depthWriteEnabled = false;
|
||||
};
|
||||
|
||||
struct StencilFaceInfo {
|
||||
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always;
|
||||
nxt::StencilOperation stencilFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation depthFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation depthStencilPass = nxt::StencilOperation::Keep;
|
||||
};
|
||||
struct StencilFaceInfo {
|
||||
nxt::CompareFunction compareFunction = nxt::CompareFunction::Always;
|
||||
nxt::StencilOperation stencilFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation depthFail = nxt::StencilOperation::Keep;
|
||||
nxt::StencilOperation depthStencilPass = nxt::StencilOperation::Keep;
|
||||
};
|
||||
|
||||
struct StencilInfo {
|
||||
StencilFaceInfo back;
|
||||
StencilFaceInfo front;
|
||||
uint32_t readMask = 0xff;
|
||||
uint32_t writeMask = 0xff;
|
||||
};
|
||||
struct StencilInfo {
|
||||
StencilFaceInfo back;
|
||||
StencilFaceInfo front;
|
||||
uint32_t readMask = 0xff;
|
||||
uint32_t writeMask = 0xff;
|
||||
};
|
||||
|
||||
bool StencilTestEnabled() const;
|
||||
const DepthInfo& GetDepth() const;
|
||||
const StencilInfo& GetStencil() const;
|
||||
bool StencilTestEnabled() const;
|
||||
const DepthInfo& GetDepth() const;
|
||||
const StencilInfo& GetStencil() const;
|
||||
|
||||
private:
|
||||
DepthInfo mDepthInfo;
|
||||
StencilInfo mStencilInfo;
|
||||
private:
|
||||
DepthInfo mDepthInfo;
|
||||
StencilInfo mStencilInfo;
|
||||
};
|
||||
|
||||
class DepthStencilStateBuilder : public Builder<DepthStencilStateBase> {
|
||||
public:
|
||||
DepthStencilStateBuilder(DeviceBase* device);
|
||||
public:
|
||||
DepthStencilStateBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction);
|
||||
void SetDepthWriteEnabled(bool enabled);
|
||||
void SetStencilFunction(nxt::Face face, nxt::CompareFunction stencilCompareFunction,
|
||||
nxt::StencilOperation stencilFail, nxt::StencilOperation depthFail, nxt::StencilOperation depthStencilPass);
|
||||
void SetStencilMask(uint32_t readMask, uint32_t writeMask);
|
||||
// NXT API
|
||||
void SetDepthCompareFunction(nxt::CompareFunction depthCompareFunction);
|
||||
void SetDepthWriteEnabled(bool enabled);
|
||||
void SetStencilFunction(nxt::Face face,
|
||||
nxt::CompareFunction stencilCompareFunction,
|
||||
nxt::StencilOperation stencilFail,
|
||||
nxt::StencilOperation depthFail,
|
||||
nxt::StencilOperation depthStencilPass);
|
||||
void SetStencilMask(uint32_t readMask, uint32_t writeMask);
|
||||
|
||||
private:
|
||||
friend class DepthStencilStateBase;
|
||||
private:
|
||||
friend class DepthStencilStateBase;
|
||||
|
||||
DepthStencilStateBase* GetResultImpl() override;
|
||||
DepthStencilStateBase* GetResultImpl() override;
|
||||
|
||||
int mPropertiesSet = 0;
|
||||
int mPropertiesSet = 0;
|
||||
|
||||
DepthStencilStateBase::DepthInfo mDepthInfo;
|
||||
DepthStencilStateBase::StencilInfo mStencilInfo;
|
||||
DepthStencilStateBase::DepthInfo mDepthInfo;
|
||||
DepthStencilStateBase::StencilInfo mStencilInfo;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_DEPTHSTENCILSTATE_H_
|
||||
#endif // BACKEND_DEPTHSTENCILSTATE_H_
|
||||
|
@ -40,7 +40,8 @@ namespace backend {
|
||||
|
||||
// The caches are unordered_sets of pointers with special hash and compare functions
|
||||
// to compare the value of the objects, instead of the pointers.
|
||||
using BindGroupLayoutCache = std::unordered_set<BindGroupLayoutBase*, BindGroupLayoutCacheFuncs, BindGroupLayoutCacheFuncs>;
|
||||
using BindGroupLayoutCache = std::
|
||||
unordered_set<BindGroupLayoutBase*, BindGroupLayoutCacheFuncs, BindGroupLayoutCacheFuncs>;
|
||||
|
||||
struct DeviceBase::Caches {
|
||||
BindGroupLayoutCache bindGroupLayouts;
|
||||
@ -62,7 +63,8 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceBase::SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata) {
|
||||
void DeviceBase::SetErrorCallback(nxt::DeviceErrorCallback callback,
|
||||
nxt::CallbackUserdata userdata) {
|
||||
mErrorCallback = callback;
|
||||
mErrorUserdata = userdata;
|
||||
}
|
||||
@ -71,7 +73,9 @@ namespace backend {
|
||||
return this;
|
||||
}
|
||||
|
||||
BindGroupLayoutBase* DeviceBase::GetOrCreateBindGroupLayout(const BindGroupLayoutBase* blueprint, BindGroupLayoutBuilder* builder) {
|
||||
BindGroupLayoutBase* DeviceBase::GetOrCreateBindGroupLayout(
|
||||
const BindGroupLayoutBase* blueprint,
|
||||
BindGroupLayoutBuilder* builder) {
|
||||
// The blueprint is only used to search in the cache and is not modified. However cached
|
||||
// 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
|
||||
@ -159,4 +163,4 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -25,89 +25,91 @@ namespace backend {
|
||||
using ErrorCallback = void (*)(const char* errorMessage, void* userData);
|
||||
|
||||
class DeviceBase {
|
||||
public:
|
||||
DeviceBase();
|
||||
virtual ~DeviceBase();
|
||||
public:
|
||||
DeviceBase();
|
||||
virtual ~DeviceBase();
|
||||
|
||||
void HandleError(const char* message);
|
||||
void HandleError(const char* message);
|
||||
|
||||
// Used by autogenerated code, returns itself
|
||||
DeviceBase* GetDevice();
|
||||
// Used by autogenerated code, returns itself
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
virtual BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) = 0;
|
||||
virtual BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* builder) = 0;
|
||||
virtual BlendStateBase* CreateBlendState(BlendStateBuilder* builder) = 0;
|
||||
virtual BufferBase* CreateBuffer(BufferBuilder* builder) = 0;
|
||||
virtual BufferViewBase* CreateBufferView(BufferViewBuilder* builder) = 0;
|
||||
virtual CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) = 0;
|
||||
virtual ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) = 0;
|
||||
virtual DepthStencilStateBase* CreateDepthStencilState(DepthStencilStateBuilder* builder) = 0;
|
||||
virtual FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) = 0;
|
||||
virtual InputStateBase* CreateInputState(InputStateBuilder* builder) = 0;
|
||||
virtual PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) = 0;
|
||||
virtual QueueBase* CreateQueue(QueueBuilder* builder) = 0;
|
||||
virtual RenderPassBase* CreateRenderPass(RenderPassBuilder* builder) = 0;
|
||||
virtual RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) = 0;
|
||||
virtual SamplerBase* CreateSampler(SamplerBuilder* builder) = 0;
|
||||
virtual ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) = 0;
|
||||
virtual SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) = 0;
|
||||
virtual TextureBase* CreateTexture(TextureBuilder* builder) = 0;
|
||||
virtual TextureViewBase* CreateTextureView(TextureViewBuilder* builder) = 0;
|
||||
virtual BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) = 0;
|
||||
virtual BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* builder) = 0;
|
||||
virtual BlendStateBase* CreateBlendState(BlendStateBuilder* builder) = 0;
|
||||
virtual BufferBase* CreateBuffer(BufferBuilder* builder) = 0;
|
||||
virtual BufferViewBase* CreateBufferView(BufferViewBuilder* builder) = 0;
|
||||
virtual CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) = 0;
|
||||
virtual ComputePipelineBase* CreateComputePipeline(ComputePipelineBuilder* builder) = 0;
|
||||
virtual DepthStencilStateBase* CreateDepthStencilState(
|
||||
DepthStencilStateBuilder* builder) = 0;
|
||||
virtual FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) = 0;
|
||||
virtual InputStateBase* CreateInputState(InputStateBuilder* builder) = 0;
|
||||
virtual PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) = 0;
|
||||
virtual QueueBase* CreateQueue(QueueBuilder* builder) = 0;
|
||||
virtual RenderPassBase* CreateRenderPass(RenderPassBuilder* builder) = 0;
|
||||
virtual RenderPipelineBase* CreateRenderPipeline(RenderPipelineBuilder* builder) = 0;
|
||||
virtual SamplerBase* CreateSampler(SamplerBuilder* builder) = 0;
|
||||
virtual ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) = 0;
|
||||
virtual SwapChainBase* CreateSwapChain(SwapChainBuilder* builder) = 0;
|
||||
virtual TextureBase* CreateTexture(TextureBuilder* builder) = 0;
|
||||
virtual TextureViewBase* CreateTextureView(TextureViewBuilder* builder) = 0;
|
||||
|
||||
virtual void TickImpl() = 0;
|
||||
virtual void TickImpl() = 0;
|
||||
|
||||
// Many NXT objects are completely immutable once created which means that if two
|
||||
// builders are given the same arguments, they can return the same object. Reusing
|
||||
// objects will help make comparisons between objects by a single pointer comparison.
|
||||
//
|
||||
// Technically no object is immutable as they have a reference count, and an
|
||||
// application with reference-counting issues could "see" that objects are reused.
|
||||
// This is solved by automatic-reference counting, and also the fact that when using
|
||||
// the client-server wire every creation will get a different proxy object, with a
|
||||
// different reference count.
|
||||
//
|
||||
// When trying to create an object, we give both the builder and an example of what
|
||||
// the built object will be, the "blueprint". The blueprint is just a FooBase object
|
||||
// instead of a backend Foo object. If the blueprint doesn't match an object in the
|
||||
// cache, then the builder is used to make a new object.
|
||||
BindGroupLayoutBase* GetOrCreateBindGroupLayout(const BindGroupLayoutBase* blueprint, BindGroupLayoutBuilder* builder);
|
||||
void UncacheBindGroupLayout(BindGroupLayoutBase* obj);
|
||||
// Many NXT objects are completely immutable once created which means that if two
|
||||
// builders are given the same arguments, they can return the same object. Reusing
|
||||
// objects will help make comparisons between objects by a single pointer comparison.
|
||||
//
|
||||
// Technically no object is immutable as they have a reference count, and an
|
||||
// application with reference-counting issues could "see" that objects are reused.
|
||||
// This is solved by automatic-reference counting, and also the fact that when using
|
||||
// the client-server wire every creation will get a different proxy object, with a
|
||||
// different reference count.
|
||||
//
|
||||
// When trying to create an object, we give both the builder and an example of what
|
||||
// the built object will be, the "blueprint". The blueprint is just a FooBase object
|
||||
// instead of a backend Foo object. If the blueprint doesn't match an object in the
|
||||
// cache, then the builder is used to make a new object.
|
||||
BindGroupLayoutBase* GetOrCreateBindGroupLayout(const BindGroupLayoutBase* blueprint,
|
||||
BindGroupLayoutBuilder* builder);
|
||||
void UncacheBindGroupLayout(BindGroupLayoutBase* obj);
|
||||
|
||||
// NXT API
|
||||
BindGroupBuilder* CreateBindGroupBuilder();
|
||||
BindGroupLayoutBuilder* CreateBindGroupLayoutBuilder();
|
||||
BlendStateBuilder* CreateBlendStateBuilder();
|
||||
BufferBuilder* CreateBufferBuilder();
|
||||
CommandBufferBuilder* CreateCommandBufferBuilder();
|
||||
ComputePipelineBuilder* CreateComputePipelineBuilder();
|
||||
DepthStencilStateBuilder* CreateDepthStencilStateBuilder();
|
||||
FramebufferBuilder* CreateFramebufferBuilder();
|
||||
InputStateBuilder* CreateInputStateBuilder();
|
||||
PipelineLayoutBuilder* CreatePipelineLayoutBuilder();
|
||||
QueueBuilder* CreateQueueBuilder();
|
||||
RenderPassBuilder* CreateRenderPassBuilder();
|
||||
RenderPipelineBuilder* CreateRenderPipelineBuilder();
|
||||
SamplerBuilder* CreateSamplerBuilder();
|
||||
ShaderModuleBuilder* CreateShaderModuleBuilder();
|
||||
SwapChainBuilder* CreateSwapChainBuilder();
|
||||
TextureBuilder* CreateTextureBuilder();
|
||||
// NXT API
|
||||
BindGroupBuilder* CreateBindGroupBuilder();
|
||||
BindGroupLayoutBuilder* CreateBindGroupLayoutBuilder();
|
||||
BlendStateBuilder* CreateBlendStateBuilder();
|
||||
BufferBuilder* CreateBufferBuilder();
|
||||
CommandBufferBuilder* CreateCommandBufferBuilder();
|
||||
ComputePipelineBuilder* CreateComputePipelineBuilder();
|
||||
DepthStencilStateBuilder* CreateDepthStencilStateBuilder();
|
||||
FramebufferBuilder* CreateFramebufferBuilder();
|
||||
InputStateBuilder* CreateInputStateBuilder();
|
||||
PipelineLayoutBuilder* CreatePipelineLayoutBuilder();
|
||||
QueueBuilder* CreateQueueBuilder();
|
||||
RenderPassBuilder* CreateRenderPassBuilder();
|
||||
RenderPipelineBuilder* CreateRenderPipelineBuilder();
|
||||
SamplerBuilder* CreateSamplerBuilder();
|
||||
ShaderModuleBuilder* CreateShaderModuleBuilder();
|
||||
SwapChainBuilder* CreateSwapChainBuilder();
|
||||
TextureBuilder* CreateTextureBuilder();
|
||||
|
||||
void Tick();
|
||||
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata);
|
||||
void Reference();
|
||||
void Release();
|
||||
void Tick();
|
||||
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata);
|
||||
void Reference();
|
||||
void Release();
|
||||
|
||||
private:
|
||||
// The object caches aren't exposed in the header as they would require a lot of
|
||||
// additional includes.
|
||||
struct Caches;
|
||||
Caches* mCaches = nullptr;
|
||||
private:
|
||||
// The object caches aren't exposed in the header as they would require a lot of
|
||||
// additional includes.
|
||||
struct Caches;
|
||||
Caches* mCaches = nullptr;
|
||||
|
||||
nxt::DeviceErrorCallback mErrorCallback = nullptr;
|
||||
nxt::CallbackUserdata mErrorUserdata = 0;
|
||||
uint32_t mRefCount = 1;
|
||||
nxt::DeviceErrorCallback mErrorCallback = nullptr;
|
||||
nxt::CallbackUserdata mErrorUserdata = 0;
|
||||
uint32_t mRefCount = 1;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_DEVICEBASE_H_
|
||||
#endif // BACKEND_DEVICEBASE_H_
|
||||
|
@ -60,13 +60,13 @@ namespace backend {
|
||||
|
||||
class DeviceBase;
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class Ref;
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class PerStage;
|
||||
|
||||
enum PushConstantType : uint8_t;
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_FORWARD_H_
|
||||
#endif // BACKEND_FORWARD_H_
|
||||
|
@ -25,9 +25,13 @@ namespace backend {
|
||||
// Framebuffer
|
||||
|
||||
FramebufferBase::FramebufferBase(FramebufferBuilder* builder)
|
||||
: 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()) {
|
||||
: 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() {
|
||||
@ -48,7 +52,8 @@ namespace backend {
|
||||
return mClearColors[attachmentSlot];
|
||||
}
|
||||
|
||||
FramebufferBase::ClearDepthStencil FramebufferBase::GetClearDepthStencil(uint32_t attachmentSlot) {
|
||||
FramebufferBase::ClearDepthStencil FramebufferBase::GetClearDepthStencil(
|
||||
uint32_t attachmentSlot) {
|
||||
ASSERT(attachmentSlot < mClearDepthStencils.size());
|
||||
return mClearDepthStencils[attachmentSlot];
|
||||
}
|
||||
@ -61,7 +66,11 @@ namespace backend {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
void FramebufferBase::AttachmentSetClearColor(uint32_t attachmentSlot, float clearR, float clearG, float clearB, float clearA) {
|
||||
void FramebufferBase::AttachmentSetClearColor(uint32_t attachmentSlot,
|
||||
float clearR,
|
||||
float clearG,
|
||||
float clearB,
|
||||
float clearA) {
|
||||
if (attachmentSlot >= mRenderPass->GetAttachmentCount()) {
|
||||
mDevice->HandleError("Framebuffer attachment out of bounds");
|
||||
return;
|
||||
@ -74,7 +83,9 @@ namespace backend {
|
||||
c.color[3] = clearA;
|
||||
}
|
||||
|
||||
void FramebufferBase::AttachmentSetClearDepthStencil(uint32_t attachmentSlot, float clearDepth, uint32_t clearStencil) {
|
||||
void FramebufferBase::AttachmentSetClearDepthStencil(uint32_t attachmentSlot,
|
||||
float clearDepth,
|
||||
uint32_t clearStencil) {
|
||||
if (attachmentSlot >= mRenderPass->GetAttachmentCount()) {
|
||||
mDevice->HandleError("Framebuffer attachment out of bounds");
|
||||
return;
|
||||
@ -92,12 +103,12 @@ namespace backend {
|
||||
FRAMEBUFFER_PROPERTY_DIMENSIONS = 0x2,
|
||||
};
|
||||
|
||||
FramebufferBuilder::FramebufferBuilder(DeviceBase* device)
|
||||
: Builder(device) {
|
||||
FramebufferBuilder::FramebufferBuilder(DeviceBase* device) : Builder(device) {
|
||||
}
|
||||
|
||||
FramebufferBase* FramebufferBuilder::GetResultImpl() {
|
||||
constexpr int requiredProperties = FRAMEBUFFER_PROPERTY_RENDER_PASS | FRAMEBUFFER_PROPERTY_DIMENSIONS;
|
||||
constexpr int requiredProperties =
|
||||
FRAMEBUFFER_PROPERTY_RENDER_PASS | FRAMEBUFFER_PROPERTY_DIMENSIONS;
|
||||
if ((mPropertiesSet & requiredProperties) != requiredProperties) {
|
||||
HandleError("Framebuffer missing properties");
|
||||
return nullptr;
|
||||
@ -170,4 +181,4 @@ namespace backend {
|
||||
|
||||
mTextureViews[attachmentSlot] = textureView;
|
||||
}
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -27,60 +27,66 @@
|
||||
namespace backend {
|
||||
|
||||
class FramebufferBase : public RefCounted {
|
||||
public:
|
||||
struct ClearColor {
|
||||
float color[4] = {};
|
||||
};
|
||||
public:
|
||||
struct ClearColor {
|
||||
float color[4] = {};
|
||||
};
|
||||
|
||||
struct ClearDepthStencil {
|
||||
float depth = 1.0f;
|
||||
uint32_t stencil = 0;
|
||||
};
|
||||
struct ClearDepthStencil {
|
||||
float depth = 1.0f;
|
||||
uint32_t stencil = 0;
|
||||
};
|
||||
|
||||
FramebufferBase(FramebufferBuilder* builder);
|
||||
FramebufferBase(FramebufferBuilder* builder);
|
||||
|
||||
DeviceBase* GetDevice();
|
||||
RenderPassBase* GetRenderPass();
|
||||
TextureViewBase* GetTextureView(uint32_t attachmentSlot);
|
||||
ClearColor GetClearColor(uint32_t attachmentSlot);
|
||||
ClearDepthStencil GetClearDepthStencil(uint32_t attachmentSlot);
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetHeight() const;
|
||||
DeviceBase* GetDevice();
|
||||
RenderPassBase* GetRenderPass();
|
||||
TextureViewBase* GetTextureView(uint32_t attachmentSlot);
|
||||
ClearColor GetClearColor(uint32_t attachmentSlot);
|
||||
ClearDepthStencil GetClearDepthStencil(uint32_t attachmentSlot);
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetHeight() const;
|
||||
|
||||
// NXT API
|
||||
void AttachmentSetClearColor(uint32_t attachmentSlot, float clearR, float clearG, float clearB, float clearA);
|
||||
void AttachmentSetClearDepthStencil(uint32_t attachmentSlot, float clearDepth, uint32_t clearStencil);
|
||||
// NXT API
|
||||
void AttachmentSetClearColor(uint32_t attachmentSlot,
|
||||
float clearR,
|
||||
float clearG,
|
||||
float clearB,
|
||||
float clearA);
|
||||
void AttachmentSetClearDepthStencil(uint32_t attachmentSlot,
|
||||
float clearDepth,
|
||||
uint32_t clearStencil);
|
||||
|
||||
private:
|
||||
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;
|
||||
private:
|
||||
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> {
|
||||
public:
|
||||
FramebufferBuilder(DeviceBase* device);
|
||||
public:
|
||||
FramebufferBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
FramebufferBase* GetResultImpl() override;
|
||||
void SetRenderPass(RenderPassBase* renderPass);
|
||||
void SetDimensions(uint32_t width, uint32_t height);
|
||||
void SetAttachment(uint32_t attachmentSlot, TextureViewBase* textureView);
|
||||
// NXT API
|
||||
FramebufferBase* GetResultImpl() override;
|
||||
void SetRenderPass(RenderPassBase* renderPass);
|
||||
void SetDimensions(uint32_t width, uint32_t height);
|
||||
void SetAttachment(uint32_t attachmentSlot, TextureViewBase* textureView);
|
||||
|
||||
private:
|
||||
friend class FramebufferBase;
|
||||
private:
|
||||
friend class FramebufferBase;
|
||||
|
||||
Ref<RenderPassBase> mRenderPass;
|
||||
uint32_t mWidth = 0;
|
||||
uint32_t mHeight = 0;
|
||||
std::vector<Ref<TextureViewBase>> mTextureViews;
|
||||
int mPropertiesSet = 0;
|
||||
Ref<RenderPassBase> mRenderPass;
|
||||
uint32_t mWidth = 0;
|
||||
uint32_t mHeight = 0;
|
||||
std::vector<Ref<TextureViewBase>> mTextureViews;
|
||||
int mPropertiesSet = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_FRAMEBUFFER_H_
|
||||
#endif // BACKEND_FRAMEBUFFER_H_
|
||||
|
@ -94,7 +94,7 @@ namespace backend {
|
||||
InputStateBase* InputStateBuilder::GetResultImpl() {
|
||||
for (uint32_t location = 0; location < kMaxVertexAttributes; ++location) {
|
||||
if (mAttributesSetMask[location] &&
|
||||
!mInputsSetMask[mAttributeInfos[location].bindingSlot]) {
|
||||
!mInputsSetMask[mAttributeInfos[location].bindingSlot]) {
|
||||
HandleError("Attribute uses unset input");
|
||||
return nullptr;
|
||||
}
|
||||
@ -104,7 +104,9 @@ namespace backend {
|
||||
}
|
||||
|
||||
void InputStateBuilder::SetAttribute(uint32_t shaderLocation,
|
||||
uint32_t bindingSlot, nxt::VertexFormat format, uint32_t offset) {
|
||||
uint32_t bindingSlot,
|
||||
nxt::VertexFormat format,
|
||||
uint32_t offset) {
|
||||
if (shaderLocation >= kMaxVertexAttributes) {
|
||||
HandleError("Setting attribute out of bounds");
|
||||
return;
|
||||
@ -125,8 +127,9 @@ namespace backend {
|
||||
info.offset = offset;
|
||||
}
|
||||
|
||||
void InputStateBuilder::SetInput(uint32_t bindingSlot, uint32_t stride,
|
||||
nxt::InputStepMode stepMode) {
|
||||
void InputStateBuilder::SetInput(uint32_t bindingSlot,
|
||||
uint32_t stride,
|
||||
nxt::InputStepMode stepMode) {
|
||||
if (bindingSlot >= kMaxVertexInputs) {
|
||||
HandleError("Setting input out of bounds");
|
||||
return;
|
||||
@ -142,4 +145,4 @@ namespace backend {
|
||||
info.stepMode = stepMode;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_INPUTSTATE_H_
|
||||
#define BACKEND_INPUTSTATE_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
@ -32,53 +32,54 @@ namespace backend {
|
||||
size_t VertexFormatSize(nxt::VertexFormat format);
|
||||
|
||||
class InputStateBase : public RefCounted {
|
||||
public:
|
||||
InputStateBase(InputStateBuilder* builder);
|
||||
public:
|
||||
InputStateBase(InputStateBuilder* builder);
|
||||
|
||||
struct AttributeInfo {
|
||||
uint32_t bindingSlot;
|
||||
nxt::VertexFormat format;
|
||||
uint32_t offset;
|
||||
};
|
||||
struct AttributeInfo {
|
||||
uint32_t bindingSlot;
|
||||
nxt::VertexFormat format;
|
||||
uint32_t offset;
|
||||
};
|
||||
|
||||
struct InputInfo {
|
||||
uint32_t stride;
|
||||
nxt::InputStepMode stepMode;
|
||||
};
|
||||
struct InputInfo {
|
||||
uint32_t stride;
|
||||
nxt::InputStepMode stepMode;
|
||||
};
|
||||
|
||||
const std::bitset<kMaxVertexAttributes>& GetAttributesSetMask() const;
|
||||
const AttributeInfo& GetAttribute(uint32_t location) const;
|
||||
const std::bitset<kMaxVertexInputs>& GetInputsSetMask() const;
|
||||
const InputInfo& GetInput(uint32_t slot) const;
|
||||
const std::bitset<kMaxVertexAttributes>& GetAttributesSetMask() const;
|
||||
const AttributeInfo& GetAttribute(uint32_t location) const;
|
||||
const std::bitset<kMaxVertexInputs>& GetInputsSetMask() const;
|
||||
const InputInfo& GetInput(uint32_t slot) const;
|
||||
|
||||
private:
|
||||
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
|
||||
std::array<AttributeInfo, kMaxVertexAttributes> mAttributeInfos;
|
||||
std::bitset<kMaxVertexInputs> mInputsSetMask;
|
||||
std::array<InputInfo, kMaxVertexInputs> mInputInfos;
|
||||
private:
|
||||
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
|
||||
std::array<AttributeInfo, kMaxVertexAttributes> mAttributeInfos;
|
||||
std::bitset<kMaxVertexInputs> mInputsSetMask;
|
||||
std::array<InputInfo, kMaxVertexInputs> mInputInfos;
|
||||
};
|
||||
|
||||
class InputStateBuilder : public Builder<InputStateBase> {
|
||||
public:
|
||||
InputStateBuilder(DeviceBase* device);
|
||||
public:
|
||||
InputStateBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetAttribute(uint32_t shaderLocation, uint32_t bindingSlot,
|
||||
nxt::VertexFormat format, uint32_t offset);
|
||||
void SetInput(uint32_t bindingSlot, uint32_t stride,
|
||||
nxt::InputStepMode stepMode);
|
||||
// NXT API
|
||||
void SetAttribute(uint32_t shaderLocation,
|
||||
uint32_t bindingSlot,
|
||||
nxt::VertexFormat format,
|
||||
uint32_t offset);
|
||||
void SetInput(uint32_t bindingSlot, uint32_t stride, nxt::InputStepMode stepMode);
|
||||
|
||||
private:
|
||||
friend class InputStateBase;
|
||||
private:
|
||||
friend class InputStateBase;
|
||||
|
||||
InputStateBase* GetResultImpl() override;
|
||||
InputStateBase* GetResultImpl() override;
|
||||
|
||||
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
|
||||
std::array<InputStateBase::AttributeInfo, kMaxVertexAttributes> mAttributeInfos;
|
||||
std::bitset<kMaxVertexInputs> mInputsSetMask;
|
||||
std::array<InputStateBase::InputInfo, kMaxVertexInputs> mInputInfos;
|
||||
std::bitset<kMaxVertexAttributes> mAttributesSetMask;
|
||||
std::array<InputStateBase::AttributeInfo, kMaxVertexAttributes> mAttributeInfos;
|
||||
std::bitset<kMaxVertexInputs> mInputsSetMask;
|
||||
std::array<InputStateBase::InputInfo, kMaxVertexInputs> mInputInfos;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_INPUTSTATE_H_
|
||||
#endif // BACKEND_INPUTSTATE_H_
|
||||
|
@ -26,4 +26,4 @@ namespace backend {
|
||||
return static_cast<nxt::ShaderStageBit>(1 << static_cast<uint32_t>(stage));
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -29,42 +29,49 @@ namespace backend {
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Fragment) < kNumStages, "");
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Compute) < kNumStages, "");
|
||||
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Vertex) == (1 << static_cast<uint32_t>(nxt::ShaderStage::Vertex)), "");
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Fragment) == (1 << static_cast<uint32_t>(nxt::ShaderStage::Fragment)), "");
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Compute) == (1 << static_cast<uint32_t>(nxt::ShaderStage::Compute)), "");
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Vertex) ==
|
||||
(1 << static_cast<uint32_t>(nxt::ShaderStage::Vertex)),
|
||||
"");
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Fragment) ==
|
||||
(1 << static_cast<uint32_t>(nxt::ShaderStage::Fragment)),
|
||||
"");
|
||||
static_assert(static_cast<uint32_t>(nxt::ShaderStageBit::Compute) ==
|
||||
(1 << static_cast<uint32_t>(nxt::ShaderStage::Compute)),
|
||||
"");
|
||||
|
||||
BitSetIterator<kNumStages, nxt::ShaderStage> IterateStages(nxt::ShaderStageBit stages);
|
||||
nxt::ShaderStageBit StageBit(nxt::ShaderStage stage);
|
||||
|
||||
static constexpr nxt::ShaderStageBit kAllStages = static_cast<nxt::ShaderStageBit>((1 << kNumStages) - 1);
|
||||
static constexpr nxt::ShaderStageBit kAllStages =
|
||||
static_cast<nxt::ShaderStageBit>((1 << kNumStages) - 1);
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class PerStage {
|
||||
public:
|
||||
T& operator[](nxt::ShaderStage stage) {
|
||||
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
|
||||
return mData[static_cast<uint32_t>(stage)];
|
||||
}
|
||||
const T& operator[](nxt::ShaderStage stage) const {
|
||||
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
|
||||
return mData[static_cast<uint32_t>(stage)];
|
||||
}
|
||||
public:
|
||||
T& operator[](nxt::ShaderStage stage) {
|
||||
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
|
||||
return mData[static_cast<uint32_t>(stage)];
|
||||
}
|
||||
const T& operator[](nxt::ShaderStage stage) const {
|
||||
NXT_ASSERT(static_cast<uint32_t>(stage) < kNumStages);
|
||||
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 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 mData[Log2(bit)];
|
||||
}
|
||||
T& operator[](nxt::ShaderStageBit stageBit) {
|
||||
uint32_t bit = static_cast<uint32_t>(stageBit);
|
||||
NXT_ASSERT(bit != 0 && IsPowerOfTwo(bit) && bit <= (1 << kNumStages));
|
||||
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 mData[Log2(bit)];
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<T, kNumStages> mData;
|
||||
private:
|
||||
std::array<T, kNumStages> mData;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_PERSTAGE_H_
|
||||
#endif // BACKEND_PERSTAGE_H_
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
#include "backend/Pipeline.h"
|
||||
|
||||
#include "backend/Device.h"
|
||||
#include "backend/DepthStencilState.h"
|
||||
#include "backend/Device.h"
|
||||
#include "backend/InputState.h"
|
||||
#include "backend/PipelineLayout.h"
|
||||
#include "backend/RenderPass.h"
|
||||
@ -28,7 +28,10 @@ namespace backend {
|
||||
PipelineBase::PipelineBase(PipelineBuilder* builder)
|
||||
: mStageMask(builder->mStageMask), mLayout(std::move(builder->mLayout)) {
|
||||
if (!mLayout) {
|
||||
mLayout = builder->GetParentBuilder()->GetDevice()->CreatePipelineLayoutBuilder()->GetResult();
|
||||
mLayout = builder->GetParentBuilder()
|
||||
->GetDevice()
|
||||
->CreatePipelineLayoutBuilder()
|
||||
->GetResult();
|
||||
}
|
||||
|
||||
auto FillPushConstants = [](const ShaderModuleBase* module, PushConstantInfo* info) {
|
||||
@ -58,7 +61,8 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
const PipelineBase::PushConstantInfo& PipelineBase::GetPushConstants(nxt::ShaderStage stage) const {
|
||||
const PipelineBase::PushConstantInfo& PipelineBase::GetPushConstants(
|
||||
nxt::ShaderStage stage) const {
|
||||
return mPushConstants[stage];
|
||||
}
|
||||
|
||||
@ -89,7 +93,9 @@ namespace backend {
|
||||
mLayout = layout;
|
||||
}
|
||||
|
||||
void PipelineBuilder::SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint) {
|
||||
void PipelineBuilder::SetStage(nxt::ShaderStage stage,
|
||||
ShaderModuleBase* module,
|
||||
const char* entryPoint) {
|
||||
if (entryPoint != std::string("main")) {
|
||||
mParentBuilder->HandleError("Currently the entry point has to be main()");
|
||||
return;
|
||||
@ -111,4 +117,4 @@ namespace backend {
|
||||
mStages[stage].entryPoint = entryPoint;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_PIPELINE_H_
|
||||
#define BACKEND_PIPELINE_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/PerStage.h"
|
||||
#include "backend/PipelineLayout.h"
|
||||
#include "backend/RefCounted.h"
|
||||
@ -38,48 +38,48 @@ namespace backend {
|
||||
class PipelineBuilder;
|
||||
|
||||
class PipelineBase {
|
||||
public:
|
||||
PipelineBase(PipelineBuilder* builder);
|
||||
public:
|
||||
PipelineBase(PipelineBuilder* builder);
|
||||
|
||||
struct PushConstantInfo {
|
||||
std::bitset<kMaxPushConstants> mask;
|
||||
std::array<PushConstantType, kMaxPushConstants> types;
|
||||
};
|
||||
const PushConstantInfo& GetPushConstants(nxt::ShaderStage stage) const;
|
||||
nxt::ShaderStageBit GetStageMask() const;
|
||||
struct PushConstantInfo {
|
||||
std::bitset<kMaxPushConstants> mask;
|
||||
std::array<PushConstantType, kMaxPushConstants> types;
|
||||
};
|
||||
const PushConstantInfo& GetPushConstants(nxt::ShaderStage stage) const;
|
||||
nxt::ShaderStageBit GetStageMask() const;
|
||||
|
||||
PipelineLayoutBase* GetLayout();
|
||||
PipelineLayoutBase* GetLayout();
|
||||
|
||||
private:
|
||||
nxt::ShaderStageBit mStageMask;
|
||||
Ref<PipelineLayoutBase> mLayout;
|
||||
PerStage<PushConstantInfo> mPushConstants;
|
||||
private:
|
||||
nxt::ShaderStageBit mStageMask;
|
||||
Ref<PipelineLayoutBase> mLayout;
|
||||
PerStage<PushConstantInfo> mPushConstants;
|
||||
};
|
||||
|
||||
class PipelineBuilder {
|
||||
public:
|
||||
PipelineBuilder(BuilderBase* parentBuilder);
|
||||
public:
|
||||
PipelineBuilder(BuilderBase* parentBuilder);
|
||||
|
||||
struct StageInfo {
|
||||
std::string entryPoint;
|
||||
Ref<ShaderModuleBase> module;
|
||||
};
|
||||
const StageInfo& GetStageInfo(nxt::ShaderStage stage) const;
|
||||
BuilderBase* GetParentBuilder() const;
|
||||
struct StageInfo {
|
||||
std::string entryPoint;
|
||||
Ref<ShaderModuleBase> module;
|
||||
};
|
||||
const StageInfo& GetStageInfo(nxt::ShaderStage stage) const;
|
||||
BuilderBase* GetParentBuilder() const;
|
||||
|
||||
// NXT API
|
||||
void SetLayout(PipelineLayoutBase* layout);
|
||||
void SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint);
|
||||
// NXT API
|
||||
void SetLayout(PipelineLayoutBase* layout);
|
||||
void SetStage(nxt::ShaderStage stage, ShaderModuleBase* module, const char* entryPoint);
|
||||
|
||||
private:
|
||||
friend class PipelineBase;
|
||||
private:
|
||||
friend class PipelineBase;
|
||||
|
||||
BuilderBase* mParentBuilder;
|
||||
Ref<PipelineLayoutBase> mLayout;
|
||||
nxt::ShaderStageBit mStageMask;
|
||||
PerStage<StageInfo> mStages;
|
||||
BuilderBase* mParentBuilder;
|
||||
Ref<PipelineLayoutBase> mLayout;
|
||||
nxt::ShaderStageBit mStageMask;
|
||||
PerStage<StageInfo> mStages;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_PIPELINE_H_
|
||||
#endif // BACKEND_PIPELINE_H_
|
||||
|
@ -35,8 +35,9 @@ namespace backend {
|
||||
return mMask;
|
||||
}
|
||||
|
||||
std::bitset<kMaxBindGroups> PipelineLayoutBase::InheritedGroupsMask(const PipelineLayoutBase* other) const {
|
||||
return { GroupsInheritUpTo(other) - 1 };
|
||||
std::bitset<kMaxBindGroups> PipelineLayoutBase::InheritedGroupsMask(
|
||||
const PipelineLayoutBase* other) const {
|
||||
return {GroupsInheritUpTo(other) - 1};
|
||||
}
|
||||
|
||||
uint32_t PipelineLayoutBase::GroupsInheritUpTo(const PipelineLayoutBase* other) const {
|
||||
@ -54,8 +55,8 @@ namespace backend {
|
||||
}
|
||||
|
||||
PipelineLayoutBase* PipelineLayoutBuilder::GetResultImpl() {
|
||||
// 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
|
||||
// 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 (!mBindGroupLayouts[group]) {
|
||||
mBindGroupLayouts[group] = mDevice->CreateBindGroupLayoutBuilder()->GetResult();
|
||||
@ -65,7 +66,8 @@ namespace backend {
|
||||
return mDevice->CreatePipelineLayout(this);
|
||||
}
|
||||
|
||||
void PipelineLayoutBuilder::SetBindGroupLayout(uint32_t groupIndex, BindGroupLayoutBase* layout) {
|
||||
void PipelineLayoutBuilder::SetBindGroupLayout(uint32_t groupIndex,
|
||||
BindGroupLayoutBase* layout) {
|
||||
if (groupIndex >= kMaxBindGroups) {
|
||||
HandleError("groupIndex is over the maximum allowed");
|
||||
return;
|
||||
@ -79,4 +81,4 @@ namespace backend {
|
||||
mMask.set(groupIndex);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_PIPELINELAYOUT_H_
|
||||
#define BACKEND_PIPELINELAYOUT_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
@ -30,40 +30,41 @@ namespace backend {
|
||||
using BindGroupLayoutArray = std::array<Ref<BindGroupLayoutBase>, kMaxBindGroups>;
|
||||
|
||||
class PipelineLayoutBase : public RefCounted {
|
||||
public:
|
||||
PipelineLayoutBase(PipelineLayoutBuilder* builder);
|
||||
public:
|
||||
PipelineLayoutBase(PipelineLayoutBuilder* builder);
|
||||
|
||||
const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const;
|
||||
const std::bitset<kMaxBindGroups> GetBindGroupsLayoutMask() const;
|
||||
const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const;
|
||||
const std::bitset<kMaxBindGroups> GetBindGroupsLayoutMask() const;
|
||||
|
||||
// Utility functions to compute inherited bind groups.
|
||||
// Returns the inherited bind groups as a mask
|
||||
std::bitset<kMaxBindGroups> InheritedGroupsMask(const PipelineLayoutBase* other) const;
|
||||
// Utility functions to compute inherited bind groups.
|
||||
// Returns the inherited bind groups as a mask.
|
||||
std::bitset<kMaxBindGroups> InheritedGroupsMask(const PipelineLayoutBase* other) const;
|
||||
|
||||
// Returns the index of the first incompatible bind group (in the range [1, kMaxBindGroups + 1])
|
||||
uint32_t GroupsInheritUpTo(const PipelineLayoutBase* other) const;
|
||||
// Returns the index of the first incompatible bind group in the range
|
||||
// [1, kMaxBindGroups + 1]
|
||||
uint32_t GroupsInheritUpTo(const PipelineLayoutBase* other) const;
|
||||
|
||||
protected:
|
||||
BindGroupLayoutArray mBindGroupLayouts;
|
||||
std::bitset<kMaxBindGroups> mMask;
|
||||
protected:
|
||||
BindGroupLayoutArray mBindGroupLayouts;
|
||||
std::bitset<kMaxBindGroups> mMask;
|
||||
};
|
||||
|
||||
class PipelineLayoutBuilder : public Builder<PipelineLayoutBase> {
|
||||
public:
|
||||
PipelineLayoutBuilder(DeviceBase* device);
|
||||
public:
|
||||
PipelineLayoutBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetBindGroupLayout(uint32_t groupIndex, BindGroupLayoutBase* layout);
|
||||
// NXT API
|
||||
void SetBindGroupLayout(uint32_t groupIndex, BindGroupLayoutBase* layout);
|
||||
|
||||
private:
|
||||
friend class PipelineLayoutBase;
|
||||
private:
|
||||
friend class PipelineLayoutBase;
|
||||
|
||||
PipelineLayoutBase* GetResultImpl() override;
|
||||
PipelineLayoutBase* GetResultImpl() override;
|
||||
|
||||
BindGroupLayoutArray mBindGroupLayouts;
|
||||
std::bitset<kMaxBindGroups> mMask;
|
||||
BindGroupLayoutArray mBindGroupLayouts;
|
||||
std::bitset<kMaxBindGroups> mMask;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_PIPELINELAYOUT_H_
|
||||
#endif // BACKEND_PIPELINELAYOUT_H_
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
#include "backend/Queue.h"
|
||||
|
||||
#include "backend/Device.h"
|
||||
#include "backend/CommandBuffer.h"
|
||||
#include "backend/Device.h"
|
||||
|
||||
namespace backend {
|
||||
|
||||
@ -41,4 +41,4 @@ namespace backend {
|
||||
return mDevice->CreateQueue(this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_QUEUE_H_
|
||||
#define BACKEND_QUEUE_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
@ -24,38 +24,39 @@
|
||||
namespace backend {
|
||||
|
||||
class QueueBase : public RefCounted {
|
||||
public:
|
||||
QueueBase(QueueBuilder* builder);
|
||||
public:
|
||||
QueueBase(QueueBuilder* builder);
|
||||
|
||||
DeviceBase* GetDevice();
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
template<typename T>
|
||||
bool ValidateSubmit(uint32_t numCommands, T* const * commands) {
|
||||
static_assert(std::is_base_of<CommandBufferBase, T>::value, "invalid command buffer type");
|
||||
template <typename T>
|
||||
bool ValidateSubmit(uint32_t numCommands, T* const* commands) {
|
||||
static_assert(std::is_base_of<CommandBufferBase, T>::value,
|
||||
"invalid command buffer type");
|
||||
|
||||
for (uint32_t i = 0; i < numCommands; ++i) {
|
||||
if (!ValidateSubmitCommand(commands[i])) {
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < numCommands; ++i) {
|
||||
if (!ValidateSubmitCommand(commands[i])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool ValidateSubmitCommand(CommandBufferBase* command);
|
||||
private:
|
||||
bool ValidateSubmitCommand(CommandBufferBase* command);
|
||||
|
||||
DeviceBase* mDevice;
|
||||
DeviceBase* mDevice;
|
||||
};
|
||||
|
||||
class QueueBuilder : public Builder<QueueBase> {
|
||||
public:
|
||||
QueueBuilder(DeviceBase* device);
|
||||
public:
|
||||
QueueBuilder(DeviceBase* device);
|
||||
|
||||
private:
|
||||
friend class QueueBase;
|
||||
QueueBase* GetResultImpl() override;
|
||||
private:
|
||||
friend class QueueBase;
|
||||
QueueBase* GetResultImpl() override;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_QUEUE_H_
|
||||
#endif // BACKEND_QUEUE_H_
|
||||
|
@ -27,12 +27,12 @@ namespace backend {
|
||||
void RefCounted::ReferenceInternal() {
|
||||
ASSERT(mInternalRefs != 0);
|
||||
// TODO(cwallez@chromium.org): what to do on overflow?
|
||||
mInternalRefs ++;
|
||||
mInternalRefs++;
|
||||
}
|
||||
|
||||
void RefCounted::ReleaseInternal() {
|
||||
ASSERT(mInternalRefs != 0);
|
||||
mInternalRefs --;
|
||||
mInternalRefs--;
|
||||
if (mInternalRefs == 0) {
|
||||
ASSERT(mExternalRefs == 0);
|
||||
// TODO(cwallez@chromium.org): would this work with custom allocators?
|
||||
@ -51,15 +51,15 @@ namespace backend {
|
||||
void RefCounted::Reference() {
|
||||
ASSERT(mExternalRefs != 0);
|
||||
// TODO(cwallez@chromium.org): what to do on overflow?
|
||||
mExternalRefs ++;
|
||||
mExternalRefs++;
|
||||
}
|
||||
|
||||
void RefCounted::Release() {
|
||||
ASSERT(mExternalRefs != 0);
|
||||
mExternalRefs --;
|
||||
mExternalRefs--;
|
||||
if (mExternalRefs == 0) {
|
||||
ReleaseInternal();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -20,107 +20,110 @@
|
||||
namespace backend {
|
||||
|
||||
class RefCounted {
|
||||
public:
|
||||
RefCounted();
|
||||
virtual ~RefCounted();
|
||||
public:
|
||||
RefCounted();
|
||||
virtual ~RefCounted();
|
||||
|
||||
void ReferenceInternal();
|
||||
void ReleaseInternal();
|
||||
void ReferenceInternal();
|
||||
void ReleaseInternal();
|
||||
|
||||
uint32_t GetExternalRefs() const;
|
||||
uint32_t GetInternalRefs() const;
|
||||
uint32_t GetExternalRefs() const;
|
||||
uint32_t GetInternalRefs() const;
|
||||
|
||||
// NXT API
|
||||
void Reference();
|
||||
void Release();
|
||||
// NXT API
|
||||
void Reference();
|
||||
void Release();
|
||||
|
||||
protected:
|
||||
uint32_t mExternalRefs = 1;
|
||||
uint32_t mInternalRefs = 1;
|
||||
protected:
|
||||
uint32_t mExternalRefs = 1;
|
||||
uint32_t mInternalRefs = 1;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class Ref {
|
||||
public:
|
||||
Ref() {}
|
||||
public:
|
||||
Ref() {
|
||||
}
|
||||
|
||||
Ref(T* p): mPointee(p) {
|
||||
Reference();
|
||||
}
|
||||
|
||||
Ref(const Ref<T>& other): mPointee(other.mPointee) {
|
||||
Reference();
|
||||
}
|
||||
Ref<T>& operator=(const Ref<T>& other) {
|
||||
if (&other == this) return *this;
|
||||
|
||||
other.Reference();
|
||||
Release();
|
||||
mPointee = other.mPointee;
|
||||
Ref(T* p) : mPointee(p) {
|
||||
Reference();
|
||||
}
|
||||
|
||||
Ref(const Ref<T>& other) : mPointee(other.mPointee) {
|
||||
Reference();
|
||||
}
|
||||
Ref<T>& operator=(const Ref<T>& other) {
|
||||
if (&other == this)
|
||||
return *this;
|
||||
}
|
||||
|
||||
Ref(Ref<T>&& other) {
|
||||
mPointee = other.mPointee;
|
||||
other.mPointee = nullptr;
|
||||
}
|
||||
Ref<T>& operator=(Ref<T>&& other) {
|
||||
if (&other == this) return *this;
|
||||
other.Reference();
|
||||
Release();
|
||||
mPointee = other.mPointee;
|
||||
|
||||
Release();
|
||||
mPointee = other.mPointee;
|
||||
other.mPointee = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Ref(Ref<T>&& other) {
|
||||
mPointee = other.mPointee;
|
||||
other.mPointee = nullptr;
|
||||
}
|
||||
Ref<T>& operator=(Ref<T>&& other) {
|
||||
if (&other == this)
|
||||
return *this;
|
||||
}
|
||||
|
||||
~Ref() {
|
||||
Release();
|
||||
mPointee = nullptr;
|
||||
}
|
||||
Release();
|
||||
mPointee = other.mPointee;
|
||||
other.mPointee = nullptr;
|
||||
|
||||
operator bool() {
|
||||
return mPointee != nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const T& operator*() const {
|
||||
return *mPointee;
|
||||
}
|
||||
T& operator*() {
|
||||
return *mPointee;
|
||||
}
|
||||
~Ref() {
|
||||
Release();
|
||||
mPointee = nullptr;
|
||||
}
|
||||
|
||||
const T* operator->() const {
|
||||
return mPointee;
|
||||
}
|
||||
T* operator->() {
|
||||
return mPointee;
|
||||
}
|
||||
operator bool() {
|
||||
return mPointee != nullptr;
|
||||
}
|
||||
|
||||
const T* Get() const {
|
||||
return mPointee;
|
||||
}
|
||||
T* Get() {
|
||||
return mPointee;
|
||||
}
|
||||
const T& operator*() const {
|
||||
return *mPointee;
|
||||
}
|
||||
T& operator*() {
|
||||
return *mPointee;
|
||||
}
|
||||
|
||||
private:
|
||||
void Reference() const {
|
||||
if (mPointee != nullptr) {
|
||||
mPointee->ReferenceInternal();
|
||||
}
|
||||
}
|
||||
void Release() const {
|
||||
if (mPointee != nullptr) {
|
||||
mPointee->ReleaseInternal();
|
||||
}
|
||||
}
|
||||
const T* operator->() const {
|
||||
return mPointee;
|
||||
}
|
||||
T* operator->() {
|
||||
return mPointee;
|
||||
}
|
||||
|
||||
//static_assert(std::is_base_of<RefCounted, T>::value, "");
|
||||
T* mPointee = nullptr;
|
||||
const T* Get() const {
|
||||
return mPointee;
|
||||
}
|
||||
T* Get() {
|
||||
return mPointee;
|
||||
}
|
||||
|
||||
private:
|
||||
void Reference() const {
|
||||
if (mPointee != nullptr) {
|
||||
mPointee->ReferenceInternal();
|
||||
}
|
||||
}
|
||||
void Release() const {
|
||||
if (mPointee != nullptr) {
|
||||
mPointee->ReleaseInternal();
|
||||
}
|
||||
}
|
||||
|
||||
// static_assert(std::is_base_of<RefCounted, T>::value, "");
|
||||
T* mPointee = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_REFCOUNTED_H_
|
||||
#endif // BACKEND_REFCOUNTED_H_
|
||||
|
@ -25,7 +25,8 @@ namespace backend {
|
||||
// RenderPass
|
||||
|
||||
RenderPassBase::RenderPassBase(RenderPassBuilder* builder)
|
||||
: mAttachments(std::move(builder->mAttachments)), mSubpasses(std::move(builder->mSubpasses)) {
|
||||
: 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)) {
|
||||
@ -49,7 +50,8 @@ namespace backend {
|
||||
return static_cast<uint32_t>(mAttachments.size());
|
||||
}
|
||||
|
||||
const RenderPassBase::AttachmentInfo& RenderPassBase::GetAttachmentInfo(uint32_t attachment) const {
|
||||
const RenderPassBase::AttachmentInfo& RenderPassBase::GetAttachmentInfo(
|
||||
uint32_t attachment) const {
|
||||
ASSERT(attachment < mAttachments.size());
|
||||
return mAttachments[attachment];
|
||||
}
|
||||
@ -76,12 +78,12 @@ namespace backend {
|
||||
RENDERPASS_PROPERTY_SUBPASS_COUNT = 0x2,
|
||||
};
|
||||
|
||||
RenderPassBuilder::RenderPassBuilder(DeviceBase* device)
|
||||
: Builder(device), mSubpasses(1) {
|
||||
RenderPassBuilder::RenderPassBuilder(DeviceBase* device) : Builder(device), mSubpasses(1) {
|
||||
}
|
||||
|
||||
RenderPassBase* RenderPassBuilder::GetResultImpl() {
|
||||
constexpr int requiredProperties = RENDERPASS_PROPERTY_ATTACHMENT_COUNT | RENDERPASS_PROPERTY_SUBPASS_COUNT;
|
||||
constexpr int requiredProperties =
|
||||
RENDERPASS_PROPERTY_ATTACHMENT_COUNT | RENDERPASS_PROPERTY_SUBPASS_COUNT;
|
||||
if ((mPropertiesSet & requiredProperties) != requiredProperties) {
|
||||
HandleError("Render pass missing properties");
|
||||
return nullptr;
|
||||
@ -105,7 +107,8 @@ namespace backend {
|
||||
if (subpass.depthStencilAttachmentSet) {
|
||||
uint32_t slot = subpass.depthStencilAttachment;
|
||||
if (!TextureFormatHasDepthOrStencil(mAttachments[slot].format)) {
|
||||
HandleError("Render pass depth/stencil attachment is not of a depth/stencil format");
|
||||
HandleError(
|
||||
"Render pass depth/stencil attachment is not of a depth/stencil format");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -125,7 +128,8 @@ namespace backend {
|
||||
mPropertiesSet |= RENDERPASS_PROPERTY_ATTACHMENT_COUNT;
|
||||
}
|
||||
|
||||
void RenderPassBuilder::AttachmentSetFormat(uint32_t attachmentSlot, nxt::TextureFormat format) {
|
||||
void RenderPassBuilder::AttachmentSetFormat(uint32_t attachmentSlot,
|
||||
nxt::TextureFormat format) {
|
||||
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
|
||||
HandleError("Render pass attachment count not set yet");
|
||||
return;
|
||||
@ -156,7 +160,9 @@ namespace backend {
|
||||
mAttachments[attachmentSlot].colorLoadOp = op;
|
||||
}
|
||||
|
||||
void RenderPassBuilder::AttachmentSetDepthStencilLoadOps(uint32_t attachmentSlot, nxt::LoadOp depthOp, nxt::LoadOp stencilOp) {
|
||||
void RenderPassBuilder::AttachmentSetDepthStencilLoadOps(uint32_t attachmentSlot,
|
||||
nxt::LoadOp depthOp,
|
||||
nxt::LoadOp stencilOp) {
|
||||
if ((mPropertiesSet & RENDERPASS_PROPERTY_ATTACHMENT_COUNT) == 0) {
|
||||
HandleError("Render pass attachment count not set yet");
|
||||
return;
|
||||
@ -170,7 +176,6 @@ namespace backend {
|
||||
mAttachments[attachmentSlot].stencilLoadOp = stencilOp;
|
||||
}
|
||||
|
||||
|
||||
void RenderPassBuilder::SetSubpassCount(uint32_t subpassCount) {
|
||||
if ((mPropertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) != 0) {
|
||||
HandleError("Render pass subpass count property set multiple times");
|
||||
@ -185,7 +190,9 @@ namespace backend {
|
||||
mPropertiesSet |= RENDERPASS_PROPERTY_SUBPASS_COUNT;
|
||||
}
|
||||
|
||||
void RenderPassBuilder::SubpassSetColorAttachment(uint32_t subpass, uint32_t outputAttachmentLocation, uint32_t attachmentSlot) {
|
||||
void RenderPassBuilder::SubpassSetColorAttachment(uint32_t subpass,
|
||||
uint32_t outputAttachmentLocation,
|
||||
uint32_t attachmentSlot) {
|
||||
if ((mPropertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) == 0) {
|
||||
HandleError("Render pass subpass count not set yet");
|
||||
return;
|
||||
@ -215,7 +222,8 @@ namespace backend {
|
||||
mSubpasses[subpass].colorAttachments[outputAttachmentLocation] = attachmentSlot;
|
||||
}
|
||||
|
||||
void RenderPassBuilder::SubpassSetDepthStencilAttachment(uint32_t subpass, uint32_t attachmentSlot) {
|
||||
void RenderPassBuilder::SubpassSetDepthStencilAttachment(uint32_t subpass,
|
||||
uint32_t attachmentSlot) {
|
||||
if ((mPropertiesSet & RENDERPASS_PROPERTY_SUBPASS_COUNT) == 0) {
|
||||
HandleError("Render pass subpass count not set yet");
|
||||
return;
|
||||
@ -241,4 +249,4 @@ namespace backend {
|
||||
mSubpasses[subpass].depthStencilAttachment = attachmentSlot;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -29,68 +29,68 @@
|
||||
namespace backend {
|
||||
|
||||
class RenderPassBase : public RefCounted {
|
||||
public:
|
||||
RenderPassBase(RenderPassBuilder* builder);
|
||||
public:
|
||||
RenderPassBase(RenderPassBuilder* builder);
|
||||
|
||||
struct AttachmentInfo {
|
||||
nxt::TextureFormat format;
|
||||
nxt::LoadOp colorLoadOp = nxt::LoadOp::Load;
|
||||
nxt::LoadOp depthLoadOp = nxt::LoadOp::Load;
|
||||
nxt::LoadOp stencilLoadOp = nxt::LoadOp::Load;
|
||||
// The first subpass that this attachment is used in.
|
||||
// This is used to determine, for each subpass, whether each
|
||||
// of its attachments is being used for the first time.
|
||||
uint32_t firstSubpass = UINT32_MAX;
|
||||
};
|
||||
struct AttachmentInfo {
|
||||
nxt::TextureFormat format;
|
||||
nxt::LoadOp colorLoadOp = nxt::LoadOp::Load;
|
||||
nxt::LoadOp depthLoadOp = nxt::LoadOp::Load;
|
||||
nxt::LoadOp stencilLoadOp = nxt::LoadOp::Load;
|
||||
// The first subpass that this attachment is used in. This is used to determine, for
|
||||
// each subpass, whether each of its attachments is being used for the first time.
|
||||
uint32_t firstSubpass = UINT32_MAX;
|
||||
};
|
||||
|
||||
struct SubpassInfo {
|
||||
// Set of locations which are set
|
||||
std::bitset<kMaxColorAttachments> colorAttachmentsSet;
|
||||
// Mapping from location to attachment slot
|
||||
std::array<uint32_t, kMaxColorAttachments> colorAttachments;
|
||||
bool depthStencilAttachmentSet = false;
|
||||
uint32_t depthStencilAttachment = 0;
|
||||
};
|
||||
struct SubpassInfo {
|
||||
// Set of locations which are set
|
||||
std::bitset<kMaxColorAttachments> colorAttachmentsSet;
|
||||
// Mapping from location to attachment slot
|
||||
std::array<uint32_t, kMaxColorAttachments> colorAttachments;
|
||||
bool depthStencilAttachmentSet = false;
|
||||
uint32_t depthStencilAttachment = 0;
|
||||
};
|
||||
|
||||
uint32_t GetAttachmentCount() const;
|
||||
const AttachmentInfo& GetAttachmentInfo(uint32_t attachment) const;
|
||||
uint32_t GetSubpassCount() const;
|
||||
const SubpassInfo& GetSubpassInfo(uint32_t subpass) const;
|
||||
bool IsCompatibleWith(const RenderPassBase* other) const;
|
||||
uint32_t GetAttachmentCount() const;
|
||||
const AttachmentInfo& GetAttachmentInfo(uint32_t attachment) const;
|
||||
uint32_t GetSubpassCount() const;
|
||||
const SubpassInfo& GetSubpassInfo(uint32_t subpass) const;
|
||||
bool IsCompatibleWith(const RenderPassBase* other) const;
|
||||
|
||||
private:
|
||||
std::vector<AttachmentInfo> mAttachments;
|
||||
std::vector<SubpassInfo> mSubpasses;
|
||||
private:
|
||||
std::vector<AttachmentInfo> mAttachments;
|
||||
std::vector<SubpassInfo> mSubpasses;
|
||||
};
|
||||
|
||||
class RenderPassBuilder : public Builder<RenderPassBase> {
|
||||
public:
|
||||
RenderPassBuilder(DeviceBase* device);
|
||||
public:
|
||||
RenderPassBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
RenderPassBase* GetResultImpl() override;
|
||||
void SetAttachmentCount(uint32_t attachmentCount);
|
||||
void AttachmentSetFormat(uint32_t attachmentSlot, nxt::TextureFormat format);
|
||||
void AttachmentSetColorLoadOp(uint32_t attachmentSlot, nxt::LoadOp op);
|
||||
void AttachmentSetDepthStencilLoadOps(uint32_t attachmentSlot, nxt::LoadOp depthOp, nxt::LoadOp stencilOp);
|
||||
void SetSubpassCount(uint32_t subpassCount);
|
||||
void SubpassSetColorAttachment(uint32_t subpass, uint32_t outputAttachmentLocation, uint32_t attachmentSlot);
|
||||
void SubpassSetDepthStencilAttachment(uint32_t subpass, uint32_t attachmentSlot);
|
||||
// NXT API
|
||||
RenderPassBase* GetResultImpl() override;
|
||||
void SetAttachmentCount(uint32_t attachmentCount);
|
||||
void AttachmentSetFormat(uint32_t attachmentSlot, nxt::TextureFormat format);
|
||||
void AttachmentSetColorLoadOp(uint32_t attachmentSlot, nxt::LoadOp op);
|
||||
void AttachmentSetDepthStencilLoadOps(uint32_t attachmentSlot,
|
||||
nxt::LoadOp depthOp,
|
||||
nxt::LoadOp stencilOp);
|
||||
void SetSubpassCount(uint32_t subpassCount);
|
||||
void SubpassSetColorAttachment(uint32_t subpass,
|
||||
uint32_t outputAttachmentLocation,
|
||||
uint32_t attachmentSlot);
|
||||
void SubpassSetDepthStencilAttachment(uint32_t subpass, uint32_t attachmentSlot);
|
||||
|
||||
private:
|
||||
friend class RenderPassBase;
|
||||
private:
|
||||
friend class RenderPassBase;
|
||||
|
||||
enum AttachmentProperty {
|
||||
ATTACHMENT_PROPERTY_FORMAT,
|
||||
ATTACHMENT_PROPERTY_COUNT
|
||||
};
|
||||
enum AttachmentProperty { ATTACHMENT_PROPERTY_FORMAT, ATTACHMENT_PROPERTY_COUNT };
|
||||
|
||||
std::vector<std::bitset<ATTACHMENT_PROPERTY_COUNT>> mAttachmentProperties;
|
||||
std::vector<RenderPassBase::AttachmentInfo> mAttachments;
|
||||
std::vector<RenderPassBase::SubpassInfo> mSubpasses;
|
||||
int mPropertiesSet = 0;
|
||||
std::vector<std::bitset<ATTACHMENT_PROPERTY_COUNT>> mAttachmentProperties;
|
||||
std::vector<RenderPassBase::AttachmentInfo> mAttachments;
|
||||
std::vector<RenderPassBase::SubpassInfo> mSubpasses;
|
||||
int mPropertiesSet = 0;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_RENDERPASS_H_
|
||||
#endif // BACKEND_RENDERPASS_H_
|
||||
|
@ -15,8 +15,8 @@
|
||||
#include "backend/RenderPipeline.h"
|
||||
|
||||
#include "backend/BlendState.h"
|
||||
#include "backend/Device.h"
|
||||
#include "backend/DepthStencilState.h"
|
||||
#include "backend/Device.h"
|
||||
#include "backend/InputState.h"
|
||||
#include "backend/RenderPass.h"
|
||||
#include "common/BitSetIterator.h"
|
||||
@ -32,8 +32,8 @@ namespace backend {
|
||||
mInputState(std::move(builder->mInputState)),
|
||||
mPrimitiveTopology(builder->mPrimitiveTopology),
|
||||
mBlendStates(builder->mBlendStates),
|
||||
mRenderPass(std::move(builder->mRenderPass)), mSubpass(builder->mSubpass) {
|
||||
|
||||
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");
|
||||
return;
|
||||
@ -41,7 +41,9 @@ namespace backend {
|
||||
|
||||
// TODO(kainino@chromium.org): Need to verify the pipeline against its render subpass.
|
||||
|
||||
if ((builder->GetStageInfo(nxt::ShaderStage::Vertex).module->GetUsedVertexAttributes() & ~mInputState->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;
|
||||
}
|
||||
@ -83,7 +85,8 @@ namespace backend {
|
||||
}
|
||||
|
||||
RenderPipelineBase* RenderPipelineBuilder::GetResultImpl() {
|
||||
// TODO(cwallez@chromium.org): the layout should be required, and put the default objects in the device
|
||||
// TODO(cwallez@chromium.org): the layout should be required, and put the default objects in
|
||||
// the device
|
||||
if (!mInputState) {
|
||||
mInputState = mDevice->CreateInputStateBuilder()->GetResult();
|
||||
}
|
||||
@ -95,21 +98,24 @@ namespace backend {
|
||||
return nullptr;
|
||||
}
|
||||
const auto& subpassInfo = mRenderPass->GetSubpassInfo(mSubpass);
|
||||
if ((mBlendStatesSet | subpassInfo.colorAttachmentsSet) != subpassInfo.colorAttachmentsSet) {
|
||||
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 & ~mBlendStatesSet)) {
|
||||
for (uint32_t attachmentSlot :
|
||||
IterateBitSet(subpassInfo.colorAttachmentsSet & ~mBlendStatesSet)) {
|
||||
mBlendStates[attachmentSlot] = mDevice->CreateBlendStateBuilder()->GetResult();
|
||||
}
|
||||
|
||||
return mDevice->CreateRenderPipeline(this);
|
||||
}
|
||||
|
||||
void RenderPipelineBuilder::SetColorAttachmentBlendState(uint32_t attachmentSlot, BlendStateBase* blendState) {
|
||||
void RenderPipelineBuilder::SetColorAttachmentBlendState(uint32_t attachmentSlot,
|
||||
BlendStateBase* blendState) {
|
||||
if (attachmentSlot > mBlendStates.size()) {
|
||||
HandleError("Attachment index out of bounds");
|
||||
return;
|
||||
@ -144,4 +150,4 @@ namespace backend {
|
||||
mSubpass = subpass;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -25,55 +25,56 @@
|
||||
namespace backend {
|
||||
|
||||
class RenderPipelineBase : public RefCounted, public PipelineBase {
|
||||
public:
|
||||
RenderPipelineBase(RenderPipelineBuilder* builder);
|
||||
public:
|
||||
RenderPipelineBase(RenderPipelineBuilder* builder);
|
||||
|
||||
BlendStateBase* GetBlendState(uint32_t attachmentSlot);
|
||||
DepthStencilStateBase* GetDepthStencilState();
|
||||
nxt::IndexFormat GetIndexFormat() const;
|
||||
InputStateBase* GetInputState();
|
||||
nxt::PrimitiveTopology GetPrimitiveTopology() const;
|
||||
RenderPassBase* GetRenderPass();
|
||||
uint32_t GetSubPass();
|
||||
BlendStateBase* GetBlendState(uint32_t attachmentSlot);
|
||||
DepthStencilStateBase* GetDepthStencilState();
|
||||
nxt::IndexFormat GetIndexFormat() const;
|
||||
InputStateBase* GetInputState();
|
||||
nxt::PrimitiveTopology GetPrimitiveTopology() const;
|
||||
RenderPassBase* GetRenderPass();
|
||||
uint32_t GetSubPass();
|
||||
|
||||
private:
|
||||
Ref<DepthStencilStateBase> mDepthStencilState;
|
||||
nxt::IndexFormat mIndexFormat;
|
||||
Ref<InputStateBase> mInputState;
|
||||
nxt::PrimitiveTopology mPrimitiveTopology;
|
||||
std::array<Ref<BlendStateBase>, kMaxColorAttachments> mBlendStates;
|
||||
Ref<RenderPassBase> mRenderPass;
|
||||
uint32_t mSubpass;
|
||||
private:
|
||||
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 {
|
||||
public:
|
||||
RenderPipelineBuilder(DeviceBase* device);
|
||||
public:
|
||||
RenderPipelineBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetColorAttachmentBlendState(uint32_t attachmentSlot, BlendStateBase* blendState);
|
||||
void SetDepthStencilState(DepthStencilStateBase* depthStencilState);
|
||||
void SetPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology);
|
||||
void SetIndexFormat(nxt::IndexFormat format);
|
||||
void SetInputState(InputStateBase* inputState);
|
||||
void SetSubpass(RenderPassBase* renderPass, uint32_t subpass);
|
||||
// NXT API
|
||||
void SetColorAttachmentBlendState(uint32_t attachmentSlot, BlendStateBase* blendState);
|
||||
void SetDepthStencilState(DepthStencilStateBase* depthStencilState);
|
||||
void SetPrimitiveTopology(nxt::PrimitiveTopology primitiveTopology);
|
||||
void SetIndexFormat(nxt::IndexFormat format);
|
||||
void SetInputState(InputStateBase* inputState);
|
||||
void SetSubpass(RenderPassBase* renderPass, uint32_t subpass);
|
||||
|
||||
private:
|
||||
friend class RenderPipelineBase;
|
||||
private:
|
||||
friend class RenderPipelineBase;
|
||||
|
||||
RenderPipelineBase* GetResultImpl() override;
|
||||
RenderPipelineBase* GetResultImpl() override;
|
||||
|
||||
Ref<DepthStencilStateBase> mDepthStencilState;
|
||||
Ref<InputStateBase> mInputState;
|
||||
// TODO(enga@google.com): Remove default when we validate that all required properties are set
|
||||
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;
|
||||
Ref<DepthStencilStateBase> mDepthStencilState;
|
||||
Ref<InputStateBase> mInputState;
|
||||
// TODO(enga@google.com): Remove default when we validate that all required properties are
|
||||
// set
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_RENDERPIPELINE_H_
|
||||
#endif // BACKEND_RENDERPIPELINE_H_
|
||||
|
@ -43,7 +43,9 @@ namespace backend {
|
||||
return mMipMapFilter;
|
||||
}
|
||||
|
||||
void SamplerBuilder::SetFilterMode(nxt::FilterMode magFilter, nxt::FilterMode minFilter, nxt::FilterMode mipMapFilter) {
|
||||
void SamplerBuilder::SetFilterMode(nxt::FilterMode magFilter,
|
||||
nxt::FilterMode minFilter,
|
||||
nxt::FilterMode mipMapFilter) {
|
||||
if ((mPropertiesSet & SAMPLER_PROPERTY_FILTER) != 0) {
|
||||
HandleError("Sampler filter property set multiple times");
|
||||
return;
|
||||
@ -59,4 +61,4 @@ namespace backend {
|
||||
return mDevice->CreateSampler(this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_SAMPLER_H_
|
||||
#define BACKEND_SAMPLER_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Buffer.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
@ -24,33 +24,35 @@
|
||||
namespace backend {
|
||||
|
||||
class SamplerBase : public RefCounted {
|
||||
public:
|
||||
SamplerBase(SamplerBuilder* builder);
|
||||
public:
|
||||
SamplerBase(SamplerBuilder* builder);
|
||||
};
|
||||
|
||||
class SamplerBuilder : public Builder<SamplerBase> {
|
||||
public:
|
||||
SamplerBuilder(DeviceBase* device);
|
||||
public:
|
||||
SamplerBuilder(DeviceBase* device);
|
||||
|
||||
nxt::FilterMode GetMagFilter() const;
|
||||
nxt::FilterMode GetMinFilter() const;
|
||||
nxt::FilterMode GetMipMapFilter() const;
|
||||
nxt::FilterMode GetMagFilter() const;
|
||||
nxt::FilterMode GetMinFilter() const;
|
||||
nxt::FilterMode GetMipMapFilter() const;
|
||||
|
||||
// NXT API
|
||||
void SetFilterMode(nxt::FilterMode magFilter, nxt::FilterMode minFilter, nxt::FilterMode mipMapFilter);
|
||||
// NXT API
|
||||
void SetFilterMode(nxt::FilterMode magFilter,
|
||||
nxt::FilterMode minFilter,
|
||||
nxt::FilterMode mipMapFilter);
|
||||
|
||||
private:
|
||||
friend class SamplerBase;
|
||||
private:
|
||||
friend class SamplerBase;
|
||||
|
||||
SamplerBase* GetResultImpl() override;
|
||||
SamplerBase* GetResultImpl() override;
|
||||
|
||||
int mPropertiesSet = 0;
|
||||
int mPropertiesSet = 0;
|
||||
|
||||
nxt::FilterMode mMagFilter = nxt::FilterMode::Nearest;
|
||||
nxt::FilterMode mMinFilter = nxt::FilterMode::Nearest;
|
||||
nxt::FilterMode mMipMapFilter = nxt::FilterMode::Nearest;
|
||||
nxt::FilterMode mMagFilter = nxt::FilterMode::Nearest;
|
||||
nxt::FilterMode mMinFilter = nxt::FilterMode::Nearest;
|
||||
nxt::FilterMode mMipMapFilter = nxt::FilterMode::Nearest;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_SAMPLER_H_
|
||||
#endif // BACKEND_SAMPLER_H_
|
||||
|
@ -23,8 +23,7 @@
|
||||
|
||||
namespace backend {
|
||||
|
||||
ShaderModuleBase::ShaderModuleBase(ShaderModuleBuilder* builder)
|
||||
: mDevice(builder->mDevice) {
|
||||
ShaderModuleBase::ShaderModuleBase(ShaderModuleBuilder* builder) : mDevice(builder->mDevice) {
|
||||
}
|
||||
|
||||
DeviceBase* ShaderModuleBase::GetDevice() const {
|
||||
@ -62,8 +61,10 @@ namespace backend {
|
||||
ASSERT(blockType.basetype == spirv_cross::SPIRType::Struct);
|
||||
|
||||
for (uint32_t i = 0; i < blockType.member_types.size(); i++) {
|
||||
ASSERT(compiler.get_member_decoration_mask(blockType.self, i) & 1ull << spv::DecorationOffset);
|
||||
uint32_t offset = compiler.get_member_decoration(blockType.self, i, spv::DecorationOffset);
|
||||
ASSERT(compiler.get_member_decoration_mask(blockType.self, i) &
|
||||
1ull << spv::DecorationOffset);
|
||||
uint32_t offset =
|
||||
compiler.get_member_decoration(blockType.self, i, spv::DecorationOffset);
|
||||
ASSERT(offset % 4 == 0);
|
||||
offset /= 4;
|
||||
|
||||
@ -78,8 +79,8 @@ namespace backend {
|
||||
constantType = PushConstantType::Float;
|
||||
}
|
||||
|
||||
// TODO(cwallez@chromium.org): check for overflows and make the logic better take into account
|
||||
// things like the array of types with padding.
|
||||
// TODO(cwallez@chromium.org): check for overflows and make the logic better take
|
||||
// into account things like the array of types with padding.
|
||||
uint32_t size = memberType.vecsize * memberType.columns;
|
||||
// Handle unidimensional arrays
|
||||
if (!memberType.array.empty()) {
|
||||
@ -92,7 +93,8 @@ namespace backend {
|
||||
}
|
||||
|
||||
mPushConstants.mask.set(offset);
|
||||
mPushConstants.names[offset] = interfaceBlock.name + "." + compiler.get_member_name(blockType.self, i);
|
||||
mPushConstants.names[offset] =
|
||||
interfaceBlock.name + "." + compiler.get_member_name(blockType.self, i);
|
||||
mPushConstants.sizes[offset] = size;
|
||||
mPushConstants.types[offset] = constantType;
|
||||
}
|
||||
@ -100,11 +102,14 @@ namespace backend {
|
||||
|
||||
// Fill in bindingInfo with the SPIRV bindings
|
||||
auto ExtractResourcesBinding = [this](const std::vector<spirv_cross::Resource>& resources,
|
||||
const spirv_cross::Compiler& compiler, nxt::BindingType bindingType) {
|
||||
constexpr uint64_t requiredBindingDecorationMask = (1ull << spv::DecorationBinding) | (1ull << spv::DecorationDescriptorSet);
|
||||
const spirv_cross::Compiler& compiler,
|
||||
nxt::BindingType bindingType) {
|
||||
constexpr uint64_t requiredBindingDecorationMask =
|
||||
(1ull << spv::DecorationBinding) | (1ull << spv::DecorationDescriptorSet);
|
||||
|
||||
for (const auto& resource : resources) {
|
||||
ASSERT((compiler.get_decoration_mask(resource.id) & requiredBindingDecorationMask) == requiredBindingDecorationMask);
|
||||
ASSERT((compiler.get_decoration_mask(resource.id) &
|
||||
requiredBindingDecorationMask) == requiredBindingDecorationMask);
|
||||
uint32_t binding = compiler.get_decoration(resource.id, spv::DecorationBinding);
|
||||
uint32_t set = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet);
|
||||
|
||||
@ -121,10 +126,13 @@ namespace backend {
|
||||
}
|
||||
};
|
||||
|
||||
ExtractResourcesBinding(resources.uniform_buffers, compiler, nxt::BindingType::UniformBuffer);
|
||||
ExtractResourcesBinding(resources.separate_images, compiler, nxt::BindingType::SampledTexture);
|
||||
ExtractResourcesBinding(resources.uniform_buffers, compiler,
|
||||
nxt::BindingType::UniformBuffer);
|
||||
ExtractResourcesBinding(resources.separate_images, compiler,
|
||||
nxt::BindingType::SampledTexture);
|
||||
ExtractResourcesBinding(resources.separate_samplers, compiler, nxt::BindingType::Sampler);
|
||||
ExtractResourcesBinding(resources.storage_buffers, compiler, nxt::BindingType::StorageBuffer);
|
||||
ExtractResourcesBinding(resources.storage_buffers, compiler,
|
||||
nxt::BindingType::StorageBuffer);
|
||||
|
||||
// Extract the vertex attributes
|
||||
if (mExecutionModel == nxt::ShaderStage::Vertex) {
|
||||
@ -140,10 +148,11 @@ namespace backend {
|
||||
mUsedVertexAttributes.set(location);
|
||||
}
|
||||
|
||||
// Without a location qualifier on vertex outputs, spirv_cross::CompilerMSL gives them all
|
||||
// the location 0, causing a compile error.
|
||||
// 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))) {
|
||||
if (!(compiler.get_decoration_mask(attrib.id) &
|
||||
(1ull << spv::DecorationLocation))) {
|
||||
mDevice->HandleError("Need location qualifier on vertex output");
|
||||
return;
|
||||
}
|
||||
@ -151,10 +160,11 @@ namespace backend {
|
||||
}
|
||||
|
||||
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.
|
||||
// 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))) {
|
||||
if (!(compiler.get_decoration_mask(attrib.id) &
|
||||
(1ull << spv::DecorationLocation))) {
|
||||
mDevice->HandleError("Need location qualifier on fragment input");
|
||||
return;
|
||||
}
|
||||
@ -187,7 +197,8 @@ namespace backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShaderModuleBase::IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout) {
|
||||
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 = mBindingInfo[group][i];
|
||||
@ -227,4 +238,4 @@ namespace backend {
|
||||
mSpirv.assign(code, code + codeSize);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_SHADERMODULE_H_
|
||||
#define BACKEND_SHADERMODULE_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
@ -33,64 +33,65 @@ namespace spirv_cross {
|
||||
namespace backend {
|
||||
|
||||
class ShaderModuleBase : public RefCounted {
|
||||
public:
|
||||
ShaderModuleBase(ShaderModuleBuilder* builder);
|
||||
public:
|
||||
ShaderModuleBase(ShaderModuleBuilder* builder);
|
||||
|
||||
DeviceBase* GetDevice() const;
|
||||
DeviceBase* GetDevice() const;
|
||||
|
||||
void ExtractSpirvInfo(const spirv_cross::Compiler& compiler);
|
||||
void ExtractSpirvInfo(const spirv_cross::Compiler& compiler);
|
||||
|
||||
struct PushConstantInfo {
|
||||
std::bitset<kMaxPushConstants> mask;
|
||||
struct PushConstantInfo {
|
||||
std::bitset<kMaxPushConstants> mask;
|
||||
|
||||
std::array<std::string, kMaxPushConstants> names;
|
||||
std::array<uint32_t, kMaxPushConstants> sizes;
|
||||
std::array<PushConstantType, kMaxPushConstants> types;
|
||||
};
|
||||
std::array<std::string, kMaxPushConstants> names;
|
||||
std::array<uint32_t, kMaxPushConstants> sizes;
|
||||
std::array<PushConstantType, kMaxPushConstants> types;
|
||||
};
|
||||
|
||||
struct BindingInfo {
|
||||
// The SPIRV ID of the resource.
|
||||
uint32_t id;
|
||||
uint32_t base_type_id;
|
||||
nxt::BindingType type;
|
||||
bool used = false;
|
||||
};
|
||||
using ModuleBindingInfo = std::array<std::array<BindingInfo, kMaxBindingsPerGroup>, kMaxBindGroups>;
|
||||
struct BindingInfo {
|
||||
// The SPIRV ID of the resource.
|
||||
uint32_t id;
|
||||
uint32_t base_type_id;
|
||||
nxt::BindingType type;
|
||||
bool used = false;
|
||||
};
|
||||
using ModuleBindingInfo =
|
||||
std::array<std::array<BindingInfo, kMaxBindingsPerGroup>, kMaxBindGroups>;
|
||||
|
||||
const PushConstantInfo& GetPushConstants() const;
|
||||
const ModuleBindingInfo& GetBindingInfo() const;
|
||||
const std::bitset<kMaxVertexAttributes>& GetUsedVertexAttributes() const;
|
||||
nxt::ShaderStage GetExecutionModel() const;
|
||||
const PushConstantInfo& GetPushConstants() const;
|
||||
const ModuleBindingInfo& GetBindingInfo() const;
|
||||
const std::bitset<kMaxVertexAttributes>& GetUsedVertexAttributes() const;
|
||||
nxt::ShaderStage GetExecutionModel() const;
|
||||
|
||||
bool IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout);
|
||||
bool IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout);
|
||||
|
||||
private:
|
||||
bool IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout);
|
||||
private:
|
||||
bool IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout);
|
||||
|
||||
DeviceBase* mDevice;
|
||||
PushConstantInfo mPushConstants = {};
|
||||
ModuleBindingInfo mBindingInfo;
|
||||
std::bitset<kMaxVertexAttributes> mUsedVertexAttributes;
|
||||
nxt::ShaderStage mExecutionModel;
|
||||
DeviceBase* mDevice;
|
||||
PushConstantInfo mPushConstants = {};
|
||||
ModuleBindingInfo mBindingInfo;
|
||||
std::bitset<kMaxVertexAttributes> mUsedVertexAttributes;
|
||||
nxt::ShaderStage mExecutionModel;
|
||||
};
|
||||
|
||||
class ShaderModuleBuilder : public Builder<ShaderModuleBase> {
|
||||
public:
|
||||
ShaderModuleBuilder(DeviceBase* device);
|
||||
public:
|
||||
ShaderModuleBuilder(DeviceBase* device);
|
||||
|
||||
std::vector<uint32_t> AcquireSpirv();
|
||||
std::vector<uint32_t> AcquireSpirv();
|
||||
|
||||
// NXT API
|
||||
void SetSource(uint32_t codeSize, const uint32_t* code);
|
||||
// NXT API
|
||||
void SetSource(uint32_t codeSize, const uint32_t* code);
|
||||
|
||||
private:
|
||||
friend class ShaderModuleBase;
|
||||
private:
|
||||
friend class ShaderModuleBase;
|
||||
|
||||
ShaderModuleBase* GetResultImpl() override;
|
||||
ShaderModuleBase* GetResultImpl() override;
|
||||
|
||||
std::vector<uint32_t> mSpirv;
|
||||
std::vector<uint32_t> mSpirv;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_SHADERMODULE_H_
|
||||
#endif // BACKEND_SHADERMODULE_H_
|
||||
|
@ -22,7 +22,7 @@ namespace backend {
|
||||
// SwapChain
|
||||
|
||||
SwapChainBase::SwapChainBase(SwapChainBuilder* builder)
|
||||
: mDevice(builder->mDevice), mImplementation(builder->mImplementation) {
|
||||
: mDevice(builder->mDevice), mImplementation(builder->mImplementation) {
|
||||
}
|
||||
|
||||
SwapChainBase::~SwapChainBase() {
|
||||
@ -34,7 +34,10 @@ namespace backend {
|
||||
return mDevice;
|
||||
}
|
||||
|
||||
void SwapChainBase::Configure(nxt::TextureFormat format, nxt::TextureUsageBit allowedUsage, uint32_t width, uint32_t height) {
|
||||
void SwapChainBase::Configure(nxt::TextureFormat format,
|
||||
nxt::TextureUsageBit allowedUsage,
|
||||
uint32_t width,
|
||||
uint32_t height) {
|
||||
if (width == 0 || height == 0) {
|
||||
mDevice->HandleError("Swap chain cannot be configured to zero size");
|
||||
return;
|
||||
@ -45,8 +48,8 @@ namespace backend {
|
||||
mAllowedUsage = allowedUsage;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mImplementation.Configure(mImplementation.userData,
|
||||
static_cast<nxtTextureFormat>(format), static_cast<nxtTextureUsageBit>(allowedUsage), width, height);
|
||||
mImplementation.Configure(mImplementation.userData, static_cast<nxtTextureFormat>(format),
|
||||
static_cast<nxtTextureUsageBit>(allowedUsage), width, height);
|
||||
}
|
||||
|
||||
TextureBase* SwapChainBase::GetNextTexture() {
|
||||
@ -87,8 +90,7 @@ namespace backend {
|
||||
|
||||
// SwapChain Builder
|
||||
|
||||
SwapChainBuilder::SwapChainBuilder(DeviceBase* device)
|
||||
: Builder(device) {
|
||||
SwapChainBuilder::SwapChainBuilder(DeviceBase* device) : Builder(device) {
|
||||
}
|
||||
|
||||
SwapChainBase* SwapChainBuilder::GetResultImpl() {
|
||||
@ -105,14 +107,15 @@ namespace backend {
|
||||
return;
|
||||
}
|
||||
|
||||
nxtSwapChainImplementation& impl = *reinterpret_cast<nxtSwapChainImplementation*>(implementation);
|
||||
nxtSwapChainImplementation& impl =
|
||||
*reinterpret_cast<nxtSwapChainImplementation*>(implementation);
|
||||
|
||||
if (!impl.Init || !impl.Destroy || !impl.Configure ||
|
||||
!impl.GetNextTexture || !impl.Present) {
|
||||
if (!impl.Init || !impl.Destroy || !impl.Configure || !impl.GetNextTexture ||
|
||||
!impl.Present) {
|
||||
HandleError("Implementation is incomplete");
|
||||
return;
|
||||
}
|
||||
|
||||
mImplementation = impl;
|
||||
}
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,55 +15,58 @@
|
||||
#ifndef BACKEND_SWAPCHAIN_H_
|
||||
#define BACKEND_SWAPCHAIN_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
#include "nxt/nxt_wsi.h"
|
||||
#include "nxt/nxtcpp.h"
|
||||
|
||||
namespace backend {
|
||||
|
||||
class SwapChainBase : public RefCounted {
|
||||
public:
|
||||
SwapChainBase(SwapChainBuilder* builder);
|
||||
~SwapChainBase();
|
||||
public:
|
||||
SwapChainBase(SwapChainBuilder* builder);
|
||||
~SwapChainBase();
|
||||
|
||||
DeviceBase* GetDevice();
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
// NXT API
|
||||
void Configure(nxt::TextureFormat format, nxt::TextureUsageBit allowedUsage, uint32_t width, uint32_t height);
|
||||
TextureBase* GetNextTexture();
|
||||
void Present(TextureBase* texture);
|
||||
// NXT API
|
||||
void Configure(nxt::TextureFormat format,
|
||||
nxt::TextureUsageBit allowedUsage,
|
||||
uint32_t width,
|
||||
uint32_t height);
|
||||
TextureBase* GetNextTexture();
|
||||
void Present(TextureBase* texture);
|
||||
|
||||
protected:
|
||||
const nxtSwapChainImplementation& GetImplementation();
|
||||
virtual TextureBase* GetNextTextureImpl(TextureBuilder* builder) = 0;
|
||||
protected:
|
||||
const nxtSwapChainImplementation& GetImplementation();
|
||||
virtual TextureBase* GetNextTextureImpl(TextureBuilder* builder) = 0;
|
||||
|
||||
private:
|
||||
DeviceBase* mDevice = nullptr;
|
||||
nxtSwapChainImplementation mImplementation = {};
|
||||
nxt::TextureFormat mFormat = {};
|
||||
nxt::TextureUsageBit mAllowedUsage;
|
||||
uint32_t mWidth = 0;
|
||||
uint32_t mHeight = 0;
|
||||
TextureBase* mLastNextTexture = nullptr;
|
||||
private:
|
||||
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> {
|
||||
public:
|
||||
SwapChainBuilder(DeviceBase* device);
|
||||
public:
|
||||
SwapChainBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
SwapChainBase* GetResultImpl() override;
|
||||
void SetImplementation(uint64_t implementation);
|
||||
// NXT API
|
||||
SwapChainBase* GetResultImpl() override;
|
||||
void SetImplementation(uint64_t implementation);
|
||||
|
||||
private:
|
||||
friend class SwapChainBase;
|
||||
private:
|
||||
friend class SwapChainBase;
|
||||
|
||||
nxtSwapChainImplementation mImplementation = {};
|
||||
nxtSwapChainImplementation mImplementation = {};
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_SWAPCHAIN_H_
|
||||
#endif // BACKEND_SWAPCHAIN_H_
|
||||
|
@ -71,13 +71,18 @@ namespace backend {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TextureBase
|
||||
|
||||
TextureBase::TextureBase(TextureBuilder* builder)
|
||||
: 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) {
|
||||
: 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() {
|
||||
@ -121,7 +126,8 @@ namespace backend {
|
||||
return mIsFrozen && (usage & mAllowedUsage);
|
||||
}
|
||||
|
||||
bool TextureBase::IsUsagePossible(nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit usage) {
|
||||
bool TextureBase::IsUsagePossible(nxt::TextureUsageBit allowedUsage,
|
||||
nxt::TextureUsageBit usage) {
|
||||
bool allowed = (usage & allowedUsage) == usage;
|
||||
bool singleUse = nxt::HasZeroOrOneBits(usage);
|
||||
return allowed && singleUse;
|
||||
@ -173,13 +179,13 @@ namespace backend {
|
||||
TEXTURE_PROPERTY_INITIAL_USAGE = 0x20,
|
||||
};
|
||||
|
||||
TextureBuilder::TextureBuilder(DeviceBase* device)
|
||||
: Builder(device) {
|
||||
TextureBuilder::TextureBuilder(DeviceBase* device) : Builder(device) {
|
||||
}
|
||||
|
||||
TextureBase* TextureBuilder::GetResultImpl() {
|
||||
constexpr int allProperties = TEXTURE_PROPERTY_DIMENSION | TEXTURE_PROPERTY_EXTENT |
|
||||
TEXTURE_PROPERTY_FORMAT | TEXTURE_PROPERTY_MIP_LEVELS | TEXTURE_PROPERTY_ALLOWED_USAGE;
|
||||
TEXTURE_PROPERTY_FORMAT | TEXTURE_PROPERTY_MIP_LEVELS |
|
||||
TEXTURE_PROPERTY_ALLOWED_USAGE;
|
||||
if ((mPropertiesSet & allProperties) != allProperties) {
|
||||
HandleError("Texture missing properties");
|
||||
return nullptr;
|
||||
@ -264,8 +270,7 @@ namespace backend {
|
||||
|
||||
// TextureViewBase
|
||||
|
||||
TextureViewBase::TextureViewBase(TextureViewBuilder* builder)
|
||||
: mTexture(builder->mTexture) {
|
||||
TextureViewBase::TextureViewBase(TextureViewBuilder* builder) : mTexture(builder->mTexture) {
|
||||
}
|
||||
|
||||
TextureBase* TextureViewBase::GetTexture() {
|
||||
@ -282,4 +287,4 @@ namespace backend {
|
||||
return mDevice->CreateTextureView(this);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_TEXTURE_H_
|
||||
#define BACKEND_TEXTURE_H_
|
||||
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/Builder.h"
|
||||
#include "backend/Forward.h"
|
||||
#include "backend/RefCounted.h"
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
@ -29,93 +29,94 @@ namespace backend {
|
||||
bool TextureFormatHasDepthOrStencil(nxt::TextureFormat format);
|
||||
|
||||
class TextureBase : public RefCounted {
|
||||
public:
|
||||
TextureBase(TextureBuilder* builder);
|
||||
public:
|
||||
TextureBase(TextureBuilder* builder);
|
||||
|
||||
nxt::TextureDimension GetDimension() const;
|
||||
nxt::TextureFormat GetFormat() const;
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetHeight() const;
|
||||
uint32_t GetDepth() const;
|
||||
uint32_t GetNumMipLevels() const;
|
||||
nxt::TextureUsageBit GetAllowedUsage() const;
|
||||
nxt::TextureUsageBit GetUsage() const;
|
||||
bool IsFrozen() const;
|
||||
bool HasFrozenUsage(nxt::TextureUsageBit usage) const;
|
||||
static bool IsUsagePossible(nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit usage);
|
||||
bool IsTransitionPossible(nxt::TextureUsageBit usage) const;
|
||||
void UpdateUsageInternal(nxt::TextureUsageBit usage);
|
||||
nxt::TextureDimension GetDimension() const;
|
||||
nxt::TextureFormat GetFormat() const;
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetHeight() const;
|
||||
uint32_t GetDepth() const;
|
||||
uint32_t GetNumMipLevels() const;
|
||||
nxt::TextureUsageBit GetAllowedUsage() const;
|
||||
nxt::TextureUsageBit GetUsage() const;
|
||||
bool IsFrozen() const;
|
||||
bool HasFrozenUsage(nxt::TextureUsageBit usage) const;
|
||||
static bool IsUsagePossible(nxt::TextureUsageBit allowedUsage, nxt::TextureUsageBit usage);
|
||||
bool IsTransitionPossible(nxt::TextureUsageBit usage) const;
|
||||
void UpdateUsageInternal(nxt::TextureUsageBit usage);
|
||||
|
||||
DeviceBase* GetDevice();
|
||||
DeviceBase* GetDevice();
|
||||
|
||||
// NXT API
|
||||
TextureViewBuilder* CreateTextureViewBuilder();
|
||||
void TransitionUsage(nxt::TextureUsageBit usage);
|
||||
void FreezeUsage(nxt::TextureUsageBit usage);
|
||||
// NXT API
|
||||
TextureViewBuilder* CreateTextureViewBuilder();
|
||||
void TransitionUsage(nxt::TextureUsageBit usage);
|
||||
void FreezeUsage(nxt::TextureUsageBit usage);
|
||||
|
||||
virtual void TransitionUsageImpl(nxt::TextureUsageBit currentUsage, nxt::TextureUsageBit targetUsage) = 0;
|
||||
virtual void TransitionUsageImpl(nxt::TextureUsageBit currentUsage,
|
||||
nxt::TextureUsageBit targetUsage) = 0;
|
||||
|
||||
private:
|
||||
DeviceBase* mDevice;
|
||||
private:
|
||||
DeviceBase* mDevice;
|
||||
|
||||
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;
|
||||
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> {
|
||||
public:
|
||||
TextureBuilder(DeviceBase* device);
|
||||
public:
|
||||
TextureBuilder(DeviceBase* device);
|
||||
|
||||
// NXT API
|
||||
void SetDimension(nxt::TextureDimension dimension);
|
||||
void SetExtent(uint32_t width, uint32_t height, uint32_t depth);
|
||||
void SetFormat(nxt::TextureFormat format);
|
||||
void SetMipLevels(uint32_t numMipLevels);
|
||||
void SetAllowedUsage(nxt::TextureUsageBit usage);
|
||||
void SetInitialUsage(nxt::TextureUsageBit usage);
|
||||
// NXT API
|
||||
void SetDimension(nxt::TextureDimension dimension);
|
||||
void SetExtent(uint32_t width, uint32_t height, uint32_t depth);
|
||||
void SetFormat(nxt::TextureFormat format);
|
||||
void SetMipLevels(uint32_t numMipLevels);
|
||||
void SetAllowedUsage(nxt::TextureUsageBit usage);
|
||||
void SetInitialUsage(nxt::TextureUsageBit usage);
|
||||
|
||||
private:
|
||||
friend class TextureBase;
|
||||
private:
|
||||
friend class TextureBase;
|
||||
|
||||
TextureBase* GetResultImpl() override;
|
||||
TextureBase* GetResultImpl() override;
|
||||
|
||||
int mPropertiesSet = 0;
|
||||
int mPropertiesSet = 0;
|
||||
|
||||
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;
|
||||
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 {
|
||||
public:
|
||||
TextureViewBase(TextureViewBuilder* builder);
|
||||
public:
|
||||
TextureViewBase(TextureViewBuilder* builder);
|
||||
|
||||
TextureBase* GetTexture();
|
||||
TextureBase* GetTexture();
|
||||
|
||||
private:
|
||||
Ref<TextureBase> mTexture;
|
||||
private:
|
||||
Ref<TextureBase> mTexture;
|
||||
};
|
||||
|
||||
class TextureViewBuilder : public Builder<TextureViewBase> {
|
||||
public:
|
||||
TextureViewBuilder(DeviceBase* device, TextureBase* texture);
|
||||
public:
|
||||
TextureViewBuilder(DeviceBase* device, TextureBase* texture);
|
||||
|
||||
private:
|
||||
friend class TextureViewBase;
|
||||
private:
|
||||
friend class TextureViewBase;
|
||||
|
||||
TextureViewBase* GetResultImpl() override;
|
||||
TextureViewBase* GetResultImpl() override;
|
||||
|
||||
Ref<TextureBase> mTexture;
|
||||
Ref<TextureBase> mTexture;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_TEXTURE_H_
|
||||
#endif // BACKEND_TEXTURE_H_
|
||||
|
@ -20,105 +20,105 @@
|
||||
namespace backend {
|
||||
|
||||
// ToBackendTraits implements the mapping from base type to member type of BackendTraits
|
||||
template<typename T, typename BackendTraits>
|
||||
template <typename T, typename BackendTraits>
|
||||
struct ToBackendTraits;
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<BindGroupBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::BindGroupType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<BindGroupLayoutBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::BindGroupLayoutType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<BlendStateBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::BlendStateType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<BufferBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::BufferType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<BufferViewBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::BufferViewType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<CommandBufferBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::CommandBufferType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<ComputePipelineBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::ComputePipelineType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<DepthStencilStateBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::DepthStencilStateType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<DeviceBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::DeviceType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<FramebufferBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::FramebufferType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<InputStateBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::InputStateType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<PipelineLayoutBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::PipelineLayoutType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<QueueBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::QueueType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<RenderPassBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::RenderPassType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<RenderPipelineBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::RenderPipelineType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<SamplerBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::SamplerType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<ShaderModuleBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::ShaderModuleType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<TextureBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::TextureType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<SwapChainBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::SwapChainType;
|
||||
};
|
||||
|
||||
template<typename BackendTraits>
|
||||
template <typename BackendTraits>
|
||||
struct ToBackendTraits<TextureViewBase, BackendTraits> {
|
||||
using BackendType = typename BackendTraits::TextureViewType;
|
||||
};
|
||||
@ -130,26 +130,30 @@ namespace backend {
|
||||
// return ToBackendBase<MyBackendTraits>(common);
|
||||
// }
|
||||
|
||||
template<typename BackendTraits, typename T>
|
||||
template <typename BackendTraits, typename T>
|
||||
Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>& ToBackendBase(Ref<T>& common) {
|
||||
return reinterpret_cast<Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>&>(common);
|
||||
return reinterpret_cast<Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>&>(
|
||||
common);
|
||||
}
|
||||
|
||||
template<typename BackendTraits, typename T>
|
||||
const Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>& ToBackendBase(const Ref<T>& common) {
|
||||
return reinterpret_cast<const Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>&>(common);
|
||||
template <typename BackendTraits, typename T>
|
||||
const Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>& ToBackendBase(
|
||||
const Ref<T>& common) {
|
||||
return reinterpret_cast<
|
||||
const Ref<typename ToBackendTraits<T, BackendTraits>::BackendType>&>(common);
|
||||
}
|
||||
|
||||
template<typename BackendTraits, typename T>
|
||||
template <typename BackendTraits, typename T>
|
||||
typename ToBackendTraits<T, BackendTraits>::BackendType* ToBackendBase(T* common) {
|
||||
return reinterpret_cast<typename ToBackendTraits<T, BackendTraits>::BackendType*>(common);
|
||||
}
|
||||
|
||||
template<typename BackendTraits, typename T>
|
||||
template <typename BackendTraits, typename T>
|
||||
const typename ToBackendTraits<T, BackendTraits>::BackendType* ToBackendBase(const T* common) {
|
||||
return reinterpret_cast<const typename ToBackendTraits<T, BackendTraits>::BackendType*>(common);
|
||||
return reinterpret_cast<const typename ToBackendTraits<T, BackendTraits>::BackendType*>(
|
||||
common);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace backend
|
||||
|
||||
#endif // BACKEND_TOBACKEND_H_
|
||||
#endif // BACKEND_TOBACKEND_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user