Skip to content

Commit

Permalink
sokol: update to match uptream at 9e0f1b4 (#19687)
Browse files Browse the repository at this point in the history
  • Loading branch information
Larpon committed Oct 28, 2023
1 parent 2cf024b commit 775b25e
Show file tree
Hide file tree
Showing 12 changed files with 3,169 additions and 2,046 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/other_ci.yml
Expand Up @@ -101,7 +101,7 @@ jobs:

- name: Shader examples can be built
run: |
wget https://github.com/floooh/sokol-tools-bin/raw/6040b18d39649d56dbae2ae1aed59fb755b26369/bin/linux/sokol-shdc
wget https://github.com/floooh/sokol-tools-bin/raw/6b84ea387a323db9e8e17f5abed2b254a6e409fe/bin/linux/sokol-shdc
chmod +x ./sokol-shdc
for f in examples/sokol/02_cubes_glsl/cube_glsl \
examples/sokol/03_march_tracing_glsl/rt_glsl \
Expand Down
4 changes: 2 additions & 2 deletions cmd/tools/vshader.v
Expand Up @@ -19,8 +19,8 @@ import flag
import net.http

const (
shdc_full_hash = '6040b18d39649d56dbae2ae1aed59fb755b26369'
tool_version = '0.0.2'
shdc_full_hash = '6b84ea387a323db9e8e17f5abed2b254a6e409fe'
tool_version = '0.0.3'
tool_description = "Compile shaders in sokol's annotated GLSL format to C headers for use with sokol based apps"
tool_name = os.file_name(os.executable())
cache_dir = os.join_path(os.cache_dir(), 'v', tool_name)
Expand Down
4 changes: 2 additions & 2 deletions examples/sokol/02_cubes_glsl/cube_glsl.v
Expand Up @@ -56,7 +56,7 @@ mut:
* Texture functions
*
******************************************************************************/
fn create_texture(w int, h int, buf &byte) (gfx.Image, gfx.Sampler) {
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
Expand Down Expand Up @@ -90,7 +90,7 @@ fn destroy_texture(sg_img gfx.Image) {
}

// Use only if usage: .dynamic is enabled
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
sz := w * h * 4
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
Expand Down
4 changes: 2 additions & 2 deletions examples/sokol/03_march_tracing_glsl/rt_glsl.v
Expand Up @@ -55,7 +55,7 @@ mut:
/******************************************************************************
* Texture functions
******************************************************************************/
fn create_texture(w int, h int, buf &byte) (gfx.Image, gfx.Sampler) {
fn create_texture(w int, h int, buf &u8) (gfx.Image, gfx.Sampler) {
sz := w * h * 4
mut img_desc := gfx.ImageDesc{
width: w
Expand Down Expand Up @@ -93,7 +93,7 @@ fn destroy_texture(sg_img gfx.Image) {
}

// Use only if usage: .dynamic is enabled
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &byte) {
fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
sz := w * h * 4
mut tmp_sbc := gfx.ImageData{}
tmp_sbc.subimage[0][0] = gfx.Range{
Expand Down
587 changes: 371 additions & 216 deletions thirdparty/sokol/sokol_app.h

Large diffs are not rendered by default.

3,748 changes: 2,310 additions & 1,438 deletions thirdparty/sokol/sokol_gfx.h

Large diffs are not rendered by default.

316 changes: 123 additions & 193 deletions thirdparty/sokol/util/sokol_fontstash.h

Large diffs are not rendered by default.

308 changes: 121 additions & 187 deletions thirdparty/sokol/util/sokol_gl.h

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions vlib/sokol/gfx/enums.v
Expand Up @@ -141,16 +141,18 @@ pub enum ImageSampleType as u32 {
depth
sint
uint
unfilterable_float
_num
_force_u32 = 0x7FFFFFFF
_force_u32 = 0x7FFFFFFF
}

pub enum SamplerType as u32 {
_default
sample
compare
filtering
nonfiltering
comparison
_num
_force_u32 = 0x7FFFFFFF
_force_u32 = 0x7FFFFFFF
}

pub enum CubeFace as u32 {
Expand Down
26 changes: 26 additions & 0 deletions vlib/sokol/gfx/gfx.c.v
Expand Up @@ -290,3 +290,29 @@ pub fn activate_context(ctx_id Context) {
pub fn discard_context(ctx_id Context) {
C.sg_discard_context(ctx_id)
}

// frame stats

// enable_frame_stats enables the sokol frame statistics.
[inline]
pub fn enable_frame_stats() {
C.sg_enable_frame_stats()
}

// disable_frame_stats disables the sokol frame statistics.
[inline]
pub fn disable_frame_stats() {
C.sg_disable_frame_stats()
}

// frame_stats_enabled returns `true` if the sokol frame statistics is enabled.
[inline]
pub fn frame_stats_enabled() bool {
return C.sg_frame_stats_enabled()
}

// query_frame_stats returns the sokol frame statistics for the current frame.
[inline]
pub fn query_frame_stats() FrameStats {
return C.sg_query_frame_stats()
}
6 changes: 6 additions & 0 deletions vlib/sokol/gfx/gfx_funcs.c.v
Expand Up @@ -115,6 +115,12 @@ fn C.sg_fail_shader(shd C.sg_shader)
fn C.sg_fail_pipeline(pip C.sg_pipeline)
fn C.sg_fail_pass(pass C.sg_pass)

// frame stats
fn C.sg_enable_frame_stats()
fn C.sg_disable_frame_stats()
fn C.sg_frame_stats_enabled() bool
fn C.sg_query_frame_stats() C.sg_frame_stats

// rendering contexts (optional)
fn C.sg_setup_context() C.sg_context
fn C.sg_activate_context(ctx_id C.sg_context)
Expand Down
200 changes: 199 additions & 1 deletion vlib/sokol/gfx/gfx_structs.c.v
Expand Up @@ -11,10 +11,11 @@ pub mut:
pass_pool_size int
context_pool_size int
uniform_buffer_size int
staging_buffer_size int
max_commit_listeners int
disable_validation bool // disable validation layer even in debug mode, useful for tests
mtl_force_managed_storage_mode bool // for debugging: use Metal managed storage mode for resources even with UMA
wgpu_disable_bindgroups_cache bool // set to true to disable the WebGPU backend BindGroup cache
wgpu_bindgroups_cache_size int // number of slots in the WebGPU bindgroup cache (must be 2^N)
//
allocator C.sg_allocator
logger C.sg_logger
Expand Down Expand Up @@ -364,6 +365,203 @@ pub struct C.sg_pass_info {

pub type PassInfo = C.sg_pass_info

[typedef]
pub struct C.sg_frame_stats_gl {
num_bind_buffer u32
num_active_texture u32
num_bind_texture u32
num_bind_sampler u32
num_use_program u32
num_render_state u32
num_vertex_attrib_pointer u32
num_vertex_attrib_divisor u32
num_enable_vertex_attrib_array u32
num_disable_vertex_attrib_array u32
num_uniform u32
}

pub type FrameStatsGL = C.sg_frame_stats_gl

[typedef]
pub struct C.sg_frame_stats_d3d11_pass {
num_om_set_render_targets u32
num_clear_render_target_view u32
num_clear_depth_stencil_view u32
num_resolve_subresource u32
}

pub type FrameStatsD3D11Pass = C.sg_frame_stats_d3d11_pass

[typedef]
pub struct C.sg_frame_stats_d3d11_pipeline {
num_rs_set_state u32
num_om_set_depth_stencil_state u32
num_om_set_blend_state u32
num_ia_set_primitive_topology u32
num_ia_set_input_layout u32
num_vs_set_shader u32
num_vs_set_constant_buffers u32
num_ps_set_shader u32
num_ps_set_constant_buffers u32
}

pub type FrameStatsD3D11Pipeline = C.sg_frame_stats_d3d11_pipeline

[typedef]
pub struct C.sg_frame_stats_d3d11_bindings {
num_ia_set_vertex_buffers u32
num_ia_set_index_buffer u32
num_vs_set_shader_resources u32
num_ps_set_shader_resources u32
num_vs_set_samplers u32
num_ps_set_samplers u32
}

pub type FrameStatsD3D11Bindings = C.sg_frame_stats_d3d11_bindings

[typedef]
pub struct C.sg_frame_stats_d3d11_uniforms {
num_update_subresource u32
}

pub type FrameStatsD3D11Uniforms = C.sg_frame_stats_d3d11_uniforms

[typedef]
pub struct C.sg_frame_stats_d3d11_draw {
num_draw_indexed_instanced u32
num_draw_indexed u32
num_draw_instanced u32
num_draw u32
}

pub type FrameStatsD3D11Draw = C.sg_frame_stats_d3d11_draw

[typedef]
pub struct C.sg_frame_stats_d3d11 {
pass FrameStatsD3D11Pass
pipeline FrameStatsD3D11Pipeline
bindings FrameStatsD3D11Bindings
uniforms FrameStatsD3D11Uniforms
draw FrameStatsD3D11Draw
num_map u32
num_unmap u32
}

pub type FrameStatsD3D11 = C.sg_frame_stats_d3d11

[typedef]
pub struct C.sg_frame_stats_metal_idpool {
num_added u32
num_released u32
num_garbage_collected u32
}

pub type FrameStatsMetalIdpool = C.sg_frame_stats_metal_idpool

[typedef]
pub struct C.sg_frame_stats_metal_pipeline {
num_set_blend_color u32
num_set_cull_mode u32
num_set_front_facing_winding u32
num_set_stencil_reference_value u32
num_set_depth_bias u32
num_set_render_pipeline_state u32
num_set_depth_stencil_state u32
}

pub type FrameStatsMetalPipeline = C.sg_frame_stats_metal_pipeline

[typedef]
pub struct C.sg_frame_stats_metal_bindings {
num_set_vertex_buffer u32
num_set_vertex_texture u32
num_set_vertex_sampler_state u32
num_set_fragment_texture u32
num_set_fragment_sampler_state u32
}

pub type FrameStatsMetalBindings = C.sg_frame_stats_metal_bindings

[typedef]
pub struct C.sg_frame_stats_metal_uniforms {
num_set_vertex_buffer_offset u32
num_set_fragment_buffer_offset u32
}

pub type FrameStatsMetalUniforms = C.sg_frame_stats_metal_uniforms

[typedef]
pub struct C.sg_frame_stats_metal {
idpool FrameStatsMetalIdpool
pipeline FrameStatsMetalPipeline
bindings FrameStatsMetalBindings
uniforms FrameStatsMetalUniforms
}

pub type FrameStatsMetal = C.sg_frame_stats_metal

[typedef]
pub struct C.sg_frame_stats_wgpu_uniforms {
num_set_bindgroup u32
size_write_buffer u32
}

pub type FrameStatsWGPUUniforms = C.sg_frame_stats_wgpu_uniforms

[typedef]
pub struct C.sg_frame_stats_wgpu_bindings {
num_set_vertex_buffer u32
num_skip_redundant_vertex_buffer u32
num_set_index_buffer u32
num_skip_redundant_index_buffer u32
num_create_bindgroup u32
num_discard_bindgroup u32
num_set_bindgroup u32
num_skip_redundant_bindgroup u32
num_bindgroup_cache_hits u32
num_bindgroup_cache_misses u32
num_bindgroup_cache_collisions u32
num_bindgroup_cache_hash_vs_key_mismatch u32
}

pub type FrameStatsWGPUBindings = C.sg_frame_stats_wgpu_bindings

[typedef]
pub struct C.sg_frame_stats_wgpu {
uniforms FrameStatsWGPUUniforms
bindings FrameStatsWGPUBindings
}

pub type FrameStatsWGPU = C.sg_frame_stats_wgpu

[typedef]
pub struct C.sg_frame_stats {
frame_index u32 // current frame counter, starts at 0
//
num_passes u32
num_apply_viewport u32
num_apply_scissor_rect u32
num_apply_pipeline u32
num_apply_bindings u32
num_apply_uniforms u32
num_draw u32
num_update_buffer u32
num_append_buffer u32
num_update_image u32
//
size_apply_uniforms u32
size_update_buffer u32
size_append_buffer u32
size_update_image u32
//
gl FrameStatsGL
d3d11 FrameStatsD3D11
metal FrameStatsMetal
wgpu FrameStatsWGPU
}

pub type FrameStats = C.sg_frame_stats

pub struct C.sg_pass_action {
pub mut:
colors [4]ColorAttachmentAction
Expand Down

0 comments on commit 775b25e

Please sign in to comment.