Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Direct3D backend #121

Open
wants to merge 4 commits into
base: skiasharp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/c/gr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ SK_C_API gr_direct_context_t* gr_direct_context_make_vulkan(const gr_vk_backendc
SK_C_API gr_direct_context_t* gr_direct_context_make_vulkan_with_options(const gr_vk_backendcontext_t vkBackendContext, const gr_context_options_t* options);
SK_C_API gr_direct_context_t* gr_direct_context_make_metal(void* device, void* queue);
SK_C_API gr_direct_context_t* gr_direct_context_make_metal_with_options(void* device, void* queue, const gr_context_options_t* options);
SK_C_API gr_direct_context_t* gr_direct_context_make_direct3d(const gr_d3d_backendcontext_t d3dBackendContext);
SK_C_API gr_direct_context_t* gr_direct_context_make_direct3d_with_options(const gr_d3d_backendcontext_t d3dBackendContext, const gr_context_options_t* options);

// TODO: the overloads with GrContextOptions

Expand Down Expand Up @@ -77,6 +79,7 @@ SK_C_API bool gr_vk_extensions_has_extension(gr_vk_extensions_t* extensions, con
SK_C_API gr_backendtexture_t* gr_backendtexture_new_gl(int width, int height, bool mipmapped, const gr_gl_textureinfo_t* glInfo);
SK_C_API gr_backendtexture_t* gr_backendtexture_new_vulkan(int width, int height, const gr_vk_imageinfo_t* vkInfo);
SK_C_API gr_backendtexture_t* gr_backendtexture_new_metal(int width, int height, bool mipmapped, const gr_mtl_textureinfo_t* mtlInfo);
SK_C_API gr_backendtexture_t* gr_backendtexture_new_direct3d(int width, int height, const gr_d3d_textureresourceinfo_t* d3dInfo);
SK_C_API void gr_backendtexture_delete(gr_backendtexture_t* texture);

SK_C_API bool gr_backendtexture_is_valid(const gr_backendtexture_t* texture);
Expand All @@ -92,6 +95,7 @@ SK_C_API bool gr_backendtexture_get_gl_textureinfo(const gr_backendtexture_t* te
SK_C_API gr_backendrendertarget_t* gr_backendrendertarget_new_gl(int width, int height, int samples, int stencils, const gr_gl_framebufferinfo_t* glInfo);
SK_C_API gr_backendrendertarget_t* gr_backendrendertarget_new_vulkan(int width, int height, int samples, const gr_vk_imageinfo_t* vkImageInfo);
SK_C_API gr_backendrendertarget_t* gr_backendrendertarget_new_metal(int width, int height, int samples, const gr_mtl_textureinfo_t* mtlInfo);
SK_C_API gr_backendrendertarget_t* gr_backendrendertarget_new_direct3d(int width, int height, const gr_d3d_textureresourceinfo_t* d3dInfo);

SK_C_API void gr_backendrendertarget_delete(gr_backendrendertarget_t* rendertarget);

Expand Down
25 changes: 25 additions & 0 deletions include/c/sk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,4 +1116,29 @@ typedef struct skresources_resource_provider_t skresources_resource_provider_t;

SK_C_PLUS_PLUS_END_GUARD

typedef struct d3d_dxgi_adapter_t d3d_dxgi_adapter_t;
typedef struct d3d_d12_device_t d3d_d12_device_t;
typedef struct d3d_d12_command_queue_t d3d_d12_command_queue_t;
typedef struct gr_d3d_memory_allocator_t gr_d3d_memory_allocator_t;
typedef struct {
d3d_dxgi_adapter_t* fAdapter;
d3d_d12_device_t* fDevice;
d3d_d12_command_queue_t* fQueue;
gr_d3d_memory_allocator_t* fMemoryAllocator;
bool fProtectedContext;
} gr_d3d_backendcontext_t;
Kation marked this conversation as resolved.
Show resolved Hide resolved

typedef struct d3d_d12_resource_t d3d_d12_resource_t;
typedef struct d3d_alloc_t d3d_alloc_t;
Kation marked this conversation as resolved.
Show resolved Hide resolved
typedef struct {
d3d_d12_resource_t* fResource;
Kation marked this conversation as resolved.
Show resolved Hide resolved
d3d_alloc_t* fAlloc;
Kation marked this conversation as resolved.
Show resolved Hide resolved
uint32_t fResourceState;
uint32_t fFormat;
uint32_t fSampleCount;
uint32_t fLevelCount;
unsigned int fSampleQualityPattern;
bool fProtected;
} gr_d3d_textureresourceinfo_t;

#endif
24 changes: 24 additions & 0 deletions src/c/gr_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ gr_direct_context_t* gr_direct_context_make_metal_with_options(void* device, voi
return SK_ONLY_METAL(ToGrDirectContext(GrDirectContext::MakeMetal(device, queue, opts).release()), nullptr);
}

gr_direct_context_t* gr_direct_context_make_direct3d(const gr_d3d_backendcontext_t d3dBackendContext) {
return SK_ONLY_DIRECT3D(
ToGrDirectContext(
GrDirectContext::MakeDirect3D(AsGrD3DBackendContext(d3dBackendContext)).release()),
nullptr);
}

gr_direct_context_t* gr_direct_context_make_direct3d_with_options(const gr_d3d_backendcontext_t d3dBackendContext,
const gr_context_options_t* options) {
SK_ONLY_DIRECT3D(GrContextOptions opts; if (options) { opts = AsGrContextOptions(options); })
return SK_ONLY_DIRECT3D(
ToGrDirectContext(GrDirectContext::MakeDirect3D(AsGrD3DBackendContext(d3dBackendContext), opts)
.release()),
nullptr);
}

bool gr_direct_context_is_abandoned(gr_direct_context_t* context) {
return SK_ONLY_GPU(AsGrDirectContext(context)->abandoned(), true);
}
Expand Down Expand Up @@ -224,6 +240,10 @@ gr_backendtexture_t* gr_backendtexture_new_metal(int width, int height, bool mip
return SK_ONLY_METAL(ToGrBackendTexture(new GrBackendTexture(width, height, (GrMipMapped)mipmapped, AsGrMtlTextureInfo(mtlInfo))), nullptr);
}

gr_backendtexture_t* gr_backendtexture_new_direct3d(int width, int height, const gr_d3d_textureresourceinfo_t* d3dInfo) {
return SK_ONLY_DIRECT3D(ToGrBackendTexture(new GrBackendTexture(width, height, *AsGrD3DTextureResourceInfo(d3dInfo))), nullptr);
}

void gr_backendtexture_delete(gr_backendtexture_t* texture) {
SK_ONLY_GPU(delete AsGrBackendTexture(texture));
}
Expand Down Expand Up @@ -267,6 +287,10 @@ gr_backendrendertarget_t* gr_backendrendertarget_new_metal(int width, int height
return SK_ONLY_METAL(ToGrBackendRenderTarget(new GrBackendRenderTarget(width, height, samples, AsGrMtlTextureInfo(mtlInfo))), nullptr);
}

gr_backendrendertarget_t* gr_backendrendertarget_new_direct3d(int width, int height, const gr_d3d_textureresourceinfo_t* d3dInfo) {
return SK_ONLY_DIRECT3D(ToGrBackendRenderTarget(new GrBackendRenderTarget(width, height, *AsGrD3DTextureResourceInfo(d3dInfo))), nullptr);
}

void gr_backendrendertarget_delete(gr_backendrendertarget_t* rendertarget) {
SK_ONLY_GPU(delete AsGrBackendRenderTarget(rendertarget));
}
Expand Down
20 changes: 20 additions & 0 deletions src/c/sk_types_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@
# else
# define SK_ONLY_METAL(...) SK_SKIP_ARG(__VA_ARGS__)
# endif
# if SK_DIRECT3D
# include "include/gpu/d3d/GrD3DBackendContext.h"
# include "include/gpu/d3d/GrD3DTypes.h"
# define SK_ONLY_DIRECT3D(...) SK_FIRST_ARG(__VA_ARGS__)
# else
# define SK_ONLY_DIRECT3D(...) SK_SKIP_ARG(__VA_ARGS__)
# endif
#else // !SK_GANESH
# define SK_ONLY_GPU(...) SK_SKIP_ARG(__VA_ARGS__)
# define SK_ONLY_VULKAN(...) SK_SKIP_ARG(__VA_ARGS__)
# define SK_ONLY_METAL(...) SK_SKIP_ARG(__VA_ARGS__)
# define SK_ONLY_DIRECT3D(...) SK_SKIP_ARG(__VA_ARGS__)
#endif // SK_GANESH


Expand Down Expand Up @@ -177,6 +185,9 @@ DEF_STRUCT_MAP(GrGLInterface, gr_glinterface_t, GrGLInterface)
DEF_STRUCT_MAP(GrVkYcbcrConversionInfo, gr_vk_ycbcrconversioninfo_t, GrVkYcbcrConversionInfo)
DEF_STRUCT_MAP(GrVkImageInfo, gr_vk_imageinfo_t, GrVkImageInfo)

DEF_STRUCT_MAP(GrD3DBackendContext, gr_d3d_backendcontext_t, GrD3DBackendContext)
DEF_STRUCT_MAP(GrD3DTextureResourceInfo, gr_d3d_textureresourceinfo_t, GrD3DTextureResourceInfo)

#include "include/effects/SkRuntimeEffect.h"
DEF_MAP(SkRuntimeEffect::Uniform, sk_runtimeeffect_uniform_t, RuntimeEffectUniform)
DEF_MAP(SkRuntimeEffect::Child, sk_runtimeeffect_child_t, RuntimeEffectChild)
Expand Down Expand Up @@ -412,6 +423,15 @@ static inline GrMtlTextureInfo AsGrMtlTextureInfo(const gr_mtl_textureinfo_t* mt

#endif // SK_METAL

#if defined(SK_DIRECT3D)

DEF_MAP(IDXGIAdapter1, d3d_dxgi_adapter_t, IDXGIAdapter1);
DEF_MAP(ID3D12Device, d3d_d12_device_t, ID3D12Device);
DEF_MAP(ID3D12CommandQueue, d3d_d12_command_queue_t, ID3D12CommandQueue);
DEF_MAP(GrD3DMemoryAllocator, gr_d3d_memory_allocator_t, GrD3DMemoryAllocator);

#endif //SK_DIRECT3D

#endif // SK_GANESH

#endif