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

error X4502: invalid input semantic 'POSITION': Legal indices are in [1,15] #12

Closed
jeremieroy opened this issue Feb 13, 2013 · 10 comments
Closed

Comments

@jeremieroy
Copy link
Contributor

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:

$input a_position, a_normal, a_color0
$output v_normal, v_color0

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

#include "common.sh"

void main()
{
    gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );
    v_normal = mul(u_model, vec4(a_normal, 0.0) ).xyz;
    v_color0 = a_color0;
}

where common.sh is bgfx common file (that includes bgfx_shader.sh)

My shaderc command line is: (with path simplified for readability)

shaderc.exe -f shaders/vs_gwen.sc -o out/shaders/windows/vs_gwen.bin --type v 
--platform windows --varyingdef H:/GitHub/bgfx/src/varying.def.sc -p ps_3_0

I got this result:

Code:

---
  1: struct Output
  2: {
  3: float4 gl_Position : SV_POSITION;
  4: float4 v_color0 : COLOR0;
  5: float3 v_normal : TEXCOORD1;
  6: };
  7: float3 instMul(float3 _vec, float3x3 _mtx) { return mul(_mtx, _vec); }
  8: float3 instMul(float3x3 _mtx, float3 _vec) { return mul(_vec, _mtx); }
  9: float4 instMul(float4 _vec, float4x4 _mtx) { return mul(_mtx, _vec); }
 10: float4 instMul(float4x4 _mtx, float4 _vec) { return mul(_vec, _mtx); }
 11: bool2 lessThan(float2 _a, float2 _b) { return _a < _b; }
 12: bool3 lessThan(float3 _a, float3 _b) { return _a < _b; }
 13: bool4 lessThan(float4 _a, float4 _b) { return _a < _b; }
 14: bool2 lessThanEqual(float2 _a, float2 _b) { return _a <= _b; }
 15: bool2 lessThanEqual(float3 _a, float3 _b) { return _a <= _b; }
 16: bool2 lessThanEqual(float4 _a, float4 _b) { return _a <= _b; }
 17: bool2 greaterThan(float2 _a, float2 _b) { return _a > _b; }
 18: bool3 greaterThan(float3 _a, float3 _b) { return _a > _b; }
 19: bool4 greaterThan(float4 _a, float4 _b) { return _a > _b; }
 20: bool2 greaterThanEqual(float2 _a, float2 _b) { return _a >= _b; }
 21: bool3 greaterThanEqual(float3 _a, float3 _b) { return _a >= _b; }
 22: bool4 greaterThanEqual(float4 _a, float4 _b) { return _a >= _b; }
 23: bool2 notEqual(float2 _a, float2 _b) { return _a != _b; }
 24: bool3 notEqual(float3 _a, float3 _b) { return _a != _b; }
 25: bool4 notEqual(float4 _a, float4 _b) { return _a != _b; }
 26: bool2 equal(float2 _a, float2 _b) { return _a == _b; }
 27: bool3 equal(float3 _a, float3 _b) { return _a == _b; }
 28: bool4 equal(float4 _a, float4 _b) { return _a == _b; }
 29: float2 mix(float2 _a, float2 _b, float2 _t) { return lerp(_a, _b, _t); }
 30: float3 mix(float3 _a, float3 _b, float3 _t) { return lerp(_a, _b, _t); }
 31: float4 mix(float4 _a, float4 _b, float4 _t) { return lerp(_a, _b, _t); }
 32: uniform float4x4 u_view;
 33: uniform float4x4 u_viewProj;
 34: uniform float4x4 u_model;
 35: uniform float4x4 u_modelView;
 36: uniform float4x4 u_modelViewProj;
 37: uniform float4x4 u_modelViewProjX;
 38: uniform float4x4 u_viewProjX;
 39: Output main(float4 a_color0 : COLOR0 , float3 a_normal : NORMAL0 , float3 a_position : POSITION) { Output _varying_; _varying_.v_color0 = float4(
1.0, 0.0, 0.0, 1.0); _varying_.v_normal = float3(0.0, 1.0, 0.0);
 40: {
 41: _varying_.gl_Position = mul(u_modelViewProj, float4(a_position, 1.0) );
 42: _varying_.v_normal = mul(u_model, float4(a_normal, 0.0) ).xyz;
 43: _varying_.v_color0 = a_color0;
 44: } return _varying_;
 45: }

---

Error: 0x80004005 H:\GitHub\bgfxGWEN\premake\memory(15,45): warning X3206: implicit truncation of vector type
H:\GitHub\bgfxGWEN\premake\memory(16,45): warning X3206: implicit truncation of vector type
H:\GitHub\bgfxGWEN\premake\memory(39,88): error X4502: invalid input semantic 'POSITION': Legal indices are in [1,15]
H:\GitHub\bgfxGWEN\premake\memory(39,88): error X4502: invalid ps_3_0 input semantic 'POSITION'
H:\GitHub\bgfxGWEN\premake\memory(3,22): error X4502: invalid ps_3_0 output semantic 'SV_POSITION'
H:\GitHub\bgfxGWEN\premake\memory(5,19): error X4502: invalid ps_3_0 output semantic 'TEXCOORD1'

Failed to build shader.

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 ?

@jeremieroy
Copy link
Contributor Author

(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 ...)

@bkaradzic
Copy link
Owner

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.

@bkaradzic
Copy link
Owner

Fixed 391ebae

@jeremieroy
Copy link
Contributor Author

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.

@bkaradzic
Copy link
Owner

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.

@jeremieroy
Copy link
Contributor Author

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 ^^'

@bkaradzic
Copy link
Owner

I'm going to fix that. Thanks for reporting these issues, it will make it better for others who try it. :)

@jeremieroy
Copy link
Contributor Author

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.

@bkaradzic
Copy link
Owner

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.

@bkaradzic
Copy link
Owner

Fixed cc69b20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants