2017-04-20 18:38:20 +00:00
|
|
|
// Copyright 2017 The NXT Authors
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#ifndef BACKEND_PERSTAGE_H_
|
|
|
|
#define BACKEND_PERSTAGE_H_
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-10 17:46:05 +00:00
|
|
|
#include "common/Assert.h"
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "common/BitSetIterator.h"
|
|
|
|
#include "common/Constants.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
#include "nxt/nxtcpp.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace backend {
|
|
|
|
|
|
|
|
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Vertex) < kNumStages, "");
|
|
|
|
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Fragment) < kNumStages, "");
|
|
|
|
static_assert(static_cast<uint32_t>(nxt::ShaderStage::Compute) < kNumStages, "");
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
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)),
|
|
|
|
"");
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
BitSetIterator<kNumStages, nxt::ShaderStage> IterateStages(nxt::ShaderStageBit stages);
|
|
|
|
nxt::ShaderStageBit StageBit(nxt::ShaderStage stage);
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
static constexpr nxt::ShaderStageBit kAllStages =
|
|
|
|
static_cast<nxt::ShaderStageBit>((1 << kNumStages) - 1);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
template <typename T>
|
2017-04-20 18:38:20 +00:00
|
|
|
class PerStage {
|
2017-11-24 18:59:42 +00:00
|
|
|
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)];
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
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)];
|
|
|
|
}
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
|
|
|
std::array<T, kNumStages> mData;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
} // namespace backend
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
#endif // BACKEND_PERSTAGE_H_
|