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
15.15k stars 1.95k forks source link

Feature Request: Allow shaderc to specify output type #3001

Open cykoder opened 1 year ago

cykoder commented 1 year ago

Currenly the output type is just hardcoded to vec4, I have a use case where I want to write to uint textures. In GLSL its possible to do like:

#if BGFX_SHADER_LANGUAGE_GLSL >= 400
out uvec2 visibility;
#endif

But theres no way to do this for SPIRV/HLSL this way. It also does not allow overriding of void main() for HLSL shaders, which could also be a solution to this issue. Example:

#if BGFX_SHADER_LANGUAGE_SPIRV > 0
void main(float4 gl_FragCoord : SV_POSITION , nointerpolation int2 v_bufferIDs : TEXCOORD6 , out uvec2 bgfx_FragData0 : SV_TARGET0 , uint gl_PrimitiveID : SV_PrimitiveID ) {
  uint instanceID = uint(v_bufferIDs.x);
  uint triangleID = uint(gl_PrimitiveID);
  bgfx_FragData0 = uvec2(triangleID, (instanceID + 1));
}
#else
// glsl code
#endif
bkaradzic commented 1 year ago

Why solution is multiple mains and #ifdefery when it could be just providing ability to set FragData type?

cykoder commented 1 year ago

I would prefer the ability to set the FragData type of course, just mentioning that can also be another solution + it may be helpful in other scenarios whereby user wishes to define more inputs that BGFX doesnt generate. Could be seen as two separate issues but one also helps fix the other, albeit with hacky ifdefs

bkaradzic commented 1 year ago

You could already have this hacky shader with GLSL if you use --raw argument.