• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_OPENGL_SHADERMODULEGL_H_
16 #define DAWNNATIVE_OPENGL_SHADERMODULEGL_H_
17 
18 #include "dawn_native/ShaderModule.h"
19 
20 #include "dawn_native/opengl/opengl_platform.h"
21 
22 namespace dawn_native { namespace opengl {
23 
24     class Device;
25     class PipelineLayout;
26 
27     std::string GetBindingName(BindGroupIndex group, BindingNumber bindingNumber);
28 
29     struct BindingLocation {
30         BindGroupIndex group;
31         BindingNumber binding;
32     };
33     bool operator<(const BindingLocation& a, const BindingLocation& b);
34 
35     struct CombinedSampler {
36         BindingLocation samplerLocation;
37         BindingLocation textureLocation;
38         // OpenGL requires a sampler with texelFetch. If this is true, the developer did not provide
39         // one and Dawn should bind a dummy non-filtering sampler. |samplerLocation| is unused.
40         bool useDummySampler;
41         std::string GetName() const;
42     };
43     bool operator<(const CombinedSampler& a, const CombinedSampler& b);
44 
45     using CombinedSamplerInfo = std::vector<CombinedSampler>;
46 
47     using BindingInfoArrayTable =
48         std::unordered_map<std::string, std::unique_ptr<BindingInfoArray>>;
49 
50     class ShaderModule final : public ShaderModuleBase {
51       public:
52         static ResultOrError<Ref<ShaderModule>> Create(Device* device,
53                                                        const ShaderModuleDescriptor* descriptor,
54                                                        ShaderModuleParseResult* parseResult);
55 
56         ResultOrError<std::string> TranslateToGLSL(const char* entryPointName,
57                                                    SingleShaderStage stage,
58                                                    CombinedSamplerInfo* combinedSamplers,
59                                                    const PipelineLayout* layout,
60                                                    bool* needsDummySampler) const;
61 
62       private:
63         ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor);
64         ~ShaderModule() override = default;
65         MaybeError Initialize(ShaderModuleParseResult* parseResult);
66         static ResultOrError<BindingInfoArrayTable> ReflectShaderUsingSPIRVCross(
67             DeviceBase* device,
68             const std::vector<uint32_t>& spirv);
69 
70         BindingInfoArrayTable mGLBindings;
71     };
72 
73 }}  // namespace dawn_native::opengl
74 
75 #endif  // DAWNNATIVE_OPENGL_SHADERMODULEGL_H_
76