// 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. #ifndef BACKEND_COMMON_SHADERMODULE_H_ #define BACKEND_COMMON_SHADERMODULE_H_ #include "Forward.h" #include "Builder.h" #include "RefCounted.h" #include "nxt/nxtcpp.h" #include #include #include namespace spirv_cross { class Compiler; } namespace backend { class ShaderModuleBase : public RefCounted { public: ShaderModuleBase(ShaderModuleBuilder* builder); void ExtractSpirvInfo(const spirv_cross::Compiler& compiler); struct PushConstantInfo { std::bitset mask; std::array names; std::array sizes; std::array 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, kMaxBindGroups>; const PushConstantInfo& GetPushConstants() const; const ModuleBindingInfo& GetBindingInfo() const; const std::bitset& GetUsedVertexAttributes() const; nxt::ShaderStage GetExecutionModel() const; bool IsCompatibleWithPipelineLayout(const PipelineLayoutBase* layout); private: bool IsCompatibleWithBindGroupLayout(size_t group, const BindGroupLayoutBase* layout); DeviceBase* device; PushConstantInfo pushConstants = {}; ModuleBindingInfo bindingInfo; std::bitset usedVertexAttributes; nxt::ShaderStage executionModel; }; class ShaderModuleBuilder : public Builder { public: ShaderModuleBuilder(DeviceBase* device); std::vector AcquireSpirv(); // NXT API ShaderModuleBase* GetResult(); void SetSource(uint32_t codeSize, const uint32_t* code); private: friend class ShaderModuleBase; std::vector spirv; }; } #endif // BACKEND_COMMON_SHADERMODULE_H_