Skip to content

Instantly share code, notes, and snippets.

using import ..pijul.utils.va
#inline va-pos (val args...)
va-lifold none
inline "#hidden" (i key arg result)
dump i key arg result
static-if (not (none? result)) result
elseif (arg == val) i
else result
args...
import .glfw
fn start-glfw ()
if ((glfw.init) == 0)
return;
defer glfw.terminate
let window =
glfw.createWindow 640 480 "Hello World" null null
if (window == null)
@porky11
porky11 / number-parser.sc
Created August 26, 2019 13:22
Parsing arbitrary numbers types as values to specific number types
inline value-to-number-maker (number-type)
fn (value)
match ('typeof value)
case i8
number-type
value as i8
case i16
number-type
value as i16
case i32
@porky11
porky11 / draw.frag
Created August 15, 2019 03:37
SPIRV disassembly glsl code containing separate texture and sampler types
#version 450
layout(location = 0) in vec2 v_TexCoord;
layout(location = 0) out vec4 o_Target;
layout(set = 0, binding = 1) uniform texture2D t_Color;
layout(set = 0, binding = 2) uniform sampler s_Color;
void main() {
o_Target = texture(sampler2D(t_Color, s_Color), v_TexCoord);
}
@porky11
porky11 / voxel.comp
Created August 13, 2019 15:33
Compute Shader test
#version 460
layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
struct Sphere {
vec4 center;
};
layout(binding = 1, std140) uniform Camera {
vec4 pos;
vec4 dir;
@porky11
porky11 / texture-bindings.sc
Created August 11, 2019 06:41
Binding a texture as image3D in wgpu using scopes
local layout-bindings =
arrayof wgpu.BindGroupLayoutBinding
typeinit
binding = 0
visibility = wgpu.ShaderStage.COMPUTE
ty = wgpu.BindingType.StorageTexture
let size = 0x10
let texture =
@porky11
porky11 / implicit-orderless.sc
Created June 8, 2019 12:05
Some test for functions without explicitly specifying arguments
inline va-type@ (T args...)
va-lfold none
inline "#hidden" (key value)
static-if ((typeof value) <= T)
return value
args...
inline va-type@... (T args...)
va-rfold none
inline (key value result...)
@porky11
porky11 / Slice.sc
Created June 2, 2019 20:17
Slice test
using import struct
inline Slice (T)
struct ("[" .. (tostring T) .. "]")
first : (mutable pointer T)
size : usize
inline __countof (self)
self.size
fn slice (array start end)
@porky11
porky11 / simple-wgpu-example.sc
Last active June 1, 2019 15:23
Finished port of the wgpu example to scopes
load-library "/usr/local/lib/libwgpu_native.so"
load-library "/usr/lib/libglfw.so.3"
run-stage;
include;
""""#include <wgpu.h>
#include <stdio.h>
#include <stdlib.h>
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_X11