Skip to content

Commit

Permalink
move target version to context
Browse files Browse the repository at this point in the history
  • Loading branch information
Hatrickek authored and martty committed Jan 21, 2024
1 parent 8632b34 commit f7e4b3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions include/vuk/Context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ namespace vuk {
/// Internal pipeline cache to use
VkPipelineCache vk_pipeline_cache = VK_NULL_HANDLE;

/// Shader compiler Vulkan version
uint32_t shader_compiler_target_version = VK_API_VERSION_1_3;

/// @brief Create a pipeline base that can be recalled by name
void create_named_pipeline(Name name, PipelineBaseCreateInfo pbci);

Expand All @@ -155,6 +158,9 @@ namespace vuk {
Program get_pipeline_reflection_info(const PipelineBaseCreateInfo& pbci);
/// @brief Explicitly compile give ShaderSource into a ShaderModule
ShaderModule compile_shader(ShaderSource source, std::string path);
/// @brief Set the target Vulkan version for shader compilers.
/// @param target_version the version to be set. VK_API_VERSION_1_X defines must be used.
void set_shader_target_version(uint32_t target_version = VK_API_VERSION_1_3);

/// @brief Load a Vulkan pipeline cache
bool load_pipeline_cache(std::span<std::byte> data);
Expand Down
1 change: 0 additions & 1 deletion include/vuk/ShaderSource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace vuk {
O3
} optimization_level = OptimizationLevel::O3;

uint32_t target_version = VK_API_VERSION_1_3;
std::vector<std::wstring> dxc_extra_arguments = { L"-spirv", L"-fvk-use-gl-layout", L"-no-warnings" };
};

Expand Down
9 changes: 7 additions & 2 deletions src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ namespace vuk {
{ VK_API_VERSION_1_3, shaderc_env_version_vulkan_1_3 },
};

options.SetTargetEnvironment(shaderc_target_env_vulkan, target_version.at(cinfo.compile_options.target_version));
options.SetTargetEnvironment(shaderc_target_env_vulkan, target_version.at(shader_compiler_target_version));

static const std::unordered_map<ShaderCompileOptions::OptimizationLevel, shaderc_optimization_level> optimization_level = {
{ ShaderCompileOptions::OptimizationLevel::O0, shaderc_optimization_level_zero },
Expand Down Expand Up @@ -419,7 +419,7 @@ namespace vuk {
{ VK_API_VERSION_1_3, L"-fspv-target-env=vulkan1.1"},
};

arguments.push_back(target_version.at(cinfo.compile_options.target_version));
arguments.push_back(target_version.at(shader_compiler_target_version));

static const std::unordered_map<ShaderCompileOptions::OptimizationLevel, const wchar_t*> optimization_level = {
{ ShaderCompileOptions::OptimizationLevel::O0, L"-O0" },
Expand Down Expand Up @@ -734,6 +734,11 @@ namespace vuk {
return impl->shader_modules.acquire(sci);
}

void Context::set_shader_target_version(const uint32_t target_version) {
assert((target_version >= VK_API_VERSION_1_0 && target_version <= VK_API_VERSION_1_3) && "Invalid target version was passed.");
shader_compiler_target_version = target_version;
}

Texture Context::allocate_texture(Allocator& allocator, ImageCreateInfo ici, SourceLocationAtFrame loc) {
ici.imageType = ici.extent.depth > 1 ? ImageType::e3D : ici.extent.height > 1 ? ImageType::e2D : ImageType::e1D;
VkImageFormatListCreateInfo listci = { VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO };
Expand Down

0 comments on commit f7e4b3d

Please sign in to comment.