Added uniform frequency. (#3485)

* Added uniform frequency.

* Cleanup.

* Cleanup.
This commit is contained in:
Branimir Karadžić
2025-11-10 15:41:33 -08:00
committed by GitHub
parent 8a9bc3ed65
commit 35911ac2d9
25 changed files with 1294 additions and 117 deletions

View File

@@ -1847,6 +1847,27 @@ public static class bgfx
Count
}
[AllowDuplicates]
public enum UniformFreq : uint32
{
/// <summary>
/// Changing per draw call.
/// </summary>
Draw,
/// <summary>
/// Changing per view.
/// </summary>
View,
/// <summary>
/// Changing per frame.
/// </summary>
Frame,
Count
}
[AllowDuplicates]
public enum BackbufferRatio : uint32
{
@@ -3432,6 +3453,41 @@ public static class bgfx
[LinkName("bgfx_create_uniform")]
public static extern UniformHandle create_uniform(char8* _name, UniformType _type, uint16 _num);
/// <summary>
/// Create shader uniform parameter.
/// @remarks
/// 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
/// multiple times with the same uniform name. The library will always
/// return the same handle, but the handle reference count will be
/// incremented. This means that the same number of `bgfx::destroyUniform`
/// must be called to properly destroy the uniform.
/// 2. Predefined uniforms (declared in `bgfx_shader.sh`):
/// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
/// view, in pixels.
/// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
/// width and height
/// - `u_view mat4` - view matrix
/// - `u_invView mat4` - inverted view matrix
/// - `u_proj mat4` - projection matrix
/// - `u_invProj mat4` - inverted projection matrix
/// - `u_viewProj mat4` - concatenated view projection matrix
/// - `u_invViewProj mat4` - concatenated inverted view projection matrix
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
/// - `u_modelView mat4` - concatenated model view matrix, only first
/// model matrix from array is used.
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
/// - `u_alphaRef float` - alpha reference value for alpha test.
/// </summary>
///
/// <param name="_name">Uniform name in shader.</param>
/// <param name="_freq">Uniform change frequency (See: `bgfx::UniformFreq`).</param>
/// <param name="_type">Type of uniform (See: `bgfx::UniformType`).</param>
/// <param name="_num">Number of elements in array.</param>
///
[LinkName("bgfx_create_uniform_with_freq")]
public static extern UniformHandle create_uniform_with_freq(char8* _name, UniformFreq _freq, UniformType _type, uint16 _num);
/// <summary>
/// Retrieve uniform info.
/// </summary>
@@ -3804,6 +3860,31 @@ public static class bgfx
[LinkName("bgfx_encoder_set_uniform")]
public static extern void encoder_set_uniform(Encoder* _this, UniformHandle _handle, void* _value, uint16 _num);
/// <summary>
/// Set shader uniform parameter for view.
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
/// </summary>
///
/// <param name="_id">View id.</param>
/// <param name="_handle">Uniform.</param>
/// <param name="_value">Pointer to uniform data.</param>
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
///
[LinkName("bgfx_set_view_uniform")]
public static extern void set_view_uniform(ViewId _id, UniformHandle _handle, void* _value, uint16 _num);
/// <summary>
/// Set shader uniform parameter for frame.
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
/// </summary>
///
/// <param name="_handle">Uniform.</param>
/// <param name="_value">Pointer to uniform data.</param>
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
///
[LinkName("bgfx_set_frame_uniform")]
public static extern void set_frame_uniform(UniformHandle _handle, void* _value, uint16 _num);
/// <summary>
/// Set index buffer for draw primitive.
/// </summary>

View File

@@ -1185,6 +1185,20 @@ enum UniformType : uint
COUNT
}
enum UniformFreq : uint
{
// Changing per draw call.
DRAW,
// Changing per view.
VIEW,
// Changing per frame.
FRAME,
COUNT
}
enum BackbufferRatio : uint
{
// Equal to backbuffer.
@@ -2452,6 +2466,36 @@ extern fn void destroy_frame_buffer(FrameBufferHandle _handle) @extern("bgfx_des
// _num : `Number of elements in array.`
extern fn UniformHandle create_uniform(ZString _name, UniformType _type, ushort _num) @extern("bgfx_create_uniform");
// Create shader uniform parameter.
// @remarks
// 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
// multiple times with the same uniform name. The library will always
// return the same handle, but the handle reference count will be
// incremented. This means that the same number of `bgfx::destroyUniform`
// must be called to properly destroy the uniform.
// 2. Predefined uniforms (declared in `bgfx_shader.sh`):
// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
// view, in pixels.
// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
// width and height
// - `u_view mat4` - view matrix
// - `u_invView mat4` - inverted view matrix
// - `u_proj mat4` - projection matrix
// - `u_invProj mat4` - inverted projection matrix
// - `u_viewProj mat4` - concatenated view projection matrix
// - `u_invViewProj mat4` - concatenated inverted view projection matrix
// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
// - `u_modelView mat4` - concatenated model view matrix, only first
// model matrix from array is used.
// - `u_invModelView mat4` - inverted concatenated model view matrix.
// - `u_modelViewProj mat4` - concatenated model view projection matrix.
// - `u_alphaRef float` - alpha reference value for alpha test.
// _name : `Uniform name in shader.`
// _freq : `Uniform change frequency (See: `bgfx::UniformFreq`).`
// _type : `Type of uniform (See: `bgfx::UniformType`).`
// _num : `Number of elements in array.`
extern fn UniformHandle create_uniform_with_freq(ZString _name, UniformFreq _freq, UniformType _type, ushort _num) @extern("bgfx_create_uniform_with_freq");
// Retrieve uniform info.
// _handle : `Handle to uniform object.`
// _info : `Uniform info.`
@@ -2666,6 +2710,21 @@ extern fn uint encoder_alloc_transform(Encoder* _this, Transform* _transform, us
// _num : `Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.`
extern fn void encoder_set_uniform(Encoder* _this, UniformHandle _handle, void* _value, ushort _num) @extern("bgfx_encoder_set_uniform");
// Set shader uniform parameter for view.
// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
// _id : `View id.`
// _handle : `Uniform.`
// _value : `Pointer to uniform data.`
// _num : `Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.`
extern fn void set_view_uniform(ushort _id, UniformHandle _handle, void* _value, ushort _num) @extern("bgfx_set_view_uniform");
// Set shader uniform parameter for frame.
// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
// _handle : `Uniform.`
// _value : `Pointer to uniform data.`
// _num : `Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.`
extern fn void set_frame_uniform(UniformHandle _handle, void* _value, ushort _num) @extern("bgfx_set_frame_uniform");
// Set index buffer for draw primitive.
// _handle : `Index buffer.`
// _firstIndex : `First index to render.`

View File

@@ -1839,6 +1839,26 @@ public static partial class bgfx
Count
}
public enum UniformFreq
{
/// <summary>
/// Changing per draw call.
/// </summary>
Draw,
/// <summary>
/// Changing per view.
/// </summary>
View,
/// <summary>
/// Changing per frame.
/// </summary>
Frame,
Count
}
public enum BackbufferRatio
{
/// <summary>
@@ -3386,6 +3406,41 @@ public static partial class bgfx
[DllImport(DllName, EntryPoint="bgfx_create_uniform", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe UniformHandle create_uniform([MarshalAs(UnmanagedType.LPStr)] string _name, UniformType _type, ushort _num);
/// <summary>
/// Create shader uniform parameter.
/// @remarks
/// 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
/// multiple times with the same uniform name. The library will always
/// return the same handle, but the handle reference count will be
/// incremented. This means that the same number of `bgfx::destroyUniform`
/// must be called to properly destroy the uniform.
/// 2. Predefined uniforms (declared in `bgfx_shader.sh`):
/// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
/// view, in pixels.
/// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
/// width and height
/// - `u_view mat4` - view matrix
/// - `u_invView mat4` - inverted view matrix
/// - `u_proj mat4` - projection matrix
/// - `u_invProj mat4` - inverted projection matrix
/// - `u_viewProj mat4` - concatenated view projection matrix
/// - `u_invViewProj mat4` - concatenated inverted view projection matrix
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
/// - `u_modelView mat4` - concatenated model view matrix, only first
/// model matrix from array is used.
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
/// - `u_alphaRef float` - alpha reference value for alpha test.
/// </summary>
///
/// <param name="_name">Uniform name in shader.</param>
/// <param name="_freq">Uniform change frequency (See: `bgfx::UniformFreq`).</param>
/// <param name="_type">Type of uniform (See: `bgfx::UniformType`).</param>
/// <param name="_num">Number of elements in array.</param>
///
[DllImport(DllName, EntryPoint="bgfx_create_uniform_with_freq", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe UniformHandle create_uniform_with_freq([MarshalAs(UnmanagedType.LPStr)] string _name, UniformFreq _freq, UniformType _type, ushort _num);
/// <summary>
/// Retrieve uniform info.
/// </summary>
@@ -3758,6 +3813,31 @@ public static partial class bgfx
[DllImport(DllName, EntryPoint="bgfx_encoder_set_uniform", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void encoder_set_uniform(Encoder* _this, UniformHandle _handle, void* _value, ushort _num);
/// <summary>
/// Set shader uniform parameter for view.
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
/// </summary>
///
/// <param name="_id">View id.</param>
/// <param name="_handle">Uniform.</param>
/// <param name="_value">Pointer to uniform data.</param>
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
///
[DllImport(DllName, EntryPoint="bgfx_set_view_uniform", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void set_view_uniform(ushort _id, UniformHandle _handle, void* _value, ushort _num);
/// <summary>
/// Set shader uniform parameter for frame.
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
/// </summary>
///
/// <param name="_handle">Uniform.</param>
/// <param name="_value">Pointer to uniform data.</param>
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
///
[DllImport(DllName, EntryPoint="bgfx_set_frame_uniform", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void set_frame_uniform(UniformHandle _handle, void* _value, ushort _num);
/// <summary>
/// Set index buffer for draw primitive.
/// </summary>

View File

@@ -54,6 +54,11 @@ extern(C++, "bgfx") package final abstract class UniformType{
sampler,end,vec4,mat3,mat4,count
}
}
extern(C++, "bgfx") package final abstract class UniformFreq{
enum Enum{
draw,view,frame,count
}
}
extern(C++, "bgfx") package final abstract class BackbufferRatio{
enum Enum{
equal,half,quarter,eighth,sixteenth,double_,count

View File

@@ -9,7 +9,7 @@ import bindbc.common.types: c_int64, c_uint64, va_list;
import bindbc.bgfx.config;
static import bgfx.impl;
enum uint apiVersion = 133;
enum uint apiVersion = 134;
alias ViewID = ushort;
@@ -771,6 +771,14 @@ enum UniformType: bgfx.impl.UniformType.Enum{
count = bgfx.impl.UniformType.Enum.count,
}
///Uniform frequency enum.
enum UniformFreq: bgfx.impl.UniformFreq.Enum{
draw = bgfx.impl.UniformFreq.Enum.draw,
view = bgfx.impl.UniformFreq.Enum.view,
frame = bgfx.impl.UniformFreq.Enum.frame,
count = bgfx.impl.UniformFreq.Enum.count,
}
///Backbuffer ratio enum.
enum BackbufferRatio: bgfx.impl.BackbufferRatio.Enum{
equal = bgfx.impl.BackbufferRatio.Enum.equal,
@@ -2848,6 +2856,39 @@ mixin(joinFnBinds((){
*/
{q{UniformHandle}, q{createUniform}, q{const(char)* name, bgfx.impl.UniformType.Enum type, ushort num=1}, ext: `C++, "bgfx"`},
/**
* Create shader uniform parameter.
* Remarks:
* 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
* multiple times with the same uniform name. The library will always
* return the same handle, but the handle reference count will be
* incremented. This means that the same number of `bgfx::destroyUniform`
* must be called to properly destroy the uniform.
* 2. Predefined uniforms (declared in `bgfx_shader.sh`):
* - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
* view, in pixels.
* - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
* width and height
* - `u_view mat4` - view matrix
* - `u_invView mat4` - inverted view matrix
* - `u_proj mat4` - projection matrix
* - `u_invProj mat4` - inverted projection matrix
* - `u_viewProj mat4` - concatenated view projection matrix
* - `u_invViewProj mat4` - concatenated inverted view projection matrix
* - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
* - `u_modelView mat4` - concatenated model view matrix, only first
* model matrix from array is used.
* - `u_invModelView mat4` - inverted concatenated model view matrix.
* - `u_modelViewProj mat4` - concatenated model view projection matrix.
* - `u_alphaRef float` - alpha reference value for alpha test.
Params:
name = Uniform name in shader.
freq = Uniform change frequency (See: `bgfx::UniformFreq`).
type = Type of uniform (See: `bgfx::UniformType`).
num = Number of elements in array.
*/
{q{UniformHandle}, q{createUniform}, q{const(char)* name, bgfx.impl.UniformFreq.Enum freq, bgfx.impl.UniformType.Enum type, ushort num=1}, ext: `C++, "bgfx"`},
/**
* Retrieve uniform info.
Params:
@@ -3065,6 +3106,29 @@ mixin(joinFnBinds((){
*/
{q{void}, q{end}, q{Encoder* encoder}, ext: `C++, "bgfx"`},
/**
* Set shader uniform parameter for view.
* Attention: Uniform must be created with `bgfx::UniformFreq::View` argument.
Params:
id = View id.
handle = Uniform.
value = Pointer to uniform data.
num = Number of elements. Passing `UINT16_MAX` will
use the _num passed on uniform creation.
*/
{q{void}, q{setViewUniform}, q{ViewID id, UniformHandle handle, const(void)* value, ushort num=1}, ext: `C++, "bgfx"`},
/**
* Set shader uniform parameter for frame.
* Attention: Uniform must be created with `bgfx::UniformFreq::View` argument.
Params:
handle = Uniform.
value = Pointer to uniform data.
num = Number of elements. Passing `UINT16_MAX` will
use the _num passed on uniform creation.
*/
{q{void}, q{setFrameUniform}, q{UniformHandle handle, const(void)* value, ushort num=1}, ext: `C++, "bgfx"`},
/**
* Request screen shot of window back buffer.
* Remarks:

View File

@@ -1151,6 +1151,19 @@ pub const UniformType = enum(c_int) {
Count
};
pub const UniformFreq = enum(c_int) {
/// Changing per draw call.
Draw,
/// Changing per view.
View,
/// Changing per frame.
Frame,
Count
};
pub const BackbufferRatio = enum(c_int) {
/// Equal to backbuffer.
Equal,
@@ -2760,6 +2773,39 @@ pub inline fn createUniform(_name: [*c]const u8, _type: UniformType, _num: u16)
}
extern fn bgfx_create_uniform(_name: [*c]const u8, _type: UniformType, _num: u16) UniformHandle;
/// Create shader uniform parameter.
/// @remarks
/// 1. Uniform names are unique. It's valid to call `bgfx::createUniform`
/// multiple times with the same uniform name. The library will always
/// return the same handle, but the handle reference count will be
/// incremented. This means that the same number of `bgfx::destroyUniform`
/// must be called to properly destroy the uniform.
/// 2. Predefined uniforms (declared in `bgfx_shader.sh`):
/// - `u_viewRect vec4(x, y, width, height)` - view rectangle for current
/// view, in pixels.
/// - `u_viewTexel vec4(1.0/width, 1.0/height, undef, undef)` - inverse
/// width and height
/// - `u_view mat4` - view matrix
/// - `u_invView mat4` - inverted view matrix
/// - `u_proj mat4` - projection matrix
/// - `u_invProj mat4` - inverted projection matrix
/// - `u_viewProj mat4` - concatenated view projection matrix
/// - `u_invViewProj mat4` - concatenated inverted view projection matrix
/// - `u_model mat4[BGFX_CONFIG_MAX_BONES]` - array of model matrices.
/// - `u_modelView mat4` - concatenated model view matrix, only first
/// model matrix from array is used.
/// - `u_invModelView mat4` - inverted concatenated model view matrix.
/// - `u_modelViewProj mat4` - concatenated model view projection matrix.
/// - `u_alphaRef float` - alpha reference value for alpha test.
/// <param name="_name">Uniform name in shader.</param>
/// <param name="_freq">Uniform change frequency (See: `bgfx::UniformFreq`).</param>
/// <param name="_type">Type of uniform (See: `bgfx::UniformType`).</param>
/// <param name="_num">Number of elements in array.</param>
pub inline fn createUniformWithFreq(_name: [*c]const u8, _freq: UniformFreq, _type: UniformType, _num: u16) UniformHandle {
return bgfx_create_uniform_with_freq(_name, _freq, _type, _num);
}
extern fn bgfx_create_uniform_with_freq(_name: [*c]const u8, _freq: UniformFreq, _type: UniformType, _num: u16) UniformHandle;
/// Retrieve uniform info.
/// <param name="_handle">Handle to uniform object.</param>
/// <param name="_info">Uniform info.</param>
@@ -3040,6 +3086,27 @@ extern fn bgfx_encoder_alloc_transform(self: ?*Encoder, _transform: [*c]Transfor
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
extern fn bgfx_encoder_set_uniform(self: ?*Encoder, _handle: UniformHandle, _value: ?*const anyopaque, _num: u16) void;
/// Set shader uniform parameter for view.
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
/// <param name="_id">View id.</param>
/// <param name="_handle">Uniform.</param>
/// <param name="_value">Pointer to uniform data.</param>
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
pub inline fn setViewUniform(_id: ViewId, _handle: UniformHandle, _value: ?*const anyopaque, _num: u16) void {
return bgfx_set_view_uniform(_id, _handle, _value, _num);
}
extern fn bgfx_set_view_uniform(_id: ViewId, _handle: UniformHandle, _value: ?*const anyopaque, _num: u16) void;
/// Set shader uniform parameter for frame.
/// @attention Uniform must be created with `bgfx::UniformFreq::View` argument.
/// <param name="_handle">Uniform.</param>
/// <param name="_value">Pointer to uniform data.</param>
/// <param name="_num">Number of elements. Passing `UINT16_MAX` will use the _num passed on uniform creation.</param>
pub inline fn setFrameUniform(_handle: UniformHandle, _value: ?*const anyopaque, _num: u16) void {
return bgfx_set_frame_uniform(_handle, _value, _num);
}
extern fn bgfx_set_frame_uniform(_handle: UniformHandle, _value: ?*const anyopaque, _num: u16) void;
/// Set index buffer for draw primitive.
/// <param name="_handle">Index buffer.</param>
/// <param name="_firstIndex">First index to render.</param>