Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 1 | // Copyright 2018 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 VK_SHADER_MODULE_HPP_ |
| 16 | #define VK_SHADER_MODULE_HPP_ |
| 17 | |
| 18 | #include "VkObject.hpp" |
Nicolas Capens | 4aa4fcd | 2019-06-19 13:14:11 -0400 | [diff] [blame] | 19 | |
| 20 | #include <atomic> |
Chris Forbes | af4ed53 | 2018-12-06 18:33:27 -0800 | [diff] [blame] | 21 | #include <vector> |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 22 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 23 | namespace rr { |
| 24 | class Routine; |
| 25 | } |
Alexis Hetu | c0f92f2 | 2018-11-15 16:25:38 -0500 | [diff] [blame] | 26 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 27 | namespace vk { |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 28 | |
| 29 | class ShaderModule : public Object<ShaderModule, VkShaderModule> |
| 30 | { |
| 31 | public: |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 32 | ShaderModule(const VkShaderModuleCreateInfo *pCreateInfo, void *mem); |
| 33 | void destroy(const VkAllocationCallbacks *pAllocator); |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 34 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 35 | static size_t ComputeRequiredAllocationSize(const VkShaderModuleCreateInfo *pCreateInfo); |
Chris Forbes | af4ed53 | 2018-12-06 18:33:27 -0800 | [diff] [blame] | 36 | // TODO: reconsider boundary of ShaderModule class; try to avoid 'expose the |
| 37 | // guts' operations, and this copy. |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 38 | std::vector<uint32_t> getCode() const { return std::vector<uint32_t>{ code, code + wordCount }; } |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 39 | |
Nicolas Capens | 4aa4fcd | 2019-06-19 13:14:11 -0400 | [diff] [blame] | 40 | uint32_t getSerialID() const { return serialID; } |
| 41 | static uint32_t nextSerialID() { return serialCounter++; } |
| 42 | |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 43 | private: |
Nicolas Capens | 4aa4fcd | 2019-06-19 13:14:11 -0400 | [diff] [blame] | 44 | const uint32_t serialID; |
| 45 | static std::atomic<uint32_t> serialCounter; |
| 46 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 47 | uint32_t *code = nullptr; |
Chris Forbes | af4ed53 | 2018-12-06 18:33:27 -0800 | [diff] [blame] | 48 | uint32_t wordCount = 0; |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 49 | }; |
| 50 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 51 | static inline ShaderModule *Cast(VkShaderModule object) |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 52 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 53 | return ShaderModule::Cast(object); |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 54 | } |
| 55 | |
Nicolas Capens | 157ba26 | 2019-12-10 17:49:14 -0500 | [diff] [blame] | 56 | } // namespace vk |
Alexis Hetu | 259ad3d | 2018-11-15 13:44:31 -0500 | [diff] [blame] | 57 | |
Ben Clayton | 2ed93ab | 2019-12-17 20:38:03 +0000 | [diff] [blame] | 58 | #endif // VK_SHADER_MODULE_HPP_ |