blob: 19dc131fd6e834f2036e4c85fa9b7f63d0423659 [file] [log] [blame]
Alexis Hetu259ad3d2018-11-15 13:44:31 -05001// 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 Capens4aa4fcd2019-06-19 13:14:11 -040019
20#include <atomic>
Chris Forbesaf4ed532018-12-06 18:33:27 -080021#include <vector>
Alexis Hetu259ad3d2018-11-15 13:44:31 -050022
Ben Clayton2ed93ab2019-12-17 20:38:03 +000023namespace rr {
24class Routine;
25}
Alexis Hetuc0f92f22018-11-15 16:25:38 -050026
Nicolas Capens157ba262019-12-10 17:49:14 -050027namespace vk {
Alexis Hetu259ad3d2018-11-15 13:44:31 -050028
29class ShaderModule : public Object<ShaderModule, VkShaderModule>
30{
31public:
Ben Clayton2ed93ab2019-12-17 20:38:03 +000032 ShaderModule(const VkShaderModuleCreateInfo *pCreateInfo, void *mem);
33 void destroy(const VkAllocationCallbacks *pAllocator);
Alexis Hetu259ad3d2018-11-15 13:44:31 -050034
Ben Clayton2ed93ab2019-12-17 20:38:03 +000035 static size_t ComputeRequiredAllocationSize(const VkShaderModuleCreateInfo *pCreateInfo);
Chris Forbesaf4ed532018-12-06 18:33:27 -080036 // TODO: reconsider boundary of ShaderModule class; try to avoid 'expose the
37 // guts' operations, and this copy.
Ben Clayton2ed93ab2019-12-17 20:38:03 +000038 std::vector<uint32_t> getCode() const { return std::vector<uint32_t>{ code, code + wordCount }; }
Alexis Hetu259ad3d2018-11-15 13:44:31 -050039
Nicolas Capens4aa4fcd2019-06-19 13:14:11 -040040 uint32_t getSerialID() const { return serialID; }
41 static uint32_t nextSerialID() { return serialCounter++; }
42
Alexis Hetu259ad3d2018-11-15 13:44:31 -050043private:
Nicolas Capens4aa4fcd2019-06-19 13:14:11 -040044 const uint32_t serialID;
45 static std::atomic<uint32_t> serialCounter;
46
Ben Clayton2ed93ab2019-12-17 20:38:03 +000047 uint32_t *code = nullptr;
Chris Forbesaf4ed532018-12-06 18:33:27 -080048 uint32_t wordCount = 0;
Alexis Hetu259ad3d2018-11-15 13:44:31 -050049};
50
Ben Clayton2ed93ab2019-12-17 20:38:03 +000051static inline ShaderModule *Cast(VkShaderModule object)
Alexis Hetu259ad3d2018-11-15 13:44:31 -050052{
Alexis Hetubd4cf812019-06-14 15:14:07 -040053 return ShaderModule::Cast(object);
Alexis Hetu259ad3d2018-11-15 13:44:31 -050054}
55
Nicolas Capens157ba262019-12-10 17:49:14 -050056} // namespace vk
Alexis Hetu259ad3d2018-11-15 13:44:31 -050057
Ben Clayton2ed93ab2019-12-17 20:38:03 +000058#endif // VK_SHADER_MODULE_HPP_