[dawn] Add unimplemented `TexelBufferView` object

* Added `TexelBufferViewDescriptor`

Bug: 382544164
Change-Id: I63c6a064944789fc752f9784ca259a4c368f308b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/253816
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: Diego Rodrigues <diejorarr@gmail.com>
diff --git a/src/dawn/dawn.json b/src/dawn/dawn.json
index 6f4318b..32cf2f9 100644
--- a/src/dawn/dawn.json
+++ b/src/dawn/dawn.json
@@ -4228,6 +4228,17 @@
             {"name": "usage", "type": "texture usage"}
         ]
     },
+    "texel buffer view descriptor": {
+        "category": "structure",
+        "tags": ["dawn"],
+        "extensible": "in",
+        "members": [
+            {"name": "label", "type": "string view", "optional": true},
+            {"name": "format", "type": "texture format"},
+            {"name": "offset", "type": "uint64_t", "default": "0"},
+            {"name": "size", "type": "uint64_t", "default": "whole size"}
+        ]
+    },
     "texture component swizzle descriptor": {
         "category": "structure",
         "tags": ["dawn"],
@@ -4248,6 +4259,18 @@
             }
         ]
     },
+    "texel buffer view": {
+        "category": "object",
+        "tags": ["dawn"],
+        "methods": [
+            {
+                "name": "set label",
+                "args": [
+                    {"name": "label", "type": "string view"}
+                ]
+            }
+        ]
+    },
     "texture view dimension": {
         "category": "enum",
         "values": [
diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn
index cdc3768..c7b0670 100644
--- a/src/dawn/native/BUILD.gn
+++ b/src/dawn/native/BUILD.gn
@@ -393,6 +393,8 @@
     "SystemEvent.h",
     "SystemHandle.cpp",
     "SystemHandle.h",
+    "TexelBufferView.cpp",
+    "TexelBufferView.h",
     "Texture.cpp",
     "Texture.h",
     "TintUtils.cpp",
diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp
index d80acfb..c66a0a9 100644
--- a/src/dawn/native/Buffer.cpp
+++ b/src/dawn/native/Buffer.cpp
@@ -406,6 +406,8 @@
             break;
     }
     mState.store(BufferState::Destroyed, std::memory_order::release);
+
+    mTexelBufferViews.Destroy();
 }
 
 // static
@@ -928,4 +930,8 @@
     dump->AddString(name.c_str(), "usage", absl::StrFormat("%s", GetInternalUsage()));
 }
 
+ApiObjectList* BufferBase::GetTexelBufferViewTrackingList() {
+    return &mTexelBufferViews;
+}
+
 }  // namespace dawn::native
diff --git a/src/dawn/native/Buffer.h b/src/dawn/native/Buffer.h
index ac09b4f..66e397d 100644
--- a/src/dawn/native/Buffer.h
+++ b/src/dawn/native/Buffer.h
@@ -142,6 +142,8 @@
     wgpu::BufferMapState APIGetMapState() const;
     uint64_t APIGetSize() const;
 
+    ApiObjectList* GetTexelBufferViewTrackingList();
+
   protected:
     BufferBase(DeviceBase* device, const UnpackedPtr<BufferDescriptor>& descriptor);
     BufferBase(DeviceBase* device, const BufferDescriptor* descriptor, ObjectBase::ErrorTag tag);
@@ -209,6 +211,10 @@
     // staging buffer recursively.
     Ref<BufferBase> mStagingBuffer = nullptr;
 
+    // Track texel buffer views created from this buffer so they can be destroyed
+    // when the buffer is destroyed.
+    ApiObjectList mTexelBufferViews;
+
     // Mapping specific states.
     wgpu::MapMode mMapMode = wgpu::MapMode::None;
     size_t mMapOffset = 0;
diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt
index 53573e8..35deada 100644
--- a/src/dawn/native/CMakeLists.txt
+++ b/src/dawn/native/CMakeLists.txt
@@ -149,6 +149,7 @@
     "SystemEvent.h"
     "SystemHandle.h"
     "Texture.h"
+    "TexelBufferView.h"
     "TintUtils.h"
     "ToBackend.h"
     "Toggles.h"
@@ -256,6 +257,7 @@
     "SystemEvent.cpp"
     "SystemHandle.cpp"
     "Texture.cpp"
+    "TexelBufferView.cpp"
     "TintUtils.cpp"
     "Toggles.cpp"
     "utils/WGPUHelpers.cpp"
diff --git a/src/dawn/native/Forward.h b/src/dawn/native/Forward.h
index 74d2fe2..54b0e78 100644
--- a/src/dawn/native/Forward.h
+++ b/src/dawn/native/Forward.h
@@ -70,6 +70,7 @@
 class SwapChainBase;
 class TextureBase;
 class TextureViewBase;
