c++ - When converting HLSL to GLSL with shaderc and SPIRV-Cross, how can I keep inout variable names consistent? - Stack Overflo

Here's my C++ code that converts HLSL to GLSL:const shaderc::Compiler scompiler;shaderc::CompileO

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744727098a4590245.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信