Skip to content

Commit

Permalink
Added support for the Vulkan performance pipeline runtime layer (#1025)
Browse files Browse the repository at this point in the history
This commit adds a new option that will allow amber to measure the runtime of a pipeline using the Vulkan performance layers.
  • Loading branch information
mdagois authored Jun 9, 2023
1 parent bb702e5 commit a55625c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
7 changes: 6 additions & 1 deletion samples/amber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct Options {
bool log_graphics_calls_time = false;
bool log_execute_calls = false;
bool disable_spirv_validation = false;
bool enable_pipeline_runtime_layer = false;
std::string shader_filename;
amber::EngineType engine = amber::kEngineTypeVulkan;
std::string spv_env;
Expand Down Expand Up @@ -103,6 +104,7 @@ const char kUsage[] = R"(Usage: amber [options] SCRIPT [SCRIPTS...]
--log-graphics-calls-time -- Log timing of graphics API calls timing (Vulkan only).
--log-execute-calls -- Log each execute call before run.
--disable-spirv-val -- Disable SPIR-V validation.
--enable-runtime-layer -- Enable pipeline runtime layer.
-h -- This help text.
)";

Expand Down Expand Up @@ -280,6 +282,8 @@ bool ParseArgs(const std::vector<std::string>& args, Options* opts) {
opts->log_execute_calls = true;
} else if (arg == "--disable-spirv-val") {
opts->disable_spirv_validation = true;
} else if (arg == "--enable-runtime-layer") {
opts->enable_pipeline_runtime_layer = true;
} else if (arg.size() > 0 && arg[0] == '-') {
std::cerr << "Unrecognized option " << arg << std::endl;
return false;
Expand Down Expand Up @@ -567,7 +571,8 @@ int main(int argc, const char** argv) {
required_instance_extensions.end()),
std::vector<std::string>(required_device_extensions.begin(),
required_device_extensions.end()),
options.disable_validation_layer, options.show_version_info, &config);
options.disable_validation_layer, options.enable_pipeline_runtime_layer,
options.show_version_info, &config);

if (!r.IsSuccess()) {
std::cout << r.Error() << std::endl;
Expand Down
4 changes: 3 additions & 1 deletion samples/config_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ amber::Result ConfigHelper::CreateConfig(
const std::vector<std::string>& required_instance_extensions,
const std::vector<std::string>& required_device_extensions,
bool disable_validation_layer,
bool enable_pipeline_runtime_layer,
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config) {
switch (engine) {
Expand All @@ -70,7 +71,8 @@ amber::Result ConfigHelper::CreateConfig(
return impl_->CreateConfig(
engine_major, engine_minor, selected_device, required_features,
required_instance_extensions, required_device_extensions,
disable_validation_layer, show_version_info, config);
disable_validation_layer, enable_pipeline_runtime_layer,
show_version_info, config);
}

} // namespace sample
2 changes: 2 additions & 0 deletions samples/config_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ConfigHelperImpl {
const std::vector<std::string>& required_instance_extensions,
const std::vector<std::string>& required_device_extensions,
bool disable_validation_layer,
bool enable_pipeline_runtime_layer,
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config) = 0;
};
Expand All @@ -64,6 +65,7 @@ class ConfigHelper {
const std::vector<std::string>& required_instance_extensions,
const std::vector<std::string>& required_device_extensions,
bool disable_validation_layer,
bool enable_pipeline_runtime_layer,
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config);

