Austin Eng | 463c394 | 2020-03-13 23:51:50 +0000 | [diff] [blame] | 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 | |
Jiawei Shao | 0e5301c | 2020-05-29 07:51:08 +0000 | [diff] [blame] | 17 | #include "dawn_native/Texture.h" |
Austin Eng | 463c394 | 2020-03-13 23:51:50 +0000 | [diff] [blame] | 18 | #include "dawn_native/opengl/BindGroupLayoutGL.h" |
| 19 | #include "dawn_native/opengl/DeviceGL.h" |
| 20 | |
| 21 | namespace dawn_native { namespace opengl { |
| 22 | |
Jiawei Shao | 0e5301c | 2020-05-29 07:51:08 +0000 | [diff] [blame] | 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); |
Brandon Jones | 3af532b | 2020-12-21 20:14:26 +0000 | [diff] [blame] | 33 | if (bindingInfo.bindingType == BindingInfoType::StorageTexture) { |
| 34 | ASSERT(entry.textureView != nullptr); |
| 35 | const uint32_t textureViewLayerCount = entry.textureView->GetLayerCount(); |
Brandon Jones | fc5cae6 | 2021-10-21 16:37:45 +0000 | [diff] [blame] | 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()); |
Jiawei Shao | 0e5301c | 2020-05-29 07:51:08 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | return {}; |
| 47 | } |
| 48 | |
Austin Eng | 463c394 | 2020-03-13 23:51:50 +0000 | [diff] [blame] | 49 | BindGroup::BindGroup(Device* device, const BindGroupDescriptor* descriptor) |
| 50 | : BindGroupBase(this, device, descriptor) { |
| 51 | } |
| 52 | |
Loko Kung | 2c67af9 | 2021-11-11 00:39:22 +0000 | [diff] [blame] | 53 | BindGroup::~BindGroup() = default; |
| 54 | |
Loko Kung | e9c84c0 | 2021-11-11 01:39:52 +0000 | [diff] [blame] | 55 | void BindGroup::DestroyImpl() { |
Austin Eng | 463c394 | 2020-03-13 23:51:50 +0000 | [diff] [blame] | 56 | ToBackend(GetLayout())->DeallocateBindGroup(this); |
| 57 | } |
| 58 | |
| 59 | // static |
Corentin Wallez | 50f9958 | 2021-03-31 18:36:32 +0000 | [diff] [blame] | 60 | Ref<BindGroup> BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) { |
Austin Eng | 463c394 | 2020-03-13 23:51:50 +0000 | [diff] [blame] | 61 | return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor); |
| 62 | } |
| 63 | |
| 64 | }} // namespace dawn_native::opengl |