Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for sokol-gfx bindings cleanup. #31

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ jobs:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@main
Expand Down
18 changes: 5 additions & 13 deletions examples/blend/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" fn init(user_data: *mut ffi::c_void) {
layout: {
let mut layout = sg::VertexLayoutState::new();
layout.buffers[0].stride = 28;
layout.attrs[shader::ATTR_VS_BG_POSITION].format = sg::VertexFormat::Float2;
layout.attrs[shader::ATTR_BG_POSITION].format = sg::VertexFormat::Float2;
layout
},
primitive_type: sg::PrimitiveType::TriangleStrip,
Expand All @@ -73,8 +73,8 @@ extern "C" fn init(user_data: *mut ffi::c_void) {
let mut pip_desc = sg::PipelineDesc {
layout: {
let mut layout = sg::VertexLayoutState::new();
layout.attrs[shader::ATTR_VS_QUAD_POSITION].format = sg::VertexFormat::Float3;
layout.attrs[shader::ATTR_VS_QUAD_COLOR0].format = sg::VertexFormat::Float4;
layout.attrs[shader::ATTR_QUAD_POSITION].format = sg::VertexFormat::Float3;
layout.attrs[shader::ATTR_QUAD_COLOR0].format = sg::VertexFormat::Float4;
layout
},
shader: quad_shd,
Expand Down Expand Up @@ -119,11 +119,7 @@ extern "C" fn frame(user_data: *mut ffi::c_void) {
// draw a background quad
sg::apply_pipeline(state.bg_pip);
sg::apply_bindings(&state.bind);
sg::apply_uniforms(
sg::ShaderStage::Fs,
shader::SLOT_BG_FS_PARAMS,
&sg::value_as_range(&state.bg_fs_params),
);
sg::apply_uniforms(shader::UB_BG_FS_PARAMS, &sg::value_as_range(&state.bg_fs_params));
sg::draw(0, 4, 1);

// draw the blended quads
Expand All @@ -139,11 +135,7 @@ extern "C" fn frame(user_data: *mut ffi::c_void) {

sg::apply_pipeline(state.pips[src][dst]);
sg::apply_bindings(&state.bind);
sg::apply_uniforms(
sg::ShaderStage::Vs,
shader::SLOT_QUAD_VS_PARAMS,
&sg::value_as_range(&state.quad_vs_params),
);
sg::apply_uniforms(shader::UB_QUAD_VS_PARAMS, &sg::value_as_range(&state.quad_vs_params));
sg::draw(0, 4, 1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/blend/shader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() {
@end

@fs fs_bg
uniform bg_fs_params {
layout(binding=0) uniform bg_fs_params {
float tick;
};

Expand All @@ -28,7 +28,7 @@ void main() {
@program bg vs_bg fs_bg

@vs vs_quad
uniform quad_vs_params {
layout(binding=0) uniform quad_vs_params {
mat4 mvp;
};

Expand Down
161 changes: 86 additions & 75 deletions examples/blend/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@ use sokol::gfx as sg;
=========
Shader program: 'bg':
Get shader desc: bg_shader_desc(sg::query_backend());
Vertex shader: vs_bg
Attributes:
ATTR_VS_BG_POSITION => 0
Fragment shader: fs_bg
Uniform block 'bg_fs_params':
Rust struct: BgFsParams
Bind slot: SLOT_BG_FS_PARAMS => 0
Vertex Shader: vs_bg
Fragment Shader: fs_bg
Attributes:
ATTR_BG_POSITION => 0
Shader program: 'quad':
Get shader desc: quad_shader_desc(sg::query_backend());
Vertex shader: vs_quad
Attributes:
ATTR_VS_QUAD_POSITION => 0
ATTR_VS_QUAD_COLOR0 => 1
Uniform block 'quad_vs_params':
Rust struct: QuadVsParams
Bind slot: SLOT_QUAD_VS_PARAMS => 0
Fragment shader: fs_quad
Vertex Shader: vs_quad
Fragment Shader: fs_quad
Attributes:
ATTR_QUAD_POSITION => 0
ATTR_QUAD_COLOR0 => 1
Bindings:
Uniform block 'bg_fs_params':
Rust struct: BgFsParams
Bind slot: UB_BG_FS_PARAMS => 0
Uniform block 'quad_vs_params':
Rust struct: QuadVsParams
Bind slot: UB_QUAD_VS_PARAMS => 0
*/
pub const ATTR_VS_BG_POSITION: usize = 0;
pub const ATTR_VS_QUAD_POSITION: usize = 0;
pub const ATTR_VS_QUAD_COLOR0: usize = 1;
pub const SLOT_BG_FS_PARAMS: usize = 0;
pub const SLOT_QUAD_VS_PARAMS: usize = 0;
pub const ATTR_BG_POSITION: usize = 0;
pub const ATTR_QUAD_POSITION: usize = 0;
pub const ATTR_QUAD_COLOR0: usize = 1;
pub const UB_BG_FS_PARAMS: usize = 0;
pub const UB_QUAD_VS_PARAMS: usize = 0;
#[repr(C, align(16))]
pub struct BgFsParams {
pub tick: f32,
Expand Down Expand Up @@ -660,36 +661,41 @@ pub fn bg_shader_desc(backend: sg::Backend) -> sg::ShaderDesc {
desc.label = c"bg_shader".as_ptr();
match backend {
sg::Backend::Glcore => {
desc.attrs[0].name = c"position".as_ptr();
desc.vs.source = &VS_BG_SOURCE_GLSL430 as *const _ as *const _;
desc.vs.entry = c"main".as_ptr();
desc.fs.source = &FS_BG_SOURCE_GLSL430 as *const _ as *const _;
desc.fs.entry = c"main".as_ptr();
desc.fs.uniform_blocks[0].size = 16;
desc.fs.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.fs.uniform_blocks[0].uniforms[0].name = c"bg_fs_params".as_ptr();
desc.fs.uniform_blocks[0].uniforms[0]._type = sg::UniformType::Float4;
desc.fs.uniform_blocks[0].uniforms[0].array_count = 1;
desc.vertex_func.source = &VS_BG_SOURCE_GLSL430 as *const _ as *const _;
desc.vertex_func.entry = c"main".as_ptr();
desc.fragment_func.source = &FS_BG_SOURCE_GLSL430 as *const _ as *const _;
desc.fragment_func.entry = c"main".as_ptr();
desc.attrs[0].glsl_name = c"position".as_ptr();
desc.uniform_blocks[0].stage = sg::ShaderStage::Fragment;
desc.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.uniform_blocks[0].size = 16;
desc.uniform_blocks[0].glsl_uniforms[0]._type = sg::UniformType::Float4;
desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1;
desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = c"bg_fs_params".as_ptr();
},
sg::Backend::D3d11 => {
desc.attrs[0].sem_name = c"TEXCOORD".as_ptr();
desc.attrs[0].sem_index = 0;
desc.vs.source = &VS_BG_SOURCE_HLSL5 as *const _ as *const _;
desc.vs.d3d11_target = c"vs_5_0".as_ptr();
desc.vs.entry = c"main".as_ptr();
desc.fs.source = &FS_BG_SOURCE_HLSL5 as *const _ as *const _;
desc.fs.d3d11_target = c"ps_5_0".as_ptr();
desc.fs.entry = c"main".as_ptr();
desc.fs.uniform_blocks[0].size = 16;
desc.fs.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.vertex_func.source = &VS_BG_SOURCE_HLSL5 as *const _ as *const _;
desc.vertex_func.d3d11_target = c"vs_5_0".as_ptr();
desc.vertex_func.entry = c"main".as_ptr();
desc.fragment_func.source = &FS_BG_SOURCE_HLSL5 as *const _ as *const _;
desc.fragment_func.d3d11_target = c"ps_5_0".as_ptr();
desc.fragment_func.entry = c"main".as_ptr();
desc.attrs[0].hlsl_sem_name = c"TEXCOORD".as_ptr();
desc.attrs[0].hlsl_sem_index = 0;
desc.uniform_blocks[0].stage = sg::ShaderStage::Fragment;
desc.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.uniform_blocks[0].size = 16;
desc.uniform_blocks[0].hlsl_register_b_n = 0;
},
sg::Backend::MetalMacos => {
desc.vs.source = &VS_BG_SOURCE_METAL_MACOS as *const _ as *const _;
desc.vs.entry = c"main0".as_ptr();
desc.fs.source = &FS_BG_SOURCE_METAL_MACOS as *const _ as *const _;
desc.fs.entry = c"main0".as_ptr();
desc.fs.uniform_blocks[0].size = 16;
desc.fs.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.vertex_func.source = &VS_BG_SOURCE_METAL_MACOS as *const _ as *const _;
desc.vertex_func.entry = c"main0".as_ptr();
desc.fragment_func.source = &FS_BG_SOURCE_METAL_MACOS as *const _ as *const _;
desc.fragment_func.entry = c"main0".as_ptr();
desc.uniform_blocks[0].stage = sg::ShaderStage::Fragment;
desc.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.uniform_blocks[0].size = 16;
desc.uniform_blocks[0].msl_buffer_n = 0;
},
_ => {},
}
Expand All @@ -700,39 +706,44 @@ pub fn quad_shader_desc(backend: sg::Backend) -> sg::ShaderDesc {
desc.label = c"quad_shader".as_ptr();
match backend {
sg::Backend::Glcore => {
desc.attrs[0].name = c"position".as_ptr();
desc.attrs[1].name = c"color0".as_ptr();
desc.vs.source = &VS_QUAD_SOURCE_GLSL430 as *const _ as *const _;
desc.vs.entry = c"main".as_ptr();
desc.vs.uniform_blocks[0].size = 64;
desc.vs.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.vs.uniform_blocks[0].uniforms[0].name = c"quad_vs_params".as_ptr();
desc.vs.uniform_blocks[0].uniforms[0]._type = sg::UniformType::Float4;
desc.vs.uniform_blocks[0].uniforms[0].array_count = 4;
desc.fs.source = &FS_QUAD_SOURCE_GLSL430 as *const _ as *const _;
desc.fs.entry = c"main".as_ptr();
desc.vertex_func.source = &VS_QUAD_SOURCE_GLSL430 as *const _ as *const _;
desc.vertex_func.entry = c"main".as_ptr();
desc.fragment_func.source = &FS_QUAD_SOURCE_GLSL430 as *const _ as *const _;
desc.fragment_func.entry = c"main".as_ptr();
desc.attrs[0].glsl_name = c"position".as_ptr();
desc.attrs[1].glsl_name = c"color0".as_ptr();
desc.uniform_blocks[0].stage = sg::ShaderStage::Vertex;
desc.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.uniform_blocks[0].size = 64;
desc.uniform_blocks[0].glsl_uniforms[0]._type = sg::UniformType::Float4;
desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4;
desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = c"quad_vs_params".as_ptr();
},
sg::Backend::D3d11 => {
desc.attrs[0].sem_name = c"TEXCOORD".as_ptr();
desc.attrs[0].sem_index = 0;
desc.attrs[1].sem_name = c"TEXCOORD".as_ptr();
desc.attrs[1].sem_index = 1;
desc.vs.source = &VS_QUAD_SOURCE_HLSL5 as *const _ as *const _;
desc.vs.d3d11_target = c"vs_5_0".as_ptr();
desc.vs.entry = c"main".as_ptr();
desc.vs.uniform_blocks[0].size = 64;
desc.vs.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.fs.source = &FS_QUAD_SOURCE_HLSL5 as *const _ as *const _;
desc.fs.d3d11_target = c"ps_5_0".as_ptr();
desc.fs.entry = c"main".as_ptr();
desc.vertex_func.source = &VS_QUAD_SOURCE_HLSL5 as *const _ as *const _;
desc.vertex_func.d3d11_target = c"vs_5_0".as_ptr();
desc.vertex_func.entry = c"main".as_ptr();
desc.fragment_func.source = &FS_QUAD_SOURCE_HLSL5 as *const _ as *const _;
desc.fragment_func.d3d11_target = c"ps_5_0".as_ptr();
desc.fragment_func.entry = c"main".as_ptr();
desc.attrs[0].hlsl_sem_name = c"TEXCOORD".as_ptr();
desc.attrs[0].hlsl_sem_index = 0;
desc.attrs[1].hlsl_sem_name = c"TEXCOORD".as_ptr();
desc.attrs[1].hlsl_sem_index = 1;
desc.uniform_blocks[0].stage = sg::ShaderStage::Vertex;
desc.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.uniform_blocks[0].size = 64;
desc.uniform_blocks[0].hlsl_register_b_n = 0;
},
sg::Backend::MetalMacos => {
desc.vs.source = &VS_QUAD_SOURCE_METAL_MACOS as *const _ as *const _;
desc.vs.entry = c"main0".as_ptr();
desc.vs.uniform_blocks[0].size = 64;
desc.vs.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.fs.source = &FS_QUAD_SOURCE_METAL_MACOS as *const _ as *const _;
desc.fs.entry = c"main0".as_ptr();
desc.vertex_func.source = &VS_QUAD_SOURCE_METAL_MACOS as *const _ as *const _;
desc.vertex_func.entry = c"main0".as_ptr();
desc.fragment_func.source = &FS_QUAD_SOURCE_METAL_MACOS as *const _ as *const _;
desc.fragment_func.entry = c"main0".as_ptr();
desc.uniform_blocks[0].stage = sg::ShaderStage::Vertex;
desc.uniform_blocks[0].layout = sg::UniformLayout::Std140;
desc.uniform_blocks[0].size = 64;
desc.uniform_blocks[0].msl_buffer_n = 0;
},
_ => {},
}
Expand Down
6 changes: 3 additions & 3 deletions examples/cube/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ extern "C" fn init(user_data: *mut ffi::c_void) {
let mut layout = sg::VertexLayoutState::new();
layout.buffers[0].stride = 28;

layout.attrs[shader::ATTR_VS_POSITION].format = sg::VertexFormat::Float3;
layout.attrs[shader::ATTR_VS_COLOR0].format = sg::VertexFormat::Float4;
layout.attrs[shader::ATTR_CUBE_POSITION].format = sg::VertexFormat::Float3;
layout.attrs[shader::ATTR_CUBE_COLOR0].format = sg::VertexFormat::Float4;

layout
},
Expand Down Expand Up @@ -131,7 +131,7 @@ extern "C" fn frame(user_data: *mut ffi::c_void) {
sg::begin_pass(&sg::Pass { action: pass_action, swapchain: sglue::swapchain(), ..Default::default() });
sg::apply_pipeline(state.pip);
sg::apply_bindings(&state.bind);
sg::apply_uniforms(sg::ShaderStage::Vs, shader::SLOT_VS_PARAMS, &sg::value_as_range(&vs_params));
sg::apply_uniforms(shader::UB_VS_PARAMS, &sg::value_as_range(&vs_params));
sg::draw(0, 36, 1);
sg::end_pass();
sg::commit();
Expand Down
2 changes: 1 addition & 1 deletion examples/cube/shader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@ctype mat4 m::Mat4

@vs vs
uniform vs_params {
layout(binding=0) uniform vs_params {
mat4 mvp;
};

Expand Down
Loading