capi: fix pointer type bindings for D3D11
This commit is contained in:
parent
62b0d590ad
commit
8e67c637a5
|
@ -23,6 +23,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __LIBRASHADER_H__
|
#ifndef __LIBRASHADER_H__
|
||||||
#define __LIBRASHADER_H__
|
#define __LIBRASHADER_H__
|
||||||
|
|
||||||
|
@ -36,12 +37,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#if defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11)
|
#if defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11)
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#else
|
#else
|
||||||
typedef void ID3D11Device;typedef void ID3D11RenderTargetView;typedef void ID3D11ShaderResourceView;
|
typedef void ID3D11Device;
|
||||||
|
typedef void ID3D11RenderTargetView;
|
||||||
|
typedef void ID3D11ShaderResourceView;
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBRA_RUNTIME_VULKAN)
|
#if defined(LIBRA_RUNTIME_VULKAN)
|
||||||
#include <vulkan\vulkan.h>
|
#include <vulkan\vulkan.h>
|
||||||
|
#else
|
||||||
|
typedef int32_t VkFormat;
|
||||||
|
typedef uint64_t VkImage;
|
||||||
|
typedef void* VkPhysicalDevice;
|
||||||
|
typedef void* VkInstance;
|
||||||
|
typedef void* VkCommandBuffer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// Error codes for librashader error types.
|
/// Error codes for librashader error types.
|
||||||
enum LIBRA_ERRNO
|
enum LIBRA_ERRNO
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -199,7 +209,7 @@ typedef struct _filter_chain_d3d11 *libra_d3d11_filter_chain_t;
|
||||||
/// OpenGL parameters for the source image.
|
/// OpenGL parameters for the source image.
|
||||||
typedef struct libra_source_image_d3d11_t {
|
typedef struct libra_source_image_d3d11_t {
|
||||||
/// A shader resource view into the source image
|
/// A shader resource view into the source image
|
||||||
const ID3D11ShaderResourceView *handle;
|
const ID3D11ShaderResourceView * handle;
|
||||||
/// The height of the source image.
|
/// The height of the source image.
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
/// The width of the source image.
|
/// The width of the source image.
|
||||||
|
@ -238,6 +248,11 @@ typedef struct filter_chain_vk_opt_t {
|
||||||
uint32_t frames_in_flight;
|
uint32_t frames_in_flight;
|
||||||
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
|
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
|
||||||
bool force_no_mipmaps;
|
bool force_no_mipmaps;
|
||||||
|
/// The format to use for the render pass. If this is `VK_FORMAT_UNDEFINED`, dynamic rendering
|
||||||
|
/// will be used instead of a render pass. If this is set to some format, the render passes
|
||||||
|
/// will be created with such format. It is recommended if possible to use dynamic rendering,
|
||||||
|
/// because render-pass mode will create new framebuffers per pass.
|
||||||
|
VkFormat render_pass_format;
|
||||||
} filter_chain_vk_opt_t;
|
} filter_chain_vk_opt_t;
|
||||||
|
|
||||||
#if defined(LIBRA_RUNTIME_VULKAN)
|
#if defined(LIBRA_RUNTIME_VULKAN)
|
||||||
|
@ -382,7 +397,7 @@ typedef libra_error_t (*PFN_libra_gl_filter_chain_free)(libra_gl_filter_chain_t
|
||||||
///libra_d3d11_filter_chain_create
|
///libra_d3d11_filter_chain_create
|
||||||
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_create)(libra_shader_preset_t *preset,
|
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_create)(libra_shader_preset_t *preset,
|
||||||
const struct filter_chain_d3d11_opt_t *options,
|
const struct filter_chain_d3d11_opt_t *options,
|
||||||
const ID3D11Device *device,
|
const ID3D11Device * device,
|
||||||
libra_d3d11_filter_chain_t *out);
|
libra_d3d11_filter_chain_t *out);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -393,7 +408,7 @@ typedef libra_error_t (*PFN_libra_d3d11_filter_chain_frame)(libra_d3d11_filter_c
|
||||||
size_t frame_count,
|
size_t frame_count,
|
||||||
struct libra_source_image_d3d11_t image,
|
struct libra_source_image_d3d11_t image,
|
||||||
struct libra_viewport_t viewport,
|
struct libra_viewport_t viewport,
|
||||||
const ID3D11RenderTargetView *out,
|
const ID3D11RenderTargetView * out,
|
||||||
const float *mvp,
|
const float *mvp,
|
||||||
const struct frame_d3d11_opt_t *opt);
|
const struct frame_d3d11_opt_t *opt);
|
||||||
#endif
|
#endif
|
||||||
|
@ -717,10 +732,11 @@ libra_error_t libra_gl_filter_chain_free(libra_gl_filter_chain_t *chain);
|
||||||
/// ## Safety:
|
/// ## Safety:
|
||||||
/// - `preset` must be either null, or valid and aligned.
|
/// - `preset` must be either null, or valid and aligned.
|
||||||
/// - `options` must be either null, or valid and aligned.
|
/// - `options` must be either null, or valid and aligned.
|
||||||
|
/// - `device` must not be null.
|
||||||
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
|
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
|
||||||
libra_error_t libra_d3d11_filter_chain_create(libra_shader_preset_t *preset,
|
libra_error_t libra_d3d11_filter_chain_create(libra_shader_preset_t *preset,
|
||||||
const struct filter_chain_d3d11_opt_t *options,
|
const struct filter_chain_d3d11_opt_t *options,
|
||||||
const ID3D11Device *device,
|
const ID3D11Device * device,
|
||||||
libra_d3d11_filter_chain_t *out);
|
libra_d3d11_filter_chain_t *out);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -734,11 +750,13 @@ libra_error_t libra_d3d11_filter_chain_create(libra_shader_preset_t *preset,
|
||||||
/// values for the model view projection matrix.
|
/// values for the model view projection matrix.
|
||||||
/// - `opt` may be null, or if it is not null, must be an aligned pointer to a valid `frame_gl_opt_t`
|
/// - `opt` may be null, or if it is not null, must be an aligned pointer to a valid `frame_gl_opt_t`
|
||||||
/// struct.
|
/// struct.
|
||||||
|
/// - `out` must not be null.
|
||||||
|
/// - `image.handle` must not be null.
|
||||||
libra_error_t libra_d3d11_filter_chain_frame(libra_d3d11_filter_chain_t *chain,
|
libra_error_t libra_d3d11_filter_chain_frame(libra_d3d11_filter_chain_t *chain,
|
||||||
size_t frame_count,
|
size_t frame_count,
|
||||||
struct libra_source_image_d3d11_t image,
|
struct libra_source_image_d3d11_t image,
|
||||||
struct libra_viewport_t viewport,
|
struct libra_viewport_t viewport,
|
||||||
const ID3D11RenderTargetView *out,
|
const ID3D11RenderTargetView * out,
|
||||||
const float *mvp,
|
const float *mvp,
|
||||||
const struct frame_d3d11_opt_t *opt);
|
const struct frame_d3d11_opt_t *opt);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,12 +26,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#ifndef __LIBRASHADER_LD_H__
|
#ifndef __LIBRASHADER_LD_H__
|
||||||
#define __LIBRASHADER_LD_H__
|
#define __LIBRASHADER_LD_H__
|
||||||
#pragma once
|
#pragma once
|
||||||
#define LIBRA_RUNTIME_OPENGL
|
|
||||||
#define LIBRA_RUNTIME_VULKAN
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
// Uncomment the following defines to activate runtimes.
|
||||||
#define LIBRA_RUNTIME_D3D11
|
|
||||||
#endif
|
//#define LIBRA_RUNTIME_OPENGL
|
||||||
|
//#define LIBRA_RUNTIME_VULKAN
|
||||||
|
//
|
||||||
|
//#if defined(_WIN32)
|
||||||
|
//#define LIBRA_RUNTIME_D3D11
|
||||||
|
//#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
|
@ -4,7 +4,51 @@ include_guard = "__LIBRASHADER_H__"
|
||||||
pragma_once = true
|
pragma_once = true
|
||||||
usize_is_size_t = true
|
usize_is_size_t = true
|
||||||
documentation_style = "c++"
|
documentation_style = "c++"
|
||||||
after_includes = "#if defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11)\n#include <d3d11.h>\n#else\ntypedef void ID3D11Device;typedef void ID3D11RenderTargetView;typedef void ID3D11ShaderResourceView;\n#endif\n#if defined(LIBRA_RUNTIME_VULKAN)\n#include <vulkan\\vulkan.h>\n#endif"
|
header = """
|
||||||
|
/*
|
||||||
|
librashader.h
|
||||||
|
SPDX-License-Identifier: MIT
|
||||||
|
This file is part of the librashader C headers.
|
||||||
|
|
||||||
|
Copyright 2022 chyyran
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
"""
|
||||||
|
|
||||||
|
after_includes = """
|
||||||
|
#if defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11)
|
||||||
|
#include <d3d11.h>
|
||||||
|
#else
|
||||||
|
typedef void ID3D11Device;
|
||||||
|
typedef void ID3D11RenderTargetView;
|
||||||
|
typedef void ID3D11ShaderResourceView;
|
||||||
|
#endif
|
||||||
|
#if defined(LIBRA_RUNTIME_VULKAN)
|
||||||
|
#include <vulkan\\vulkan.h>
|
||||||
|
#else
|
||||||
|
typedef int32_t VkFormat;
|
||||||
|
typedef uint64_t VkImage;
|
||||||
|
typedef void* VkPhysicalDevice;
|
||||||
|
typedef void* VkInstance;
|
||||||
|
typedef void* VkCommandBuffer;
|
||||||
|
#endif
|
||||||
|
"""
|
||||||
|
|
||||||
[defines]
|
[defines]
|
||||||
"feature = runtime-opengl" = "LIBRA_RUNTIME_OPENGL"
|
"feature = runtime-opengl" = "LIBRA_RUNTIME_OPENGL"
|
||||||
|
@ -95,4 +139,9 @@ include = [
|
||||||
"Device" = "VkDevice"
|
"Device" = "VkDevice"
|
||||||
"CommandBuffer" = "VkCommandBuffer"
|
"CommandBuffer" = "VkCommandBuffer"
|
||||||
"Format" = "VkFormat"
|
"Format" = "VkFormat"
|
||||||
"Image" = "VkImage"
|
"Image" = "VkImage"
|
||||||
|
|
||||||
|
#hack to get proper pointer indirection for COM pointers
|
||||||
|
"ID3D11Device" = "const ID3D11Device *"
|
||||||
|
"ID3D11RenderTargetView" = "const ID3D11RenderTargetView *"
|
||||||
|
"ID3D11ShaderResourceView" = "const ID3D11ShaderResourceView *"
|
|
@ -20,7 +20,7 @@ use librashader::runtime::{FilterChainParameters, Size, Viewport};
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct libra_source_image_d3d11_t {
|
pub struct libra_source_image_d3d11_t {
|
||||||
/// A shader resource view into the source image
|
/// A shader resource view into the source image
|
||||||
pub handle: *const ID3D11ShaderResourceView,
|
pub handle: ID3D11ShaderResourceView,
|
||||||
/// The height of the source image.
|
/// The height of the source image.
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
/// The width of the source image.
|
/// The width of the source image.
|
||||||
|
@ -31,11 +31,10 @@ impl TryFrom<libra_source_image_d3d11_t> for D3D11InputView {
|
||||||
type Error = LibrashaderError;
|
type Error = LibrashaderError;
|
||||||
|
|
||||||
fn try_from(value: libra_source_image_d3d11_t) -> Result<Self, Self::Error> {
|
fn try_from(value: libra_source_image_d3d11_t) -> Result<Self, Self::Error> {
|
||||||
let handle = value.handle;
|
let handle = value.handle.clone();
|
||||||
assert_non_null!(noexport handle);
|
|
||||||
|
|
||||||
Ok(D3D11InputView {
|
Ok(D3D11InputView {
|
||||||
handle: unsafe { (*handle).clone() },
|
handle,
|
||||||
size: Size::new(value.width, value.height),
|
size: Size::new(value.width, value.height),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -50,15 +49,15 @@ extern_fn! {
|
||||||
/// ## Safety:
|
/// ## Safety:
|
||||||
/// - `preset` must be either null, or valid and aligned.
|
/// - `preset` must be either null, or valid and aligned.
|
||||||
/// - `options` must be either null, or valid and aligned.
|
/// - `options` must be either null, or valid and aligned.
|
||||||
|
/// - `device` must not be null.
|
||||||
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
|
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
|
||||||
fn libra_d3d11_filter_chain_create(
|
fn libra_d3d11_filter_chain_create(
|
||||||
preset: *mut libra_shader_preset_t,
|
preset: *mut libra_shader_preset_t,
|
||||||
options: *const FilterChainOptionsD3D11,
|
options: *const FilterChainOptionsD3D11,
|
||||||
device: *const ID3D11Device,
|
device: ID3D11Device,
|
||||||
out: *mut MaybeUninit<libra_d3d11_filter_chain_t>
|
out: *mut MaybeUninit<libra_d3d11_filter_chain_t>
|
||||||
) {
|
) {
|
||||||
assert_non_null!(preset);
|
assert_non_null!(preset);
|
||||||
assert_non_null!(device);
|
|
||||||
let preset = unsafe {
|
let preset = unsafe {
|
||||||
let preset_ptr = &mut *preset;
|
let preset_ptr = &mut *preset;
|
||||||
let preset = preset_ptr.take();
|
let preset = preset_ptr.take();
|
||||||
|
@ -72,7 +71,7 @@ extern_fn! {
|
||||||
};
|
};
|
||||||
|
|
||||||
let chain = librashader::runtime::d3d11::capi::FilterChainD3D11::load_from_preset(
|
let chain = librashader::runtime::d3d11::capi::FilterChainD3D11::load_from_preset(
|
||||||
unsafe { &*device },
|
&device,
|
||||||
*preset,
|
*preset,
|
||||||
options,
|
options,
|
||||||
)?;
|
)?;
|
||||||
|
@ -95,17 +94,18 @@ extern_fn! {
|
||||||
/// values for the model view projection matrix.
|
/// values for the model view projection matrix.
|
||||||
/// - `opt` may be null, or if it is not null, must be an aligned pointer to a valid `frame_gl_opt_t`
|
/// - `opt` may be null, or if it is not null, must be an aligned pointer to a valid `frame_gl_opt_t`
|
||||||
/// struct.
|
/// struct.
|
||||||
|
/// - `out` must not be null.
|
||||||
|
/// - `image.handle` must not be null.
|
||||||
fn libra_d3d11_filter_chain_frame(
|
fn libra_d3d11_filter_chain_frame(
|
||||||
chain: *mut libra_d3d11_filter_chain_t,
|
chain: *mut libra_d3d11_filter_chain_t,
|
||||||
frame_count: usize,
|
frame_count: usize,
|
||||||
image: libra_source_image_d3d11_t,
|
image: libra_source_image_d3d11_t,
|
||||||
viewport: libra_viewport_t,
|
viewport: libra_viewport_t,
|
||||||
out: *const ID3D11RenderTargetView,
|
out: ID3D11RenderTargetView,
|
||||||
mvp: *const f32,
|
mvp: *const f32,
|
||||||
opt: *const FrameOptionsD3D11
|
opt: *const FrameOptionsD3D11
|
||||||
) mut |chain| {
|
) mut |chain| {
|
||||||
assert_some_ptr!(mut chain);
|
assert_some_ptr!(mut chain);
|
||||||
assert_non_null!(out);
|
|
||||||
|
|
||||||
let mvp = if mvp.is_null() {
|
let mvp = if mvp.is_null() {
|
||||||
None
|
None
|
||||||
|
@ -124,7 +124,7 @@ extern_fn! {
|
||||||
y: viewport.y,
|
y: viewport.y,
|
||||||
output: D3D11OutputView {
|
output: D3D11OutputView {
|
||||||
size: Size::new(viewport.width, viewport.height),
|
size: Size::new(viewport.width, viewport.height),
|
||||||
handle: unsafe { (*out).clone() },
|
handle: out.clone(),
|
||||||
},
|
},
|
||||||
mvp,
|
mvp,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue