├── .gitignore ├── PVRPerfDoc.png ├── tests ├── glsl │ ├── quad_no_output.frag │ ├── quad.vert │ ├── basic.comp │ ├── quad.frag │ ├── quad_no_attribs.vert │ ├── quad_sampler.frag │ ├── sampler.comp │ ├── push_constant.comp │ └── CMakeLists.txt ├── util │ ├── stub │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ └── vulkan_test.hpp ├── stub-layer-test.cpp ├── query-test.cpp ├── push-constant.cpp ├── CMakeLists.txt ├── pipeline-test.cpp ├── descriptor-set-allocation-checks.cpp ├── draw-call.cpp ├── compute-test.cpp └── transient.cpp ├── .gitmodules ├── toolchains └── armhf.cmake ├── layer ├── exports.def ├── VkLayer_mali_perf_doc.json ├── VkLayer_mali_perf_doc_win32.json ├── VkLayer_powervr_perf_doc.json ├── VkLayer_powervr_perf_doc_win32.json ├── queue.cpp ├── event.cpp ├── image_view.cpp ├── pipeline_layout.cpp ├── shader_module.cpp ├── swapchain.cpp ├── commandpool.cpp ├── queue.hpp ├── pipeline_layout.hpp ├── descriptor_set_layout.cpp ├── image_view.hpp ├── sampler.hpp ├── framebuffer.hpp ├── shader_module.hpp ├── device_memory.hpp ├── perfdoc.hpp ├── descriptor_pool.hpp ├── event.hpp ├── swapchain.hpp ├── commandpool.hpp ├── logger.hpp ├── instance.hpp ├── descriptor_set_layout.hpp ├── buffer.hpp ├── base_object.cpp ├── descriptor_pool.cpp ├── device_memory.cpp ├── render_pass.hpp ├── descriptor_set.hpp ├── queue_tracker.hpp ├── logger.cpp ├── base_object.hpp ├── perfdoc-default.cfg ├── pipeline.hpp ├── buffer.cpp ├── image.hpp ├── message_codes.hpp ├── CMakeLists.txt ├── descriptor_set.cpp ├── device.cpp ├── framebuffer.cpp ├── include │ └── vulkan │ │ └── vk_platform.h ├── dispatch_helper.hpp ├── config.cpp ├── heuristic.hpp ├── device.hpp ├── commandbuffer.hpp └── sampler.cpp ├── LICENSE ├── run_tests.sh ├── format_all.sh ├── BUILD.md ├── CMakeLists.txt ├── cross_build.sh └── .clang-format /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.swp 3 | .idea 4 | -------------------------------------------------------------------------------- /PVRPerfDoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/powervr-graphics/perfdoc/HEAD/PVRPerfDoc.png -------------------------------------------------------------------------------- /tests/glsl/quad_no_output.frag: -------------------------------------------------------------------------------- 1 | #version 310 es 2 | 3 | precision mediump float; 4 | 5 | void main() 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "layer/SPIRV-Cross"] 2 | path = layer/SPIRV-Cross 3 | url = git://github.com/KhronosGroup/SPIRV-Cross.git 4 | -------------------------------------------------------------------------------- /toolchains/armhf.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) 4 | set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) 5 | -------------------------------------------------------------------------------- /layer/exports.def: -------------------------------------------------------------------------------- 1 | LIBRARY VkLayer_powervr_perf_doc 2 | EXPORTS 3 | vkGetInstanceProcAddr 4 | vkGetDeviceProcAddr 5 | vkEnumerateDeviceLayerProperties 6 | vkEnumerateInstanceLayerProperties 7 | vkEnumerateDeviceExtensionProperties 8 | vkEnumerateInstanceExtensionProperties 9 | -------------------------------------------------------------------------------- /tests/util/stub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB sources *.cpp) 2 | file(GLOB sources-headers *.hpp) 3 | add_library(vulkan-stub STATIC 4 | ${sources} 5 | ${sources-headers}) 6 | 7 | target_include_directories(vulkan-stub PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../../../layer/include) 8 | target_link_libraries(vulkan-stub) 9 | 10 | -------------------------------------------------------------------------------- /layer/VkLayer_mali_perf_doc.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_format_version" : "1.0.0", 3 | "layer" : { 4 | "name": "VK_LAYER_ARM_mali_perf_doc", 5 | "type": "GLOBAL", 6 | "library_path": "./libVkLayer_mali_perf_doc.so", 7 | "api_version": "1.0.32", 8 | "implementation_version": "1", 9 | "description": "ARM Mali PerfDoc", 10 | "instance_extensions": [ 11 | { 12 | "name": "VK_EXT_debug_report", 13 | "spec_version": "3" 14 | } 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /layer/VkLayer_mali_perf_doc_win32.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_format_version" : "1.0.0", 3 | "layer" : { 4 | "name": "VK_LAYER_ARM_mali_perf_doc", 5 | "type": "GLOBAL", 6 | "library_path": ".\\VkLayer_mali_perf_doc.dll", 7 | "api_version": "1.0.32", 8 | "implementation_version": "1", 9 | "description": "ARM Mali PerfDoc", 10 | "instance_extensions": [ 11 | { 12 | "name": "VK_EXT_debug_report", 13 | "spec_version": "3" 14 | } 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /layer/VkLayer_powervr_perf_doc.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_format_version" : "1.0.0", 3 | "layer" : { 4 | "name": "VK_LAYER_IMG_powervr_perf_doc", 5 | "type": "GLOBAL", 6 | "library_path": "./libVkLayer_powervr_perf_doc.so", 7 | "api_version": "1.0.0", 8 | "implementation_version": "1", 9 | "description": "IMG PowerVR PerfDoc", 10 | "instance_extensions": [ 11 | { 12 | "name": "VK_EXT_debug_report", 13 | "spec_version": "3" 14 | } 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /layer/VkLayer_powervr_perf_doc_win32.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_format_version" : "1.0.0", 3 | "layer" : { 4 | "name": "VK_LAYER_IMG_powervr_perf_doc", 5 | "type": "GLOBAL", 6 | "library_path": ".\\VkLayer_powervr_perf_doc.dll", 7 | "api_version": "1.0.0", 8 | "implementation_version": "1", 9 | "description": "IMG PowerVR PerfDoc", 10 | "instance_extensions": [ 11 | { 12 | "name": "VK_EXT_debug_report", 13 | "spec_version": "3" 14 | } 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, ARM Limited and Contributors 2 | Copyright (c) 2019, Imagination Technologies Ltd. 3 | 4 | SPDX-License-Identifier: MIT 5 | 6 | Permission is hereby granted, free of charge, 7 | to any person obtaining a copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 15 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2017, ARM Limited and Contributors 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Permission is hereby granted, free of charge, 8 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | # to deal in the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | CURDIR="`pwd`" 23 | VK_LAYER_PATH="$CURDIR/layer" ctest -R perfdoc --verbose $@ 24 | -------------------------------------------------------------------------------- /tests/glsl/quad.vert: -------------------------------------------------------------------------------- 1 | #version 310 es 2 | 3 | /* Copyright (c) 2017, ARM Limited and Contributors 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | layout(location = 0) in vec4 Position; 24 | 25 | void main() 26 | { 27 | gl_Position = Position; 28 | } 29 | -------------------------------------------------------------------------------- /tests/glsl/basic.comp: -------------------------------------------------------------------------------- 1 | #version 310 es 2 | 3 | /* Copyright (c) 2017, ARM Limited and Contributors 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | layout(local_size_x = WG_X, local_size_y = WG_Y, local_size_z = WG_Z) in; 24 | 25 | void main() 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /layer/queue.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "queue.hpp" 22 | 23 | namespace MPD 24 | { 25 | VkResult Queue::init(VkQueue queue) 26 | { 27 | this->queue = queue; 28 | return VK_SUCCESS; 29 | } 30 | } -------------------------------------------------------------------------------- /tests/glsl/quad.frag: -------------------------------------------------------------------------------- 1 | #version 310 es 2 | 3 | /* Copyright (c) 2017, ARM Limited and Contributors 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | precision mediump float; 24 | 25 | layout(location = 0) out vec4 FragColor; 26 | 27 | void main() 28 | { 29 | FragColor = vec4(1.0); 30 | } 31 | -------------------------------------------------------------------------------- /format_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2017, ARM Limited and Contributors 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Permission is hereby granted, free of charge, 8 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | # to deal in the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | shopt -s globstar 23 | 24 | for file in layer/*.{cpp,hpp} tests/*.cpp tests/util/*.{cpp,hpp} 25 | do 26 | echo "Formatting file: $file ..." 27 | clang-format -style=file -i $file 28 | sed -i $file -e 's|\r||g' 29 | done 30 | -------------------------------------------------------------------------------- /tests/glsl/quad_no_attribs.vert: -------------------------------------------------------------------------------- 1 | #version 310 es 2 | 3 | /* Copyright (c) 2017, ARM Limited and Contributors 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | void main() 24 | { 25 | const vec2 POSITIONS[4] = vec2[](vec2(-1.0, 1.0), vec2(3.0, 1.0), vec2(-1.0, -3.0), vec2(0.0)); 26 | 27 | gl_Position = vec4(POSITIONS[gl_VertexIndex & 3], 0.0, 1.0); 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/glsl/quad_sampler.frag: -------------------------------------------------------------------------------- 1 | #version 310 es 2 | 3 | /* Copyright (c) 2017, ARM Limited and Contributors 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | precision mediump float; 24 | 25 | layout(location = 0) out vec4 FragColor; 26 | layout(set = 0, binding = 0) uniform sampler2D uSampler; 27 | 28 | void main() 29 | { 30 | FragColor = texture(uSampler, vec2(0.5)); 31 | } 32 | -------------------------------------------------------------------------------- /tests/stub-layer-test.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "vulkan_test.hpp" 22 | #include "perfdoc.hpp" 23 | #include "util.hpp" 24 | using namespace MPD; 25 | 26 | class StubTest : public VulkanTestHelper 27 | { 28 | bool runTest() override 29 | { 30 | return true; 31 | } 32 | }; 33 | 34 | VulkanTestHelper *MPD::createTest() 35 | { 36 | return new StubTest; 37 | } 38 | -------------------------------------------------------------------------------- /tests/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, ARM Limited and Contributors 2 | # 3 | # SPDX-License-Identifier: MIT 4 | # 5 | # Permission is hereby granted, free of charge, 6 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | # to deal in the Software without restriction, including without limitation the rights to 8 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | add_subdirectory(stub) 21 | 22 | add_library(test-util STATIC util.cpp util.hpp vulkan_test.cpp vulkan_test.hpp) 23 | target_include_directories(test-util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../..) 24 | target_link_libraries(test-util spirv-cross-core vulkan-stub) 25 | 26 | if (NOT WIN32) 27 | target_link_libraries(test-util dl) 28 | endif() 29 | -------------------------------------------------------------------------------- /layer/event.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "event.hpp" 22 | #include "device.hpp" 23 | 24 | namespace MPD 25 | { 26 | VkResult Event::init(VkEvent event, const VkEventCreateInfo &createInfo) 27 | { 28 | this->event = event; 29 | this->createInfo = createInfo; 30 | return VK_SUCCESS; 31 | } 32 | 33 | void Event::reset() 34 | { 35 | signalled = false; 36 | } 37 | 38 | void Event::signal() 39 | { 40 | signalled = true; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /layer/image_view.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "image_view.hpp" 22 | #include "device.hpp" 23 | 24 | namespace MPD 25 | { 26 | VkResult ImageView::init(VkImageView imageView_, const VkImageViewCreateInfo &createInfo_) 27 | { 28 | imageView = imageView_; 29 | createInfo = createInfo_; 30 | image = baseDevice->get(createInfo.image); 31 | return VK_SUCCESS; 32 | } 33 | 34 | void ImageView::signalUsage(Image::Usage usage) 35 | { 36 | image->signalUsage(createInfo.subresourceRange, usage); 37 | } 38 | } -------------------------------------------------------------------------------- /layer/pipeline_layout.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "pipeline_layout.hpp" 22 | #include "device.hpp" 23 | 24 | namespace MPD 25 | { 26 | VkResult PipelineLayout::init(const VkPipelineLayoutCreateInfo *pCreateInfo) 27 | { 28 | uint32_t numSets = pCreateInfo->setLayoutCount; 29 | for (uint32_t i = 0; i < numSets; i++) 30 | { 31 | auto *setLayout = baseDevice->get(pCreateInfo->pSetLayouts[i]); 32 | MPD_ASSERT(setLayout); 33 | descriptorSetLayouts.push_back(setLayout); 34 | } 35 | 36 | return VK_SUCCESS; 37 | } 38 | } -------------------------------------------------------------------------------- /tests/glsl/sampler.comp: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | /* Copyright (c) 2017, ARM Limited and Contributors 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | layout(local_size_x = WG_X, local_size_y = WG_Y, local_size_z = WG_Z) in; 24 | 25 | #if defined(SAMPLER_2D) 26 | layout(set = 0, binding = 0) uniform sampler2D uSampler; 27 | #elif defined(SAMPLER_1D) 28 | layout(set = 0, binding = 0) uniform sampler1D uSampler; 29 | #endif 30 | 31 | void main() 32 | { 33 | #if defined(SAMPLER_2D) 34 | vec4 value = textureLod(uSampler, vec2(0.5), 0.0); 35 | #elif defined(SAMPLER_1D) 36 | vec4 value = textureLod(uSampler, 0.5, 0.0); 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | ## Building 2 | 3 | ``` 4 | git submodule init 5 | git submodule update 6 | ``` 7 | 8 | ### Building layer 9 | ``` 10 | mkdir build 11 | cd build 12 | cmake .. -DCMAKE_BUILD_TYPE=Debug # For some reason the CMAKE_BUILD_TYPE must be set, or include path issues will happen. 13 | make -j8 # If using Makefile target in CMake. 14 | ``` 15 | 16 | ### Building and running tests 17 | ``` 18 | # To run tests 19 | # glslc must be in $PATH. 20 | cmake .. -DCMAKE_BUILD_TYPE=Debug -DPERFDOC_TESTS=ON 21 | make -j8 # If using Makefile target in CMake. 22 | ../run_tests.sh -C # -C is required on MSVC. 23 | ``` 24 | 25 | ### Android 26 | 27 | The layer can be built using bundled CMake and NDK from Android Studio 28 | 29 | ``` 30 | mkdir build-android 31 | cd build-android 32 | 33 | export ANDROID_SDK=$HOME/Android/Sdk # Typical, but depends where Android Studio installed the SDK. 34 | export ANDROID_ABI=arm64-v8a # For aarch64, armeabi-v7a for ARMv7a. 35 | $ANDROID_SDK/cmake/3.6.3155560/bin/cmake \ 36 | .. \ 37 | -DANDROID_STL=c++_static \ 38 | -DANDROID_TOOLCHAIN=clang \ 39 | -DCMAKE_TOOLCHAIN_FILE=$ANDROID_SDK/ndk-bundle/build/cmake/android.toolchain.cmake \ 40 | -DANDROID_ABI=$ANDROID_ABI \ 41 | -DANDROID_CPP_FEATURES=exceptions \ 42 | -DANDROID_ARM_MODE=arm 43 | 44 | make -j8 45 | ``` 46 | 47 | ### Windows 48 | 49 | #### MinGW-w64 50 | 51 | ``` 52 | mkdir build-windows 53 | cd build-windows 54 | x86_64-w64-mingw-cmake .. 55 | make -j8 56 | ``` 57 | 58 | #### MSVC 59 | 60 | Build has been tested with MSVC 2017, but may work on earlier versions. 61 | 62 | ``` 63 | mkdir build-windows-msvc 64 | cd build-windows-msvc 65 | cmake .. -G "Visual Studio 15 2017 Win64" 66 | cmake --build . --config Release # Or, open the solution in MSVC and build there. 67 | ``` 68 | 69 | -------------------------------------------------------------------------------- /layer/shader_module.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "shader_module.hpp" 22 | 23 | using namespace std; 24 | 25 | namespace MPD 26 | { 27 | VkResult ShaderModule::init(VkShaderModule shaderModule_, const VkShaderModuleCreateInfo &createInfo) 28 | { 29 | shaderModule = shaderModule_; 30 | spirv.reserve(createInfo.codeSize / sizeof(uint32_t)); 31 | spirv.insert(end(spirv), createInfo.pCode, createInfo.pCode + createInfo.codeSize / sizeof(uint32_t)); 32 | 33 | // We don't yet know the entry point nor the pipeline stage, so we cannot do any analysis yet, defer till pipeline creation. 34 | return VK_SUCCESS; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/query-test.cpp: -------------------------------------------------------------------------------- 1 | 2 | //Note vulkan test needs to come before perfdoc... 3 | #include "vulkan_test.hpp" 4 | #include "perfdoc.hpp" 5 | #include "util.hpp" 6 | #include 7 | #include 8 | using namespace MPD; 9 | using namespace std; 10 | 11 | class QueryTest : public VulkanTestHelper 12 | { 13 | public: 14 | bool testQueryPoolReset(bool positiveTest) 15 | { 16 | auto cmdbuf = make_shared(device); 17 | cmdbuf->initPrimary(); 18 | 19 | VkQueryPoolCreateInfo qpci = { VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO }; 20 | qpci.queryCount = positiveTest ? 1 : 100; 21 | qpci.queryType = VK_QUERY_TYPE_OCCLUSION; 22 | qpci.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT; 23 | 24 | VkQueryPool pool; 25 | vkCreateQueryPool(device, &qpci, 0, &pool); 26 | 27 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; 28 | vkBeginCommandBuffer(cmdbuf->commandBuffer, &cbbi); 29 | 30 | vkCmdResetQueryPool(cmdbuf->commandBuffer, pool, 0, positiveTest ? 1 : 100); 31 | 32 | vkEndCommandBuffer(cmdbuf->commandBuffer); 33 | 34 | vkDestroyQueryPool(device, pool, 0); 35 | 36 | uint32_t count = getCount(MESSAGE_CODE_QUERY_BUNDLE_TOO_SMALL); 37 | resetCounts(); 38 | 39 | if (positiveTest) 40 | { 41 | if (count != 1) 42 | return false; 43 | } 44 | else 45 | { 46 | if (count != 0) 47 | return false; 48 | } 49 | return true; 50 | } 51 | 52 | bool runTest() override 53 | { 54 | if (!testQueryPoolReset(false)) 55 | return false; 56 | 57 | if (!testQueryPoolReset(true)) 58 | return false; 59 | 60 | return true; 61 | } 62 | 63 | virtual bool initialize() 64 | { 65 | return true; 66 | } 67 | }; 68 | 69 | VulkanTestHelper *MPD::createTest() 70 | { 71 | return new QueryTest; 72 | } 73 | -------------------------------------------------------------------------------- /layer/swapchain.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "swapchain.hpp" 22 | 23 | namespace MPD 24 | { 25 | VkResult SwapchainKHR::init(VkSwapchainKHR swapchain_, const VkSwapchainCreateInfoKHR &createInfo_, 26 | std::vector swapchainImages_) 27 | { 28 | swapchain = swapchain_; 29 | createInfo = createInfo_; 30 | swapchainImages = move(swapchainImages_); 31 | 32 | return VK_SUCCESS; 33 | } 34 | 35 | bool SwapchainKHR::potentiallySteal(VkImage swapchainImage) 36 | { 37 | for (auto &image : swapchainImages) 38 | { 39 | if (image == swapchainImage) 40 | { 41 | image = VK_NULL_HANDLE; 42 | return true; 43 | } 44 | } 45 | return false; 46 | } 47 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, ARM Limited and Contributors 2 | # 3 | # SPDX-License-Identifier: MIT 4 | # 5 | # Permission is hereby granted, free of charge, 6 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | # to deal in the Software without restriction, including without limitation the rights to 8 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | cmake_minimum_required(VERSION 3.5) 21 | 22 | set(CMAKE_CXX_STANDARD 11) 23 | set(CMAKE_C_STANDARD 99) 24 | 25 | project(PowerVR-PerfDoc LANGUAGES CXX C) 26 | 27 | if ((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")) 28 | set(PERFDOC_CXX_FLAGS -Wall -Wextra -Wno-missing-field-initializers) 29 | elseif(MSVC) 30 | set(PERFDOC_CXX_FLAGS /wd4244 /wd4996 /wd4800 /D_CRT_SECURE_NO_WARNINGS /DNOMINMAX) 31 | endif() 32 | 33 | enable_testing() 34 | set(PLATFORM png) 35 | add_subdirectory(layer) 36 | 37 | option(PERFDOC_TESTS "Enable unit tests." OFF) 38 | if (PERFDOC_TESTS) 39 | if (NOT ANDROID) 40 | add_subdirectory(tests) 41 | endif() 42 | endif() 43 | -------------------------------------------------------------------------------- /layer/commandpool.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "commandpool.hpp" 22 | #include "commandbuffer.hpp" 23 | #include "device.hpp" 24 | 25 | namespace MPD 26 | { 27 | CommandPool::~CommandPool() 28 | { 29 | baseDevice->freeCommandBuffers(this); 30 | } 31 | 32 | VkResult CommandPool::init(VkCommandPool commandPool_) 33 | { 34 | commandPool = commandPool_; 35 | commandBuffers.clear(); 36 | return VK_SUCCESS; 37 | } 38 | 39 | void CommandPool::addCommandBuffer(CommandBuffer *commandBuffer) 40 | { 41 | commandBuffers.insert(commandBuffer); 42 | } 43 | 44 | void CommandPool::removeCommandBuffer(CommandBuffer *commandBuffer) 45 | { 46 | commandBuffers.erase(commandBuffer); 47 | } 48 | 49 | void CommandPool::resetCommandBuffers() 50 | { 51 | for (auto it : commandBuffers) 52 | it->reset(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /layer/queue.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "perfdoc.hpp" 25 | #include "queue_tracker.hpp" 26 | 27 | namespace MPD 28 | { 29 | class Queue : public BaseObject 30 | { 31 | public: 32 | using VulkanType = VkQueue; 33 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT; 34 | 35 | Queue(Device *device, uint64_t objHandle_) 36 | : BaseObject(device, objHandle_, VULKAN_OBJECT_TYPE) 37 | , queueTracker(*this) 38 | { 39 | } 40 | 41 | VkResult init(VkQueue queue); 42 | 43 | VkQueue getQueue() const 44 | { 45 | return queue; 46 | } 47 | 48 | QueueTracker &getQueueTracker() 49 | { 50 | return queueTracker; 51 | } 52 | 53 | private: 54 | VkQueue queue; 55 | QueueTracker queueTracker; 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /layer/pipeline_layout.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "descriptor_set_layout.hpp" 24 | 25 | #include 26 | 27 | namespace MPD 28 | { 29 | class PipelineLayout : public BaseObject 30 | { 31 | public: 32 | using VulkanType = VkPipelineLayout; 33 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT; 34 | 35 | PipelineLayout(Device *device_, uint64_t objHandle_) 36 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 37 | { 38 | } 39 | 40 | VkResult init(const VkPipelineLayoutCreateInfo *pCreateInfo); 41 | 42 | const std::vector &getDescriptorSetLayouts() const 43 | { 44 | return descriptorSetLayouts; 45 | } 46 | 47 | private: 48 | std::vector descriptorSetLayouts; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /layer/descriptor_set_layout.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "descriptor_set_layout.hpp" 22 | 23 | namespace MPD 24 | { 25 | VkResult DescriptorSetLayout::init(const VkDescriptorSetLayoutCreateInfo *pCreateInfo) 26 | { 27 | uint32_t bindings = pCreateInfo->bindingCount; 28 | for (uint32_t i = 0; i < bindings; i++) 29 | { 30 | auto &binding = pCreateInfo->pBindings[i]; 31 | 32 | switch (binding.descriptorType) 33 | { 34 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: 35 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: 36 | sampledImageBindings.insert(binding.binding); 37 | break; 38 | 39 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: 40 | storageImageBindings.insert(binding.binding); 41 | break; 42 | 43 | default: 44 | break; 45 | } 46 | 47 | this->bindings[binding.binding] = { binding.descriptorType, binding.descriptorCount }; 48 | } 49 | 50 | return VK_SUCCESS; 51 | } 52 | } -------------------------------------------------------------------------------- /layer/image_view.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "image.hpp" 24 | #include 25 | 26 | namespace MPD 27 | { 28 | class ImageView : public BaseObject 29 | { 30 | public: 31 | using VulkanType = VkImageView; 32 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT; 33 | 34 | ImageView(Device *device_, uint64_t objHandle_) 35 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 36 | { 37 | } 38 | 39 | VkResult init(VkImageView imageView, const VkImageViewCreateInfo &createInfo); 40 | 41 | const VkImageViewCreateInfo &getCreateInfo() const 42 | { 43 | return createInfo; 44 | } 45 | 46 | void signalUsage(Image::Usage usage); 47 | 48 | private: 49 | VkImageView imageView = VK_NULL_HANDLE; 50 | VkImageViewCreateInfo createInfo; 51 | Image *image = nullptr; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /layer/sampler.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | 24 | namespace MPD 25 | { 26 | class Sampler : BaseObject 27 | { 28 | public: 29 | using VulkanType = VkSampler; 30 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT; 31 | 32 | Sampler(Device *device_, uint64_t objHandle_) 33 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 34 | { 35 | } 36 | 37 | VkResult init(VkSampler sampler, const VkSamplerCreateInfo &createInfo); 38 | 39 | const VkSamplerCreateInfo &getCreateInfo() const 40 | { 41 | return createInfo; 42 | } 43 | 44 | private: 45 | VkSampler sampler; 46 | VkSamplerCreateInfo createInfo; 47 | 48 | void checkIdenticalWrapping(); 49 | void checkLodClamping(); 50 | void checkLodBias(); 51 | void checkBorderClamp(); 52 | void checkUnnormalizedCoords(); 53 | void checkAnisotropy(); 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /layer/framebuffer.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "image_view.hpp" 24 | #include 25 | 26 | namespace MPD 27 | { 28 | class Framebuffer : public BaseObject 29 | { 30 | public: 31 | using VulkanType = VkFramebuffer; 32 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT; 33 | 34 | Framebuffer(Device *device_, uint64_t objHandle_) 35 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 36 | { 37 | } 38 | 39 | VkResult init(VkFramebuffer framebuffer, const VkFramebufferCreateInfo &createInfo); 40 | 41 | const VkFramebufferCreateInfo &getCreateInfo() const 42 | { 43 | return createInfo; 44 | } 45 | 46 | private: 47 | VkFramebuffer framebuffer = VK_NULL_HANDLE; 48 | VkFramebufferCreateInfo createInfo; 49 | std::vector imageViews; 50 | 51 | void checkPotentiallyTransient(); 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /layer/shader_module.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "perfdoc.hpp" 25 | #include 26 | 27 | namespace MPD 28 | { 29 | class ShaderModule : public BaseObject 30 | { 31 | public: 32 | using VulkanType = VkShaderModule; 33 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT; 34 | 35 | ShaderModule(Device *device_, uint64_t objHandle_) 36 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 37 | { 38 | } 39 | 40 | VkResult init(VkShaderModule shaderModule, const VkShaderModuleCreateInfo &createInfo); 41 | 42 | const std::vector &getCode() const 43 | { 44 | return spirv; 45 | } 46 | 47 | VkShaderModule getShaderModule() const 48 | { 49 | return shaderModule; 50 | } 51 | 52 | private: 53 | VkShaderModule shaderModule; 54 | std::vector spirv; 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /layer/device_memory.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "perfdoc.hpp" 25 | 26 | namespace MPD 27 | { 28 | class DeviceMemory : public BaseObject 29 | { 30 | public: 31 | using VulkanType = VkDeviceMemory; 32 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT; 33 | 34 | DeviceMemory(Device *device, uint64_t objHandle_) 35 | : BaseObject(device, objHandle_, VULKAN_OBJECT_TYPE) 36 | { 37 | } 38 | 39 | VkResult init(VkDeviceMemory memory, const VkMemoryAllocateInfo &allocInfo); 40 | 41 | const VkMemoryAllocateInfo &getAllocateInfo() const 42 | { 43 | return allocInfo; 44 | } 45 | 46 | void *getMappedMemory() const 47 | { 48 | return mappedMemory; 49 | } 50 | 51 | private: 52 | void *mappedMemory; 53 | VkDeviceMemory memory = VK_NULL_HANDLE; 54 | VkMemoryAllocateInfo allocInfo; 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /layer/perfdoc.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include 23 | #include 24 | 25 | #define MPD_ASSERT(x) assert(x) 26 | 27 | /// Used for test scenarios where we should never fail. 28 | #define MPD_ALWAYS_ASSERT(x) \ 29 | do \ 30 | { \ 31 | if (!(x)) \ 32 | std::terminate(); \ 33 | } while (0) 34 | 35 | /// Used in test code only. 36 | #define MPD_ASSERT_RESULT(x) \ 37 | do \ 38 | { \ 39 | if ((x) != VK_SUCCESS) \ 40 | std::terminate(); \ 41 | } while (0) 42 | 43 | #define VK_LAYER_IMG_powervr_perf_doc "VK_LAYER_IMG_powervr_perf_doc" 44 | 45 | #ifdef ANDROID 46 | #include 47 | #define MPD_LOG(...) __android_log_print(ANDROID_LOG_DEBUG, "PowerVRPerfDoc", __VA_ARGS__) 48 | #else 49 | #define MPD_LOG(...) fprintf(stderr, __VA_ARGS__) 50 | #endif 51 | 52 | #define MPD_UNUSED(x) ((void)(x)) 53 | -------------------------------------------------------------------------------- /layer/descriptor_pool.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include 24 | #include 25 | 26 | namespace MPD 27 | { 28 | 29 | class DescriptorSet; 30 | 31 | class DescriptorPool : public BaseObject 32 | { 33 | public: 34 | using VulkanType = VkDescriptorPool; 35 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT; 36 | 37 | DescriptorPool(Device *device, uint64_t objHandle_) 38 | : BaseObject(device, objHandle_, VULKAN_OBJECT_TYPE) 39 | { 40 | } 41 | 42 | ~DescriptorPool(); 43 | 44 | VkResult init(const VkDescriptorPoolCreateInfo &) 45 | { 46 | return VK_SUCCESS; 47 | } 48 | 49 | void descriptorSetCreated(DescriptorSet *dset); 50 | 51 | void descriptorSetDeleted(DescriptorSet *dset); 52 | 53 | void reset(); 54 | 55 | private: 56 | struct DescriptorSetLayoutInfo 57 | { 58 | uint32_t descriptorSetsFreedCount; 59 | }; 60 | 61 | std::unordered_map layoutInfos; 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /tests/util/vulkan_test.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "libvulkan-stub.h" 24 | #include "layer/config.hpp" 25 | #include "layer/message_codes.hpp" 26 | 27 | namespace MPD 28 | { 29 | class VulkanTestHelper 30 | { 31 | public: 32 | VulkanTestHelper(); 33 | virtual ~VulkanTestHelper(); 34 | 35 | virtual bool initialize() 36 | { 37 | return true; 38 | } 39 | 40 | virtual bool runTest() = 0; 41 | 42 | const Config &getConfig() const 43 | { 44 | return cfg; 45 | } 46 | 47 | void notifyCallback(MessageCodes code); 48 | 49 | protected: 50 | void resetCounts(); 51 | unsigned getCount(MessageCodes code) const; 52 | 53 | VkInstance instance = VK_NULL_HANDLE; 54 | VkDevice device = VK_NULL_HANDLE; 55 | VkPhysicalDevice gpu = VK_NULL_HANDLE; 56 | VkQueue queue = VK_NULL_HANDLE; 57 | VkPhysicalDeviceMemoryProperties memoryProperties = {}; 58 | VkPhysicalDeviceProperties gpuProperties = {}; 59 | VkDebugReportCallbackEXT callback = VK_NULL_HANDLE; 60 | 61 | unsigned warningCount[MESSAGE_CODE_COUNT] = {}; 62 | Config cfg; 63 | }; 64 | 65 | // Implemented by tests. 66 | VulkanTestHelper *createTest(); 67 | } -------------------------------------------------------------------------------- /layer/event.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "image_view.hpp" 24 | #include "queue_tracker.hpp" 25 | #include 26 | 27 | namespace MPD 28 | { 29 | class Event : public BaseObject 30 | { 31 | public: 32 | using VulkanType = VkEvent; 33 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT; 34 | 35 | Event(Device *device_, uint64_t objHandle_) 36 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 37 | { 38 | } 39 | 40 | VkResult init(VkEvent event, const VkEventCreateInfo &createInfo); 41 | 42 | const VkEventCreateInfo &getCreateInfo() const 43 | { 44 | return createInfo; 45 | } 46 | 47 | void reset(); 48 | void signal(); 49 | 50 | bool getSignalStatus() const 51 | { 52 | return signalled; 53 | } 54 | 55 | uint64_t *getWaitList() 56 | { 57 | return waitList; 58 | } 59 | 60 | const uint64_t *getWaitList() const 61 | { 62 | return waitList; 63 | } 64 | 65 | private: 66 | VkEvent event; 67 | VkEventCreateInfo createInfo; 68 | uint64_t waitList[QueueTracker::STAGE_COUNT] = {}; 69 | bool signalled = false; 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /layer/swapchain.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "base_object.hpp" 24 | #include 25 | 26 | namespace MPD 27 | { 28 | class SwapchainKHR : public BaseObject 29 | { 30 | public: 31 | using VulkanType = VkSwapchainKHR; 32 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT; 33 | 34 | SwapchainKHR(Device *device_, uint64_t objHandle_) 35 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 36 | { 37 | } 38 | 39 | VkResult init(VkSwapchainKHR swapchain, const VkSwapchainCreateInfoKHR &createInfo, 40 | std::vector swapchainImages); 41 | 42 | const VkSwapchainCreateInfoKHR &getCreateInfo() const 43 | { 44 | return createInfo; 45 | } 46 | 47 | const std::vector &getSwapchainImages() const 48 | { 49 | return swapchainImages; 50 | } 51 | 52 | VkSwapchainKHR getSwapchain() const 53 | { 54 | return swapchain; 55 | } 56 | 57 | bool potentiallySteal(VkImage swapchainImage); 58 | 59 | private: 60 | VkSwapchainKHR swapchain; 61 | VkSwapchainCreateInfoKHR createInfo; 62 | std::vector swapchainImages; 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /layer/commandpool.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "perfdoc.hpp" 25 | 26 | #include 27 | 28 | namespace MPD 29 | { 30 | 31 | class CommandBuffer; 32 | 33 | class CommandPool : public BaseObject 34 | { 35 | public: 36 | using VulkanType = VkCommandPool; 37 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT; 38 | 39 | CommandPool(Device *device, uint64_t objHandle_) 40 | : BaseObject(device, objHandle_, VULKAN_OBJECT_TYPE) 41 | { 42 | } 43 | 44 | ~CommandPool(); 45 | 46 | VkResult init(VkCommandPool commandPool_); 47 | 48 | VkCommandPool getCommandPool() const 49 | { 50 | return commandPool; 51 | } 52 | 53 | void addCommandBuffer(CommandBuffer *commandBuffer); 54 | void removeCommandBuffer(CommandBuffer *commandBuffer); 55 | void resetCommandBuffers(); 56 | 57 | std::unordered_set &getCommandBuffers() 58 | { 59 | return commandBuffers; 60 | } 61 | 62 | private: 63 | VkCommandPool commandPool = VK_NULL_HANDLE; 64 | std::unordered_set commandBuffers; 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /layer/logger.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "perfdoc.hpp" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace MPD 30 | { 31 | 32 | // Opaque, only used internally. 33 | struct LoggerCallback; 34 | 35 | struct LoggerMessageInfo 36 | { 37 | VkDebugReportFlagsEXT flags; 38 | VkDebugReportObjectTypeEXT objectType; 39 | uint64_t object; 40 | int32_t messageCode; 41 | }; 42 | 43 | /// The main logger. 44 | class Logger 45 | { 46 | public: 47 | Logger(); 48 | ~Logger(); 49 | 50 | Logger(const Logger &) = delete; 51 | Logger &operator=(const Logger &) = delete; 52 | 53 | LoggerCallback *createAndRegisterCallback(VkDebugReportCallbackEXT callback, 54 | const VkDebugReportCallbackCreateInfoEXT &createInfo); 55 | 56 | void unregisterAndDestroyCallback(VkDebugReportCallbackEXT callback); 57 | 58 | /// Send a formated message. 59 | void write(const LoggerMessageInfo &inf, const char *msg); 60 | 61 | private: 62 | std::unordered_map> debugCallbacks; 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /layer/instance.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "config.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "logger.hpp" 25 | #include "perfdoc.hpp" 26 | #include 27 | #include 28 | 29 | namespace MPD 30 | { 31 | class Instance 32 | { 33 | public: 34 | bool init(VkInstance instance_, VkLayerInstanceDispatchTable *pTable_, PFN_vkGetInstanceProcAddr gpa_); 35 | 36 | VkInstance getInstance() const 37 | { 38 | return instance; 39 | } 40 | 41 | const VkLayerInstanceDispatchTable *getTable() const 42 | { 43 | return pTable; 44 | } 45 | 46 | PFN_vkVoidFunction getProcAddr(const char *pName) 47 | { 48 | return gpa(instance, pName); 49 | } 50 | 51 | Logger &getLogger() 52 | { 53 | return logger; 54 | } 55 | 56 | const Config &getConfig() const 57 | { 58 | return cfg; 59 | } 60 | 61 | private: 62 | VkInstance instance = VK_NULL_HANDLE; 63 | VkLayerInstanceDispatchTable *pTable = nullptr; 64 | PFN_vkGetInstanceProcAddr gpa = nullptr; 65 | 66 | struct FILEDeleter 67 | { 68 | void operator()(FILE *file) 69 | { 70 | if (file) 71 | fclose(file); 72 | } 73 | }; 74 | std::unique_ptr cfgLogFile; 75 | Logger logger; 76 | Config cfg; 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /tests/glsl/push_constant.comp: -------------------------------------------------------------------------------- 1 | #version 310 es 2 | 3 | /* Copyright (c) 2017, ARM Limited and Contributors 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * Permission is hereby granted, free of charge, 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | layout(local_size_x = 1) in; 24 | 25 | // Including a push constant block silences the warning. 26 | #ifdef PUSH_CONSTANT 27 | layout(std430, push_constant) uniform Push 28 | { 29 | vec4 dummy; 30 | } registers; 31 | #endif 32 | 33 | struct Foobar 34 | { 35 | vec4 a; 36 | vec4 b; 37 | }; 38 | 39 | struct FoobarDynamic 40 | { 41 | vec4 a; 42 | vec4 b[10]; 43 | }; 44 | 45 | layout(std140, set = 0, binding = 0) uniform UBO 46 | { 47 | vec4 dummy1[16]; // This cannot be a push constant. 48 | vec4 dummy2; // This can be a push constant. 49 | }; 50 | 51 | layout(std140, set = 0, binding = 1) uniform UBO1 52 | { 53 | vec4 dummy3; // This can be. 54 | Foobar dummy4; // This can be. 55 | FoobarDynamic dummy5; // This cannot be. 56 | }; 57 | 58 | layout(std140, set = 0, binding = 2) uniform UBOS 59 | { 60 | vec4 dummy; 61 | } ubos[1]; // Array of UBOs should not be considered. 62 | 63 | void main() 64 | { 65 | #ifdef PUSH_CONSTANT 66 | vec4 dummy = registers.dummy; 67 | #endif 68 | 69 | vec4 t; 70 | t = dummy1[gl_WorkGroupID.x]; 71 | t = dummy2; 72 | t = vec4(dummy3[gl_WorkGroupID.x]); // This is fine. 73 | t = dummy4.a; 74 | t = dummy5.b[gl_WorkGroupID.x]; 75 | t = ubos[0].dummy; 76 | } 77 | -------------------------------------------------------------------------------- /layer/descriptor_set_layout.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include 24 | #include 25 | 26 | namespace MPD 27 | { 28 | 29 | class DescriptorSetLayout : public BaseObject 30 | { 31 | public: 32 | using VulkanType = VkDescriptorSetLayout; 33 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT; 34 | 35 | DescriptorSetLayout(Device *device, uint64_t objHandle_) 36 | : BaseObject(device, objHandle_, VULKAN_OBJECT_TYPE) 37 | { 38 | } 39 | 40 | VkResult init(const VkDescriptorSetLayoutCreateInfo *pCreateInfo); 41 | 42 | const std::unordered_set &getSampledImageBindings() const 43 | { 44 | return sampledImageBindings; 45 | } 46 | 47 | const std::unordered_set &getStorageImageBindings() const 48 | { 49 | return storageImageBindings; 50 | } 51 | 52 | struct Binding 53 | { 54 | VkDescriptorType descriptorType; 55 | uint32_t arraySize; 56 | }; 57 | 58 | const std::unordered_map &getBindings() const 59 | { 60 | return bindings; 61 | } 62 | 63 | private: 64 | std::unordered_set sampledImageBindings; 65 | std::unordered_set storageImageBindings; 66 | std::unordered_map bindings; 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /layer/buffer.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "perfdoc.hpp" 25 | 26 | namespace MPD 27 | { 28 | class DeviceMemory; 29 | class Buffer : public BaseObject 30 | { 31 | public: 32 | using VulkanType = VkBuffer; 33 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT; 34 | 35 | static const uint32_t INDEXBUFFER_MEMORY_PROPERTIES = 36 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; 37 | 38 | Buffer(Device *device, uint64_t objHandle_) 39 | : BaseObject(device, objHandle_, VULKAN_OBJECT_TYPE) 40 | { 41 | } 42 | 43 | VkResult init(VkBuffer buffer_, const VkBufferCreateInfo &createInfo); 44 | VkResult bindMemory(DeviceMemory *memory, VkDeviceSize offset); 45 | 46 | const VkMemoryRequirements &getMemoryRequirements() const 47 | { 48 | return memoryRequirements; 49 | } 50 | 51 | const DeviceMemory *getDeviceMemory() const 52 | { 53 | return memory; 54 | } 55 | 56 | uint32_t getMemoryOffset() const 57 | { 58 | return memoryOffset; 59 | } 60 | 61 | private: 62 | VkBuffer buffer = VK_NULL_HANDLE; 63 | DeviceMemory *memory = nullptr; 64 | VkDeviceSize memoryOffset = 0; 65 | VkBufferCreateInfo createInfo; 66 | VkMemoryRequirements memoryRequirements; 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /tests/push-constant.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "vulkan_test.hpp" 22 | #include "perfdoc.hpp" 23 | #include "util.hpp" 24 | using namespace MPD; 25 | 26 | class PushConstant : public VulkanTestHelper 27 | { 28 | bool checkPushConstant(bool positive) 29 | { 30 | resetCounts(); 31 | static const uint32_t negativeCode[] = 32 | #include "push_constant.push.comp.inc" 33 | ; 34 | 35 | static const uint32_t positiveCode[] = 36 | #include "push_constant.nopush.comp.inc" 37 | ; 38 | 39 | const uint32_t *code = positive ? positiveCode : negativeCode; 40 | size_t codeSize = positive ? sizeof(positiveCode) : sizeof(negativeCode); 41 | 42 | Pipeline ppline(device); 43 | ppline.initCompute(code, codeSize); 44 | 45 | if (positive) 46 | { 47 | if (getCount(MESSAGE_CODE_POTENTIAL_PUSH_CONSTANT) != 4) 48 | return false; 49 | } 50 | else 51 | { 52 | if (getCount(MESSAGE_CODE_POTENTIAL_PUSH_CONSTANT) != 0) 53 | return false; 54 | } 55 | 56 | if (getCount(MESSAGE_CODE_NO_PIPELINE_CACHE) != 1) 57 | return false; 58 | 59 | return true; 60 | } 61 | 62 | bool runTest() 63 | { 64 | if (!checkPushConstant(false)) 65 | return false; 66 | if (!checkPushConstant(true)) 67 | return false; 68 | return true; 69 | } 70 | }; 71 | 72 | VulkanTestHelper *MPD::createTest() 73 | { 74 | return new PushConstant; 75 | } 76 | -------------------------------------------------------------------------------- /layer/base_object.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "base_object.hpp" 22 | #include "device.hpp" 23 | #include "instance.hpp" 24 | #include 25 | 26 | namespace MPD 27 | { 28 | 29 | std::atomic BaseObject::uuids = { 1 }; 30 | 31 | Instance *BaseObject::getInstance() const 32 | { 33 | return baseDevice->getInstance(); 34 | } 35 | 36 | static void dispatchLog(Logger &logger, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT type, 37 | uint64_t objHandle, int32_t messageCode, const char *fmt, va_list args) 38 | { 39 | char buffer[1024 * 10]; 40 | vsnprintf(buffer, sizeof(buffer), fmt, args); 41 | 42 | LoggerMessageInfo inf; 43 | inf.flags = flags; 44 | inf.objectType = type; 45 | inf.object = objHandle; 46 | inf.messageCode = messageCode; 47 | logger.write(inf, buffer); 48 | } 49 | 50 | void BaseObject::log(VkDebugReportFlagsEXT flags, int32_t messageCode, const char *fmt, ...) 51 | { 52 | va_list args; 53 | va_start(args, fmt); 54 | dispatchLog(getInstance()->getLogger(), flags, type, objHandle, messageCode, fmt, args); 55 | va_end(args); 56 | } 57 | 58 | void BaseInstanceObject::log(VkDebugReportFlagsEXT flags, int32_t messageCode, const char *fmt, ...) 59 | { 60 | va_list args; 61 | va_start(args, fmt); 62 | dispatchLog(baseInstance->getLogger(), flags, type, objHandle, messageCode, fmt, args); 63 | va_end(args); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /layer/descriptor_pool.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "descriptor_pool.hpp" 22 | #include "descriptor_set.hpp" 23 | #include "device.hpp" 24 | #include "message_codes.hpp" 25 | 26 | namespace MPD 27 | { 28 | 29 | DescriptorPool::~DescriptorPool() 30 | { 31 | baseDevice->freeDescriptorSets(this); 32 | } 33 | 34 | void DescriptorPool::descriptorSetCreated(DescriptorSet *dset) 35 | { 36 | MPD_ASSERT(dset); 37 | 38 | const auto &cfg = this->getDevice()->getConfig(); 39 | 40 | auto it = layoutInfos.find(dset->getLayoutUuid()); 41 | if (it != layoutInfos.end()) 42 | { 43 | DescriptorSetLayoutInfo &inf = it->second; 44 | 45 | if (cfg.msgDescriptorSetAllocationChecks && inf.descriptorSetsFreedCount > 0) 46 | { 47 | inf.descriptorSetsFreedCount = 0; 48 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_DESCRIPTOR_SET_ALLOCATION_CHECKS, 49 | "It appears that some redundant descriptor set allocations happened. " 50 | "Consider recycling descriptor sets."); 51 | } 52 | } 53 | else 54 | { 55 | DescriptorSetLayoutInfo inf = { 56 | 0, 57 | }; 58 | layoutInfos[dset->getLayoutUuid()] = inf; 59 | } 60 | } 61 | 62 | void DescriptorPool::descriptorSetDeleted(DescriptorSet *dset) 63 | { 64 | MPD_ASSERT(dset); 65 | 66 | auto it = layoutInfos.find(dset->getLayoutUuid()); 67 | MPD_ASSERT(it != layoutInfos.end()); 68 | ++it->second.descriptorSetsFreedCount; 69 | } 70 | 71 | void DescriptorPool::reset() 72 | { 73 | baseDevice->freeDescriptorSets(this); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /layer/device_memory.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "device_memory.hpp" 22 | #include "buffer.hpp" 23 | #include "device.hpp" 24 | #include "message_codes.hpp" 25 | 26 | namespace MPD 27 | { 28 | VkResult DeviceMemory::init(VkDeviceMemory memory_, const VkMemoryAllocateInfo &allocInfo_) 29 | { 30 | memory = memory_; 31 | allocInfo = allocInfo_; 32 | mappedMemory = NULL; 33 | 34 | const VkPhysicalDeviceMemoryProperties &memoryProperties = getDevice()->getMemoryProperties(); 35 | if ((memoryProperties.memoryTypes[allocInfo.memoryTypeIndex].propertyFlags & 36 | Buffer::INDEXBUFFER_MEMORY_PROPERTIES) == Buffer::INDEXBUFFER_MEMORY_PROPERTIES) 37 | { 38 | VkResult res = 39 | getDevice()->getTable()->MapMemory(getDevice()->getDevice(), memory, 0, VK_WHOLE_SIZE, 0, &mappedMemory); 40 | if (res != VK_SUCCESS) 41 | { 42 | mappedMemory = NULL; 43 | } 44 | } 45 | 46 | const auto &cfg = this->getDevice()->getConfig(); 47 | 48 | if (cfg.msgSmallAllocation && 49 | allocInfo.allocationSize < baseDevice->getConfig().minDeviceAllocationSize) 50 | { 51 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_SMALL_ALLOCATION, 52 | "Allocating a VkDeviceMemory of size %llu. This is a very small allocation (current threshold is %llu " 53 | "bytes). " 54 | "You should make large allocations and sub-allocate from one large VkDeviceMemory.", 55 | allocInfo.allocationSize, baseDevice->getConfig().minDeviceAllocationSize); 56 | } 57 | return VK_SUCCESS; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /layer/render_pass.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include 24 | 25 | namespace MPD 26 | { 27 | class RenderPass : public BaseObject 28 | { 29 | public: 30 | using VulkanType = VkRenderPass; 31 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT; 32 | 33 | RenderPass(Device *device_, uint64_t objHandle_) 34 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 35 | { 36 | } 37 | 38 | VkResult init(VkRenderPass renderPass, const VkRenderPassCreateInfo &createInfo); 39 | 40 | const VkRenderPassCreateInfo &getCreateInfo() const 41 | { 42 | return createInfo; 43 | } 44 | 45 | bool renderPassUsesAttachmentOnTile(uint32_t attachment) const; 46 | bool renderPassUsesAttachmentAsImageOnly(uint32_t attachment) const; 47 | 48 | private: 49 | VkRenderPass renderPass = VK_NULL_HANDLE; 50 | VkRenderPassCreateInfo createInfo; 51 | std::vector subpassDependencies; 52 | std::vector attachments; 53 | 54 | struct SubpassAttachments 55 | { 56 | std::vector colorAttachments; 57 | std::vector resolveAttachments; 58 | std::vector inputAttachments; 59 | std::vector preserveAttachments; 60 | VkAttachmentReference depthStencilAttachment; 61 | }; 62 | std::vector subpasses; 63 | std::vector subpassDescriptions; 64 | 65 | void checkMultisampling(); 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /layer/descriptor_set.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include 24 | #include 25 | #include 26 | 27 | namespace MPD 28 | { 29 | 30 | class DescriptorSetLayout; 31 | class DescriptorPool; 32 | class ImageView; 33 | 34 | class DescriptorSet : public BaseObject 35 | { 36 | public: 37 | using VulkanType = VkDescriptorSet; 38 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT; 39 | 40 | DescriptorSet(Device *device, uint64_t objHandle_) 41 | : BaseObject(device, objHandle_, VULKAN_OBJECT_TYPE) 42 | { 43 | } 44 | 45 | ~DescriptorSet(); 46 | 47 | /// @note The DescriptorSet will not hold any reference to the layout. The spec allows layouts to be deleted before 48 | /// sets. 49 | VkResult init(const DescriptorSetLayout *layout, DescriptorPool *pool); 50 | 51 | uint64_t getLayoutUuid() const 52 | { 53 | return layoutUuid; 54 | } 55 | 56 | const DescriptorPool *getPool() const 57 | { 58 | return pool; 59 | } 60 | 61 | void signalUsage(); 62 | 63 | static void writeDescriptors(Device *device, const VkWriteDescriptorSet &write); 64 | static void copyDescriptors(Device *device, const VkCopyDescriptorSet ©); 65 | 66 | private: 67 | uint64_t layoutUuid = 0; 68 | DescriptorPool *pool = nullptr; 69 | const DescriptorSetLayout *layout = nullptr; 70 | 71 | struct BindingData 72 | { 73 | std::vector views; 74 | VkDescriptorType descriptorType; 75 | }; 76 | 77 | std::unordered_map bindings; 78 | }; 79 | } 80 | -------------------------------------------------------------------------------- /layer/queue_tracker.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "perfdoc.hpp" 25 | 26 | namespace MPD 27 | { 28 | class Queue; 29 | class Event; 30 | class QueueTracker 31 | { 32 | public: 33 | QueueTracker(Queue &queue); 34 | 35 | enum StageFlagBits 36 | { 37 | STAGE_COMPUTE_BIT = 1 << 0, 38 | STAGE_GEOMETRY_BIT = 1 << 1, 39 | STAGE_FRAGMENT_BIT = 1 << 2, 40 | STAGE_TRANSFER_BIT = 1 << 3, 41 | STAGE_ALL_BITS = STAGE_COMPUTE_BIT | STAGE_GEOMETRY_BIT | STAGE_FRAGMENT_BIT | STAGE_TRANSFER_BIT 42 | }; 43 | using StageFlags = uint32_t; 44 | 45 | enum Stage 46 | { 47 | STAGE_COMPUTE = 0, 48 | STAGE_GEOMETRY = 1, 49 | STAGE_FRAGMENT = 2, 50 | STAGE_TRANSFER = 3, 51 | STAGE_COUNT 52 | }; 53 | 54 | void pushWork(Stage stage); 55 | void pipelineBarrier(StageFlags srcStages, StageFlags dstStages); 56 | void waitEvent(const Event &event, StageFlags dstStages); 57 | void signalEvent(Event &event, StageFlags srcStages); 58 | 59 | Queue &getQueue() 60 | { 61 | return queue; 62 | } 63 | 64 | private: 65 | Queue &queue; 66 | 67 | struct StageStatus 68 | { 69 | // Waits for work associated with an index to complete in other stages. 70 | uint64_t waitList[STAGE_COUNT] = {}; 71 | 72 | // The number of work items pushed to this pipeline stage so far. 73 | uint64_t index = 0; 74 | 75 | // The index when this stage was last used as a dstStageMask. 76 | uint64_t lastDstStageIndex[STAGE_COUNT] = {}; 77 | }; 78 | StageStatus stages[STAGE_COUNT]; 79 | 80 | void barrier(StageFlags srcStages, Stage dstStage); 81 | }; 82 | } -------------------------------------------------------------------------------- /layer/logger.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "logger.hpp" 22 | 23 | using namespace std; 24 | 25 | namespace MPD 26 | { 27 | 28 | Logger::Logger() 29 | { 30 | } 31 | 32 | Logger::~Logger() 33 | { 34 | } 35 | 36 | struct LoggerCallback 37 | { 38 | VkDebugReportCallbackEXT callback; 39 | VkDebugReportFlagsEXT flags; 40 | PFN_vkDebugReportCallbackEXT pfnCallback; 41 | void *pUserData; 42 | }; 43 | 44 | LoggerCallback *Logger::createAndRegisterCallback(VkDebugReportCallbackEXT callback, 45 | const VkDebugReportCallbackCreateInfoEXT &createInfo) 46 | { 47 | MPD_ASSERT(createInfo.pfnCallback); 48 | 49 | auto pCallback = unique_ptr(new LoggerCallback); 50 | pCallback->callback = callback; 51 | pCallback->flags = createInfo.flags; 52 | pCallback->pfnCallback = createInfo.pfnCallback; 53 | pCallback->pUserData = createInfo.pUserData; 54 | 55 | auto *ret = pCallback.get(); 56 | debugCallbacks[callback] = move(pCallback); 57 | return ret; 58 | } 59 | 60 | void Logger::unregisterAndDestroyCallback(VkDebugReportCallbackEXT callback) 61 | { 62 | auto itr = debugCallbacks.find(callback); 63 | debugCallbacks.erase(itr); 64 | } 65 | 66 | void Logger::write(const LoggerMessageInfo &inf, const char *msg) 67 | { 68 | for (const auto &callback : debugCallbacks) 69 | { 70 | auto &cb = callback.second; 71 | auto u = cb->flags & inf.flags; 72 | if (u) 73 | { 74 | size_t location = 0; 75 | cb->pfnCallback(u, inf.objectType, inf.object, location, inf.messageCode, "PowerVRPerfDoc", msg, 76 | cb->pUserData); 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /layer/base_object.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "perfdoc.hpp" 23 | #include 24 | 25 | namespace MPD 26 | { 27 | 28 | class Instance; 29 | class Device; 30 | 31 | /// The base of all Vulkan objects which derive from a VkDevice. 32 | class BaseObject 33 | { 34 | public: 35 | BaseObject(Device *device, uint64_t objHandle_, VkDebugReportObjectTypeEXT type_) 36 | : baseDevice(device) 37 | , objHandle(objHandle_) 38 | , type(type_) 39 | , uuid(uuids.fetch_add(1)) 40 | { 41 | } 42 | 43 | void log(VkDebugReportFlagsEXT flags, int32_t messageCode, const char *fmt, ...); 44 | 45 | Instance *getInstance() const; 46 | Device *getDevice() const 47 | { 48 | return baseDevice; 49 | } 50 | 51 | /// Get universaly unique identifier. It's unique for all objects. 52 | uint64_t getUuid() const 53 | { 54 | return uuid; 55 | } 56 | 57 | protected: 58 | Device *baseDevice; 59 | 60 | private: 61 | uint64_t objHandle; 62 | VkDebugReportObjectTypeEXT type; 63 | uint64_t uuid; 64 | static std::atomic uuids; 65 | }; 66 | 67 | /// The base of all Vulkan objects which derive from a VkInstance. 68 | class BaseInstanceObject 69 | { 70 | public: 71 | BaseInstanceObject(Instance *inst, uint64_t objHandle_, VkDebugReportObjectTypeEXT type_) 72 | : baseInstance(inst) 73 | , objHandle(objHandle_) 74 | , type(type_) 75 | { 76 | } 77 | 78 | void log(VkDebugReportFlagsEXT flags, int32_t messageCode, const char *fmt, ...); 79 | 80 | Instance *getInstance() const 81 | { 82 | return baseInstance; 83 | } 84 | 85 | protected: 86 | Instance *baseInstance; 87 | 88 | private: 89 | uint64_t objHandle; 90 | VkDebugReportObjectTypeEXT type; 91 | }; 92 | } 93 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, ARM Limited and Contributors 2 | # 3 | # SPDX-License-Identifier: MIT 4 | # 5 | # Permission is hereby granted, free of charge, 6 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | # to deal in the Software without restriction, including without limitation the rights to 8 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | option(UNIT_TESTS "Build unit tests" ON) 21 | 22 | function(add_layer_test TARGET SOURCES) 23 | add_executable(${TARGET} ${SOURCES}) 24 | add_test(NAME ${TARGET} COMMAND $) 25 | target_compile_options(${TARGET} PUBLIC ${PERFDOC_CXX_FLAGS}) 26 | target_link_libraries(${TARGET} test-util) 27 | target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../layer ${CMAKE_BINARY_DIR}/glsl) 28 | add_dependencies(${TARGET} shaders) 29 | endfunction() 30 | 31 | if (UNIT_TESTS) 32 | set(CTEST_ENVIRONMENT "VK_LAYER_PATH=${CMAKE_BINARY_DIR}/layer" "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/layer:${LD_LIBRARY_PATH}") 33 | add_subdirectory(glsl) 34 | add_subdirectory(util) 35 | add_layer_test(stub-layer-perfdoc stub-layer-test.cpp) 36 | add_layer_test(commandbuffer-perfdoc commandbuffer-test.cpp) 37 | add_layer_test(allocation-size-perfdoc allocation-size-test.cpp) 38 | add_layer_test(multisampling-perfdoc multisampling.cpp) 39 | add_layer_test(transient-perfdoc transient.cpp) 40 | add_layer_test(sampler-perfdoc samplers.cpp) 41 | add_layer_test(descriptor-set-allocation-checks descriptor-set-allocation-checks.cpp) 42 | add_layer_test(compute-perfdoc compute-test.cpp) 43 | add_layer_test(push-constant-perfdoc push-constant.cpp) 44 | add_layer_test(queue-perfdoc queue-test.cpp) 45 | add_layer_test(clear-image-perfdoc clear-image.cpp) 46 | add_layer_test(texture-perfdoc texture-test.cpp) 47 | add_layer_test(draw-call-perfdoc draw-call.cpp) 48 | add_layer_test(fbcdc-perfdoc fbcdc-test.cpp) 49 | add_layer_test(subpass-perfdoc subpass-test.cpp) 50 | add_layer_test(pipeline-perfdoc pipeline-test.cpp) 51 | add_layer_test(query-perfdoc query-test.cpp) 52 | endif() 53 | -------------------------------------------------------------------------------- /tests/glsl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, ARM Limited and Contributors 2 | # 3 | # SPDX-License-Identifier: MIT 4 | # 5 | # Permission is hereby granted, free of charge, 6 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | # to deal in the Software without restriction, including without limitation the rights to 8 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | add_custom_target(shaders) 21 | 22 | set(GLSL_FLAGS -mfmt=c) 23 | function(add_shader OUTPUT INPUT) 24 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/glsl) 25 | add_custom_command( 26 | OUTPUT ${CMAKE_BINARY_DIR}/glsl/${OUTPUT}.inc 27 | COMMAND glslc ${ARGN} -o ${CMAKE_BINARY_DIR}/glsl/${OUTPUT}.inc ${GLSL_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT} 28 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT} 29 | IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT} 30 | ) 31 | add_custom_target(${OUTPUT} DEPENDS ${CMAKE_BINARY_DIR}/glsl/${OUTPUT}.inc) 32 | set_source_files_properties(${CMAKE_BINARY_DIR}/glsl/${OUTPUT}.inc PROPERTIES GENERATED TRUE) 33 | add_dependencies(shaders ${OUTPUT}) 34 | endfunction(add_shader) 35 | 36 | add_shader(quad.vert quad.vert) 37 | add_shader(quad.frag quad.frag) 38 | add_shader(quad_no_output.frag quad_no_output.frag) 39 | add_shader(quad_sampler.frag quad_sampler.frag) 40 | add_shader(quad_no_attribs.vert quad_no_attribs.vert) 41 | 42 | add_shader(compute.wg.4.1.1.comp basic.comp -DWG_X=4 -DWG_Y=1 -DWG_Z=1) 43 | add_shader(compute.wg.4.1.3.comp basic.comp -DWG_X=4 -DWG_Y=1 -DWG_Z=3) 44 | add_shader(compute.wg.16.8.1.comp basic.comp -DWG_X=16 -DWG_Y=8 -DWG_Z=1) 45 | 46 | add_shader(compute.wg.32.1.1.comp basic.comp -DWG_X=32 -DWG_Y=1 -DWG_Z=1) 47 | add_shader(compute.wg.31.1.1.comp basic.comp -DWG_X=31 -DWG_Y=1 -DWG_Z=1) 48 | 49 | add_shader(compute.sampler.2d.8.8.1.comp sampler.comp -DWG_X=8 -DWG_Y=8 -DWG_Z=1 -DSAMPLER_2D) 50 | add_shader(compute.sampler.1d.64.1.1.comp sampler.comp -DWG_X=64 -DWG_Y=1 -DWG_Z=1 -DSAMPLER_1D) 51 | add_shader(compute.sampler.2d.64.1.1.comp sampler.comp -DWG_X=64 -DWG_Y=1 -DWG_Z=1 -DSAMPLER_2D) 52 | 53 | add_shader(push_constant.push.comp push_constant.comp -DPUSH_CONSTANT) 54 | add_shader(push_constant.nopush.comp push_constant.comp) 55 | 56 | -------------------------------------------------------------------------------- /layer/perfdoc-default.cfg: -------------------------------------------------------------------------------- 1 | # Doesn't really apply to PowerVR 2 | # Maximum number of threads which can efficiently be part of a compute workgroup when using thread group barriers 3 | maxEfficientWorkGroupThreads 64 4 | 5 | # PowerVR is scalar, so it's fine. 6 | # On Midgard, compute threads are dispatched in groups. On Bifrost, threads run in lock-step. 7 | threadGroupSize 4 8 | 9 | # Size of post-transform cache used for estimating index buffer cache hit-rate 10 | indexBufferVertexPostTransformCache 32 11 | 12 | # If a buffer or image is allocated and it consumes an entire VkDeviceMemory, it should at least be this large. This is slightly different from minDeviceAllocationSize since the 256K buffer can still be sensibly suballocated from. If we consume an entire allocation with one image or buffer, it should at least be for a very large allocation 13 | minDedicatedAllocationSize 2097152 14 | 15 | # How many indices make a small indexed drawcall 16 | smallIndexedDrawcallIndices 10 17 | 18 | # Minimum number of indices to take into account when doing depth pre-pass checks 19 | depthPrePassMinIndices 1 20 | 21 | # Maximum number of instanced vertex buffers which should be used 22 | maxInstancedVertexBuffers 1 23 | 24 | # Maximum sample count for full throughput 25 | maxEfficientSamples 2 26 | 27 | # How many small indexed drawcalls in a command buffer before a warning is thrown 28 | maxSmallIndexedDrawcalls 10 29 | 30 | # Minimum number of vertices to take into account when doing depth pre-pass checks 31 | depthPrePassMinVertices 1 32 | 33 | # Minimum number of drawcalls in order to trigger depth pre-pass 34 | depthPrePassNumDrawCalls 1 35 | 36 | # Skip index buffer scanning of drawcalls with less than this limit 37 | indexBufferScanMinIndexCount 128 38 | 39 | # Recomended allocation size for vkAllocateMemory 40 | minDeviceAllocationSize 262144 41 | 42 | # Only report cache hit performance warnings if cache hit is below this threshold 43 | indexBufferCacheHitThreshold 0.5 44 | 45 | # The minimum LOD level which is equivalent to unclamped maxLod 46 | unclampedMaxLod 32 47 | 48 | # Only report indexbuffer fragmentation warning if utilization is below this threshold 49 | indexBufferUtilizationThreshold 0.5 50 | 51 | # This setting specifies where to log output from the layer. 52 | # The setting does not impact VK_EXT_debug_report which will always be supported. 53 | # This filename represents a path on the file system, but special values include: 54 | # stdout 55 | # stderr 56 | # logcat (Android only) 57 | # debug_output (OutputDebugString, Windows only). 58 | loggingFilename "" 59 | 60 | # If enabled, scans the index buffer in place on vkCmdDrawIndexed. This is useful to narrow down exactly which draw call is causing the issue as you can backtrace the debug callback, but scanning indices here will only work if the index buffer is actually valid when calling this function. If not enabled, indices will be scanned on vkQueueSubmit. 61 | indexBufferScanningInPlace off 62 | 63 | # If enabled, scans the index buffer for every draw call in an attempt to find inefficiencies. This is fairly expensive, so it should be disabled once index buffers have been validated. 64 | indexBufferScanningEnable on 65 | 66 | -------------------------------------------------------------------------------- /tests/pipeline-test.cpp: -------------------------------------------------------------------------------- 1 | 2 | //Note vulkan test needs to come before perfdoc... 3 | #include "vulkan_test.hpp" 4 | #include "perfdoc.hpp" 5 | #include "util.hpp" 6 | #include 7 | #include 8 | using namespace MPD; 9 | using namespace std; 10 | 11 | class PipelineTest : public VulkanTestHelper 12 | { 13 | public: 14 | bool testFlag(bool positiveTest) 15 | { 16 | VkAttachmentDescription attachments[1] = {}; 17 | attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 18 | attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 19 | attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; 20 | attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; 21 | attachments[0].samples = VK_SAMPLE_COUNT_1_BIT; 22 | attachments[0].format = VK_FORMAT_R8G8B8A8_UNORM; 23 | attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 24 | attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 25 | 26 | const VkAttachmentReference attachment = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }; 27 | 28 | VkSubpassDescription subpass = {}; 29 | subpass.colorAttachmentCount = 1; 30 | subpass.pColorAttachments = &attachment; 31 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; 32 | 33 | VkRenderPassCreateInfo info = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO }; 34 | info.attachmentCount = 1; 35 | info.subpassCount = 1; 36 | info.pSubpasses = &subpass; 37 | info.pAttachments = &attachments[0]; 38 | 39 | VkRenderPass renderPass; 40 | MPD_ASSERT_RESULT(vkCreateRenderPass(device, &info, nullptr, &renderPass)); 41 | 42 | static const uint32_t vertCode[] = 43 | #include "quad_no_attribs.vert.inc" 44 | ; 45 | 46 | static const uint32_t fragCode[] = 47 | #include "quad.frag.inc" 48 | ; 49 | 50 | VkPipelineColorBlendAttachmentState att = {}; 51 | att.blendEnable = true; 52 | att.colorWriteMask = 0xf; 53 | 54 | VkPipelineColorBlendStateCreateInfo blend = { VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO }; 55 | blend.attachmentCount = 1; 56 | blend.pAttachments = &att; 57 | 58 | VkGraphicsPipelineCreateInfo gpci = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO }; 59 | gpci.renderPass = renderPass; 60 | gpci.pColorBlendState = &blend; 61 | gpci.flags = positiveTest ? VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT : 0; 62 | 63 | auto pipeline = make_shared(device); 64 | pipeline->initGraphics(vertCode, sizeof(vertCode), fragCode, sizeof(fragCode), &gpci); 65 | 66 | vkDestroyRenderPass(device, renderPass, 0); 67 | 68 | uint32_t count = getCount(MESSAGE_CODE_PIPELINE_OPTIMISATION_DISABLED); 69 | resetCounts(); 70 | 71 | if (positiveTest) 72 | { 73 | if (count != 1) 74 | return false; 75 | } 76 | else 77 | { 78 | if (count != 0) 79 | return false; 80 | } 81 | return true; 82 | } 83 | 84 | bool runTest() override 85 | { 86 | if (!testFlag(false)) 87 | return false; 88 | 89 | if (!testFlag(true)) 90 | return false; 91 | 92 | return true; 93 | } 94 | 95 | virtual bool initialize() 96 | { 97 | return true; 98 | } 99 | }; 100 | 101 | VulkanTestHelper *MPD::createTest() 102 | { 103 | return new PipelineTest; 104 | } 105 | -------------------------------------------------------------------------------- /layer/pipeline.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "pipeline_layout.hpp" 24 | 25 | #include 26 | 27 | namespace MPD 28 | { 29 | class Pipeline : public BaseObject 30 | { 31 | public: 32 | using VulkanType = VkPipeline; 33 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT; 34 | 35 | Pipeline(Device *device_, uint64_t objHandle_) 36 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 37 | { 38 | } 39 | 40 | enum class Type 41 | { 42 | Compute, 43 | Graphics 44 | }; 45 | 46 | Type getPipelineType() const 47 | { 48 | return type; 49 | } 50 | 51 | VkResult initGraphics(VkPipeline pipeline, const VkGraphicsPipelineCreateInfo &createInfo); 52 | VkResult initCompute(VkPipeline pipeline, const VkComputePipelineCreateInfo &createInfo); 53 | 54 | const VkGraphicsPipelineCreateInfo &getGraphicsCreateInfo() const 55 | { 56 | MPD_ASSERT(type == Type::Graphics); 57 | return createInfo.graphics; 58 | } 59 | 60 | const VkComputePipelineCreateInfo &getComputeCreateInfo() const 61 | { 62 | MPD_ASSERT(type == Type::Compute); 63 | return createInfo.compute; 64 | } 65 | 66 | const PipelineLayout *getPipelineLayout() const 67 | { 68 | return layout; 69 | } 70 | 71 | private: 72 | VkPipeline pipeline = VK_NULL_HANDLE; 73 | const PipelineLayout *layout = nullptr; 74 | union { 75 | VkGraphicsPipelineCreateInfo graphics; 76 | VkComputePipelineCreateInfo compute; 77 | } createInfo; 78 | 79 | VkPipelineDepthStencilStateCreateInfo depthStencilState; 80 | VkPipelineColorBlendStateCreateInfo colorBlendState; 81 | VkPipelineInputAssemblyStateCreateInfo inputAssemblyState; 82 | std::vector colorBlendAttachmentState; 83 | 84 | void checkInstancedVertexBuffer(const VkGraphicsPipelineCreateInfo &createInfo); 85 | void checkMultisampledBlending(const VkGraphicsPipelineCreateInfo &createInfo); 86 | 87 | Type type; 88 | void checkWorkGroupSize(const VkComputePipelineCreateInfo &createInfo); 89 | void checkPushConstantsForStage(const VkPipelineShaderStageCreateInfo &stage); 90 | }; 91 | } 92 | -------------------------------------------------------------------------------- /layer/buffer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "buffer.hpp" 22 | #include "device.hpp" 23 | #include "device_memory.hpp" 24 | #include "message_codes.hpp" 25 | 26 | namespace MPD 27 | { 28 | VkResult Buffer::init(VkBuffer buffer_, const VkBufferCreateInfo &createInfo_) 29 | { 30 | buffer = buffer_; 31 | createInfo = createInfo_; 32 | 33 | baseDevice->getTable()->GetBufferMemoryRequirements(baseDevice->getDevice(), buffer, &memoryRequirements); 34 | 35 | // we need to be able to map indexbuffer back to host memory 36 | // so modify memory requirements such that host_visible is always used 37 | if (createInfo.usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT) 38 | { 39 | const VkPhysicalDeviceMemoryProperties &memoryProperties = getDevice()->getMemoryProperties(); 40 | memoryRequirements.memoryTypeBits = INDEXBUFFER_MEMORY_PROPERTIES; 41 | 42 | for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++) 43 | { 44 | if ((memoryProperties.memoryTypes[i].propertyFlags & INDEXBUFFER_MEMORY_PROPERTIES) == 45 | INDEXBUFFER_MEMORY_PROPERTIES) 46 | { 47 | memoryRequirements.memoryTypeBits = 1u << i; 48 | break; 49 | } 50 | } 51 | } 52 | 53 | return VK_SUCCESS; 54 | } 55 | 56 | VkResult Buffer::bindMemory(DeviceMemory *memory_, VkDeviceSize offset) 57 | { 58 | memory = memory_; 59 | memoryOffset = offset; 60 | 61 | auto memorySize = memory->getAllocateInfo().allocationSize; 62 | 63 | const auto &cfg = this->getDevice()->getConfig(); 64 | 65 | // If we're consuming an entire memory block here, it better be a very large allocation. 66 | if ( 67 | cfg.msgSmallDedicatedAllocation && 68 | memorySize == memoryRequirements.size && memorySize < baseDevice->getConfig().minDedicatedAllocationSize) 69 | { 70 | // Sanity check. 71 | MPD_ASSERT(offset == 0); 72 | 73 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_SMALL_DEDICATED_ALLOCATION, 74 | "Trying to bind a VkBuffer to a memory block which is fully consumed by the buffer. " 75 | "The required size of the allocation is %llu, but smaller buffers like this should be sub-allocated from " 76 | "larger memory blocks. " 77 | "(Current threshold is %llu bytes.)", 78 | memorySize, baseDevice->getConfig().minDedicatedAllocationSize); 79 | } 80 | return VK_SUCCESS; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /layer/image.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "perfdoc.hpp" 25 | #include 26 | 27 | namespace MPD 28 | { 29 | class DeviceMemory; 30 | class Image : public BaseObject 31 | { 32 | public: 33 | using VulkanType = VkImage; 34 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT; 35 | 36 | Image(Device *device_, uint64_t objHandle_) 37 | : BaseObject(device_, objHandle_, VULKAN_OBJECT_TYPE) 38 | { 39 | } 40 | 41 | VkResult init(VkImage image_, const VkImageCreateInfo &createInfo); 42 | VkResult initSwapchain(VkImage image_, const VkImageCreateInfo &createInfo); 43 | VkResult bindMemory(DeviceMemory *memory, VkDeviceSize offset); 44 | 45 | const VkMemoryRequirements &getMemoryRequirements() const 46 | { 47 | MPD_ASSERT(!swapchainImage); 48 | return memoryRequirements; 49 | } 50 | 51 | const VkImageCreateInfo &getCreateInfo() const 52 | { 53 | return createInfo; 54 | } 55 | 56 | bool isSwapchainImage() const 57 | { 58 | return swapchainImage; 59 | } 60 | 61 | enum class Usage 62 | { 63 | Undefined = 0, 64 | RenderPassCleared = 1 << 0, 65 | RenderPassReadToTile = 1 << 1, 66 | Cleared = 1 << 2, 67 | ResourceRead = 1 << 3, 68 | ResourceWrite = 1 << 4, 69 | RenderPassStored = 1 << 5, 70 | RenderPassDiscarded = 1 << 6 71 | }; 72 | 73 | void signalUsage(uint32_t arrayLayer, uint32_t mipLevel, Usage usage); 74 | void signalUsage(const VkImageSubresourceRange &range, Usage usage); 75 | void signalUsage(const VkImageSubresourceLayers &range, Usage usage); 76 | 77 | Usage getLastUsage(uint32_t arrayLayer, uint32_t mipLevel) const; 78 | uint32_t getUsageFlags(uint32_t arrayLayer, uint32_t mipLevel) const; 79 | 80 | private: 81 | VkImage image = VK_NULL_HANDLE; 82 | DeviceMemory *memory = nullptr; 83 | VkDeviceSize memoryOffset = 0; 84 | VkImageCreateInfo createInfo; 85 | VkMemoryRequirements memoryRequirements; 86 | bool swapchainImage = false; 87 | 88 | void checkLazyAndTransient(); 89 | void checkAllocationSize(); 90 | 91 | struct MipLevel 92 | { 93 | Usage lastUsage = Usage::Undefined; 94 | uint32_t usageFlags = 0; 95 | }; 96 | 97 | struct Layer 98 | { 99 | std::vector mipLevels; 100 | }; 101 | 102 | std::vector arrayLayers; 103 | }; 104 | } 105 | -------------------------------------------------------------------------------- /cross_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2017, ARM Limited and Contributors 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | # Permission is hereby granted, free of charge, 8 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 9 | # to deal in the Software without restriction, including without limitation the rights to 10 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 11 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 16 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | mode=$1 23 | if [ -z $1 ]; then 24 | mode=Release 25 | fi 26 | 27 | njobs=`nproc` 28 | 29 | # Desktop Linux 30 | mkdir -p build-linux-x64 31 | cd build-linux-x64 32 | cmake .. -DPERFDOC_TESTS=ON -DCMAKE_BUILD_TYPE=$mode 33 | make -j$njobs 34 | cd .. 35 | 36 | # ARM Linux (ARMv7 hard-float) 37 | mkdir -p build-linux-armv7-hf 38 | cd build-linux-armv7-hf 39 | cmake .. -DPERFDOC_TESTS=ON -DCMAKE_BUILD_TYPE=$mode -DCMAKE_TOOLCHAIN_FILE=../toolchains/armhf.cmake 40 | make -j$njobs 41 | cd .. 42 | 43 | # Android 44 | if [ -z $ANDROID_SDK ]; then 45 | ANDROID_SDK="$HOME/Android/Sdk" 46 | fi 47 | 48 | # Android armeabi-v7a 49 | mkdir -p build-android-armeabi-v7a 50 | cd build-android-armeabi-v7a 51 | 52 | ANDROID_ABI=armeabi-v7a 53 | "$ANDROID_SDK"/cmake/*/bin/cmake \ 54 | .. \ 55 | -DANDROID_STL=c++_static \ 56 | -DANDROID_TOOLCHAIN=clang \ 57 | -DCMAKE_TOOLCHAIN_FILE="$ANDROID_SDK/ndk-bundle/build/cmake/android.toolchain.cmake" \ 58 | -DANDROID_ABI=$ANDROID_ABI \ 59 | -DANDROID_CPP_FEATURES=exceptions \ 60 | -DANDROID_ARM_MODE=arm \ 61 | -DCMAKE_BUILD_TYPE=$mode 62 | 63 | make -j$njobs 64 | cd .. 65 | 66 | # Android arm64-v8a 67 | mkdir -p build-android-arm64-v8a 68 | cd build-android-arm64-v8a 69 | 70 | ANDROID_ABI=arm64-v8a 71 | "$ANDROID_SDK"/cmake/*/bin/cmake \ 72 | .. \ 73 | -DANDROID_STL=c++_static \ 74 | -DANDROID_TOOLCHAIN=clang \ 75 | -DCMAKE_TOOLCHAIN_FILE="$ANDROID_SDK/ndk-bundle/build/cmake/android.toolchain.cmake" \ 76 | -DANDROID_ABI=$ANDROID_ABI \ 77 | -DANDROID_CPP_FEATURES=exceptions \ 78 | -DANDROID_ARM_MODE=arm \ 79 | -DCMAKE_BUILD_TYPE=$mode 80 | 81 | make -j$njobs 82 | cd .. 83 | 84 | # MinGW i686 85 | mkdir -p build-windows-x86 86 | cd build-windows-x86 87 | i686-w64-mingw32-cmake .. -DPERFDOC_TESTS=ON -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$mode 88 | make -j$njobs 89 | cd .. 90 | 91 | # MinGW x86_64 92 | mkdir -p build-windows-x64 93 | cd build-windows-x64 94 | x86_64-w64-mingw32-cmake .. -DPERFDOC_TESTS=ON -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$mode 95 | make -j$njobs 96 | cd .. 97 | 98 | day=$(date "+%Y-%m-%d") 99 | commit=$(git rev-parse HEAD | cut -b 1-10) 100 | zip powervr-perfdoc-$day-$commit.zip \ 101 | README.md \ 102 | layer/perfdoc-default.cfg \ 103 | build-linux-x64/layer/*.{so,json} \ 104 | build-linux-armv7-hf/layer/*.{so,json} \ 105 | build-android-armeabi-v7a/layer/*.so \ 106 | build-android-arm64-v8a/layer/*.so \ 107 | build-windows-x86/layer/*.{dll,json} \ 108 | build-windows-x64/layer/*.{dll,json} 109 | 110 | -------------------------------------------------------------------------------- /layer/message_codes.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | 23 | namespace MPD 24 | { 25 | enum MessageCodes 26 | { 27 | MESSAGE_CODE_COMMAND_BUFFER_RESET = 1, 28 | MESSAGE_CODE_COMMAND_BUFFER_SIMULTANEOUS_USE = 2, 29 | MESSAGE_CODE_SMALL_ALLOCATION = 3, 30 | MESSAGE_CODE_SMALL_DEDICATED_ALLOCATION = 4, 31 | MESSAGE_CODE_TOO_LARGE_SAMPLE_COUNT = 5, 32 | MESSAGE_CODE_NON_LAZY_MULTISAMPLED_IMAGE = 6, 33 | MESSAGE_CODE_NON_LAZY_TRANSIENT_IMAGE = 7, 34 | MESSAGE_CODE_MULTISAMPLED_IMAGE_REQUIRES_MEMORY = 8, 35 | MESSAGE_CODE_RESOLVE_IMAGE = 9, 36 | MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_BE_TRANSIENT = 10, 37 | MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_NOT_BE_TRANSIENT = 11, 38 | MESSAGE_CODE_INDEX_BUFFER_SPARSE = 12, 39 | MESSAGE_CODE_INDEX_BUFFER_CACHE_THRASHING = 13, 40 | MESSAGE_CODE_TOO_MANY_INSTANCED_VERTEX_BUFFERS = 14, 41 | MESSAGE_CODE_DISSIMILAR_WRAPPING = 15, 42 | MESSAGE_CODE_NO_PIPELINE_CACHE = 16, 43 | MESSAGE_CODE_DESCRIPTOR_SET_ALLOCATION_CHECKS = 17, 44 | MESSAGE_CODE_COMPUTE_NO_THREAD_GROUP_ALIGNMENT = 18, 45 | MESSAGE_CODE_COMPUTE_LARGE_WORK_GROUP = 19, 46 | MESSAGE_CODE_COMPUTE_POOR_SPATIAL_LOCALITY = 20, 47 | MESSAGE_CODE_POTENTIAL_PUSH_CONSTANT = 21, 48 | MESSAGE_CODE_MANY_SMALL_INDEXED_DRAWCALLS = 22, 49 | MESSAGE_CODE_DEPTH_PRE_PASS = 23, 50 | MESSAGE_CODE_PIPELINE_BUBBLE = 24, 51 | MESSAGE_CODE_NOT_FULL_THROUGHPUT_BLENDING = 25, 52 | MESSAGE_CODE_SAMPLER_LOD_CLAMPING = 26, 53 | MESSAGE_CODE_SAMPLER_LOD_BIAS = 27, 54 | MESSAGE_CODE_SAMPLER_BORDER_CLAMP_COLOR = 28, 55 | MESSAGE_CODE_SAMPLER_UNNORMALIZED_COORDS = 29, 56 | MESSAGE_CODE_SAMPLER_ANISOTROPY = 30, 57 | MESSAGE_CODE_TILE_READBACK = 31, 58 | MESSAGE_CODE_CLEAR_ATTACHMENTS_AFTER_LOAD = 32, 59 | MESSAGE_CODE_CLEAR_ATTACHMENTS_NO_DRAW_CALL = 33, 60 | MESSAGE_CODE_REDUNDANT_RENDERPASS_STORE = 34, 61 | MESSAGE_CODE_REDUNDANT_IMAGE_CLEAR = 35, 62 | MESSAGE_CODE_INEFFICIENT_CLEAR = 36, 63 | MESSAGE_CODE_LAZY_TRANSIENT_IMAGE_NOT_SUPPORTED = 37, 64 | 65 | /////////////////////////////////////////////// 66 | //new messages from here 67 | /////////////////////////////////////////////// 68 | 69 | MESSAGE_CODE_UNCOMPRESSED_TEXTURE_USED = 38, 70 | MESSAGE_CODE_NON_MIPMAPPED_TEXTURE_USED = 39, 71 | MESSAGE_CODE_NON_INDEXED_DRAW_CALL = 40, 72 | MESSAGE_CODE_SUBOPTIMAL_TEXTURE_FORMAT = 41, 73 | MESSAGE_CODE_TEXTURE_LINEAR_TILING = 42, 74 | MESSAGE_CODE_NO_FBCDC = 43, 75 | MESSAGE_CODE_ROBUST_BUFFER_ACCESS_ENABLED = 44, 76 | MESSAGE_CODE_SUBOPTIMAL_SUBPASS_DEPENDENCY_FLAG = 45, 77 | MESSAGE_CODE_PARTIAL_CLEAR = 46, 78 | MESSAGE_CODE_PIPELINE_OPTIMISATION_DISABLED = 47, 79 | MESSAGE_CODE_WORKGROUP_SIZE_DIVISOR = 48, 80 | MESSAGE_CODE_POTENTIAL_SUBPASS = 49, 81 | MESSAGE_CODE_SUBPASS_STENCIL_SELF_DEPENDENCY = 50, 82 | MESSAGE_CODE_INEFFICIENT_DEPTH_STENCIL_OPS = 51, 83 | MESSAGE_CODE_QUERY_BUNDLE_TOO_SMALL = 52, 84 | 85 | MESSAGE_CODE_COUNT 86 | }; 87 | } 88 | -------------------------------------------------------------------------------- /layer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017, ARM Limited and Contributors 2 | # 3 | # SPDX-License-Identifier: MIT 4 | # 5 | # Permission is hereby granted, free of charge, 6 | # to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | # to deal in the Software without restriction, including without limitation the rights to 8 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | # and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | if (WIN32) 21 | set(export-file exports.def) 22 | else() 23 | set(export-file ) 24 | endif() 25 | 26 | add_library(VkLayer_powervr_perf_doc SHARED 27 | logger.cpp 28 | config.cpp 29 | base_object.cpp 30 | dispatch.cpp 31 | dispatch_helper.cpp 32 | instance.cpp 33 | device.cpp 34 | commandbuffer.cpp 35 | buffer.cpp 36 | image.cpp 37 | device_memory.cpp 38 | render_pass.cpp 39 | framebuffer.cpp 40 | image_view.cpp 41 | pipeline.cpp 42 | pipeline_layout.cpp 43 | queue.cpp 44 | queue_tracker.cpp 45 | event.cpp 46 | sampler.cpp 47 | commandpool.cpp 48 | descriptor_pool.cpp 49 | shader_module.cpp 50 | descriptor_set.cpp 51 | descriptor_set_layout.cpp 52 | swapchain.cpp 53 | heuristic.cpp 54 | ${export-file}) 55 | target_include_directories(VkLayer_powervr_perf_doc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) 56 | 57 | target_compile_options(VkLayer_powervr_perf_doc PUBLIC ${PERFDOC_CXX_FLAGS}) 58 | 59 | file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/layer) 60 | 61 | if (WIN32) 62 | add_custom_command(TARGET VkLayer_powervr_perf_doc POST_BUILD 63 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/VkLayer_powervr_perf_doc_win32.json ${CMAKE_BINARY_DIR}/layer/VkLayer_powervr_perf_doc.json) 64 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES PREFIX "" LIBRARY_OUTPUT_NAME VkLayer_powervr_perf_doc) 65 | if (CMAKE_COMPILER_IS_GNUCXX) 66 | if (${CMAKE_BUILD_TYPE} MATCHES "Release") 67 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES LINK_FLAGS "-Wl,--no-undefined -static -s") 68 | else() 69 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES LINK_FLAGS "-Wl,--no-undefined -static") 70 | endif() 71 | endif() 72 | else() 73 | add_custom_command(TARGET VkLayer_powervr_perf_doc POST_BUILD 74 | COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/VkLayer_powervr_perf_doc.json ${CMAKE_BINARY_DIR}/layer/VkLayer_powervr_perf_doc.json) 75 | if (${CMAKE_BUILD_TYPE} MATCHES "Release") 76 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES LINK_FLAGS "-Wl,--no-undefined -s") 77 | else() 78 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES LINK_FLAGS "-Wl,--no-undefined") 79 | endif() 80 | endif() 81 | 82 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/layer") 83 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/layer") 84 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_BINARY_DIR}/layer") 85 | set_target_properties(VkLayer_powervr_perf_doc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/layer") 86 | 87 | add_subdirectory(SPIRV-Cross EXCLUDE_FROM_ALL) 88 | set_property(TARGET spirv-cross-core PROPERTY POSITION_INDEPENDENT_CODE TRUE) 89 | target_link_libraries(VkLayer_powervr_perf_doc spirv-cross-core) 90 | 91 | if (ANDROID) 92 | target_link_libraries(VkLayer_powervr_perf_doc log) 93 | endif() 94 | -------------------------------------------------------------------------------- /layer/descriptor_set.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "descriptor_set.hpp" 22 | #include "descriptor_pool.hpp" 23 | #include "descriptor_set_layout.hpp" 24 | #include "device.hpp" 25 | #include "image_view.hpp" 26 | 27 | namespace MPD 28 | { 29 | 30 | VkResult DescriptorSet::init(const DescriptorSetLayout *layout_, DescriptorPool *pool_) 31 | { 32 | MPD_ASSERT(layout_); 33 | MPD_ASSERT(pool_); 34 | 35 | pool = pool_; 36 | layout = layout_; 37 | layoutUuid = layout->getUuid(); 38 | 39 | for (auto &binding : layout->getBindings()) 40 | { 41 | bindings[binding.first].views.resize(binding.second.arraySize); 42 | bindings[binding.first].descriptorType = binding.second.descriptorType; 43 | } 44 | 45 | pool->descriptorSetCreated(this); 46 | return VK_SUCCESS; 47 | } 48 | 49 | void DescriptorSet::copyDescriptors(Device *device, const VkCopyDescriptorSet ©) 50 | { 51 | auto *dst = device->get(copy.dstSet); 52 | auto *src = device->get(copy.srcSet); 53 | 54 | auto &dstData = dst->bindings[copy.dstBinding]; 55 | auto &srcData = src->bindings[copy.srcBinding]; 56 | 57 | for (uint32_t i = 0; i < copy.descriptorCount; i++) 58 | { 59 | MPD_ASSERT(copy.dstArrayElement + i < dstData.views.size()); 60 | MPD_ASSERT(copy.srcArrayElement + i < srcData.views.size()); 61 | MPD_ASSERT(dstData.descriptorType == srcData.descriptorType); 62 | dstData.views[copy.dstArrayElement + i] = srcData.views[copy.srcArrayElement + i]; 63 | } 64 | } 65 | 66 | void DescriptorSet::writeDescriptors(Device *device, const VkWriteDescriptorSet &write) 67 | { 68 | auto *dst = device->get(write.dstSet); 69 | uint32_t binding = write.dstBinding; 70 | uint32_t arrayIndex = write.dstArrayElement; 71 | uint32_t count = write.descriptorCount; 72 | 73 | auto &bindingData = dst->bindings[binding]; 74 | for (uint32_t i = 0; i < count; i++) 75 | { 76 | MPD_ASSERT(arrayIndex + i < bindingData.views.size()); 77 | MPD_ASSERT(bindingData.descriptorType == write.descriptorType); 78 | 79 | switch (write.descriptorType) 80 | { 81 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: 82 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: 83 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: 84 | bindingData.views[arrayIndex + i] = device->get(write.pImageInfo[i].imageView); 85 | break; 86 | 87 | default: 88 | bindingData.views[arrayIndex + i] = nullptr; 89 | break; 90 | } 91 | } 92 | } 93 | 94 | void DescriptorSet::signalUsage() 95 | { 96 | for (auto &binding : layout->getSampledImageBindings()) 97 | { 98 | for (auto &view : bindings[binding].views) 99 | { 100 | if (view) 101 | view->signalUsage(Image::Usage::ResourceRead); 102 | } 103 | } 104 | 105 | for (auto &binding : layout->getStorageImageBindings()) 106 | { 107 | for (auto &view : bindings[binding].views) 108 | { 109 | if (view) 110 | view->signalUsage(Image::Usage::ResourceWrite); 111 | } 112 | } 113 | } 114 | 115 | DescriptorSet::~DescriptorSet() 116 | { 117 | if (pool) 118 | pool->descriptorSetDeleted(this); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /layer/device.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "device.hpp" 22 | #include "buffer.hpp" 23 | #include "commandbuffer.hpp" 24 | #include "commandpool.hpp" 25 | #include "descriptor_pool.hpp" 26 | #include "descriptor_set.hpp" 27 | #include "descriptor_set_layout.hpp" 28 | #include "device_memory.hpp" 29 | #include "dispatch_helper.hpp" 30 | #include "event.hpp" 31 | #include "framebuffer.hpp" 32 | #include "image.hpp" 33 | #include "instance.hpp" 34 | #include "pipeline.hpp" 35 | #include "pipeline_layout.hpp" 36 | #include "queue.hpp" 37 | #include "render_pass.hpp" 38 | #include "sampler.hpp" 39 | #include "shader_module.hpp" 40 | #include "swapchain.hpp" 41 | 42 | namespace MPD 43 | { 44 | Device::Device(Instance *inst, uint64_t objHandle_) 45 | : BaseInstanceObject(inst, objHandle_, VULKAN_OBJECT_TYPE) 46 | { 47 | } 48 | 49 | Device::~Device() 50 | { 51 | } 52 | 53 | void Device::setQueue(uint32_t family, uint32_t index, VkQueue queue) 54 | { 55 | if (family >= queueFamilies.size()) 56 | queueFamilies.resize(family + 1); 57 | 58 | auto &list = queueFamilies[family]; 59 | if (index >= list.size()) 60 | list.resize(index + 1); 61 | 62 | list[index] = queue; 63 | } 64 | 65 | VkQueue Device::getQueue(uint32_t family, uint32_t index) const 66 | { 67 | MPD_ASSERT(family < queueFamilies.size()); 68 | MPD_ASSERT(index < queueFamilies[family].size()); 69 | return queueFamilies[family][index]; 70 | } 71 | 72 | VkResult Device::init(VkPhysicalDevice gpu_, VkDevice device_, const VkLayerInstanceDispatchTable *pInstanceTable_, 73 | VkLayerDispatchTable *pTable_) 74 | { 75 | gpu = gpu_; 76 | device = device_; 77 | pInstanceTable = pInstanceTable_; 78 | pTable = pTable_; 79 | 80 | getInstanceTable()->GetPhysicalDeviceMemoryProperties(gpu, &memoryProperties); 81 | getInstanceTable()->GetPhysicalDeviceProperties(gpu, &properties); 82 | 83 | return VK_SUCCESS; 84 | } 85 | 86 | void Device::freeDescriptorSets(DescriptorPool *pool) 87 | { 88 | MPD_ASSERT(pool); 89 | auto &map = static_cast> &>(maps); 90 | 91 | while (1) 92 | { 93 | auto it = map.begin(); 94 | const auto end = map.end(); 95 | while (it != end) 96 | { 97 | if (it->second->getPool() == pool) 98 | { 99 | it = map.erase(it); 100 | break; 101 | } 102 | 103 | ++it; 104 | } 105 | 106 | if (it == end) 107 | break; 108 | } 109 | } 110 | 111 | void Device::freeCommandBuffers(CommandPool *pool) 112 | { 113 | MPD_ASSERT(pool); 114 | auto &map = static_cast> &>(maps); 115 | 116 | while (1) 117 | { 118 | auto it = map.begin(); 119 | const auto end = map.end(); 120 | while (it != end) 121 | { 122 | if (it->second->getCommandPool() == pool) 123 | { 124 | it = map.erase(it); 125 | break; 126 | } 127 | 128 | ++it; 129 | } 130 | 131 | if (it == end) 132 | break; 133 | } 134 | } 135 | 136 | const Config &Device::getConfig() const 137 | { 138 | return baseInstance->getConfig(); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /layer/framebuffer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "framebuffer.hpp" 22 | #include "device.hpp" 23 | #include "format.hpp" 24 | #include "image.hpp" 25 | #include "message_codes.hpp" 26 | #include "render_pass.hpp" 27 | #include 28 | #include 29 | 30 | namespace MPD 31 | { 32 | VkResult Framebuffer::init(VkFramebuffer framebuffer_, const VkFramebufferCreateInfo &createInfo_) 33 | { 34 | framebuffer = framebuffer_; 35 | createInfo = createInfo_; 36 | 37 | if (createInfo.attachmentCount) 38 | { 39 | copy(createInfo.pAttachments, createInfo.pAttachments + createInfo.attachmentCount, back_inserter(imageViews)); 40 | createInfo.pAttachments = imageViews.empty() ? nullptr : imageViews.data(); 41 | } 42 | 43 | checkPotentiallyTransient(); 44 | 45 | return VK_SUCCESS; 46 | } 47 | 48 | void Framebuffer::checkPotentiallyTransient() 49 | { 50 | auto *renderPass = baseDevice->get(createInfo.renderPass); 51 | for (uint32_t i = 0; i < createInfo.attachmentCount; i++) 52 | { 53 | if (createInfo.pAttachments[i] == VK_NULL_HANDLE) 54 | continue; 55 | if (i >= renderPass->getCreateInfo().attachmentCount) 56 | continue; 57 | 58 | auto *view = baseDevice->get(createInfo.pAttachments[i]); 59 | MPD_ASSERT(view); 60 | MPD_ASSERT(view->getCreateInfo().image); 61 | auto *baseImage = baseDevice->get(view->getCreateInfo().image); 62 | MPD_ASSERT(baseImage); 63 | bool imageIsTransient = (baseImage->getCreateInfo().usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0; 64 | 65 | auto &attachment = renderPass->getCreateInfo().pAttachments[i]; 66 | bool attachmentShouldBeTransient = 67 | attachment.loadOp != VK_ATTACHMENT_LOAD_OP_LOAD && attachment.storeOp != VK_ATTACHMENT_STORE_OP_STORE; 68 | if (formatIsStencilOnly(attachment.format) || formatIsDepthStencil(attachment.format)) 69 | attachmentShouldBeTransient &= attachment.stencilLoadOp != VK_ATTACHMENT_LOAD_OP_LOAD && 70 | attachment.stencilStoreOp != VK_ATTACHMENT_STORE_OP_STORE; 71 | 72 | const auto &cfg = this->getDevice()->getConfig(); 73 | 74 | if ( 75 | cfg.msgFramebufferAttachmentShouldBeTransient && 76 | attachmentShouldBeTransient && !imageIsTransient) 77 | { 78 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_BE_TRANSIENT, 79 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which never have to be backed by physical memory, " 80 | "but the image backing the image view does not have VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " 81 | "You can save physical memory by using transient attachment backed by lazily allocated memory here.", 82 | i); 83 | } 84 | else if ( 85 | cfg.msgFramebufferAttachmentShouldNotBeTransient && 86 | !attachmentShouldBeTransient && imageIsTransient) 87 | { 88 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, 89 | MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_NOT_BE_TRANSIENT, 90 | "Attachment %u in VkFramebuffer uses loadOp/storeOps which need to access physical memory, " 91 | "but the image backing the image view has VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT set. " 92 | "Physical memory will need to be backed lazily to this image, potentially causing stalls.", 93 | i); 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /layer/include/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright (c) 2014-2015 The Khronos Group Inc. 6 | ** 7 | ** Licensed under the Apache License, Version 2.0 (the "License"); 8 | ** you may not use this file except in compliance with the License. 9 | ** You may obtain a copy of the License at 10 | ** 11 | ** http://www.apache.org/licenses/LICENSE-2.0 12 | ** 13 | ** Unless required by applicable law or agreed to in writing, software 14 | ** distributed under the License is distributed on an "AS IS" BASIS, 15 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ** See the License for the specific language governing permissions and 17 | ** limitations under the License. 18 | */ 19 | 20 | 21 | #ifndef VK_PLATFORM_H_ 22 | #define VK_PLATFORM_H_ 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | { 27 | #endif // __cplusplus 28 | 29 | /* 30 | *************************************************************************************************** 31 | * Platform-specific directives and type declarations 32 | *************************************************************************************************** 33 | */ 34 | 35 | /* Platform-specific calling convention macros. 36 | * 37 | * Platforms should define these so that Vulkan clients call Vulkan commands 38 | * with the same calling conventions that the Vulkan implementation expects. 39 | * 40 | * VKAPI_ATTR - Placed before the return type in function declarations. 41 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 42 | * VKAPI_CALL - Placed after the return type in function declarations. 43 | * Useful for MSVC-style calling convention syntax. 44 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 45 | * 46 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 47 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 48 | */ 49 | #if defined(_WIN32) 50 | // On Windows, Vulkan commands use the stdcall convention 51 | #define VKAPI_ATTR 52 | #define VKAPI_CALL __stdcall 53 | #define VKAPI_PTR VKAPI_CALL 54 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 55 | #error "Vulkan isn't supported for the 'armeabi' NDK ABI" 56 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 57 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 58 | // calling convention, i.e. float parameters are passed in registers. This 59 | // is true even if the rest of the application passes floats on the stack, 60 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 61 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 62 | #define VKAPI_CALL 63 | #define VKAPI_PTR VKAPI_ATTR 64 | #else 65 | // On other platforms, use the default calling convention 66 | #define VKAPI_ATTR 67 | #define VKAPI_CALL 68 | #define VKAPI_PTR 69 | #endif 70 | 71 | #include 72 | 73 | #if !defined(VK_NO_STDINT_H) 74 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 75 | typedef signed __int8 int8_t; 76 | typedef unsigned __int8 uint8_t; 77 | typedef signed __int16 int16_t; 78 | typedef unsigned __int16 uint16_t; 79 | typedef signed __int32 int32_t; 80 | typedef unsigned __int32 uint32_t; 81 | typedef signed __int64 int64_t; 82 | typedef unsigned __int64 uint64_t; 83 | #else 84 | #include 85 | #endif 86 | #endif // !defined(VK_NO_STDINT_H) 87 | 88 | #ifdef __cplusplus 89 | } // extern "C" 90 | #endif // __cplusplus 91 | 92 | // Platform-specific headers required by platform window system extensions. 93 | // These are enabled prior to #including "vulkan.h". The same enable then 94 | // controls inclusion of the extension interfaces in vulkan.h. 95 | 96 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 97 | #include 98 | #endif 99 | 100 | #ifdef VK_USE_PLATFORM_MIR_KHR 101 | #include 102 | #endif 103 | 104 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 105 | #include 106 | #endif 107 | 108 | #ifdef VK_USE_PLATFORM_WIN32_KHR 109 | #include 110 | #endif 111 | 112 | #ifdef VK_USE_PLATFORM_XLIB_KHR 113 | #include 114 | #endif 115 | 116 | #ifdef VK_USE_PLATFORM_XCB_KHR 117 | #include 118 | #endif 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /layer/dispatch_helper.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "perfdoc.hpp" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace MPD 31 | { 32 | using InstanceTable = std::unordered_map>; 33 | using DeviceTable = std::unordered_map>; 34 | 35 | static inline VkLayerDeviceCreateInfo *getChainInfo(const VkInstanceCreateInfo *pCreateInfo, VkLayerFunction func) 36 | { 37 | auto *chain_info = static_cast(pCreateInfo->pNext); 38 | while (chain_info && 39 | !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO && chain_info->function == func)) 40 | chain_info = static_cast(chain_info->pNext); 41 | MPD_ASSERT(chain_info != nullptr); 42 | return const_cast(chain_info); 43 | } 44 | 45 | static inline VkLayerDeviceCreateInfo *getChainInfo(const VkDeviceCreateInfo *pCreateInfo, VkLayerFunction func) 46 | { 47 | auto *chain_info = static_cast(pCreateInfo->pNext); 48 | while (chain_info && 49 | !(chain_info->sType == VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO && chain_info->function == func)) 50 | chain_info = static_cast(chain_info->pNext); 51 | MPD_ASSERT(chain_info != nullptr); 52 | return const_cast(chain_info); 53 | } 54 | 55 | void layerInitDeviceDispatchTable(VkDevice device, VkLayerDispatchTable *table, PFN_vkGetDeviceProcAddr gpa); 56 | 57 | void layerInitInstanceDispatchTable(VkInstance instance, VkLayerInstanceDispatchTable *table, 58 | PFN_vkGetInstanceProcAddr gpa); 59 | 60 | static inline void *getDispatchKey(void *ptr) 61 | { 62 | return *static_cast(ptr); 63 | } 64 | 65 | template 66 | static inline T *getLayerData(void *key, const std::unordered_map> &m) 67 | { 68 | auto itr = m.find(key); 69 | if (itr != end(m)) 70 | return itr->second.get(); 71 | else 72 | return nullptr; 73 | } 74 | 75 | template 76 | static inline T *createLayerData(void *key, std::unordered_map> &m, TArgs &&... args) 77 | { 78 | auto *ptr = new T(std::forward(args)...); 79 | m[key] = std::unique_ptr(ptr); 80 | return ptr; 81 | } 82 | 83 | template 84 | static inline void destroyLayerData(void *key, std::unordered_map> &m) 85 | { 86 | auto itr = m.find(key); 87 | MPD_ASSERT(itr != end(m)); 88 | m.erase(itr); 89 | } 90 | 91 | static inline VkLayerInstanceDispatchTable *initInstanceTable(VkInstance instance, const PFN_vkGetInstanceProcAddr gpa, 92 | InstanceTable &table) 93 | { 94 | auto key = getDispatchKey(instance); 95 | auto itr = table.find(key); 96 | VkLayerInstanceDispatchTable *pTable = nullptr; 97 | if (itr == end(table)) 98 | { 99 | pTable = new VkLayerInstanceDispatchTable; 100 | table[key] = std::unique_ptr(pTable); 101 | } 102 | else 103 | pTable = itr->second.get(); 104 | 105 | layerInitInstanceDispatchTable(instance, pTable, gpa); 106 | return pTable; 107 | } 108 | 109 | static inline VkLayerDispatchTable *initDeviceTable(VkDevice device, const PFN_vkGetDeviceProcAddr gpa, 110 | DeviceTable &table) 111 | { 112 | auto key = getDispatchKey(device); 113 | auto itr = table.find(key); 114 | VkLayerDispatchTable *pTable = nullptr; 115 | if (itr == end(table)) 116 | { 117 | pTable = new VkLayerDispatchTable; 118 | table[key] = std::unique_ptr(pTable); 119 | } 120 | else 121 | pTable = itr->second.get(); 122 | 123 | layerInitDeviceDispatchTable(device, pTable, gpa); 124 | return pTable; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /layer/config.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "config.hpp" 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace std; 28 | 29 | namespace MPD 30 | { 31 | 32 | static bool blankString(const string &str) 33 | { 34 | if (str.empty()) 35 | return true; 36 | 37 | const char *s = str.c_str(); 38 | 39 | while (isspace(*s)) 40 | s++; 41 | 42 | return *s == '\0'; 43 | } 44 | 45 | bool Config::tryToLoadFromFile(const std::string &fname) 46 | { 47 | ifstream file(fname); 48 | 49 | if (!file.is_open()) 50 | { 51 | return false; 52 | } 53 | 54 | while (!file.eof()) 55 | { 56 | string line; 57 | if (!getline(file, line)) 58 | break; 59 | 60 | if (line[0] == '#') 61 | continue; 62 | 63 | if (blankString(line)) 64 | continue; 65 | 66 | // Manually parse here to deal with paths properly. 67 | auto index = line.find_first_of(' '); 68 | if (index == string::npos) 69 | continue; 70 | 71 | auto optionName = line.substr(0, index); 72 | index = line.find_first_not_of(' ', index); 73 | if (index == string::npos) 74 | continue; 75 | 76 | string optionVal; 77 | if (line[index] == '"') // Substring until next " 78 | { 79 | auto endIndex = line.find_first_of('"', index + 1); 80 | if (endIndex == string::npos) 81 | continue; 82 | else 83 | optionVal = line.substr(index + 1, endIndex - (index + 1)); 84 | } 85 | else 86 | { 87 | // Substring until next space in case we have trailing spaces for whatever reason. 88 | auto endIndex = line.find_first_of(' ', index); 89 | if (endIndex == string::npos) 90 | optionVal = line.substr(index); 91 | else 92 | optionVal = line.substr(index, endIndex - index); 93 | } 94 | 95 | // Find option 96 | { 97 | auto it = ints.find(optionName.c_str()); 98 | if (it != ints.end()) 99 | { 100 | *(it->second.ptrToValue) = stoi(optionVal); 101 | continue; 102 | } 103 | } 104 | 105 | { 106 | auto it = uints.find(optionName.c_str()); 107 | if (it != uints.end()) 108 | { 109 | *(it->second.ptrToValue) = stoul(optionVal); 110 | continue; 111 | } 112 | } 113 | 114 | { 115 | auto it = floats.find(optionName.c_str()); 116 | if (it != floats.end()) 117 | { 118 | *(it->second.ptrToValue) = stof(optionVal); 119 | continue; 120 | } 121 | } 122 | 123 | { 124 | auto it = strings.find(optionName.c_str()); 125 | if (it != strings.end()) 126 | { 127 | *(it->second.ptrToValue) = optionVal; 128 | continue; 129 | } 130 | } 131 | 132 | { 133 | auto it = bools.find(optionName.c_str()); 134 | if (it != bools.end()) 135 | { 136 | bool result = false; 137 | if (optionVal == "true" || optionVal == "on" || optionVal == "1") 138 | result = true; 139 | 140 | *(it->second.ptrToValue) = result; 141 | continue; 142 | } 143 | } 144 | 145 | MPD_ASSERT("Unknown option"); 146 | } 147 | return true; 148 | } 149 | 150 | void Config::dumpToFile(const std::string &fname) const 151 | { 152 | ofstream file(fname); 153 | 154 | for (const auto &it : ints) 155 | { 156 | file << "# " << it.second.description << "\n"; 157 | file << it.second.name << " " << *it.second.ptrToValue << "\n\n"; 158 | } 159 | 160 | for (const auto &it : uints) 161 | { 162 | file << "# " << it.second.description << "\n"; 163 | file << it.second.name << " " << *it.second.ptrToValue << "\n\n"; 164 | } 165 | 166 | for (const auto &it : floats) 167 | { 168 | file << "# " << it.second.description << "\n"; 169 | file << it.second.name << " " << *it.second.ptrToValue << "\n\n"; 170 | } 171 | 172 | for (const auto &it : strings) 173 | { 174 | file << "# " << it.second.description << "\n"; 175 | file << it.second.name; 176 | file << " \""; 177 | file << *it.second.ptrToValue; 178 | file << "\"\n\n"; 179 | } 180 | 181 | for (const auto &it : bools) 182 | { 183 | file << "# " << it.second.description << "\n"; 184 | file << it.second.name << " " << (*it.second.ptrToValue ? "on" : "off") << "\n\n"; 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /tests/descriptor-set-allocation-checks.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "vulkan_test.hpp" 22 | #include "perfdoc.hpp" 23 | #include "util.hpp" 24 | 25 | using namespace MPD; 26 | 27 | class DescriptorSetAllocationsTest : public VulkanTestHelper 28 | { 29 | VkDescriptorPool pool; 30 | VkDescriptorSetLayout descriptorSetLayout; 31 | 32 | bool initialize() 33 | { 34 | if (!VulkanTestHelper::initialize()) 35 | return false; 36 | 37 | // Create pool 38 | { 39 | VkDescriptorPoolSize poolSizes[] = { { VK_DESCRIPTOR_TYPE_SAMPLER, 100 } }; 40 | 41 | VkDescriptorPoolCreateInfo inf = {}; 42 | inf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; 43 | inf.maxSets = 100; 44 | inf.poolSizeCount = sizeof(poolSizes) / sizeof(poolSizes[0]); 45 | inf.pPoolSizes = &poolSizes[0]; 46 | 47 | MPD_ASSERT_RESULT(vkCreateDescriptorPool(device, &inf, nullptr, &pool)); 48 | } 49 | 50 | // Create a layout 51 | { 52 | VkDescriptorSetLayoutBinding bindings[1] = {}; 53 | bindings[0].binding = 0; 54 | bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; 55 | bindings[0].descriptorCount = 1; 56 | bindings[0].stageFlags = ~0u; 57 | 58 | VkDescriptorSetLayoutCreateInfo inf = {}; 59 | inf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; 60 | inf.bindingCount = sizeof(bindings) / sizeof(bindings[0]); 61 | inf.pBindings = &bindings[0]; 62 | 63 | MPD_ASSERT_RESULT(vkCreateDescriptorSetLayout(device, &inf, nullptr, &descriptorSetLayout)); 64 | } 65 | 66 | return true; 67 | } 68 | 69 | bool runTest() 70 | { 71 | if (!testPositive()) 72 | return false; 73 | 74 | if (!testPositiveResetPool()) 75 | return false; 76 | 77 | if (!testNegative()) 78 | return false; 79 | 80 | return true; 81 | } 82 | 83 | bool testPositive() 84 | { 85 | resetCounts(); 86 | VkDescriptorSet set = VK_NULL_HANDLE; 87 | 88 | // Allocate a descriptor set 89 | VkDescriptorSetAllocateInfo inf = {}; 90 | inf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; 91 | inf.descriptorPool = pool; 92 | inf.descriptorSetCount = 1; 93 | inf.pSetLayouts = &descriptorSetLayout; 94 | MPD_ASSERT_RESULT(vkAllocateDescriptorSets(device, &inf, &set)); 95 | 96 | // Free it 97 | MPD_ASSERT_RESULT(vkFreeDescriptorSets(device, pool, 1, &set)); 98 | 99 | // Create again 100 | MPD_ASSERT_RESULT(vkAllocateDescriptorSets(device, &inf, &set)); 101 | 102 | if (getCount(MESSAGE_CODE_DESCRIPTOR_SET_ALLOCATION_CHECKS) != 1) 103 | return false; 104 | 105 | return true; 106 | } 107 | 108 | bool testPositiveResetPool() 109 | { 110 | resetCounts(); 111 | VkDescriptorSet set = VK_NULL_HANDLE; 112 | 113 | // Allocate a descriptor set 114 | VkDescriptorSetAllocateInfo inf = {}; 115 | inf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; 116 | inf.descriptorPool = pool; 117 | inf.descriptorSetCount = 1; 118 | inf.pSetLayouts = &descriptorSetLayout; 119 | MPD_ASSERT_RESULT(vkAllocateDescriptorSets(device, &inf, &set)); 120 | 121 | // Free it by reseting the pool 122 | MPD_ASSERT_RESULT(vkResetDescriptorPool(device, pool, 0)); 123 | 124 | // Create again 125 | MPD_ASSERT_RESULT(vkAllocateDescriptorSets(device, &inf, &set)); 126 | if (getCount(MESSAGE_CODE_DESCRIPTOR_SET_ALLOCATION_CHECKS) != 1) 127 | return false; 128 | 129 | return true; 130 | } 131 | 132 | bool testNegative() 133 | { 134 | resetCounts(); 135 | const unsigned COUNT = 2; 136 | VkDescriptorSet sets[COUNT] = {}; 137 | VkDescriptorSetLayout layouts[COUNT] = { descriptorSetLayout, descriptorSetLayout }; 138 | 139 | // Allocate a descriptor set 140 | VkDescriptorSetAllocateInfo inf = {}; 141 | inf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; 142 | inf.descriptorPool = pool; 143 | inf.descriptorSetCount = COUNT; 144 | inf.pSetLayouts = &layouts[0]; 145 | MPD_ASSERT_RESULT(vkAllocateDescriptorSets(device, &inf, &sets[0])); 146 | 147 | // Free it 148 | MPD_ASSERT_RESULT(vkFreeDescriptorSets(device, pool, COUNT, &sets[0])); 149 | if (getCount(MESSAGE_CODE_DESCRIPTOR_SET_ALLOCATION_CHECKS) != 0) 150 | return false; 151 | 152 | return true; 153 | } 154 | }; 155 | 156 | VulkanTestHelper *MPD::createTest() 157 | { 158 | return new DescriptorSetAllocationsTest; 159 | } 160 | -------------------------------------------------------------------------------- /layer/heuristic.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "base_object.hpp" 24 | 25 | namespace MPD 26 | { 27 | 28 | class Device; 29 | class CommandBuffer; 30 | class RenderPass; 31 | 32 | class Heuristic 33 | { 34 | public: 35 | Heuristic(Device *device) 36 | : device(device) 37 | { 38 | } 39 | 40 | virtual ~Heuristic() 41 | { 42 | } 43 | 44 | virtual void cmdBeginRenderPass(VkCommandBuffer, const VkRenderPassBeginInfo *, VkSubpassContents) 45 | { 46 | } 47 | 48 | virtual void cmdSetRenderPass(VkCommandBuffer, RenderPass *) 49 | { 50 | } 51 | 52 | virtual void cmdClearAttachments(VkCommandBuffer, uint32_t, const VkClearAttachment *, uint32_t, 53 | const VkClearRect *) 54 | { 55 | } 56 | 57 | virtual void cmdSetSubpass(VkCommandBuffer, uint32_t index, VkSubpassContents) 58 | { 59 | } 60 | 61 | virtual void cmdEndRenderPass(VkCommandBuffer) 62 | { 63 | } 64 | 65 | virtual void cmdBindPipeline(VkCommandBuffer, VkPipelineBindPoint, VkPipeline) 66 | { 67 | } 68 | 69 | virtual void cmdDraw(VkCommandBuffer, uint32_t, uint32_t, uint32_t, uint32_t) 70 | { 71 | } 72 | 73 | virtual void cmdDrawIndexed(VkCommandBuffer, uint32_t, uint32_t, uint32_t, int32_t, uint32_t) 74 | { 75 | } 76 | 77 | virtual void submit() 78 | { 79 | } 80 | 81 | virtual void reset() 82 | { 83 | } 84 | 85 | protected: 86 | Device *device; 87 | }; 88 | 89 | class DepthPrePassHeuristic : public Heuristic 90 | { 91 | public: 92 | DepthPrePassHeuristic(CommandBuffer *commandBuffer, Device *device); 93 | 94 | void cmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, 95 | VkSubpassContents contents) override; 96 | 97 | void cmdEndRenderPass(VkCommandBuffer commandBuffer) override; 98 | 99 | void cmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, 100 | VkPipeline pipeline) override; 101 | 102 | void cmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, 103 | uint32_t firstInstance) override; 104 | 105 | void cmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, 106 | int32_t vertexOffset, uint32_t firstInstance) override; 107 | 108 | private: 109 | void reset() override; 110 | 111 | static const uint32_t DEPTH_ATTACHMENT = 0x1; 112 | static const uint32_t COLOR_ATTACHMENT = 0x2; 113 | static const uint32_t DEPTH_ONLY = 0x4; 114 | static const uint32_t DEPTH_EQUAL_TEST = 0x8; 115 | static const uint32_t INSIDE_RENDERPASS = 0x10; 116 | 117 | CommandBuffer *commandBuffer; 118 | 119 | uint32_t state; 120 | uint32_t numDrawCallsDepthOnly; 121 | uint32_t numDrawCallsDepthEqual; 122 | }; 123 | 124 | class TileReadbackHeuristic : public Heuristic 125 | { 126 | public: 127 | TileReadbackHeuristic(CommandBuffer *commandBuffer, Device *device); 128 | 129 | void cmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, 130 | VkSubpassContents contents) override; 131 | 132 | private: 133 | CommandBuffer *commandBuffer; 134 | }; 135 | 136 | class ClearAttachmentsHeuristic : public Heuristic 137 | { 138 | public: 139 | ClearAttachmentsHeuristic(CommandBuffer *commandBuffer, Device *device); 140 | void cmdBeginRenderPass(VkCommandBuffer, const VkRenderPassBeginInfo *, VkSubpassContents) override; 141 | void cmdClearAttachments(VkCommandBuffer, uint32_t, const VkClearAttachment *, uint32_t, 142 | const VkClearRect *) override; 143 | void cmdSetSubpass(VkCommandBuffer, uint32_t index, VkSubpassContents) override; 144 | void cmdSetRenderPass(VkCommandBuffer, RenderPass *renderPass) override; 145 | 146 | void cmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, 147 | uint32_t firstInstance) override; 148 | 149 | void cmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, 150 | int32_t vertexOffset, uint32_t firstInstance) override; 151 | 152 | void reset() override; 153 | 154 | private: 155 | CommandBuffer *commandBuffer; 156 | const VkRenderPassCreateInfo *renderPassInfo = nullptr; 157 | uint32_t currentSubpass = 0; 158 | bool hasSeenDrawCall = false; 159 | }; 160 | } 161 | -------------------------------------------------------------------------------- /tests/draw-call.cpp: -------------------------------------------------------------------------------- 1 | 2 | //Note vulkan test needs to come before perfdoc... 3 | #include "vulkan_test.hpp" 4 | #include "perfdoc.hpp" 5 | #include "util.hpp" 6 | #include 7 | #include 8 | using namespace MPD; 9 | using namespace std; 10 | 11 | class DrawCallTest : public VulkanTestHelper 12 | { 13 | public: 14 | //test with uncompressed texture format 15 | bool testNonIndexed(bool positiveTest) 16 | { 17 | VkAttachmentDescription attachments[1] = {}; 18 | attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 19 | attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 20 | attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; 21 | attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; 22 | attachments[0].samples = VK_SAMPLE_COUNT_1_BIT; 23 | attachments[0].format = VK_FORMAT_R8G8B8A8_UNORM; 24 | attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 25 | attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 26 | 27 | const VkAttachmentReference attachment = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }; 28 | 29 | VkSubpassDescription subpass = {}; 30 | subpass.colorAttachmentCount = 1; 31 | subpass.pColorAttachments = &attachment; 32 | subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; 33 | 34 | VkRenderPassCreateInfo info = { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO }; 35 | info.attachmentCount = 1; 36 | info.subpassCount = 1; 37 | info.pSubpasses = &subpass; 38 | info.pAttachments = &attachments[0]; 39 | 40 | VkRenderPass renderPass; 41 | MPD_ASSERT_RESULT(vkCreateRenderPass(device, &info, nullptr, &renderPass)); 42 | 43 | static const uint32_t vertCode[] = 44 | #include "quad_no_attribs.vert.inc" 45 | ; 46 | 47 | static const uint32_t fragCode[] = 48 | #include "quad.frag.inc" 49 | ; 50 | 51 | VkPipelineColorBlendAttachmentState att = {}; 52 | att.blendEnable = true; 53 | att.colorWriteMask = 0xf; 54 | 55 | VkPipelineColorBlendStateCreateInfo blend = { VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO }; 56 | blend.attachmentCount = 1; 57 | blend.pAttachments = &att; 58 | 59 | VkGraphicsPipelineCreateInfo gpci = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO }; 60 | gpci.renderPass = renderPass; 61 | gpci.pColorBlendState = &blend; 62 | 63 | auto pipeline = make_shared(device); 64 | pipeline->initGraphics(vertCode, sizeof(vertCode), fragCode, sizeof(fragCode), &gpci); 65 | 66 | auto cmdBuf = make_shared(device); 67 | cmdBuf->initPrimary(); 68 | 69 | auto tex = make_shared(device); 70 | tex->initRenderTarget2D(128, 128, VK_FORMAT_R8G8B8A8_UNORM); 71 | 72 | setImageLayout(device, queue, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, tex->image, 73 | 0, 1, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT); 74 | 75 | VkFramebufferCreateInfo fbinf = { VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO }; 76 | fbinf.renderPass = renderPass; 77 | fbinf.attachmentCount = 1; 78 | fbinf.pAttachments = &tex->view; 79 | fbinf.width = tex->width; 80 | fbinf.height = tex->height; 81 | fbinf.layers = 1; 82 | 83 | VkFramebuffer fbo; 84 | MPD_ASSERT_RESULT(vkCreateFramebuffer(device, &fbinf, nullptr, &fbo)); 85 | 86 | VkCommandBufferBeginInfo cbbi = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; 87 | cbbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; 88 | MPD_ASSERT_RESULT(vkBeginCommandBuffer(cmdBuf->commandBuffer, &cbbi)); 89 | 90 | vkCmdBindPipeline(cmdBuf->commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline); 91 | 92 | VkClearValue cv = {}; 93 | 94 | VkRenderPassBeginInfo rpbi = { VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO }; 95 | rpbi.renderPass = renderPass; 96 | rpbi.renderArea.offset.x = 0; 97 | rpbi.renderArea.offset.y = 0; 98 | rpbi.renderArea.extent.width = 128; 99 | rpbi.renderArea.extent.height = 128; 100 | rpbi.framebuffer = fbo; 101 | rpbi.clearValueCount = 1; 102 | rpbi.pClearValues = &cv; 103 | 104 | vkCmdBeginRenderPass(cmdBuf->commandBuffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE); 105 | 106 | VkViewport viewport; 107 | viewport.x = 0; 108 | viewport.y = 0; 109 | viewport.width = 128; 110 | viewport.height = 128; 111 | viewport.minDepth = 0; 112 | viewport.maxDepth = 1; 113 | 114 | vkCmdSetViewport(cmdBuf->commandBuffer, 0, 1, &viewport); 115 | 116 | VkRect2D scissor; 117 | scissor.offset.x = 0; 118 | scissor.offset.y = 0; 119 | scissor.extent.width = 128; 120 | scissor.extent.height = 128; 121 | 122 | vkCmdSetScissor(cmdBuf->commandBuffer, 0, 1, &scissor); 123 | 124 | vkCmdDraw(cmdBuf->commandBuffer, positiveTest ? 30 : 3, 1, 0, 0); 125 | 126 | vkCmdEndRenderPass(cmdBuf->commandBuffer); 127 | 128 | MPD_ASSERT_RESULT(vkEndCommandBuffer(cmdBuf->commandBuffer)); 129 | 130 | VkSubmitInfo submit = { VK_STRUCTURE_TYPE_SUBMIT_INFO }; 131 | submit.commandBufferCount = 1; 132 | submit.pCommandBuffers = &cmdBuf->commandBuffer; 133 | vkQueueSubmit(queue, 1, &submit, VK_NULL_HANDLE); 134 | vkQueueWaitIdle(queue); 135 | 136 | vkDestroyRenderPass(device, renderPass, 0); 137 | vkDestroyFramebuffer(device, fbo, 0); 138 | 139 | uint32_t count = getCount(MESSAGE_CODE_NON_INDEXED_DRAW_CALL); 140 | resetCounts(); 141 | 142 | if (positiveTest) 143 | { 144 | if (count != 1) 145 | return false; 146 | } 147 | else 148 | { 149 | if (count != 0) 150 | return false; 151 | } 152 | return true; 153 | } 154 | 155 | bool runTest() override 156 | { 157 | if (!testNonIndexed(false)) 158 | return false; 159 | 160 | if (!testNonIndexed(true)) 161 | return false; 162 | 163 | return true; 164 | } 165 | 166 | virtual bool initialize() 167 | { 168 | return true; 169 | } 170 | }; 171 | 172 | VulkanTestHelper *MPD::createTest() 173 | { 174 | return new DrawCallTest; 175 | } 176 | -------------------------------------------------------------------------------- /layer/device.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "config.hpp" 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace MPD 30 | { 31 | class CommandBuffer; 32 | class CommandPool; 33 | class Buffer; 34 | class Image; 35 | class DescriptorSetLayout; 36 | class DescriptorSet; 37 | class DescriptorPool; 38 | class DeviceMemory; 39 | class RenderPass; 40 | class Pipeline; 41 | class Framebuffer; 42 | class ImageView; 43 | class Sampler; 44 | class ShaderModule; 45 | class SwapchainKHR; 46 | class Queue; 47 | class Event; 48 | class PipelineLayout; 49 | 50 | #define MPD_OBJECT_MAP(ourType) std::unordered_map> 51 | 52 | class ObjectMaps : public MPD_OBJECT_MAP(CommandBuffer), 53 | public MPD_OBJECT_MAP(CommandPool), 54 | public MPD_OBJECT_MAP(Buffer), 55 | public MPD_OBJECT_MAP(Image), 56 | public MPD_OBJECT_MAP(DescriptorSetLayout), 57 | public MPD_OBJECT_MAP(DescriptorSet), 58 | public MPD_OBJECT_MAP(DescriptorPool), 59 | public MPD_OBJECT_MAP(DeviceMemory), 60 | public MPD_OBJECT_MAP(RenderPass), 61 | public MPD_OBJECT_MAP(Pipeline), 62 | public MPD_OBJECT_MAP(Framebuffer), 63 | public MPD_OBJECT_MAP(ImageView), 64 | public MPD_OBJECT_MAP(Sampler), 65 | public MPD_OBJECT_MAP(ShaderModule), 66 | public MPD_OBJECT_MAP(Queue), 67 | public MPD_OBJECT_MAP(SwapchainKHR), 68 | public MPD_OBJECT_MAP(Event), 69 | public MPD_OBJECT_MAP(PipelineLayout) 70 | { 71 | }; 72 | 73 | #undef MPD_OBJECT_MAP 74 | 75 | class Device : public BaseInstanceObject 76 | { 77 | public: 78 | using VulkanType = VkDevice; 79 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT; 80 | 81 | Device(Instance *inst, uint64_t objHandle_); 82 | 83 | ~Device(); 84 | 85 | VkResult init(VkPhysicalDevice gpu_, VkDevice device_, const VkLayerInstanceDispatchTable *pInstanceTable_, 86 | VkLayerDispatchTable *pTable_); 87 | 88 | VkDevice getDevice() const 89 | { 90 | return device; 91 | } 92 | 93 | const VkLayerDispatchTable *getTable() const 94 | { 95 | return pTable; 96 | } 97 | 98 | const VkLayerInstanceDispatchTable *getInstanceTable() const 99 | { 100 | return pInstanceTable; 101 | } 102 | 103 | const VkPhysicalDeviceMemoryProperties &getMemoryProperties() const 104 | { 105 | return memoryProperties; 106 | } 107 | 108 | const VkPhysicalDeviceProperties &getProperties() const 109 | { 110 | return properties; 111 | } 112 | 113 | void setQueue(uint32_t family, uint32_t index, VkQueue queue); 114 | VkQueue getQueue(uint32_t family, uint32_t index) const; 115 | 116 | template 117 | T *alloc(typename T::VulkanType handle) 118 | { 119 | using VkType = typename T::VulkanType; 120 | using MapType = std::unordered_map>; 121 | auto &map = static_cast(maps); 122 | 123 | MPD_ASSERT(map.find(handle) == map.end()); 124 | // Reinterpret cast while changing integer size doesn't work on MSVC. 125 | T *n = new T(this, (uint64_t)handle); 126 | map[handle] = std::unique_ptr(n); 127 | return n; 128 | } 129 | 130 | template 131 | T *get(typename T::VulkanType handle) 132 | { 133 | using VkType = typename T::VulkanType; 134 | using MapType = std::unordered_map>; 135 | auto &map = static_cast(maps); 136 | 137 | auto it = map.find(handle); 138 | if (it != map.end()) 139 | return it->second.get(); 140 | else 141 | return nullptr; 142 | } 143 | 144 | template 145 | void destroy(typename T::VulkanType handle) 146 | { 147 | if (handle == VK_NULL_HANDLE) 148 | return; 149 | 150 | using VkType = typename T::VulkanType; 151 | using MapType = std::unordered_map>; 152 | auto &map = static_cast(maps); 153 | 154 | auto it = map.find(handle); 155 | MPD_ASSERT(it != map.end()); 156 | map.erase(it); 157 | } 158 | 159 | void freeDescriptorSets(DescriptorPool *pool); 160 | void freeCommandBuffers(CommandPool *pool); 161 | 162 | const Config &getConfig() const; 163 | 164 | private: 165 | VkPhysicalDevice gpu = VK_NULL_HANDLE; 166 | VkDevice device = VK_NULL_HANDLE; 167 | const VkLayerInstanceDispatchTable *pInstanceTable = nullptr; 168 | VkLayerDispatchTable *pTable = nullptr; 169 | 170 | ObjectMaps maps; 171 | VkPhysicalDeviceMemoryProperties memoryProperties; 172 | VkPhysicalDeviceProperties properties; 173 | 174 | std::vector> queueFamilies; 175 | }; 176 | } 177 | -------------------------------------------------------------------------------- /tests/compute-test.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "perfdoc.hpp" 22 | #include "util.hpp" 23 | #include "vulkan_test.hpp" 24 | #include 25 | #include 26 | using namespace MPD; 27 | using namespace std; 28 | 29 | class Compute : public VulkanTestHelper 30 | { 31 | enum class Test 32 | { 33 | Aligned, 34 | Unaligned, 35 | Large 36 | }; 37 | 38 | bool checkWorkGroupSizeDivisible(bool positiveTest) 39 | { 40 | resetCounts(); 41 | 42 | static const uint32_t badCode[] = 43 | #include "compute.wg.31.1.1.comp.inc" 44 | ; 45 | 46 | static const uint32_t goodCode[] = 47 | #include "compute.wg.32.1.1.comp.inc" 48 | ; 49 | 50 | auto pipeline = make_shared(device); 51 | if (positiveTest) 52 | { 53 | pipeline->initCompute(badCode, sizeof(badCode)); 54 | } 55 | else 56 | { 57 | pipeline->initCompute(goodCode, sizeof(goodCode)); 58 | } 59 | 60 | if (getCount(MESSAGE_CODE_WORKGROUP_SIZE_DIVISOR) != 0) 61 | return false; 62 | 63 | return true; 64 | } 65 | 66 | bool checkWorkGroupSize(Test test) 67 | { 68 | resetCounts(); 69 | static const uint32_t alignedCode[] = 70 | #include "compute.wg.4.1.1.comp.inc" 71 | ; 72 | 73 | static const uint32_t unalignedCode[] = 74 | #include "compute.wg.4.1.3.comp.inc" 75 | ; 76 | 77 | static const uint32_t largeGroup[] = 78 | #include "compute.wg.16.8.1.comp.inc" 79 | ; 80 | 81 | auto pipeline = make_shared(device); 82 | switch (test) 83 | { 84 | case Test::Aligned: 85 | pipeline->initCompute(alignedCode, sizeof(alignedCode)); 86 | break; 87 | case Test::Unaligned: 88 | pipeline->initCompute(unalignedCode, sizeof(unalignedCode)); 89 | break; 90 | case Test::Large: 91 | pipeline->initCompute(largeGroup, sizeof(largeGroup)); 92 | break; 93 | } 94 | 95 | switch (test) 96 | { 97 | case Test::Aligned: 98 | if (getCount(MESSAGE_CODE_COMPUTE_NO_THREAD_GROUP_ALIGNMENT) != 0) 99 | return false; 100 | if (getCount(MESSAGE_CODE_COMPUTE_LARGE_WORK_GROUP) != 0) 101 | return false; 102 | break; 103 | case Test::Unaligned: 104 | if (getCount(MESSAGE_CODE_COMPUTE_NO_THREAD_GROUP_ALIGNMENT) != 1) 105 | return false; 106 | if (getCount(MESSAGE_CODE_COMPUTE_LARGE_WORK_GROUP) != 0) 107 | return false; 108 | break; 109 | case Test::Large: 110 | if (getCount(MESSAGE_CODE_COMPUTE_NO_THREAD_GROUP_ALIGNMENT) != 0) 111 | return false; 112 | if (getCount(MESSAGE_CODE_COMPUTE_LARGE_WORK_GROUP) != 1) 113 | return false; 114 | break; 115 | } 116 | 117 | return true; 118 | } 119 | 120 | enum class DimTest 121 | { 122 | Negative2D, 123 | Negative1D, 124 | Positive2D 125 | }; 126 | 127 | bool checkDimensions(DimTest test) 128 | { 129 | resetCounts(); 130 | static const uint32_t dim_2d_negative[] = 131 | #include "compute.sampler.2d.8.8.1.comp.inc" 132 | ; 133 | static const uint32_t dim_1d_negative[] = 134 | #include "compute.sampler.1d.64.1.1.comp.inc" 135 | ; 136 | static const uint32_t dim_2d_positive[] = 137 | #include "compute.sampler.2d.64.1.1.comp.inc" 138 | ; 139 | 140 | const uint32_t *code; 141 | size_t size; 142 | switch (test) 143 | { 144 | case DimTest::Negative2D: 145 | code = dim_2d_negative; 146 | size = sizeof(dim_2d_negative); 147 | break; 148 | case DimTest::Negative1D: 149 | code = dim_1d_negative; 150 | size = sizeof(dim_1d_negative); 151 | break; 152 | case DimTest::Positive2D: 153 | code = dim_2d_positive; 154 | size = sizeof(dim_2d_positive); 155 | break; 156 | } 157 | 158 | auto pipeline = make_shared(device); 159 | pipeline->initCompute(code, size); 160 | 161 | switch (test) 162 | { 163 | case DimTest::Negative2D: 164 | if (getCount(MESSAGE_CODE_COMPUTE_POOR_SPATIAL_LOCALITY) != 0) 165 | return false; 166 | break; 167 | case DimTest::Negative1D: 168 | if (getCount(MESSAGE_CODE_COMPUTE_POOR_SPATIAL_LOCALITY) != 0) 169 | return false; 170 | break; 171 | case DimTest::Positive2D: 172 | if (getCount(MESSAGE_CODE_COMPUTE_POOR_SPATIAL_LOCALITY) != 1) 173 | return false; 174 | break; 175 | } 176 | 177 | return true; 178 | } 179 | 180 | bool runTest() 181 | { 182 | if (!checkWorkGroupSizeDivisible(true)) 183 | return false; 184 | if (!checkWorkGroupSizeDivisible(false)) 185 | return false; 186 | 187 | if (!checkWorkGroupSize(Test::Aligned)) 188 | return false; 189 | if (!checkWorkGroupSize(Test::Unaligned)) 190 | return false; 191 | if (!checkWorkGroupSize(Test::Large)) 192 | return false; 193 | if (!checkDimensions(DimTest::Negative2D)) 194 | return false; 195 | if (!checkDimensions(DimTest::Negative1D)) 196 | return false; 197 | if (!checkDimensions(DimTest::Positive2D)) 198 | return false; 199 | return true; 200 | } 201 | }; 202 | 203 | VulkanTestHelper *MPD::createTest() 204 | { 205 | return new Compute; 206 | } 207 | -------------------------------------------------------------------------------- /layer/commandbuffer.hpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #pragma once 22 | #include "base_object.hpp" 23 | #include "dispatch_helper.hpp" 24 | #include "heuristic.hpp" 25 | #include "perfdoc.hpp" 26 | #include "pipeline.hpp" 27 | #include "queue_tracker.hpp" 28 | 29 | #include 30 | #include 31 | 32 | namespace MPD 33 | { 34 | 35 | class CommandPool; 36 | class Buffer; 37 | class Queue; 38 | class RenderPass; 39 | class DescriptorSet; 40 | class PipelineLayout; 41 | 42 | class CommandBuffer : public BaseObject 43 | { 44 | public: 45 | using VulkanType = VkCommandBuffer; 46 | static const VkDebugReportObjectTypeEXT VULKAN_OBJECT_TYPE = VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT; 47 | 48 | CommandBuffer(Device *device, uint64_t objHandle_); 49 | 50 | VkResult init(VkCommandBuffer commandBuffer_, CommandPool *commandPool_); 51 | 52 | VkCommandBuffer getCommandBuffer() const 53 | { 54 | return commandBuffer; 55 | } 56 | 57 | CommandPool *getCommandPool() const 58 | { 59 | return commandPool; 60 | } 61 | 62 | void enqueueDeferredFunction(std::function Function); 63 | void callDeferredFunctions(Queue &queue); 64 | 65 | void bindIndexBuffer(Buffer *buffer, VkDeviceSize offset, VkIndexType indexType); 66 | void executeCommandBuffer(CommandBuffer *commandBuffer); 67 | 68 | void bindPipeline(VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline); 69 | void beginRenderPass(const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents); 70 | void nextSubpass(VkSubpassContents contents); 71 | void endRenderPass(); 72 | 73 | void bindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, uint32_t firstSet, 74 | uint32_t descriptorSetCount, const VkDescriptorSet *pDescriptorSets, 75 | uint32_t dynamicOffsetCount, const uint32_t *pDynamicOffsets); 76 | 77 | void draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance); 78 | void drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, 79 | uint32_t firstInstance); 80 | 81 | void pipelineBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, 82 | VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, 83 | const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, 84 | const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, 85 | const VkImageMemoryBarrier *pImageMemoryBarriers); 86 | 87 | void clearAttachments(uint32_t attachmentCount, const VkClearAttachment *pAttachments, uint32_t rectCount, 88 | const VkClearRect *pRect); 89 | 90 | void reset(); 91 | 92 | void setIsSecondaryCommandBuffer(bool secondary) 93 | { 94 | this->secondary = secondary; 95 | } 96 | 97 | void setCurrentRenderPass(RenderPass *renderPass); 98 | 99 | void setCurrentSubpassIndex(uint32_t index); 100 | 101 | static QueueTracker::StageFlags vkStagesToTracker(VkPipelineStageFlags stages); 102 | 103 | void enqueueGraphicsDescriptorSetUsage(); 104 | void enqueueComputeDescriptorSetUsage(); 105 | 106 | void setFramebuffer(VkFramebuffer fb) 107 | { 108 | lastFB = fb; 109 | } 110 | 111 | VkFramebuffer getLastFramebuffer() 112 | { 113 | return lastFB; 114 | } 115 | 116 | uint32_t getCurrentSubpassIndex() 117 | { 118 | return currentSubpassIndex; 119 | } 120 | 121 | private: 122 | void scanIndices(Buffer *buffer, VkDeviceSize indexOffset, VkIndexType indexType, uint32_t indexCount, 123 | uint32_t firstIndex, bool primitiveRestart); 124 | 125 | VkCommandBuffer commandBuffer = VK_NULL_HANDLE; 126 | CommandPool *commandPool; 127 | 128 | std::vector executedCommandBuffers; 129 | std::vector> deferredFunctions; 130 | 131 | VkFramebuffer lastFB; 132 | 133 | Buffer *indexBuffer; 134 | VkDeviceSize indexOffset; 135 | VkIndexType indexType; 136 | Pipeline *pipeline; 137 | 138 | uint32_t smallIndexedDrawcallCount = 0; 139 | 140 | std::vector> heuristics; 141 | const RenderPass *currentRenderPass; 142 | uint32_t currentSubpassIndex = 0; 143 | bool secondary = false; 144 | 145 | struct CacheEntry 146 | { 147 | uint32_t value; 148 | uint32_t age; 149 | }; 150 | 151 | std::vector cacheEntries; 152 | static bool testCache(uint32_t value, uint32_t iteration, CacheEntry *cacheEntries, uint32_t cacheSize); 153 | 154 | void enqueueRenderPassLoadOps(VkRenderPass renderPass, VkFramebuffer framebuffer); 155 | void enqueueRenderPassStoreOps(VkRenderPass renderPass, VkFramebuffer framebuffer); 156 | 157 | struct DescriptorSetInfo 158 | { 159 | DescriptorSet *set = nullptr; 160 | bool dirty = true; 161 | }; 162 | std::vector graphicsDescriptorSets; 163 | std::vector computeDescriptorSets; 164 | const PipelineLayout *graphicsLayout = nullptr; 165 | const PipelineLayout *computeLayout = nullptr; 166 | }; 167 | } // namespace MPD 168 | -------------------------------------------------------------------------------- /layer/sampler.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "sampler.hpp" 22 | #include "device.hpp" 23 | #include "message_codes.hpp" 24 | 25 | namespace MPD 26 | { 27 | 28 | void Sampler::checkIdenticalWrapping() 29 | { 30 | const auto &cfg = this->getDevice()->getConfig(); 31 | 32 | bool differentAddress = 33 | (createInfo.addressModeU != createInfo.addressModeV) || (createInfo.addressModeV != createInfo.addressModeW); 34 | //works fine on PowerVR 35 | if (cfg.msgDissimilarWrapping && differentAddress) 36 | { 37 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_DISSIMILAR_WRAPPING, 38 | "Creating a sampler object with wrapping modes which do not match (U = %u, V = %u, W = %u). " 39 | "This will lead to less efficient descriptors being created on Mali-G71, Mali-G72 and Mali-G51 even if " 40 | "only U (1D image) or U/V wrapping " 41 | "modes (2D image) are actually used and may cause reduced performance. " 42 | "If you need different wrapping modes, disregard this warning.", 43 | static_cast(createInfo.addressModeU), static_cast(createInfo.addressModeV), 44 | static_cast(createInfo.addressModeW)); 45 | } 46 | } 47 | 48 | void Sampler::checkLodClamping() 49 | { 50 | const auto &cfg = this->getDevice()->getConfig(); 51 | 52 | bool lodClamping = (createInfo.minLod != 0.0f) || (createInfo.maxLod < baseDevice->getConfig().unclampedMaxLod); 53 | //works fine on PowerVR 54 | if (cfg.msgSamplerLodClamping && lodClamping) 55 | { 56 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_SAMPLER_LOD_CLAMPING, 57 | "Creating a sampler object with LOD clamping (minLod = %f, maxLod = %f). " 58 | "This will lead to less efficient descriptors being created on Mali-G71, Mali-G72 and Mali-G51 and may " 59 | "cause reduced performance. " 60 | "Instead of clamping LOD in the sampler, consider using an VkImageView which restricts the mip-levels, " 61 | "set minLod to 0.0, and maxLod to at least %f (or just VK_LOD_CLAMP_NONE).", 62 | createInfo.minLod, createInfo.maxLod, baseDevice->getConfig().unclampedMaxLod); 63 | } 64 | } 65 | 66 | void Sampler::checkLodBias() 67 | { 68 | const auto &cfg = this->getDevice()->getConfig(); 69 | 70 | bool lodBias = createInfo.mipLodBias != 0.0f; 71 | //works fine on PowerVR 72 | if (cfg.msgSamplerLodBias && lodBias) 73 | { 74 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_SAMPLER_LOD_BIAS, 75 | "Creating a sampler object with LOD bias != 0.0 (%f). " 76 | "This will lead to less efficient descriptors being created on Mali-G71, Mali-G72 and Mali-G51 and may " 77 | "cause reduced performance.", 78 | createInfo.mipLodBias); 79 | } 80 | } 81 | 82 | void Sampler::checkBorderClamp() 83 | { 84 | const auto &cfg = this->getDevice()->getConfig(); 85 | 86 | if (createInfo.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || 87 | createInfo.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER || 88 | createInfo.addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) 89 | { 90 | //works fine on PowerVR 91 | if (cfg.msgSamplerBorderClampColor && createInfo.borderColor != VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK) 92 | { 93 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_SAMPLER_BORDER_CLAMP_COLOR, 94 | "Creating a sampler object with border clamping and borderColor != " 95 | "VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK. " 96 | "This will lead to less efficient descriptors being created on Mali-G71, Mali-G72 and Mali-G51 and " 97 | "may cause reduced performance. " 98 | "If possible, use VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK as the border color."); 99 | } 100 | } 101 | } 102 | 103 | void Sampler::checkUnnormalizedCoords() 104 | { 105 | const auto &cfg = this->getDevice()->getConfig(); 106 | 107 | //works fine on PowerVR 108 | if (cfg.msgSamplerUnnormalizedCoords && createInfo.unnormalizedCoordinates) 109 | { 110 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_SAMPLER_UNNORMALIZED_COORDS, 111 | "Creating a sampler object with unnormalized coordinates. " 112 | "This will lead to less efficient descriptors being created on Mali-G71, Mali-G72 and Mali-G51 and may " 113 | "cause reduced performance."); 114 | } 115 | } 116 | 117 | void Sampler::checkAnisotropy() 118 | { 119 | const auto &cfg = this->getDevice()->getConfig(); 120 | 121 | if (cfg.msgSamplerAnisotropy && createInfo.anisotropyEnable) 122 | { 123 | log(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, MESSAGE_CODE_SAMPLER_ANISOTROPY, 124 | "Creating a sampler object with anisotropy. " 125 | "This will lead to less efficient descriptors being created on Mali-G71, Mali-G72 and Mali-G51 and may " 126 | "cause reduced performance."); 127 | } 128 | } 129 | 130 | VkResult Sampler::init(VkSampler sampler_, const VkSamplerCreateInfo &createInfo_) 131 | { 132 | sampler = sampler_; 133 | createInfo = createInfo_; 134 | checkIdenticalWrapping(); 135 | checkLodClamping(); 136 | checkLodBias(); 137 | checkBorderClamp(); 138 | checkUnnormalizedCoords(); 139 | checkAnisotropy(); 140 | return VK_SUCCESS; 141 | } 142 | } -------------------------------------------------------------------------------- /tests/transient.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2017, ARM Limited and Contributors 2 | * 3 | * SPDX-License-Identifier: MIT 4 | * 5 | * Permission is hereby granted, free of charge, 6 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 9 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | */ 20 | 21 | #include "vulkan_test.hpp" 22 | #include "perfdoc.hpp" 23 | #include "util.hpp" 24 | using namespace MPD; 25 | using namespace std; 26 | 27 | class Transient : public VulkanTestHelper 28 | { 29 | bool runTest() 30 | { 31 | if (!testTransient(false)) 32 | return false; 33 | if (!testTransient(true)) 34 | return false; 35 | 36 | if (!testTransientMismatch(false, false)) 37 | return false; 38 | if (!testTransientMismatch(false, true)) 39 | return false; 40 | if (!testTransientMismatch(true, false)) 41 | return false; 42 | if (!testTransientMismatch(true, true)) 43 | return false; 44 | 45 | return true; 46 | } 47 | 48 | bool testTransientMismatch(bool transientImage, bool transientRenderPass) 49 | { 50 | resetCounts(); 51 | 52 | auto renderTarget = make_shared(device); 53 | renderTarget->initRenderTarget2D(1024, 1024, VK_FORMAT_R8G8B8A8_UNORM, transientImage); 54 | 55 | auto fb = make_shared(device); 56 | fb->initOnlyColor(renderTarget, transientRenderPass ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD, 57 | transientRenderPass ? VK_ATTACHMENT_STORE_OP_DONT_CARE : VK_ATTACHMENT_STORE_OP_STORE); 58 | 59 | if (transientRenderPass && !transientImage) 60 | { 61 | if (getCount(MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_BE_TRANSIENT) != 1) 62 | return false; 63 | if (getCount(MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_NOT_BE_TRANSIENT) != 0) 64 | return false; 65 | } 66 | else if (!transientRenderPass && transientImage) 67 | { 68 | if (getCount(MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_BE_TRANSIENT) != 0) 69 | return false; 70 | if (getCount(MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_NOT_BE_TRANSIENT) != 1) 71 | return false; 72 | } 73 | else 74 | { 75 | if (getCount(MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_BE_TRANSIENT) != 0) 76 | return false; 77 | if (getCount(MESSAGE_CODE_FRAMEBUFFER_ATTACHMENT_SHOULD_NOT_BE_TRANSIENT) != 0) 78 | return false; 79 | } 80 | 81 | return true; 82 | } 83 | 84 | bool testTransient(bool positiveTest) 85 | { 86 | resetCounts(); 87 | VkImageCreateInfo info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO }; 88 | info.format = VK_FORMAT_R8G8B8A8_UNORM; 89 | info.samples = VK_SAMPLE_COUNT_1_BIT; 90 | info.arrayLayers = 1; 91 | info.mipLevels = 1; 92 | info.imageType = VK_IMAGE_TYPE_2D; 93 | info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; 94 | info.tiling = VK_IMAGE_TILING_OPTIMAL; 95 | info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | 96 | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; 97 | info.extent.width = 1024; 98 | info.extent.height = 1024; 99 | info.extent.depth = 1; 100 | 101 | VkImage image; 102 | MPD_ASSERT_RESULT(vkCreateImage(device, &info, nullptr, &image)); 103 | 104 | VkMemoryRequirements memoryRequirements; 105 | vkGetImageMemoryRequirements(device, image, &memoryRequirements); 106 | 107 | // First figure out if implementation supports lazy memory. 108 | bool implementationSupportsLazy = false; 109 | bool implementationSupportsNonLazy = false; 110 | uint32_t lazyType = 0; 111 | uint32_t nonLazyType = 0; 112 | for (uint32_t i = 0; i < memoryProperties.memoryTypeCount; i++) 113 | { 114 | if ((1u << i) & memoryRequirements.memoryTypeBits) 115 | { 116 | if (memoryProperties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) 117 | { 118 | implementationSupportsLazy = true; 119 | lazyType = i; 120 | } 121 | else if (memoryProperties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) 122 | { 123 | implementationSupportsNonLazy = true; 124 | nonLazyType = i; 125 | } 126 | } 127 | } 128 | 129 | MPD_ALWAYS_ASSERT(implementationSupportsLazy || implementationSupportsNonLazy); 130 | 131 | // If we have a positive test and we don't support lazy here, we have no way to test it. 132 | if (positiveTest && !implementationSupportsLazy) 133 | return true; 134 | 135 | VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO }; 136 | allocInfo.allocationSize = memoryRequirements.size; 137 | 138 | if (positiveTest) 139 | { 140 | // For positive test, use the "wrong" type. 141 | allocInfo.memoryTypeIndex = nonLazyType; 142 | } 143 | else 144 | { 145 | // For negative test, use the correct type. 146 | allocInfo.memoryTypeIndex = implementationSupportsLazy ? lazyType : nonLazyType; 147 | } 148 | 149 | VkDeviceMemory memory; 150 | MPD_ASSERT_RESULT(vkAllocateMemory(device, &allocInfo, nullptr, &memory)); 151 | MPD_ASSERT_RESULT(vkBindImageMemory(device, image, memory, 0)); 152 | 153 | if (positiveTest) 154 | { 155 | if (getCount(MESSAGE_CODE_NON_LAZY_TRANSIENT_IMAGE) != 1) 156 | return false; 157 | } 158 | else 159 | { 160 | if (getCount(MESSAGE_CODE_NON_LAZY_TRANSIENT_IMAGE) != 0) 161 | return false; 162 | } 163 | 164 | vkDestroyImage(device, image, nullptr); 165 | vkFreeMemory(device, memory, nullptr); 166 | return true; 167 | } 168 | }; 169 | 170 | VulkanTestHelper *MPD::createTest() 171 | { 172 | return new Transient; 173 | } 174 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # The style used for all options not specifically set in the configuration. 2 | BasedOnStyle: LLVM 3 | 4 | # The extra indent or outdent of access modifiers, e.g. public:. 5 | AccessModifierOffset: -4 6 | 7 | # If true, aligns escaped newlines as far left as possible. Otherwise puts them into the right-most column. 8 | AlignEscapedNewlinesLeft: true 9 | 10 | # If true, aligns trailing comments. 11 | AlignTrailingComments: false 12 | 13 | # Allow putting all parameters of a function declaration onto the next line even if BinPackParameters is false. 14 | AllowAllParametersOfDeclarationOnNextLine: false 15 | 16 | # Allows contracting simple braced statements to a single line. 17 | AllowShortBlocksOnASingleLine: false 18 | 19 | # If true, short case labels will be contracted to a single line. 20 | AllowShortCaseLabelsOnASingleLine: false 21 | 22 | # Dependent on the value, int f() { return 0; } can be put on a single line. Possible values: None, Inline, All. 23 | AllowShortFunctionsOnASingleLine: None 24 | 25 | # If true, if (a) return; can be put on a single line. 26 | AllowShortIfStatementsOnASingleLine: false 27 | 28 | # If true, while (true) continue; can be put on a single line. 29 | AllowShortLoopsOnASingleLine: false 30 | 31 | # If true, always break after function definition return types. 32 | AlwaysBreakAfterDefinitionReturnType: false 33 | 34 | # If true, always break before multiline string literals. 35 | AlwaysBreakBeforeMultilineStrings: false 36 | 37 | # If true, always break after the template<...> of a template declaration. 38 | AlwaysBreakTemplateDeclarations: true 39 | 40 | # If false, a function call's arguments will either be all on the same line or will have one line each. 41 | BinPackArguments: true 42 | 43 | # If false, a function declaration's or function definition's parameters will either all be on the same line 44 | # or will have one line each. 45 | BinPackParameters: true 46 | 47 | # The way to wrap binary operators. Possible values: None, NonAssignment, All. 48 | BreakBeforeBinaryOperators: None 49 | 50 | # The brace breaking style to use. Possible values: Attach, Linux, Stroustrup, Allman, GNU. 51 | BreakBeforeBraces: Allman 52 | 53 | # If true, ternary operators will be placed after line breaks. 54 | BreakBeforeTernaryOperators: false 55 | 56 | # Always break constructor initializers before commas and align the commas with the colon. 57 | BreakConstructorInitializersBeforeComma: true 58 | 59 | # The column limit. A column limit of 0 means that there is no column limit. 60 | ColumnLimit: 120 61 | 62 | # A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed. 63 | CommentPragmas: '^ *' 64 | 65 | # If the constructor initializers don't fit on a line, put each initializer on its own line. 66 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 67 | 68 | # The number of characters to use for indentation of constructor initializer lists. 69 | ConstructorInitializerIndentWidth: 4 70 | 71 | # Indent width for line continuations. 72 | ContinuationIndentWidth: 4 73 | 74 | # If true, format braced lists as best suited for C++11 braced lists. 75 | Cpp11BracedListStyle: false 76 | 77 | # Disables formatting at all. 78 | DisableFormat: false 79 | 80 | # A vector of macros that should be interpreted as foreach loops instead of as function calls. 81 | #ForEachMacros: '' 82 | 83 | # Indent case labels one level from the switch statement. 84 | # When false, use the same indentation level as for the switch statement. 85 | # Switch statement body is always indented one level more than case labels. 86 | IndentCaseLabels: false 87 | 88 | # The number of columns to use for indentation. 89 | IndentWidth: 4 90 | 91 | # Indent if a function definition or declaration is wrapped after the type. 92 | IndentWrappedFunctionNames: false 93 | 94 | # If true, empty lines at the start of blocks are kept. 95 | KeepEmptyLinesAtTheStartOfBlocks: true 96 | 97 | # Language, this format style is targeted at. Possible values: None, Cpp, Java, JavaScript, Proto. 98 | Language: Cpp 99 | 100 | # The maximum number of consecutive empty lines to keep. 101 | MaxEmptyLinesToKeep: 1 102 | 103 | # The indentation used for namespaces. Possible values: None, Inner, All. 104 | NamespaceIndentation: None 105 | 106 | # The penalty for breaking a function call after "call(". 107 | PenaltyBreakBeforeFirstCallParameter: 19 108 | 109 | # The penalty for each line break introduced inside a comment. 110 | PenaltyBreakComment: 300 111 | 112 | # The penalty for breaking before the first <<. 113 | PenaltyBreakFirstLessLess: 120 114 | 115 | # The penalty for each line break introduced inside a string literal. 116 | PenaltyBreakString: 1000 117 | 118 | # The penalty for each character outside of the column limit. 119 | PenaltyExcessCharacter: 1000000 120 | 121 | # Penalty for putting the return type of a function onto its own line. 122 | PenaltyReturnTypeOnItsOwnLine: 1000000000 123 | 124 | # Pointer and reference alignment style. Possible values: Left, Right, Middle. 125 | PointerAlignment: Right 126 | 127 | # If true, a space may be inserted after C style casts. 128 | SpaceAfterCStyleCast: false 129 | 130 | # If false, spaces will be removed before assignment operators. 131 | SpaceBeforeAssignmentOperators: true 132 | 133 | # Defines in which cases to put a space before opening parentheses. Possible values: Never, ControlStatements, Always. 134 | SpaceBeforeParens: ControlStatements 135 | 136 | # If true, spaces may be inserted into '()'. 137 | SpaceInEmptyParentheses: false 138 | 139 | # The number of spaces before trailing line comments (// - comments). 140 | SpacesBeforeTrailingComments: 1 141 | 142 | # If true, spaces will be inserted after '<' and before '>' in template argument lists. 143 | SpacesInAngles: false 144 | 145 | # If true, spaces may be inserted into C style casts. 146 | SpacesInCStyleCastParentheses: false 147 | 148 | # If true, spaces are inserted inside container literals (e.g. ObjC and Javascript array and dict literals). 149 | SpacesInContainerLiterals: false 150 | 151 | # If true, spaces will be inserted after '(' and before ')'. 152 | SpacesInParentheses: false 153 | 154 | # If true, spaces will be inserted after '[' and befor']'. 155 | SpacesInSquareBrackets: false 156 | 157 | # Format compatible with this standard, e.g. use A > instead of A> for LS_Cpp03. Possible values: Cpp03, Cpp11, Auto. 158 | Standard: Cpp11 159 | 160 | # The number of columns used for tab stops. 161 | TabWidth: 4 162 | 163 | # The way to use tab characters in the resulting file. Possible values: Never, ForIndentation, Always. 164 | UseTab: ForIndentation 165 | --------------------------------------------------------------------------------