Migrating to librashader ABI 2
October 3, 2024 · View on GitHub
librashader version 0.5.0 introduces an ABI change to the C ABI that is incompatible with prior versions.
If a version of librashader prior to 0.5.0 was linked via libashader_ld.h, it should correctly fail to load when attempting
to load an instance of librashader 0.5.0 or later.
This document is only relevant to consumers of the librashader C ABI. Rust users should consult docs.rs/librashader.
LIBRASHADER_CURRENT_ABI change
LIBRASHADER_CURRENT_ABI has changed from 1 to 2. There is no change to LIBRASHADER_CURRENT_API, as new features
have not been added. Option structs should continue to pass LIBRASHADER_CURRENT_API for the latest available feature set.
SONAME change
On Linux, the canonical SONAME of librashader.so has changed from librashader.so.1 to librashader.so.2. This will
affect consumers that link via the linkage table with -lrashader or equivalent rather than through libashader_ld.h.
libra_preset changes
- The
_internal_allocfield fromlibra_preset_param_list_thas been removed. This change was made to reduce the potential surface area for undefined behaviour to occur. If librashader was used correctly, there is no code change required.
LIBRA_RUNTIME_VULKAN changes
The following changes are applicable if LIBRA_RUNTIME_VULKAN is defined.
- The
libra_output_image_vk_tandlibra_source_image_vk_tstructs have been replaced withlibra_image_vk_t.libra_image_vk_thas the same layout and semantics forlibra_source_image_vk_t.- When passed as
out, you should now pass what was previously.widthand.heightoflibra_viewport_tto the same fields inlibra_image_vk_t. Thehandleandformatfields retain the same semantics aslibra_output_image_vk_t.
- A field
queueof typeVkQueuewas added tolibra_device_vk_t. This field can beNULL. If notNULL, it is the handle to theVkQueuegraphics queue to use for the filter chain. IfNULL, a suitable queue will be chosen. - The
imageandoutparameters oflibra_vk_filter_chain_framehas changed fromlibra_source_image_vk_tandlibra_output_image_vk_t, tolibra_image_vk_t. - In
libra_vk_filter_chain_frame, the position of theviewportparameter has moved to after theoutparameter, and its type has changed fromlibra_viewport_ttolibra_viewport_t *, which is allowed to beNULL. Seelibra_viewport_tchanges for more details. - The
chainparameter oflibra_vk_filter_chain_get_paramhas been madeconst. - It is always thread safe to call
libra_vk_filter_chain_set_paramfrom any thread 1.
LIBRA_RUNTIME_OPENGL changes
The following changes are applicable if LIBRA_RUNTIME_OPENGL is defined.
- The
libra_gl_init_contextfunction has been removed. - The function
libra_gl_filter_chain_createnow accepts aloaderparameter of typelibra_gl_loader_t. This will be the OpenGL loader used to create the filter chain, previously passed tolibra_gl_init_contextThe filter chain will be created against the current OpenGL context. - The
libra_output_framebuffer_gl_tandlibra_source_image_gl_tstructs have been replaced withlibra_image_gl_t.libra_image_gl_thas the same layout and semantics forlibra_source_image_gl_t.- When passed as
out, you should now pass what was previously.widthand.heightoflibra_viewport_tto the same fields inlibra_image_gl_t. Thehandleandformatfields retain the same semantics aslibra_output_image_gl_t. - The
fbofield previously inlibra_output_image_gl_tis no longer necessary. librashader will now internally manage a framebuffer object to write to the provided texture.
- In
libra_gl_filter_chain_frame, the position of theviewportparameter has moved to after theoutparameter, and its type has changed fromlibra_viewport_ttolibra_viewport_t *, which is allowed to beNULL. Seelibra_viewport_tchanges for more details. - The
chainparameter oflibra_gl_filter_chain_get_paramhas been madeconst. - It is always thread safe to call
libra_gl_filter_chain_set_paramfrom any thread 1.
LIBRA_RUNTIME_D3D11 changes
The following changes are applicable if LIBRA_RUNTIME_D3D11 is defined.
- The
imageparameter oflibra_d3d11_filter_chain_framehas changed fromlibra_source_image_d3d11_ttoID3D11ShaderResourceView *.- You should now pass what was previously the
.handlefield oflibra_source_image_d3d11_tfield directly asimagetolibra_d3d11_filter_chain_frame.
- You should now pass what was previously the
- The
libra_source_image_d3d11_tstruct has been removed. - In
libra_d3d11_filter_chain_frame, the position of theviewportparameter has moved to after theoutparameter, and its type has changed fromlibra_viewport_ttolibra_viewport_t *, which is allowed to beNULL. Seelibra_viewport_tchanges for more details. - The
chainparameter oflibra_d3d11_filter_chain_get_paramhas been madeconst. - It is always thread safe to call
libra_d3d11_filter_chain_set_paramfrom any thread 1.
LIBRA_RUNTIME_D3D12 changes
The following changes are applicable if LIBRA_RUNTIME_D3D12 is defined.
- The lifetime of resources will not be extended past the call to the
libra_d3d12_filter_chain_framefunction. In other words, the refcount for any resources passed into the function will no longer be changed, and it is explicitly the responsibility of the caller to ensure any resources remain alive until theID3D12GraphicsCommandListprovided is submitted. - The fields
format,width, andheighthave been removed fromlibra_source_image_d3d12_t. - The field
descriptornow comes before the fieldresourcein the layout oflibra_source_image_d3d12_t. - The fields
widthandheighthave been added tolibra_output_image_d3d12_t.- You should now pass what was previously
.widthand.heightoflibra_viewport_tto these new fields inlibra_output_image_d3d12_t.
- You should now pass what was previously
- The
imageparameter oflibra_d3d12_filter_chain_framehas changed fromlibra_source_image_d3d12_ttolibra_image_d3d12_t.- To maintain the previous behaviour,
.image_typeof thelibra_image_d3d12_tshould be set toLIBRA_D3D12_IMAGE_TYPE_SOURCE_IMAGE, and.handle.sourceshould be thelibra_source_image_d3d12_tstruct.
- To maintain the previous behaviour,
- The
outparameter oflibra_d3d12_filter_chain_framehas changed fromlibra_output_image_d3d11_ttolibra_image_d3d12_t.- To maintain the previous behaviour,
.image_typeof thelibra_image_d3d12_tshould be set toLIBRA_D3D12_IMAGE_TYPE_OUTPUT_IMAGE, and.handle.outputshould be thelibra_output_image_d3d12_tstruct.
- To maintain the previous behaviour,
- Any
libra_image_d3d12_tcan now optionally pass only theID3D12Resource *for the texture by setting.image_typetoLIBRA_D3D12_IMAGE_TYPE_RESOURCEand setting.handle.resourceto the resource pointer.- If using
LIBRA_D3D12_IMAGE_TYPE_RESOURCE, shader resource view and render target view descriptors for the input and output images will be internally allocated by the filter chain. This may result in marginally worse performance.
- If using
- In
libra_d3d12_filter_chain_frame, the position of theviewportparameter has moved to after theoutparameter, and its type has changed fromlibra_viewport_ttolibra_viewport_t *, which is allowed to beNULL. Seelibra_viewport_tchanges for more details. - The
chainparameter oflibra_d3d12_filter_chain_get_paramhas been madeconst. - It is always thread safe to call
libra_d3d12_filter_chain_set_paramfrom any thread 1.
LIBRA_RUNTIME_D3D9 changes
The following changes are applicable if LIBRA_RUNTIME_D3D9 is defined.
- In
libra_d3d9_filter_chain_frame, the position of theviewportparameter has moved to after theoutparameter, and its type has changed fromlibra_viewport_ttolibra_viewport_t *, which is allowed to beNULL. Seelibra_viewport_tchanges for more details. - The
chainparameter oflibra_d3d9_filter_chain_get_paramhas been madeconst. - It is always thread safe to call
libra_d3d9_filter_chain_set_paramfrom any thread 1.
LIBRA_RUNTIME_METAL changes
The following changes are applicable if LIBRA_RUNTIME_METAL is defined.
- In
libra_mtl_filter_chain_frame, the position of theviewportparameter has moved to after theoutparameter, and its type has changed fromlibra_viewport_ttolibra_viewport_t *, which is allowed to beNULL. Seelibra_viewport_tchanges for more details. - The
chainparameter oflibra_mtl_filter_chain_get_paramhas been madeconst. - It is always thread safe to call
libra_mtl_filter_chain_set_paramfrom any thread 1.
libra_viewport_t changes
All viewport parameters for libra_*_filter_chain_frame now take a pointer to a libra_viewport_t struct. In ABI 1, the semantics of libra_viewport_t
was unspecified (but not undefined behaviour) if width and height did not match the width and height of the output texture.
This caused confusion as to what the actual purpose of the width and height fields were. The behaviour differed across runtimes:
In some runtimes, it specified the size of the output texture, in others they were used to set the clipping rect for the render target.
In ABI 2, the semantics of viewport as a parameter in libra_*_filter_chain_frame are as specified.
- If
viewportisNULL, then this will be the same as the specified behaviour in ABI 1—that is, as if the behaviour wherewidthandheightoflibra_viewport_twere equal to that of the output texture.- In other words, if
viewportisNULL, then it will set the render viewport to be equal to the width and height of the output texture.
- In other words, if
- If
viewportis notNULL, then the following occurs.- The width and height of the viewport rectangle for the output quad will be set to
viewport.widthandviewport.heightrespectively. - The origin point of the viewport rectangle will be set to (
x,y), in the native coordinate system of the runtime.- This behaviour may change over an API version bump. API version 1 will always retain the behaviour specified here.
- The scissor rectangle will be set to the same size and origin as the viewport rectangle.
- The width and height of the viewport rectangle for the output quad will be set to
Footnotes
-
This has been the case since librashader 0.4.0 on ABI 1. ABI 2 codifies this guarantee: any loosening in the thread-safety guarantees of
libra_*_filter_chain_set_paramin the future may only change across an API version bump. API version 1 will always retain the behaviour specified here. ↩ ↩2 ↩3 ↩4 ↩5 ↩6