capi: fix pointer type bindings for D3D11

This commit is contained in:
chyyran 2023-01-26 19:05:48 -05:00
parent 62b0d590ad
commit 8e67c637a5
4 changed files with 93 additions and 23 deletions

View file

@ -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.
*/
#ifndef __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)
#include <d3d11.h>
#else
typedef void ID3D11Device;typedef void ID3D11RenderTargetView;typedef void ID3D11ShaderResourceView;
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
/// Error codes for librashader error types.
enum LIBRA_ERRNO
#ifdef __cplusplus
@ -199,7 +209,7 @@ typedef struct _filter_chain_d3d11 *libra_d3d11_filter_chain_t;
/// OpenGL parameters for the source image.
typedef struct libra_source_image_d3d11_t {
/// A shader resource view into the source image
const ID3D11ShaderResourceView *handle;
const ID3D11ShaderResourceView * handle;
/// The height of the source image.
uint32_t height;
/// The width of the source image.
@ -238,6 +248,11 @@ typedef struct filter_chain_vk_opt_t {
uint32_t frames_in_flight;
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
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;
#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
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_create)(libra_shader_preset_t *preset,
const struct filter_chain_d3d11_opt_t *options,
const ID3D11Device *device,
const ID3D11Device * device,
libra_d3d11_filter_chain_t *out);
#endif
@ -393,7 +408,7 @@ typedef libra_error_t (*PFN_libra_d3d11_filter_chain_frame)(libra_d3d11_filter_c
size_t frame_count,
struct libra_source_image_d3d11_t image,
struct libra_viewport_t viewport,
const ID3D11RenderTargetView *out,
const ID3D11RenderTargetView * out,
const float *mvp,
const struct frame_d3d11_opt_t *opt);
#endif
@ -717,10 +732,11 @@ libra_error_t libra_gl_filter_chain_free(libra_gl_filter_chain_t *chain);
/// ## Safety:
/// - `preset` 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.
libra_error_t libra_d3d11_filter_chain_create(libra_shader_preset_t *preset,
const struct filter_chain_d3d11_opt_t *options,
const ID3D11Device *device,
const ID3D11Device * device,
libra_d3d11_filter_chain_t *out);
#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.
/// - `opt` may be null, or if it is not null, must be an aligned pointer to a valid `frame_gl_opt_t`
/// 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,
size_t frame_count,
struct libra_source_image_d3d11_t image,
struct libra_viewport_t viewport,
const ID3D11RenderTargetView *out,
const ID3D11RenderTargetView * out,
const float *mvp,
const struct frame_d3d11_opt_t *opt);
#endif

View file

@ -26,12 +26,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef __LIBRASHADER_LD_H__
#define __LIBRASHADER_LD_H__
#pragma once
#define LIBRA_RUNTIME_OPENGL
#define LIBRA_RUNTIME_VULKAN
#if defined(_WIN32)
#define LIBRA_RUNTIME_D3D11
#endif
// Uncomment the following defines to activate runtimes.
//#define LIBRA_RUNTIME_OPENGL
//#define LIBRA_RUNTIME_VULKAN
//
//#if defined(_WIN32)
//#define LIBRA_RUNTIME_D3D11
//#endif
#if defined(_WIN32)
#include <windows.h>

View file

@ -4,7 +4,51 @@ include_guard = "__LIBRASHADER_H__"
pragma_once = true
usize_is_size_t = true
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]
"feature = runtime-opengl" = "LIBRA_RUNTIME_OPENGL"
@ -95,4 +139,9 @@ include = [
"Device" = "VkDevice"
"CommandBuffer" = "VkCommandBuffer"
"Format" = "VkFormat"
"Image" = "VkImage"
"Image" = "VkImage"
#hack to get proper pointer indirection for COM pointers
"ID3D11Device" = "const ID3D11Device *"
"ID3D11RenderTargetView" = "const ID3D11RenderTargetView *"
"ID3D11ShaderResourceView" = "const ID3D11ShaderResourceView *"

View file

@ -20,7 +20,7 @@ use librashader::runtime::{FilterChainParameters, Size, Viewport};
#[repr(C)]
pub struct libra_source_image_d3d11_t {
/// A shader resource view into the source image
pub handle: *const ID3D11ShaderResourceView,
pub handle: ID3D11ShaderResourceView,
/// The height of the source image.
pub height: u32,
/// The width of the source image.
@ -31,11 +31,10 @@ impl TryFrom<libra_source_image_d3d11_t> for D3D11InputView {
type Error = LibrashaderError;
fn try_from(value: libra_source_image_d3d11_t) -> Result<Self, Self::Error> {
let handle = value.handle;
assert_non_null!(noexport handle);
let handle = value.handle.clone();
Ok(D3D11InputView {
handle: unsafe { (*handle).clone() },
handle,
size: Size::new(value.width, value.height),
})
}
@ -50,15 +49,15 @@ extern_fn! {
/// ## Safety:
/// - `preset` 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.
fn libra_d3d11_filter_chain_create(
preset: *mut libra_shader_preset_t,
options: *const FilterChainOptionsD3D11,
device: *const ID3D11Device,
device: ID3D11Device,
out: *mut MaybeUninit<libra_d3d11_filter_chain_t>
) {
assert_non_null!(preset);
assert_non_null!(device);
let preset = unsafe {
let preset_ptr = &mut *preset;
let preset = preset_ptr.take();
@ -72,7 +71,7 @@ extern_fn! {
};
let chain = librashader::runtime::d3d11::capi::FilterChainD3D11::load_from_preset(
unsafe { &*device },
&device,
*preset,
options,
)?;
@ -95,17 +94,18 @@ extern_fn! {
/// 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`
/// struct.
/// - `out` must not be null.
/// - `image.handle` must not be null.
fn libra_d3d11_filter_chain_frame(
chain: *mut libra_d3d11_filter_chain_t,
frame_count: usize,
image: libra_source_image_d3d11_t,
viewport: libra_viewport_t,
out: *const ID3D11RenderTargetView,
out: ID3D11RenderTargetView,
mvp: *const f32,
opt: *const FrameOptionsD3D11
) mut |chain| {
assert_some_ptr!(mut chain);
assert_non_null!(out);
let mvp = if mvp.is_null() {
None
@ -124,7 +124,7 @@ extern_fn! {
y: viewport.y,
output: D3D11OutputView {
size: Size::new(viewport.width, viewport.height),
handle: unsafe { (*out).clone() },
handle: out.clone(),
},
mvp,
};