Allow GrD3DTextureResourceInfo to include declared D3D12 types.

Changes the GrD3DTextureResourceInfo member in GrD3DBackendSurfaceInfo
to be a unique_ptr<> so we can use forward refs.

This will allow us to use a shared_ptr variant to manage the
ID3D12Resource on GrD3DResourceResourceInfo, without polluting
client files with Windows definitions. Clients can use GrD3DTypes.h
to get the full declarations, GrD3DTypesMinimal.h for only the forward
references.

Bug: skia:9935
Change-Id: I075a3fc608bf6767dae202efd8cbf06cdd4a9457
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280602
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Jim Van Verth 2020-03-31 11:34:00 -04:00 committed by Skia Commit-Bot
parent 3b6a0ab182
commit 8e75147214
6 changed files with 60 additions and 20 deletions

View File

@ -732,6 +732,7 @@ skia_vk_sources = [
skia_direct3d_sources = [
"$_include/gpu/d3d/GrD3DBackendContext.h",
"$_include/gpu/d3d/GrD3DTypes.h",
"$_include/gpu/d3d/GrD3DTypesMinimal.h",
"$_include/private/GrD3DTypesPriv.h",
"$_src/gpu/d3d/GrD3D12.h",
"$_src/gpu/d3d/GrD3DCaps.cpp",

View File

@ -31,7 +31,7 @@ class GrGLTextureParameters;
#endif
#ifdef SK_DIRECT3D
#include "include/gpu/d3d/GrD3DTypes.h"
#include "include/gpu/d3d/GrD3DTypesMinimal.h"
#include "include/private/GrD3DTypesPriv.h"
class GrD3DResourceState;
#endif

View File

@ -9,33 +9,40 @@
#ifndef GrD3DTypes_DEFINED
#define GrD3DTypes_DEFINED
#include <dxgiformat.h>
// This file includes d3d12.h, which in turn includes windows.h, which redefines many
// common identifiers such as:
// * interface
// * small
// * near
// * far
// * CreateSemaphore
// * MemoryBarrier
//
// You should only include this header if you need the Direct3D definitions and are
// prepared to rename those identifiers. Otherwise use GrD3DTypesMinimal.h.
#include <functional>
#include "include/gpu/GrTypes.h"
struct ID3D12Resource;
typedef int GrD3DResourceStateEnum;
#include "include/gpu/d3d/GrD3DTypesMinimal.h"
#include <d3d12.h>
// Note: there is no notion of Borrowed or Adopted resources in the D3D backend,
// so Ganesh will ref fResource once it's asked to wrap it.
// Clients are responsible for releasing their own ref to avoid memory leaks.
struct GrD3DTextureResourceInfo {
ID3D12Resource* fResource;
GrD3DResourceStateEnum fResourceState;
D3D12_RESOURCE_STATES fResourceState;
DXGI_FORMAT fFormat;
uint32_t fLevelCount;
GrProtected fProtected;
GrD3DTextureResourceInfo()
: fResource(nullptr)
, fResourceState(0) // D3D_RESOURCE_STATES_COMMON
, fResourceState(D3D12_RESOURCE_STATE_COMMON)
, fFormat(DXGI_FORMAT_UNKNOWN)
, fLevelCount(0)
, fProtected(GrProtected::kNo) {}
GrD3DTextureResourceInfo(ID3D12Resource* resource,
GrD3DResourceStateEnum resourceState,
D3D12_RESOURCE_STATES resourceState,
DXGI_FORMAT format,
uint32_t levelCount,
GrProtected isProtected = GrProtected::kNo)
@ -48,7 +55,7 @@ struct GrD3DTextureResourceInfo {
GrD3DTextureResourceInfo(const GrD3DTextureResourceInfo& info,
GrD3DResourceStateEnum resourceState)
: fResource(info.fResource)
, fResourceState(resourceState)
, fResourceState(static_cast<D3D12_RESOURCE_STATES>(resourceState))
, fFormat(info.fFormat)
, fLevelCount(info.fLevelCount)
, fProtected(info.fProtected) {}

View File

@ -0,0 +1,23 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrD3DTypesMinimal_DEFINED
#define GrD3DTypesMinimal_DEFINED
// Minimal definitions of Direct3D types, without including d3d12.h
#include <dxgiformat.h>
#include <functional>
#include "include/gpu/GrTypes.h"
struct ID3D12Resource;
typedef int GrD3DResourceStateEnum;
struct GrD3DTextureResourceInfo;
#endif

View File

@ -9,7 +9,7 @@
#define GrD3DTypesPriv_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/gpu/d3d/GrD3DTypes.h"
#include "include/gpu/d3d/GrD3DTypesMinimal.h"
class GrD3DResourceState;
@ -20,8 +20,7 @@ class GrD3DResourceState;
// track the current D3D12_RESOURCE_STATES which can be shared with an internal GrD3DTextureResource
// so that state updates can be seen by all users of the texture.
struct GrD3DBackendSurfaceInfo {
GrD3DBackendSurfaceInfo(GrD3DTextureResourceInfo info, GrD3DResourceState* state)
: fTextureResourceInfo(info), fResourceState(state) {}
GrD3DBackendSurfaceInfo(const GrD3DTextureResourceInfo& info, GrD3DResourceState* state);
void cleanup();
@ -37,13 +36,13 @@ struct GrD3DBackendSurfaceInfo {
GrD3DTextureResourceInfo snapTextureResourceInfo() const;
bool isProtected() const { return fTextureResourceInfo.fProtected == GrProtected::kYes; }
bool isProtected() const;
#if GR_TEST_UTILS
bool operator==(const GrD3DBackendSurfaceInfo& that) const;
#endif
private:
GrD3DTextureResourceInfo fTextureResourceInfo;
std::unique_ptr<GrD3DTextureResourceInfo> fTextureResourceInfo;
GrD3DResourceState* fResourceState;
};

View File

@ -5,18 +5,24 @@
* found in the LICENSE file.
*/
#include "include/gpu/d3d/GrD3DTypes.h"
#include "include/private/GrD3DTypesPriv.h"
#include "src/gpu/d3d/GrD3D12.h"
#include "src/gpu/d3d/GrD3DResourceState.h"
GrD3DBackendSurfaceInfo::GrD3DBackendSurfaceInfo(const GrD3DTextureResourceInfo& info,
GrD3DResourceState* state)
: fTextureResourceInfo(new GrD3DTextureResourceInfo(info))
, fResourceState(state) {}
void GrD3DBackendSurfaceInfo::cleanup() {
SkSafeUnref(fResourceState);
fResourceState = nullptr;
};
void GrD3DBackendSurfaceInfo::assign(const GrD3DBackendSurfaceInfo& that, bool isThisValid) {
fTextureResourceInfo = that.fTextureResourceInfo;
fTextureResourceInfo.reset(new GrD3DTextureResourceInfo(*that.fTextureResourceInfo));
GrD3DResourceState* oldLayout = fResourceState;
fResourceState = SkSafeRef(that.fResourceState);
if (isThisValid) {
@ -35,13 +41,17 @@ sk_sp<GrD3DResourceState> GrD3DBackendSurfaceInfo::getGrD3DResourceState() const
}
GrD3DTextureResourceInfo GrD3DBackendSurfaceInfo::snapTextureResourceInfo() const {
return GrD3DTextureResourceInfo(fTextureResourceInfo, fResourceState->getResourceState());
return GrD3DTextureResourceInfo(*fTextureResourceInfo, fResourceState->getResourceState());
}
bool GrD3DBackendSurfaceInfo::isProtected() const {
return fTextureResourceInfo->fProtected == GrProtected::kYes;
}
#if GR_TEST_UTILS
bool GrD3DBackendSurfaceInfo::operator==(const GrD3DBackendSurfaceInfo& that) const {
GrD3DTextureResourceInfo cpyInfoThis = fTextureResourceInfo;
GrD3DTextureResourceInfo cpyInfoThat = that.fTextureResourceInfo;
GrD3DTextureResourceInfo cpyInfoThis = *fTextureResourceInfo;
GrD3DTextureResourceInfo cpyInfoThat = *that.fTextureResourceInfo;
// We don't care about the fResourceState here since we require they use the same
// GrD3DResourceState.
cpyInfoThis.fResourceState = D3D12_RESOURCE_STATE_COMMON;