Macos ios fixes (#1192)
* Configure MoltenVK to use a dedicated compute queue for compute[*] examples with sync barriers * Modify descriptorindexing example for iOS and variable descriptor count limitations on MoltenVK * Remove obsolete macOS #ifdefs no longer needed for modern MoltenVK versions * Update iOS project to fix missing vkloader.c reference and revise example list * Set required features and API version for VVL in debugprintf example * Remove unnecessary Apple-specific code from descriptorindexing example * Add Layer Settings capability to VulkanExampleBase::createInstance() * Replace setenv() in examples with Layer Settings configuration for macOS/iOS * Update comments in examples.h and fix missing initializer in computeraytracing example * Update imgui overlay and example to support iOS Simulator * Update more comments in examples.h and remove redundant initializers in deferred* examples * Separate variable descriptor count declarations for apple and non-apple platforms * Consolidate variable descriptor count declarations for apple vs. non-apple platforms * Configure MoltenVK with a dedicated compute queue in VulkanExampleBase() and remove from samples
This commit is contained in:
parent
e1c962289f
commit
9a562a5426
17 changed files with 221 additions and 83 deletions
|
|
@ -65,7 +65,7 @@ public:
|
|||
glm::vec4 normalAndDistance;
|
||||
};
|
||||
struct SceneObject {
|
||||
SceneObjectProperty objectProperties;
|
||||
SceneObjectProperty objectProperties{};
|
||||
glm::vec3 diffuse;
|
||||
float specular{ 1.0f };
|
||||
uint32_t id{ 0 };
|
||||
|
|
@ -85,11 +85,6 @@ public:
|
|||
camera.setTranslation(glm::vec3(0.0f, 0.0f, -4.0f));
|
||||
camera.rotationSpeed = 0.0f;
|
||||
camera.movementSpeed = 2.5f;
|
||||
|
||||
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// SRS - on macOS set environment variable to ensure MoltenVK disables Metal argument buffers for this example
|
||||
setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "0", 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
~VulkanExample()
|
||||
|
|
|
|||
|
|
@ -47,12 +47,39 @@ public:
|
|||
enabledDeviceExtensions.push_back(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME);
|
||||
|
||||
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && defined(VK_EXAMPLE_XCODE_GENERATED)
|
||||
// SRS - Force validation on since debugPrintfEXT provided by VK_LAYER_KHRONOS_validation on macOS
|
||||
// SRS - Force validation on since shader printf provided by VK_LAYER_KHRONOS_validation on macOS
|
||||
settings.validation = true;
|
||||
setenv("VK_LAYER_ENABLES", "VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT", 1);
|
||||
|
||||
// SRS - RenderDoc not available on macOS so redirect debugPrintfEXT output to stdout
|
||||
setenv("VK_KHRONOS_VALIDATION_PRINTF_TO_STDOUT", "1", 1);
|
||||
// Use layer settings extension to configure Validation Layer
|
||||
enabledInstanceExtensions.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
|
||||
// SRS - Enable the Validation Layer's printf feature
|
||||
VkLayerSettingEXT layerSetting;
|
||||
layerSetting.pLayerName = "VK_LAYER_KHRONOS_validation";
|
||||
layerSetting.pSettingName = "enables";
|
||||
layerSetting.type = VK_LAYER_SETTING_TYPE_STRING_EXT;
|
||||
layerSetting.valueCount = 1;
|
||||
|
||||
// Make static so layer setting reference remains valid after leaving constructor scope
|
||||
static const char *layerEnables = "VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT";
|
||||
layerSetting.pValues = &layerEnables;
|
||||
enabledLayerSettings.push_back(layerSetting);
|
||||
|
||||
// SRS - RenderDoc not available on macOS so redirect printf output to stdout
|
||||
layerSetting.pSettingName = "printf_to_stdout";
|
||||
layerSetting.type = VK_LAYER_SETTING_TYPE_BOOL32_EXT;
|
||||
layerSetting.valueCount = 1;
|
||||
|
||||
// Make static so layer setting reference remains valid after leaving constructor scope
|
||||
static const VkBool32 layerSettingOn = VK_TRUE;
|
||||
layerSetting.pValues = &layerSettingOn;
|
||||
enabledLayerSettings.push_back(layerSetting);
|
||||
|
||||
// Enable required features and set API version for Validation Layer printf
|
||||
enabledFeatures.fragmentStoresAndAtomics = VK_TRUE;
|
||||
enabledFeatures.vertexPipelineStoresAndAtomics = VK_TRUE;
|
||||
|
||||
apiVersion = VK_API_VERSION_1_1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ public:
|
|||
} uniformDataComposition;
|
||||
|
||||
struct {
|
||||
vks::Buffer offscreen{ VK_NULL_HANDLE };
|
||||
vks::Buffer composition{ VK_NULL_HANDLE };
|
||||
vks::Buffer offscreen;
|
||||
vks::Buffer composition;
|
||||
} uniformBuffers;
|
||||
|
||||
struct {
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ public:
|
|||
} uniformDataComposition;
|
||||
|
||||
struct {
|
||||
vks::Buffer offscreen{ VK_NULL_HANDLE };
|
||||
vks::Buffer composition{ VK_NULL_HANDLE };
|
||||
vks::Buffer offscreen;
|
||||
vks::Buffer composition;
|
||||
} uniformBuffers;
|
||||
|
||||
struct {
|
||||
|
|
@ -72,7 +72,7 @@ public:
|
|||
VkDescriptorSet model{ VK_NULL_HANDLE };
|
||||
VkDescriptorSet background{ VK_NULL_HANDLE };
|
||||
VkDescriptorSet composition{ VK_NULL_HANDLE };
|
||||
} descriptorSets{ VK_NULL_HANDLE };
|
||||
} descriptorSets;
|
||||
|
||||
VkDescriptorSetLayout descriptorSetLayout{ VK_NULL_HANDLE };
|
||||
|
||||
|
|
|
|||
|
|
@ -68,10 +68,21 @@ public:
|
|||
|
||||
deviceCreatepNextChain = &physicalDeviceDescriptorIndexingFeatures;
|
||||
|
||||
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// SRS - on macOS set environment variable to configure MoltenVK for using Metal argument buffers (needed for descriptor indexing)
|
||||
// - MoltenVK supports Metal argument buffers on macOS, iOS possible in future (see https://github.com/KhronosGroup/MoltenVK/issues/1651)
|
||||
setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "1", 1);
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// Use layer settings extension to configure MoltenVK
|
||||
enabledInstanceExtensions.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
|
||||
// Configure MoltenVK to use Metal argument buffers (needed for descriptor indexing)
|
||||
VkLayerSettingEXT layerSetting;
|
||||
layerSetting.pLayerName = "MoltenVK";
|
||||
layerSetting.pSettingName = "MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS";
|
||||
layerSetting.type = VK_LAYER_SETTING_TYPE_BOOL32_EXT;
|
||||
layerSetting.valueCount = 1;
|
||||
|
||||
// Make this static so layer setting reference remains valid after leaving constructor scope
|
||||
static const VkBool32 layerSettingOn = VK_TRUE;
|
||||
layerSetting.pValues = &layerSettingOn;
|
||||
enabledLayerSettings.push_back(layerSetting);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -214,8 +225,8 @@ public:
|
|||
vks::initializers::descriptorPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, static_cast<uint32_t>(textures.size()))
|
||||
};
|
||||
VkDescriptorPoolCreateInfo descriptorPoolInfo = vks::initializers::descriptorPoolCreateInfo(poolSizes, 2);
|
||||
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// SRS - increase the per-stage descriptor samplers limit on macOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// Increase the per-stage descriptor samplers limit on macOS/iOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
descriptorPoolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT;
|
||||
#endif
|
||||
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
||||
|
|
@ -237,6 +248,27 @@ public:
|
|||
// Binding 1 are the fragment shader images, which use indexing
|
||||
// In the fragment shader:
|
||||
// layout (set = 0, binding = 1) uniform sampler2D textures[];
|
||||
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// Disable variable descriptor count feature on macOS/iOS until MoltenVK supports this feature when using combined image sampler textures
|
||||
// Note we are using only 1 descriptor set with a fixed descriptor count/pool size, so we can simply turn off the capability for now
|
||||
std::vector<VkDescriptorBindingFlagsEXT> descriptorBindingFlags = {
|
||||
0,
|
||||
0
|
||||
};
|
||||
setLayoutBindingFlags.pBindingFlags = descriptorBindingFlags.data();
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
|
||||
// Increase the per-stage descriptor samplers limit on macOS/iOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
descriptorSetLayoutCI.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT;
|
||||
descriptorSetLayoutCI.pNext = &setLayoutBindingFlags;
|
||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayout));
|
||||
|
||||
// [POI] Descriptor sets
|
||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1);
|
||||
allocInfo.pNext = nullptr;
|
||||
#else
|
||||
// Enable variable descriptor count feature on platforms other than macOS/iOS
|
||||
std::vector<VkDescriptorBindingFlagsEXT> descriptorBindingFlags = {
|
||||
0,
|
||||
VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT
|
||||
|
|
@ -244,10 +276,6 @@ public:
|
|||
setLayoutBindingFlags.pBindingFlags = descriptorBindingFlags.data();
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
|
||||
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// SRS - increase the per-stage descriptor samplers limit on macOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
descriptorSetLayoutCI.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT;
|
||||
#endif
|
||||
descriptorSetLayoutCI.pNext = &setLayoutBindingFlags;
|
||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayout));
|
||||
|
||||
|
|
@ -264,6 +292,7 @@ public:
|
|||
|
||||
VkDescriptorSetAllocateInfo allocInfo = vks::initializers::descriptorSetAllocateInfo(descriptorPool, &descriptorSetLayout, 1);
|
||||
allocInfo.pNext = &variableDescriptorCountAllocInfo;
|
||||
#endif
|
||||
|
||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &allocInfo, &descriptorSet));
|
||||
|
||||
|
|
|
|||
|
|
@ -524,7 +524,13 @@ public:
|
|||
vkCmdDrawIndexed(commandBuffer, pcmd->ElemCount, 1, indexOffset, vertexOffset, 0);
|
||||
indexOffset += pcmd->ElemCount;
|
||||
}
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT)) && TARGET_OS_SIMULATOR
|
||||
// Apple Device Simulator does not support vkCmdDrawIndexed() with vertexOffset > 0, so rebind vertex buffer instead
|
||||
offsets[0] += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
|
||||
vkCmdBindVertexBuffers(commandBuffer, 0, 1, &vertexBuffer.buffer, offsets);
|
||||
#else
|
||||
vertexOffset += cmd_list->VtxBuffer.Size;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,11 +46,6 @@ public:
|
|||
camera.setPerspective(60.0f, ((float)width / 3.0f) / (float)height, 0.1f, 512.0f);
|
||||
camera.setRotation(glm::vec3(-40.0f, -90.0f, 0.0f));
|
||||
camera.setTranslation(glm::vec3(0.0f, 0.0f, -2.0f));
|
||||
|
||||
#if (defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_METAL_EXT))
|
||||
// SRS - on macOS set environment variable to ensure MoltenVK disables Metal argument buffers for this example
|
||||
setenv("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS", "0", 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
~VulkanExample()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue