Skip to content

Commit a2909a7

Browse files
committed
Profile layer: Add per frame support
1 parent 6eb6fb6 commit a2909a7

12 files changed

+607
-94
lines changed

layer_gpu_profile/README_LAYER.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,32 @@ application under test and the capture process. For full instructions see the
113113

114114
## Layer configuration
115115

116-
The current layer supports two `sampling_mode` values:
116+
### Setting frame selection mode
117117

118-
* `periodic_frame`: Sample every N frames.
119-
* `frame_list`: Sample specific frames.
118+
The current layer supports the following ways to select frames to profile using
119+
the `frame_mode` config option:
120120

121-
When `mode` is `periodic_frame` the integer value of the `periodic_frame` key
122-
defines the frame sampling period. The integer value of the
123-
`periodic_min_frame` key defines the first possible frame that could be
124-
profiled, allowing profiles to skip over any loading frames. By default frame 0
125-
is ignored.
121+
* `disabled`: Sampling is disabled.
122+
* `periodic`: Sample every N frames.
123+
* `list`: Sample specific frames.
126124

127-
When `mode` is `frame_list` the value of the `frame_list` key defines a list
128-
of integers giving the specific frames to capture.
125+
When frame selection mode is `periodic` the integer value of the
126+
`periodic_frame` key defines the frame sampling period. The integer value of
127+
the `periodic_min_frame` key defines the first possible frame that could be
128+
profiled, allowing profiles to skip over any loading frames. By default frame
129+
0 is ignored.
130+
131+
When frame selection mode is `list` the value of the `frame_list` key defines
132+
a list of integers giving the specific frames to capture.
133+
134+
### Setting counter sampling mode
135+
136+
The current layer supports the following ways to select how to sample counters
137+
to profile using the `sample_mode` config option:
138+
139+
* `disabled`: Sampling is disabled.
140+
* `workload`: Sample every workload in each frame of interest.
141+
* `frame`: Sample at the end of each frame of interest.
129142

130143
## Layer counters
131144

layer_gpu_profile/layer_config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"layer": "VK_LAYER_LGL_gpu_profile",
3-
"sample_mode": "periodic_frame",
3+
"frame_mode": "periodic",
4+
"sample_mode": "frame",
45
"periodic_min_frame": 1,
56
"periodic_frame": 600,
67
"frame_list": []

layer_gpu_profile/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ add_library(
5555
layer_device_functions_render_pass.cpp
5656
layer_device_functions_trace_rays.cpp
5757
layer_device_functions_transfer.cpp
58+
layer_instance_functions.cpp
5859
submit_visitor.cpp)
5960

