blob: 70975a9875b216c3204a67614dcb7d951114bdd3 [file] [log] [blame]
Austin Eng463c3942020-03-13 23:51:50 +00001// 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 Shao0e5301c2020-05-29 07:51:08 +000017#include "dawn_native/Texture.h"
Austin Eng463c3942020-03-13 23:51:50 +000018#include "dawn_native/opengl/BindGroupLayoutGL.h"
19#include "dawn_native/opengl/DeviceGL.h"
20
21namespace dawn_native { namespace opengl {
22
Jiawei Shao0e5301c2020-05-29 07:51:08 +000023 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 Jones3af532b2020-12-21 20:14:26 +000033 if (bindingInfo.bindingType == BindingInfoType::StorageTexture) {
34 ASSERT(entry.textureView != nullptr);
35 const uint32_t textureViewLayerCount = entry.textureView->GetLayerCount();
Brandon Jonesfc5cae62021-10-21 16:37:45 +000036 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 Shao0e5301c2020-05-29 07:51:08 +000043 }
44 }
45
46 return {};
47 }
48
Austin Eng463c3942020-03-13 23:51:50 +000049 BindGroup::BindGroup(Device* device, const BindGroupDescriptor* descriptor)
50 : BindGroupBase(this, device, descriptor) {
51 }
52
Loko Kung2c67af92021-11-11 00:39:22 +000053 BindGroup::~BindGroup() = default;
54
Loko Kunge9c84c02021-11-11 01:39:52 +000055 void BindGroup::DestroyImpl() {
Austin Eng463c3942020-03-13 23:51:50 +000056 ToBackend(GetLayout())->DeallocateBindGroup(this);
57 }
58
59 // static
Corentin Wallez50f99582021-03-31 18:36:32 +000060 Ref<BindGroup> BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) {
Austin Eng463c3942020-03-13 23:51:50 +000061 return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor);
62 }
63
64}} // namespace dawn_native::opengl