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_SHADERMODULE_H_
|
|
|
|
#define BACKEND_SHADERMODULE_H_
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/Builder.h"
|
2017-11-24 18:59:42 +00:00
|
|
|
#include "backend/Forward.h"
|
2017-07-06 18:41:13 +00:00
|
|
|
#include "backend/RefCounted.h"
|
|
|
|
#include "common/Constants.h"
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
#include "nxt/nxtcpp.h"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <bitset>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace spirv_cross {
|
|
|
|
class Compiler;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace backend {
|
|
|
|
|
|
|
|
class ShaderModuleBase : public RefCounted {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
|
|
|
ShaderModuleBase(ShaderModuleBuilder* builder);
|
|
|
|
|
|
|
|
DeviceBase* GetDevice() const;
|
|
|
|
|
|
|
|
void ExtractSpirvInfo(const spirv_cross::Compiler& compiler);
|
|
|
|
|
|
|
|
struct PushConstantInfo {
|
|
|
|
std::bitset<kMaxPushConstants> mask;
|
|
|
|
|
|
|
|
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>;
|
|
|
|
|
|
|
|
const PushConstantInfo& GetPushConstants() const;
|
|
|
|
const ModuleBindingInfo& GetBindingInfo() const;
|
|
|
|
const std::bitset<kMaxVertexAttributes>& GetUsedVertexAttributes() const;
|
|
|
|
nxt::ShaderStage GetExecutionModel() const;
|
|
|
|
|
|
|
|
bool IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout);
|
|
|
|
|
|
|
|
DeviceBase* mDevice;
|
|
|
|
PushConstantInfo mPushConstants = {};
|
|
|
|
ModuleBindingInfo mBindingInfo;
|
|
|
|
std::bitset<kMaxVertexAttributes> mUsedVertexAttributes;
|
|
|
|
nxt::ShaderStage mExecutionModel;
|
2017-04-20 18:38:20 +00:00
|
|
|
};
|
|
|
|
|
2017-05-08 13:17:44 +00:00
|
|
|
class ShaderModuleBuilder : public Builder<ShaderModuleBase> {
|
2017-11-24 18:59:42 +00:00
|
|
|
public:
|
|
|
|
ShaderModuleBuilder(DeviceBase* device);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
std::vector<uint32_t> AcquireSpirv();
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
// NXT API
|
|
|
|
void SetSource(uint32_t codeSize, const uint32_t* code);
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
private:
|
|
|
|
friend class ShaderModuleBase;
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
ShaderModuleBase* GetResultImpl() override;
|
2017-05-08 13:17:44 +00:00
|
|
|
|
2017-11-24 18:59:42 +00:00
|
|
|
std::vector<uint32_t> mSpirv;
|
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_SHADERMODULE_H_
|