Skip to content

Commit

Permalink
shaderObject: Add env var for pre-caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ziga-lunarg committed Sep 11, 2024
1 parent e1269e5 commit 3af5422
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
12 changes: 11 additions & 1 deletion docs/shader_object_layer.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- markdownlint-disable MD041 -->
<p align="left"><img src="https://vulkan.lunarg.com/img/NewLunarGLogoBlack.png" alt="LunarG" width=263 height=113 /></p>

Copyright &copy; 2015-2023 LunarG, Inc.
Copyright &copy; 2015-2024 LunarG, Inc.

[![Creative Commons][3]][4]

Expand Down Expand Up @@ -75,6 +75,16 @@ To force the layer to be enabled for Vulkan applications, even though the Vulkan

export VK_SHADER_OBJECT_FORCE_ENABLE=true

To disable pipeline pre-caching to reduce memory overhead, you can set the `VK_SHADER_OBJECT_PIPELINE_DISABLE_PRE_CACHING` environment variable in the following way:

**Windows**

set VK_SHADER_OBJECT_PIPELINE_DISABLE_PRE_CACHING=true

**Linux/MacOS**

export VK_SHADER_OBJECT_PIPELINE_DISABLE_PRE_CACHING=true

<br>

### Settings Priority
Expand Down
8 changes: 8 additions & 0 deletions layers/json/VkLayer_khronos_shader_object.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@
"description": "Force the layer to be active even if the underlying driver also implements the shader object extension.",
"type": "BOOL",
"default": false
},
{
"key": "disable_pipeline_pre_caching",
"env": "VK_SHADER_OBJECT_DISABLE_PIPELINE_PRE_CACHING",
"label": "Disable Pipeline Pre-Caching",
"description": "Disable the layer from pre-caching pipelines, reducing the memory overhead.",
"type": "BOOL",
"default": false
}
]
}
Expand Down
12 changes: 11 additions & 1 deletion layers/shader_object/shader_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "shader_object/shader_object_structs.h"

#define kLayerSettingsForceEnable "force_enable"
#define kLayerSettingsDisablePipelinePreCaching "disable_pipeline_pre_caching"
#define kLayerSettingsCustomSTypeInfo "custom_stype_list"

#define SHADER_OBJECT_BINARY_VERSION 1
Expand Down Expand Up @@ -160,6 +161,7 @@ namespace shader_object {

struct LayerSettings {
bool force_enable{false};
bool disable_pipeline_pre_caching{false};
};

struct InstanceData {
Expand Down Expand Up @@ -1345,6 +1347,9 @@ PartialPipeline CreatePartiallyCompiledPipeline(DeviceData const& deviceData, Vk
}

static VkResult PopulateCachesForShaders(DeviceData const& deviceData, VkAllocationCallbacks const& allocator, bool are_graphics_shaders_linked, uint32_t shaderCount, VkShaderEXT* pShaders) {
if (deviceData.disable_pipeline_pre_caching) {
return VK_SUCCESS;
}
if (deviceData.graphics_pipeline_library.graphicsPipelineLibrary == VK_TRUE) {
// Compile partial pipelines to fill cache and to keep around for first draw pipeline creation

Expand Down Expand Up @@ -1582,7 +1587,7 @@ void InitLayerSettings(const VkInstanceCreateInfo* pCreateInfo, const VkAllocati
VkuLayerSettingSet layer_setting_set = VK_NULL_HANDLE;
vkuCreateLayerSettingSet(kLayerName, create_info, pAllocator, nullptr, &layer_setting_set);

static const char* setting_names[] = {kLayerSettingsForceEnable, kLayerSettingsCustomSTypeInfo};
static const char* setting_names[] = {kLayerSettingsForceEnable, kLayerSettingsDisablePipelinePreCaching kLayerSettingsCustomSTypeInfo};
uint32_t setting_name_count = static_cast<uint32_t>(std::size(setting_names));

uint32_t unknown_setting_count = 0;
Expand All @@ -1603,6 +1608,10 @@ void InitLayerSettings(const VkInstanceCreateInfo* pCreateInfo, const VkAllocati
vkuGetLayerSettingValue(layer_setting_set, kLayerSettingsForceEnable, layer_settings->force_enable);
}

if (vkuHasLayerSetting(layer_setting_set, kLayerSettingsDisablePipelinePreCaching)) {
vkuGetLayerSettingValue(layer_setting_set, kLayerSettingsDisablePipelinePreCaching, layer_settings->disable_pipeline_pre_caching);
}

if (vkuHasLayerSetting(layer_setting_set, kLayerSettingsCustomSTypeInfo)) {
vkuGetLayerSettingValues(layer_setting_set, kLayerSettingsCustomSTypeInfo, vku::GetCustomStypeInfo());
}
Expand Down Expand Up @@ -2094,6 +2103,7 @@ static VKAPI_ATTR VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physicalDevi
device_data->flags = enable_layer ? DeviceData::SHADER_OBJECT_LAYER_ENABLED : 0;
device_data->reserved_private_data_slot_count = total_private_data_slot_request_count;
device_data->enabled_extensions = enabled_additional_extensions;
device_data->disable_pipeline_pre_caching = instance_data->layer_settings.disable_pipeline_pre_caching;

#include "generated/shader_object_device_data_set_extension_variables.inl"

Expand Down
1 change: 1 addition & 0 deletions layers/shader_object/shader_object_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ struct DeviceData {
VkDevice device;
Flags flags;
AdditionalExtensionFlags enabled_extensions;
bool disable_pipeline_pre_caching;
VkPhysicalDeviceProperties properties;
LayerDispatchDevice vtable;
VkPrivateDataSlot private_data_slot;
Expand Down

0 comments on commit 3af5422

Please sign in to comment.