Add GrD3DBuffer.

Supports buffer creation and destruction.

Bug: skia:9935
Change-Id: I6d8c6d67209a8857989a9384818272e7108177ad
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281577
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Jim Van Verth 2020-04-03 14:59:20 -04:00
parent cc8a76f3c7
commit d6ad48086d
7 changed files with 3643 additions and 3 deletions

View File

@ -724,6 +724,8 @@ skia_direct3d_sources = [
"$_include/gpu/d3d/GrD3DTypes.h", "$_include/gpu/d3d/GrD3DTypes.h",
"$_include/gpu/d3d/GrD3DTypesMinimal.h", "$_include/gpu/d3d/GrD3DTypesMinimal.h",
"$_include/private/GrD3DTypesPriv.h", "$_include/private/GrD3DTypesPriv.h",
"$_src/gpu/d3d/GrD3DBuffer.cpp",
"$_src/gpu/d3d/GrD3DBuffer.h",
"$_src/gpu/d3d/GrD3DCaps.cpp", "$_src/gpu/d3d/GrD3DCaps.cpp",
"$_src/gpu/d3d/GrD3DCaps.h", "$_src/gpu/d3d/GrD3DCaps.h",
"$_src/gpu/d3d/GrD3DCommandList.cpp", "$_src/gpu/d3d/GrD3DCommandList.cpp",

3440
include/third_party/d3d/d3dx12.h vendored Normal file

File diff suppressed because it is too large Load Diff

8
include/third_party/d3d/readme.md vendored Normal file
View File

@ -0,0 +1,8 @@
# The D3D12 Helper Library
This library provides helper functions and structs to make certain common operations less verbose in your code.
Documentation of the helper functions and structures can he found on [MSDN](https://msdn.microsoft.com/en-us/library/windows/desktop/dn708058(v=vs.85).aspx)
Note that Windows 10 October 2018 Update and Visual Studio 2017 are required for the latest version of D3D12 Helper Library. Visual Studio 2015 compatible version can be found from https://github.com/Microsoft/DirectX-Graphics-Samples/releases/tag/v10.0.14393.4.

View File

@ -0,0 +1,96 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/d3d/GrD3DBuffer.h"
#include "src/gpu/d3d/GrD3DGpu.h"
#include "src/gpu/d3d/GrD3DUtil.h"
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-type-limit-compare"
#endif
#include "include/third_party/d3d/d3dx12.h"
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
sk_sp<GrD3DBuffer::Resource> GrD3DBuffer::Resource::Make(GrD3DGpu* gpu, size_t size,
GrGpuBufferType intendedType,
GrAccessPattern accessPattern,
D3D12_RESOURCE_STATES* resourceState) {
D3D12_HEAP_TYPE heapType;
if (accessPattern == kStatic_GrAccessPattern) {
SkASSERT(intendedType != GrGpuBufferType::kXferCpuToGpu &&
intendedType != GrGpuBufferType::kXferGpuToCpu);
heapType = D3D12_HEAP_TYPE_DEFAULT;
// Can be transitioned to different states
*resourceState = D3D12_RESOURCE_STATE_COMMON;
} else {
if (intendedType == GrGpuBufferType::kXferGpuToCpu) {
heapType = D3D12_HEAP_TYPE_READBACK;
// Cannot be changed
*resourceState = D3D12_RESOURCE_STATE_COPY_DEST;
} else {
heapType = D3D12_HEAP_TYPE_UPLOAD;
// Cannot be changed
// Includes VERTEX_AND_CONSTANT_BUFFER, INDEX_BUFFER, and COPY_SOURCE
*resourceState = D3D12_RESOURCE_STATE_GENERIC_READ;
}
}
ID3D12Resource* resource;
CD3DX12_HEAP_PROPERTIES heapProperties(heapType);
CD3DX12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(size);
HRESULT hr = gpu->device()->CreateCommittedResource(
&heapProperties,
D3D12_HEAP_FLAG_NONE,
&bufferDesc,
*resourceState,
nullptr,
IID_PPV_ARGS(&resource));
if (!SUCCEEDED(hr)) {
return nullptr;
}
return sk_sp<Resource>(new GrD3DBuffer::Resource(std::move(gr_cp<ID3D12Resource>(resource))));
}
sk_sp<GrD3DBuffer> GrD3DBuffer::Make(GrD3DGpu* gpu, size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern) {
SkASSERT(!gpu->protectedContext() || (accessPattern != kStatic_GrAccessPattern));
D3D12_RESOURCE_STATES resourceState;
sk_sp<Resource> resource = Resource::Make(gpu, size, intendedType, accessPattern,
&resourceState);
if (!resource) {
return nullptr;
}
return sk_sp<GrD3DBuffer>(new GrD3DBuffer(gpu, size, intendedType, accessPattern,
std::move(resource), resourceState));
}
GrD3DBuffer::GrD3DBuffer(GrD3DGpu* gpu, size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, const sk_sp<Resource>& bufferResource,
D3D12_RESOURCE_STATES resourceState)
: INHERITED(gpu, size, intendedType, accessPattern)
, fResourceState(resourceState)
, fResource(bufferResource) {
}
void GrD3DBuffer::onRelease() {
if (!this->wasDestroyed()) {
fResource.reset();
}
INHERITED::onRelease();
}
void GrD3DBuffer::onAbandon() {
if (!this->wasDestroyed()) {
fResource.reset();
}
INHERITED::onAbandon();
}

87
src/gpu/d3d/GrD3DBuffer.h Normal file
View File

@ -0,0 +1,87 @@
/*
* 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 GrD3DBuffer_DEFINED
#define GrD3DBuffer_DEFINED
#include "include/gpu/d3d/GrD3DTypes.h"
#include "src/gpu/GrGpuBuffer.h"
#include "src/gpu/GrManagedResource.h"
class GrD3DGpu;
class GrD3DBuffer : public GrGpuBuffer {
private:
class Resource;
public:
static sk_sp<GrD3DBuffer> Make(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern);
~GrD3DBuffer() override {
// release should have been called by the owner of this object.
SkASSERT(!fResource);
}
ID3D12Resource* d3dResource() const {
SkASSERT(fResource);
return fResource->fD3DResource.get();
}
const Resource* resource() const {
SkASSERT(fResource);
return fResource.get();
}
protected:
GrD3DBuffer(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern, const sk_sp<Resource>&,
D3D12_RESOURCE_STATES);
void onAbandon() override;
void onRelease() override;
D3D12_RESOURCE_STATES fResourceState;
private:
void onMap() override {} // TODO
void onUnmap() override {} // TODO
bool onUpdateData(const void* src, size_t srcSizeInBytes) override { return false; } // TODO
class Resource : public GrRecycledResource {
public:
explicit Resource()
: fD3DResource(nullptr) {
}
Resource(const gr_cp<ID3D12Resource>& bufferResource)
: fD3DResource(bufferResource) {
}
static sk_sp<Resource> Make(GrD3DGpu*, size_t size, GrGpuBufferType, GrAccessPattern,
D3D12_RESOURCE_STATES*);
#ifdef SK_TRACE_MANAGED_RESOURCES
void dumpInfo() const override {
SkDebugf("GrD3DBuffer: %d (%d refs)\n", fD3DResource.get(), this->getRefCnt());
}
#endif
mutable gr_cp<ID3D12Resource> fD3DResource;
private:
void freeGPUData() const override {
fD3DResource.reset();
}
void onRecycle() const override { this->unref(); } // TODO
typedef GrRecycledResource INHERITED;
};
sk_sp<Resource> fResource;
typedef GrGpuBuffer INHERITED;
};
#endif

View File

@ -8,6 +8,7 @@
#include "src/gpu/d3d/GrD3DGpu.h" #include "src/gpu/d3d/GrD3DGpu.h"
#include "include/gpu/d3d/GrD3DBackendContext.h" #include "include/gpu/d3d/GrD3DBackendContext.h"
#include "src/gpu/d3d/GrD3DBuffer.h"
#include "src/gpu/d3d/GrD3DCaps.h" #include "src/gpu/d3d/GrD3DCaps.h"
#include "src/gpu/d3d/GrD3DOpsRenderPass.h" #include "src/gpu/d3d/GrD3DOpsRenderPass.h"
#include "src/gpu/d3d/GrD3DTexture.h" #include "src/gpu/d3d/GrD3DTexture.h"
@ -404,9 +405,13 @@ sk_sp<GrRenderTarget> GrD3DGpu::onWrapBackendTextureAsRenderTarget(const GrBacke
} }
sk_sp<GrGpuBuffer> GrD3DGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type, sk_sp<GrGpuBuffer> GrD3DGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type,
GrAccessPattern accessPattern, const void*) { GrAccessPattern accessPattern, const void* data) {
// TODO sk_sp<GrD3DBuffer> buffer = GrD3DBuffer::Make(this, sizeInBytes, type, accessPattern);
return nullptr; if (data && buffer) {
buffer->updateData(data, sizeInBytes);
}
return std::move(buffer);
} }
GrStencilAttachment* GrD3DGpu::createStencilAttachmentForRenderTarget( GrStencilAttachment* GrD3DGpu::createStencilAttachmentForRenderTarget(

View File

@ -33,6 +33,8 @@ public:
ID3D12Device* device() const { return fDevice.get(); } ID3D12Device* device() const { return fDevice.get(); }
ID3D12CommandQueue* queue() const { return fQueue.get(); } ID3D12CommandQueue* queue() const { return fQueue.get(); }
bool protectedContext() const { return false; }
void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override; void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override;
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}