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"
19
20#include <atomic>
21#include <vector>
22
23namespace rr
24{
25 class Routine;
26}
27
28namespace vk
29{
30
31class ShaderModule : public Object<ShaderModule, VkShaderModule>
32{
33public:
34 ShaderModule(const VkShaderModuleCreateInfo* pCreateInfo, void* mem);
35 void destroy(const VkAllocationCallbacks* pAllocator);
36
37 static size_t ComputeRequiredAllocationSize(const VkShaderModuleCreateInfo* pCreateInfo);
38 // TODO: reconsider boundary of ShaderModule class; try to avoid 'expose the
39 // guts' operations, and this copy.
40 std::vector<uint32_t> getCode() const { return std::vector<uint32_t>{ code, code + wordCount };}
41
42 uint32_t getSerialID() const { return serialID; }
43 static uint32_t nextSerialID() { return serialCounter++; }
44
45private:
46 const uint32_t serialID;
47 static std::atomic<uint32_t> serialCounter;
48
49 uint32_t* code = nullptr;
50 uint32_t wordCount = 0;
51};
52
53static inline ShaderModule* Cast(VkShaderModule object)
54{
55 return ShaderModule::Cast(object);
56}
57
58} // namespace vk
59
60#endif // VK_SHADER_MODULE_HPP_
61