6061
target_include_directories(

layer_gpu_profile/source/device_utils.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
VkCommandBuffer commandBuffer
5959
) {
6060
// Don't instrument outside of active frame of interest
61-
if(!layer.isFrameOfInterest)
61+
bool isEnabled = layer.instance->config.isSamplingWorkloads();
62+
if(!layer.isFrameOfInterest || !isEnabled)
6263
{
6364
return;
6465
}

layer_gpu_profile/source/instance.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ const std::vector<std::string> Instance::requiredDriverExtensions {
4646
const std::vector<std::pair<std::string, uint32_t>> Instance::injectedInstanceExtensions {};
4747

4848
/* See header for documentation. */
49-
std::vector<std::pair<std::string, uint32_t>> Instance::injectedDeviceExtensions {};
49+
std::vector<std::pair<std::string, uint32_t>> Instance::injectedDeviceExtensions {
50+
{VK_EXT_FRAME_BOUNDARY_EXTENSION_NAME, VK_EXT_FRAME_BOUNDARY_SPEC_VERSION}
51+
};
5052

5153
/* See header for documentation. */
5254
void Instance::store(VkInstance handle, std::unique_ptr<Instance>& instance)

layer_gpu_profile/source/layer_config.cpp

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,45 +43,70 @@
4343
/* See header for documentation. */
4444
void LayerConfig::parseSamplingOptions(const json& config)
4545
{
46-
// Decode top level options
47-
std::string rawMode = config.at("sample_mode");
46+
// Decode frame selection mode
47+
std::string rawFrameMode = config.at("frame_mode");
4848

49-
if (rawMode == "disabled")
49+
if (rawFrameMode == "disabled")
5050
{
51-
mode = MODE_DISABLED;
51+
frameMode = FRAME_SELECTION_DISABLED;
5252
}
53-
else if (rawMode == "periodic_frame")
53+
else if (rawFrameMode == "periodic")
5454
{
55-
mode = MODE_PERIODIC_FRAME;
55+
frameMode = FRAME_SELECTION_PERIODIC;
5656
periodicFrame = config.at("periodic_frame");
5757
periodicMinFrame = config.at("periodic_min_frame");
5858
}
59-
else if (rawMode == "frame_list")
59+
else if (rawFrameMode == "list")
6060
{
61-
mode = MODE_FRAME_LIST;
61+
frameMode = FRAME_SELECTION_LIST;
6262
specificFrames = config.at("frame_list").get<std::vector<uint64_t>>();
6363
}
6464
else
6565
{
66-
LAYER_ERR("Unknown counter sample_mode: %s", rawMode.c_str());
67-
rawMode = "disabled";
66+
LAYER_ERR("Unknown frame_mode: %s", rawFrameMode.c_str());
67+
frameMode = FRAME_SELECTION_DISABLED;
68+
rawFrameMode = "disabled";
69+
}
70+
71+
// Decode counter sampling mode
72+
std::string rawSampleMode = config.at("sample_mode");
73+
74+
if (rawSampleMode == "disabled")
75+
{
76+
samplingMode = COUNTER_SAMPLING_DISABLED;
77+
}
78+
else if (rawSampleMode == "frame")
79+
{
80+
samplingMode = COUNTER_SAMPLING_FRAMES;
81+
}
82+
else if (rawSampleMode == "workload")
83+
{
84+
samplingMode = COUNTER_SAMPLING_WORKLOADS;
85+
}
86+
else
87+
{
88+
LAYER_ERR("Unknown sample_mode: %s", rawSampleMode.c_str());
89+
samplingMode = COUNTER_SAMPLING_DISABLED;
90+
rawSampleMode = "disabled";
6891
}
6992

7093
LAYER_LOG("Layer sampling configuration");
7194
LAYER_LOG("============================");
72-
LAYER_LOG(" - Sample mode: %s", rawMode.c_str());
95+
LAYER_LOG(" - Frame selection mode: %s", rawFrameMode.c_str());
7396

74-
if (mode == MODE_PERIODIC_FRAME)
97+
if (frameMode == FRAME_SELECTION_PERIODIC)
7598
{
7699
LAYER_LOG(" - Frame period: %" PRIu64, periodicFrame);
77100
LAYER_LOG(" - Minimum frame: %" PRIu64, periodicMinFrame);
78101
}
79-
else if (mode == MODE_FRAME_LIST)
102+
else if (frameMode == FRAME_SELECTION_LIST)
80103
{
81104
std::stringstream result;
82105
std::copy(specificFrames.begin(), specificFrames.end(), std::ostream_iterator<uint64_t>(result, " "));
83106
LAYER_LOG(" - Frames: %s", result.str().c_str());
84107
}
108+
109+
LAYER_LOG(" - Counter sampling mode: %s", rawSampleMode.c_str());
85110
}
86111

87112
/* See header for documentation. */
@@ -131,18 +156,36 @@ LayerConfig::LayerConfig()
131156
bool LayerConfig::isFrameOfInterest(
132157
uint64_t frameID
133158
) const {
134-
switch(mode)
159+
switch(frameMode)
135160
{
136-
case MODE_DISABLED:
161+
case FRAME_SELECTION_DISABLED:
137162
return false;
138-
case MODE_PERIODIC_FRAME:
163+
case FRAME_SELECTION_PERIODIC:
139164
return (frameID >= periodicMinFrame) &&
140165
((frameID % periodicFrame) == 0);
141-
case MODE_FRAME_LIST:
166+
case FRAME_SELECTION_LIST:
142167
return isIn(frameID, specificFrames);
143168
}
144169

145170
// Should never reach here
146171
return false;
147172
}
148173

174+
/* See header for documentation. */
175+
bool LayerConfig::isSamplingWorkloads() const {
176+
return frameMode != FRAME_SELECTION_DISABLED &&
177+
samplingMode == COUNTER_SAMPLING_WORKLOADS;
178+
}
179+
180+
/* See header for documentation. */
181+
bool LayerConfig::isSamplingFrames() const {
182+
return frameMode != FRAME_SELECTION_DISABLED &&
183+
samplingMode == COUNTER_SAMPLING_FRAMES;
184+
}
185+
186+
/* See header for documentation. */
187+
bool LayerConfig::isSamplingAny() const {
188+
return frameMode != FRAME_SELECTION_DISABLED &&
189+
samplingMode != COUNTER_SAMPLING_DISABLED;
190+
}
191+

layer_gpu_profile/source/layer_config.hpp

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,50 @@ class LayerConfig
5454
*
5555
* @param frameID The index of the next frame.
5656
*
57-
* @return True if profiling should be enabled, False otherwise.
57+
* @return @c true if profiling should be enabled, @c false otherwise.
5858
*/
5959
bool isFrameOfInterest(uint64_t frameID) const;
6060

61+
/**
62+
* @brief Test if we are sampling workloads.
63+
*
64+
* @return @c true if profiling workloads, @c false otherwise.
65+
*/
66+
bool isSamplingWorkloads() const;
67+
68+
/**
69+
* @brief Test if we are sampling frames.
70+
*
71+
* @return @c true if profiling frames, @c false otherwise.
72+
*/
73+
bool isSamplingFrames() const;
74+
75+
/**
76+
* @brief Test if any kind of sampling is active.
77+
*
78+
* @return @c true if profiling, @c false otherwise.
79+
*/
80+
bool isSamplingAny() const;
81+
6182
private:
6283
/**
63-
* @brief Supported sampling modes.
84+
* @brief Supported frame selection modes.
85+
*/
86+
enum FrameSelectionMode
87+
{
88+
FRAME_SELECTION_DISABLED,
89+
FRAME_SELECTION_LIST,
90+
FRAME_SELECTION_PERIODIC
91+
};
92+
93+
/**
94+
* @brief Supported counter sampling modes.
6495
*/
65-
enum SamplingMode
96+
enum CounterSamplingMode
6697
{
67-
MODE_DISABLED,
68-
MODE_FRAME_LIST,
69-
MODE_PERIODIC_FRAME
98+
COUNTER_SAMPLING_DISABLED,
99+
COUNTER_SAMPLING_WORKLOADS,
100+
COUNTER_SAMPLING_FRAMES
70101
};
71102

72103
/**
@@ -79,9 +110,15 @@ class LayerConfig
79110
void parseSamplingOptions(const json& config);
80111

81112
/**
82-
* @brief The sampling mode.
113+
* @brief The frame selection mode.
83114
*/
84-
SamplingMode mode {MODE_DISABLED};
115+
FrameSelectionMode frameMode {FRAME_SELECTION_DISABLED};
116+
117+
/**
118+
* @brief The counter sampling mode.
119+
*/
120+
CounterSamplingMode samplingMode {COUNTER_SAMPLING_DISABLED};
121+
85122

86123
/**
87124
* @brief The sampling period in frames, or 0 if disabled.

layer_gpu_profile/source/layer_device_functions.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,10 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR<user_tag>(VkQueue queue,
419419
uint32_t submitCount,
420420
const VkSubmitInfo2* pSubmits,
421421
VkFence fence);
422+
423+
/* See Vulkan API for documentation. */
424+
template <>
425+
VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueBindSparse<user_tag>(VkQueue queue,
426+
uint32_t bindInfoCount,
427+
const VkBindSparseInfo* pBindInfo,
428+
VkFence fence);

0 commit comments

Comments
 (0)