chromium/third_party/dawn/src/dawn/native/Texture.cpp

// Copyright 2017 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/Texture.h"

#include <algorithm>
#include <utility>

#include "absl/strings/str_format.h"
#include "dawn/common/Assert.h"
#include "dawn/common/Constants.h"
#include "dawn/common/Math.h"
#include "dawn/native/Adapter.h"
#include "dawn/native/BlitTextureToBuffer.h"
#include "dawn/native/ChainUtils.h"
#include "dawn/native/CommandValidation.h"
#include "dawn/native/Device.h"
#include "dawn/native/EnumMaskIterator.h"
#include "dawn/native/ObjectType_autogen.h"
#include "dawn/native/PassResourceUsage.h"
#include "dawn/native/PhysicalDevice.h"
#include "dawn/native/SharedTextureMemory.h"
#include "dawn/native/ValidationUtils_autogen.h"

namespace dawn::native {

namespace {

MaybeError ValidateTextureViewFormatCompatibility(const DeviceBase* device,
                                                  const Format& format,
                                                  wgpu::TextureFormat viewFormatEnum) {}

MaybeError ValidateCanViewTextureAs(const DeviceBase* device,
                                    const TextureBase* texture,
                                    const Format& viewFormat,
                                    wgpu::TextureAspect aspect) {}

bool IsTextureViewDimensionCompatibleWithTextureDimension(
    wgpu::TextureViewDimension textureViewDimension,
    wgpu::TextureDimension textureDimension) {}

MaybeError ValidateDepthOrArrayLayersIsCompatibleWithTextureBindingViewDimension(
    wgpu::TextureViewDimension textureBindingViewDimension,
    uint32_t depthOrArrayLayers) {}

bool IsArrayLayerValidForTextureViewDimension(wgpu::TextureViewDimension textureViewDimension,
                                              uint32_t textureViewArrayLayer) {}

MaybeError ValidateSampleCount(const TextureDescriptor* descriptor,
                               wgpu::TextureUsage usage,
                               const Format* format) {}

MaybeError ValidateTextureViewDimensionCompatibility(
    const DeviceBase* device,
    const TextureBase* texture,
    const UnpackedPtr<TextureViewDescriptor>& descriptor) {}

MaybeError ValidateTextureSize(const DeviceBase* device,
                               const TextureDescriptor* descriptor,
                               const Format* format) {}

MaybeError ValidateTextureUsage(const DeviceBase* device,
                                const TextureDescriptor* descriptor,
                                wgpu::TextureUsage usage,
                                const Format* format,
                                std::optional<wgpu::TextureUsage> allowedSharedTextureMemoryUsage) {}

// We need to add an internal RenderAttachment usage to some textures that has CopyDst usage as we
// apply a workaround that writes to them with a render pipeline.
bool CopyDstNeedsInternalRenderAttachmentUsage(const DeviceBase* device, const Format& format) {}

// We need to add an internal TextureBinding usage to some textures that has CopySrc usage as we
// apply a workaround that binds them to a compute pipeline for their copy operation.
bool CopySrcNeedsInternalTextureBindingUsage(const DeviceBase* device, const Format& format) {}

wgpu::TextureViewDimension ResolveDefaultCompatiblityTextureBindingViewDimension(
    const DeviceBase* device,
    const UnpackedPtr<TextureDescriptor>& descriptor) {}

}  // anonymous namespace

MaybeError ValidateTextureDescriptor(
    const DeviceBase* device,
    const UnpackedPtr<TextureDescriptor>& descriptor,
    AllowMultiPlanarTextureFormat allowMultiPlanar,
    std::optional<wgpu::TextureUsage> allowedSharedTextureMemoryUsage) {}

MaybeError ValidateTextureViewDescriptor(const DeviceBase* device,
                                         const TextureBase* texture,
                                         const UnpackedPtr<TextureViewDescriptor>& descriptor) {}

ResultOrError<TextureViewDescriptor> GetTextureViewDescriptorWithDefaults(
    const TextureBase* texture,
    const TextureViewDescriptor* descriptor) {}

// WebGPU only supports sample counts of 1 and 4. We could expand to more based on
// platform support, but it would probably be a feature.
bool IsValidSampleCount(uint32_t sampleCount) {}

// TextureBase

TextureBase::TextureState::TextureState() :{}

TextureBase::TextureBase(DeviceBase* device, const UnpackedPtr<TextureDescriptor>& descriptor)
    :{}

TextureBase::~TextureBase() = default;

static constexpr Format kUnusedFormat;

TextureBase::TextureBase(DeviceBase* device,
                         const TextureDescriptor* descriptor,
                         ObjectBase::ErrorTag tag)
    :{}

void TextureBase::DestroyImpl() {}

// static
Ref<TextureBase> TextureBase::MakeError(DeviceBase* device, const TextureDescriptor* descriptor) {}

ObjectType TextureBase::GetType() const {}

void TextureBase::FormatLabel(absl::FormatSink* s) const {}

std::string TextureBase::GetSizeLabel() const {}

wgpu::TextureDimension TextureBase::GetDimension() const {}

wgpu::TextureViewDimension TextureBase::GetCompatibilityTextureBindingViewDimension() const {}

const Format& TextureBase::GetFormat() const {}
const FormatSet& TextureBase::GetViewFormats() const {}

const Extent3D& TextureBase::GetBaseSize() const {}

Extent3D TextureBase::GetSize(Aspect aspect) const {}
Extent3D TextureBase::GetSize(wgpu::TextureAspect textureAspect) const {}
uint32_t TextureBase::GetWidth(Aspect aspect) const {}
uint32_t TextureBase::GetHeight(Aspect aspect) const {}
uint32_t TextureBase::GetDepth(Aspect aspect) const {}
uint32_t TextureBase::GetArrayLayers() const {}
uint32_t TextureBase::GetNumMipLevels() const {}
SubresourceRange TextureBase::GetAllSubresources() const {}
uint32_t TextureBase::GetSampleCount() const {}
uint32_t TextureBase::GetSubresourceCount() const {}
wgpu::TextureUsage TextureBase::GetUsage() const {}
wgpu::TextureUsage TextureBase::GetInternalUsage() const {}
void TextureBase::AddInternalUsage(wgpu::TextureUsage usage) {}

bool TextureBase::IsDestroyed() const {}

bool TextureBase::IsInitialized() const {}

void TextureBase::SetInitialized(bool initialized) {}

ExecutionSerial TextureBase::OnEndAccess() {}

void TextureBase::OnBeginAccess() {}

bool TextureBase::HasAccess() const {}

uint32_t TextureBase::GetSubresourceIndex(uint32_t mipLevel,
                                          uint32_t arraySlice,
                                          Aspect aspect) const {}

bool TextureBase::IsSubresourceContentInitialized(const SubresourceRange& range) const {}

void TextureBase::SetIsSubresourceContentInitialized(bool isInitialized,
                                                     const SubresourceRange& range) {}

MaybeError TextureBase::ValidateCanUseInSubmitNow() const {}

bool TextureBase::IsMultisampledTexture() const {}

bool TextureBase::IsReadOnly() const {}

bool TextureBase::CoversFullSubresource(uint32_t mipLevel,
                                        Aspect aspect,
                                        const Extent3D& size) const {}

Extent3D TextureBase::GetMipLevelSingleSubresourceVirtualSize(uint32_t level, Aspect aspect) const {}

Extent3D TextureBase::GetMipLevelSingleSubresourcePhysicalSize(uint32_t level,
                                                               Aspect aspect) const {}

Extent3D TextureBase::ClampToMipLevelVirtualSize(uint32_t level,
                                                 Aspect aspect,
                                                 const Origin3D& origin,
                                                 const Extent3D& extent) const {}

Extent3D TextureBase::GetMipLevelSubresourceVirtualSize(uint32_t level, Aspect aspect) const {}

ResultOrError<Ref<TextureViewBase>> TextureBase::CreateView(
    const TextureViewDescriptor* descriptor) {}

Ref<TextureViewBase> TextureBase::CreateErrorView(const TextureViewDescriptor* descriptor) {}

ApiObjectList* TextureBase::GetViewTrackingList() {}

TextureViewBase* TextureBase::APICreateView(const TextureViewDescriptor* descriptor) {}

TextureViewBase* TextureBase::APICreateErrorView(const TextureViewDescriptor* descriptor) {}

bool TextureBase::IsImplicitMSAARenderTextureViewSupported() const {}

void TextureBase::SetSharedResourceMemoryContentsForTesting(
    Ref<SharedResourceMemoryContents> contents) {}

void TextureBase::DumpMemoryStatistics(dawn::native::MemoryDump* dump, const char* prefix) const {}

uint64_t TextureBase::ComputeEstimatedByteSize() const {}

void TextureBase::APIDestroy() {}

uint32_t TextureBase::APIGetWidth() const {}

uint32_t TextureBase::APIGetHeight() const {}
uint32_t TextureBase::APIGetDepthOrArrayLayers() const {}

uint32_t TextureBase::APIGetMipLevelCount() const {}

uint32_t TextureBase::APIGetSampleCount() const {}

wgpu::TextureDimension TextureBase::APIGetDimension() const {}

wgpu::TextureFormat TextureBase::APIGetFormat() const {}

wgpu::TextureUsage TextureBase::APIGetUsage() const {}

// TextureViewBase

TextureViewBase::TextureViewBase(TextureBase* texture,
                                 const UnpackedPtr<TextureViewDescriptor>& descriptor)
    :{}

TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag, const char* label)
    :{}

TextureViewBase::~TextureViewBase() = default;

void TextureViewBase::DestroyImpl() {}

// static
Ref<TextureViewBase> TextureViewBase::MakeError(DeviceBase* device, const char* label) {}

ObjectType TextureViewBase::GetType() const {}

void TextureViewBase::FormatLabel(absl::FormatSink* s) const {}

const TextureBase* TextureViewBase::GetTexture() const {}

TextureBase* TextureViewBase::GetTexture() {}

Aspect TextureViewBase::GetAspects() const {}

const Format& TextureViewBase::GetFormat() const {}

wgpu::TextureViewDimension TextureViewBase::GetDimension() const {}

uint32_t TextureViewBase::GetBaseMipLevel() const {}

uint32_t TextureViewBase::GetLevelCount() const {}

uint32_t TextureViewBase::GetBaseArrayLayer() const {}

uint32_t TextureViewBase::GetLayerCount() const {}

const SubresourceRange& TextureViewBase::GetSubresourceRange() const {}

Extent3D TextureViewBase::GetSingleSubresourceVirtualSize() const {}

ApiObjectList* TextureViewBase::GetObjectTrackingList() {}

}  // namespace dawn::native