Dawn: implement sk_app window contexts for all backends.
Implement Window contexts for D3D12, Metal and Vulkan, as well as a base class for all of them (DawnWindowContext). Implement WSI, swap chains and external textures for all backends. Add Dawn support to Viewer app. Change-Id: I9368eae8d43594821aa1edd9fd559c8a9ba30066 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228060 Commit-Queue: Stephen White <senorblanco@chromium.org> Reviewed-by: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
f8e5aadbd4
commit
a800ec96f7
21
BUILD.gn
21
BUILD.gn
@ -2314,6 +2314,10 @@ if (skia_enable_tools) {
|
||||
]
|
||||
libs = []
|
||||
|
||||
if (skia_use_dawn) {
|
||||
sources += [ "tools/sk_app/DawnWindowContext.cpp" ]
|
||||
}
|
||||
|
||||
if (is_android) {
|
||||
sources += [
|
||||
"tools/sk_app/android/GLWindowContext_android.cpp",
|
||||
@ -2331,6 +2335,13 @@ if (skia_enable_tools) {
|
||||
"tools/sk_app/unix/keysym2ucs.c",
|
||||
"tools/sk_app/unix/main_unix.cpp",
|
||||
]
|
||||
if (skia_use_dawn) {
|
||||
if (dawn_enable_vulkan) {
|
||||
sources += [ "tools/sk_app/unix/DawnVulkanWindowContext_unix.cpp" ]
|
||||
defines = [ "VK_USE_PLATFORM_XCB_KHR" ]
|
||||
libs += [ "X11-xcb" ]
|
||||
}
|
||||
}
|
||||
libs += [
|
||||
"GL",
|
||||
"X11",
|
||||
@ -2345,6 +2356,11 @@ if (skia_enable_tools) {
|
||||
if (skia_use_angle) {
|
||||
sources += [ "tools/sk_app/win/ANGLEWindowContext_win.cpp" ]
|
||||
}
|
||||
if (skia_use_dawn) {
|
||||
if (dawn_enable_d3d12) {
|
||||
sources += [ "tools/sk_app/win/DawnD3D12WindowContext_win.cpp" ]
|
||||
}
|
||||
}
|
||||
} else if (is_mac) {
|
||||
sources += [
|
||||
"tools/sk_app/mac/GLWindowContext_mac.mm",
|
||||
@ -2352,6 +2368,11 @@ if (skia_enable_tools) {
|
||||
"tools/sk_app/mac/Window_mac.mm",
|
||||
"tools/sk_app/mac/main_mac.mm",
|
||||
]
|
||||
if (skia_use_dawn) {
|
||||
if (dawn_enable_metal) {
|
||||
sources += [ "tools/sk_app/mac/DawnMTLWindowContext_mac.mm" ]
|
||||
}
|
||||
}
|
||||
libs += [
|
||||
"QuartzCore.framework",
|
||||
"Cocoa.framework",
|
||||
|
122
tools/sk_app/DawnWindowContext.cpp
Normal file
122
tools/sk_app/DawnWindowContext.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "include/core/SkSurface.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "src/core/SkAutoMalloc.h"
|
||||
#include "tools/sk_app/DawnWindowContext.h"
|
||||
|
||||
static void PrintDeviceError(const char* message, void*) {
|
||||
printf("Device error: %s\n", message);
|
||||
SkASSERT(false);
|
||||
}
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
DawnWindowContext::DawnWindowContext(const DisplayParams& params,
|
||||
dawn::TextureFormat swapChainFormat)
|
||||
: WindowContext(params)
|
||||
, fSwapChainFormat(swapChainFormat)
|
||||
, fInstance(std::make_unique<dawn_native::Instance>()) {
|
||||
}
|
||||
|
||||
void DawnWindowContext::initializeContext(int width, int height) {
|
||||
fWidth = width;
|
||||
fHeight = height;
|
||||
fDevice = onInitializeContext();
|
||||
fContext = GrContext::MakeDawn(fDevice, fDisplayParams.fGrContextOptions);
|
||||
|
||||
if (!fContext) {
|
||||
return;
|
||||
}
|
||||
fSwapChainImplementation = this->createSwapChainImplementation(-1, -1, fDisplayParams);
|
||||
dawn::SwapChainDescriptor swapChainDesc;
|
||||
swapChainDesc.implementation = reinterpret_cast<int64_t>(&fSwapChainImplementation);
|
||||
fSwapChain = fDevice.CreateSwapChain(&swapChainDesc);
|
||||
if (!fSwapChain) {
|
||||
fContext.reset();
|
||||
return;
|
||||
}
|
||||
fSwapChain.Configure(fSwapChainFormat, dawn::TextureUsageBit::OutputAttachment, width, height);
|
||||
fDevice.SetErrorCallback(PrintDeviceError, 0);
|
||||
}
|
||||
|
||||
DawnWindowContext::~DawnWindowContext() {
|
||||
}
|
||||
|
||||
void DawnWindowContext::destroyContext() {
|
||||
if (!fDevice.Get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->onDestroyContext();
|
||||
|
||||
fContext.reset();
|
||||
fDevice = nullptr;
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> DawnWindowContext::getBackbufferSurface() {
|
||||
GrDawnImageInfo imageInfo;
|
||||
imageInfo.fTexture = fSwapChain.GetNextTexture();
|
||||
imageInfo.fFormat = fSwapChainFormat;
|
||||
imageInfo.fLevelCount = 1; // FIXME
|
||||
GrBackendTexture backendTexture(fWidth, fHeight, imageInfo);
|
||||
fSurface = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext.get(),
|
||||
backendTexture,
|
||||
this->getRTOrigin(),
|
||||
fDisplayParams.fMSAASampleCount,
|
||||
fDisplayParams.fColorType,
|
||||
fDisplayParams.fColorSpace,
|
||||
&fDisplayParams.fSurfaceProps);
|
||||
return fSurface;
|
||||
}
|
||||
|
||||
void DawnWindowContext::swapBuffers() {
|
||||
GrBackendRenderTarget backendRT = fSurface->getBackendRenderTarget(
|
||||
SkSurface::kFlushRead_BackendHandleAccess);
|
||||
GrDawnImageInfo imageInfo;
|
||||
SkAssertResult(backendRT.getDawnImageInfo(&imageInfo));
|
||||
|
||||
fSwapChain.Present(imageInfo.fTexture);
|
||||
this->onSwapBuffers();
|
||||
}
|
||||
|
||||
void DawnWindowContext::resize(int w, int h) {
|
||||
fWidth = w;
|
||||
fHeight = h;
|
||||
fSwapChainImplementation = this->createSwapChainImplementation(w, h, fDisplayParams);
|
||||
dawn::SwapChainDescriptor swapChainDesc;
|
||||
swapChainDesc.implementation = reinterpret_cast<int64_t>(&fSwapChainImplementation);
|
||||
fSwapChain = fDevice.CreateSwapChain(&swapChainDesc);
|
||||
if (!fSwapChain) {
|
||||
fContext.reset();
|
||||
return;
|
||||
}
|
||||
fSwapChain.Configure(fSwapChainFormat, dawn::TextureUsageBit::OutputAttachment, fWidth,
|
||||
fHeight);
|
||||
}
|
||||
|
||||
void DawnWindowContext::setDisplayParams(const DisplayParams& params) {
|
||||
fDisplayParams = params;
|
||||
}
|
||||
|
||||
dawn::Device DawnWindowContext::createDevice(dawn_native::BackendType type) {
|
||||
fInstance->DiscoverDefaultAdapters();
|
||||
DawnProcTable backendProcs = dawn_native::GetProcs();
|
||||
dawnSetProcs(&backendProcs);
|
||||
|
||||
std::vector<dawn_native::Adapter> adapters = fInstance->GetAdapters();
|
||||
for (dawn_native::Adapter adapter : adapters) {
|
||||
if (adapter.GetBackendType() == type) {
|
||||
return adapter.CreateDevice();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} //namespace sk_app
|
56
tools/sk_app/DawnWindowContext.h
Normal file
56
tools/sk_app/DawnWindowContext.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
#ifndef DawnWindowContext_DEFINED
|
||||
#define DawnWindowContext_DEFINED
|
||||
|
||||
#include "include/core/SkRefCnt.h"
|
||||
#include "include/core/SkSurface.h"
|
||||
|
||||
#include "tools/sk_app/WindowContext.h"
|
||||
#include "dawn/dawncpp.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn/dawn_wsi.h"
|
||||
|
||||
class GrContext;
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class DawnWindowContext : public WindowContext {
|
||||
public:
|
||||
DawnWindowContext(const DisplayParams&, dawn::TextureFormat swapChainFormat);
|
||||
~DawnWindowContext() override;
|
||||
sk_sp<SkSurface> getBackbufferSurface() override;
|
||||
void swapBuffers() override;
|
||||
bool isValid() override { return SkToBool(fDevice.Get()); }
|
||||
|
||||
void resize(int w, int h) override;
|
||||
|
||||
void setDisplayParams(const DisplayParams& params) override;
|
||||
|
||||
protected:
|
||||
bool isGpuContext() override { return true; }
|
||||
void initializeContext(int width, int height);
|
||||
dawn::Device createDevice(dawn_native::BackendType type);
|
||||
virtual dawn::Device onInitializeContext() = 0;
|
||||
virtual void onDestroyContext() = 0;
|
||||
virtual void onSwapBuffers() = 0;
|
||||
virtual GrSurfaceOrigin getRTOrigin() const { return kTopLeft_GrSurfaceOrigin; }
|
||||
void destroyContext();
|
||||
virtual DawnSwapChainImplementation createSwapChainImplementation( int width, int height,
|
||||
const DisplayParams& params) = 0;
|
||||
|
||||
sk_sp<SkSurface> fSurface;
|
||||
DawnSwapChainImplementation fSwapChainImplementation;
|
||||
dawn::TextureFormat fSwapChainFormat;
|
||||
dawn::SwapChain fSwapChain;
|
||||
dawn::Device fDevice;
|
||||
std::unique_ptr<dawn_native::Instance> fInstance;
|
||||
};
|
||||
|
||||
} // namespace sk_app
|
||||
|
||||
#endif
|
@ -48,6 +48,9 @@ public:
|
||||
#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
|
||||
kANGLE_BackendType,
|
||||
#endif
|
||||
#ifdef SK_DAWN
|
||||
kDawn_BackendType,
|
||||
#endif
|
||||
#ifdef SK_VULKAN
|
||||
kVulkan_BackendType,
|
||||
#endif
|
||||
|
146
tools/sk_app/mac/DawnMTLWindowContext_mac.mm
Normal file
146
tools/sk_app/mac/DawnMTLWindowContext_mac.mm
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "tools/sk_app/DawnWindowContext.h"
|
||||
#include "tools/sk_app/mac/WindowContextFactory_mac.h"
|
||||
#include "common/SwapChainUtils.h"
|
||||
#include "dawn/dawncpp.h"
|
||||
#include "dawn/dawn_wsi.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_native/MetalBackend.h"
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
#import <QuartzCore/CAMetalLayer.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
using sk_app::window_context_factory::MacWindowInfo;
|
||||
|
||||
class DawnMTLWindowContext : public DawnWindowContext {
|
||||
public:
|
||||
DawnMTLWindowContext(const MacWindowInfo& info, const DisplayParams& params);
|
||||
~DawnMTLWindowContext() override;
|
||||
dawn::Device onInitializeContext() override;
|
||||
void onDestroyContext() override;
|
||||
DawnSwapChainImplementation createSwapChainImplementation(int width, int height,
|
||||
const DisplayParams& params) override;
|
||||
void onSwapBuffers() override;
|
||||
private:
|
||||
NSView* fMainView;
|
||||
id<MTLDevice> fMTLDevice;
|
||||
CAMetalLayer* fLayer;
|
||||
};
|
||||
|
||||
class SwapChainImplMTL {
|
||||
public:
|
||||
typedef void WSIContext;
|
||||
static DawnSwapChainImplementation Create(id<MTLDevice> device, CAMetalLayer* layer) {
|
||||
auto impl = new SwapChainImplMTL(device, layer);
|
||||
return CreateSwapChainImplementation<SwapChainImplMTL>(impl);
|
||||
}
|
||||
|
||||
void Init(WSIContext* ctx) {}
|
||||
|
||||
SwapChainImplMTL(id<MTLDevice> device, CAMetalLayer* layer)
|
||||
: fQueue([device newCommandQueue])
|
||||
, fLayer(layer) {}
|
||||
|
||||
~SwapChainImplMTL() {}
|
||||
|
||||
DawnSwapChainError Configure(DawnTextureFormat format, DawnTextureUsageBit,
|
||||
uint32_t width, uint32_t height) {
|
||||
if (format != DAWN_TEXTURE_FORMAT_RGBA8_UNORM) {
|
||||
return "unsupported format";
|
||||
}
|
||||
SkASSERT(width > 0);
|
||||
SkASSERT(height > 0);
|
||||
|
||||
return DAWN_SWAP_CHAIN_NO_ERROR;
|
||||
}
|
||||
|
||||
DawnSwapChainError GetNextTexture(DawnSwapChainNextTexture* nextTexture) {
|
||||
fCurrentDrawable = [fLayer nextDrawable];
|
||||
|
||||
nextTexture->texture.ptr = reinterpret_cast<void*>(fCurrentDrawable.texture);
|
||||
|
||||
return DAWN_SWAP_CHAIN_NO_ERROR;
|
||||
}
|
||||
|
||||
DawnSwapChainError Present() {
|
||||
id<MTLCommandBuffer> commandBuffer = [fQueue commandBuffer];
|
||||
[commandBuffer presentDrawable: fCurrentDrawable];
|
||||
[commandBuffer commit];
|
||||
return DAWN_SWAP_CHAIN_NO_ERROR;
|
||||
}
|
||||
private:
|
||||
id<MTLCommandQueue> fQueue;
|
||||
CAMetalLayer* fLayer;
|
||||
id<CAMetalDrawable> fCurrentDrawable = nil;
|
||||
};
|
||||
|
||||
DawnMTLWindowContext::DawnMTLWindowContext(const MacWindowInfo& info, const DisplayParams& params)
|
||||
: DawnWindowContext(params, dawn::TextureFormat::BGRA8Unorm)
|
||||
, fMainView(info.fMainView) {
|
||||
CGSize size = fMainView.bounds.size;
|
||||
this->initializeContext(size.width, size.height);
|
||||
}
|
||||
|
||||
DawnMTLWindowContext::~DawnMTLWindowContext() {
|
||||
this->destroyContext();
|
||||
}
|
||||
|
||||
DawnSwapChainImplementation DawnMTLWindowContext::createSwapChainImplementation(
|
||||
int width, int height, const DisplayParams& params) {
|
||||
return SwapChainImplMTL::Create(fMTLDevice, fLayer);
|
||||
}
|
||||
|
||||
dawn::Device DawnMTLWindowContext::onInitializeContext() {
|
||||
dawn::Device device = this->createDevice(dawn_native::BackendType::Metal);
|
||||
if (!device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
fMTLDevice = dawn_native::metal::GetMetalDevice(device.Get());
|
||||
|
||||
CGSize size;
|
||||
size.width = width();
|
||||
size.height = height();
|
||||
|
||||
fLayer = [CAMetalLayer layer];
|
||||
[fLayer setDevice:fMTLDevice];
|
||||
[fLayer setPixelFormat: MTLPixelFormatBGRA8Unorm];
|
||||
[fLayer setFramebufferOnly: YES];
|
||||
[fLayer setDrawableSize: size];
|
||||
[fLayer setColorspace: CGColorSpaceCreateDeviceRGB()];
|
||||
|
||||
[fMainView setWantsLayer: YES];
|
||||
[fMainView setLayer: fLayer];
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
void DawnMTLWindowContext::onDestroyContext() {
|
||||
}
|
||||
|
||||
void DawnMTLWindowContext::onSwapBuffers() {
|
||||
}
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
std::unique_ptr<WindowContext> MakeDawnMTLForMac(const MacWindowInfo& winInfo,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new DawnMTLWindowContext(winInfo, params));
|
||||
if (!ctx->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} //namespace sk_app
|
@ -36,6 +36,10 @@ inline std::unique_ptr<WindowContext> MakeVulkanForMac(const MacWindowInfo&, con
|
||||
|
||||
std::unique_ptr<WindowContext> MakeGLForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
|
||||
#ifdef SK_DAWN
|
||||
std::unique_ptr<WindowContext> MakeDawnMTLForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
#endif
|
||||
|
||||
std::unique_ptr<WindowContext> MakeRasterForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
#ifdef SK_METAL
|
||||
std::unique_ptr<WindowContext> MakeMetalForMac(const MacWindowInfo&, const DisplayParams&);
|
||||
|
@ -122,6 +122,11 @@ bool Window_mac::attach(BackendType attachType) {
|
||||
case kRaster_BackendType:
|
||||
fWindowContext = MakeRasterForMac(info, fRequestedDisplayParams);
|
||||
break;
|
||||
#ifdef SK_DAWN
|
||||
case kDawn_BackendType:
|
||||
fWindowContext = MakeDawnMTLForMac(info, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
#ifdef SK_VULKAN
|
||||
case kVulkan_BackendType:
|
||||
fWindowContext = MakeVulkanForMac(info, fRequestedDisplayParams);
|
||||
|
107
tools/sk_app/unix/DawnVulkanWindowContext_unix.cpp
Normal file
107
tools/sk_app/unix/DawnVulkanWindowContext_unix.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "tools/sk_app/DawnWindowContext.h"
|
||||
#include "tools/sk_app/unix/WindowContextFactory_unix.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_native/VulkanBackend.h"
|
||||
#include "src/ports/SkOSLibrary.h"
|
||||
#include "tools/gpu/vk/VkTestUtils.h"
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <X11/Xlib-xcb.h>
|
||||
|
||||
using sk_app::window_context_factory::XlibWindowInfo;
|
||||
using sk_app::DisplayParams;
|
||||
using sk_app::DawnWindowContext;
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class DawnVulkanWindowContext_xlib : public DawnWindowContext {
|
||||
public:
|
||||
DawnVulkanWindowContext_xlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
~DawnVulkanWindowContext_xlib() override {}
|
||||
dawn::Device onInitializeContext() override;
|
||||
void onDestroyContext() override {}
|
||||
DawnSwapChainImplementation createSwapChainImplementation(
|
||||
int width, int height, const DisplayParams& params) override;
|
||||
void onSwapBuffers() override {}
|
||||
|
||||
private:
|
||||
Display* fDisplay;
|
||||
XWindow fWindow;
|
||||
VkSurfaceKHR fVkSurface = nullptr;
|
||||
|
||||
typedef DawnWindowContext INHERITED;
|
||||
};
|
||||
|
||||
DawnVulkanWindowContext_xlib::DawnVulkanWindowContext_xlib(const XlibWindowInfo& winInfo,
|
||||
const DisplayParams& params)
|
||||
: INHERITED(params, dawn::TextureFormat::BGRA8Unorm)
|
||||
, fDisplay(winInfo.fDisplay)
|
||||
, fWindow(winInfo.fWindow) {
|
||||
XWindow root;
|
||||
int x, y;
|
||||
unsigned int border_width, depth;
|
||||
unsigned int width, height;
|
||||
XGetGeometry(fDisplay, fWindow, &root, &x, &y, &width, &height, &border_width, &depth);
|
||||
this->initializeContext(width, height);
|
||||
}
|
||||
|
||||
DawnSwapChainImplementation DawnVulkanWindowContext_xlib::createSwapChainImplementation(
|
||||
int width, int height, const DisplayParams& params) {
|
||||
return dawn_native::vulkan::CreateNativeSwapChainImpl(fDevice.Get(), fVkSurface);
|
||||
}
|
||||
|
||||
dawn::Device DawnVulkanWindowContext_xlib::onInitializeContext() {
|
||||
dawn::Device device = this->createDevice(dawn_native::BackendType::Vulkan);
|
||||
if (!device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void *vkLib = DynamicLoadLibrary("libvulkan.so.1");
|
||||
if (!vkLib) {
|
||||
return nullptr;
|
||||
}
|
||||
VkInstance instance = dawn_native::vulkan::GetInstance(device.Get());
|
||||
if (!instance) {
|
||||
return nullptr;
|
||||
}
|
||||
auto createXcbSurfaceKHR =
|
||||
reinterpret_cast<PFN_vkCreateXcbSurfaceKHR>(GetProcedureAddress(vkLib,
|
||||
"vkCreateXcbSurfaceKHR"));
|
||||
if (!createXcbSurfaceKHR) {
|
||||
printf("couldn't get extensions :(\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VkXcbSurfaceCreateInfoKHR surfaceCreateInfo;
|
||||
memset(&surfaceCreateInfo, 0, sizeof(VkXcbSurfaceCreateInfoKHR));
|
||||
surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
|
||||
surfaceCreateInfo.pNext = nullptr;
|
||||
surfaceCreateInfo.flags = 0;
|
||||
surfaceCreateInfo.connection = XGetXCBConnection(fDisplay);
|
||||
surfaceCreateInfo.window = fWindow;
|
||||
|
||||
createXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &fVkSurface);
|
||||
return device;
|
||||
}
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
std::unique_ptr<WindowContext> MakeDawnVulkanForXlib(const XlibWindowInfo& winInfo,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new DawnVulkanWindowContext_xlib(winInfo, params));
|
||||
if (!ctx->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace sk_app
|
@ -40,6 +40,10 @@ std::unique_ptr<WindowContext> MakeVulkanForXlib(const XlibWindowInfo&, const Di
|
||||
|
||||
std::unique_ptr<WindowContext> MakeGLForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
|
||||
#ifdef SK_DAWN
|
||||
std::unique_ptr<WindowContext> MakeDawnVulkanForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
#endif
|
||||
|
||||
std::unique_ptr<WindowContext> MakeRasterForXlib(const XlibWindowInfo&, const DisplayParams&);
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
@ -358,6 +358,12 @@ bool Window_unix::attach(BackendType attachType) {
|
||||
}
|
||||
|
||||
switch (attachType) {
|
||||
#ifdef SK_DAWN
|
||||
case kDawn_BackendType:
|
||||
fWindowContext =
|
||||
window_context_factory::MakeDawnVulkanForXlib(winInfo, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
#ifdef SK_VULKAN
|
||||
case kVulkan_BackendType:
|
||||
fWindowContext =
|
||||
|
72
tools/sk_app/win/DawnD3D12WindowContext_win.cpp
Normal file
72
tools/sk_app/win/DawnD3D12WindowContext_win.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "tools/sk_app/DawnWindowContext.h"
|
||||
#include "tools/sk_app/win/WindowContextFactory_win.h"
|
||||
#include "dawn/dawncpp.h"
|
||||
#include "dawn/dawn_wsi.h"
|
||||
#include "dawn_native/DawnNative.h"
|
||||
#include "dawn_native/D3D12Backend.h"
|
||||
#include "common/SwapChainUtils.h"
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
class DawnD3D12WindowContext : public DawnWindowContext {
|
||||
public:
|
||||
DawnD3D12WindowContext(HWND hwnd, const DisplayParams& params);
|
||||
virtual ~DawnD3D12WindowContext();
|
||||
dawn::Device onInitializeContext() override;
|
||||
void onDestroyContext() override;
|
||||
DawnSwapChainImplementation createSwapChainImplementation(
|
||||
int width, int height, const DisplayParams& params) override;
|
||||
void onSwapBuffers() override;
|
||||
private:
|
||||
HWND fWindow;
|
||||
};
|
||||
|
||||
// NOTE: this texture format must match the one in D3D12's swap chain impl
|
||||
DawnD3D12WindowContext::DawnD3D12WindowContext(HWND hwnd, const DisplayParams& params)
|
||||
: DawnWindowContext(params, dawn::TextureFormat::RGBA8Unorm)
|
||||
, fWindow(hwnd) {
|
||||
RECT rect;
|
||||
GetClientRect(hwnd, &rect);
|
||||
this->initializeContext(rect.right - rect.left, rect.bottom - rect.top);
|
||||
}
|
||||
|
||||
DawnD3D12WindowContext::~DawnD3D12WindowContext() {
|
||||
this->destroyContext();
|
||||
}
|
||||
|
||||
DawnSwapChainImplementation DawnD3D12WindowContext::createSwapChainImplementation(
|
||||
int width, int height, const DisplayParams& params) {
|
||||
return dawn_native::d3d12::CreateNativeSwapChainImpl(fDevice.Get(), fWindow);
|
||||
}
|
||||
|
||||
dawn::Device DawnD3D12WindowContext::onInitializeContext() {
|
||||
return this->createDevice(dawn_native::BackendType::D3D12);
|
||||
}
|
||||
|
||||
void DawnD3D12WindowContext::onDestroyContext() {
|
||||
}
|
||||
|
||||
void DawnD3D12WindowContext::onSwapBuffers() {
|
||||
}
|
||||
|
||||
namespace window_context_factory {
|
||||
|
||||
std::unique_ptr<WindowContext> MakeDawnD3D12ForWin(HWND hwnd,
|
||||
const DisplayParams& params) {
|
||||
std::unique_ptr<WindowContext> ctx(new DawnD3D12WindowContext(hwnd, params));
|
||||
if (!ctx->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} //namespace sk_app
|
@ -26,6 +26,10 @@ std::unique_ptr<WindowContext> MakeGLForWin(HWND, const DisplayParams&);
|
||||
|
||||
std::unique_ptr<WindowContext> MakeANGLEForWin(HWND, const DisplayParams&);
|
||||
|
||||
#ifdef SK_DAWN
|
||||
std::unique_ptr<WindowContext> MakeDawnD3D12ForWin(HWND, const DisplayParams&);
|
||||
#endif
|
||||
|
||||
std::unique_ptr<WindowContext> MakeRasterForWin(HWND, const DisplayParams&);
|
||||
|
||||
} // namespace window_context_factory
|
||||
|
@ -358,6 +358,12 @@ bool Window_win::attach(BackendType attachType) {
|
||||
fWindowContext =
|
||||
window_context_factory::MakeANGLEForWin(fHWnd, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
#ifdef SK_DAWN
|
||||
case kDawn_BackendType:
|
||||
fWindowContext =
|
||||
window_context_factory::MakeDawnD3D12ForWin(fHWnd, fRequestedDisplayParams);
|
||||
break;
|
||||
#endif
|
||||
case kRaster_BackendType:
|
||||
fWindowContext =
|
||||
|
@ -81,10 +81,12 @@ Application* Application::Create(int argc, char** argv, void* platformData) {
|
||||
static DEFINE_string(slide, "", "Start on this sample.");
|
||||
static DEFINE_bool(list, false, "List samples?");
|
||||
|
||||
#ifdef SK_VULKAN
|
||||
#if defined(SK_VULKAN)
|
||||
# define BACKENDS_STR "\"sw\", \"gl\", and \"vk\""
|
||||
#elif defined(SK_METAL) && defined(SK_BUILD_FOR_MAC)
|
||||
# define BACKENDS_STR "\"sw\", \"gl\", and \"mtl\""
|
||||
#elif defined(SK_DAWN)
|
||||
# define BACKENDS_STR "\"sw\", \"gl\", and \"dawn\""
|
||||
#else
|
||||
# define BACKENDS_STR "\"sw\" and \"gl\""
|
||||
#endif
|
||||
@ -133,6 +135,9 @@ const char* kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
|
||||
#if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
|
||||
"ANGLE",
|
||||
#endif
|
||||
#ifdef SK_DAWN
|
||||
"Dawn",
|
||||
#endif
|
||||
#ifdef SK_VULKAN
|
||||
"Vulkan",
|
||||
#endif
|
||||
@ -143,6 +148,11 @@ const char* kBackendTypeStrings[sk_app::Window::kBackendTypeCount] = {
|
||||
};
|
||||
|
||||
static sk_app::Window::BackendType get_backend_type(const char* str) {
|
||||
#ifdef SK_DAWN
|
||||
if (0 == strcmp(str, "dawn")) {
|
||||
return sk_app::Window::kDawn_BackendType;
|
||||
} else
|
||||
#endif
|
||||
#ifdef SK_VULKAN
|
||||
if (0 == strcmp(str, "vk")) {
|
||||
return sk_app::Window::kVulkan_BackendType;
|
||||
@ -1520,6 +1530,10 @@ void Viewer::drawImGui() {
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("ANGLE", &newBackend, sk_app::Window::kANGLE_BackendType);
|
||||
#endif
|
||||
#if defined(SK_DAWN)
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("Dawn", &newBackend, sk_app::Window::kDawn_BackendType);
|
||||
#endif
|
||||
#if defined(SK_VULKAN)
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("Vulkan", &newBackend, sk_app::Window::kVulkan_BackendType);
|
||||
|
Loading…
Reference in New Issue
Block a user