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