Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 1 | // Copyright 2019 The SwiftShader Authors. All Rights Reserved. |
| 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 sw_ComputeProgram_hpp |
| 16 | #define sw_ComputeProgram_hpp |
| 17 | |
| 18 | #include "SpirvShader.hpp" |
| 19 | |
| 20 | #include "Reactor/Reactor.hpp" |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 21 | #include "Device/Context.hpp" |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 22 | #include "Vulkan/VkDescriptorSet.hpp" |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 23 | |
| 24 | #include <functional> |
| 25 | |
| 26 | namespace vk |
| 27 | { |
| 28 | class PipelineLayout; |
| 29 | } // namespace vk |
| 30 | |
| 31 | namespace sw |
| 32 | { |
| 33 | |
| 34 | using namespace rr; |
| 35 | |
| 36 | class DescriptorSetsLayout; |
| 37 | |
| 38 | // ComputeProgram builds a SPIR-V compute shader. |
| 39 | class ComputeProgram : public Function<Void(Pointer<Byte>)> |
| 40 | { |
| 41 | public: |
Nicolas Capens | 09591b8 | 2019-04-08 22:51:08 -0400 | [diff] [blame] | 42 | ComputeProgram(SpirvShader const *spirvShader, vk::PipelineLayout const *pipelineLayout, const vk::DescriptorSet::Bindings &descriptorSets); |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 43 | |
| 44 | virtual ~ComputeProgram(); |
| 45 | |
| 46 | // generate builds the shader program. |
| 47 | void generate(); |
| 48 | |
| 49 | // run executes the compute shader routine for all workgroups. |
| 50 | // TODO(bclayton): This probably does not belong here. Consider moving. |
| 51 | static void run( |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 52 | Routine *routine, |
| 53 | vk::DescriptorSet::Bindings const &descriptorSetBindings, |
| 54 | vk::DescriptorSet::DynamicOffsets const &descriptorDynamicOffsets, |
| 55 | PushConstantStorage const &pushConstants, |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 56 | uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ); |
| 57 | |
| 58 | protected: |
| 59 | void emit(); |
| 60 | |
Ben Clayton | c2bb50b | 2019-03-13 14:28:32 +0000 | [diff] [blame] | 61 | void setInputBuiltin(spv::BuiltIn id, std::function<void(const SpirvShader::BuiltinMapping& builtin, Array<SIMD::Float>& value)> cb); |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 62 | |
| 63 | Pointer<Byte> data; // argument 0 |
| 64 | |
| 65 | struct Data |
| 66 | { |
Ben Clayton | 225a130 | 2019-04-02 12:28:22 +0100 | [diff] [blame] | 67 | vk::DescriptorSet::Bindings descriptorSets; |
| 68 | vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets; |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 69 | uint4 numWorkgroups; |
| 70 | uint4 workgroupID; |
Chris Forbes | a30de54 | 2019-03-18 18:51:55 -0700 | [diff] [blame] | 71 | PushConstantStorage pushConstants; |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | SpirvRoutine routine; |
| 75 | SpirvShader const * const shader; |
| 76 | vk::PipelineLayout const * const pipelineLayout; |
Nicolas Capens | 09591b8 | 2019-04-08 22:51:08 -0400 | [diff] [blame] | 77 | const vk::DescriptorSet::Bindings &descriptorSets; |
Ben Clayton | f2be26a | 2019-03-08 12:02:05 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace sw |
| 81 | |
| 82 | #endif // sw_ComputeProgram_hpp |