• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Dawn 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 DAWNNATIVE_VULKAN_SHADERMODULEVK_H_
16 #define DAWNNATIVE_VULKAN_SHADERMODULEVK_H_
17 
18 #include "dawn_native/ShaderModule.h"
19 
20 #include "common/vulkan_platform.h"
21 #include "dawn_native/Error.h"
22 
23 #include <mutex>
24 
25 namespace dawn_native { namespace vulkan {
26 
27     class Device;
28     class PipelineLayout;
29 
30     class ShaderModule final : public ShaderModuleBase {
31       public:
32         static ResultOrError<Ref<ShaderModule>> Create(Device* device,
33                                                        const ShaderModuleDescriptor* descriptor,
34                                                        ShaderModuleParseResult* parseResult);
35 
36         ResultOrError<VkShaderModule> GetTransformedModuleHandle(const char* entryPointName,
37                                                                  PipelineLayout* layout);
38 
39       private:
40         ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
41         ~ShaderModule() override;
42         MaybeError Initialize(ShaderModuleParseResult* parseResult);
43         void DestroyImpl() override;
44 
45         // New handles created by GetTransformedModuleHandle at pipeline creation time
46         class ConcurrentTransformedShaderModuleCache {
47           public:
48             explicit ConcurrentTransformedShaderModuleCache(Device* device);
49             ~ConcurrentTransformedShaderModuleCache();
50             VkShaderModule FindShaderModule(const PipelineLayoutEntryPointPair& key);
51             VkShaderModule AddOrGetCachedShaderModule(const PipelineLayoutEntryPointPair& key,
52                                                       VkShaderModule value);
53 
54           private:
55             Device* mDevice;
56             std::mutex mMutex;
57             std::unordered_map<PipelineLayoutEntryPointPair,
58                                VkShaderModule,
59                                PipelineLayoutEntryPointPairHashFunc>
60                 mTransformedShaderModuleCache;
61         };
62         std::unique_ptr<ConcurrentTransformedShaderModuleCache> mTransformedShaderModuleCache;
63     };
64 
65 }}  // namespace dawn_native::vulkan
66 
67 #endif  // DAWNNATIVE_VULKAN_SHADERMODULEVK_H_
68