capi(mtl): implement capi for metal

This commit is contained in:
chyyran 2024-02-13 03:03:45 -05:00 committed by Ronny Chan
parent d89839be16
commit 76aa5ce4c6
32 changed files with 992 additions and 205 deletions

View file

@ -35,28 +35,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdlib.h>
#if defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11)
#include <d3d11.h>
#else
typedef void ID3D11Device;
typedef void ID3D11DeviceContext;
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
#if defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)
#include <d3d12.h>
#else
typedef void ID3D12GraphicsCommandList;
typedef void ID3D12Device;
typedef void ID3D12Resource;
typedef void D3D12_CPU_DESCRIPTOR_HANDLE;
#endif
#if defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__)
#import <Metal/Metal.h>
#endif
#if defined(LIBRA_RUNTIME_VULKAN)
#include <vulkan\vulkan.h>
#endif
/// Error codes for librashader error types.
@ -116,6 +103,9 @@ typedef struct _filter_chain_d3d12 _filter_chain_d3d12;
/// Opaque struct for an OpenGL filter chain.
typedef struct _filter_chain_gl _filter_chain_gl;
/// Opaque struct for a Metal filter chain.
typedef struct _filter_chain_mtl _filter_chain_mtl;
/// Opaque struct for a Vulkan filter chain.
typedef struct _filter_chain_vk _filter_chain_vk;
@ -246,6 +236,12 @@ typedef struct frame_gl_opt_t {
/// The direction of rendering.
/// -1 indicates that the frames are played in reverse order.
int32_t frame_direction;
/// The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 4 = 270deg.
uint32_t rotation;
/// The total number of subframes ran. Default is 1.
uint32_t total_subframes;
/// The current sub frame. Default is 1.
uint32_t current_subframe;
} frame_gl_opt_t;
#endif
@ -270,16 +266,16 @@ typedef struct libra_device_vk_t {
/// Options for filter chain creation.
typedef struct filter_chain_vk_opt_t {
/// The librashader API version.
size_t version;
LIBRASHADER_API_VERSION version;
/// The number of frames in flight to keep. If zero, defaults to three.
uint32_t frames_in_flight;
/// Whether or not to explicitly disable mipmap generation regardless of
/// shader preset settings.
bool force_no_mipmaps;
/// Use explicit render pass objects It is recommended if possible to use
/// dynamic rendering, because render-pass mode will create new framebuffers
/// per pass.
bool use_render_pass;
/// Use dynamic rendering over explicit render pass objects.
/// It is recommended if possible to use dynamic rendering,
/// because render-pass mode will create new framebuffers per pass.
bool use_dynamic_rendering;
/// Disable the shader object cache. Shaders will be
/// recompiled rather than loaded from the cache.
bool disable_cache;
@ -319,16 +315,22 @@ typedef struct libra_output_image_vk_t {
/// Options for each Vulkan shader frame.
typedef struct frame_vk_opt_t {
/// The librashader API version.
size_t version;
LIBRASHADER_API_VERSION version;
/// Whether or not to clear the history buffers.
bool clear_history;
/// The direction of rendering.
/// -1 indicates that the frames are played in reverse order.
int32_t frame_direction;
/// The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 4 = 270deg.
uint32_t rotation;
/// The total number of subframes ran. Default is 1.
uint32_t total_subframes;
/// The current sub frame. Default is 1.
uint32_t current_subframe;
} frame_vk_opt_t;
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Options for Direct3D 11 filter chain creation.
typedef struct filter_chain_d3d11_opt_t {
/// The librashader API version.
@ -342,12 +344,12 @@ typedef struct filter_chain_d3d11_opt_t {
} filter_chain_d3d11_opt_t;
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// A handle to a Direct3D 11 filter chain.
typedef struct _filter_chain_d3d11 *libra_d3d11_filter_chain_t;
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Direct3D 11 parameters for the source image.
typedef struct libra_source_image_d3d11_t {
/// A shader resource view into the source image
@ -359,7 +361,7 @@ typedef struct libra_source_image_d3d11_t {
} libra_source_image_d3d11_t;
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Options for each Direct3D 11 shader frame.
typedef struct frame_d3d11_opt_t {
/// The librashader API version.
@ -369,10 +371,16 @@ typedef struct frame_d3d11_opt_t {
/// The direction of rendering.
/// -1 indicates that the frames are played in reverse order.
int32_t frame_direction;
/// The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 4 = 270deg.
uint32_t rotation;
/// The total number of subframes ran. Default is 1.
uint32_t total_subframes;
/// The current sub frame. Default is 1.
uint32_t current_subframe;
} frame_d3d11_opt_t;
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Options for Direct3D11 filter chain creation.
typedef struct filter_chain_d3d12_opt_t {
/// The librashader API version.
@ -389,12 +397,12 @@ typedef struct filter_chain_d3d12_opt_t {
} filter_chain_d3d12_opt_t;
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// A handle to a Direct3D 12 filter chain.
typedef struct _filter_chain_d3d12 *libra_d3d12_filter_chain_t;
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Direct3D 12 parameters for the source image.
typedef struct libra_source_image_d3d12_t {
/// The resource containing the image.
@ -410,7 +418,7 @@ typedef struct libra_source_image_d3d12_t {
} libra_source_image_d3d12_t;
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Direct3D 12 parameters for the output image.
typedef struct libra_output_image_d3d12_t {
/// A CPU descriptor handle to a shader resource view of the image.
@ -420,7 +428,7 @@ typedef struct libra_output_image_d3d12_t {
} libra_output_image_d3d12_t;
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Options for each Direct3D 12 shader frame.
typedef struct frame_d3d12_opt_t {
/// The librashader API version.
@ -430,9 +438,49 @@ typedef struct frame_d3d12_opt_t {
/// The direction of rendering.
/// -1 indicates that the frames are played in reverse order.
int32_t frame_direction;
/// The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 4 = 270deg.
uint32_t rotation;
/// The total number of subframes ran. Default is 1.
uint32_t total_subframes;
/// The current sub frame. Default is 1.
uint32_t current_subframe;
} frame_d3d12_opt_t;
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Options for filter chain creation.
typedef struct filter_chain_mtl_opt_t {
/// The librashader API version.
LIBRASHADER_API_VERSION version;
/// Whether or not to explicitly disable mipmap generation regardless of
/// shader preset settings.
bool force_no_mipmaps;
} filter_chain_mtl_opt_t;
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
typedef struct _filter_chain_mtl *libra_mtl_filter_chain_t;
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Options for each Vulkan shader frame.
typedef struct frame_mtl_opt_t {
/// The librashader API version.
LIBRASHADER_API_VERSION version;
/// Whether or not to clear the history buffers.
bool clear_history;
/// The direction of rendering.
/// -1 indicates that the frames are played in reverse order.
int32_t frame_direction;
/// The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 4 = 270deg.
uint32_t rotation;
/// The total number of subframes ran. Default is 1.
uint32_t total_subframes;
/// The current sub frame. Default is 1.
uint32_t current_subframe;
} frame_mtl_opt_t;
#endif
typedef size_t LIBRASHADER_ABI_VERSION;
/// Function pointer definition for libra_abi_version
@ -674,7 +722,7 @@ typedef libra_error_t (*PFN_libra_vk_filter_chain_free)(
libra_vk_filter_chain_t *chain);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_create
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_create)(
@ -683,7 +731,7 @@ typedef libra_error_t (*PFN_libra_d3d11_filter_chain_create)(
libra_d3d11_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_create_deferred
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_create_deferred)(
@ -693,7 +741,7 @@ typedef libra_error_t (*PFN_libra_d3d11_filter_chain_create_deferred)(
libra_d3d11_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_frame
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_frame)(
@ -703,42 +751,42 @@ typedef libra_error_t (*PFN_libra_d3d11_filter_chain_frame)(
const float *mvp, const struct frame_d3d11_opt_t *options);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_set_param
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_set_param)(
libra_d3d11_filter_chain_t *chain, const char *param_name, float value);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_get_param
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_get_param)(
libra_d3d11_filter_chain_t *chain, const char *param_name, float *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_set_active_pass_count
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_set_active_pass_count)(
libra_d3d11_filter_chain_t *chain, uint32_t value);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_get_active_pass_count
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_get_active_pass_count)(
libra_d3d11_filter_chain_t *chain, uint32_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Function pointer definition for
/// libra_d3d11_filter_chain_free
typedef libra_error_t (*PFN_libra_d3d11_filter_chain_free)(
libra_d3d11_filter_chain_t *chain);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_create
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_create)(
@ -747,7 +795,7 @@ typedef libra_error_t (*PFN_libra_d3d12_filter_chain_create)(
libra_d3d12_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_create_deferred
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_create_deferred)(
@ -757,7 +805,7 @@ typedef libra_error_t (*PFN_libra_d3d12_filter_chain_create_deferred)(
libra_d3d12_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_frame
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_frame)(
@ -767,41 +815,104 @@ typedef libra_error_t (*PFN_libra_d3d12_filter_chain_frame)(
const float *mvp, const struct frame_d3d12_opt_t *options);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_set_param
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_set_param)(
libra_d3d12_filter_chain_t *chain, const char *param_name, float value);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_get_param
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_get_param)(
libra_d3d12_filter_chain_t *chain, const char *param_name, float *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_set_active_pass_count
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_set_active_pass_count)(
libra_d3d12_filter_chain_t *chain, uint32_t value);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_get_active_pass_count
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_get_active_pass_count)(
libra_d3d12_filter_chain_t *chain, uint32_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Function pointer definition for
/// libra_d3d12_filter_chain_free
typedef libra_error_t (*PFN_libra_d3d12_filter_chain_free)(
libra_d3d12_filter_chain_t *chain);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_create
typedef libra_error_t (*PFN_libra_mtl_filter_chain_create)(
libra_shader_preset_t *preset, id<MTLCommandQueue> queue,
const struct filter_chain_mtl_opt_t *options,
libra_mtl_filter_chain_t *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_create_deferred
typedef libra_error_t (*PFN_libra_mtl_filter_chain_create_deferred)(
libra_shader_preset_t *preset, id<MTLCommandQueue> queue,
id<MTLCommandBuffer> command_buffer,
const struct filter_chain_mtl_opt_t *options,
libra_mtl_filter_chain_t *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_frame
typedef libra_error_t (*PFN_libra_mtl_filter_chain_frame)(
libra_mtl_filter_chain_t *chain, id<MTLCommandBuffer> command_buffer,
size_t frame_count, id<MTLTexture> image, struct libra_viewport_t viewport,
id<MTLTexture> output, const float *mvp, const struct frame_mtl_opt_t *opt);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_set_param
typedef libra_error_t (*PFN_libra_mtl_filter_chain_set_param)(
libra_mtl_filter_chain_t *chain, const char *param_name, float value);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_get_param
typedef libra_error_t (*PFN_libra_mtl_filter_chain_get_param)(
libra_mtl_filter_chain_t *chain, const char *param_name, float *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_set_active_pass_count
typedef libra_error_t (*PFN_libra_mtl_filter_chain_set_active_pass_count)(
libra_mtl_filter_chain_t *chain, uint32_t value);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_get_active_pass_count
typedef libra_error_t (*PFN_libra_mtl_filter_chain_get_active_pass_count)(
libra_mtl_filter_chain_t *chain, uint32_t *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Function pointer definition for
/// libra_mtl_filter_chain_free
typedef libra_error_t (*PFN_libra_mtl_filter_chain_free)(
libra_mtl_filter_chain_t *chain);
#endif
/// The current version of the librashader API.
/// Pass this into `version` for config structs.
///
@ -811,7 +922,11 @@ typedef libra_error_t (*PFN_libra_d3d12_filter_chain_free)(
/// versions must remain backwards compatible.
/// ## API Versions
/// - API version 0: 0.1.0
#define LIBRASHADER_CURRENT_VERSION 0
/// - API version 1: 0.2.0
/// - Added rotation, total_subframes, current_subframes to frame options
/// - Added preset context API
/// - Added Metal runtime API
#define LIBRASHADER_CURRENT_VERSION 1
/// The current version of the librashader ABI.
/// Used by the loader to check ABI compatibility.
@ -1106,8 +1221,7 @@ libra_error_t libra_gl_filter_chain_free(libra_gl_filter_chain_t *chain);
/// ## Safety:
/// - The handles provided in `vulkan` must be valid for the command buffers
/// that
/// `libra_vk_filter_chain_frame` will write to. Namely, the VkDevice must
/// have been
/// `libra_vk_filter_chain_frame` will write to.
/// created with the `VK_KHR_dynamic_rendering` extension.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
@ -1128,9 +1242,7 @@ libra_error_t libra_vk_filter_chain_create(
/// ## Safety:
/// - The handles provided in `vulkan` must be valid for the command buffers
/// that
/// `libra_vk_filter_chain_frame` will write to. Namely, the VkDevice must
/// have been
/// created with the `VK_KHR_dynamic_rendering` extension.
/// `libra_vk_filter_chain_frame` will write to.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
@ -1235,7 +1347,7 @@ libra_error_t libra_vk_filter_chain_get_active_pass_count(
libra_error_t libra_vk_filter_chain_free(libra_vk_filter_chain_t *chain);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Create the filter chain given the shader preset.
///
/// The shader preset is immediately invalidated and must be recreated after
@ -1252,7 +1364,7 @@ libra_error_t libra_d3d11_filter_chain_create(
libra_d3d11_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Create the filter chain given the shader preset, deferring and GPU-side
/// initialization to the caller. This function is therefore requires no
/// external synchronization of the immediate context, as long as the immediate
@ -1289,7 +1401,7 @@ libra_error_t libra_d3d11_filter_chain_create_deferred(
libra_d3d11_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Draw a frame with the given parameters for the given filter chain.
///
/// If `device_context` is null, then commands are recorded onto the immediate
@ -1323,7 +1435,7 @@ libra_error_t libra_d3d11_filter_chain_frame(
const float *mvp, const struct frame_d3d11_opt_t *options);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Sets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
@ -1335,7 +1447,7 @@ libra_error_t libra_d3d11_filter_chain_set_param(
libra_d3d11_filter_chain_t *chain, const char *param_name, float value);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Gets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
@ -1347,7 +1459,7 @@ libra_error_t libra_d3d11_filter_chain_get_param(
libra_d3d11_filter_chain_t *chain, const char *param_name, float *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Sets the number of active passes for this chain.
///
/// ## Safety
@ -1357,7 +1469,7 @@ libra_error_t libra_d3d11_filter_chain_set_active_pass_count(
libra_d3d11_filter_chain_t *chain, uint32_t value);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Gets the number of active passes for this chain.
///
/// ## Safety
@ -1367,7 +1479,7 @@ libra_error_t libra_d3d11_filter_chain_get_active_pass_count(
libra_d3d11_filter_chain_t *chain, uint32_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D11)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D11))
/// Free a D3D11 filter chain.
///
/// The resulting value in `chain` then becomes null.
@ -1377,7 +1489,7 @@ libra_error_t libra_d3d11_filter_chain_get_active_pass_count(
libra_error_t libra_d3d11_filter_chain_free(libra_d3d11_filter_chain_t *chain);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Create the filter chain given the shader preset.
///
/// The shader preset is immediately invalidated and must be recreated after
@ -1394,7 +1506,7 @@ libra_error_t libra_d3d12_filter_chain_create(
libra_d3d12_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Create the filter chain given the shader preset deferring and GPU-side
/// initialization to the caller. This function therefore requires no external
/// synchronization of the device queue.
@ -1420,7 +1532,7 @@ libra_error_t libra_d3d12_filter_chain_create_deferred(
libra_d3d12_filter_chain_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Records rendering commands for a frame with the given parameters for the
/// given filter chain to the input command list.
///
@ -1460,7 +1572,7 @@ libra_error_t libra_d3d12_filter_chain_frame(
const float *mvp, const struct frame_d3d12_opt_t *options);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Sets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
@ -1472,7 +1584,7 @@ libra_error_t libra_d3d12_filter_chain_set_param(
libra_d3d12_filter_chain_t *chain, const char *param_name, float value);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Gets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
@ -1484,7 +1596,7 @@ libra_error_t libra_d3d12_filter_chain_get_param(
libra_d3d12_filter_chain_t *chain, const char *param_name, float *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Sets the number of active passes for this chain.
///
/// ## Safety
@ -1494,7 +1606,7 @@ libra_error_t libra_d3d12_filter_chain_set_active_pass_count(
libra_d3d12_filter_chain_t *chain, uint32_t value);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Gets the number of active passes for this chain.
///
/// ## Safety
@ -1504,7 +1616,7 @@ libra_error_t libra_d3d12_filter_chain_get_active_pass_count(
libra_d3d12_filter_chain_t *chain, uint32_t *out);
#endif
#if defined(LIBRA_RUNTIME_D3D12)
#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12))
/// Free a D3D12 filter chain.
///
/// The resulting value in `chain` then becomes null.
@ -1514,6 +1626,135 @@ libra_error_t libra_d3d12_filter_chain_get_active_pass_count(
libra_error_t libra_d3d12_filter_chain_free(libra_d3d12_filter_chain_t *chain);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Create the filter chain given the shader preset.
///
/// The shader preset is immediately invalidated and must be recreated after
/// the filter chain is created.
///
/// ## Safety:
/// - `queue` must be valid for the command buffers
/// that `libra_mtl_filter_chain_frame` will write to.
/// - `queue` must be a reference to a `id<MTLCommandQueue>`.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
libra_error_t libra_mtl_filter_chain_create(
libra_shader_preset_t *preset, id<MTLCommandQueue> queue,
const struct filter_chain_mtl_opt_t *options,
libra_mtl_filter_chain_t *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Create the filter chain given the shader preset deferring and GPU-side
/// initialization to the caller. This function therefore requires no external
/// synchronization of the device queue.
///
/// The shader preset is immediately invalidated and must be recreated after
/// the filter chain is created.
///
/// ## Safety:
/// - `queue` must be valid for the command buffers
/// that `libra_mtl_filter_chain_frame` will write to.
/// - `queue` must be a reference to a `id<MTLCommandQueue>`.
/// - `command_buffer` must be a valid reference to a `MTLCommandBuffer` that is
/// not already encoding.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
///
/// The provided command buffer must be ready for recording and contain no prior
/// commands. The caller is responsible for ending the command buffer and
/// immediately submitting it to a graphics queue. The command buffer must be
/// completely executed before calling `libra_mtl_filter_chain_frame`.
libra_error_t libra_mtl_filter_chain_create_deferred(
libra_shader_preset_t *preset, id<MTLCommandQueue> queue,
id<MTLCommandBuffer> command_buffer,
const struct filter_chain_mtl_opt_t *options,
libra_mtl_filter_chain_t *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Records rendering commands for a frame with the given parameters for the
/// given filter chain to the input command buffer.
///
/// ## Safety
/// - `command_buffer` must be a valid reference to a `MTLCommandBuffer` that is
/// not already encoding.
/// - `chain` may be null, invalid, but not uninitialized. If `chain` is null or
/// invalid, this
/// function will return an error.
/// - `mvp` may be null, or if it is not null, must be an aligned pointer to 16
/// consecutive `float`
/// 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_mtl_opt_t`
/// struct.
/// - You must ensure that only one thread has access to `chain` before you call
/// this function. Only one
/// thread at a time may call this function.
libra_error_t libra_mtl_filter_chain_frame(
libra_mtl_filter_chain_t *chain, id<MTLCommandBuffer> command_buffer,
size_t frame_count, id<MTLTexture> image, struct libra_viewport_t viewport,
id<MTLTexture> output, const float *mvp, const struct frame_mtl_opt_t *opt);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Sets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
/// - `param_name` must be either null or a null terminated string.
libra_error_t libra_mtl_filter_chain_set_param(libra_mtl_filter_chain_t *chain,
const char *param_name,
float value);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Gets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
/// - `param_name` must be either null or a null terminated string.
libra_error_t libra_mtl_filter_chain_get_param(libra_mtl_filter_chain_t *chain,
const char *param_name,
float *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Sets the number of active passes for this chain.
///
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
libra_error_t libra_mtl_filter_chain_set_active_pass_count(
libra_mtl_filter_chain_t *chain, uint32_t value);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Gets the number of active passes for this chain.
///
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
libra_error_t libra_mtl_filter_chain_get_active_pass_count(
libra_mtl_filter_chain_t *chain, uint32_t *out);
#endif
#if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__))
/// Free a Vulkan filter chain.
///
/// The resulting value in `chain` then becomes null.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
libra_error_t libra_mtl_filter_chain_free(libra_mtl_filter_chain_t *chain);
#endif
/// Get the ABI version of the loaded instance.
LIBRASHADER_ABI_VERSION libra_instance_abi_version(void);

View file

@ -37,6 +37,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// #define LIBRA_RUNTIME_D3D12
// #endif
// #if (defined(__APPLE__) && defined(__OBJC__))
// #define LIBRA_RUNTIME_METAL
// #endif
#if defined(_WIN32)
#include <windows.h>
#define _LIBRASHADER_ASSIGN(HMOD, INSTANCE, NAME) \
@ -388,6 +392,59 @@ libra_error_t __librashader__noop_d3d12_filter_chain_get_active_pass_count(
return NULL;
}
#endif
#if defined(LIBRA_RUNTIME_METAL)
libra_error_t __librashader__noop_mtl_filter_chain_create(
libra_shader_preset_t *preset, id<MTLCommandQueue> queue,
const struct filter_chain_mtl_opt_t *options,
libra_mtl_filter_chain_t *out) {
*out = NULL;
return NULL;
}
libra_error_t __librashader__noop_mtl_filter_chain_create_deferred(
libra_shader_preset_t *preset, id<MTLCommandQueue> queue,
id<MTLCommandBuffer> command_buffer,
const struct filter_chain_mtl_opt_t *options,
libra_mtl_filter_chain_t *out) {
*out = NULL;
return NULL;
}
libra_error_t __librashader__noop_mtl_filter_chain_frame(
libra_mtl_filter_chain_t *chain, id<MTLCommandBuffer> command_buffer,
size_t frame_count, id<MTLTexture> image, struct libra_viewport_t viewport,
id<MTLTexture> output, const float *mvp,
const struct frame_mtl_opt_t *opt) {
return NULL;
}
libra_error_t __librashader__mtl_filter_chain_free(
libra_mtl_filter_chain_t *chain) {
return NULL;
}
libra_error_t __librashader__noop_mtl_filter_chain_set_param(
libra_mtl_filter_chain_t *chain, const char *param_name, float value) {
return NULL;
}
libra_error_t __librashader__noop_mtl_filter_chain_get_param(
libra_mtl_filter_chain_t *chain, const char *param_name, float *out) {
return NULL;
}
libra_error_t __librashader__noop_mtl_filter_chain_set_active_pass_count(
libra_mtl_filter_chain_t *chain, uint32_t value) {
return NULL;
}
libra_error_t __librashader__noop_mtl_filter_chain_get_active_pass_count(
libra_mtl_filter_chain_t *chain, uint32_t *out) {
return NULL;
}
#endif
typedef struct libra_instance_t {
/// Get the supported ABI version of the loaded instance.
///
@ -1106,6 +1163,104 @@ typedef struct libra_instance_t {
PFN_libra_d3d12_filter_chain_set_param d3d12_filter_chain_set_param;
#endif
#if defined(LIBRA_RUNTIME_METAL)
/// Create the filter chain given the shader preset.
///
/// The shader preset is immediately invalidated and must be recreated after
/// the filter chain is created.
///
/// If this function is not loaded, `out` will unconditionally be set to
/// null. If this function returns an error, the state of `out` is
/// unspecified.
///
/// ## Safety:
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
PFN_libra_mtl_filter_chain_create mtl_filter_chain_create;
/// Create the filter chain given the shader preset deferring and GPU-side
/// initialization
/// to the caller. This function therefore requires no external
/// synchronization of the device queue.
///
/// The shader preset is immediately invalidated and must be recreated after
/// the filter chain is created.
///
/// If this function is not loaded, `out` will unconditionally be set to
/// null. If this function returns an error, the state of `out` is
/// unspecified.
///
/// ## 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.
/// - `cmd` must not be null.
///
/// The provided command list must be ready for recording and contain no
/// prior commands. The caller is responsible for ending the command list
/// and immediately submitting it to a graphics queue. The command list must
/// be completely executed before calling `libra_mtl_filter_chain_frame`
PFN_libra_mtl_filter_chain_create_deferred mtl_filter_chain_create_deferred;
/// Draw a frame with the given parameters for the given filter chain.
///
/// ## Safety
/// - `chain` may be null, invalid, but not uninitialized. If `chain` is
/// null or invalid, this
/// function will return an error.
/// - `mvp` may be null, or if it is not null, must be an aligned pointer to
/// 16 consecutive `float`
/// 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_mtl_opt_t`
/// struct.
PFN_libra_mtl_filter_chain_frame mtl_filter_chain_frame;
/// Free a D3D11 filter chain.
///
/// The resulting value in `chain` then becomes null.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
PFN_libra_mtl_filter_chain_free mtl_filter_chain_free;
/// Gets the number of active passes for this chain.
///
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
PFN_libra_mtl_filter_chain_get_active_pass_count
mtl_filter_chain_get_active_pass_count;
/// Sets the number of active passes for this chain.
///
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
PFN_libra_mtl_filter_chain_set_active_pass_count
mtl_filter_chain_set_active_pass_count;
/// Gets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
/// - `param_name` must be either null or a null terminated string.
PFN_libra_mtl_filter_chain_get_param mtl_filter_chain_get_param;
/// Sets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an
/// initialized `libra_mtl_filter_chain_t`.
/// - `param_name` must be either null or a null terminated string.
PFN_libra_mtl_filter_chain_set_param mtl_filter_chain_set_param;
#endif
/// Helper flag for if the librashader instance was loaded.
///
/// This flag is not indicative of whether any functions were loaded
@ -1237,6 +1392,22 @@ libra_instance_t __librashader_make_null_instance() {
.d3d12_filter_chain_set_param =
__librashader__noop_d3d12_filter_chain_set_param,
#endif
#if defined(LIBRA_RUNTIME_METAL)
.mtl_filter_chain_create = __librashader__noop_mtl_filter_chain_create,
.mtl_filter_chain_create_deferred =
__librashader__noop_mtl_filter_chain_create_deferred,
.mtl_filter_chain_frame = __librashader__noop_mtl_filter_chain_frame,
.mtl_filter_chain_free = __librashader__noop_mtl_filter_chain_free,
.mtl_filter_chain_get_active_pass_count =
__librashader__noop_mtl_filter_chain_get_active_pass_count,
.mtl_filter_chain_set_active_pass_count =
__librashader__noop_mtl_filter_chain_set_active_pass_count,
.mtl_filter_chain_get_param =
__librashader__noop_mtl_filter_chain_get_param,
.mtl_filter_chain_set_param =
__librashader__noop_mtl_filter_chain_set_param,
#endif
.instance_loaded = false,
};
}
@ -1358,6 +1529,20 @@ libra_instance_t librashader_load_instance() {
_LIBRASHADER_ASSIGN(librashader, instance,
d3d12_filter_chain_set_active_pass_count);
#endif
#if defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL)
_LIBRASHADER_ASSIGN(librashader, instance, mtl_filter_chain_create);
_LIBRASHADER_ASSIGN(librashader, instance,
mtl_filter_chain_create_deferred);
_LIBRASHADER_ASSIGN(librashader, instance, mtl_filter_chain_frame);
_LIBRASHADER_ASSIGN(librashader, instance, mtl_filter_chain_free);
_LIBRASHADER_ASSIGN(librashader, instance, mtl_filter_chain_get_param);
_LIBRASHADER_ASSIGN(librashader, instance, mtl_filter_chain_set_param);
_LIBRASHADER_ASSIGN(librashader, instance,
mtl_filter_chain_get_active_pass_count);
_LIBRASHADER_ASSIGN(librashader, instance,
mtl_filter_chain_set_active_pass_count);
#endif
instance.instance_loaded = true;
return instance;
}

View file

@ -2,7 +2,7 @@
name = "librashader-cache"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -12,13 +12,12 @@ description = "RetroArch shaders for all."
[dependencies]
serde = { version = "1.0" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9", features = ["serialize"] }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11", features = ["serialize"] }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
platform-dirs = "0.3.0"
blake3 = { version = "1.3.3" }
thiserror = "1.0.38"
bincode = { version = "2.0.0-rc.2", features = ["serde"] }
persy = "1.4.7"
bytemuck = "1.13.0"

View file

@ -3,7 +3,7 @@ name = "librashader-capi"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -16,15 +16,21 @@ crate-type = [ "cdylib", "staticlib" ]
[features]
default = ["runtime-all" ]
runtime-all = ["runtime-opengl", "runtime-d3d11", "runtime-d3d12", "runtime-vulkan"]
runtime-all = ["runtime-opengl", "runtime-d3d11", "runtime-d3d12", "runtime-vulkan", "runtime-metal"]
runtime-opengl = ["gl", "librashader/runtime-gl"]
runtime-d3d11 = ["windows", "librashader/runtime-d3d11", "windows/Win32_Graphics_Direct3D11"]
runtime-d3d12 = ["windows", "librashader/runtime-d3d12", "windows/Win32_Graphics_Direct3D12"]
runtime-vulkan = ["ash", "librashader/runtime-vk"]
runtime-metal = ["icrate", "objc2", "librashader/runtime-metal"]
runtime-metal = ["__cbindgen_internal_objc", "librashader/runtime-metal"]
__cbindgen_internal = ["runtime-all"]
# make runtime-metal depend on this, so its automatically implied.
# this will make cbindgen generate __OBJC__ ifdefs for metal functions.
__cbindgen_internal_objc = ["icrate", "objc2"]
[dependencies]
librashader = { path = "../librashader", version = "0.2.0-beta.9" }
librashader = { path = "../librashader", version = "0.2.0-beta.11" }
thiserror = "1.0.37"
paste = "1.0.9"
gl = { version = "0.14.0", optional = true }

View file

@ -34,28 +34,15 @@ 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 ID3D11DeviceContext;
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
#if defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)
#include <d3d12.h>
#else
typedef void ID3D12GraphicsCommandList;
typedef void ID3D12Device;
typedef void ID3D12Resource;
typedef void D3D12_CPU_DESCRIPTOR_HANDLE;
#endif
#if defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__)
#import <Metal/Metal.h>
#endif
#if defined(LIBRA_RUNTIME_VULKAN)
#include <vulkan\\vulkan.h>
#endif
"""
@ -64,12 +51,19 @@ typedef void D3D12_CPU_DESCRIPTOR_HANDLE;
"feature = runtime-vulkan" = "LIBRA_RUNTIME_VULKAN"
"feature = runtime-d3d11" = "LIBRA_RUNTIME_D3D11"
"feature = runtime-d3d12" = "LIBRA_RUNTIME_D3D12"
"feature = runtime-metal" = "LIBRA_RUNTIME_METAL"
"feature = __cbindgen_internal_objc" = "__OBJC__"
"target_os = windows" = "_WIN32"
"target_vendor = apple" = "__APPLE__"
[parse]
parse_deps = true
parse_deps = false
include = ["librashader"]
expand = ["librashader-capi"]
[parse.expand]
crates = ["librashader-capi"]
features = ["__cbindgen_internal"]
[struct]
@ -153,9 +147,24 @@ include = [
"PFN_libra_d3d12_filter_chain_set_active_pass_count",
"PFN_libra_d3d12_filter_chain_get_active_pass_count",
"PFN_libra_d3d12_filter_chain_free",
# metal
"PFN_libra_mtl_filter_chain_create",
"PFN_libra_mtl_filter_chain_create_deferred",
"PFN_libra_mtl_filter_chain_frame",
"PFN_libra_mtl_filter_chain_set_param",
"PFN_libra_mtl_filter_chain_get_param",
"PFN_libra_mtl_filter_chain_set_active_pass_count",
"PFN_libra_mtl_filter_chain_get_active_pass_count",
"PFN_libra_mtl_filter_chain_free",
]
exclude = ["Option_ID3D11DeviceContext"]
exclude = [
"Option_ID3D11DeviceContext",
"PMTLCommandQueue",
"PMTLCommandBuffer",
"PMTLTexture"
]
[export.rename]
"LibrashaderError" = "_libra_error"
@ -167,6 +176,7 @@ exclude = ["Option_ID3D11DeviceContext"]
"FilterChainVulkan" = "_filter_chain_vk"
"FilterChainD3D11" = "_filter_chain_d3d11"
"FilterChainD3D12" = "_filter_chain_d3d12"
"FilterChainMetal" = "_filter_chain_mtl"
# vulkan renames
"PhysicalDevice" = "VkPhysicalDevice"
@ -190,3 +200,7 @@ exclude = ["Option_ID3D11DeviceContext"]
"ID3D12Device" = "ID3D12Device *"
"ID3D12Resource" = "ID3D12Resource *"
"ID3D12GraphicsCommandList" = "ID3D12GraphicsCommandList *"
"PMTLCommandQueue" = "id<MTLCommandQueue>"
"PMTLCommandBuffer" = "id<MTLCommandBuffer>"
"PMTLTexture" = "id<MTLTexture>"

View file

@ -64,19 +64,18 @@ use librashader::runtime::gl::FilterChain as FilterChainGL;
pub type libra_gl_filter_chain_t = Option<NonNull<FilterChainGL>>;
/// A handle to a Direct3D 11 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
#[cfg(any(feature = "__cbindgen_internal", all(target_os = "windows", feature = "runtime-d3d11")))]
use librashader::runtime::d3d11::FilterChain as FilterChainD3D11;
/// A handle to a Direct3D 11 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d11")))]
#[cfg(any(feature = "__cbindgen_internal", all(target_os = "windows", feature = "runtime-d3d11")))]
pub type libra_d3d11_filter_chain_t = Option<NonNull<FilterChainD3D11>>;
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
#[cfg(any(feature = "__cbindgen_internal", all(target_os = "windows", feature = "runtime-d3d12")))]
use librashader::runtime::d3d12::FilterChain as FilterChainD3D12;
/// A handle to a Direct3D 12 filter chain.
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))]
#[cfg(any(feature = "__cbindgen_internal", all(target_os = "windows", feature = "runtime-d3d12")))]
pub type libra_d3d12_filter_chain_t = Option<NonNull<FilterChainD3D12>>;
#[cfg(feature = "runtime-vulkan")]
@ -86,6 +85,12 @@ use librashader::runtime::vk::FilterChain as FilterChainVulkan;
#[doc(cfg(feature = "runtime-vulkan"))]
pub type libra_vk_filter_chain_t = Option<NonNull<FilterChainVulkan>>;
#[cfg(all(target_os = "macos", feature = "runtime-metal"))]
use librashader::runtime::mtl::FilterChain as FilterChainMetal;
#[doc(cfg(all(target_vendor = "apple", feature = "runtime-metal")))]
#[cfg(any(feature = "__cbindgen_internal", all(target_vendor = "apple", feature = "runtime-metal", feature = "__cbindgen_internal_objc")))]
pub type libra_mtl_filter_chain_t = Option<NonNull<FilterChainMetal>>;
/// Defines the output viewport for a rendered frame.
#[repr(C)]
pub struct libra_viewport_t {
@ -170,5 +175,7 @@ mod __cbindgen_opaque_forward_declarations {
FilterChainD3D12;
/// Opaque struct for a Vulkan filter chain.
FilterChainVulkan;
/// Opaque struct for a Metal filter chain.
FilterChainMetal;
}
}

View file

@ -41,6 +41,10 @@ pub enum LibrashaderError {
#[doc(cfg(feature = "runtime-vulkan"))]
#[error("There was an error in the Vulkan filter chain.")]
VulkanFilterError(#[from] librashader::runtime::vk::error::FilterChainError),
#[doc(cfg(all(target_vendor = "apple", feature = "runtime-metal")))]
#[cfg(all(target_vendor = "apple", feature = "runtime-metal"))]
#[error("There was an error in the D3D12 filter chain.")]
MetalFilterError(#[from] librashader::runtime::mtl::error::FilterChainError),
}
/// Error codes for librashader error types.
@ -187,6 +191,8 @@ impl LibrashaderError {
LibrashaderError::D3D12FilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
#[cfg(feature = "runtime-vulkan")]
LibrashaderError::VulkanFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
#[cfg(all(target_vendor = "apple", feature = "runtime-metal"))]
LibrashaderError::MetalFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR
}
}
pub(crate) const fn ok() -> libra_error_t {

View file

@ -77,7 +77,7 @@ pub struct frame_d3d11_opt_t {
pub rotation: u32,
/// The total number of subframes ran. Default is 1.
pub total_subframes: u32,
// The current sub frame. Default is 1.
/// The current sub frame. Default is 1.
pub current_subframe: u32,
}

View file

@ -58,7 +58,7 @@ pub struct frame_d3d12_opt_t {
pub rotation: u32,
/// The total number of subframes ran. Default is 1.
pub total_subframes: u32,
// The current sub frame. Default is 1.
/// The current sub frame. Default is 1.
pub current_subframe: u32,
}

View file

@ -68,7 +68,7 @@ pub struct frame_gl_opt_t {
pub rotation: u32,
/// The total number of subframes ran. Default is 1.
pub total_subframes: u32,
// The current sub frame. Default is 1.
/// The current sub frame. Default is 1.
pub current_subframe: u32,
}

View file

@ -8,9 +8,13 @@ pub mod gl;
pub mod vk;
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d11")))]
#[cfg(all(target_os = "windows", feature = "runtime-d3d11"))]
#[cfg(any(feature = "__cbindgen_internal", all(target_os = "windows", feature = "runtime-d3d11")))]
pub mod d3d11;
#[doc(cfg(all(target_os = "windows", feature = "runtime-d3d12")))]
#[cfg(all(target_os = "windows", feature = "runtime-d3d12"))]
#[cfg(any(feature = "__cbindgen_internal", all(target_os = "windows", feature = "runtime-d3d12")))]
pub mod d3d12;
#[doc(cfg(all(target_vendor = "apple", feature = "runtime-metal")))]
#[cfg(any(feature = "__cbindgen_internal", all(target_vendor = "apple", feature = "runtime-metal", feature = "__cbindgen_internal_objc")))]
pub mod mtl;

View file

@ -0,0 +1,319 @@
use crate::ctypes::{
config_struct, libra_shader_preset_t, libra_viewport_t, libra_mtl_filter_chain_t, FromUninit,
};
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::extern_fn;
use librashader::runtime::mtl::{
FilterChain, FilterChainOptions, FrameOptions,
};
use std::ffi::CStr;
use std::ffi::{c_char};
use std::mem::MaybeUninit;
use std::ptr::NonNull;
use std::slice;
use librashader::runtime::FilterChainParameters;
use librashader::runtime::{Size, Viewport};
use icrate::Metal::{MTLCommandBuffer, MTLCommandQueue, MTLTexture};
use objc2::runtime::ProtocolObject;
use crate::LIBRASHADER_API_VERSION;
pub type PMTLCommandQueue = *const ProtocolObject<dyn MTLCommandQueue>;
pub type PMTLCommandBuffer = *const ProtocolObject<dyn MTLCommandBuffer>;
pub type PMTLTexture = *const ProtocolObject<dyn MTLTexture>;
/// Options for each Vulkan shader frame.
#[repr(C)]
#[derive(Default, Debug, Clone)]
pub struct frame_mtl_opt_t {
/// The librashader API version.
pub version: LIBRASHADER_API_VERSION,
/// Whether or not to clear the history buffers.
pub clear_history: bool,
/// The direction of rendering.
/// -1 indicates that the frames are played in reverse order.
pub frame_direction: i32,
/// The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 4 = 270deg.
pub rotation: u32,
/// The total number of subframes ran. Default is 1.
pub total_subframes: u32,
/// The current sub frame. Default is 1.
pub current_subframe: u32,
}
config_struct! {
impl FrameOptions => frame_mtl_opt_t {
0 => [clear_history, frame_direction];
1 => [rotation, total_subframes, current_subframe]
}
}
/// Options for filter chain creation.
#[repr(C)]
#[derive(Default, Debug, Clone)]
pub struct filter_chain_mtl_opt_t {
/// The librashader API version.
pub version: LIBRASHADER_API_VERSION,
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
pub force_no_mipmaps: bool,
}
config_struct! {
impl FilterChainOptions => filter_chain_mtl_opt_t {
0 => [force_no_mipmaps];
}
}
extern_fn! {
/// Create the filter chain given the shader preset.
///
/// The shader preset is immediately invalidated and must be recreated after
/// the filter chain is created.
///
/// ## Safety:
/// - `queue` must be valid for the command buffers
/// that `libra_mtl_filter_chain_frame` will write to.
/// - `queue` must be a reference to a `id<MTLCommandQueue>`.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
fn libra_mtl_filter_chain_create(
preset: *mut libra_shader_preset_t,
queue: PMTLCommandQueue,
options: *const MaybeUninit<filter_chain_mtl_opt_t>,
out: *mut MaybeUninit<libra_mtl_filter_chain_t>
) |queue| {
assert_non_null!(preset);
let preset = unsafe {
let preset_ptr = &mut *preset;
let preset = preset_ptr.take();
Box::from_raw(preset.unwrap().as_ptr())
};
let options = if options.is_null() {
None
} else {
Some(unsafe { options.read() })
};
let queue = queue.as_ref();
let options = options.map(FromUninit::from_uninit);
unsafe {
let chain = FilterChain::load_from_preset(*preset, queue, options.as_ref())?;
out.write(MaybeUninit::new(NonNull::new(Box::into_raw(Box::new(
chain,
)))))
}
}
}
extern_fn! {
/// Create the filter chain given the shader preset deferring and GPU-side initialization
/// to the caller. This function therefore requires no external synchronization of the device queue.
///
/// The shader preset is immediately invalidated and must be recreated after
/// the filter chain is created.
///
/// ## Safety:
/// - `queue` must be valid for the command buffers
/// that `libra_mtl_filter_chain_frame` will write to.
/// - `queue` must be a reference to a `id<MTLCommandQueue>`.
/// - `command_buffer` must be a valid reference to a `MTLCommandBuffer` that is not already encoding.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
/// - `out` must be aligned, but may be null, invalid, or uninitialized.
///
/// The provided command buffer must be ready for recording and contain no prior commands.
/// The caller is responsible for ending the command buffer and immediately submitting it to a
/// graphics queue. The command buffer must be completely executed before calling `libra_mtl_filter_chain_frame`.
fn libra_mtl_filter_chain_create_deferred(
preset: *mut libra_shader_preset_t,
queue: PMTLCommandQueue,
command_buffer: PMTLCommandBuffer,
options: *const MaybeUninit<filter_chain_mtl_opt_t>,
out: *mut MaybeUninit<libra_mtl_filter_chain_t>
) |queue, command_buffer| {
assert_non_null!(preset);
let preset = unsafe {
let preset_ptr = &mut *preset;
let preset = preset_ptr.take();
Box::from_raw(preset.unwrap().as_ptr())
};
let options = if options.is_null() {
None
} else {
Some(unsafe { options.read() })
};
let options = options.map(FromUninit::from_uninit);
unsafe {
let chain = FilterChain::load_from_preset_deferred(*preset,
queue,
command_buffer,
options.as_ref())?;
out.write(MaybeUninit::new(NonNull::new(Box::into_raw(Box::new(
chain,
)))))
}
}
}
extern_fn! {
/// Records rendering commands for a frame with the given parameters for the given filter chain
/// to the input command buffer.
///
/// ## Safety
/// - `command_buffer` must be a valid reference to a `MTLCommandBuffer` that is not already encoding.
/// - `chain` may be null, invalid, but not uninitialized. If `chain` is null or invalid, this
/// function will return an error.
/// - `mvp` may be null, or if it is not null, must be an aligned pointer to 16 consecutive `float`
/// 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_mtl_opt_t`
/// struct.
/// - You must ensure that only one thread has access to `chain` before you call this function. Only one
/// thread at a time may call this function.
nopanic fn libra_mtl_filter_chain_frame(
chain: *mut libra_mtl_filter_chain_t,
command_buffer: PMTLCommandBuffer,
frame_count: usize,
image: PMTLTexture,
viewport: libra_viewport_t,
output: PMTLTexture,
mvp: *const f32,
opt: *const MaybeUninit<frame_mtl_opt_t>
) |command_buffer, image, output|; mut |chain| {
assert_some_ptr!(mut chain);
let mvp = if mvp.is_null() {
None
} else {
Some(<&[f32; 16]>::try_from(unsafe { slice::from_raw_parts(mvp, 16) }).unwrap())
};
let opt = if opt.is_null() {
None
} else {
Some(unsafe { opt.read() })
};
let opt = opt.map(FromUninit::from_uninit);
let viewport = Viewport {
x: viewport.x,
y: viewport.y,
output,
mvp,
};
chain.frame(&image, &viewport, command_buffer, frame_count, opt.as_ref())?;
}
}
extern_fn! {
/// Sets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an initialized `libra_mtl_filter_chain_t`.
/// - `param_name` must be either null or a null terminated string.
fn libra_mtl_filter_chain_set_param(
chain: *mut libra_mtl_filter_chain_t,
param_name: *const c_char,
value: f32
) mut |chain| {
assert_some_ptr!(mut chain);
unsafe {
let name = CStr::from_ptr(param_name);
let name = name.to_str()?;
if chain.set_parameter(name, value).is_none() {
return LibrashaderError::UnknownShaderParameter(param_name).export()
}
}
}
}
extern_fn! {
/// Gets a parameter for the filter chain.
///
/// If the parameter does not exist, returns an error.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an initialized `libra_mtl_filter_chain_t`.
/// - `param_name` must be either null or a null terminated string.
fn libra_mtl_filter_chain_get_param(
chain: *mut libra_mtl_filter_chain_t,
param_name: *const c_char,
out: *mut MaybeUninit<f32>
) mut |chain| {
assert_some_ptr!(mut chain);
unsafe {
let name = CStr::from_ptr(param_name);
let name = name.to_str()?;
let Some(value) = chain.get_parameter(name) else {
return LibrashaderError::UnknownShaderParameter(param_name).export()
};
out.write(MaybeUninit::new(value));
}
}
}
extern_fn! {
/// Sets the number of active passes for this chain.
///
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an initialized `libra_mtl_filter_chain_t`.
fn libra_mtl_filter_chain_set_active_pass_count(
chain: *mut libra_mtl_filter_chain_t,
value: u32
) mut |chain| {
assert_some_ptr!(mut chain);
chain.set_enabled_pass_count(value as usize);
}
}
extern_fn! {
/// Gets the number of active passes for this chain.
///
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an initialized `libra_mtl_filter_chain_t`.
fn libra_mtl_filter_chain_get_active_pass_count(
chain: *mut libra_mtl_filter_chain_t,
out: *mut MaybeUninit<u32>
) mut |chain| {
assert_some_ptr!(mut chain);
let value = chain.get_enabled_pass_count();
unsafe {
out.write(MaybeUninit::new(value as u32))
}
}
}
extern_fn! {
/// Free a Vulkan filter chain.
///
/// The resulting value in `chain` then becomes null.
/// ## Safety
/// - `chain` must be either null or a valid and aligned pointer to an initialized `libra_mtl_filter_chain_t`.
fn libra_mtl_filter_chain_free(
chain: *mut libra_mtl_filter_chain_t
) {
assert_non_null!(chain);
unsafe {
let chain_ptr = &mut *chain;
let chain = chain_ptr.take();
drop(Box::from_raw(chain.unwrap().as_ptr()))
};
}
}

View file

@ -0,0 +1,5 @@
//! C API for the librashader Metal Runtime (`libra_mtl_*`).
mod filter_chain;
pub use filter_chain::*;

View file

@ -98,7 +98,7 @@ pub struct frame_vk_opt_t {
pub rotation: u32,
/// The total number of subframes ran. Default is 1.
pub total_subframes: u32,
// The current sub frame. Default is 1.
/// The current sub frame. Default is 1.
pub current_subframe: u32,
}
@ -142,7 +142,7 @@ extern_fn! {
///
/// ## Safety:
/// - The handles provided in `vulkan` must be valid for the command buffers that
/// `libra_vk_filter_chain_frame` will write to. Namely, the VkDevice must have been
/// `libra_vk_filter_chain_frame` will write to.
/// created with the `VK_KHR_dynamic_rendering` extension.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
@ -188,8 +188,7 @@ extern_fn! {
///
/// ## Safety:
/// - The handles provided in `vulkan` must be valid for the command buffers that
/// `libra_vk_filter_chain_frame` will write to. Namely, the VkDevice must have been
/// created with the `VK_KHR_dynamic_rendering` extension.
/// `libra_vk_filter_chain_frame` will write to.
/// - `preset` must be either null, or valid and aligned.
/// - `options` must be either null, or valid and aligned.
/// - `out` must be aligned, but may be null, invalid, or uninitialized.

View file

@ -1,4 +1,4 @@
//! C API for the librashader OpenGL Runtime (`libra_vk_*`).
//! C API for the librashader Vulkan Runtime (`libra_vk_*`).
mod filter_chain;
pub use filter_chain::*;

View file

@ -3,7 +3,7 @@ name = "librashader-common"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -42,4 +42,4 @@ features = [
[target.'cfg(target_vendor="apple")'.dependencies.icrate]
optional = true
version = "0.1.0"
features = ["Metal", "Metal_all"]
features = ["Metal", "Metal_all"]

View file

@ -3,7 +3,7 @@ name = "librashader-preprocess"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -14,7 +14,7 @@ description = "RetroArch shaders for all."
[dependencies]
thiserror = "1.0.37"
nom = "7.1.1"
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.9" }
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.11" }
rustc-hash = "1.1.0"
encoding_rs = "0.8.31"

View file

@ -3,7 +3,7 @@ name = "librashader-presets"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -15,7 +15,7 @@ description = "RetroArch shaders for all."
thiserror = "1.0.37"
nom = "7.1.1"
nom_locate = "4.0.0"
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.9" }
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.11" }
num-traits = "0.2"
once_cell = "1"
# we don't need unicode

View file

@ -3,7 +3,7 @@ name = "librashader-reflect"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -19,9 +19,9 @@ thiserror = "1.0.37"
bitflags = "2.4.2"
rustc-hash = "1.1.0"
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
spirv_cross = { package = "librashader-spirv-cross", version = "0.25.1", optional = true }
@ -45,4 +45,4 @@ wgsl = ["cross", "naga/wgsl-out", "spirv", "rspirv"]
cross = [ "spirv_cross", "spirv_cross/glsl", "spirv_cross/hlsl", "spirv_cross/msl" ]
naga = [ "rspirv", "spirv", "naga/spv-in", "naga/spv-out", "naga/wgsl-out", "naga/msl-out" ]
serialize = [ "serde" ]
msl = [ "spirv_cross/msl", "naga/msl-out" ]
msl = [ "spirv_cross/msl", "naga/msl-out" ]

View file

@ -3,7 +3,7 @@ name = "librashader-runtime-d3d11"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -12,12 +12,12 @@ keywords = ["shader", "retroarch", "SPIR-V"]
description = "RetroArch shaders for all."
[dependencies]
librashader-common = { path = "../librashader-common", features = ["d3d11"], version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9" }
librashader-runtime = { path = "../librashader-runtime", version = "0.2.0-beta.9" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.9", features = ["d3d"] }
librashader-common = { path = "../librashader-common", features = ["d3d11"], version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11" }
librashader-runtime = { path = "../librashader-runtime", version = "0.2.0-beta.11" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.11", features = ["d3d"] }
thiserror = "1.0.37"
rustc-hash = "1.1.0"

View file

@ -3,7 +3,7 @@ name = "librashader-runtime-d3d12"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -12,12 +12,12 @@ keywords = ["shader", "retroarch", "SPIR-V"]
description = "RetroArch shaders for all."
[dependencies]
librashader-common = { path = "../librashader-common", features = ["d3d12"], version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9", features = ["dxil"] }
librashader-runtime = { path = "../librashader-runtime", version = "0.2.0-beta.9" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.9", features = ["d3d"] }
librashader-common = { path = "../librashader-common", features = ["d3d12"], version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11", features = ["dxil"] }
librashader-runtime = { path = "../librashader-runtime", version = "0.2.0-beta.11" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.11", features = ["d3d"] }
thiserror = "1.0.37"
parking_lot = "0.12.1"

View file

@ -3,7 +3,7 @@ name = "librashader-runtime-gl"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -12,12 +12,12 @@ keywords = ["shader", "retroarch", "SPIR-V"]
description = "RetroArch shaders for all."
[dependencies]
librashader-common = { path = "../librashader-common", features = ["opengl"], version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9" }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.9" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.9" }
librashader-common = { path = "../librashader-common", features = ["opengl"], version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11" }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.11" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.11" }
spirv_cross = { package = "librashader-spirv-cross", version = "0.25.1" }
rustc-hash = "1.1.0"

View file

@ -3,7 +3,7 @@ name = "librashader-runtime-mtl"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -14,11 +14,11 @@ description = "RetroArch shaders for all."
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
librashader-common = { path = "../librashader-common", features = ["metal"], version = "0.2.0-beta.7" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.7" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.7" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.7" }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.7" }
librashader-common = { path = "../librashader-common", features = ["metal"], version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11" }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.11" }
rustc-hash = "1.1.0"
@ -33,13 +33,14 @@ path = "tests/hello_triangle/main.rs"
harness = false
[package.metadata.docs.rs]
features = ["librashader-cache/docsrs"]
targets = ["x86_64-apple-darwin", "aarch64-apple-darwin", "aarch64-apple-ios"]
[target.'cfg(target_vendor="apple")'.dependencies]
icrate = { version = "0.1.0" , features = [ "Metal", "Metal_all" ]}
icrate = { version = "0.1.0" , features = [ "Metal", "Metal_all" ] }
objc2 = { version = "0.5.0", features = ["apple"] }
[features]
run_test = ["icrate/AppKit", "icrate/AppKit_all", "icrate/Foundation", "icrate/Foundation_all", "icrate/MetalKit", "icrate/MetalKit_all"]
#[lib]

View file

@ -7,7 +7,7 @@ use crate::graphics_pipeline::MetalGraphicsPipeline;
use crate::luts::LutTexture;
use crate::options::{FilterChainOptionsMetal, FrameOptionsMetal};
use crate::samplers::SamplerSet;
use crate::texture::{get_texture_size, InputTexture, MetalOutputView, OwnedTexture};
use crate::texture::{get_texture_size, InputTexture, MetalTextureRef, OwnedTexture};
use icrate::Foundation::NSString;
use icrate::Metal::{
MTLCommandBuffer, MTLCommandEncoder, MTLCommandQueue, MTLDevice, MTLLoadActionClear,
@ -326,7 +326,7 @@ impl FilterChainMetal {
pub fn frame(
&mut self,
input: &ProtocolObject<dyn MTLTexture>,
viewport: &Viewport<MetalOutputView>,
viewport: &Viewport<MetalTextureRef>,
cmd: &ProtocolObject<dyn MTLCommandBuffer>,
frame_count: usize,
options: Option<&FrameOptionsMetal>,
@ -369,8 +369,6 @@ impl FilterChainMetal {
return Ok(());
}
// let original_image_view = input.create_view(&wgpu::TextureViewDescriptor::default());
let filter = passes[0].config.filter;
let wrap_mode = passes[0].config.wrap_mode;

View file

@ -21,7 +21,7 @@ pub mod options;
use librashader_runtime::impl_filter_chain_parameters;
impl_filter_chain_parameters!(FilterChainMetal);
pub use texture::MetalOutputView;
pub use texture::MetalTextureRef;
fn select_optimal_pixel_format(format: MTLPixelFormat) -> MTLPixelFormat {
if format == MTLPixelFormatRGBA8Unorm {

View file

@ -4,7 +4,6 @@ use icrate::Metal::{MTLBlitCommandEncoder, MTLDevice, MTLOrigin, MTLPixelFormatB
use librashader_presets::TextureConfig;
use librashader_runtime::image::{Image, BGRA8};
use librashader_runtime::scaling::MipmapSize;
use objc2::rc::Id;
use objc2::runtime::ProtocolObject;
use std::ffi::c_void;
use std::ptr::NonNull;

View file

@ -8,7 +8,9 @@ use objc2::rc::Id;
use objc2::runtime::ProtocolObject;
pub type MetalTexture = Id<ProtocolObject<dyn MTLTexture>>;
pub type MetalOutputView<'a> = &'a ProtocolObject<dyn MTLTexture>;
/// Alias to an `id<MTLTexture>`.
pub type MetalTextureRef<'a> = &'a ProtocolObject<dyn MTLTexture>;
pub struct OwnedTexture {
pub(crate) texture: MetalTexture,

View file

@ -3,7 +3,7 @@ name = "librashader-runtime-vk"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -14,12 +14,12 @@ description = "RetroArch shaders for all."
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
librashader-common = { path = "../librashader-common", features = ["vulkan"], version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9" }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.9" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.9" }
librashader-common = { path = "../librashader-common", features = ["vulkan"], version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11" }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.11" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.11" }
rustc-hash = "1.1.0"
bytemuck = { version = "1.12.3", features = ["derive"] }

View file

@ -2,7 +2,7 @@
name = "librashader-runtime-wgpu"
edition = "2021"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
license = "MPL-2.0 OR GPL-3.0-only"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
@ -14,11 +14,11 @@ description = "RetroArch shaders for all."
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
librashader-common = { path = "../librashader-common", features = ["wgpu"], version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9", features = ["wgsl"], default-features = false }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.9" }
librashader-common = { path = "../librashader-common", features = ["wgpu"], version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11", features = ["wgsl"], default-features = false }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.0-beta.11" }
wgpu = { version = "0.19.0", features = ["spirv"] }
rustc-hash = "1.1.0"

View file

@ -3,7 +3,7 @@ name = "librashader-runtime"
edition = "2021"
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -12,10 +12,10 @@ keywords = ["shader", "retroarch", "SPIR-V"]
description = "RetroArch shaders for all."
[dependencies]
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9" }
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11" }
bytemuck = "1.12.3"
rustc-hash = "1.1.0"
num-traits = "0.2.15"

View file

@ -4,7 +4,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
license = "MPL-2.0 OR GPL-3.0-only"
version = "0.2.0-beta.9"
version = "0.2.0-beta.11"
authors = ["Ronny Chan <ronny@ronnychan.ca>"]
repository = "https://github.com/SnowflakePowered/librashader"
readme = "../README.md"
@ -13,19 +13,19 @@ keywords = ["shader", "retroarch", "SPIR-V"]
description = "RetroArch shaders for all."
[dependencies]
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.9" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.9" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.9" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.9" }
librashader-runtime = { path = "../librashader-runtime", version = "0.2.0-beta.9" }
librashader-runtime-d3d11 = { path = "../librashader-runtime-d3d11", version = "0.2.0-beta.9", optional = true }
librashader-runtime-d3d12 = { path = "../librashader-runtime-d3d12", version = "0.2.0-beta.9", optional = true }
librashader-runtime-gl = { path = "../librashader-runtime-gl", version = "0.2.0-beta.9", optional = true }
librashader-runtime-vk = { path = "../librashader-runtime-vk", version = "0.2.0-beta.9", optional = true }
librashader-runtime-wgpu = { path = "../librashader-runtime-wgpu", version = "0.2.0-beta.9", optional = true }
librashader-runtime-mtl = { path = "../librashader-runtime-mtl", version = "0.2.0-beta.9", optional = true }
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.11" }
librashader-presets = { path = "../librashader-presets", version = "0.2.0-beta.11" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.0-beta.11" }
librashader-reflect = { path = "../librashader-reflect", version = "0.2.0-beta.11" }
librashader-runtime = { path = "../librashader-runtime", version = "0.2.0-beta.11" }
librashader-runtime-d3d11 = { path = "../librashader-runtime-d3d11", version = "0.2.0-beta.11", optional = true }
librashader-runtime-d3d12 = { path = "../librashader-runtime-d3d12", version = "0.2.0-beta.11", optional = true }
librashader-runtime-gl = { path = "../librashader-runtime-gl", version = "0.2.0-beta.11", optional = true }
librashader-runtime-vk = { path = "../librashader-runtime-vk", version = "0.2.0-beta.11", optional = true }
librashader-runtime-wgpu = { path = "../librashader-runtime-wgpu", version = "0.2.0-beta.11", optional = true }
librashader-runtime-mtl = { path = "../librashader-runtime-mtl", version = "0.2.0-beta.11", optional = true }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.9" }
librashader-cache = { path = "../librashader-cache", version = "0.2.0-beta.11" }
ash = { version = "0.37", optional = true }
wgpu = { version = "0.19", optional = true }
@ -70,8 +70,8 @@ internal = []
full = ["runtime-all", "reflect-all", "preprocess", "presets"]
# cache hack
docsrs = ["librashader-cache/docsrs"]
docsrs = ["librashader-cache/docsrs", "objc2/unstable-docsrs"]
[package.metadata.docs.rs]
targets = ["x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "aarch64-apple-darwin", "aarch64-apple-ios"]
features = [ "librashader-cache/docsrs" ]
features = [ "librashader-cache/docsrs", "objc2/unstable-docsrs"]

View file

@ -100,9 +100,11 @@ pub mod preprocess {
/// use librashader::presets::ShaderPreset;
/// use librashader::reflect::{CompileReflectShader, FromCompilation, CompilePresetTarget, ShaderPassArtifact};
/// use librashader::reflect::targets::SPIRV;
/// use librashader::reflect::cross::GlslangCompilation;
/// use librashader::reflect::Glslang;
/// use librashader::reflect::semantics::ShaderSemantics;
/// type Artifact = impl CompileReflectShader<SPIRV, GlslangCompilation>;
/// use librashader_reflect::front::{ShaderInputCompiler, SpirvCompilation};
/// use librashader_reflect::reflect::cross::SpirvCross;
/// type Artifact = impl CompileReflectShader<SPIRV, Glslang, SpirvCross>;
/// type ShaderPassMeta = ShaderPassArtifact<Artifact>;
///
/// // Compile single shader
@ -110,15 +112,15 @@ pub mod preprocess {
/// source: &ShaderSource,
/// ) -> Result<Artifact, Box<dyn Error>>
/// {
/// let compilation = GlslangCompilation::compile(&source)?;
/// let spirv = SPIRV::from_compilation(artifact)?;
/// let compilation = Glslang::compile(&source)?;
/// let spirv = SPIRV::from_compilation(compilation)?;
/// Ok(spirv)
/// }
///
/// // Compile preset
/// pub fn compile_preset(preset: ShaderPreset) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), Box<dyn Error>>
/// {
/// let (passes, semantics) = SPIRV::compile_preset_passes::<GlslangCompilation, Box<dyn Error>>(
/// let (passes, semantics) = SPIRV::compile_preset_passes::<Glslang, SpirvCompilation, SpirvCross, Box<dyn Error>>(
/// preset.shaders, &preset.textures)?;
/// Ok((passes, semantics))
/// }
@ -129,8 +131,8 @@ pub mod preprocess {
/// [naga](https://docs.rs/naga/latest/naga/index.html), a pure-Rust shader compiler, when it has
/// matured enough to support [the features librashader needs](https://github.com/gfx-rs/naga/issues/1012).
///
/// In the meanwhile, the only supported compilation type is [GlslangCompilation](crate::reflect::cross::GlslangCompilation),
/// which does transpilation via [glslang](https://github.com/KhronosGroup/glslang/) and [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross).
/// In the meanwhile, the only supported input compiler is [Glslang](crate::reflect::Glslang),
/// which does compilation of GLSL to SPIR-V via [glslang](https://github.com/KhronosGroup/glslang/).
pub mod reflect {
/// Supported shader compiler targets.
pub mod targets {
@ -287,7 +289,7 @@ pub mod runtime {
options::{
FilterChainOptionsMetal as FilterChainOptions, FrameOptionsMetal as FrameOptions,
},
FilterChainMetal as FilterChain, MetalOutputView,
FilterChainMetal as FilterChain, MetalTextureRef,
};
}