Here's my C++ code that converts HLSL to GLSL:
const shaderc::Compiler scompiler;
shaderc::CompileOptions soptions;
soptions.SetSourceLanguage(shaderc_source_language_hlsl);
soptions.SetOptimizationLevel(shaderc_optimization_level_performance);
soptions.SetIncluder(std::make_unique<MyIncluder>(includer));
soptions.SetAutoSampledTextures(true);
soptions.SetGenerateDebugInfo();
const shaderc::SpvCompilationResult vertex_result = scompiler.CompileGlslToSpv(
source, shaderc_vertex_shader, name, vert_entry, soptions);
const shaderc::SpvCompilationResult fragment_result = scompiler.CompileGlslToSpv(
source, shaderc_fragment_shader, name, frag_entry, soptions);
const std::vector spirv_vert(vertex_result.cbegin(), vertex_result.cend()),
const std::vector spirv_frag(fragment_result.cbegin(), fragment_result.cend()),
spirv_cross::CompilerGLSL gcompiler(source);
spirv_cross::CompilerGLSL::Options goptions;
goptions.version = 330;
goptions.enable_row_major_load_workaround = false;
goptions.emit_uniform_buffer_as_plain_uniforms = true;
gcompiler.set_common_options(goptions);
std::cout << gcompilerpile();
Here's the input HLSL:
struct VertexInput {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
};
struct VertexOutput {
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
Texture2D mainTexture;
SamplerState mainTextureSampler;
VertexOutput vertShader(VertexInput input) {
VertexOutput output;
output.position = input.position;
output.texcoord = input.texcoord;
return output;
};
float4 fragShader(VertexOutput input) : SV_TARGET {
return mainTexture.Sample(mainTextureSampler, input.texcoord);
};
This gives me the following vertex and fragment shader output in GLSL:
#version 330
#ifdef GL_ARB_shading_language_420pack
#extension GL_ARB_shading_language_420pack : require
#endif
layout(location = 0) in vec4 input_position;
layout(location = 1) in vec2 input_texcoord;
out vec2 _entryPointOutput_texcoord;
void main()
{
gl_Position = input_position;
_entryPointOutput_texcoord = input_texcoord;
}
#version 330
#ifdef GL_ARB_shading_language_420pack
#extension GL_ARB_shading_language_420pack : require
#endif
layout(binding = 0) uniform sampler2D mainTexture;
in vec2 input_texcoord;
layout(location = 0) out vec4 _entryPointOutput;
void main()
{
_entryPointOutput = texture(mainTexture, input_texcoord);
}
When compiling these shaders using OpenGL, it complains that input_texcoord
is not set in the fragment shader. This is because the output variable from the vertex shader _entryPointOutput_texcoord
has a different name.
How can I get shaderc/SPIRV-Cross to keep the in/out names consistent between the vertex and fragment shaders?