@@ -4083,30 +4083,32 @@ string CompilerGLSL::to_function_name(uint32_t tex, const SPIRType &imgtype, boo
40834083 return is_legacy () ? legacy_tex_op (fname, imgtype, lod, tex) : fname;
40844084}
40854085
4086- std::string CompilerGLSL::convert_separate_image_to_combined (uint32_t id)
4086+ std::string CompilerGLSL::convert_separate_image_to_expression (uint32_t id)
40874087{
4088- auto &imgtype = expression_type (id);
40894088 auto *var = maybe_get_backing_variable (id);
40904089
4091- // If we are fetching from a plain OpTypeImage, we must combine with a dummy sampler.
4090+ // If we are fetching from a plain OpTypeImage, we must combine with a dummy sampler in GLSL.
4091+ // In Vulkan GLSL, we can make use of the newer GL_EXT_samplerless_texture_functions.
40924092 if (var)
40934093 {
40944094 auto &type = get<SPIRType>(var->basetype );
40954095 if (type.basetype == SPIRType::Image && type.image .sampled == 1 && type.image .dim != DimBuffer)
40964096 {
4097- if (!dummy_sampler_id)
4098- SPIRV_CROSS_THROW (
4099- " Cannot find dummy sampler ID. Was build_dummy_sampler_for_combined_images() called?" );
4100-
41014097 if (options.vulkan_semantics )
41024098 {
4103- auto sampled_type = imgtype;
4104- sampled_type. basetype = SPIRType::SampledImage;
4105- return join ( type_to_glsl (sampled_type), " ( " , to_expression (id), " , " , to_expression (dummy_sampler_id),
4106- " ) " );
4099+ // Newer glslang supports this extension to deal with texture2D as argument to texture functions.
4100+ if (dummy_sampler_id)
4101+ SPIRV_CROSS_THROW ( " Vulkan GLSL should not have a dummy sampler for combining. " );
4102+ require_extension_internal ( " GL_EXT_samplerless_texture_functions " );
41074103 }
41084104 else
4105+ {
4106+ if (!dummy_sampler_id)
4107+ SPIRV_CROSS_THROW (
4108+ " Cannot find dummy sampler ID. Was build_dummy_sampler_for_combined_images() called?" );
4109+
41094110 return to_combined_image_sampler (id, dummy_sampler_id);
4111+ }
41104112 }
41114113 }
41124114
@@ -4121,7 +4123,7 @@ string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &imgtype, boo
41214123{
41224124 string farg_str;
41234125 if (is_fetch)
4124- farg_str = convert_separate_image_to_combined (img);
4126+ farg_str = convert_separate_image_to_expression (img);
41254127 else
41264128 farg_str = to_expression (img);
41274129
@@ -7526,7 +7528,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
75267528 if (options.es )
75277529 SPIRV_CROSS_THROW (" textureQueryLevels not supported in ES profile." );
75287530
7529- auto expr = join (" textureQueryLevels(" , convert_separate_image_to_combined (ops[2 ]), " )" );
7531+ auto expr = join (" textureQueryLevels(" , convert_separate_image_to_expression (ops[2 ]), " )" );
75307532 auto &restype = get<SPIRType>(ops[0 ]);
75317533 expr = bitcast_expression (restype, SPIRType::Int, expr);
75327534 emit_op (result_type, id, expr, true );
@@ -7543,7 +7545,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
75437545 if (type.image .sampled == 2 )
75447546 expr = join (" imageSamples(" , to_expression (ops[2 ]), " )" );
75457547 else
7546- expr = join (" textureSamples(" , convert_separate_image_to_combined (ops[2 ]), " )" );
7548+ expr = join (" textureSamples(" , convert_separate_image_to_expression (ops[2 ]), " )" );
75477549
75487550 auto &restype = get<SPIRType>(ops[0 ]);
75497551 expr = bitcast_expression (restype, SPIRType::Int, expr);
@@ -7564,7 +7566,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
75647566 uint32_t result_type = ops[0 ];
75657567 uint32_t id = ops[1 ];
75667568
7567- auto expr = join (" textureSize(" , convert_separate_image_to_combined (ops[2 ]), " , " ,
7569+ auto expr = join (" textureSize(" , convert_separate_image_to_expression (ops[2 ]), " , " ,
75687570 bitcast_expression (SPIRType::Int, ops[3 ]), " )" );
75697571 auto &restype = get<SPIRType>(ops[0 ]);
75707572 expr = bitcast_expression (restype, SPIRType::Int, expr);
@@ -7783,7 +7785,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
77837785 else
77847786 {
77857787 // This path is hit for samplerBuffers and multisampled images which do not have LOD.
7786- expr = join (" textureSize(" , convert_separate_image_to_combined (ops[2 ]), " )" );
7788+ expr = join (" textureSize(" , convert_separate_image_to_expression (ops[2 ]), " )" );
77877789 }
77887790
77897791 auto &restype = get<SPIRType>(ops[0 ]);
@@ -9282,8 +9284,7 @@ void CompilerGLSL::branch(uint32_t from, uint32_t to)
92829284 // Only sensible solution is to make a ladder variable, which we declare at the top of the switch block,
92839285 // write to the ladder here, and defer the break.
92849286 // The loop we're breaking out of must dominate the switch block, or there is no ladder breaking case.
9285- if (current_emitting_switch && is_loop_break (to) &&
9286- current_emitting_switch->loop_dominator != -1u &&
9287+ if (current_emitting_switch && is_loop_break (to) && current_emitting_switch->loop_dominator != -1u &&
92879288 get<SPIRBlock>(current_emitting_switch->loop_dominator ).merge_block == to)
92889289 {
92899290 if (!current_emitting_switch->need_ladder_break )
0 commit comments