Closed jeremieroy closed 11 years ago
(As a side note ), I think there is a small error in shaderc documentation. -p, --profile Shader model (f.e. ps_3_0).\n" The line above suggest that you can use either -p or --profile to define the shader model. However, only the "-p" keyword is valid. "--profile" seems to be only checked at the beginning. See f.e. shaderc.cpp line 552. in( compileHLSLShaderDx9 ). (I may have overlooked something but if I try to use the "profile" keyword, shaderc ask me to declare a profile so ...)
The best way to setup shader compiling is by using makefile. It does everything you need, you just call make TARGET=<#> to compile for target platform. See: https://github.com/bkaradzic/bgfx/blob/master/examples/01-cubes/makefile
It uses: https://github.com/bkaradzic/bgfx/blob/master/premake/shader.mk
I'm going to look -p, --profile inconsistency you mentioned.
The makefile works fine. Thanks a lot :) In the meantime, I ported it to premake so that a single build system ca be used. (it also ease deployment) (E.g. make shader compilation a part of the projects generation pass) In case you are interested, it's there: see: bgfx_compile_shader.lua https://github.com/jeremieroy/bgfxGWEN/tree/master/premake
It is used like this in my premake.lua file:
dofile "bgfx_compile_shader.lua"
function compileShaders()
bgfx_compile_shader(INPUT_SHADERS_DIR, ENV_DIR, BUILD_DIR, "dx9" )
bgfx_compile_shader(INPUT_SHADERS_DIR, ENV_DIR, BUILD_DIR, "dx11" )
bgfx_compile_shader(INPUT_SHADERS_DIR, ENV_DIR, BUILD_DIR, "nacl" )
bgfx_compile_shader(INPUT_SHADERS_DIR, ENV_DIR, BUILD_DIR, "android" )
bgfx_compile_shader(INPUT_SHADERS_DIR, ENV_DIR, BUILD_DIR, "linux" )
end
However, I didn't get exactly what the dependencies are supposed to do. (files with .bin.d) (recursive call to make ?) Didn't find a sample that use it in the bgfx repo. I'll update my premake file once I get it.
bgfx shaders can include files, dependencies (it's standard makefile dependency functionality) are there to recognize changes and rebuild all affected shaders. For example if you include shaderlib.sh and use it in your shaders, once new functionality is added to shaderlib.sh all shaders that depend on it will be rebuilt.
It make sense. I'll look how to do it with premake. Another minor issue (that doesn't necessary require a fix) I encountered: Shader file compiled with shaderc must contains a final endline. If it doesn't it refuse to compile with a :"error X3000: syntax error: unexpected end of file"
While I understand that this is part of the posix standard definition of a text file, (for good legit reasons) many text editors don't do it by default. (I'm using SublimeText2) And when you encounter the issue, it's not obvious to understand what is wrong. (could be a bracket, a macro issue etc...) I think this could be very easily handled in shaderc, (e.g. after loading the file, add a trailing newline if it is missing. Or throw an explicit error message. )
However, this is not a big deal ^^'
I'm going to fix that. Thanks for reporting these issues, it will make it better for others who try it. :)
You're welcome. But you are the one to deserve the praise, your code is beautiful :)
Another (minor) issue: adding "void" in the main function of a shader return a random error. (while this is legit glsl code)
void main(void)
{
float dist = texture2D(u_texColor, v_texcoord0.xy).a;
return a random error
void main()
{
float dist = texture2D(u_texColor, v_texcoord0.xy).a;
works fine.
Thanks! :)
Yeah bgfx shader although it looks like GLSL should not be considered 100% GLSL, because it's HLSL code when compiling for DX9 and DX11. I just used preprocessor trickery to unify all those and have single shader source code. "void main()" is "special" keyword... I'll add better error message if "void main()" doesn't exist.
I'm struggling to make shaderc to work :(
I'm trying to compile a simple vs with only the stock shader file from bgfx but failed so far.
The shader:
where common.sh is bgfx common file (that includes bgfx_shader.sh)
My shaderc command line is: (with path simplified for readability)
I got this result:
I tried various profile but everything seems to fail so far. I'm doing something wrong but ran of out idea to try. Any hint ?