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

Use explicit "vulkan-style" shaders to generate all shader outputs #333

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
34 changes: 20 additions & 14 deletions gl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,16 @@ impl GLDevice {
unsafe {
match *data {
UniformData::Float(value) => {
gl::Uniform1f(uniform.location, value); ck();
gl::Uniform4f(uniform.location, value, 0.0, 0.0, 0.0); ck();
}
UniformData::IVec2(value) => {
gl::Uniform2i(uniform.location, value[0], value[1]); ck();
gl::Uniform4i(uniform.location, value[0], value[1], 0, 0); ck();
}
UniformData::IVec3(value) => {
gl::Uniform3i(uniform.location, value[0], value[1], value[2]); ck();
gl::Uniform4i(uniform.location, value[0], value[1], value[2], 0); ck();
}
UniformData::Int(value) => {
gl::Uniform1i(uniform.location, value); ck();
gl::Uniform4i(uniform.location, value, 0, 0, 0); ck();
}
UniformData::Mat2(data) => {
assert_eq!(mem::size_of::<F32x4>(), 4 * 4);
Expand All @@ -168,17 +168,16 @@ impl GLDevice {
}
UniformData::Mat4(data) => {
assert_eq!(mem::size_of::<[F32x4; 4]>(), 4 * 4 * 4);
let data_ptr: *const F32x4 = data.as_ptr();
gl::UniformMatrix4fv(uniform.location,
1,
gl::FALSE,
data_ptr as *const GLfloat);
gl::Uniform4f(uniform.location, data[0].x(), data[0].y(), data[0].z(), data[0].w()); ck();
gl::Uniform4f(uniform.location + 1, data[1].x(), data[1].y(), data[1].z(), data[1].w()); ck();
gl::Uniform4f(uniform.location + 2, data[2].x(), data[2].y(), data[2].z(), data[2].w()); ck();
gl::Uniform4f(uniform.location + 3, data[3].x(), data[3].y(), data[3].z(), data[3].w()); ck();
}
UniformData::Vec2(data) => {
gl::Uniform2f(uniform.location, data.x(), data.y()); ck();
gl::Uniform4f(uniform.location, data.x(), data.y(), 0.0, 0.0); ck();
}
UniformData::Vec3(data) => {
gl::Uniform3f(uniform.location, data[0], data[1], data[2]); ck();
gl::Uniform4f(uniform.location, data[0], data[1], data[2], 0.0); ck();
}
UniformData::Vec4(data) => {
gl::Uniform4f(uniform.location, data.x(), data.y(), data.z(), data.w()); ck();
Expand Down Expand Up @@ -432,10 +431,17 @@ impl Device for GLDevice {
}

fn get_uniform(&self, program: &GLProgram, name: &str) -> GLUniform {
let name = CString::new(format!("u{}", name)).unwrap();
let location = unsafe {
gl::GetUniformLocation(program.gl_program, name.as_ptr() as *const GLchar)
let uniform_name = CString::new(format!("u{}", name)).unwrap();
let mut location = unsafe {
gl::GetUniformLocation(program.gl_program, uniform_name.as_ptr() as *const GLchar)
}; ck();
if location < 0 {
let uniform_name = CString::new(format!("SPIRV_Cross_Combinedu{}uSampler", name)).unwrap();
location = unsafe {
gl::GetUniformLocation(program.gl_program, uniform_name.as_ptr() as *const GLchar)
};
ck();
};
GLUniform { location }
}

Expand Down
2 changes: 1 addition & 1 deletion metal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ impl MetalDevice {
None => panic!("get_uniform_index() called before reflection!"),
Some(ref arguments) => arguments,
};
let (main_name, sampler_name) = (format!("u{}", name), format!("u{}Smplr", name));
let (main_name, sampler_name) = (format!("u{}", name), format!("u{}Sampler", name));
let (mut main_argument, mut sampler_argument) = (None, None);
for argument_index in 0..arguments.len() {
let argument = arguments.object_at(argument_index);
Expand Down
28 changes: 6 additions & 22 deletions resources/shaders/gl3/blit.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,14 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!












precision highp float;





uniform sampler2D uSrc;
uniform sampler2D SPIRV_Cross_CombineduSrcuSampler;

in vec2 vTexCoord;
layout(location = 0) out vec4 oFragColor;

out vec4 oFragColor;

void main(){
vec4 color = texture(uSrc, vTexCoord);
oFragColor = vec4(color . rgb * color . a, color . a);
void main()
{
vec4 color = texture(SPIRV_Cross_CombineduSrcuSampler, vTexCoord);
oFragColor = vec4(color.xyz * color.w, color.w);
}

27 changes: 4 additions & 23 deletions resources/shaders/gl3/blit.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,13 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!












precision highp float;





in ivec2 aPosition;

layout(location = 0) in ivec2 aPosition;
out vec2 vTexCoord;

void main(){
void main()
{
vec2 texCoord = vec2(aPosition);



vTexCoord = texCoord;
gl_Position = vec4(mix(vec2(- 1.0), vec2(1.0), vec2(aPosition)), 0.0, 1.0);
gl_Position = vec4(mix(vec2(-1.0), vec2(1.0), vec2(aPosition)), 0.0, 1.0);
}

26 changes: 5 additions & 21 deletions resources/shaders/gl3/clear.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,11 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!


uniform vec4 uColor[1];
layout(location = 0) out vec4 oFragColor;










precision highp float;





uniform vec4 uColor;

out vec4 oFragColor;

void main(){
oFragColor = vec4(uColor . rgb, 1.0)* uColor . a;
void main()
{
oFragColor = vec4(uColor[0].xyz, 1.0) * uColor[0].w;
}

32 changes: 8 additions & 24 deletions resources/shaders/gl3/clear.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,13 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!












precision highp float;





uniform vec4 uRect;
uniform vec2 uFramebufferSize;

in ivec2 aPosition;

void main(){
vec2 position = mix(uRect . xy, uRect . zw, vec2(aPosition))/ uFramebufferSize * 2.0 - 1.0;
gl_Position = vec4(position . x, - position . y, 0.0, 1.0);
uniform vec4 uRect[1];
uniform vec4 uFramebufferSize[1];
layout(location = 0) in ivec2 aPosition;

void main()
{
vec2 position = ((mix(uRect[0].xy, uRect[0].zw, vec2(aPosition)) / uFramebufferSize[0].xy) * 2.0) - vec2(1.0);
gl_Position = vec4(position.x, -position.y, 0.0, 1.0);
}

26 changes: 5 additions & 21 deletions resources/shaders/gl3/debug_solid.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,11 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!


uniform vec4 uColor[1];
layout(location = 0) out vec4 oFragColor;










precision highp float;





uniform vec4 uColor;

out vec4 oFragColor;

void main(){
oFragColor = vec4(uColor . rgb, 1.0)* uColor . a;
void main()
{
oFragColor = vec4(uColor[0].xyz, 1.0) * uColor[0].w;
}

28 changes: 6 additions & 22 deletions resources/shaders/gl3/debug_solid.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!


uniform vec4 uFramebufferSize[1];
layout(location = 0) in ivec2 aPosition;










precision highp float;





uniform vec2 uFramebufferSize;

in ivec2 aPosition;

void main(){
vec2 position = vec2(aPosition)/ uFramebufferSize * 2.0 - 1.0;
gl_Position = vec4(position . x, - position . y, 0.0, 1.0);
void main()
{
vec2 position = ((vec2(aPosition) / uFramebufferSize[0].xy) * 2.0) - vec2(1.0);
gl_Position = vec4(position.x, -position.y, 0.0, 1.0);
}

30 changes: 7 additions & 23 deletions resources/shaders/gl3/debug_texture.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,15 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!












precision highp float;





uniform sampler2D uTexture;
uniform vec4 uColor;
uniform vec4 uColor[1];
uniform sampler2D SPIRV_Cross_CombineduTextureuSampler;

in vec2 vTexCoord;
layout(location = 0) out vec4 oFragColor;

out vec4 oFragColor;

void main(){
float alpha = texture(uTexture, vTexCoord). r * uColor . a;
oFragColor = alpha * vec4(uColor . rgb, 1.0);
void main()
{
float alpha = texture(SPIRV_Cross_CombineduTextureuSampler, vTexCoord).x * uColor[0].w;
oFragColor = vec4(uColor[0].xyz, 1.0) * alpha;
}

37 changes: 10 additions & 27 deletions resources/shaders/gl3/debug_texture.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,16 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!












precision highp float;





uniform vec2 uFramebufferSize;
uniform vec2 uTextureSize;

in ivec2 aPosition;
in ivec2 aTexCoord;

uniform vec4 uTextureSize[1];
uniform vec4 uFramebufferSize[1];
out vec2 vTexCoord;

void main(){
vTexCoord = vec2(aTexCoord)/ uTextureSize;
vec2 position = vec2(aPosition)/ uFramebufferSize * 2.0 - 1.0;
gl_Position = vec4(position . x, - position . y, 0.0, 1.0);
layout(location = 1) in ivec2 aTexCoord;
layout(location = 0) in ivec2 aPosition;

void main()
{
vTexCoord = vec2(aTexCoord) / uTextureSize[0].xy;
vec2 position = ((vec2(aPosition) / uFramebufferSize[0].xy) * 2.0) - vec2(1.0);
gl_Position = vec4(position.x, -position.y, 0.0, 1.0);
}

Loading