Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
Change-Id: I612998cd9fdcf89c9c1ba0cff75db72876955594
  • Loading branch information
dj2 committed May 9, 2024
1 parent 41127eb commit d0dd8c8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.13)
if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ vars = {
'vulkan_headers_revision': '4bc77c26ff9ce89cf4a4f79e1c24a44604132d53',
'vulkan_loader_revision': 'e69a59a96b241038f24a0e425445d001ea099b2c',
'vulkan_utility_libraries_revision': '358a107a6ff284906dcccbabe5b0183c03fd85b6',
'vulkan_validationlayers_revision': 'a5f65dae0d9b08cd7076d88c3dabddf1b41b73b4',
'vulkan_validationlayers_revision': '23455c903e2ab21db2b4497331d80d610841cae1',
}

deps = {
Expand Down
2 changes: 1 addition & 1 deletion samples/amber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct Options {
std::vector<std::string> fb_names;
std::vector<amber::BufferInfo> buffer_to_dump;
uint32_t engine_major = 1;
uint32_t engine_minor = 0;
uint32_t engine_minor = 1;
int32_t fence_timeout = -1;
int32_t selected_device = -1;
bool parse_only = false;
Expand Down
92 changes: 74 additions & 18 deletions samples/config_helper_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ amber::Result ConfigHelperVulkan::CheckVulkanPhysicalDeviceRequirements(
supports_subgroup_size_control_ = true;
else if (ext == "VK_KHR_shader_subgroup_extended_types")
supports_shader_subgroup_extended_types_ = true;
else if (ext == "VK_KHR_variable_pointers")
supports_variable_pointers_ = true;
}

VkPhysicalDeviceFeatures required_vulkan_features =
Expand Down Expand Up @@ -980,28 +982,32 @@ amber::Result ConfigHelperVulkan::CreateVulkanDevice(
queue_info.queueCount = 1;
queue_info.pQueuePriorities = priorities;

std::vector<const char*> required_extensions_in_char;
std::transform(
required_extensions.begin(), required_extensions.end(),
std::back_inserter(required_extensions_in_char),
[](const std::string& ext) -> const char* { return ext.c_str(); });

VkDeviceCreateInfo info = VkDeviceCreateInfo();
info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
info.pQueueCreateInfos = &queue_info;
info.queueCreateInfoCount = 1;
info.enabledExtensionCount =
static_cast<uint32_t>(required_extensions_in_char.size());
info.ppEnabledExtensionNames = required_extensions_in_char.data();

if (supports_get_physical_device_properties2_)
return CreateDeviceWithFeatures2(required_features, &info);
return CreateDeviceWithFeatures1(required_features, &info);
return CreateDeviceWithFeatures2(required_features, required_extensions,
&info);
return CreateDeviceWithFeatures1(required_features, required_extensions,
&info);
}

amber::Result ConfigHelperVulkan::CreateDeviceWithFeatures1(
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
VkDeviceCreateInfo* info) {
std::vector<const char*> required_extensions_in_char;
std::transform(
required_extensions.begin(), required_extensions.end(),
std::back_inserter(required_extensions_in_char),
[](const std::string& ext) -> const char* { return ext.c_str(); });

info->enabledExtensionCount =
static_cast<uint32_t>(required_extensions_in_char.size());
info->ppEnabledExtensionNames = required_extensions_in_char.data();

VkPhysicalDeviceFeatures required_vulkan_features =
VkPhysicalDeviceFeatures();
amber::Result r =
Expand All @@ -1015,6 +1021,7 @@ amber::Result ConfigHelperVulkan::CreateDeviceWithFeatures1(

amber::Result ConfigHelperVulkan::CreateDeviceWithFeatures2(
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
VkDeviceCreateInfo* info) {
variable_pointers_feature_.sType =
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR;
Expand All @@ -1040,35 +1047,84 @@ amber::Result ConfigHelperVulkan::CreateDeviceWithFeatures2(
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_SUBGROUP_EXTENDED_TYPES_FEATURES;
shader_subgroup_extended_types_feature_.pNext = nullptr;

void** next_ptr = &variable_pointers_feature_.pNext;
std::vector<std::string> exts = required_extensions;

void* pnext = nullptr;
void** next_ptr = nullptr;

if (supports_variable_pointers_) {
if (pnext == nullptr) {
pnext = &variable_pointers_feature_;
}
if (next_ptr != nullptr) {
*next_ptr = &variable_pointers_feature_.pNext;
}
exts.push_back(VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME);
}

if (supports_shader_float16_int8_) {
*next_ptr = &float16_int8_feature_;
if (pnext == nullptr) {
pnext = &float16_int8_feature_;
}
if (next_ptr != nullptr) {
*next_ptr = &float16_int8_feature_;
}
next_ptr = &float16_int8_feature_.pNext;
}

if (supports_shader_8bit_storage_) {
*next_ptr = &storage_8bit_feature_;
if (pnext == nullptr) {
pnext = &storage_8bit_feature_;
}
if (next_ptr != nullptr) {
*next_ptr = &storage_8bit_feature_;
}
next_ptr = &storage_8bit_feature_.pNext;
}

if (supports_shader_16bit_storage_) {
*next_ptr = &storage_16bit_feature_;
if (pnext == nullptr) {
pnext = &storage_16bit_feature_;
}
if (next_ptr != nullptr) {
*next_ptr = &storage_16bit_feature_;
}
next_ptr = &storage_16bit_feature_.pNext;
}

if (supports_subgroup_size_control_) {
*next_ptr = &subgroup_size_control_feature_;
if (pnext == nullptr) {
pnext = &subgroup_size_control_feature_;
}
if (next_ptr != nullptr) {
*next_ptr = &subgroup_size_control_feature_;
}
next_ptr = &subgroup_size_control_feature_.pNext;

exts.push_back(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);
}

if (supports_shader_subgroup_extended_types_) {
*next_ptr = &shader_subgroup_extended_types_feature_;
if (pnext == nullptr) {
pnext = &shader_subgroup_extended_types_feature_;
}
if (next_ptr != nullptr) {
*next_ptr = &shader_subgroup_extended_types_feature_;
}
next_ptr = &shader_subgroup_extended_types_feature_.pNext;
}

available_features2_.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
available_features2_.pNext = &variable_pointers_feature_;
available_features2_.pNext = pnext;

std::vector<const char*> required_extensions_in_char;
std::transform(
exts.begin(), exts.end(), std::back_inserter(required_extensions_in_char),
[](const std::string& ext) -> const char* { return ext.c_str(); });

info->enabledExtensionCount =
static_cast<uint32_t>(required_extensions_in_char.size());
info->ppEnabledExtensionNames = required_extensions_in_char.data();

std::vector<std::string> feature1_names;
for (const auto& feature : required_features) {
Expand Down
3 changes: 3 additions & 0 deletions samples/config_helper_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
/// Sets up the device creation to use VkPhysicalDeviceFeatures.
amber::Result CreateDeviceWithFeatures1(
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
VkDeviceCreateInfo* info);
/// Sets up the device creation to use VkPhysicalDeviceFeatures2KHR.
amber::Result CreateDeviceWithFeatures2(
const std::vector<std::string>& required_features,
const std::vector<std::string>& required_extensions,
VkDeviceCreateInfo* info);

/// Creates the physical device given the device |info|.
Expand All @@ -111,6 +113,7 @@ class ConfigHelperVulkan : public ConfigHelperImpl {
VkDevice vulkan_device_ = VK_NULL_HANDLE;

bool supports_get_physical_device_properties2_ = false;
bool supports_variable_pointers_ = false;
bool supports_shader_float16_int8_ = false;
bool supports_shader_8bit_storage_ = false;
bool supports_shader_16bit_storage_ = false;
Expand Down

0 comments on commit d0dd8c8

Please sign in to comment.