1 // Copyright 2018 The Amber Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SRC_DAWN_PIPELINE_INFO_H_ 16 #define SRC_DAWN_PIPELINE_INFO_H_ 17 18 #include <cstdint> 19 #include <memory> 20 #include <set> 21 #include <unordered_map> 22 #include <utility> 23 #include <vector> 24 25 #include "amber/result.h" 26 #include "dawn/dawncpp.h" 27 #include "src/command.h" 28 #include "src/format.h" 29 30 namespace amber { 31 namespace dawn { 32 33 struct hash_pair { 34 template <class T1, class T2> operatorhash_pair35 size_t operator()(const std::pair<T1, T2>& p) const { 36 auto hash1 = std::hash<T1>{}(p.first); 37 auto hash2 = std::hash<T2>{}(p.second); 38 return hash1 ^ hash2; 39 } 40 }; 41 42 /// Stores information relating to a graphics pipeline in Dawn. 43 struct RenderPipelineInfo { RenderPipelineInfoRenderPipelineInfo44 RenderPipelineInfo() {} RenderPipelineInfoRenderPipelineInfo45 RenderPipelineInfo(::amber::Pipeline* the_pipeline, 46 ::dawn::ShaderModule vert, 47 ::dawn::ShaderModule frag) 48 : pipeline(the_pipeline), vertex_shader(vert), fragment_shader(frag) {} 49 50 ::amber::Pipeline* pipeline = nullptr; 51 52 ::dawn::ShaderModule vertex_shader; 53 ::dawn::ShaderModule fragment_shader; 54 ::dawn::Color clear_color_value = {0.f, 0.f, 0.f, 0.f}; 55 float clear_depth_value = 1.0f; 56 uint32_t clear_stencil_value = 0; 57 58 // Depth-stencil target. This resides on the GPU. 59 ::dawn::Texture depth_stencil_texture; 60 // Vertex buffers 61 std::vector<::dawn::Buffer> vertex_buffers; 62 // Index buffer 63 ::dawn::Buffer index_buffer; 64 // Storage and uniform buffers 65 std::vector<::dawn::Buffer> buffers; 66 // Binding info 67 std::vector<::dawn::BindGroup> bind_groups; 68 std::vector<::dawn::BindGroupLayout> bind_group_layouts; 69 70 // Mapping from the <descriptor_set, binding> to dawn buffer index in buffers 71 std::unordered_map<std::pair<uint32_t, uint32_t>, uint32_t, hash_pair> 72 buffer_map; 73 std::set<int> used_descriptor_set; 74 }; 75 76 /// Stores information relating to a compute pipeline in Dawn. 77 struct ComputePipelineInfo { ComputePipelineInfoComputePipelineInfo78 ComputePipelineInfo() {} ComputePipelineInfoComputePipelineInfo79 ComputePipelineInfo(::amber::Pipeline* the_pipeline, 80 ::dawn::ShaderModule comp) 81 : pipeline(the_pipeline), compute_shader(comp) {} 82 83 ::amber::Pipeline* pipeline = nullptr; 84 ::dawn::ShaderModule compute_shader; 85 86 // storage and uniform buffers 87 std::vector<::dawn::Buffer> buffers; 88 89 std::vector<::dawn::BindGroup> bind_groups; 90 std::vector<::dawn::BindGroupLayout> bind_group_layouts; 91 92 // Mapping from the <descriptor_set, binding> to dawn buffer index in buffers 93 std::unordered_map<std::pair<uint32_t, uint32_t>, uint32_t, hash_pair> 94 buffer_map; 95 std::set<int> used_descriptor_set; 96 }; 97 98 /// Holds either a render or compute pipeline. 99 struct Pipeline { 100 std::unique_ptr<RenderPipelineInfo> render_pipeline; 101 std::unique_ptr<ComputePipelineInfo> compute_pipeline; 102 }; 103 104 } // namespace dawn 105 } // namespace amber 106 107 #endif // SRC_DAWN_PIPELINE_INFO_H_ 108