+class TexelBufferViewBase;
 
 class DeviceBase;
 
diff --git a/src/dawn/native/TexelBufferView.cpp b/src/dawn/native/TexelBufferView.cpp
new file mode 100644
index 0000000..1b5771f
--- /dev/null
+++ b/src/dawn/native/TexelBufferView.cpp
@@ -0,0 +1,90 @@
+// Copyright 2025 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+//    contributors may be used to endorse or promote products derived from
+//    this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "dawn/native/TexelBufferView.h"
+#include "dawn/native/Buffer.h"
+#include "dawn/native/ChainUtils.h"
+#include "dawn/native/Device.h"
+#include "dawn/native/ObjectType_autogen.h"
+
+namespace dawn::native {
+
+TexelBufferViewBase::TexelBufferViewBase(BufferBase* buffer,
+                                         const UnpackedPtr<TexelBufferViewDescriptor>& desc)
+    : ApiObjectBase(buffer->GetDevice(), desc->label),
+      mBuffer(buffer),
+      mFormat(desc->format),
+      mOffset(desc->offset),
+      mSize(desc->size) {
+    GetObjectTrackingList()->Track(this);
+}
+
+TexelBufferViewBase::TexelBufferViewBase(DeviceBase* device,
+                                         ObjectBase::ErrorTag tag,
+                                         StringView label)
+    : ApiObjectBase(device, tag, label) {}
+
+TexelBufferViewBase::~TexelBufferViewBase() = default;
+
+Ref<TexelBufferViewBase> TexelBufferViewBase::MakeError(DeviceBase* device, StringView label) {
+    return AcquireRef(new TexelBufferViewBase(device, ObjectBase::kError, label));
+}
+
+ObjectType TexelBufferViewBase::GetType() const {
+    return ObjectType::TexelBufferView;
+}
+
+BufferBase* TexelBufferViewBase::GetBuffer() const {
+    DAWN_ASSERT(!IsError());
+    return mBuffer.Get();
+}
+
+wgpu::TextureFormat TexelBufferViewBase::GetFormat() const {
+    DAWN_ASSERT(!IsError());
+    return mFormat;
+}
+
+uint64_t TexelBufferViewBase::GetOffset() const {
+    DAWN_ASSERT(!IsError());
+    return mOffset;
+}
+
+uint64_t TexelBufferViewBase::GetSize() const {
+    DAWN_ASSERT(!IsError());
+    return mSize;
+}
+
+void TexelBufferViewBase::DestroyImpl() {}
+
+ApiObjectList* TexelBufferViewBase::GetObjectTrackingList() {
+    if (mBuffer != nullptr) {
+        return mBuffer->GetTexelBufferViewTrackingList();
+    }
+    return ApiObjectBase::GetObjectTrackingList();
+}
+
+}  // namespace dawn::native
diff --git a/src/dawn/native/TexelBufferView.h b/src/dawn/native/TexelBufferView.h
new file mode 100644
index 0000000..872c183
--- /dev/null
+++ b/src/dawn/native/TexelBufferView.h
@@ -0,0 +1,67 @@
+// Copyright 2025 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+//    contributors may be used to endorse or promote products derived from
+//    this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef SRC_DAWN_NATIVE_TEXELBUFFERVIEW_H_
+#define SRC_DAWN_NATIVE_TEXELBUFFERVIEW_H_
+
+#include "dawn/native/Forward.h"
+#include "dawn/native/ObjectBase.h"
+#include "dawn/native/dawn_platform.h"
+
+namespace dawn::native {
+
+class TexelBufferViewBase : public ApiObjectBase {
+  public:
+    TexelBufferViewBase(BufferBase* buffer,
+                        const UnpackedPtr<TexelBufferViewDescriptor>& descriptor);
+    TexelBufferViewBase(DeviceBase* device, ObjectBase::ErrorTag tag, StringView label);
+    ~TexelBufferViewBase() override;
+
+    static Ref<TexelBufferViewBase> MakeError(DeviceBase* device, StringView label = {});
+
+    ObjectType GetType() const override;
+
+    BufferBase* GetBuffer() const;
+    wgpu::TextureFormat GetFormat() const;
+    uint64_t GetOffset() const;
+    uint64_t GetSize() const;
+
+  protected:
+    void DestroyImpl() override;
+
+  private:
+    ApiObjectList* GetObjectTrackingList() override;
+
+    Ref<BufferBase> mBuffer;
+    wgpu::TextureFormat mFormat = wgpu::TextureFormat::Undefined;
+    uint64_t mOffset = 0;
+    uint64_t mSize = 0;
+};
+
+}  // namespace dawn::native
+
+#endif  // SRC_DAWN_NATIVE_TEXELBUFFERVIEW_H_