Merge branch 'master' of https://github.com/SaschaWillems/Vulkan
This commit is contained in:
commit
20775d9f3d
8 changed files with 74 additions and 41 deletions
|
|
@ -11,27 +11,6 @@ function(buildExample EXAMPLE_NAME)
|
|||
if(EXISTS ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h)
|
||||
SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h)
|
||||
ENDIF()
|
||||
if(APPLE)
|
||||
# SRS - Use MacPorts paths as default since the same on x86 and Apple Silicon, can override for homebrew on cmake command line
|
||||
if(NOT OpenMP_omp_LIBRARY AND EXISTS /opt/local/lib/libomp/libomp.dylib)
|
||||
set(OpenMP_omp_LIBRARY /opt/local/lib/libomp/libomp.dylib)
|
||||
endif()
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
|
||||
set(OpenMP_C_FLAGS "-Xclang -fopenmp")
|
||||
set(OpenMP_C_LIB_NAMES "omp")
|
||||
if(NOT OpenMP_C_INCLUDE_DIR AND EXISTS /opt/local/include/libomp)
|
||||
set(OpenMP_C_INCLUDE_DIR /opt/local/include/libomp)
|
||||
endif()
|
||||
endif()
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
|
||||
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
|
||||
set(OpenMP_CXX_LIB_NAMES "omp")
|
||||
if(NOT OpenMP_CXX_INCLUDE_DIR AND EXISTS /opt/local/include/libomp)
|
||||
set(OpenMP_CXX_INCLUDE_DIR /opt/local/include/libomp)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
find_package(OpenMP)
|
||||
# imgui example requires additional source files
|
||||
IF(${EXAMPLE_NAME} STREQUAL "imgui")
|
||||
file(GLOB ADD_SOURCE "../external/imgui/*.cpp")
|
||||
|
|
@ -60,6 +39,27 @@ function(buildExample EXAMPLE_NAME)
|
|||
|
||||
set_target_properties(${EXAMPLE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||
if(${EXAMPLE_NAME} STREQUAL "texture3d")
|
||||
if(APPLE)
|
||||
# SRS - Use MacPorts paths as default since the same on x86 and Apple Silicon, can override for homebrew on cmake command line
|
||||
if(NOT OpenMP_omp_LIBRARY AND EXISTS /opt/local/lib/libomp/libomp.dylib)
|
||||
set(OpenMP_omp_LIBRARY /opt/local/lib/libomp/libomp.dylib)
|
||||
endif()
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
|
||||
set(OpenMP_C_FLAGS "-Xclang -fopenmp")
|
||||
set(OpenMP_C_LIB_NAMES "omp")
|
||||
if(NOT OpenMP_C_INCLUDE_DIR AND EXISTS /opt/local/include/libomp)
|
||||
set(OpenMP_C_INCLUDE_DIR /opt/local/include/libomp)
|
||||
endif()
|
||||
endif()
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
|
||||
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
|
||||
set(OpenMP_CXX_LIB_NAMES "omp")
|
||||
if(NOT OpenMP_CXX_INCLUDE_DIR AND EXISTS /opt/local/include/libomp)
|
||||
set(OpenMP_CXX_INCLUDE_DIR /opt/local/include/libomp)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
find_package(OpenMP)
|
||||
if(OpenMP_CXX_FOUND)
|
||||
target_link_libraries(${EXAMPLE_NAME} OpenMP::OpenMP_CXX)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public:
|
|||
glm::vec3 lookat = glm::vec3(0.0f, 0.5f, 0.0f);
|
||||
float fov = 10.0f;
|
||||
} camera;
|
||||
glm::mat4 _pad;
|
||||
} ubo;
|
||||
} compute;
|
||||
|
||||
|
|
@ -90,6 +91,11 @@ 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)
|
||||
// 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()
|
||||
|
|
|
|||
|
|
@ -65,6 +65,12 @@ public:
|
|||
physicalDeviceDescriptorIndexingFeatures.descriptorBindingVariableDescriptorCount = VK_TRUE;
|
||||
|
||||
deviceCreatepNextChain = &physicalDeviceDescriptorIndexingFeatures;
|
||||
|
||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
// 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);
|
||||
#endif
|
||||
}
|
||||
|
||||
~VulkanExample()
|
||||
|
|
@ -120,15 +126,27 @@ public:
|
|||
std::uniform_int_distribution<int32_t> rndDist(0, static_cast<uint32_t>(textures.size()) - 1);
|
||||
|
||||
// Generate cubes with random per-face texture indices
|
||||
const uint32_t count = 6;
|
||||
const uint32_t count = 5;
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
// Push indices to buffer
|
||||
const std::vector<uint32_t> cubeIndices = {
|
||||
0,1,2,0,2,3,
|
||||
4,5,6,4,6,7,
|
||||
8,9,10,8,10,11,
|
||||
12,13,14,12,14,15,
|
||||
16,17,18,16,18,19,
|
||||
20,21,22,20,22,23
|
||||
};
|
||||
for (auto& index : cubeIndices) {
|
||||
indices.push_back(index + static_cast<uint32_t>(vertices.size()));
|
||||
}
|
||||
// Get random per-Face texture indices that the shader will sample from
|
||||
int32_t textureIndices[6];
|
||||
for (uint32_t j = 0; j < 6; j++) {
|
||||
textureIndices[j] = rndDist(rndEngine);
|
||||
}
|
||||
// Push vertices to buffer
|
||||
float pos = 2.5f * i - (count * 2.5f / 2.0f);
|
||||
float pos = 2.5f * i - (count * 2.5f / 2.0f) + 1.25f;
|
||||
const std::vector<Vertex> cube = {
|
||||
{ { -1.0f + pos, -1.0f, 1.0f }, { 0.0f, 0.0f }, textureIndices[0] },
|
||||
{ { 1.0f + pos, -1.0f, 1.0f }, { 1.0f, 0.0f }, textureIndices[0] },
|
||||
|
|
@ -163,18 +181,6 @@ public:
|
|||
for (auto& vertex : cube) {
|
||||
vertices.push_back(vertex);
|
||||
}
|
||||
// Push indices to buffer
|
||||
const std::vector<uint32_t> cubeIndices = {
|
||||
0,1,2,0,2,3,
|
||||
4,5,6,4,6,7,
|
||||
8,9,10,8,10,11,
|
||||
12,13,14,12,14,15,
|
||||
16,17,18,16,18,19,
|
||||
20,21,22,20,22,23
|
||||
};
|
||||
for (auto& index : cubeIndices) {
|
||||
indices.push_back(index + static_cast<uint32_t>(vertices.size()));
|
||||
}
|
||||
}
|
||||
|
||||
indexCount = static_cast<uint32_t>(indices.size());
|
||||
|
|
@ -203,6 +209,10 @@ 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)
|
||||
// SRS - increase the per-stage descriptor samplers limit on macOS (maxPerStageDescriptorUpdateAfterBindSamplers > maxPerStageDescriptorSamplers)
|
||||
descriptorPoolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT;
|
||||
#endif
|
||||
VK_CHECK_RESULT(vkCreateDescriptorPool(device, &descriptorPoolInfo, nullptr, &descriptorPool));
|
||||
|
||||
// Descriptor set layout
|
||||
|
|
@ -228,6 +238,10 @@ public:
|
|||
setLayoutBindingFlags.pBindingFlags = descriptorBindingFlags.data();
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings);
|
||||
#if defined(VK_USE_PLATFORM_MACOS_MVK)
|
||||
// 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));
|
||||
|
||||
|
|
@ -416,4 +430,4 @@ public:
|
|||
|
||||
};
|
||||
|
||||
VULKAN_EXAMPLE_MAIN()
|
||||
VULKAN_EXAMPLE_MAIN()
|
||||
|
|
|
|||
|
|
@ -234,7 +234,12 @@ private:
|
|||
imageInfo.mipLevels = 1;
|
||||
imageInfo.arrayLayers = 1;
|
||||
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
|
||||
// SRS - On macOS/iOS use linear tiling for atomic image access, see https://github.com/KhronosGroup/MoltenVK/issues/1027
|
||||
imageInfo.tiling = VK_IMAGE_TILING_LINEAR;
|
||||
#else
|
||||
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
#endif
|
||||
imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
|
||||
|
||||
VK_CHECK_RESULT(vkCreateImage(device, &imageInfo, nullptr, &geometryPass.headIndex.image));
|
||||
|
|
|
|||
|
|
@ -44,6 +44,11 @@ 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)
|
||||
// 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()
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#define ENABLE_VALIDATION false
|
||||
|
||||
#define SSAO_KERNEL_SIZE 32
|
||||
#define SSAO_KERNEL_SIZE 64
|
||||
#define SSAO_RADIUS 0.3f
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#define ENABLE_VALIDATION false
|
||||
|
||||
#define MAX_LAYERS 8
|
||||
|
||||
// Vertex layout for this example
|
||||
struct Vertex {
|
||||
float pos[3];
|
||||
|
|
@ -120,6 +122,7 @@ public:
|
|||
textureArray.width = ktxTexture->baseWidth;
|
||||
textureArray.height = ktxTexture->baseHeight;
|
||||
layerCount = ktxTexture->numLayers;
|
||||
assert(layerCount <= MAX_LAYERS);
|
||||
ktx_uint8_t *ktxTextureData = ktxTexture_GetData(ktxTexture);
|
||||
ktx_size_t ktxTextureSize = ktxTexture_GetSize(ktxTexture);
|
||||
|
||||
|
|
@ -475,7 +478,7 @@ public:
|
|||
{
|
||||
uboVS.instance = new UboInstanceData[layerCount];
|
||||
|
||||
uint32_t uboSize = sizeof(uboVS.matrices) + (layerCount * sizeof(UboInstanceData));
|
||||
uint32_t uboSize = sizeof(uboVS.matrices) + (MAX_LAYERS * sizeof(UboInstanceData));
|
||||
|
||||
// Vertex shader uniform buffer block
|
||||
VK_CHECK_RESULT(vulkanDevice->createBuffer(
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@
|
|||
# include "../examples/vertexattributes/vertexattributes.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. MoltenVK/Metal does not support stores and atomic operations in the fragment stage.
|
||||
// Runs, but some Apple GPUs may not support stores and atomic operations in the fragment stage.
|
||||
#ifdef MVK_oit
|
||||
# include "../examples/oit/oit.cpp"
|
||||
#endif
|
||||
|
|
@ -222,7 +222,7 @@
|
|||
# include "../examples/pushdescriptors/pushdescriptors.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run. Shader compilation fails with MoltenVK.
|
||||
// Runs on macOS 11.0 or later with Metal argument buffers enabled. Not yet supported on iOS.
|
||||
#ifdef MVK_descriptorindexing
|
||||
# include "../examples/descriptorindexing/descriptorindexing.cpp"
|
||||
#endif
|
||||
|
|
@ -358,7 +358,7 @@
|
|||
# include "../examples/graphicspipelinelibrary/graphicspipelinelibrary.cpp"
|
||||
#endif
|
||||
|
||||
// Does not run yet. Requires VK_KHR_dynamic_rendering (under development in MoltenVK)
|
||||
// Runs on MoltenVK 1.1.10 (SDK 1.3.216) or later. Requires VK_KHR_dynamic_rendering and dependencies.
|
||||
#ifdef MVK_dynamicrendering
|
||||
# include "../examples/dynamicrendering/dynamicrendering.cpp"
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue