2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#ifndef DAWNNATIVE_BINDGROUPLAYOUT_H_
|
|
|
|
#define DAWNNATIVE_BINDGROUPLAYOUT_H_
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "common/Constants.h"
|
2020-03-13 22:50:00 +00:00
|
|
|
#include "common/Math.h"
|
|
|
|
#include "common/SlabAllocator.h"
|
2020-06-17 22:35:19 +00:00
|
|
|
#include "common/ityp_span.h"
|
2020-07-14 22:20:35 +00:00
|
|
|
#include "common/ityp_vector.h"
|
2020-03-27 18:54:03 +00:00
|
|
|
#include "dawn_native/BindingInfo.h"
|
2019-10-30 00:20:03 +00:00
|
|
|
#include "dawn_native/CachedObject.h"
|
2018-07-24 11:53:51 +00:00
|
|
|
#include "dawn_native/Error.h"
|
|
|
|
#include "dawn_native/Forward.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-25 15:03:23 +00:00
|
|
|
#include "dawn_native/dawn_platform.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
#include <bitset>
|
2020-03-20 21:56:30 +00:00
|
|
|
#include <map>
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
namespace dawn_native {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2020-09-22 11:04:45 +00:00
|
|
|
MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase* device,
|
2018-07-25 15:03:23 +00:00
|
|
|
const BindGroupLayoutDescriptor* descriptor);
|
2018-07-10 19:23:50 +00:00
|
|
|
|
2020-03-20 21:56:30 +00:00
|
|
|
// Bindings are specified as a |BindingNumber| in the BindGroupLayoutDescriptor.
|
|
|
|
// These numbers may be arbitrary and sparse. Internally, Dawn packs these numbers
|
|
|
|
// into a packed range of |BindingIndex| integers.
|
2019-10-30 00:20:03 +00:00
|
|
|
class BindGroupLayoutBase : public CachedObject {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
2019-10-30 00:20:03 +00:00
|
|
|
BindGroupLayoutBase(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor);
|
2017-11-24 18:59:42 +00:00
|
|
|
~BindGroupLayoutBase() override;
|
|
|
|
|
2019-02-13 13:09:18 +00:00
|
|
|
static BindGroupLayoutBase* MakeError(DeviceBase* device);
|
2020-03-20 21:56:30 +00:00
|
|
|
|
|
|
|
// A map from the BindingNumber to its packed BindingIndex.
|
|
|
|
using BindingMap = std::map<BindingNumber, BindingIndex>;
|
|
|
|
|
2020-03-26 17:22:14 +00:00
|
|
|
const BindingInfo& GetBindingInfo(BindingIndex bindingIndex) const {
|
|
|
|
ASSERT(!IsError());
|
2020-07-14 22:20:35 +00:00
|
|
|
ASSERT(bindingIndex < mBindingInfo.size());
|
2020-03-26 17:22:14 +00:00
|
|
|
return mBindingInfo[bindingIndex];
|
|
|
|
}
|
2020-03-20 21:56:30 +00:00
|
|
|
const BindingMap& GetBindingMap() const;
|
|
|
|
BindingIndex GetBindingIndex(BindingNumber bindingNumber) const;
|
2017-11-24 18:59:42 +00:00
|
|
|
|
2019-05-01 12:57:27 +00:00
|
|
|
// Functors necessary for the unordered_set<BGLBase*>-based cache.
|
|
|
|
struct HashFunc {
|
|
|
|
size_t operator()(const BindGroupLayoutBase* bgl) const;
|
|
|
|
};
|
|
|
|
struct EqualityFunc {
|
|
|
|
bool operator()(const BindGroupLayoutBase* a, const BindGroupLayoutBase* b) const;
|
|
|
|
};
|
|
|
|
|
2020-03-20 21:56:30 +00:00
|
|
|
BindingIndex GetBindingCount() const;
|
2020-07-14 00:53:23 +00:00
|
|
|
// Returns |BindingIndex| because buffers are packed at the front.
|
2020-06-19 21:39:23 +00:00
|
|
|
BindingIndex GetBufferCount() const;
|
2020-03-20 21:56:30 +00:00
|
|
|
// Returns |BindingIndex| because dynamic buffers are packed at the front.
|
|
|
|
BindingIndex GetDynamicBufferCount() const;
|
2020-06-19 21:39:23 +00:00
|
|
|
uint32_t GetUnverifiedBufferCount() const;
|
2019-05-17 02:05:37 +00:00
|
|
|
|
2020-07-14 00:53:23 +00:00
|
|
|
// Used to get counts and validate them in pipeline layout creation. Other getters
|
|
|
|
// should be used to get typed integer counts.
|
|
|
|
const BindingCounts& GetBindingCountInfo() const;
|
|
|
|
|
2020-03-13 22:50:00 +00:00
|
|
|
struct BufferBindingData {
|
|
|
|
uint64_t offset;
|
|
|
|
uint64_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BindingDataPointers {
|
2020-06-17 22:35:19 +00:00
|
|
|
ityp::span<BindingIndex, BufferBindingData> const bufferData = {};
|
|
|
|
ityp::span<BindingIndex, Ref<ObjectBase>> const bindings = {};
|
2020-06-19 21:39:23 +00:00
|
|
|
ityp::span<uint32_t, uint64_t> const unverifiedBufferSizes = {};
|
2020-03-13 22:50:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Compute the amount of space / alignment required to store bindings for a bind group of
|
|
|
|
// this layout.
|
|
|
|
size_t GetBindingDataSize() const;
|
|
|
|
static constexpr size_t GetBindingDataAlignment() {
|
|
|
|
static_assert(alignof(Ref<ObjectBase>) <= alignof(BufferBindingData), "");
|
|
|
|
return alignof(BufferBindingData);
|
|
|
|
}
|
|
|
|
|
|
|
|
BindingDataPointers ComputeBindingDataPointers(void* dataStart) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
template <typename BindGroup>
|
|
|
|
SlabAllocator<BindGroup> MakeFrontendBindGroupAllocator(size_t size) {
|
|
|
|
return SlabAllocator<BindGroup>(
|
|
|
|
size, // bytes
|
|
|
|
Align(sizeof(BindGroup), GetBindingDataAlignment()) + GetBindingDataSize(), // size
|
|
|
|
std::max(alignof(BindGroup), GetBindingDataAlignment()) // alignment
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
2019-02-13 13:09:18 +00:00
|
|
|
BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag);
|
|
|
|
|
2020-07-14 00:53:23 +00:00
|
|
|
BindingCounts mBindingCounts = {};
|
2020-07-14 22:20:35 +00:00
|
|
|
ityp::vector<BindingIndex, BindingInfo> mBindingInfo;
|
2020-03-20 21:56:30 +00:00
|
|
|
|
|
|
|
// Map from BindGroupLayoutEntry.binding to packed indices.
|
|
|
|
BindingMap mBindingMap;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
2018-07-24 14:45:45 +00:00
|
|
|
} // namespace dawn_native
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-24 14:42:33 +00:00
|
|
|
#endif // DAWNNATIVE_BINDGROUPLAYOUT_H_
|