bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
14.86k stars 1.93k forks source link

shaderc: Add texelFetch #725

Open zlash opened 8 years ago

bkaradzic commented 8 years ago

Not everywhere right now. If you're using GLSL you can use it, HLSL needs some work to get equivalents.

zlash commented 8 years ago

I'm targeting glsl, however, with shaderc it fails with: Error: (26,16): error: no matching function for call to 'texelFetch(sampler2D, vec2)'; Is there any way to use with shaderc, or I need to use pure glsl shaders?

bkaradzic commented 8 years ago

Change version to 130: https://github.com/bkaradzic/bgfx/blob/master/scripts/shader.mk#L50

zlash commented 8 years ago

Thanks, and sorry keep coming to ask questions, but I'm having problems making it work. After bumping version to 130, now I get:

####
#define lowp
#define mediump
#define highp
#define flat
#define smooth
#define noperspective
in vec4 a_color0;
in vec3 a_position;
out vec4 v_color0;
uniform mat4 u_modelViewProj;
void main ()
{
  vec4 tmpvar_1;
  tmpvar_1.w = 1.0;
  tmpvar_1.xyz = a_position;
  gl_Position = (u_modelViewProj * tmpvar_1);
  v_color0 = a_color0;
}

####
../../../src/renderer_gl.cpp (4968): BGFX Failed to compile shader. 0: 0(9) : error C5060: out can't be used with non-varying v_color0

../../../src/bgfx.cpp (85): BGFX 0x00000002: Failed to compile shader.

I rebuilt bgfx with BGFX_CONFIG_RENDERER_OPENGL=30 and still the same error.

This is the vs (It's a copy paste of one of the examples, and it was working before bumping the verson to 130)

$input a_position, a_color0
$output v_color0

/*
 * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
 * License: http://www.opensource.org/licenses/BSD-2-Clause
 */

#include <bgfx_shader.sh>

void main()
{
    gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
    v_color0 = a_color0;
}

And the varying.def.sc


vec4 v_color0    : COLOR0    = vec4(1.0, 0.0, 0.0, 1.0);
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);

vec3 a_position   : POSITION;
vec4 a_color0     : COLOR0;
vec2 a_texcoord0  : TEXCOORD0;
bkaradzic commented 8 years ago

I just tested it and not getting it. Is this AMD GPU?

P.S. I added texelFetch for D3D11.

zlash commented 8 years ago

NVidia on Debian with propietary drivers, using glfw for Window Management. I found an related issue #92 . Sadly, the OP, fixed it reverting it to 120. I'll try to get more info with the debugger when I come home at night. Thanks.

zlash commented 8 years ago

The problems seems to originate from the lack of of a #version directive in the generated glsl code. Compiler creation seems to be taking this path: https://github.com/bkaradzic/bgfx/blob/00b3fbb8cb189f51a95039a12c1a5257c32859ed/src/renderer_gl.cpp#L4821 and not triggering any of the conditions for adding the "#version" line. Shouldn't it take the glsl version from the output of shaderc if its present instead of always guessing it? (I'll try to investigate furthermore why it's taking that path, I put defines { "BGFX_CONFIG_RENDERER_OPENGL=30" } in genie.lua but it seems it's not doing much effect)

zlash commented 8 years ago

Sorry if this seems messy, but I'm adding stuff as I find out. Setting BGFX_CONFIG_RENDERER_OPENGL=30 causes the shader compiler to fail at all. If you see the flow I linked in the previous message, there is no case covering "30", so nothing gets written to "bx::StaticMemoryBlockWriter writer" and trash is sent to the compiler.

zlash commented 8 years ago

So, this is what I gathered so far:

bkaradzic commented 8 years ago

Check latest build. I'll fix this between version issue.