Skip to content

Commit

Permalink
sokol: upgrade to latest version, fix all related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 5, 2023
1 parent 7560753 commit 0bf85d0
Show file tree
Hide file tree
Showing 36 changed files with 8,214 additions and 8,006 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/other_ci.yml
Expand Up @@ -101,7 +101,7 @@ jobs:

- name: Shader examples can be build
run: |
wget https://github.com/floooh/sokol-tools-bin/raw/33d2e4cc26088c6c28eaef5467990f8940d15aab/bin/linux/sokol-shdc
wget https://github.com/floooh/sokol-tools-bin/raw/6040b18d39649d56dbae2ae1aed59fb755b26369/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
58 changes: 39 additions & 19 deletions cmd/tools/vshader.v
Expand Up @@ -13,13 +13,14 @@
// The shader language used is, as described on the overview page linked above, an 'annotated GLSL'
// and 'modern GLSL' (v450) shader language format.
import os
import time
import io.util
import flag
import net.http

const (
shdc_full_hash = '33d2e4cc26088c6c28eaef5467990f8940d15aab'
tool_version = '0.0.1'
shdc_full_hash = '6040b18d39649d56dbae2ae1aed59fb755b26369'
tool_version = '0.0.2'
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 All @@ -29,15 +30,15 @@ const (
const (
supported_hosts = ['linux', 'macos', 'windows']
supported_slangs = [
'glsl330', // desktop GL
'glsl100', // GLES2 / WebGL
'glsl300es', // GLES3 / WebGL2
'hlsl4', // D3D11
'hlsl5', // D3D11
'metal_macos', // Metal on macOS
'metal_ios', // Metal on iOS device
'metal_sim', // Metal on iOS simulator
'wgpu', // WebGPU
'glsl330', // desktop OpenGL backend (SOKOL_GLCORE33)
'glsl100', // OpenGLES2 and WebGL (SOKOL_GLES3)
'glsl300es', // OpenGLES3 and WebGL2 (SOKOL_GLES3)
'hlsl4', // Direct3D11 with HLSL4 (SOKOL_D3D11)
'hlsl5', // Direct3D11 with HLSL5 (SOKOL_D3D11)
'metal_macos', // Metal on macOS (SOKOL_METAL)
'metal_ios', // Metal on iOS devices (SOKOL_METAL)
'metal_sim', // Metal on iOS simulator (SOKOL_METAL)
'wgsl', // WebGPU (SOKOL_WGPU)
]
default_slangs = [
'glsl330',
Expand All @@ -48,14 +49,15 @@ const (
'metal_macos',
'metal_ios',
'metal_sim',
'wgpu',
'wgsl',
]

shdc_version = shdc_full_hash[0..8]
shdc_urls = {
'windows': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/win32/sokol-shdc.exe'
'macos': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/osx/sokol-shdc'
'linux': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/linux/sokol-shdc'
'osx_a64': 'https://github.com/floooh/sokol-tools-bin/raw/${shdc_full_hash}/bin/osx_arm64/sokol-shdc'
}
shdc_version_file = os.join_path(cache_dir, 'sokol-shdc.version')
shdc = shdc_exe()
Expand Down Expand Up @@ -242,11 +244,20 @@ fn ensure_external_tools(opt Options) ! {

is_shdc_available := os.is_file(shdc)
is_shdc_executable := os.is_executable(shdc)
if is_shdc_available && is_shdc_executable {
if opt.verbose {
version := os.read_file(shdc_version_file) or { 'unknown' }
eprintln('${tool_name} using sokol-shdc version ${version} at "${shdc}"')
if opt.verbose {
eprintln('reading version from ${shdc_version_file} ...')
version := os.read_file(shdc_version_file) or { 'unknown' }
eprintln('${tool_name} using sokol-shdc version ${version} at "${shdc}"')
eprintln('executable: ${is_shdc_executable}')
eprintln(' available: ${is_shdc_available}')
if is_shdc_available {
eprintln(' file path: ${shdc}')
eprintln(' file size: ${os.file_size(shdc)}')
eprintln(' file time: ${time.unix_microsecond(os.file_last_mod_unix(shdc),
0)}')
}
}
if is_shdc_available && is_shdc_executable {
return
}

Expand All @@ -263,15 +274,24 @@ fn shdc_exe() string {
// download_shdc downloads the `sokol-shdc` tool to an OS specific cache directory.
fn download_shdc(opt Options) ! {
// We want to use the same, runtime, OS type as this tool is invoked on.
download_url := shdc_urls[runtime_os] or { '' }
mut download_url := shdc_urls[runtime_os] or { '' }
$if arm64 && macos {
download_url = shdc_urls['osx_a64']
}
if download_url == '' {
return error('${tool_name} failed to download an external dependency "sokol-shdc" for ${runtime_os}.\nThe supported host platforms for shader compilation is ${supported_hosts}')
}
if opt.verbose {
eprintln('> reading version from ${shdc_version_file} ...')
}
update_to_shdc_version := os.read_file(shdc_version_file) or { shdc_version }
if opt.verbose {
eprintln('> update_to_shdc_version: ${update_to_shdc_version} | shdc_version: ${shdc_version}')
}
file := shdc_exe()
if opt.verbose {
if shdc_version != update_to_shdc_version && os.exists(file) {
eprintln('${tool_name} updating sokol-shdc to version ${update_to_shdc_version} ...')
eprintln('${tool_name} updating sokol-shdc to version ${shdc_version} ...')
} else {
eprintln('${tool_name} installing sokol-shdc version ${update_to_shdc_version} ...')
}
Expand All @@ -298,5 +318,5 @@ fn download_shdc(opt Options) ! {
os.mv(file, shdc)!
}
// Update internal version file
os.write_file(shdc_version_file, update_to_shdc_version)!
os.write_file(shdc_version_file, shdc_version)!
}
8 changes: 4 additions & 4 deletions examples/sokol/01_cubes/cube.v
Expand Up @@ -45,11 +45,11 @@ fn create_texture(w int, h int, buf &u8) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
Expand Down
14 changes: 7 additions & 7 deletions examples/sokol/02_cubes_glsl/cube_glsl.v
Expand Up @@ -61,11 +61,11 @@ fn create_texture(w int, h int, buf &byte) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
Expand Down Expand Up @@ -361,7 +361,7 @@ fn init_cube_glsl(mut app App) {

app.cube_bind.vertex_buffers[0] = vbuf
app.cube_bind.index_buffer = ibuf
app.cube_bind.fs_images[C.SLOT_tex] = app.texture
app.cube_bind.fs.images[C.SLOT_tex] = app.texture
app.cube_pip_glsl = gfx.make_pipeline(&pipdesc)
println('GLSL init DONE!')
}
Expand All @@ -374,8 +374,8 @@ fn draw_cube_glsl(app App) {
// clear
ws := gg.window_size_real_pixels()
mut color_action := gfx.ColorAttachmentAction{
action: unsafe { gfx.Action(C.SG_ACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
value: gfx.Color{
load_action: unsafe { gfx.Action(C.SG_LOADACTION_DONTCARE) } // C.SG_ACTION_CLEAR)
clear_value: gfx.Color{
r: 1.0
g: 1.0
b: 1.0
Expand Down
14 changes: 7 additions & 7 deletions examples/sokol/03_march_tracing_glsl/rt_glsl.v
Expand Up @@ -60,11 +60,11 @@ fn create_texture(w int, h int, buf &byte) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
Expand Down Expand Up @@ -223,7 +223,7 @@ fn init_cube_glsl(mut app App) {

app.cube_bind.vertex_buffers[0] = vbuf
app.cube_bind.index_buffer = ibuf
app.cube_bind.fs_images[C.SLOT_tex] = app.texture
app.cube_bind.fs.images[C.SLOT_tex] = app.texture
app.cube_pip_glsl = gfx.make_pipeline(&pipdesc)
println('GLSL init DONE!')
}
Expand Down Expand Up @@ -312,8 +312,8 @@ fn frame(mut app App) {

// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0
Expand Down
16 changes: 8 additions & 8 deletions examples/sokol/04_multi_shader_glsl/rt_glsl.v
Expand Up @@ -63,11 +63,11 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
Expand Down Expand Up @@ -227,7 +227,7 @@ fn init_cube_glsl_m(mut app App) {
unsafe { vmemset(&bind, 0, int(sizeof(bind))) }
bind.vertex_buffers[0] = vbuf
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture
bind.fs.images[C.SLOT_tex] = app.texture
app.bind['march'] = bind

app.pipe['march'] = gfx.make_pipeline(&pipdesc)
Expand Down Expand Up @@ -342,7 +342,7 @@ fn init_cube_glsl_p(mut app App) {
unsafe { vmemset(&bind, 0, int(sizeof(bind))) }
bind.vertex_buffers[0] = vbuf
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture
bind.fs.images[C.SLOT_tex] = app.texture
app.bind['puppy'] = bind

app.pipe['puppy'] = gfx.make_pipeline(&pipdesc)
Expand Down Expand Up @@ -501,8 +501,8 @@ fn frame(mut app App) {

// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0
Expand Down
14 changes: 7 additions & 7 deletions examples/sokol/05_instancing_glsl/rt_glsl.v
Expand Up @@ -71,11 +71,11 @@ fn create_texture(w int, h int, buf byteptr) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
//usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
Expand Down Expand Up @@ -257,7 +257,7 @@ fn init_cube_glsl_i(mut app App) {
bind.vertex_buffers[0] = vbuf // vertex buffer
bind.vertex_buffers[1] = inst_buf // instance buffer
bind.index_buffer = ibuf
bind.fs_images[C.SLOT_tex] = app.texture
bind.fs.images[C.SLOT_tex] = app.texture
app.bind['inst'] = bind
app.pipe['inst'] = gfx.make_pipeline(&pipdesc)

Expand Down Expand Up @@ -384,8 +384,8 @@ fn frame(mut app App) {

// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0
Expand Down
10 changes: 5 additions & 5 deletions examples/sokol/06_obj_viewer/modules/obj/rend.v
Expand Up @@ -24,11 +24,11 @@ pub fn create_texture(w int, h int, buf &u8) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
Expand Down Expand Up @@ -133,7 +133,7 @@ pub fn (mut obj_part ObjPart) create_pipeline(in_part []int, shader gfx.Shader,

res.bind.vertex_buffers[0] = vbuf
res.bind.index_buffer = ibuf
res.bind.fs_images[C.SLOT_tex] = texture
res.bind.fs.images[C.SLOT_tex] = texture
res.pipeline = gfx.make_pipeline(&pipdesc)
// println('Buffers part [$in_part] init done!')

Expand Down
4 changes: 2 additions & 2 deletions examples/sokol/06_obj_viewer/show_obj.v
Expand Up @@ -150,8 +150,8 @@ fn frame(mut app App) {

// clear
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.0
g: 0.0
b: 0.0
Expand Down
4 changes: 2 additions & 2 deletions examples/sokol/fonts.v
Expand Up @@ -15,8 +15,8 @@ mut:

fn main() {
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 0.3
g: 0.3
b: 0.32
Expand Down
4 changes: 2 additions & 2 deletions examples/sokol/freetype_raven.v
Expand Up @@ -63,8 +63,8 @@ mut:

fn main() {
mut color_action := gfx.ColorAttachmentAction{
action: .clear
value: gfx.Color{
load_action: .clear
clear_value: gfx.Color{
r: 1.0
g: 1.0
b: 1.0
Expand Down
8 changes: 4 additions & 4 deletions examples/viewer/view.v
Expand Up @@ -121,11 +121,11 @@ fn create_texture(w int, h int, buf &u8) gfx.Image {
width: w
height: h
num_mipmaps: 0
min_filter: .linear
mag_filter: .linear
// min_filter: .linear
// mag_filter: .linear
// usage: .dynamic
wrap_u: .clamp_to_edge
wrap_v: .clamp_to_edge
// wrap_u: .clamp_to_edge
// wrap_v: .clamp_to_edge
label: &u8(0)
d3d11_texture: 0
}
Expand Down

0 comments on commit 0bf85d0

Please sign in to comment.