Expand Down
1 change: 1 addition & 0 deletions samples/config_helper_dawn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ amber::Result ConfigHelperDawn::CreateConfig(
const std::vector<std::string>&,
bool,
bool,
bool,
std::unique_ptr<amber::EngineConfig>* config) {
// Set procedure table and error callback.
DawnProcTable backendProcs = dawn_native::GetProcs();
Expand Down
1 change: 1 addition & 0 deletions samples/config_helper_dawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ConfigHelperDawn : public ConfigHelperImpl {
const std::vector<std::string>& required_instance_extensions,
const std::vector<std::string>& required_device_extensions,
bool disable_validation_layer,
bool enable_pipeline_runtime_layer,
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config) override;

Expand Down
39 changes: 28 additions & 11 deletions samples/config_helper_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const char* const kRequiredValidationLayers[] = {
const size_t kNumberOfRequiredValidationLayers =
sizeof(kRequiredValidationLayers) / sizeof(const char*);

const char kPipelineRuntimeLayerName[] = "VK_LAYER_STADIA_pipeline_runtime";

const char kVariablePointers[] = "VariablePointerFeatures.variablePointers";
const char kVariablePointersStorageBuffer[] =
"VariablePointerFeatures.variablePointersStorageBuffer";
Expand Down Expand Up @@ -672,7 +674,8 @@ amber::Result ConfigHelperVulkan::CreateVulkanInstance(
uint32_t engine_major,
uint32_t engine_minor,
std::vector<std::string> required_extensions,
bool disable_validation_layer) {
bool disable_validation_layer,
bool enable_pipeline_runtime_layer) {
VkApplicationInfo app_info = VkApplicationInfo();
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;

Expand All @@ -685,19 +688,29 @@ amber::Result ConfigHelperVulkan::CreateVulkanInstance(
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instance_info.pApplicationInfo = &app_info;

std::vector<const char*> layer_names;

if (!disable_validation_layer) {
if (!AreAllValidationLayersSupported())
return amber::Result("Sample: not all validation layers are supported");
if (!AreAllValidationExtensionsSupported()) {
return amber::Result(
"Sample: extensions of validation layers are not supported");
}
instance_info.enabledLayerCount = kNumberOfRequiredValidationLayers;
instance_info.ppEnabledLayerNames = kRequiredValidationLayers;

for (size_t i = 0; i < kNumberOfRequiredValidationLayers; ++i) {
layer_names.push_back(kRequiredValidationLayers[i]);
}
required_extensions.push_back(kExtensionForValidationLayer);
}

if (enable_pipeline_runtime_layer) {
layer_names.push_back(kPipelineRuntimeLayerName);
}

instance_info.enabledLayerCount = static_cast<uint32_t>(layer_names.size());
instance_info.ppEnabledLayerNames =
instance_info.enabledLayerCount > 0 ? layer_names.data() : nullptr;

available_instance_extensions_ = GetAvailableInstanceExtensions();
if (!required_extensions.empty()) {
if (!AreAllExtensionsSupported(available_instance_extensions_,
Expand Down Expand Up @@ -729,9 +742,12 @@ amber::Result ConfigHelperVulkan::CreateVulkanInstance(
static_cast<uint32_t>(required_extensions_in_char.size());
instance_info.ppEnabledExtensionNames = required_extensions_in_char.data();

if (vkCreateInstance(&instance_info, nullptr, &vulkan_instance_) !=
VK_SUCCESS) {
return amber::Result("Unable to create vulkan instance");
const VkResult result =
vkCreateInstance(&instance_info, nullptr, &vulkan_instance_);
if (result != VK_SUCCESS) {
std::stringstream error_message;
error_message << "Unable to create vulkan instance (code=" << result << ")";
return amber::Result(error_message.str());
}
return {};
}
Expand Down Expand Up @@ -805,7 +821,7 @@ amber::Result ConfigHelperVulkan::CheckVulkanPhysicalDeviceRequirements(
: nullptr;

shader_subgroup_extended_types_features.sType =
// NOLINTNEXTLINE(whitespace/line_length)
// NOLINTNEXTLINE(whitespace/line_length)
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES;
shader_subgroup_extended_types_features.pNext = &variable_pointers_features;

Expand Down Expand Up @@ -1227,11 +1243,12 @@ amber::Result ConfigHelperVulkan::CreateConfig(
const std::vector<std::string>& required_instance_extensions,
const std::vector<std::string>& required_device_extensions,
bool disable_validation_layer,
bool enable_pipeline_runtime_layer,
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* cfg_holder) {
amber::Result r = CreateVulkanInstance(engine_major, engine_minor,
required_instance_extensions,
disable_validation_layer);
amber::Result r = CreateVulkanInstance(
engine_major, engine_minor, required_instance_extensions,
disable_validation_layer, enable_pipeline_runtime_layer);
if (!r.IsSuccess())
return r;

Expand Down
4 changes: 3 additions & 1 deletion samples/config_helper_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
const std::vector<std::string>& required_instance_extensions,
const std::vector<std::string>& required_device_extensions,
bool disable_validation_layer,
bool enable_pipeline_runtime_layer,
bool show_version_info,
std::unique_ptr<amber::EngineConfig>* config) override;

Expand All @@ -58,7 +59,8 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
uint32_t engine_major,
uint32_t engine_minor,
std::vector<std::string> required_instance_extensions,
bool disable_validation_layer);
bool disable_validation_layer,
bool enable_pipeline_runtime_layer);

/// Create |vulkan_callback_| that reports validation layer errors
/// via debugCallback() function in config_helper_vulkan.cc.
Expand Down

0 comments on commit a55625c

Please sign in to comment.