mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-04 19:25:47 +00:00
To make B2B, B2T and T2B testes work, this CL implements several missed functions: - Texture::Clear() is need for initializing texture data - Texture::Read() is need for readback data from 2d and 3d textures Bug: dawn:1740,dawn:1768 Change-Id: Ib9e354c82fcdc8cc4e86b1699fa652cfc4a50721 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128621 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Peng Huang <penghuang@chromium.org>
128 lines
4.9 KiB
C++
128 lines
4.9 KiB
C++
// Copyright 2023 The Dawn Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef SRC_DAWN_NATIVE_D3D11_TEXTURED3D11_H_
|
|
#define SRC_DAWN_NATIVE_D3D11_TEXTURED3D11_H_
|
|
|
|
#include "dawn/native/DawnNative.h"
|
|
#include "dawn/native/Error.h"
|
|
#include "dawn/native/IntegerTypes.h"
|
|
#include "dawn/native/PassResourceUsage.h"
|
|
#include "dawn/native/Texture.h"
|
|
#include "dawn/native/d3d/d3d_platform.h"
|
|
|
|
namespace dawn::native {
|
|
struct CopyTextureToTextureCmd;
|
|
} // namespace dawn::native
|
|
|
|
namespace dawn::native::d3d11 {
|
|
|
|
class CommandRecordingContext;
|
|
class Device;
|
|
|
|
class Texture final : public TextureBase {
|
|
public:
|
|
static ResultOrError<Ref<Texture>> Create(Device* device, const TextureDescriptor* descriptor);
|
|
static ResultOrError<Ref<Texture>> Create(Device* device,
|
|
const TextureDescriptor* descriptor,
|
|
ComPtr<ID3D11Resource> d3d11Texture);
|
|
|
|
DXGI_FORMAT GetD3D11Format() const;
|
|
ID3D11Resource* GetD3D11Resource() const;
|
|
|
|
D3D11_RENDER_TARGET_VIEW_DESC GetRTVDescriptor(const Format& format,
|
|
const SubresourceRange& range) const;
|
|
D3D11_DEPTH_STENCIL_VIEW_DESC GetDSVDescriptor(const SubresourceRange& range,
|
|
bool depthReadOnly,
|
|
bool stencilReadOnly) const;
|
|
|
|
MaybeError EnsureSubresourceContentInitialized(CommandRecordingContext* commandContext,
|
|
const SubresourceRange& range);
|
|
|
|
MaybeError Write(CommandRecordingContext* commandContext,
|
|
const SubresourceRange& subresources,
|
|
const Origin3D& origin,
|
|
const Extent3D& size,
|
|
const uint8_t* data,
|
|
uint32_t bytesPerRow,
|
|
uint32_t rowsPerImage);
|
|
using ReadCallback = std::function<MaybeError(const uint8_t* data, size_t offset, size_t size)>;
|
|
MaybeError Read(CommandRecordingContext* commandContext,
|
|
const SubresourceRange& subresources,
|
|
const Origin3D& origin,
|
|
Extent3D size,
|
|
uint32_t bytesPerRow,
|
|
uint32_t rowsPerImage,
|
|
ReadCallback callback);
|
|
static MaybeError Copy(CommandRecordingContext* commandContext, CopyTextureToTextureCmd* copy);
|
|
|
|
private:
|
|
static ResultOrError<Ref<Texture>> CreateStaging(Device* device,
|
|
const TextureDescriptor* descriptor);
|
|
|
|
Texture(Device* device,
|
|
const TextureDescriptor* descriptor,
|
|
TextureState state,
|
|
bool isStaging);
|
|
~Texture() override;
|
|
|
|
template <typename T>
|
|
T GetD3D11TextureDesc() const;
|
|
|
|
MaybeError InitializeAsInternalTexture();
|
|
MaybeError InitializeAsSwapChainTexture(ComPtr<ID3D11Resource> d3d11Texture);
|
|
|
|
void SetLabelHelper(const char* prefix);
|
|
|
|
// Dawn API
|
|
void SetLabelImpl() override;
|
|
void DestroyImpl() override;
|
|
|
|
MaybeError Clear(CommandRecordingContext* commandContext,
|
|
const SubresourceRange& range,
|
|
TextureBase::ClearValue clearValue);
|
|
MaybeError ReadStaging(CommandRecordingContext* commandContext,
|
|
const SubresourceRange& subresources,
|
|
const Origin3D& origin,
|
|
Extent3D size,
|
|
uint32_t bytesPerRow,
|
|
uint32_t rowsPerImage,
|
|
ReadCallback callback);
|
|
|
|
const bool mIsStaging = false;
|
|
ComPtr<ID3D11Resource> mD3d11Resource;
|
|
};
|
|
|
|
class TextureView final : public TextureViewBase {
|
|
public:
|
|
static Ref<TextureView> Create(TextureBase* texture, const TextureViewDescriptor* descriptor);
|
|
|
|
DXGI_FORMAT GetD3D11Format() const;
|
|
ResultOrError<ComPtr<ID3D11ShaderResourceView>> CreateD3D11ShaderResourceView() const;
|
|
ResultOrError<ComPtr<ID3D11RenderTargetView>> CreateD3D11RenderTargetView() const;
|
|
ResultOrError<ComPtr<ID3D11DepthStencilView>> CreateD3D11DepthStencilView(
|
|
bool depthReadOnly,
|
|
bool stencilReadOnly) const;
|
|
ResultOrError<ComPtr<ID3D11UnorderedAccessView>> CreateD3D11UnorderedAccessView() const;
|
|
|
|
private:
|
|
using TextureViewBase::TextureViewBase;
|
|
|
|
~TextureView() override;
|
|
};
|
|
|
|
} // namespace dawn::native::d3d11
|
|
|
|
#endif // SRC_DAWN_NATIVE_D3D11_TEXTURED3D11_H_
|