1 // Copyright 2020 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/BindGroupGL.h" 16 17 #include "dawn_native/Texture.h" 18 #include "dawn_native/opengl/BindGroupLayoutGL.h" 19 #include "dawn_native/opengl/DeviceGL.h" 20 21 namespace dawn_native { namespace opengl { 22 ValidateGLBindGroupDescriptor(const BindGroupDescriptor * descriptor)23 MaybeError ValidateGLBindGroupDescriptor(const BindGroupDescriptor* descriptor) { 24 const BindGroupLayoutBase::BindingMap& bindingMap = descriptor->layout->GetBindingMap(); 25 for (uint32_t i = 0; i < descriptor->entryCount; ++i) { 26 const BindGroupEntry& entry = descriptor->entries[i]; 27 28 const auto& it = bindingMap.find(BindingNumber(entry.binding)); 29 BindingIndex bindingIndex = it->second; 30 ASSERT(bindingIndex < descriptor->layout->GetBindingCount()); 31 32 const BindingInfo& bindingInfo = descriptor->layout->GetBindingInfo(bindingIndex); 33 if (bindingInfo.bindingType == BindingInfoType::StorageTexture) { 34 ASSERT(entry.textureView != nullptr); 35 const uint32_t textureViewLayerCount = entry.textureView->GetLayerCount(); 36 DAWN_INVALID_IF( 37 textureViewLayerCount != 1 && 38 textureViewLayerCount != entry.textureView->GetTexture()->GetArrayLayers(), 39 "%s binds %u layers. Currently the OpenGL backend only supports either binding " 40 "1 layer or the all layers (%u) for storage texture.", 41 entry.textureView, textureViewLayerCount, 42 entry.textureView->GetTexture()->GetArrayLayers()); 43 } 44 } 45 46 return {}; 47 } 48 BindGroup(Device * device,const BindGroupDescriptor * descriptor)49 BindGroup::BindGroup(Device* device, const BindGroupDescriptor* descriptor) 50 : BindGroupBase(this, device, descriptor) { 51 } 52 53 BindGroup::~BindGroup() = default; 54 DestroyImpl()55 void BindGroup::DestroyImpl() { 56 BindGroupBase::DestroyImpl(); 57 ToBackend(GetLayout())->DeallocateBindGroup(this); 58 } 59 60 // static Create(Device * device,const BindGroupDescriptor * descriptor)61 Ref<BindGroup> BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) { 62 return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor); 63 } 64 65 }} // namespace dawn_native::opengl 66