yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
62f5430e
vulkan-sdk-1.4.357.0
1// Copyright (C) 2026 NVIDIA Corporation. 2// 3// All rights reserved. 4// 5// Redistribution and use in source and binary forms, with or without 6// modification, are permitted provided that the following conditions 7// are met: 8// 9// Redistributions of source code must retain the above copyright 10// notice, this list of conditions and the following disclaimer. 11// 12// Redistributions in binary form must reproduce the above 13// copyright notice, this list of conditions and the following 14// disclaimer in the documentation and/or other materials provided 15// with the distribution. 16// 17// Neither the name of 3Dlabs Inc. Ltd. nor the names of its 18// contributors may be used to endorse or promote products derived 19// from this software without specific prior written permission. 20// 21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32// POSSIBILITY OF SUCH DAMAGE. 33 34// Tests for NonSemantic.Shader.DebugInfo (NSDI) features. 35 36#include "TestFixture.h" 37#include "SPIRV/NonSemanticShaderDebugInfo.h" 38#include "glslang/Public/ResourceLimits.h" 39#include <gtest/gtest.h> 40#include <cstdint> 41#include <sstream> 42#include <string> 43#include <vector> 44 45namespace glslangtest { 46namespace { 47 48std :: string decodeLiteralString ( const uint32_t * words , size_t wordCount ) 49{ 50std :: string result ; 51for ( size_t wordIndex = 0 ; wordIndex < wordCount ; ++ wordIndex ) { 52for ( unsigned int byteIndex = 0 ; byteIndex < 4 ; ++ byteIndex ) { 53const char character = static_cast < char > (( words [ wordIndex ] >> ( 8 * byteIndex )) & 0xff ) ; 54if ( character == ' \0 ' ) 55return result ; 56result . push_back ( character ) ; 57} 58} 59return result ; 60} 61 62bool containsDebugTypeBasic ( const std :: vector < uint32_t >& spirv , const char * expectedName , 63uint32_t expectedWidth , spv :: FPEncoding expectedFPEncoding ) 64{ 65if ( spirv . size () < 5 || spirv [ 0 ] != spv :: MagicNumber ) 66return false ; 67 68const uint32_t idBound = spirv [ 3 ] ; 69std :: vector < std :: string > strings ( idBound ) ; 70std :: vector < uint32_t > constants ( idBound ) ; 71std :: vector < bool > isConstant ( idBound ) ; 72uint32_t debugInfoImportId = 0 ; 73 74size_t end = spirv . size () ; 75 76// Resolve the IDs referenced by DebugTypeBasic before inspecting the instruction itself. 77// OpExtInstImport gives the result ID used to select the .101 debug-info instruction set, 78// OpString gives the source-level type name, and OpConstant gives the values of the width, 79// base encoding, flags, and optional FPEncoding operands. 80// 81// For example, the relevant SPIR-V for floate2m1_t has this shape: 82// %debug = OpExtInstImport "NonSemantic.Shader.DebugInfo.101" 83// %name = OpString "floate2m1_t" 84// %width = OpConstant %uint 4 85// %encoding = OpConstant %uint 3 ; NonSemanticShaderDebugInfoFloat 86// %flags = OpConstant %uint 0 ; NonSemanticShaderDebugInfoNone 87// %fpEncoding = OpConstant %uint 4225 ; Float4E2M1EXT 88// %type = OpExtInst %void %debug DebugTypeBasic 89// %name %width %encoding %flags %fpEncoding 90for ( size_t offset = 5 ; offset < spirv . size () ; ) { 91const uint32_t wordCount = spirv [ offset ] >> spv :: WordCountShift ; 92const spv :: Op opcode = static_cast < spv :: Op > ( spirv [ offset ] & spv :: OpCodeMask ) ; 93if ( wordCount == 0 || offset + wordCount > spirv . size ()) 94return false ; 95 96if ( opcode == spv :: Op :: OpFunction ) { 97// SPIR-V's logical layout places imports, debug strings, constants, and global 98// debug-type instructions before the first OpFunction. Record that boundary while 99// resolving IDs so this pass can exit early and the subsequent DebugTypeBasic scan 100// can stop there as well. 101end = offset ; 102break ; 103} 104 105if ( opcode == spv :: Op :: OpExtInstImport && wordCount >= 3 ) { 106const uint32_t resultId = spirv [ offset + 1 ] ; 107if ( resultId < idBound && 108decodeLiteralString ( & spirv [ offset + 2 ] , wordCount - 2 ) == 109"NonSemantic.Shader.DebugInfo.101" ) { 110debugInfoImportId = resultId ; 111} 112} else if ( opcode == spv :: Op :: OpString && wordCount >= 3 ) { 113const uint32_t resultId = spirv [ offset + 1 ] ; 114if ( resultId < idBound ) 115strings [ resultId ] = decodeLiteralString ( & spirv [ offset + 2 ] , wordCount - 2 ) ; 116} else if ( opcode == spv :: Op :: OpConstant && wordCount == 4 ) { 117const uint32_t resultId = spirv [ offset + 2 ] ; 118if ( resultId < idBound ) { 119constants [ resultId ] = spirv [ offset + 3 ] ; 120isConstant [ resultId ] = true ; 121} 122} 123 124offset += wordCount ; 125} 126 127if ( debugInfoImportId == 0 ) 128return false ; 129 130const auto hasConstantValue = [ & ]( uint32_t id , uint32_t value ) { 131return id < idBound && isConstant [ id ] && constants [ id ] == value ; 132} ; 133 134// A DebugTypeBasic with an FPEncoding has five operands after its instruction number: 135// Name, Size, Encoding, Flags, and FPEncoding. Including the five-word OpExtInst prefix, 136// that gives a word count of 10. Match the imported .101 instruction set and resolve each 137// operand ID through the OpString and OpConstant tables populated above. 138for ( size_t offset = 5 ; offset < end ; ) { 139const uint32_t wordCount = spirv [ offset ] >> spv :: WordCountShift ; 140const spv :: Op opcode = static_cast < spv :: Op > ( spirv [ offset ] & spv :: OpCodeMask ) ; 141if ( wordCount == 0 || offset + wordCount > spirv . size ()) 142return false ; 143 144if ( opcode == spv :: Op :: OpExtInst && wordCount == 10 && 145spirv [ offset + 3 ] == debugInfoImportId && 146spirv [ offset + 4 ] == NonSemanticShaderDebugInfoDebugTypeBasic ) { 147const uint32_t nameId = spirv [ offset + 5 ] ; 148const uint32_t widthId = spirv [ offset + 6 ] ; 149const uint32_t encodingId = spirv [ offset + 7 ] ; 150const uint32_t flagsId = spirv [ offset + 8 ] ; 151const uint32_t fpEncodingId = spirv [ offset + 9 ] ; 152if ( nameId < idBound && strings [ nameId ] == expectedName && 153hasConstantValue ( widthId , expectedWidth ) && 154hasConstantValue ( encodingId , NonSemanticShaderDebugInfoFloat ) && 155hasConstantValue ( flagsId , NonSemanticShaderDebugInfoNone ) && 156hasConstantValue ( fpEncodingId , static_cast < uint32_t > ( expectedFPEncoding ))) { 157return true ; 158} 159} 160 161offset += wordCount ; 162} 163 164return false ; 165} 166 167class SpvDebugInfoTest : public :: testing :: Test { 168protected : 169bool compileToSpirvWithDebugInfo ( const std :: string & source , std :: vector < uint32_t >& spirv , 170std :: string & error ) 171{ 172spirv . clear () ; 173error . clear () ; 174glslang :: TShader shader ( EShLangCompute ) ; 175const char * str = source . c_str () ; 176shader . setStrings ( & str , 1 ) ; 177shader . setEnvInput ( glslang :: EShSourceGlsl , EShLangCompute , 178glslang :: EShClientVulkan , 110 ) ; 179shader . setEnvClient ( glslang :: EShClientVulkan , glslang :: EShTargetVulkan_1_1 ) ; 180shader . setEnvTarget ( glslang :: EShTargetSpv , glslang :: EShTargetSpv_1_3 ) ; 181 182EShMessages messages = static_cast < EShMessages > ( EShMsgDefault | EShMsgDebugInfo ) ; 183if ( ! shader . parse ( GetDefaultResources () , 450 , false , messages )) { 184error = "COMPILATION_FAILED: " + std :: string ( shader . getInfoLog ()) ; 185return false ; 186} 187 188glslang :: TProgram program ; 189program . addShader ( & shader ) ; 190if ( ! program . link ( messages )) { 191error = "LINKING_FAILED: " + std :: string ( program . getInfoLog ()) ; 192return false ; 193} 194 195glslang :: SpvOptions opts ; 196opts . generateDebugInfo = true ; 197opts . emitNonSemanticShaderDebugInfo = true ; 198opts . disableOptimizer = true ; 199 200glslang :: GlslangToSpv ( * program . getIntermediate ( EShLangCompute ) , spirv , & opts ) ; 201return true ; 202} 203 204// Compile a GLSL compute shader with NonSemantic debug info enabled, targeting 205// Vulkan 1.1 / SPIR-V 1.3, and return the disassembly. 206std :: string compileWithDebugInfo ( const std :: string & source ) 207{ 208std :: vector < uint32_t > spirv ; 209std :: string error ; 210if ( ! compileToSpirvWithDebugInfo ( source , spirv , error )) 211return error ; 212 213std :: ostringstream out ; 214spv :: Disassemble ( out , spirv ) ; 215return out . str () ; 216} 217} ; 218 219// DebugTypeVectorIdEXT (opcode 109) must be emitted for OpTypeCooperativeVectorNV 220// when NonSemantic debug info is enabled. 221TEST_F ( SpvDebugInfoTest , CooperativeVectorNVEmitsDebugTypeVectorIdEXT ) 222{ 223const std :: string source = R"( 224#version 450 core 225#extension GL_KHR_memory_scope_semantics : enable 226#extension GL_NV_cooperative_vector : enable 227#extension GL_EXT_shader_explicit_arithmetic_types : enable 228layout(local_size_x = 64) in; 229layout(set = 0, binding = 0) buffer B { float data[]; } buf; 230void main() { 231coopvecNV<float, 8> v = coopvecNV<float, 8>(0.0); 232v = v + v; 233buf.data[gl_GlobalInvocationID.x] = v[0]; 234} 235)" ; 236std :: string spirv = compileWithDebugInfo ( source ) ; 237EXPECT_NE ( spirv . find ( "DebugTypeVectorIdEXT" ) , std :: string :: npos ) 238<< "Expected DebugTypeVectorIdEXT in disassembly. \n SPIR-V: \n " << spirv ; 239EXPECT_NE ( spirv . find ( "TypeCooperativeVectorNV" ) , std :: string :: npos ) 240<< "Expected TypeCooperativeVectorNV in disassembly. \n SPIR-V: \n " << spirv ; 241} 242 243// DebugTypeVectorIdEXT must also be emitted when the component count is a 244// specialization constant (OpSpecConstant), since the spec allows any constant 245// instruction for the ComponentCount operand. 246TEST_F ( SpvDebugInfoTest , CooperativeVectorNVSpecConstCountEmitsDebugTypeVectorIdEXT ) 247{ 248const std :: string source = R"( 249#version 450 core 250#extension GL_KHR_memory_scope_semantics : enable 251#extension GL_NV_cooperative_vector : enable 252#extension GL_EXT_shader_explicit_arithmetic_types : enable 253layout(local_size_x = 64) in; 254layout(constant_id = 0) const uint N = 16; 255layout(set = 0, binding = 0) buffer B { float data[]; } buf; 256void main() { 257coopvecNV<float, N> v = coopvecNV<float, N>(1.0); 258buf.data[gl_GlobalInvocationID.x] = v[0]; 259} 260)" ; 261std :: string spirv = compileWithDebugInfo ( source ) ; 262EXPECT_NE ( spirv . find ( "DebugTypeVectorIdEXT" ) , std :: string :: npos ) 263<< "Expected DebugTypeVectorIdEXT with spec-constant count. \n SPIR-V: \n " << spirv ; 264} 265 266// DebugTypeCooperativeMatrixKHR (opcode 110) must replace the former 267// opaque-composite workaround for OpTypeCooperativeMatrixKHR. 268TEST_F ( SpvDebugInfoTest , CooperativeMatrixKHREmitsDebugTypeCooperativeMatrixKHR ) 269{ 270const std :: string source = R"( 271#version 450 core 272#pragma use_vulkan_memory_model 273#extension GL_KHR_memory_scope_semantics : enable 274#extension GL_KHR_cooperative_matrix : enable 275#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable 276layout(local_size_x = 32) in; 277layout(set = 0, binding = 0) buffer B { float16_t data[]; } buf; 278void main() { 279coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> m = 280coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(float16_t(0.0)); 281coopMatStore(m, buf.data, 0, 0, gl_CooperativeMatrixLayoutRowMajor); 282} 283)" ; 284std :: string spirv = compileWithDebugInfo ( source ) ; 285EXPECT_NE ( spirv . find ( "DebugTypeCooperativeMatrixKHR" ) , std :: string :: npos ) 286<< "Expected DebugTypeCooperativeMatrixKHR in disassembly. \n SPIR-V: \n " << spirv ; 287// The old opaque-composite workaround must not appear. 288EXPECT_EQ ( spirv . find ( "coopmat<" ) , std :: string :: npos ) 289<< "Opaque-composite workaround should not appear in disassembly. \n SPIR-V: \n " << spirv ; 290} 291 292// DebugTypeCooperativeMatrixKHR must be emitted when Rows and Columns are 293// specialization constants (OpSpecConstant), since the spec allows any constant 294// instruction for those operands. 295TEST_F ( SpvDebugInfoTest , CooperativeMatrixKHRSpecConstDimsEmitsDebugType ) 296{ 297const std :: string source = R"( 298#version 450 core 299#pragma use_vulkan_memory_model 300#extension GL_KHR_memory_scope_semantics : enable 301#extension GL_KHR_cooperative_matrix : enable 302#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable 303layout(local_size_x = 32) in; 304layout(constant_id = 0) const uint M = 16; 305layout(constant_id = 1) const uint N = 16; 306layout(set = 0, binding = 0) buffer B { float16_t data[]; } buf; 307void main() { 308coopmat<float16_t, gl_ScopeSubgroup, M, N, gl_MatrixUseAccumulator> m = 309coopmat<float16_t, gl_ScopeSubgroup, M, N, gl_MatrixUseAccumulator>(float16_t(0.0)); 310coopMatStore(m, buf.data, 0, 0, gl_CooperativeMatrixLayoutRowMajor); 311} 312)" ; 313std :: string spirv = compileWithDebugInfo ( source ) ; 314EXPECT_NE ( spirv . find ( "DebugTypeCooperativeMatrixKHR" ) , std :: string :: npos ) 315<< "Expected DebugTypeCooperativeMatrixKHR with spec-constant dims. \n SPIR-V: \n " << spirv ; 316} 317 318// DebugTypeCooperativeMatrixKHR must be emitted for each distinct (component, 319// scope, rows, cols, use) tuple -- MatrixUseA, MatrixUseB, and MatrixUseAccumulator 320// with different component types all produce separate debug type instructions. 321TEST_F ( SpvDebugInfoTest , CooperativeMatrixKHRMultipleUsesEmitDistinctDebugTypes ) 322{ 323const std :: string source = R"( 324#version 450 core 325#pragma use_vulkan_memory_model 326#extension GL_KHR_memory_scope_semantics : enable 327#extension GL_KHR_cooperative_matrix : enable 328#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable 329layout(local_size_x = 32) in; 330layout(set = 0, binding = 0) buffer B { float16_t data[]; } buf; 331void main() { 332coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseA> matA; 333coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseB> matB; 334coopmat<float, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> matC = 335coopmat<float, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(0.0); 336matC = coopMatMulAdd(matA, matB, matC); 337coopMatStore(matC, buf.data, 0, 0, gl_CooperativeMatrixLayoutRowMajor); 338} 339)" ; 340std :: string spirv = compileWithDebugInfo ( source ) ; 341 342// Count occurrences of DebugTypeCooperativeMatrixKHR: one for each distinct 343// (component, scope, rows, cols, use) combination used above. 344size_t count = 0 ; 345size_t pos = 0 ; 346while (( pos = spirv . find ( "DebugTypeCooperativeMatrixKHR" , pos )) != std :: string :: npos ) { 347++ count ; 348pos += 1 ; 349} 350EXPECT_GE ( count , 3u ) 351<< "Expected at least 3 DebugTypeCooperativeMatrixKHR instructions. \n SPIR-V: \n " << spirv ; 352} 353 354// The removed golden-file test spv.debuginfo.coopmatKHR.comp combined spec-constant 355// dimensions with all three matrix use types. Verify that distinct 356// DebugTypeCooperativeMatrixKHR instructions are emitted for MatrixUseA (lM x lK), 357// MatrixUseB (lK x lN), and MatrixUseAccumulator (lM x lN) when all dimensions are 358// specialization constants. 359TEST_F ( SpvDebugInfoTest , CooperativeMatrixKHRSpecConstDimsMultipleUsesEmitDistinctDebugTypes ) 360{ 361const std :: string source = R"( 362#version 450 core 363#pragma use_vulkan_memory_model 364#extension GL_KHR_memory_scope_semantics : enable 365#extension GL_KHR_cooperative_matrix : enable 366#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable 367layout(local_size_x = 32) in; 368layout(constant_id = 0) const uint lM = 16; 369layout(constant_id = 1) const uint lN = 16; 370layout(constant_id = 2) const uint lK = 16; 371layout(set = 0, binding = 0) buffer B { float data[]; } buf; 372void main() { 373coopmat<float16_t, gl_ScopeSubgroup, lM, lK, gl_MatrixUseA> matA; 374coopmat<float16_t, gl_ScopeSubgroup, lK, lN, gl_MatrixUseB> matB; 375coopmat<float, gl_ScopeSubgroup, lM, lN, gl_MatrixUseAccumulator> matC = 376coopmat<float, gl_ScopeSubgroup, lM, lN, gl_MatrixUseAccumulator>(0.0); 377matC = coopMatMulAdd(matA, matB, matC); 378coopMatStore(matC, buf.data, 0, 0, gl_CooperativeMatrixLayoutRowMajor); 379} 380)" ; 381std :: string spirv = compileWithDebugInfo ( source ) ; 382 383size_t count = 0 ; 384size_t pos = 0 ; 385while (( pos = spirv . find ( "DebugTypeCooperativeMatrixKHR" , pos )) != std :: string :: npos ) { 386++ count ; 387pos += 1 ; 388} 389EXPECT_GE ( count , 3u ) 390<< "Expected at least 3 DebugTypeCooperativeMatrixKHR instructions " 391"(one per use type with spec-constant dimensions). \n SPIR-V: \n " << spirv ; 392} 393 394// DebugTypeBasic for bfloat16_t must carry the debug type name "bfloat16_t", 395// which is emitted only when the FPEncoding operand (BFloat16KHR = 0) is present. 396TEST_F ( SpvDebugInfoTest , BFloat16EmitsDebugTypeBasicWithFPEncoding ) 397{ 398const std :: string source = R"( 399#version 450 core 400#extension GL_EXT_bfloat16 : require 401#extension GL_EXT_shader_explicit_arithmetic_types : enable 402layout(local_size_x = 64) in; 403layout(set = 0, binding = 0) buffer B { float data[]; } buf; 404void main() { 405bfloat16_t bf = bfloat16_t(1.0); 406buf.data[gl_GlobalInvocationID.x] = float(bf); 407} 408)" ; 409std :: string spirv = compileWithDebugInfo ( source ) ; 410// The DebugTypeBasic for bfloat16_t should contain the name "bfloat16_t". 411EXPECT_NE ( spirv . find ( " \" bfloat16_t \" " ) , std :: string :: npos ) 412<< "Expected \" bfloat16_t \" string in debug type. \n SPIR-V: \n " << spirv ; 413} 414 415// DebugTypeBasic for floate4m3_t must carry the debug type name "floate4m3_t", 416// which is emitted only when the FPEncoding operand (Float8E4M3EXT = 4214) is present. 417TEST_F ( SpvDebugInfoTest , Float8E4M3EmitsDebugTypeBasicWithFPEncoding ) 418{ 419const std :: string source = R"( 420#version 450 core 421#extension GL_EXT_bfloat16 : require 422#extension GL_EXT_float_e4m3 : require 423#extension GL_EXT_shader_explicit_arithmetic_types : enable 424layout(local_size_x = 64) in; 425layout(set = 0, binding = 0) buffer B { float data[]; } buf; 426void main() { 427floate4m3_t f = floate4m3_t(2.0); 428buf.data[gl_GlobalInvocationID.x] = float(f); 429} 430)" ; 431std :: string spirv = compileWithDebugInfo ( source ) ; 432EXPECT_NE ( spirv . find ( " \" floate4m3_t \" " ) , std :: string :: npos ) 433<< "Expected \" floate4m3_t \" string in debug type. \n SPIR-V: \n " << spirv ; 434} 435 436// DebugTypeBasic for floate5m2_t must carry the debug type name "floate5m2_t", 437// which is emitted only when the FPEncoding operand (Float8E5M2EXT = 4215) is present. 438TEST_F ( SpvDebugInfoTest , Float8E5M2EmitsDebugTypeBasicWithFPEncoding ) 439{ 440const std :: string source = R"( 441#version 450 core 442#extension GL_EXT_bfloat16 : require 443#extension GL_EXT_float_e5m2 : require 444#extension GL_EXT_shader_explicit_arithmetic_types : enable 445layout(local_size_x = 64) in; 446layout(set = 0, binding = 0) buffer B { float data[]; } buf; 447void main() { 448floate5m2_t f = floate5m2_t(3.0); 449buf.data[gl_GlobalInvocationID.x] = float(f); 450} 451)" ; 452std :: string spirv = compileWithDebugInfo ( source ) ; 453EXPECT_NE ( spirv . find ( " \" floate5m2_t \" " ) , std :: string :: npos ) 454<< "Expected \" floate5m2_t \" string in debug type. \n SPIR-V: \n " << spirv ; 455} 456 457// DebugTypeBasic for OCP microscaling types must carry their source-level type 458// names, which are emitted only when the FPEncoding operand is present. 459TEST_F ( SpvDebugInfoTest , OcpMicroscalingTypesEmitDebugTypeBasicWithFPEncoding ) 460{ 461const std :: string source = R"( 462#version 450 core 463#extension GL_EXT_float_e2m1 : require 464#extension GL_EXT_float_e3m2 : require 465#extension GL_EXT_float_e2m3 : require 466#extension GL_EXT_float_ue8m0 : require 467#extension GL_EXT_float_mxint8 : require 468#extension GL_EXT_shader_explicit_arithmetic_types : enable 469layout(local_size_x = 64) in; 470layout(set = 0, binding = 0) buffer B { float data[]; } buf; 471void main() { 472floate2m1_t e2m1 = floate2m1_t(1.0fe2m1); 473floate3m2_t e3m2 = floate3m2_t(1.0fe3m2); 474floate2m3_t e2m3 = floate2m3_t(1.0fe2m3); 475floatue8m0_t ue8m0 = floatue8m0_t(1.0fue8m0); 476floatmxint8_t mxint8 = floatmxint8_t(1.0fmxint8); 477buf.data[gl_GlobalInvocationID.x] = 478float(e2m1) + float(e3m2) + float(e2m3) + float(ue8m0) + float(mxint8); 479} 480)" ; 481std :: vector < uint32_t > spirv ; 482std :: string error ; 483ASSERT_TRUE ( compileToSpirvWithDebugInfo ( source , spirv , error )) << error ; 484 485struct ExpectedDebugType { 486const char * name ; 487uint32_t width ; 488spv :: FPEncoding fpEncoding ; 489} ; 490const ExpectedDebugType expectedTypes [] = { 491{ "floate2m1_t" , 4 , spv :: FPEncoding :: Float4E2M1EXT } , 492{ "floate3m2_t" , 6 , spv :: FPEncoding :: Float6E3M2EXT } , 493{ "floate2m3_t" , 6 , spv :: FPEncoding :: Float6E2M3EXT } , 494{ "floatue8m0_t" , 8 , spv :: FPEncoding :: Float8UnsignedE8M0EXT } , 495{ "floatmxint8_t" , 8 , spv :: FPEncoding :: MXInt8EXT } , 496} ; 497 498std :: ostringstream disassembly ; 499spv :: Disassemble ( disassembly , spirv ) ; 500for ( const auto & expected : expectedTypes ) { 501EXPECT_TRUE ( containsDebugTypeBasic ( spirv , expected . name , expected . width , expected . fpEncoding )) 502<< "Expected DebugTypeBasic for \" " << expected . name << " \" with width " << expected . width 503<< " and FPEncoding " << static_cast < uint32_t > ( expected . fpEncoding ) 504<< ". \n SPIR-V: \n " << disassembly . str () ; 505} 506} 507 508// When a version-101 opcode is emitted the import string must be promoted to 509// NonSemantic.Shader.DebugInfo.101. 510TEST_F ( SpvDebugInfoTest , Version101OpcodePromotesImportStringTo101 ) 511{ 512// DebugTypeCooperativeMatrixKHR is a version-101 opcode; using it must 513// cause the import string to read ".101", not ".100". 514const std :: string source = R"( 515#version 450 core 516#pragma use_vulkan_memory_model 517#extension GL_KHR_memory_scope_semantics : enable 518#extension GL_KHR_cooperative_matrix : enable 519#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable 520layout(local_size_x = 32) in; 521layout(set = 0, binding = 0) buffer B { float16_t data[]; } buf; 522void main() { 523coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator> m = 524coopmat<float16_t, gl_ScopeSubgroup, 16, 16, gl_MatrixUseAccumulator>(float16_t(0.0)); 525coopMatStore(m, buf.data, 0, 0, gl_CooperativeMatrixLayoutRowMajor); 526} 527)" ; 528std :: string spirv = compileWithDebugInfo ( source ) ; 529EXPECT_NE ( spirv . find ( " \" NonSemantic.Shader.DebugInfo.101 \" " ) , std :: string :: npos ) 530<< "Expected import string NonSemantic.Shader.DebugInfo.101. \n SPIR-V: \n " << spirv ; 531EXPECT_EQ ( spirv . find ( " \" NonSemantic.Shader.DebugInfo.100 \" " ) , std :: string :: npos ) 532<< "Import string must not be .100 when version-101 opcodes are used. \n SPIR-V: \n " << spirv ; 533} 534 535// When only version-100 opcodes are emitted the import string must stay at 536// NonSemantic.Shader.DebugInfo.100 and must not be promoted to .101. 537TEST_F ( SpvDebugInfoTest , Version100OnlyKeepsImportStringAt100 ) 538{ 539const std :: string source = R"( 540#version 450 core 541layout(local_size_x = 64) in; 542layout(set = 0, binding = 0) buffer B { float data[]; } buf; 543void main() { 544float x = buf.data[gl_GlobalInvocationID.x]; 545buf.data[gl_GlobalInvocationID.x] = x * 2.0; 546} 547)" ; 548std :: string spirv = compileWithDebugInfo ( source ) ; 549EXPECT_NE ( spirv . find ( " \" NonSemantic.Shader.DebugInfo.100 \" " ) , std :: string :: npos ) 550<< "Expected import string NonSemantic.Shader.DebugInfo.100. \n SPIR-V: \n " << spirv ; 551EXPECT_EQ ( spirv . find ( " \" NonSemantic.Shader.DebugInfo.101 \" " ) , std :: string :: npos ) 552<< "Import string must not be .101 when only version-100 opcodes are used. \n SPIR-V: \n " << spirv ; 553} 554 555} // namespace 556} // namespace glslangtest