/ appendices / VK_AMD_shader_info.txt
VK_AMD_shader_info.txt
1 include::meta/VK_AMD_shader_info.txt[] 2 3 *Last Modified Date*:: 4 2017-10-09 5 *IP Status*:: 6 No known IP claims. 7 *Contributors*:: 8 - Jaakko Konttinen, AMD 9 10 This extension adds a way to query certain information about a compiled 11 shader which is part of a pipeline. 12 This information may include shader disassembly, shader binary and various 13 statistics about a shader's resource usage. 14 15 While this extension provides a mechanism for extracting this information, 16 the details regarding the contents or format of this information are not 17 specified by this extension and may be provided by the vendor externally. 18 19 Furthermore, all information types are optionally supported, and users 20 should not assume every implementation supports querying every type of 21 information. 22 23 === New Object Types 24 25 None. 26 27 === New Enum Constants 28 29 None. 30 31 === New Enums 32 33 * elink:VkShaderInfoTypeAMD 34 35 === New Structures 36 37 * slink:VkShaderResourceUsageAMD 38 * slink:VkShaderStatisticsInfoAMD 39 40 === New Functions 41 42 * flink:vkGetShaderInfoAMD 43 44 === Examples 45 46 This example extracts the register usage of a fragment shader within a 47 particular graphics pipeline: 48 49 [source,c++] 50 ---------------------------------------- 51 extern VkDevice device; 52 extern VkPipeline gfxPipeline; 53 54 PFN_vkGetShaderInfoAMD pfnGetShaderInfoAMD = (PFN_vkGetShaderInfoAMD)vkGetDeviceProcAddr( 55 device, "vkGetShaderInfoAMD"); 56 57 VkShaderStatisticsInfoAMD statistics = {}; 58 59 size_t dataSize = sizeof(statistics); 60 61 if (pfnGetShaderInfoAMD(device, 62 gfxPipeline, 63 VK_SHADER_STAGE_FRAGMENT_BIT, 64 VK_SHADER_INFO_TYPE_STATISTICS_AMD, 65 &dataSize, 66 &statistics) == VK_SUCCESS) 67 { 68 printf("VGPR usage: %d\n", statistics.resourceUsage.numUsedVgprs); 69 printf("SGPR usage: %d\n", statistics.resourceUsage.numUsedSgprs); 70 } 71 ---------------------------------------- 72 73 The following example continues the previous example by subsequently 74 attempting to query and print shader disassembly about the fragment shader: 75 76 [source,c++] 77 ---------------------------------------- 78 // Query disassembly size (if available) 79 if (pfnGetShaderInfoAMD(device, 80 gfxPipeline, 81 VK_SHADER_STAGE_FRAGMENT_BIT, 82 VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD, 83 &dataSize, 84 nullptr) == VK_SUCCESS) 85 { 86 printf("Fragment shader disassembly:\n"); 87 88 void* disassembly = malloc(dataSize); 89 90 // Query disassembly and print 91 if (pfnGetShaderInfoAMD(device, 92 gfxPipeline, 93 VK_SHADER_STAGE_FRAGMENT_BIT, 94 VK_SHADER_INFO_TYPE_DISASSEMBLY_AMD, 95 &dataSize, 96 disassembly) == VK_SUCCESS) 97 { 98 printf((char*)disassembly); 99 } 100 101 free(disassembly); 102 } 103 ---------------------------------------- 104 105 106 === Version History 107 108 * Revision 1, 2017-10-09 (Jaakko Konttinen) 109 - Initial revision