1 // Copyright 2019 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_VULKAN_PUSH_CONSTANT_H_ 16 #define SRC_VULKAN_PUSH_CONSTANT_H_ 17 18 #include <memory> 19 #include <vector> 20 21 #include "amber/result.h" 22 #include "amber/vulkan_header.h" 23 #include "src/command.h" 24 25 namespace amber { 26 namespace vulkan { 27 28 class CommandBuffer; 29 class Device; 30 31 /// Class to handle push constants. 32 class PushConstant { 33 public: 34 explicit PushConstant(Device* device); 35 ~PushConstant(); 36 37 /// Retrieves a `VkPushConstantRange` class describing our push constant 38 /// requirements. 39 VkPushConstantRange GetVkPushConstantRange(); 40 41 Result RecordPushConstantVkCommand(CommandBuffer* command, 42 VkPipelineLayout pipeline_layout); 43 44 /// Add a set of values from the given |buffer| to the push constants 45 /// to be used on the next pipeline execution. The data will be added to 46 /// the push constants at |offset|. 47 Result AddBuffer(const Buffer* buffer, uint32_t offset); 48 49 /// Adds data into the push constant buffer. 50 Result AddBufferData(const BufferCommand* command); 51 52 private: 53 // Information on filling the push constant buffer. The |buffer| memory will 54 // be copied into the result buffer at |offset|. 55 struct BufferInput { 56 uint32_t offset = 0; 57 const Buffer* buffer = nullptr; 58 }; 59 60 Result UpdateMemoryWithInput(const BufferInput& input); 61 62 Device* device_; 63 64 /// Keeps the information of what and how to conduct push constant. 65 /// These are applied from lowest index to highest index, so that 66 /// if address ranges overlap, then the later values take effect. 67 std::vector<BufferInput> push_constant_data_; 68 std::unique_ptr<Buffer> buffer_; 69 }; 70 71 } // namespace vulkan 72 } // namespace amber 73 74 #endif // SRC_VULKAN_PUSH_CONSTANT_H_ 75