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 #include "dawn_native/opengl/PipelineLayoutGL.h"
16 
17 #include "common/BitSetIterator.h"
18 #include "dawn_native/BindGroupLayout.h"
19 #include "dawn_native/opengl/DeviceGL.h"
20 
21 namespace dawn_native { namespace opengl {
22 
PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor)23     PipelineLayout::PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor)
24         : PipelineLayoutBase(device, descriptor) {
25         GLuint uboIndex = 0;
26         GLuint samplerIndex = 0;
27         GLuint sampledTextureIndex = 0;
28         GLuint ssboIndex = 0;
29         GLuint storageTextureIndex = 0;
30 
31         for (BindGroupIndex group : IterateBitSet(GetBindGroupLayoutsMask())) {
32             const BindGroupLayoutBase* bgl = GetBindGroupLayout(group);
33             mIndexInfo[group].resize(bgl->GetBindingCount());
34 
35             for (BindingIndex bindingIndex{0}; bindingIndex < bgl->GetBindingCount();
36                  ++bindingIndex) {
37                 const BindingInfo& bindingInfo = bgl->GetBindingInfo(bindingIndex);
38                 switch (bindingInfo.bindingType) {
39                     case BindingInfoType::Buffer:
40                         switch (bindingInfo.buffer.type) {
41                             case wgpu::BufferBindingType::Uniform:
42                                 mIndexInfo[group][bindingIndex] = uboIndex;
43                                 uboIndex++;
44                                 break;
45                             case wgpu::BufferBindingType::Storage:
46                             case kInternalStorageBufferBinding:
47                             case wgpu::BufferBindingType::ReadOnlyStorage:
48                                 mIndexInfo[group][bindingIndex] = ssboIndex;
49                                 ssboIndex++;
50                                 break;
51                             case wgpu::BufferBindingType::Undefined:
52                                 UNREACHABLE();
53                         }
54                         break;
55 
56                     case BindingInfoType::Sampler:
57                         mIndexInfo[group][bindingIndex] = samplerIndex;
58                         samplerIndex++;
59                         break;
60 
61                     case BindingInfoType::Texture:
62                     case BindingInfoType::ExternalTexture:
63                         mIndexInfo[group][bindingIndex] = sampledTextureIndex;
64                         sampledTextureIndex++;
65                         break;
66 
67                     case BindingInfoType::StorageTexture:
68                         mIndexInfo[group][bindingIndex] = storageTextureIndex;
69                         storageTextureIndex++;
70                         break;
71                 }
72             }
73         }
74 
75         mNumSamplers = samplerIndex;
76         mNumSampledTextures = sampledTextureIndex;
77     }
78 
GetBindingIndexInfo() const79     const PipelineLayout::BindingIndexInfo& PipelineLayout::GetBindingIndexInfo() const {
80         return mIndexInfo;
81     }
82 
GetTextureUnitsUsed() const83     GLuint PipelineLayout::GetTextureUnitsUsed() const {
84         return 0;
85     }
86 
GetNumSamplers() const87     size_t PipelineLayout::GetNumSamplers() const {
88         return mNumSamplers;
89     }
90 
GetNumSampledTextures() const91     size_t PipelineLayout::GetNumSampledTextures() const {
92         return mNumSampledTextures;
93     }
94 
95 }}  // namespace dawn_native::opengl
96