diff options
Diffstat (limited to 'src/pipeline.h')
-rw-r--r-- | src/pipeline.h | 197 |
1 files changed, 181 insertions, 16 deletions
diff --git a/src/pipeline.h b/src/pipeline.h index e874613..ec38a3a 100644 --- a/src/pipeline.h +++ b/src/pipeline.h @@ -24,6 +24,9 @@ #include "amber/result.h" #include "src/buffer.h" +#include "src/command_data.h" +#include "src/pipeline_data.h" +#include "src/sampler.h" #include "src/shader.h" namespace amber { @@ -60,6 +63,36 @@ class Pipeline { return compile_options_; } + enum class RequiredSubgroupSizeSetting : uint32_t { + kNotSet = 0, + kSetToSpecificSize, + kSetToMinimumSize, + kSetToMaximumSize + }; + + void SetRequiredSubgroupSizeSetting(RequiredSubgroupSizeSetting setting, + uint32_t size) { + required_subgroup_size_setting_ = setting; + required_subgroup_size_ = size; + } + RequiredSubgroupSizeSetting GetRequiredSubgroupSizeSetting() const { + return required_subgroup_size_setting_; + } + uint32_t GetRequiredSubgroupSize() const { return required_subgroup_size_; } + + void SetVaryingSubgroupSize(const bool isSet) { + varying_subgroup_size_ = isSet; + } + bool GetVaryingSubgroupSize() const { return varying_subgroup_size_; } + + void SetRequireFullSubgroups(const bool isSet) { + require_full_subgroups_ = isSet; + } + bool GetRequireFullSubgroups() const { return require_full_subgroups_; } + + void SetEmitDebugInfo(const bool isSet) { emit_debug_info_ = isSet; } + bool GetEmitDebugInfo() const { return emit_debug_info_; } + void SetShader(Shader* shader) { shader_ = shader; } const Shader* GetShader() const { return shader_; } @@ -89,6 +122,10 @@ class Pipeline { UBO, POD, POD_UBO, + POD_PUSHCONSTANT, + RO_IMAGE, + WO_IMAGE, + SAMPLER, } kind; uint32_t descriptor_set = 0; @@ -107,6 +144,25 @@ class Pipeline { return descriptor_map_; } + /// Push constant information for an OpenCL-C shader. + struct PushConstant { + enum class PushConstantType { + kDimensions = 0, + kGlobalOffset, + kRegionOffset, + }; + PushConstantType type; + uint32_t offset = 0; + uint32_t size = 0; + }; + + void AddPushConstant(PushConstant&& pc) { + push_constants_.emplace_back(std::move(pc)); + } + const std::vector<PushConstant>& GetPushConstants() const { + return push_constants_; + } + private: Shader* shader_ = nullptr; ShaderType shader_type_; @@ -116,7 +172,13 @@ class Pipeline { std::map<uint32_t, uint32_t> specialization_; std::unordered_map<std::string, std::vector<DescriptorMapEntry>> descriptor_map_; + std::vector<PushConstant> push_constants_; std::vector<std::string> compile_options_; + RequiredSubgroupSizeSetting required_subgroup_size_setting_; + uint32_t required_subgroup_size_; + bool varying_subgroup_size_; + bool require_full_subgroups_; + bool emit_debug_info_; }; /// Information on a buffer attached to the pipeline. @@ -131,12 +193,34 @@ class Pipeline { uint32_t descriptor_set = 0; uint32_t binding = 0; uint32_t location = 0; + uint32_t base_mip_level = 0; + uint32_t dynamic_offset = 0; + std::string arg_name = ""; + uint32_t arg_no = 0; + BufferType type = BufferType::kUnknown; + InputRate input_rate = InputRate::kVertex; + Format* format; + uint32_t offset = 0; + uint32_t stride = 0; + Sampler* sampler = nullptr; + }; + + /// Information on a sampler attached to the pipeline. + struct SamplerInfo { + SamplerInfo() = default; + explicit SamplerInfo(Sampler* samp) : sampler(samp) {} + + Sampler* sampler = nullptr; + uint32_t descriptor_set = 0; + uint32_t binding = 0; std::string arg_name = ""; uint32_t arg_no = 0; + uint32_t mask = 0; }; static const char* kGeneratedColorBuffer; static const char* kGeneratedDepthBuffer; + static const char* kGeneratedPushConstantBuffer; explicit Pipeline(PipelineType type); ~Pipeline(); @@ -170,6 +254,15 @@ class Pipeline { /// Returns information on all bound shaders in this pipeline. const std::vector<ShaderInfo>& GetShaders() const { return shaders_; } + /// Returns the ShaderInfo for |shader| or nullptr. + const ShaderInfo* GetShader(Shader* shader) const { + for (const auto& info : shaders_) { + if (info.GetShader() == shader) + return &info; + } + return nullptr; + } + /// Sets the |type| of |shader| in the pipeline. Result SetShaderType(const Shader* shader, ShaderType type); /// Sets the entry point |name| for |shader| in this pipeline. @@ -180,30 +273,60 @@ class Pipeline { /// Sets the compile options for |shader| in this pipeline. Result SetShaderCompileOptions(const Shader* shader, const std::vector<std::string>& options); + /// Sets required subgroup size. + Result SetShaderRequiredSubgroupSize(const Shader* shader, + const uint32_t subgroupSize); + /// Sets required subgroup size to the device minimum supported subgroup size. + Result SetShaderRequiredSubgroupSizeToMinimum(const Shader* shader); + + /// Sets required subgroup size to the device maximum supported subgroup size. + Result SetShaderRequiredSubgroupSizeToMaximum(const Shader* shader); + /// Sets varying subgroup size property. + Result SetShaderVaryingSubgroupSize(const Shader* shader, const bool isSet); + + /// Sets require full subgroups property. + Result SetShaderRequireFullSubgroups(const Shader* shader, const bool isSet); /// Returns a list of all colour attachments in this pipeline. const std::vector<BufferInfo>& GetColorAttachments() const { return color_attachments_; } /// Adds |buf| as a colour attachment at |location| in the pipeline. - Result AddColorAttachment(Buffer* buf, uint32_t location); + /// Uses |base_mip_level| as the mip level for output. + Result AddColorAttachment(Buffer* buf, + uint32_t location, + uint32_t base_mip_level); /// Retrieves the location that |buf| is bound to in the pipeline. The /// location will be written to |loc|. An error result will be return if /// something goes wrong. Result GetLocationForColorAttachment(Buffer* buf, uint32_t* loc) const; - /// Sets |buf| as the depth buffer for this pipeline. - Result SetDepthBuffer(Buffer* buf); - /// Returns information on the depth buffer bound to the pipeline. If no - /// depth buffer is bound the |BufferInfo::buffer| parameter will be nullptr. - const BufferInfo& GetDepthBuffer() const { return depth_buffer_; } + /// Sets |buf| as the depth/stencil buffer for this pipeline. + Result SetDepthStencilBuffer(Buffer* buf); + /// Returns information on the depth/stencil buffer bound to the pipeline. If + /// no depth buffer is bound the |BufferInfo::buffer| parameter will be + /// nullptr. + const BufferInfo& GetDepthStencilBuffer() const { + return depth_stencil_buffer_; + } + + /// Returns pipeline data. + PipelineData* GetPipelineData() { return &pipeline_data_; } /// Returns information on all vertex buffers bound to the pipeline. const std::vector<BufferInfo>& GetVertexBuffers() const { return vertex_buffers_; } - /// Adds |buf| as a vertex buffer at |location| in the pipeline. - Result AddVertexBuffer(Buffer* buf, uint32_t location); + /// Adds |buf| as a vertex buffer at |location| in the pipeline using |rate| + /// as the input rate, |format| as vertex data format, |offset| as a starting + /// offset for the vertex buffer data, and |stride| for the data stride in + /// bytes. + Result AddVertexBuffer(Buffer* buf, + uint32_t location, + InputRate rate, + Format* format, + uint32_t offset, + uint32_t stride); /// Binds |buf| as the index buffer for this pipeline. Result SetIndexBuffer(Buffer* buf); @@ -211,14 +334,39 @@ class Pipeline { /// buffer bound. Buffer* GetIndexBuffer() const { return index_buffer_; } - /// Adds |buf| to the pipeline at the given |descriptor_set| and |binding|. - void AddBuffer(Buffer* buf, uint32_t descriptor_set, uint32_t binding); + /// Adds |buf| of |type| to the pipeline at the given |descriptor_set|, + /// |binding|, |base_mip_level|, and |dynamic_offset|. + void AddBuffer(Buffer* buf, + BufferType type, + uint32_t descriptor_set, + uint32_t binding, + uint32_t base_mip_level, + uint32_t dynamic_offset); /// Adds |buf| to the pipeline at the given |arg_name|. - void AddBuffer(Buffer* buf, const std::string& arg_name); + void AddBuffer(Buffer* buf, BufferType type, const std::string& arg_name); /// Adds |buf| to the pipeline at the given |arg_no|. - void AddBuffer(Buffer* buf, uint32_t arg_no); + void AddBuffer(Buffer* buf, BufferType type, uint32_t arg_no); /// Returns information on all buffers in this pipeline. const std::vector<BufferInfo>& GetBuffers() const { return buffers_; } + /// Clears all buffer bindings for given |descriptor_set| and |binding|. + void ClearBuffers(uint32_t descriptor_set, uint32_t binding); + + /// Adds |sampler| to the pipeline at the given |descriptor_set| and + /// |binding|. + void AddSampler(Sampler* sampler, uint32_t descriptor_set, uint32_t binding); + /// Adds |sampler| to the pipeline at the given |arg_name|. + void AddSampler(Sampler* sampler, const std::string& arg_name); + /// Adds |sampler| to the pieline at the given |arg_no|. + void AddSampler(Sampler* sampler, uint32_t arg_no); + /// Adds an entry for an OpenCL literal sampler. + void AddSampler(uint32_t sampler_mask, + uint32_t descriptor_set, + uint32_t binding); + /// Clears all sampler bindings for given |descriptor_set| and |binding|. + void ClearSamplers(uint32_t descriptor_set, uint32_t binding); + + /// Returns information on all samplers in this pipeline. + const std::vector<SamplerInfo>& GetSamplers() const { return samplers_; } /// Updates the descriptor set and binding info for the OpenCL-C kernel bound /// to the pipeline. No effect for other shader formats. @@ -238,8 +386,8 @@ class Pipeline { /// Generates a default color attachment in B8G8R8A8_UNORM. std::unique_ptr<Buffer> GenerateDefaultColorAttachmentBuffer(); - /// Generates a default depth attachment in D32_SFLOAT_S8_UINT format. - std::unique_ptr<Buffer> GenerateDefaultDepthAttachmentBuffer(); + /// Generates a default depth/stencil attachment in D32_SFLOAT_S8_UINT format. + std::unique_ptr<Buffer> GenerateDefaultDepthStencilAttachmentBuffer(); /// Information on values set for OpenCL-C plain-old-data args. struct ArgSetInfo { @@ -259,9 +407,23 @@ class Pipeline { /// command. This should be called after all other buffers are bound. Result GenerateOpenCLPodBuffers(); + /// Generate the samplers necessary for OpenCL literal samplers from the + /// descriptor map. This should be called after all other samplers are bound. + Result GenerateOpenCLLiteralSamplers(); + + /// Generate the push constant buffers necessary for OpenCL kernels. + Result GenerateOpenCLPushConstants(); + private: void UpdateFramebufferSizes(); + Result SetShaderRequiredSubgroupSize( + const Shader* shader, + const ShaderInfo::RequiredSubgroupSizeSetting setting, + const uint32_t subgroupSize); + + Result CreatePushConstantBuffer(); + Result ValidateGraphics() const; Result ValidateCompute() const; @@ -272,11 +434,12 @@ class Pipeline { std::vector<BufferInfo> vertex_buffers_; std::vector<BufferInfo> buffers_; std::vector<std::unique_ptr<type::Type>> types_; + std::vector<SamplerInfo> samplers_; std::vector<std::unique_ptr<Format>> formats_; - BufferInfo depth_buffer_; + BufferInfo depth_stencil_buffer_; BufferInfo push_constant_buffer_; Buffer* index_buffer_ = nullptr; - + PipelineData pipeline_data_; uint32_t fb_width_ = 250; uint32_t fb_height_ = 250; @@ -284,6 +447,8 @@ class Pipeline { std::vector<std::unique_ptr<Buffer>> opencl_pod_buffers_; /// Maps (descriptor set, binding) to the buffer for that binding pair. std::map<std::pair<uint32_t, uint32_t>, Buffer*> opencl_pod_buffer_map_; + std::vector<std::unique_ptr<Sampler>> opencl_literal_samplers_; + std::unique_ptr<Buffer> opencl_push_constants_; }; } // namespace amber |