├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── CMakeLists.txt ├── CMakeLists.txt.freeglut.in ├── CMakeLists.txt.gli.in ├── CMakeLists.txt.glm.in ├── CMakeLists.txt.glslang.in ├── CMakeLists.txt.googletest.in ├── CMakeLists.txt.openvr.in ├── CMakeLists.txt.png.in ├── CMakeLists.txt.spirv-headers.in ├── CMakeLists.txt.spirv-tools.in ├── CMakeLists.txt.zlib.in ├── CONTRIBUTING ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── cube │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.gradle │ ├── gen │ │ └── vulkan │ │ │ └── library │ │ │ └── sample │ │ │ └── cube │ │ │ ├── BuildConfig.java │ │ │ ├── Manifest.java │ │ │ └── R.java │ └── src │ │ ├── cube-frag.frag │ │ ├── cube-vert.vert │ │ ├── cube.cpp │ │ └── main │ │ ├── AndroidManifest.xml │ │ └── res │ │ ├── drawable-nodpi │ │ └── png_transparency_demonstration_1.png │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── heightmap │ ├── CMakeLists.txt │ ├── build.gradle │ └── src │ │ ├── heightmap-frag.frag │ │ ├── heightmap-tesc.tesc │ │ ├── heightmap-tese.tese │ │ ├── heightmap-vert.vert │ │ ├── heightmap.cpp │ │ └── main │ │ ├── AndroidManifest.xml │ │ └── res │ │ ├── drawable-nodpi │ │ └── png_transparency_demonstration_1.png │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── lighting │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.gradle │ ├── include │ │ └── teapot.h │ └── src │ │ ├── lighting-frag.frag │ │ ├── lighting-vert.vert │ │ ├── lighting.cpp │ │ └── main │ │ ├── AndroidManifest.xml │ │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── normal-mapping-and-cube-texture │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.gradle │ └── src │ │ ├── main │ │ ├── AndroidManifest.xml │ │ └── res │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ ├── normal-mapping-and-cube-texture-frag.frag │ │ ├── normal-mapping-and-cube-texture-vert.vert │ │ └── normal-mapping-and-cube-texture.cpp ├── openvr │ ├── CMakeLists.txt │ ├── include │ │ ├── async_cache.h │ │ ├── thread_pool.h │ │ └── vr.h │ └── src │ │ ├── openvr-frag.frag │ │ ├── openvr-vert.vert │ │ ├── openvr.cpp │ │ └── vr.cpp └── teapot │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.gradle │ ├── include │ └── teapot.h │ └── src │ ├── main │ ├── AndroidManifest.xml │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── teapot-frag.frag │ ├── teapot-vert.vert │ └── teapot.cpp ├── settings.gradle ├── spirv-reflection-test ├── CMakeLists.txt └── src │ ├── input_test.cpp │ ├── input_test1.vert │ ├── push_constant_test.cpp │ ├── push_constant_test1.comp │ ├── specialization_constant_test.cpp │ ├── specialization_constant_test1.comp │ ├── subpass_test.cpp │ ├── subpass_test1.frag │ ├── uniform_buffer_test.cpp │ └── uniform_buffer_test1.comp ├── spirv-reflection ├── CMakeLists.txt ├── include │ └── reflection │ │ ├── analyzer.h │ │ ├── internal │ │ ├── argument_parser.h │ │ ├── includes.h │ │ └── intermediate_types.h │ │ └── types.h └── src │ └── analyzer.cpp ├── textures ├── heightmap │ └── height.png ├── normal-mapping │ ├── normal_map.png │ └── source.txt ├── png │ └── PNG_transparency_demonstration_1.png └── storforsen4 │ ├── negx.jpg │ ├── negy.jpg │ ├── negz.jpg │ ├── posx.jpg │ ├── posy.jpg │ ├── posz.jpg │ ├── readme.txt │ ├── storforsen4.ktx │ └── storforsen_etc2_rgb.ktx ├── tools └── obj2gl.cpp ├── types-test ├── CMakeLists.txt └── src │ ├── serialize_type_test.cpp │ ├── storage_type_test.cpp │ └── transform_type_test.cpp ├── types ├── CMakeLists.txt ├── include │ └── type │ │ ├── internal.h │ │ ├── memory.h │ │ ├── revision.h │ │ ├── serialize.h │ │ ├── storage.h │ │ ├── supplier.h │ │ ├── transform.h │ │ └── types.h └── src │ ├── memory.cpp │ └── serialize.cpp ├── vcc-image ├── CMakeLists.txt ├── include │ └── vcc │ │ ├── image_loader.h │ │ └── internal │ │ └── loader.h └── src │ ├── android_loader.cpp │ ├── gli_loader.cpp │ ├── image.cpp │ └── png_loader.cpp ├── vcc-test ├── CMakeLists.txt └── src │ ├── compute_shader_integration_test.cpp │ └── integration-test-1.comp └── vcc ├── CMakeLists.txt ├── include └── vcc │ ├── android_asset_istream.h │ ├── buffer.h │ ├── buffer_view.h │ ├── command.h │ ├── command_buffer.h │ ├── command_pool.h │ ├── debug.h │ ├── descriptor_pool.h │ ├── descriptor_set.h │ ├── descriptor_set_layout.h │ ├── device.h │ ├── enumerate.h │ ├── event.h │ ├── fence.h │ ├── framebuffer.h │ ├── image.h │ ├── image_view.h │ ├── input_buffer.h │ ├── instance.h │ ├── internal │ ├── hook.h │ └── raii.h │ ├── memory.h │ ├── physical_device.h │ ├── pipeline.h │ ├── pipeline_cache.h │ ├── pipeline_layout.h │ ├── query_pool.h │ ├── queue.h │ ├── render_pass.h │ ├── sampler.h │ ├── semaphore.h │ ├── shader_module.h │ ├── surface.h │ ├── swapchain.h │ ├── util.h │ └── window.h └── src ├── android_asset_istream.cpp ├── buffer.cpp ├── buffer_view.cpp ├── command.cpp ├── command_buffer.cpp ├── command_pool.cpp ├── debug.cpp ├── descriptor_pool.cpp ├── descriptor_set.cpp ├── descriptor_set_layout.cpp ├── device.cpp ├── enumerate.cpp ├── event.cpp ├── fence.cpp ├── framebuffer.cpp ├── image.cpp ├── image_view.cpp ├── input_buffer.cpp ├── instance.cpp ├── main.cpp ├── memory.cpp ├── physical_device.cpp ├── pipeline.cpp ├── pipeline_cache.cpp ├── pipeline_layout.cpp ├── queue.cpp ├── render_pass.cpp ├── sampler.cpp ├── semaphore.cpp ├── shader_module.cpp ├── surface.cpp ├── swapchain.cpp ├── util.cpp └── window.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *-build/ 2 | *-download/ 3 | *-src/ 4 | openvr/* 5 | sample/*/textures/ 6 | 7 | vcc/include/vcc/export.h 8 | 9 | # TODO(gardell): Generated by freeglut, should not be here. 10 | config.h 11 | freeglut.pc 12 | freeglut.rc 13 | 14 | *.spv 15 | 16 | cpp-frp/libcpp-frp.a 17 | test/frp-test 18 | 19 | test-coverage.info 20 | test-coverage/ 21 | 22 | ## Android 23 | 24 | *.iml 25 | .gradle 26 | /local.properties 27 | /.idea/workspace.xml 28 | /.idea/libraries 29 | .DS_Store 30 | /build 31 | /captures 32 | .externalNativeBuild 33 | 34 | ## Cmake 35 | CMakeCache.txt 36 | CMakeFiles 37 | CMakeScripts 38 | Makefile 39 | cmake_install.cmake 40 | install_manifest.txt 41 | CTestTestfile.cmake 42 | 43 | Testing/ 44 | Win32/ 45 | 46 | ## Visual Studio 47 | 48 | *.sln 49 | *.vcxproj* 50 | 51 | ## Ignore Visual Studio temporary files, build results, and 52 | ## files generated by popular Visual Studio add-ons. 53 | 54 | # User-specific files 55 | *.suo 56 | *.user 57 | *.userosscache 58 | *.sln.docstates 59 | 60 | # Build results 61 | [Dd]ebug/ 62 | [Rr]elease/ 63 | RelWithDebInfo/ 64 | 65 | # Visual Studio 2015 cache/options directory 66 | .vs/ 67 | 68 | # Visual C++ cache files 69 | ipch/ 70 | *.aps 71 | *.ncb 72 | *.opendb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | *.VC.db 77 | *.VC.VC.opendb 78 | 79 | # Visual Studio profiler 80 | *.psess 81 | *.vsp 82 | *.vspx 83 | *.sap 84 | 85 | # Visual Studio cache files 86 | # files ending in .cache can be ignored 87 | *.[Cc]ache 88 | # but keep track of directories ending in .cache 89 | !*.[Cc]ache/ 90 | 91 | # Backup & report files from converting an old project file 92 | # to a newer Visual Studio version. Backup files are not needed, 93 | # because we have git ;-) 94 | _UpgradeReport_Files/ 95 | Backup*/ 96 | UpgradeLog*.XML 97 | UpgradeLog*.htm 98 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CMakeLists.txt.freeglut.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(freeglut-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(freeglut 19 | GIT_REPOSITORY https://github.com/dcnieho/FreeGLUT.git 20 | GIT_TAG git_master 21 | SOURCE_DIR "${FREEGLUT_SRC_DIR}" 22 | BINARY_DIR "${CMAKE_BINARY_DIR}/freeglut-build" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.gli.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(gli-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(gli 19 | GIT_REPOSITORY https://github.com/g-truc/gli.git 20 | GIT_TAG master 21 | SOURCE_DIR "${GLI_SRC_DIR}" 22 | BINARY_DIR "" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.glm.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(glm-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(glm 19 | GIT_REPOSITORY https://github.com/g-truc/glm.git 20 | GIT_TAG master 21 | SOURCE_DIR "${GLM_SRC_DIR}" 22 | BINARY_DIR "" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.glslang.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(glslang-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(glslang 19 | GIT_REPOSITORY https://github.com/KhronosGroup/glslang.git 20 | GIT_TAG master 21 | SOURCE_DIR "${CMAKE_BINARY_DIR}/glslang-src" 22 | BINARY_DIR "${CMAKE_BINARY_DIR}/glslang-build" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.googletest.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(googletest-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(googletest 19 | GIT_REPOSITORY https://github.com/google/googletest.git 20 | GIT_TAG master 21 | SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" 22 | BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.openvr.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(openvr-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(openvr 19 | GIT_REPOSITORY https://github.com/ValveSoftware/openvr.git 20 | GIT_TAG master 21 | SOURCE_DIR "${OPENVR_SOURCE_DIR}" 22 | BINARY_DIR "" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.png.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(png-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(png 19 | GIT_REPOSITORY https://github.com/glennrp/libpng.git 20 | GIT_TAG libpng16 21 | SOURCE_DIR "${PNG_SRC_DIR}" 22 | BINARY_DIR "${PNG_BUILD_DIR}" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.spirv-headers.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(spirv-headers-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(spirv-headers 19 | GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Headers.git 20 | GIT_TAG master 21 | SOURCE_DIR "${SPIRV-Headers_SOURCE_DIR}" 22 | BINARY_DIR "${CMAKE_BINARY_DIR}/spirv-headers-build" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.spirv-tools.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(spirv-tools-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(spirv-tools 19 | GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Tools.git 20 | GIT_TAG master 21 | SOURCE_DIR "${SPIRV_TOOLS_SRC}" 22 | BINARY_DIR "${CMAKE_BINARY_DIR}/spirv-tools-build" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CMakeLists.txt.zlib.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | cmake_minimum_required(VERSION 2.8.2) 14 | 15 | project(zlib-download NONE) 16 | 17 | include(ExternalProject) 18 | ExternalProject_Add(zlib 19 | GIT_REPOSITORY https://github.com/madler/zlib.git 20 | GIT_TAG master 21 | SOURCE_DIR "${ZLIB_SRC_DIR}" 22 | BINARY_DIR "${CMAKE_BINARY_DIR}/zlib-build" 23 | CONFIGURE_COMMAND "" 24 | BUILD_COMMAND "" 25 | INSTALL_COMMAND "" 26 | TEST_COMMAND "" 27 | ) 28 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at the end). 2 | 3 | ### Before you contribute 4 | Before we can use your code, you must sign the 5 | [Google Individual Contributor License Agreement] 6 | (https://cla.developers.google.com/about/google-individual) 7 | (CLA), which you can do online. The CLA is necessary mainly because you own the 8 | copyright to your changes, even after your contribution becomes part of our 9 | codebase, so we need your permission to use and distribute your code. We also 10 | need to be sure of various other things—for instance that you'll tell us if you 11 | know that your code infringes on other people's patents. You don't have to sign 12 | the CLA until after you've submitted your code for review and a member has 13 | approved it, but you must do it before we can put your code into our codebase. 14 | Before you start working on a larger contribution, you should get in touch with 15 | us first through the issue tracker with your idea so that we can help out and 16 | possibly guide you. Coordinating up front makes it much easier to avoid 17 | frustration later on. 18 | 19 | ### Code reviews 20 | All submissions, including submissions by project members, require review. We 21 | use Github pull requests for this purpose. 22 | 23 | ### The small print 24 | Contributions made by corporations are covered by a different agreement than 25 | the one above, the 26 | [Software Grant and Corporate Contributor License Agreement] 27 | (https://cla.developers.google.com/about/google-corporate). 28 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | } 16 | } 17 | 18 | task clean(type: Delete) { 19 | delete rootProject.buildDir 20 | } 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/cube/.gitignore: -------------------------------------------------------------------------------- 1 | ## Android 2 | 3 | *.iml 4 | .gradle 5 | /local.properties 6 | /.idea/workspace.xml 7 | /.idea/libraries 8 | .DS_Store 9 | build 10 | /captures 11 | .externalNativeBuild 12 | src/main/res/drawable-nodpi/ 13 | src/main/assets/ 14 | -------------------------------------------------------------------------------- /sample/cube/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(../../types/include) 15 | include_directories(../../vcc/include) 16 | include_directories(${CMAKE_BINARY_DIR}/vcc/include) 17 | include_directories(../../vcc-image/include) 18 | include_directories(${GLM_SRC_DIR}) 19 | if(NOT VULKAN_SDK_DIR STREQUAL "") 20 | include_directories(${VULKAN_SDK_DIR}/include) 21 | link_directories(${VULKAN_SDK_DIR}/bin) 22 | endif() 23 | 24 | set(SAMPLE_CUBE_SRCS 25 | "src/cube.cpp" 26 | ) 27 | 28 | set(SAMPLE_CUBE_SHADER_SRCS 29 | "src/cube-frag.frag" 30 | "src/cube-vert.vert" 31 | ) 32 | 33 | if(DEFINED ANDROID_NDK) 34 | include_directories(${ANDROID_NDK}/sources/android/native_app_glue/) 35 | 36 | add_library(cube SHARED ${SAMPLE_CUBE_SRCS} 37 | ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) 38 | 39 | find_library(log-lib log) 40 | find_library(android-lib android) 41 | find_library(vulkan-lib vulkan) 42 | find_library(jnigraphics-lib jnigraphics) 43 | target_link_libraries(cube ${log-lib} ${android-lib} ${vulkan-lib} ${jnigraphics-lib}) 44 | else() 45 | add_executable(cube ${SAMPLE_CUBE_SRCS}) 46 | endif() 47 | 48 | target_link_libraries(cube vcc vcc-image) 49 | 50 | if(NOT DEFINED ANDROID_NDK) 51 | foreach(FILE ${SAMPLE_CUBE_SHADER_SRCS}) 52 | get_filename_component(FILEWE ${FILE} NAME_WE) 53 | set(FILE_OUTPUT ${FILEWE}.spv) 54 | add_custom_command(TARGET cube POST_BUILD DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 55 | COMMAND glslangValidator 56 | ARGS -V -o ${CMAKE_CURRENT_BINARY_DIR}/${FILE_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 57 | WORKING_DIRECTORY .) 58 | endforeach() 59 | 60 | add_custom_command(TARGET cube POST_BUILD 61 | COMMAND ${CMAKE_COMMAND} -E copy_directory 62 | ${CMAKE_SOURCE_DIR}/textures ${CMAKE_CURRENT_BINARY_DIR}/textures) 63 | add_custom_command(TARGET cube POST_BUILD 64 | COMMAND ${CMAKE_COMMAND} -E copy $ $/) 65 | add_custom_command(TARGET cube POST_BUILD 66 | COMMAND ${CMAKE_COMMAND} -E copy $ $/) 67 | endif() 68 | -------------------------------------------------------------------------------- /sample/cube/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "vulkan.library.samples.cube" 8 | minSdkVersion 24 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | externalNativeBuild { 13 | cmake { 14 | cppFlags "-std=c++11 -frtti -fexceptions" 15 | targets "cube" 16 | } 17 | } 18 | ndk { 19 | // TODO(gardell): Build for all architectures 20 | //abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' 21 | abiFilters 'armeabi-v7a' 22 | } 23 | } 24 | buildTypes {} 25 | externalNativeBuild { 26 | cmake { 27 | path "../../CMakeLists.txt" 28 | } 29 | } 30 | } 31 | 32 | task copyPngTexture(type: Copy) { 33 | from '../../textures/png/PNG_transparency_demonstration_1.png' 34 | rename { String fileName -> 35 | fileName.toLowerCase() 36 | } 37 | into "src/main/res/drawable-nodpi/" 38 | } 39 | 40 | project.afterEvaluate { 41 | preBuild.dependsOn copyPngTexture 42 | } 43 | 44 | dependencies {} 45 | 46 | -------------------------------------------------------------------------------- /sample/cube/gen/vulkan/library/sample/cube/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package vulkan.library.sample.cube; 4 | 5 | /* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ 6 | public final class BuildConfig { 7 | public final static boolean DEBUG = Boolean.parseBoolean(null); 8 | } -------------------------------------------------------------------------------- /sample/cube/gen/vulkan/library/sample/cube/Manifest.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package vulkan.library.sample.cube; 4 | 5 | /* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ 6 | public final class Manifest { 7 | } -------------------------------------------------------------------------------- /sample/cube/gen/vulkan/library/sample/cube/R.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package vulkan.library.sample.cube; 4 | 5 | /* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ 6 | public final class R { 7 | } -------------------------------------------------------------------------------- /sample/cube/src/cube-frag.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | 20 | layout (binding = 1) uniform sampler2D tex; 21 | 22 | layout (location = 0) in vec2 texcoord; 23 | 24 | layout (location = 0) out vec4 uFragColor; 25 | 26 | void main() { 27 | uFragColor = texture(tex, texcoord); 28 | } 29 | -------------------------------------------------------------------------------- /sample/cube/src/cube-vert.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | layout(std140, binding = 0) uniform buf { 20 | mat4 modelview_projection_matrix; 21 | } ubuf; 22 | 23 | layout (location = 0) in vec3 vertex; 24 | layout (location = 1) in vec2 in_texcoord; 25 | 26 | layout (location = 0) out vec2 texcoord; 27 | 28 | out gl_PerVertex { 29 | vec4 gl_Position; 30 | }; 31 | 32 | void main() { 33 | texcoord = in_texcoord; 34 | gl_Position = ubuf.modelview_projection_matrix * vec4(vertex, 1.0); 35 | 36 | // GL->VK conventions 37 | gl_Position.y = -gl_Position.y; 38 | gl_Position.z = gl_Position.z / 2.0; 39 | } 40 | -------------------------------------------------------------------------------- /sample/cube/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 18 | 19 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sample/cube/src/main/res/drawable-nodpi/png_transparency_demonstration_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/cube/src/main/res/drawable-nodpi/png_transparency_demonstration_1.png -------------------------------------------------------------------------------- /sample/cube/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/cube/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/cube/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/cube/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/cube/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/cube/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/cube/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/cube/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/cube/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/cube/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/cube/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/cube/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/cube/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Cube Sample 3 | 4 | -------------------------------------------------------------------------------- /sample/cube/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/heightmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(../../types/include) 15 | include_directories(../../vcc/include) 16 | include_directories(${CMAKE_BINARY_DIR}/vcc/include) 17 | include_directories(../../vcc-image/include) 18 | include_directories(${CPP_FRP_SRC_DIR}/cpp-frp/include) 19 | include_directories(${GLM_SRC_DIR}) 20 | if(NOT VULKAN_SDK_DIR STREQUAL "") 21 | include_directories(${VULKAN_SDK_DIR}/include) 22 | link_directories(${VULKAN_SDK_DIR}/bin) 23 | endif() 24 | 25 | set(SAMPLE_HEIGHTMAP_SRCS 26 | "src/heightmap.cpp" 27 | ) 28 | 29 | set(SAMPLE_HEIGHTMAP_SHADER_SRCS 30 | "src/heightmap-frag.frag" 31 | "src/heightmap-tesc.tesc" 32 | "src/heightmap-tese.tese" 33 | "src/heightmap-vert.vert" 34 | ) 35 | 36 | if(DEFINED ANDROID_NDK) 37 | include_directories(${ANDROID_NDK}/sources/android/native_app_glue/) 38 | 39 | add_library(heightmap SHARED ${SAMPLE_HEIGHTMAP_SRCS} 40 | ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) 41 | 42 | find_library(log-lib log) 43 | find_library(android-lib android) 44 | find_library(vulkan-lib vulkan) 45 | find_library(jnigraphics-lib jnigraphics) 46 | target_link_libraries(heightmap ${log-lib} ${android-lib} ${vulkan-lib} ${jnigraphics-lib}) 47 | else() 48 | add_executable(heightmap ${SAMPLE_HEIGHTMAP_SRCS}) 49 | endif() 50 | 51 | target_link_libraries(heightmap vcc vcc-image) 52 | 53 | if(NOT DEFINED ANDROID_NDK) 54 | foreach(FILE ${SAMPLE_HEIGHTMAP_SHADER_SRCS}) 55 | get_filename_component(FILEWE ${FILE} NAME_WE) 56 | set(FILE_OUTPUT ${FILEWE}.spv) 57 | add_custom_command(TARGET heightmap POST_BUILD DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 58 | COMMAND glslangValidator 59 | ARGS -V -o ${CMAKE_CURRENT_BINARY_DIR}/${FILE_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 60 | WORKING_DIRECTORY .) 61 | endforeach() 62 | 63 | add_custom_command(TARGET heightmap POST_BUILD 64 | COMMAND ${CMAKE_COMMAND} -E copy_directory 65 | ${CMAKE_SOURCE_DIR}/textures ${CMAKE_CURRENT_BINARY_DIR}/textures) 66 | add_custom_command(TARGET heightmap POST_BUILD 67 | COMMAND ${CMAKE_COMMAND} -E copy $ $/) 68 | add_custom_command(TARGET heightmap POST_BUILD 69 | COMMAND ${CMAKE_COMMAND} -E copy $ $/) 70 | endif() 71 | -------------------------------------------------------------------------------- /sample/heightmap/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "vulkan.library.samples.heightmap" 8 | minSdkVersion 24 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | externalNativeBuild { 13 | cmake { 14 | cppFlags "-std=c++11 -frtti -fexceptions" 15 | targets "heightmap" 16 | } 17 | } 18 | ndk { 19 | // TODO(gardell): Build for all architectures 20 | //abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' 21 | abiFilters 'armeabi-v7a' 22 | } 23 | } 24 | buildTypes {} 25 | externalNativeBuild { 26 | cmake { 27 | path "../../CMakeLists.txt" 28 | } 29 | } 30 | } 31 | 32 | task copyPngTexture(type: Copy) { 33 | from '../../textures/png/PNG_transparency_demonstration_1.png' 34 | rename { String fileName -> 35 | fileName.toLowerCase() 36 | } 37 | into "src/main/res/drawable-nodpi/" 38 | } 39 | 40 | task copyHeightmapTexture(type: Copy) { 41 | from '../../textures/heightmap/height.png' 42 | into "src/main/res/drawable-nodpi/" 43 | } 44 | 45 | project.afterEvaluate { 46 | preBuild.dependsOn copyPngTexture 47 | preBuild.dependsOn copyHeightmapTexture 48 | } 49 | 50 | dependencies {} 51 | 52 | -------------------------------------------------------------------------------- /sample/heightmap/src/heightmap-frag.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | 20 | layout (binding = 1) uniform sampler2D tex; 21 | 22 | layout (location = 0) in vec2 texcoord; 23 | layout (location = 1) in float ec_z; 24 | 25 | layout (location = 0) out vec4 uFragColor; 26 | 27 | const vec4 clear_color = vec4(0.2, 0.2, 0.2, 0.2); 28 | 29 | void main() { 30 | uFragColor = mix(texture(tex, texcoord), clear_color, clamp(ec_z / 64, 0.0, 1.0)); 31 | } 32 | -------------------------------------------------------------------------------- /sample/heightmap/src/heightmap-tesc.tesc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | 20 | layout (vertices = 1) out; 21 | 22 | layout (location = 0) in vec2 tesc_vertex[]; 23 | 24 | layout (location = 0) out vec2 tese_vertex[]; 25 | 26 | const int subdivisions = 8; 27 | 28 | void main() { 29 | tese_vertex[gl_InvocationID] = tesc_vertex[gl_InvocationID]; 30 | if (gl_InvocationID == 0) { 31 | for (int i = 0; i < 4; ++i) { 32 | gl_TessLevelOuter[i] = subdivisions; 33 | } 34 | for (int i = 0; i < 2; ++i) { 35 | gl_TessLevelInner[i] = subdivisions; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample/heightmap/src/heightmap-tese.tese: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | 20 | layout(std140, binding = 0) uniform buf { 21 | mat4 projection_matrix; 22 | mat4 modelview_matrix; 23 | } ubuf; 24 | 25 | layout (binding = 2) uniform sampler2D height; 26 | 27 | layout(quads, equal_spacing, cw) in; 28 | 29 | layout (location = 0) in vec2 tese_vertex[]; 30 | 31 | layout (location = 0) out vec2 texcoord; 32 | layout (location = 1) out float ec_z; 33 | 34 | out gl_PerVertex { 35 | vec4 gl_Position; 36 | }; 37 | 38 | const float height_scaling = 1.0 / 128; 39 | const float y_scaling = 32; 40 | 41 | void main() { 42 | vec2 vertex = gl_TessCoord.xy + tese_vertex[0]; 43 | texcoord = gl_TessCoord.xy; 44 | 45 | float y = y_scaling * texture(height, height_scaling * vertex).x; 46 | vec4 ec_vertex = ubuf.modelview_matrix * vec4(vertex.x, y, vertex.y, 1.0); 47 | ec_z = length(ec_vertex); 48 | gl_Position = ubuf.projection_matrix * ec_vertex; 49 | } 50 | -------------------------------------------------------------------------------- /sample/heightmap/src/heightmap-vert.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | 20 | layout (location = 0) in vec2 vert_vertex; 21 | 22 | layout (location = 0) out vec2 tesc_vertex; 23 | 24 | void main() { 25 | tesc_vertex = vert_vertex; 26 | } 27 | -------------------------------------------------------------------------------- /sample/heightmap/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 18 | 19 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/drawable-nodpi/png_transparency_demonstration_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/heightmap/src/main/res/drawable-nodpi/png_transparency_demonstration_1.png -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/heightmap/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/heightmap/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/heightmap/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/heightmap/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/heightmap/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Heightmap Sample 3 | 4 | -------------------------------------------------------------------------------- /sample/heightmap/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/lighting/.gitignore: -------------------------------------------------------------------------------- 1 | ## Android 2 | 3 | *.iml 4 | .gradle 5 | /local.properties 6 | /.idea/workspace.xml 7 | /.idea/libraries 8 | .DS_Store 9 | build 10 | /captures 11 | .externalNativeBuild 12 | src/main/res/drawable-nodpi/ 13 | src/main/assets/ 14 | -------------------------------------------------------------------------------- /sample/lighting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(include) 15 | include_directories(../../types/include) 16 | include_directories(../../vcc/include) 17 | include_directories(${CMAKE_BINARY_DIR}/vcc/include) 18 | include_directories(${GLM_SRC_DIR}) 19 | if(NOT VULKAN_SDK_DIR STREQUAL "") 20 | include_directories(${VULKAN_SDK_DIR}/include) 21 | link_directories(${VULKAN_SDK_DIR}/bin) 22 | endif() 23 | 24 | set(SAMPLE_LIGHTING_INCLUDES 25 | "include/teapot.h" 26 | ) 27 | 28 | set(SAMPLE_LIGHTING_SRCS 29 | "src/lighting.cpp" 30 | ) 31 | 32 | set(SAMPLE_LIGHTING_SHADER_SRCS 33 | "src/lighting-frag.frag" 34 | "src/lighting-vert.vert" 35 | ) 36 | 37 | if(DEFINED ANDROID_NDK) 38 | include_directories(${ANDROID_NDK}/sources/android/native_app_glue/) 39 | 40 | add_library(lighting SHARED ${SAMPLE_LIGHTING_INCLUDES} ${SAMPLE_LIGHTING_SRCS} 41 | ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) 42 | 43 | find_library(log-lib log) 44 | find_library(android-lib android) 45 | find_library(vulkan-lib vulkan) 46 | find_library(jnigraphics-lib jnigraphics) 47 | target_link_libraries(lighting ${log-lib} ${android-lib} ${vulkan-lib} ${jnigraphics-lib}) 48 | else() 49 | add_executable(lighting ${SAMPLE_LIGHTING_INCLUDES} ${SAMPLE_LIGHTING_SRCS}) 50 | endif() 51 | 52 | target_link_libraries(lighting vcc) 53 | 54 | if(NOT DEFINED ANDROID_NDK) 55 | foreach(FILE ${SAMPLE_LIGHTING_SHADER_SRCS}) 56 | get_filename_component(FILEWE ${FILE} NAME_WE) 57 | set(FILE_OUTPUT ${FILEWE}.spv) 58 | add_custom_command(TARGET lighting POST_BUILD DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 59 | COMMAND glslangValidator 60 | ARGS -V -o ${CMAKE_CURRENT_BINARY_DIR}/${FILE_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 61 | WORKING_DIRECTORY .) 62 | endforeach() 63 | 64 | add_custom_command(TARGET lighting POST_BUILD 65 | COMMAND ${CMAKE_COMMAND} -E copy_directory 66 | ${CMAKE_SOURCE_DIR}/textures $/textures) 67 | endif() 68 | -------------------------------------------------------------------------------- /sample/lighting/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "vulkan.library.samples.lighting" 8 | minSdkVersion 24 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | externalNativeBuild { 13 | cmake { 14 | cppFlags "-std=c++11 -frtti -fexceptions" 15 | targets "lighting" 16 | } 17 | } 18 | ndk { 19 | // TODO(gardell): Build for all architectures 20 | //abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' 21 | abiFilters 'armeabi-v7a' 22 | } 23 | } 24 | buildTypes {} 25 | externalNativeBuild { 26 | cmake { 27 | path "../../CMakeLists.txt" 28 | } 29 | } 30 | } 31 | 32 | dependencies {} 33 | 34 | -------------------------------------------------------------------------------- /sample/lighting/src/lighting-vert.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | layout(std140, binding = 0) uniform buf { 20 | mat4 projection_matrix; 21 | mat4 modelview_matrix; 22 | mat3 normal_matrix; 23 | } ubuf; 24 | 25 | layout (location = 0) in vec3 vertex; 26 | layout (location = 1) in vec3 in_normal; 27 | 28 | layout (location = 0) out vec3 normal; 29 | layout (location = 1) out vec3 eye_position; 30 | 31 | out gl_PerVertex { 32 | vec4 gl_Position; 33 | }; 34 | 35 | void main() { 36 | vec4 position = ubuf.modelview_matrix * vec4(vertex, 1.0); 37 | eye_position = vec3(position); 38 | gl_Position = ubuf.projection_matrix * position; 39 | normal = ubuf.normal_matrix * in_normal; 40 | 41 | // GL->VK conventions 42 | gl_Position.y = -gl_Position.y; 43 | gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0; 44 | } 45 | -------------------------------------------------------------------------------- /sample/lighting/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 18 | 19 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sample/lighting/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/lighting/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/lighting/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/lighting/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/lighting/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/lighting/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/lighting/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/lighting/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/lighting/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/lighting/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/lighting/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/lighting/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/lighting/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Lighting Sample 3 | 4 | -------------------------------------------------------------------------------- /sample/lighting/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/.gitignore: -------------------------------------------------------------------------------- 1 | ## Android 2 | 3 | *.iml 4 | .gradle 5 | /local.properties 6 | /.idea/workspace.xml 7 | /.idea/libraries 8 | .DS_Store 9 | build 10 | /captures 11 | .externalNativeBuild 12 | src/main/res/drawable-nodpi/ 13 | src/main/assets/ 14 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "vulkan.library.samples.normal_mapping_and_cube_texture" 8 | minSdkVersion 24 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | externalNativeBuild { 13 | cmake { 14 | cppFlags "-std=c++11 -frtti -fexceptions" 15 | targets "normal-mapping-and-cube-texture" 16 | } 17 | } 18 | ndk { 19 | // TODO(gardell): Build for all architectures 20 | //abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' 21 | abiFilters 'armeabi-v7a' 22 | } 23 | } 24 | buildTypes {} 25 | externalNativeBuild { 26 | cmake { 27 | path "../../CMakeLists.txt" 28 | } 29 | } 30 | } 31 | 32 | task copyKtxTexture(type: Copy) { 33 | from '../../textures/storforsen4/storforsen_etc2_rgb.ktx' 34 | into "src/main/assets/" 35 | } 36 | 37 | task copyPngTexture(type: Copy) { 38 | from '../../textures/normal-mapping/normal_map.png' 39 | into "src/main/res/drawable-nodpi/" 40 | } 41 | 42 | project.afterEvaluate { 43 | preBuild.dependsOn copyKtxTexture 44 | preBuild.dependsOn copyPngTexture 45 | } 46 | 47 | dependencies {} 48 | 49 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 18 | 19 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/normal-mapping-and-cube-texture/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/normal-mapping-and-cube-texture/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/normal-mapping-and-cube-texture/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/normal-mapping-and-cube-texture/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/normal-mapping-and-cube-texture/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Normal mapping and cube texturing Sample 3 | 4 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/normal-mapping-and-cube-texture-frag.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | layout (binding = 1) uniform samplerCube tex; 20 | layout (binding = 2) uniform sampler2D normal_tex; 21 | 22 | layout (location = 0) in vec2 texcoord; 23 | layout (location = 1) in mat3 normal; 24 | layout (location = 4) in vec3 eye_position; 25 | 26 | layout (location = 0) out vec4 uFragColor; 27 | 28 | vec3 reflection_map(in vec3 incident, in vec3 normal) { 29 | return reflect(incident, normal); 30 | } 31 | 32 | void main() { 33 | vec3 incident = normalize(eye_position); 34 | vec3 normal_map = vec3(texture(normal_tex, texcoord)) * 2.0 - 1.0; 35 | uFragColor = texture(tex, reflection_map(incident, normal_map * normal)); 36 | } 37 | -------------------------------------------------------------------------------- /sample/normal-mapping-and-cube-texture/src/normal-mapping-and-cube-texture-vert.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | layout(std140, binding = 0) uniform buf { 20 | mat4 projection_matrix; 21 | mat4 modelview_matrix; 22 | mat3 normal_matrix; 23 | } ubuf; 24 | 25 | layout (location = 0) in vec3 vertex; 26 | layout (location = 1) in vec2 in_texcoord; 27 | layout (location = 2) in mat3 in_normal; 28 | 29 | layout (location = 0) out vec2 texcoord; 30 | layout (location = 1) out mat3 normal; 31 | layout (location = 4) out vec3 eye_position; 32 | 33 | out gl_PerVertex { 34 | vec4 gl_Position; 35 | }; 36 | 37 | void main() { 38 | texcoord = in_texcoord; 39 | vec4 position = ubuf.modelview_matrix * vec4(vertex, 1.0); 40 | eye_position = vec3(position); 41 | gl_Position = ubuf.projection_matrix * position; 42 | normal = ubuf.normal_matrix * in_normal; 43 | 44 | // GL->VK conventions 45 | gl_Position.y = -gl_Position.y; 46 | gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0; 47 | } 48 | -------------------------------------------------------------------------------- /sample/openvr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(include) 15 | include_directories(../../types/include) 16 | include_directories(../../vcc/include) 17 | include_directories(${CMAKE_BINARY_DIR}/vcc/include) 18 | include_directories(../../vcc-image/include) 19 | include_directories(${GLM_SRC_DIR}) 20 | include_directories(${OPENVR_SOURCE_DIR}/headers) 21 | if(NOT VULKAN_SDK_DIR STREQUAL "") 22 | include_directories(${VULKAN_SDK_DIR}/include) 23 | link_directories(${VULKAN_SDK_DIR}/bin) 24 | endif() 25 | 26 | set(SAMPLE_OPENVR_INCLUDES 27 | "include/async_cache.h" 28 | "include/thread_pool.h" 29 | "include/vr.h" 30 | ) 31 | 32 | set(SAMPLE_OPENVR_SRCS 33 | "src/openvr.cpp" 34 | "src/vr.cpp" 35 | ) 36 | 37 | set(SAMPLE_OPENVR_SHADER_SRCS 38 | "src/openvr-frag.frag" 39 | "src/openvr-vert.vert" 40 | ) 41 | 42 | if(UNIX) 43 | set(OPENVR_LIB_DIR ${OPENVR_SOURCE_DIR}/lib/linux64) 44 | set(OPENVR_LIBRARY_FILE ${OPENVR_SOURCE_DIR}/bin/linux64/libopenvr_api.so) 45 | elseif(WIN32) 46 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 47 | set(OPENVR_LIB_DIR ${OPENVR_SOURCE_DIR}/lib/win64) 48 | set(OPENVR_LIBRARY_FILE ${OPENVR_SOURCE_DIR}/bin/win64/openvr_api.dll) 49 | else() 50 | set(OPENVR_LIB_DIR ${OPENVR_SOURCE_DIR}/lib/win32) 51 | set(OPENVR_LIBRARY_FILE ${OPENVR_SOURCE_DIR}/bin/win32/openvr_api.dll) 52 | endif() 53 | endif() 54 | 55 | link_directories(${OPENVR_LIB_DIR}) 56 | 57 | add_executable(openvr ${SAMPLE_OPENVR_INCLUDES} ${SAMPLE_OPENVR_SRCS}) 58 | target_link_libraries(openvr vcc vcc-image openvr_api) 59 | 60 | foreach(FILE ${SAMPLE_OPENVR_SHADER_SRCS}) 61 | get_filename_component(FILEWE ${FILE} NAME_WE) 62 | set(FILE_OUTPUT ${FILEWE}.spv) 63 | add_custom_command(TARGET openvr POST_BUILD DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 64 | COMMAND glslangValidator 65 | ARGS -V -o ${CMAKE_CURRENT_BINARY_DIR}/${FILE_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 66 | WORKING_DIRECTORY .) 67 | endforeach() 68 | 69 | add_custom_command(TARGET openvr POST_BUILD 70 | COMMAND ${CMAKE_COMMAND} -E copy_directory 71 | ${CMAKE_SOURCE_DIR}/textures $/textures) 72 | add_custom_command(TARGET openvr POST_BUILD 73 | COMMAND ${CMAKE_COMMAND} -E copy 74 | ${OPENVR_LIBRARY_FILE} $/) 75 | 76 | -------------------------------------------------------------------------------- /sample/openvr/include/async_cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef _OPENVR_ASYNC_CACHE_H_ 17 | #define _OPENVR_ASYNC_CACHE_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | template 26 | struct async_cache_type { 27 | public: 28 | typedef std::function &&)> callback_type; 29 | typedef std::function loader_type; 30 | private: 31 | typedef std::vector callbacks_container_type; 32 | typedef std::unordered_map pending_map_type; 33 | typedef std::unordered_map> value_map_type; 34 | public: 35 | 36 | async_cache_type(ExecutorT &&executor, loader_type &&loader) 37 | : executor(std::forward(executor)), 38 | loader(std::forward(loader)) {} 39 | 40 | void put(const KeyT &key, callback_type &&callback) { 41 | { 42 | std::unique_lock lk(map_mutex); 43 | const auto value_it = values_map.find(key); 44 | if (value_it != values_map.end()) { 45 | try { 46 | callback(key, std::shared_ptr(value_it->second)); 47 | return; 48 | } 49 | catch (std::bad_weak_ptr &) { 50 | values_map.erase(value_it); 51 | } 52 | } 53 | auto &callbacks(pendings_map[key]); 54 | const bool empty(callbacks.empty()); 55 | callbacks.push_back(std::forward(callback)); 56 | if (!empty) { 57 | return; 58 | } 59 | } 60 | executor(std::bind([this, key]() { 61 | auto value(std::make_shared(loader(key))); 62 | std::vector callbacks; 63 | { 64 | std::unique_lock lk(map_mutex); 65 | values_map.emplace(key, value); 66 | callbacks = std::move(pendings_map.at(key)); 67 | } 68 | for (const auto &callback : callbacks) { 69 | callback(key, std::move(value)); 70 | } 71 | })); 72 | } 73 | 74 | private: 75 | ExecutorT executor; 76 | loader_type loader; 77 | value_map_type values_map; 78 | pending_map_type pendings_map; 79 | std::mutex map_mutex; 80 | }; 81 | 82 | #endif // _OPENVR_ASYNC_CACHE_H_ 83 | -------------------------------------------------------------------------------- /sample/openvr/src/openvr-frag.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | 20 | layout (binding = 1) uniform sampler2D tex; 21 | 22 | layout (location = 0) in vec2 texcoord; 23 | 24 | layout (location = 0) out vec4 uFragColor; 25 | 26 | void main() { 27 | uFragColor = texture(tex, texcoord); 28 | } 29 | -------------------------------------------------------------------------------- /sample/openvr/src/openvr-vert.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | layout(std140, binding = 0) uniform buf { 20 | mat4 modelview_projection_matrix[2]; 21 | } ubuf; 22 | 23 | layout (location = 0) in vec3 vertex; 24 | layout (location = 1) in vec2 in_texcoord; 25 | 26 | layout (location = 0) out vec2 texcoord; 27 | 28 | out gl_PerVertex { 29 | vec4 gl_Position; 30 | }; 31 | 32 | void main() { 33 | texcoord = in_texcoord; 34 | gl_Position = ubuf.modelview_projection_matrix[gl_InstanceIndex] 35 | * vec4(vertex, 1.0); 36 | } 37 | -------------------------------------------------------------------------------- /sample/teapot/.gitignore: -------------------------------------------------------------------------------- 1 | ## Android 2 | 3 | *.iml 4 | .gradle 5 | /local.properties 6 | /.idea/workspace.xml 7 | /.idea/libraries 8 | .DS_Store 9 | build 10 | /captures 11 | .externalNativeBuild 12 | src/main/res/drawable-nodpi/ 13 | src/main/assets/ 14 | -------------------------------------------------------------------------------- /sample/teapot/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(include) 15 | include_directories(../../types/include) 16 | include_directories(../../vcc/include) 17 | include_directories(${CMAKE_BINARY_DIR}/vcc/include) 18 | include_directories(../../vcc-image/include) 19 | include_directories(${GLM_SRC_DIR}) 20 | if(NOT VULKAN_SDK_DIR STREQUAL "") 21 | include_directories(${VULKAN_SDK_DIR}/include) 22 | link_directories(${VULKAN_SDK_DIR}/bin) 23 | endif() 24 | 25 | set(SAMPLE_TEAPOT_INCLUDES 26 | "include/teapot.h" 27 | ) 28 | 29 | set(SAMPLE_TEAPOT_SRCS 30 | "src/teapot.cpp" 31 | ) 32 | 33 | set(SAMPLE_TEAPOT_SHADER_SRCS 34 | "src/teapot-frag.frag" 35 | "src/teapot-vert.vert" 36 | ) 37 | 38 | if(DEFINED ANDROID_NDK) 39 | include_directories(${ANDROID_NDK}/sources/android/native_app_glue/) 40 | 41 | add_library(teapot SHARED ${SAMPLE_TEAPOT_INCLUDES} ${SAMPLE_TEAPOT_SRCS} 42 | ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) 43 | 44 | find_library(log-lib log) 45 | find_library(android-lib android) 46 | find_library(vulkan-lib vulkan) 47 | find_library(jnigraphics-lib jnigraphics) 48 | target_link_libraries(teapot ${log-lib} ${android-lib} ${vulkan-lib} ${jnigraphics-lib}) 49 | else() 50 | add_executable(teapot ${SAMPLE_TEAPOT_INCLUDES} ${SAMPLE_TEAPOT_SRCS}) 51 | endif() 52 | target_link_libraries(teapot vcc vcc-image) 53 | 54 | if(NOT DEFINED ANDROID_NDK) 55 | foreach(FILE ${SAMPLE_TEAPOT_SHADER_SRCS}) 56 | get_filename_component(FILEWE ${FILE} NAME_WE) 57 | set(FILE_OUTPUT ${FILEWE}.spv) 58 | add_custom_command(TARGET teapot POST_BUILD DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 59 | COMMAND glslangValidator 60 | ARGS -V -o ${CMAKE_CURRENT_BINARY_DIR}/${FILE_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 61 | WORKING_DIRECTORY .) 62 | endforeach() 63 | 64 | add_custom_command(TARGET teapot POST_BUILD 65 | COMMAND ${CMAKE_COMMAND} -E copy_directory 66 | ${CMAKE_SOURCE_DIR}/textures ${CMAKE_CURRENT_BINARY_DIR}/textures) 67 | add_custom_command(TARGET teapot POST_BUILD 68 | COMMAND ${CMAKE_COMMAND} -E copy $ $/) 69 | add_custom_command(TARGET teapot POST_BUILD 70 | COMMAND ${CMAKE_COMMAND} -E copy $ $/) 71 | endif() 72 | -------------------------------------------------------------------------------- /sample/teapot/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "vulkan.library.samples.teapot" 8 | minSdkVersion 24 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | externalNativeBuild { 13 | cmake { 14 | cppFlags "-std=c++11 -frtti -fexceptions" 15 | targets "teapot" 16 | } 17 | } 18 | ndk { 19 | // TODO(gardell): Build for all architectures 20 | //abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' 21 | abiFilters 'armeabi-v7a' 22 | } 23 | } 24 | buildTypes {} 25 | externalNativeBuild { 26 | cmake { 27 | path "../../CMakeLists.txt" 28 | } 29 | } 30 | } 31 | 32 | task copyKtxTexture(type: Copy) { 33 | from '../../textures/storforsen4/storforsen_etc2_rgb.ktx' 34 | into "src/main/assets/" 35 | } 36 | 37 | project.afterEvaluate { 38 | preBuild.dependsOn copyKtxTexture 39 | } 40 | 41 | dependencies {} 42 | 43 | -------------------------------------------------------------------------------- /sample/teapot/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 18 | 19 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sample/teapot/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/teapot/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/teapot/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/teapot/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/teapot/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/teapot/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/teapot/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/teapot/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/teapot/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/sample/teapot/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/teapot/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /sample/teapot/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/teapot/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Teapot Sample 3 | 4 | -------------------------------------------------------------------------------- /sample/teapot/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /sample/teapot/src/teapot-vert.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 400 17 | #extension GL_ARB_separate_shader_objects : enable 18 | #extension GL_ARB_shading_language_420pack : enable 19 | layout(std140, binding = 0) uniform buf { 20 | mat4 projection_matrix; 21 | } ubuf; 22 | 23 | layout (location = 0) in vec3 vertex; 24 | layout (location = 1) in vec2 in_texcoord; 25 | layout (location = 2) in vec3 in_normal; 26 | 27 | layout (location = 3) in mat4 modelview_matrix; 28 | layout (location = 7) in mat3 normal_matrix; 29 | 30 | layout (location = 0) out vec2 texcoord; 31 | layout (location = 1) out vec3 normal; 32 | layout (location = 2) out vec3 eye_position; 33 | layout (location = 3) flat out int color_index; 34 | 35 | out gl_PerVertex { 36 | vec4 gl_Position; 37 | }; 38 | 39 | void main() { 40 | texcoord = in_texcoord; 41 | vec4 position = modelview_matrix * vec4(vertex, 1.0); 42 | eye_position = vec3(position); 43 | gl_Position = ubuf.projection_matrix * position; 44 | // TODO(gardell): Make normal_matrix a mat3 when the alignment issues are resolved. 45 | normal = normal_matrix * in_normal; 46 | color_index = gl_InstanceIndex; 47 | 48 | // GL->VK conventions 49 | gl_Position.y = -gl_Position.y; 50 | gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0; 51 | } 52 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'sample:cube' 2 | include 'sample:heightmap' 3 | include 'sample:lighting' 4 | include 'sample:normal-mapping-and-cube-texture' 5 | include 'sample:teapot' 6 | -------------------------------------------------------------------------------- /spirv-reflection-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(../spirv-reflection/include) 15 | include_directories(${gtest_SOURCE_DIR}/include) 16 | include_directories(${SPIRV-Headers_SOURCE_DIR}/include/) 17 | include_directories(${SPIRV_TOOLS_SRC}/include/) 18 | 19 | set(SPIRV_REFLECTION_TEST_SRCS 20 | "src/subpass_test.cpp" 21 | "src/push_constant_test.cpp" 22 | "src/uniform_buffer_test.cpp" 23 | "src/specialization_constant_test.cpp" 24 | "src/input_test.cpp" 25 | ) 26 | 27 | set(SPIRV_REFLECTION_TEST_SHADER_SRCS 28 | "src/subpass_test1.frag" 29 | "src/push_constant_test1.comp" 30 | "src/uniform_buffer_test1.comp" 31 | "src/specialization_constant_test1.comp" 32 | "src/input_test1.vert" 33 | ) 34 | 35 | add_executable(spirv-reflection-test ${SPIRV_REFLECTION_TEST_SRCS}) 36 | target_link_libraries(spirv-reflection-test spirv-reflection SPIRV-Tools gtest gtest_main) 37 | 38 | set(SPIRV_REFLECTION_TEST_COMPILED_SHADER_BINARIES) 39 | foreach(FILE ${SPIRV_REFLECTION_TEST_SHADER_SRCS}) 40 | get_filename_component(FILEWE ${FILE} NAME_WE) 41 | set(FILE_OUTPUT ${FILEWE}.spv) 42 | add_custom_command(TARGET spirv-reflection-test POST_BUILD DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 43 | COMMAND glslangValidator 44 | ARGS -V -o ${CMAKE_CURRENT_BINARY_DIR}/${FILE_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 45 | WORKING_DIRECTORY .) 46 | list(APPEND SPIRV_REFLECTION_TEST_COMPILED_SHADER_BINARIES ${FILE_OUTPUT}) 47 | endforeach() 48 | 49 | add_test(spirv-reflection-tests spirv-reflection-test) 50 | 51 | -------------------------------------------------------------------------------- /spirv-reflection-test/src/input_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | const spirv::variable_type &find_variable_by_location(const spirv::module_type &module, 21 | spirv::identifier_type location) { 22 | for (const auto &variable : module.variables) { 23 | if (variable.second.location == location) { 24 | return variable.second; 25 | } 26 | } 27 | throw std::logic_error("Could not find variable by location"); 28 | } 29 | 30 | TEST(SpirvAnalyzer, Input1) { 31 | const spirv::module_type module(spirv::parse( 32 | std::ifstream("input_test1.spv", std::ios_base::binary))); 33 | ASSERT_EQ(module.variables.size(), 3); 34 | const spirv::variable_type &variable1(find_variable_by_location(module, 1)); 35 | ASSERT_EQ(variable1.storage_class, SpvStorageClassInput); 36 | ASSERT_EQ(variable1.name, "vertex"); 37 | ASSERT_EQ(variable1.binding, 0); 38 | ASSERT_EQ(variable1.location, 1); 39 | ASSERT_EQ(variable1.descriptor_set, 0); 40 | ASSERT_EQ(variable1.input_attachment_index, 0); 41 | ASSERT_EQ(variable1.constant_id, 0); 42 | 43 | const spirv::variable_type &variable2(find_variable_by_location(module, 2)); 44 | ASSERT_EQ(variable2.storage_class, SpvStorageClassInput); 45 | ASSERT_EQ(variable2.name, "model_view"); 46 | ASSERT_EQ(variable2.binding, 0); 47 | ASSERT_EQ(variable2.location, 2); 48 | ASSERT_EQ(variable2.descriptor_set, 0); 49 | ASSERT_EQ(variable2.input_attachment_index, 0); 50 | ASSERT_EQ(variable2.constant_id, 0); 51 | 52 | const spirv::variable_type &variable3(find_variable_by_location(module, 5)); 53 | ASSERT_EQ(variable3.storage_class, SpvStorageClassInput); 54 | ASSERT_EQ(variable3.name, "projection"); 55 | ASSERT_EQ(variable3.binding, 0); 56 | ASSERT_EQ(variable3.location, 5); 57 | ASSERT_EQ(variable3.descriptor_set, 0); 58 | ASSERT_EQ(variable3.input_attachment_index, 0); 59 | ASSERT_EQ(variable3.constant_id, 0); 60 | } 61 | -------------------------------------------------------------------------------- /spirv-reflection-test/src/input_test1.vert: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 450 17 | 18 | layout(location = 1) in vec3 vertex; 19 | layout(location = 2) in mat3 model_view; 20 | layout(location = 5) in mat3 projection; 21 | 22 | void main() {} -------------------------------------------------------------------------------- /spirv-reflection-test/src/push_constant_test1.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 450 17 | 18 | layout(push_constant) uniform block_name { 19 | int member1; 20 | float member2; 21 | vec3 member3; 22 | } instance_name; 23 | 24 | void main() {} 25 | -------------------------------------------------------------------------------- /spirv-reflection-test/src/specialization_constant_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | TEST(SpirvAnalyzer, SpecializationConstant1) { 21 | const spirv::module_type module(spirv::parse( 22 | std::ifstream("specialization_constant_test1.spv", std::ios_base::binary))); 23 | ASSERT_TRUE(module.variables.empty()); 24 | ASSERT_EQ(module.constant_types.size(), 1); 25 | const spirv::constant_type &constant(module.constant_types.begin()->second); 26 | ASSERT_EQ(constant.value.size(), 1); 27 | ASSERT_EQ(constant.value[0], 12); 28 | // TODO(gardell): compiler doesn't export name of specialization constants. 29 | //ASSERT_EQ(constant.name, "value"); 30 | ASSERT_TRUE(constant.specialization); 31 | ASSERT_EQ(constant.specialization_id, 1); 32 | 33 | const spirv::primitive_type &primitive(module.primitive_types.at(constant.type_id)); 34 | ASSERT_EQ(primitive.type, SpvOpTypeInt); 35 | ASSERT_EQ(primitive.components[0], 1); 36 | ASSERT_EQ(primitive.components[1], 1); 37 | ASSERT_EQ(primitive.bits, 32); 38 | ASSERT_EQ(primitive.array, false); 39 | ASSERT_EQ(primitive.signedness, true); 40 | ASSERT_EQ(primitive.count_id, 0); 41 | } 42 | -------------------------------------------------------------------------------- /spirv-reflection-test/src/specialization_constant_test1.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 450 17 | 18 | layout(constant_id = 1) const int value = 12; 19 | 20 | void main() {} 21 | -------------------------------------------------------------------------------- /spirv-reflection-test/src/subpass_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | TEST(SpirvAnalyzer, Subpass1) { 21 | const spirv::module_type module(spirv::parse( 22 | std::ifstream("subpass_test1.spv", std::ios_base::binary))); 23 | ASSERT_EQ(module.variables.size(), 1); 24 | const spirv::variable_type &variable(module.variables.begin()->second); 25 | ASSERT_EQ(variable.storage_class, SpvStorageClassUniformConstant); 26 | ASSERT_EQ(variable.name, "t"); 27 | ASSERT_EQ(variable.binding, 0); // subpass inputs do not have a binding 28 | ASSERT_EQ(variable.location, 0); // subpass inputs do not have a location 29 | ASSERT_EQ(variable.descriptor_set, 1); 30 | ASSERT_EQ(variable.input_attachment_index, 2); 31 | 32 | const spirv::image_type &image(module.images.at(variable.type_id)); 33 | ASSERT_EQ(image.dim, SpvDimSubpassData); 34 | ASSERT_FALSE(image.arrayed); 35 | ASSERT_FALSE(image.multisampled); 36 | const spirv::primitive_type &sampled(module.primitive_types.at(image.sampled_id)); 37 | ASSERT_EQ(sampled.type, SpvOpTypeFloat); 38 | ASSERT_EQ(sampled.components[0], 1); 39 | ASSERT_EQ(sampled.components[1], 1); 40 | ASSERT_EQ(sampled.bits, 32); 41 | ASSERT_FALSE(sampled.array); 42 | ASSERT_FALSE(sampled.signedness); 43 | ASSERT_EQ(sampled.count_id, 0); 44 | } 45 | -------------------------------------------------------------------------------- /spirv-reflection-test/src/subpass_test1.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 450 17 | 18 | layout(set = 1, input_attachment_index = 2) uniform subpassInput t; 19 | 20 | void main() {} 21 | -------------------------------------------------------------------------------- /spirv-reflection-test/src/uniform_buffer_test1.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 450 17 | 18 | layout(set = 1, binding = 2) uniform block_name { 19 | int member1; 20 | float member2; 21 | vec3 member3; 22 | } instance_name; 23 | 24 | void main() {} 25 | -------------------------------------------------------------------------------- /spirv-reflection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | include_directories(include) 14 | include_directories(../types/include) 15 | include_directories(${SPIRV-Headers_SOURCE_DIR}/include/) 16 | include_directories(${SPIRV_TOOLS_SRC}/include/) 17 | 18 | set(SPIRV_REFLECTION_INCLUDES 19 | "include/reflection/analyzer.h" 20 | "include/reflection/types.h" 21 | "include/reflection/internal/argument_parser.h" 22 | "include/reflection/internal/includes.h" 23 | "include/reflection/internal/intermediate_types.h" 24 | ) 25 | 26 | set(SPIRV_REFLECTION_SRCS 27 | "src/analyzer.cpp" 28 | ) 29 | 30 | add_library(spirv-reflection ${SPIRV_REFLECTION_INCLUDES} ${SPIRV_REFLECTION_SRCS}) 31 | 32 | -------------------------------------------------------------------------------- /spirv-reflection/include/reflection/analyzer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef SPIRV_ANALYZER_ANALYZER_H_ 17 | #define SPIRV_ANALYZER_ANALYZER_H_ 18 | 19 | #include 20 | 21 | namespace spirv { 22 | 23 | template 24 | using map_type = std::unordered_map; 25 | 26 | struct module_type { 27 | map_type constant_types; 28 | map_type struct_types; 29 | map_type primitive_types; 30 | map_type variables; 31 | map_type images; // TODO(gardell): Name image_types 32 | map_type samplers; // sampler_types; 33 | map_type sampled_images; // sampled_image_types 34 | std::vector entry_points; 35 | }; 36 | 37 | namespace internal { 38 | 39 | struct intermediate_type; 40 | 41 | module_type convert(const intermediate_type &intermediate); 42 | 43 | intermediate_type parse_intermediate(std::istream &stream); 44 | 45 | module_type parse(std::istream &stream); 46 | 47 | } // namespace internal 48 | 49 | template 50 | module_type parse(StreamT &&stream) { 51 | return internal::parse(stream); 52 | } 53 | 54 | /** 55 | * Get all the variables references by a given function, this includes searching through 56 | * variables references by intermediate functions. 57 | */ 58 | std::vector> variable_references( 59 | const module_type &module, const std::string &name); 60 | 61 | } // namespace spirv 62 | 63 | #endif // SPIRV_REFLECTION_ANALYZER_H_ 64 | -------------------------------------------------------------------------------- /spirv-reflection/include/reflection/internal/argument_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef SPIRV_REFLECTION_ARGUMENT_PARSER_H_ 17 | #define SPIRV_REFLECTION_ARGUMENT_PARSER_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace spirv { 24 | namespace internal { 25 | 26 | struct instruction_parser { 27 | 28 | explicit instruction_parser(const spv_parsed_instruction_t &instruction) 29 | : instruction(instruction) {} 30 | 31 | template 32 | T single(std::size_t operand) const { 33 | return T(instruction.words[instruction.operands[operand].offset]); 34 | } 35 | 36 | bool single_bool(std::size_t operand) const { 37 | return !!instruction.words[instruction.operands[operand].offset]; 38 | } 39 | 40 | template 41 | T optional(std::size_t operand, T default_value) const { 42 | return operand >= instruction.num_operands ? default_value : single(operand); 43 | } 44 | 45 | template 46 | std::vector multi(std::size_t operand) const { 47 | const T *words((T *) &instruction.words[instruction.operands[operand].offset]); 48 | return std::vector(words, 49 | words + instruction.operands[operand].num_words * sizeof(uint32_t) / sizeof(T)); 50 | } 51 | 52 | // Ignores num_words and just converts the "rest" of available arguments 53 | // Some commands will return num_words=1 for every argument even though its an array (2d-array effect/non-int type) 54 | template 55 | std::vector rest(std::size_t operand) const { 56 | if (operand < instruction.num_operands) { 57 | const T *words((T *)&instruction.words[instruction.operands[operand].offset]); 58 | const std::size_t count(instruction.words + instruction.num_words - words); 59 | return std::vector(words, words + count * sizeof(uint32_t) / sizeof(T)); 60 | } 61 | else { 62 | return std::vector(); 63 | } 64 | } 65 | 66 | std::string string(std::size_t operand) const { 67 | const char *words((const char *) &instruction.words[instruction.operands[operand].offset]); 68 | return std::string(words); 69 | } 70 | 71 | const spv_parsed_instruction_t &instruction; 72 | }; 73 | 74 | } // namespace internal 75 | } // namespace spirv 76 | 77 | #endif // SPIRV_REFLECTION_ARGUMENT_PARSER_H_ 78 | -------------------------------------------------------------------------------- /spirv-reflection/include/reflection/internal/includes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef _SPIRV_REFLECTION_INCLUDES_H_ 17 | #define _SPIRV_REFLECTION_INCLUDES_H_ 18 | 19 | #include 20 | #include 21 | 22 | #endif // _SPIRV_REFLECTION_INCLUDES_H_ -------------------------------------------------------------------------------- /spirv-reflection/include/reflection/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef SPIRV_REFLECTION_DATA_H_ 17 | #define SPIRV_REFLECTION_DATA_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace spirv { 24 | 25 | typedef uint32_t identifier_type; 26 | 27 | struct constant_type { 28 | identifier_type id, type_id; 29 | std::vector value; // might be larger than actual size. check primitive for bits. 30 | std::string name; 31 | bool specialization; 32 | identifier_type specialization_id; 33 | }; 34 | 35 | struct member_type { 36 | identifier_type type_id; 37 | std::string name; 38 | uint32_t offset; 39 | }; 40 | 41 | struct struct_type { 42 | bool array; 43 | identifier_type count_id; 44 | std::string name; 45 | std::vector members; 46 | }; 47 | 48 | struct primitive_type { 49 | SpvOp type; // float, int, bool, (only primitive single types). 50 | unsigned int components[2]; // [1..4] 51 | unsigned int bits; // 16, 32, 64 52 | bool array, signedness; 53 | identifier_type count_id; 54 | }; 55 | 56 | struct image_type { 57 | identifier_type result_id, sampled_id; 58 | SpvDim dim; 59 | bool arrayed; 60 | bool multisampled; 61 | }; 62 | 63 | // TODO(gardell): Possibly rename since its used with VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER 64 | struct sampled_image_type { 65 | identifier_type sampler_id, image_id; // sampler_id is OpTypeSampler, image_id is OpTypeImage. 66 | }; 67 | 68 | struct sampler_type { 69 | identifier_type sampler; 70 | }; 71 | 72 | struct variable_type { 73 | SpvStorageClass storage_class; // uniform, input etc. 74 | identifier_type identifier; 75 | std::string name; 76 | identifier_type type_id; 77 | identifier_type binding, location, descriptor_set, input_attachment_index, constant_id; 78 | }; 79 | 80 | struct entry_point_type { 81 | SpvExecutionModel execution_model; 82 | identifier_type function_id; 83 | std::string name; 84 | std::vector target_ids; 85 | }; 86 | 87 | } // namespace spirv 88 | 89 | #endif // SPIRV_REFLECTION_DATA_H_ 90 | -------------------------------------------------------------------------------- /textures/heightmap/height.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/heightmap/height.png -------------------------------------------------------------------------------- /textures/normal-mapping/normal_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/normal-mapping/normal_map.png -------------------------------------------------------------------------------- /textures/normal-mapping/source.txt: -------------------------------------------------------------------------------- 1 | This file is licensed under the Creative Commons Attribution 4.0 International license. 2 | Attribution: Julian Herzog 3 | 4 | https://commons.wikimedia.org/wiki/File:Normal_map_example_with_scene_and_result.png -------------------------------------------------------------------------------- /textures/png/PNG_transparency_demonstration_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/png/PNG_transparency_demonstration_1.png -------------------------------------------------------------------------------- /textures/storforsen4/negx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/negx.jpg -------------------------------------------------------------------------------- /textures/storforsen4/negy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/negy.jpg -------------------------------------------------------------------------------- /textures/storforsen4/negz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/negz.jpg -------------------------------------------------------------------------------- /textures/storforsen4/posx.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/posx.jpg -------------------------------------------------------------------------------- /textures/storforsen4/posy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/posy.jpg -------------------------------------------------------------------------------- /textures/storforsen4/posz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/posz.jpg -------------------------------------------------------------------------------- /textures/storforsen4/readme.txt: -------------------------------------------------------------------------------- 1 | Author 2 | ====== 3 | 4 | This is the work of Emil Persson, aka Humus. 5 | http://www.humus.name 6 | 7 | 8 | 9 | License 10 | ======= 11 | 12 | This work is licensed under a Creative Commons Attribution 3.0 Unported License. 13 | http://creativecommons.org/licenses/by/3.0/ 14 | -------------------------------------------------------------------------------- /textures/storforsen4/storforsen4.ktx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/storforsen4.ktx -------------------------------------------------------------------------------- /textures/storforsen4/storforsen_etc2_rgb.ktx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vulkan-cpp-library/82314d765013ce96e23186594259eebaf3127072/textures/storforsen4/storforsen_etc2_rgb.ktx -------------------------------------------------------------------------------- /types-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(${GLM_SRC_DIR}) 15 | include_directories(../types/include) 16 | include_directories(${gtest_SOURCE_DIR}/include) 17 | 18 | set(TYPES_TEST_SRCS 19 | "src/serialize_type_test.cpp" 20 | "src/transform_type_test.cpp" 21 | "src/storage_type_test.cpp" 22 | ) 23 | 24 | add_executable(types-test ${TYPES_TEST_SRCS}) 25 | target_link_libraries(types-test types gtest gtest_main) 26 | 27 | add_test(types-tests types-test) 28 | 29 | -------------------------------------------------------------------------------- /types/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | include_directories(${GLM_SRC_DIR}) 14 | include_directories(include) 15 | 16 | set(TYPES_INCLUDES 17 | "include/type/storage.h" 18 | "include/type/serialize.h" 19 | "include/type/types.h" 20 | "include/type/internal.h" 21 | "include/type/transform.h" 22 | "include/type/memory.h" 23 | "include/type/revision.h" 24 | "include/type/supplier.h" 25 | ) 26 | 27 | set(TYPES_SRCS 28 | "src/memory.cpp" 29 | "src/serialize.cpp" 30 | ) 31 | 32 | add_library(types ${TYPES_INCLUDES} ${TYPES_SRCS}) 33 | 34 | -------------------------------------------------------------------------------- /types/include/type/internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef _TYPES_INTERNAL_H_ 17 | #define _TYPES_INTERNAL_H_ 18 | 19 | namespace type { 20 | namespace internal { 21 | 22 | template 23 | auto get_revision(T &v)->decltype(v.get_revision())& { 24 | return v.get_revision(); 25 | } 26 | 27 | template 28 | auto get_container(T &v)->decltype(v.get_container())& { 29 | return v.get_container(); 30 | } 31 | 32 | template 33 | auto get_lock(T &v)->decltype(v.get_lock())& { 34 | return v.get_lock(); 35 | } 36 | 37 | } // namespace internal 38 | } // namespace type 39 | 40 | #endif // _TYPES_INTERNAL_H_ -------------------------------------------------------------------------------- /types/include/type/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef GTYPE_MEMORY_H_ 17 | #define GTYPE_MEMORY_H_ 18 | 19 | #include 20 | 21 | namespace type { 22 | 23 | enum memory_layout { 24 | // With linear, the data given to create will be concatenated after each other tightly. 25 | // It is up to the developer to make sure they are aligned nicely, for example on a vec4 boundary. 26 | linear = 0, 27 | // With interleaved_std140 all elements are interleaved to be used as vertex input. 28 | // They are also aligned with a vec4 boundary, i.e. all vec3 will be padded to vec4. 29 | // NOTICE: arrays of length 1 are treated as single elements, not arrays, which are not necessarily padded. 30 | // NOTICE: Interleaving only works when arrays are the same length, therefore, the data will be interleaved in groups. 31 | // For example, N vertex, N normals, 4*N texcoord, 4*N color will result in: 32 | // vertex(0), normal(0), ..., vertex(N-1), normal(N-1), texcoord(0), color(0), ..., texcoord(4*N-1), color(4*N-1) 33 | // See: https://developer.apple.com/library/ios/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html 34 | // "Use Interleaved Vertex Data" specifically "An exception to this rule..." 35 | interleaved_std140, 36 | // Same as linear but alignment according to std140 37 | linear_std140, 38 | interleaved_std430, 39 | linear_std430, 40 | // TODO(gardell): Possibly support other types too. 41 | num_layouts 42 | }; 43 | 44 | } // namespace type 45 | 46 | #endif // GTYPE_MEMORY_H_ 47 | -------------------------------------------------------------------------------- /types/include/type/revision.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef GTYPE_REVISION_TYPE_H_ 17 | #define GTYPE_REVISION_TYPE_H_ 18 | 19 | namespace type { 20 | 21 | // Not using 64 bit, even with 100 updates/second it will take +1 year to overflow. 22 | typedef unsigned long revision_type; 23 | // If a container returns REVISION_NONE it doesn't use a revision system. 24 | // An Adapter has its initial value set to REVISION_NONE to force an update. 25 | // (the default revision is 1) 26 | const revision_type REVISION_NONE = 0; 27 | 28 | } // namespace type 29 | 30 | #endif // GTYPE_REVISION_TYPE_H_ 31 | -------------------------------------------------------------------------------- /types/src/memory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | -------------------------------------------------------------------------------- /types/src/serialize.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | 19 | namespace type { 20 | 21 | } // namespace type 22 | -------------------------------------------------------------------------------- /vcc-image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | include_directories(include) 14 | include_directories(../types/include) 15 | include_directories(../vcc/include) 16 | include_directories(${CMAKE_BINARY_DIR}/vcc/include) 17 | include_directories(${GLI_SRC_DIR}) 18 | include_directories(${GLI_SRC_DIR}/external) 19 | if(NOT PNG_INCLUDE_DIR STREQUAL "") 20 | include_directories(${PNG_INCLUDE_DIR}) 21 | endif() 22 | if(NOT VULKAN_SDK_DIR STREQUAL "") 23 | include_directories(${VULKAN_SDK_DIR}/include) 24 | endif() 25 | remove_definitions(-DGLM_ENABLE_EXPERIMENTAL) 26 | 27 | set(VCC_IMAGE_INCLUDES 28 | "include/vcc/image_loader.h" 29 | "include/vcc/internal/loader.h" 30 | ) 31 | 32 | set(VCC_IMAGE_SRCS 33 | "src/image.cpp" 34 | "src/png_loader.cpp" 35 | "src/gli_loader.cpp" 36 | ) 37 | 38 | if(DEFINED ANDROID_NDK) 39 | list(APPEND VCC_IMAGE_SRCS "src/android_loader.cpp") 40 | endif() 41 | 42 | add_library(vcc-image ${VCC_IMAGE_INCLUDES} ${VCC_IMAGE_SRCS}) 43 | 44 | if(DEFINED ANDROID_NDK) 45 | target_link_libraries(vcc-image vcc) 46 | else() 47 | target_link_libraries(vcc-image vcc png) 48 | endif() 49 | -------------------------------------------------------------------------------- /vcc-image/include/vcc/image_loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef _VCC_IMAGE_LOADER_H_ 17 | #define _VCC_IMAGE_LOADER_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace vcc { 23 | namespace image { 24 | 25 | /* 26 | * Load an image from the given file. 27 | * Different loaders are supported, currently libpng and gli provide loading support. 28 | * In other words, .png, .ktx and .dds are supported. 29 | */ 30 | VCC_LIBRARY image::image_type create( 31 | const type::supplier &queue, 32 | VkImageCreateFlags flags, 33 | VkImageUsageFlags usage, 34 | VkFormatFeatureFlags feature_flags, 35 | VkSharingMode sharingMode, 36 | const std::vector &queueFamilyIndices, 37 | std::istream &&stream); 38 | 39 | #if defined(__ANDROID__) || defined(ANDROID) 40 | /* 41 | * Load an Android resource image through Java. 42 | * Note: Loads into a linear 2D single layer image. 43 | * Note: Calling thread must be able to execute JNI methods. 44 | * Note: AAssetManager can be obtained from ANativeActivity. 45 | */ 46 | VCC_LIBRARY image::image_type create( 47 | const type::supplier &queue, VkImageCreateFlags flags, 48 | VkImageUsageFlags usage, VkFormatFeatureFlags feature_flags, 49 | VkSharingMode sharingMode, const std::vector &queueFamilyIndices, 50 | JNIEnv *env, jobject context, const char *resource_identifier); 51 | #endif // __ANDROID__ 52 | 53 | // For debugging purposes only, prints the result of trying vkGetPhysicalDeviceFormatProperties with every VkFormat. 54 | VCC_LIBRARY std::string dump_physical_device_format_properties( 55 | VkPhysicalDevice physical_device); 56 | 57 | } // namespace image 58 | } // namespace vcc 59 | 60 | #endif // _VCC_IMAGE_LOADER_H_ 61 | -------------------------------------------------------------------------------- /vcc-image/include/vcc/internal/loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef _VCC_INTERNAL_LOADER_H_ 17 | #define _VCC_INTERNAL_LOADER_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace vcc { 24 | namespace image { 25 | namespace internal { 26 | 27 | struct loader_type { 28 | virtual bool can_load(std::istream &stream) = 0; 29 | virtual image::image_type load( 30 | const type::supplier &queue, 31 | VkImageCreateFlags flags, 32 | VkImageUsageFlags usage, 33 | VkFormatFeatureFlags feature_flags, 34 | VkSharingMode sharingMode, 35 | const std::vector &queueFamilyIndices, 36 | std::istream &stream) = 0; 37 | }; 38 | 39 | #if !defined(__ANDROID__) && !defined(ANDROID) 40 | 41 | struct png_loader_type : public loader_type { 42 | bool can_load(std::istream &stream); 43 | image::image_type load( 44 | const type::supplier &queue, 45 | VkImageCreateFlags flags, 46 | VkImageUsageFlags usage, 47 | VkFormatFeatureFlags feature_flags, 48 | VkSharingMode sharingMode, 49 | const std::vector &queueFamilyIndices, 50 | std::istream &stream); 51 | }; 52 | 53 | #endif // __ANDROID__ 54 | 55 | struct gli_loader_type : public loader_type { 56 | bool can_load(std::istream &stream); 57 | image::image_type load( 58 | const type::supplier &queue, 59 | VkImageCreateFlags flags, 60 | VkImageUsageFlags usage, 61 | VkFormatFeatureFlags feature_flags, 62 | VkSharingMode sharingMode, 63 | const std::vector &queueFamilyIndices, 64 | std::istream &stream); 65 | }; 66 | 67 | uint32_t bytes_per_pixel(VkFormat format); 68 | 69 | } // namespace internal 70 | } // namespace image 71 | } // namespace vcc 72 | 73 | #endif // _VCC_INTERNAL_LOADER_H_ 74 | 75 | -------------------------------------------------------------------------------- /vcc-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Google Inc. All Rights Reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # http://www.apache.org/licenses/LICENSE-2.0 7 | # Unless required by applicable law or agreed to in writing, software 8 | # distributed under the License is distributed on an "AS IS" BASIS, 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | # See the License for the specific language governing permissions and 11 | # limitations under the License. 12 | # 13 | 14 | include_directories(../vcc/include) 15 | include_directories(${CMAKE_BINARY_DIR}/vcc/include) 16 | include_directories(../types/include) 17 | include_directories(${gtest_SOURCE_DIR}/include) 18 | include_directories(${GLM_SRC_DIR}) 19 | if(NOT VULKAN_SDK_DIR STREQUAL "") 20 | include_directories(${VULKAN_SDK_DIR}/include) 21 | link_directories(${VULKAN_SDK_DIR}/bin) 22 | endif() 23 | 24 | set(VCC_TEST_SRCS 25 | "src/compute_shader_integration_test.cpp" 26 | ) 27 | 28 | set(VCC_TEST_SHADER_SRCS 29 | "src/integration-test-1.comp" 30 | ) 31 | 32 | add_executable(vcc-test ${VCC_TEST_SRCS}) 33 | 34 | target_link_libraries(vcc-test vcc types ${VULKAN_LIBRARY} gtest gtest_main) 35 | 36 | set(VCC_TEST_COMPILED_SHADER_BINARIES) 37 | foreach(FILE ${VCC_TEST_SHADER_SRCS}) 38 | get_filename_component(FILEWE ${FILE} NAME_WE) 39 | set(FILE_OUTPUT ${FILEWE}.spv) 40 | add_custom_command(TARGET vcc-test POST_BUILD DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 41 | COMMAND glslangValidator 42 | ARGS -V -o ${CMAKE_CURRENT_BINARY_DIR}/${FILE_OUTPUT} ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} 43 | WORKING_DIRECTORY .) 44 | list(APPEND VCC_TEST_COMPILED_SHADER_BINARIES ${FILE_OUTPUT}) 45 | endforeach() 46 | 47 | add_test(vcc-tests vcc-test) 48 | 49 | -------------------------------------------------------------------------------- /vcc-test/src/integration-test-1.comp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #version 450 17 | #extension GL_ARB_shading_language_420pack : enable 18 | #extension GL_ARB_compute_shader : enable 19 | 20 | layout(constant_id = 0) const int num_elements = 10; 21 | 22 | layout(std140, binding = 0) uniform inputs { 23 | float input_values[num_elements]; 24 | }; 25 | 26 | layout(std430, binding = 1) buffer outputs { 27 | float output_values[num_elements]; 28 | }; 29 | 30 | layout (local_size_x = 16, local_size_y = 1) in; 31 | void main() { 32 | const uint index = gl_LocalInvocationIndex; 33 | //output_values[index] = 2.0 * (1 + int(index)); 34 | output_values[index] = 2.0 * input_values[index]; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /vcc/include/vcc/android_asset_istream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef _ANDROID_ASSET_ISTREAM_H_ 17 | #define _ANDROID_ASSET_ISTREAM_H_ 18 | 19 | #if defined(__ANDROID__) || defined(ANDROID) 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace android { 29 | namespace internal { 30 | 31 | std::unique_ptr make_asset_istreambuf( 32 | AAssetManager *mgr, const char *filename); 33 | 34 | struct asset_istream_base { 35 | asset_istream_base(AAssetManager *mgr, const char *filename) 36 | : streambuf(std::unique_ptr(make_asset_istreambuf( 37 | mgr, filename))) {} 38 | std::unique_ptr streambuf; 39 | }; 40 | 41 | } // namespace internal 42 | 43 | struct asset_istream 44 | : private internal::asset_istream_base, public std::istream { 45 | 46 | asset_istream(AAssetManager *mgr, const char *filename) 47 | : internal::asset_istream_base(mgr, filename), 48 | std::istream(streambuf.get()) {} 49 | }; 50 | 51 | } // namespace android 52 | 53 | #endif // __ANDROID__ 54 | 55 | #endif // _ANDROID_ASSET_ISTREAM_H_ 56 | 57 | -------------------------------------------------------------------------------- /vcc/include/vcc/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef BUFFER_H_ 17 | #define BUFFER_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace memory { 23 | struct memory_type; 24 | } // namespace memory 25 | 26 | namespace buffer { 27 | 28 | struct buffer_type 29 | : public internal::movable_destructible_with_parent_and_memory { 31 | friend VCC_LIBRARY buffer_type create( 32 | const type::supplier &device, 33 | VkBufferCreateFlags flags, VkDeviceSize size, 34 | VkBufferUsageFlags usage, VkSharingMode sharingMode, 35 | const std::vector &queueFamilyIndices); 36 | 37 | buffer_type() = default; 38 | buffer_type(buffer_type &&) = default; 39 | buffer_type(const buffer_type &) = delete; 40 | buffer_type &operator=(buffer_type &&) = default; 41 | buffer_type &operator=(const buffer_type &) = delete; 42 | 43 | private: 44 | buffer_type(VkBuffer instance, const type::supplier &parent) 45 | : movable_destructible_with_parent_and_memory(instance, parent) {} 46 | }; 47 | 48 | VCC_LIBRARY buffer_type create( 49 | const type::supplier &device, 50 | VkBufferCreateFlags flags, VkDeviceSize size, 51 | VkBufferUsageFlags usage, VkSharingMode sharingMode, 52 | const std::vector &queueFamilyIndices); 53 | 54 | } // namespace buffer 55 | } // namespace vcc 56 | 57 | #endif /* BUFFER_H_ */ 58 | -------------------------------------------------------------------------------- /vcc/include/vcc/buffer_view.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef BUFFER_VIEW_H_ 17 | #define BUFFER_VIEW_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace buffer_view { 23 | 24 | struct buffer_view_type 25 | : public internal::movable_destructible_with_parent { 27 | friend VCC_LIBRARY buffer_view_type create( 28 | const type::supplier &buffer, VkFormat format, 29 | VkDeviceSize offset, VkDeviceSize range); 30 | 31 | buffer_view_type(buffer_view_type &&) = default; 32 | buffer_view_type(const buffer_view_type &) = default; 33 | buffer_view_type &operator=(buffer_view_type &&) = default; 34 | buffer_view_type &operator=(const buffer_view_type &) = delete; 35 | 36 | private: 37 | buffer_view_type(VkBufferView instance, 38 | const type::supplier &parent, 39 | const type::supplier &buffer) 40 | : movable_destructible_with_parent(instance, parent), 41 | buffer(buffer) {} 42 | 43 | type::supplier buffer; 44 | }; 45 | 46 | VCC_LIBRARY buffer_view_type create( 47 | const type::supplier &buffer, VkFormat format, 48 | VkDeviceSize offset, VkDeviceSize range); 49 | 50 | } // namespace buffer_view 51 | } // namespace vcc 52 | 53 | #endif /* BUFFER_VIEW_H_ */ 54 | -------------------------------------------------------------------------------- /vcc/include/vcc/command_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef COMMAND_POOL_H_ 17 | #define COMMAND_POOL_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace command_pool { 23 | 24 | struct command_pool_type : public internal::movable_destructible_with_parent { 26 | friend VCC_LIBRARY command_pool_type create(const type::supplier &, 27 | VkCommandPoolCreateFlags, uint32_t); 28 | command_pool_type() = default; 29 | command_pool_type(command_pool_type &&) = default; 30 | command_pool_type(const command_pool_type &) = delete; 31 | command_pool_type &operator=(command_pool_type &&) = default; 32 | command_pool_type &operator=(const command_pool_type &) = delete; 33 | 34 | private: 35 | command_pool_type(VkCommandPool instance, 36 | const type::supplier &parent) 37 | : internal::movable_destructible_with_parent(instance, parent) {} 39 | }; 40 | 41 | VCC_LIBRARY command_pool_type create( 42 | const type::supplier &device, 43 | VkCommandPoolCreateFlags flags, uint32_t queueFamilyIndex); 44 | 45 | } // namespace command_pool 46 | } // namespace vcc 47 | 48 | #endif /* COMMAND_POOL_H_ */ 49 | -------------------------------------------------------------------------------- /vcc/include/vcc/descriptor_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef DESCRIPTOR_POOL_H_ 17 | #define DESCRIPTOR_POOL_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace descriptor_pool { 23 | 24 | namespace internal { 25 | 26 | template 27 | VkDescriptorPoolCreateFlags get_flags(const T &pool) { 28 | return pool.flags; 29 | } 30 | 31 | } // namespace internal 32 | 33 | struct descriptor_pool_type 34 | : public vcc::internal::movable_destructible_with_parent { 36 | template 37 | friend VkDescriptorPoolCreateFlags internal::get_flags(const T &); 38 | friend VCC_LIBRARY descriptor_pool_type create( 39 | const type::supplier &, VkDescriptorPoolCreateFlags, uint32_t, 40 | const std::vector &); 41 | 42 | descriptor_pool_type() = default; 43 | descriptor_pool_type(descriptor_pool_type &&) = default; 44 | descriptor_pool_type(const descriptor_pool_type &) = delete; 45 | descriptor_pool_type &operator=(descriptor_pool_type &&) = default; 46 | descriptor_pool_type &operator=(const descriptor_pool_type &) = delete; 47 | 48 | private: 49 | descriptor_pool_type(VkDescriptorPool instance, 50 | const type::supplier &parent, 51 | VkDescriptorPoolCreateFlags flags) 52 | : movable_destructible_with_parent(instance, parent), flags(flags) {} 53 | 54 | VkDescriptorPoolCreateFlags flags; 55 | }; 56 | 57 | VCC_LIBRARY descriptor_pool_type create( 58 | const type::supplier &device, 59 | VkDescriptorPoolCreateFlags flags, uint32_t maxSets, 60 | const std::vector &poolSizes); 61 | 62 | } // namespace descriptor_pool 63 | } // namespace vcc 64 | 65 | #endif /* DESCRIPTOR_POOL_H_ */ 66 | -------------------------------------------------------------------------------- /vcc/include/vcc/descriptor_set_layout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef DESCRIPTOR_SET_LAYOUT_H_ 17 | #define DESCRIPTOR_SET_LAYOUT_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace vcc { 23 | namespace descriptor_set_layout { 24 | 25 | struct descriptor_set_layout_binding { 26 | uint32_t binding; 27 | VkDescriptorType descriptorType; 28 | uint32_t descriptorCount; 29 | VkShaderStageFlags stageFlags; 30 | std::vector> immutableSamplers; 31 | }; 32 | 33 | struct descriptor_set_layout_type : internal::movable_destructible_with_parent< 34 | VkDescriptorSetLayout, const device::device_type, vkDestroyDescriptorSetLayout> { 35 | friend VCC_LIBRARY descriptor_set_layout_type create( 36 | const type::supplier &device, 37 | const std::vector &bindings); 38 | 39 | descriptor_set_layout_type() = default; 40 | descriptor_set_layout_type(descriptor_set_layout_type &&) = default; 41 | descriptor_set_layout_type(const descriptor_set_layout_type &) = delete; 42 | descriptor_set_layout_type &operator=(descriptor_set_layout_type &&) = default; 43 | descriptor_set_layout_type &operator=(const descriptor_set_layout_type &) = delete; 44 | 45 | private: 46 | descriptor_set_layout_type(VkDescriptorSetLayout instance, 47 | const type::supplier &parent) 48 | : movable_destructible_with_parent(instance, parent) {} 49 | }; 50 | 51 | VCC_LIBRARY descriptor_set_layout_type create( 52 | const type::supplier &device, 53 | const std::vector &bindings); 54 | 55 | } // namespace descriptor_set_layout 56 | } // namespace vcc 57 | 58 | 59 | #endif /* DESCRIPTOR_SET_LAYOUT_H_ */ 60 | -------------------------------------------------------------------------------- /vcc/include/vcc/device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef DEVICE_H_ 17 | #define DEVICE_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace vcc { 23 | namespace device { 24 | 25 | struct queue_create_info_type { 26 | uint32_t queueFamilyIndex; 27 | std::vector queuePriorities; 28 | }; 29 | 30 | struct device_type 31 | : public internal::movable_destructible { 32 | friend VCC_LIBRARY device_type create(VkPhysicalDevice physical_device, 33 | const std::vector &queue_create_info, 34 | const std::set &layers, 35 | const std::set &extensions, 36 | const VkPhysicalDeviceFeatures &features); 37 | friend VkPhysicalDevice get_physical_device(const device_type &device); 38 | 39 | device_type() = default; 40 | device_type(const device_type&) = delete; 41 | device_type(device_type&©) = default; 42 | device_type &operator=(const device_type&) = delete; 43 | device_type &operator=(device_type&©) = default; 44 | 45 | private: 46 | device_type(VkDevice device, VkPhysicalDevice physical_device) 47 | : movable_destructible(device), physical_device(physical_device) {} 48 | 49 | internal::handle_type physical_device; 50 | }; 51 | 52 | VCC_LIBRARY device_type create(VkPhysicalDevice physical_device, 53 | const std::vector &queue_create_info, 54 | const std::set &layers, 55 | const std::set &extensions, 56 | const VkPhysicalDeviceFeatures &features); 57 | 58 | VCC_LIBRARY void wait_idle(const device_type &device); 59 | 60 | inline VkPhysicalDevice get_physical_device(const device_type &device) { 61 | return device.physical_device; 62 | } 63 | 64 | } // namespace device 65 | } // namespace vcc 66 | 67 | #endif /* DEVICE_H_ */ 68 | -------------------------------------------------------------------------------- /vcc/include/vcc/enumerate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef _ENUMERATE_H_ 17 | #define _ENUMERATE_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace vcc { 24 | namespace enumerate { 25 | 26 | VCC_LIBRARY std::vector instance_layer_properties(); 27 | VCC_LIBRARY std::vector device_layer_properties( 28 | VkPhysicalDevice device); 29 | 30 | VCC_LIBRARY std::vector instance_extension_properties( 31 | const std::string &layer_name); 32 | VCC_LIBRARY std::vector device_extension_properties( 33 | VkPhysicalDevice device, const std::string &layer_name); 34 | 35 | // TODO(gardell): Possibly contain version, not just string 36 | VCC_LIBRARY bool contains_all(const std::vector &layers, 37 | const std::set &required); 38 | 39 | VCC_LIBRARY std::vector filter( 40 | const std::vector &layers, 41 | const std::set &optional); 42 | 43 | // TODO(gardell): Possibly contain version, not just string 44 | VCC_LIBRARY bool contains_all( 45 | const std::vector &extensions, 46 | const std::set &required); 47 | 48 | VCC_LIBRARY std::vector filter( 49 | const std::vector &extensions, 50 | const std::set &optional); 51 | 52 | } // namespace enumerate 53 | } // namespace vcc 54 | 55 | #endif /* _ENUMERATE_H_ */ 56 | -------------------------------------------------------------------------------- /vcc/include/vcc/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef EVENT_H_ 17 | #define EVENT_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace event { 23 | 24 | struct event_type : internal::movable_destructible_with_parent { 26 | friend VCC_LIBRARY event_type create(const type::supplier &device); 27 | 28 | event_type() = default; 29 | event_type(event_type &&) = default; 30 | event_type(const event_type &) = delete; 31 | event_type &operator=(event_type &&) = default; 32 | event_type &operator=(const event_type &) = delete; 33 | 34 | private: 35 | event_type(VkEvent instance, const type::supplier &parent) 36 | : movable_destructible_with_parent(instance, parent) {} 37 | }; 38 | 39 | VCC_LIBRARY event_type create(const type::supplier &device); 40 | VCC_LIBRARY VkResult status(const event_type &event); 41 | VCC_LIBRARY void set(const event_type &event); 42 | VCC_LIBRARY void reset(const event_type &event); 43 | 44 | } // namespace event 45 | } // namespace vcc 46 | 47 | #endif /* EVENT_H_ */ 48 | -------------------------------------------------------------------------------- /vcc/include/vcc/fence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef FENCE_H_ 17 | #define FENCE_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace vcc { 24 | namespace fence { 25 | 26 | struct fence_type 27 | : public internal::movable_destructible_with_parent { 29 | friend VCC_LIBRARY fence_type create( 30 | const type::supplier &device, VkFenceCreateFlags flags); 31 | 32 | fence_type() = default; 33 | fence_type(fence_type &&) = default; 34 | fence_type(const fence_type &) = delete; 35 | fence_type &operator=(fence_type &&) = default; 36 | fence_type &operator=(const fence_type &) = delete; 37 | 38 | private: 39 | fence_type(VkFence instance, 40 | const type::supplier &parent) 41 | : internal::movable_destructible_with_parent(instance, parent) {} 43 | }; 44 | 45 | VCC_LIBRARY fence_type create( 46 | const type::supplier &device, 47 | VkFenceCreateFlags flags = 0); 48 | 49 | VCC_LIBRARY VkResult wait(const device::device_type &device, 50 | const std::vector> &fences, 51 | bool wait_all, std::chrono::nanoseconds timeout); 52 | 53 | VkResult wait(const device::device_type &device, 54 | const std::vector> &fences, bool wait_all); 55 | 56 | VCC_LIBRARY void reset(const device::device_type &device, 57 | const std::vector> &fences); 58 | 59 | } // namespace fence 60 | } // namespace vcc 61 | 62 | #endif /* FENCE_H_ */ 63 | -------------------------------------------------------------------------------- /vcc/include/vcc/framebuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef FRAMEBUFFER_H_ 17 | #define FRAMEBUFFER_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace vcc { 24 | namespace framebuffer { 25 | 26 | struct framebuffer_type : internal::movable_destructible_with_parent { 28 | friend VCC_LIBRARY framebuffer_type create(const type::supplier &, 29 | const type::supplier &, 30 | const std::vector> &, VkExtent2D, 31 | uint32_t); 32 | 33 | framebuffer_type() = default; 34 | framebuffer_type(framebuffer_type &&) = default; 35 | framebuffer_type(const framebuffer_type &) = delete; 36 | framebuffer_type &operator=(framebuffer_type &&) = default; 37 | framebuffer_type &operator=(const framebuffer_type &) = delete; 38 | 39 | private: 40 | framebuffer_type(VkFramebuffer instance, 41 | const type::supplier &parent, 42 | const type::supplier &render_pass, 43 | const std::vector> &image_views) 44 | : movable_destructible_with_parent(instance, parent) 45 | , render_pass(render_pass), image_views(image_views) {} 46 | 47 | type::supplier render_pass; 48 | std::vector> image_views; 49 | }; 50 | 51 | VCC_LIBRARY framebuffer_type create( 52 | const type::supplier &device, 53 | const type::supplier &render_pass, 54 | const std::vector> &image_views, 55 | VkExtent2D extent, uint32_t layers); 56 | 57 | } // namespace framebuffer 58 | } // namespace vcc 59 | 60 | #endif /* FRAMEBUFFER_H_ */ 61 | -------------------------------------------------------------------------------- /vcc/include/vcc/image_view.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef IMAGE_VIEW_H_ 17 | #define IMAGE_VIEW_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace vcc { 23 | namespace image_view { 24 | 25 | struct image_view_type 26 | : public internal::movable_destructible_with_parent { 28 | friend VCC_LIBRARY image_view_type create( 29 | const type::supplier &image, 30 | VkImageViewType viewType, VkFormat format, 31 | const VkComponentMapping &components, 32 | const VkImageSubresourceRange &subresourceRange); 33 | 34 | friend VCC_LIBRARY image_view_type create( 35 | const type::supplier &image, 36 | const VkImageSubresourceRange &subresourceRange); 37 | 38 | image_view_type() = default; 39 | image_view_type(const image_view_type &) = delete; 40 | image_view_type(image_view_type &©) = default; 41 | image_view_type& operator=(const image_view_type&) = delete; 42 | image_view_type& operator=(image_view_type&©) = default; 43 | 44 | private: 45 | image_view_type(VkImageView instance, 46 | const type::supplier &parent, 47 | const type::supplier &image) 48 | : internal::movable_destructible_with_parent(instance, parent), 50 | image(image) {} 51 | type::supplier image; 52 | }; 53 | 54 | VCC_LIBRARY image_view_type create( 55 | const type::supplier &image, 56 | VkImageViewType viewType, VkFormat format, 57 | const VkComponentMapping &components, 58 | const VkImageSubresourceRange &subresourceRange); 59 | 60 | VCC_LIBRARY image_view_type create( 61 | const type::supplier &image, 62 | const VkImageSubresourceRange &subresourceRange); 63 | 64 | } // namespace image_view 65 | } // namespace vcc 66 | 67 | #endif /* IMAGE_VIEW_H_ */ 68 | -------------------------------------------------------------------------------- /vcc/include/vcc/instance.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef INSTANCE_H_ 17 | #define INSTANCE_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace vcc { 24 | namespace instance { 25 | 26 | struct instance_type : public internal::movable_destructible { 27 | friend VCC_LIBRARY instance_type create( 28 | const std::set &layers, 29 | const std::set &extensions); 30 | 31 | instance_type() = default; 32 | instance_type(instance_type &&) = default; 33 | instance_type(const instance_type &) = delete; 34 | instance_type &operator=(instance_type &&) = default; 35 | instance_type &operator=(const instance_type &) = delete; 36 | 37 | private: 38 | explicit instance_type(VkInstance instance) 39 | : internal::movable_destructible(instance) {} 40 | }; 41 | 42 | VCC_LIBRARY instance_type create( 43 | const std::set &layers = std::set(), 44 | const std::set &extensions = std::set()); 45 | 46 | } // namespace instance 47 | } // namespace vcc 48 | 49 | #endif /* INSTANCE_H_ */ 50 | -------------------------------------------------------------------------------- /vcc/include/vcc/physical_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef PHYSICAL_DEVICE_H_ 17 | #define PHYSICAL_DEVICE_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace vcc { 24 | namespace physical_device { 25 | 26 | VCC_LIBRARY std::vector enumerate( 27 | const instance::instance_type &instance); 28 | 29 | inline VkPhysicalDeviceProperties properties( 30 | VkPhysicalDevice physical_device) { 31 | VkPhysicalDeviceProperties properties; 32 | vkGetPhysicalDeviceProperties(physical_device, &properties); 33 | return properties; 34 | } 35 | 36 | inline VkPhysicalDeviceFeatures features(VkPhysicalDevice physical_device) { 37 | VkPhysicalDeviceFeatures features; 38 | vkGetPhysicalDeviceFeatures(physical_device, &features); 39 | return features; 40 | } 41 | 42 | inline VkFormatProperties format_properties(VkPhysicalDevice physical_device, 43 | VkFormat format) { 44 | VkFormatProperties properties; 45 | vkGetPhysicalDeviceFormatProperties(physical_device, format, &properties); 46 | return properties; 47 | } 48 | 49 | VCC_LIBRARY VkPhysicalDeviceMemoryProperties memory_properties( 50 | VkPhysicalDevice physical_device); 51 | 52 | // TODO: More get methods 53 | 54 | VCC_LIBRARY std::vector queue_famility_properties( 55 | VkPhysicalDevice physical_device); 56 | 57 | VCC_LIBRARY uint32_t get_queue_family_properties_with_flag( 58 | const std::vector &properties, 59 | VkQueueFlags flags); 60 | 61 | } // namespace physical_device 62 | } // namespace vcc 63 | 64 | 65 | #endif /* PHYSICAL_DEVICE_H_ */ 66 | -------------------------------------------------------------------------------- /vcc/include/vcc/pipeline_cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef PIPELINE_CACHE_H_ 17 | #define PIPELINE_CACHE_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace pipeline_cache { 23 | 24 | struct pipeline_cache_type : internal::movable_destructible_with_parent { 26 | 27 | friend VCC_LIBRARY pipeline_cache_type create( 28 | const type::supplier &, const std::string &); 29 | 30 | pipeline_cache_type() = default; 31 | pipeline_cache_type(pipeline_cache_type &&) = default; 32 | pipeline_cache_type(const pipeline_cache_type &) = delete; 33 | pipeline_cache_type &operator=(pipeline_cache_type &&) = default; 34 | pipeline_cache_type &operator=(const pipeline_cache_type &) = delete; 35 | 36 | private: 37 | pipeline_cache_type(VkPipelineCache instance, 38 | const type::supplier &parent) 39 | : movable_destructible_with_parent(instance, parent) {} 40 | }; 41 | 42 | VCC_LIBRARY pipeline_cache_type create(const type::supplier &device, 43 | const std::string &data = std::string()); 44 | 45 | VCC_LIBRARY std::string serialize(const pipeline_cache_type &pipeline_cache); 46 | 47 | VCC_LIBRARY void merge(const pipeline_cache_type &pipeline_cache, 48 | const std::vector> &source_caches); 49 | 50 | } // namespace pipeline_cache 51 | } // namespace vcc 52 | 53 | 54 | #endif /* PIPELINE_CACHE_H_ */ 55 | -------------------------------------------------------------------------------- /vcc/include/vcc/query_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef QUERY_POOL_H_ 17 | #define QUERY_POOL_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace query_pool { 23 | 24 | struct query_pool_type : internal::movable_destructible_with_parent { 26 | 27 | friend VCC_LIBRARY query_pool_type create(const type::supplier &, 28 | VkQueryType, uint32_t, VkQueryPipelineStatisticFlags); 29 | 30 | query_pool_type() = default; 31 | query_pool_type(query_pool_type &&) = default; 32 | query_pool_type(const query_pool_type &) = delete; 33 | query_pool_type &operator=(query_pool_type &&) = default; 34 | query_pool_type &operator=(const query_pool_type &) = delete; 35 | 36 | private: 37 | query_pool_type(VkQueryPool instance, const type::supplier &parent) 38 | : movable_destructible_with_parent(instance, parent) {} 39 | }; 40 | 41 | VCC_LIBRARY query_pool_type create(const type::supplier &device, 42 | VkQueryType queryType, uint32_t queryCount, VkQueryPipelineStatisticFlags pipelineStatistics); 43 | 44 | VCC_LIBRARY void get_results(uint32_t firstQuery, uint32_t queryCount, size_t dataSize, 45 | void* pData, VkDeviceSize stride, VkQueryResultFlags flags); 46 | 47 | } // namespace query_pool 48 | } // namespace vcc 49 | 50 | #endif /* QUERY_POOL_H_ */ 51 | -------------------------------------------------------------------------------- /vcc/include/vcc/render_pass.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef RENDER_PASS_H_ 17 | #define RENDER_PASS_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace render_pass { 23 | 24 | struct subpass_description_type { 25 | std::vector inputAttachments; 26 | std::vector colorAttachments; 27 | std::vector resolveAttachments; 28 | VkAttachmentReference depthStencilAttachment; 29 | std::vector preserveAttachments; 30 | }; 31 | 32 | struct render_pass_type : internal::movable_destructible_with_parent { 34 | friend VCC_LIBRARY render_pass_type create( 35 | const type::supplier &device, 36 | const std::vector &attachment_descriptions, 37 | const std::vector &subpass_descriptions, 38 | const std::vector &subpass_dependency); 39 | 40 | render_pass_type() = default; 41 | render_pass_type(render_pass_type &&) = default; 42 | render_pass_type(const render_pass_type &) = delete; 43 | render_pass_type &operator=(render_pass_type &&) = default; 44 | render_pass_type &operator=(const render_pass_type &) = delete; 45 | 46 | private: 47 | render_pass_type(VkRenderPass instance, 48 | const type::supplier &parent) 49 | : movable_destructible_with_parent(instance, parent) {} 50 | }; 51 | 52 | VCC_LIBRARY render_pass_type create( 53 | const type::supplier &device, 54 | const std::vector &attachment_descriptions, 55 | const std::vector &subpass_descriptions, 56 | const std::vector &subpass_dependency); 57 | 58 | VCC_LIBRARY VkExtent2D get_render_area_granularity(const render_pass_type &render_pass); 59 | 60 | } // namespace render_pass 61 | } // namespace vcc 62 | 63 | #endif /* RENDER_PASS_H_ */ 64 | -------------------------------------------------------------------------------- /vcc/include/vcc/sampler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef SAMPLER_H_ 17 | #define SAMPLER_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace sampler { 23 | 24 | struct sampler_type : internal::movable_destructible_with_parent { 26 | 27 | friend VCC_LIBRARY sampler_type create( 28 | const type::supplier &, VkFilter, VkFilter, VkSamplerMipmapMode, 29 | VkSamplerAddressMode, VkSamplerAddressMode, VkSamplerAddressMode, float, VkBool32, float, 30 | VkBool32, VkCompareOp, float, float, VkBorderColor, VkBool32); 31 | 32 | sampler_type() = default; 33 | sampler_type(sampler_type &&) = default; 34 | sampler_type(const sampler_type &) = delete; 35 | sampler_type &operator=(sampler_type &&) = default; 36 | sampler_type &operator=(const sampler_type &) = delete; 37 | 38 | private: 39 | sampler_type(VkSampler instance, const type::supplier &parent) 40 | : movable_destructible_with_parent(instance, parent) {} 41 | }; 42 | 43 | VCC_LIBRARY sampler_type create(const type::supplier &device, 44 | VkFilter magFilter, VkFilter minFilter, VkSamplerMipmapMode mipmapMode, 45 | VkSamplerAddressMode addressModeU, VkSamplerAddressMode addressModeV, 46 | VkSamplerAddressMode addressModeW, float mipLodBias, VkBool32 anisotropyEnable, 47 | float maxAnisotropy, VkBool32 compareEnable, VkCompareOp compareOp, float minLod, float maxLod, 48 | VkBorderColor borderColor, VkBool32 unnormalizedCoordinates); 49 | 50 | } // namespace sampler 51 | } // namespace vcc 52 | 53 | #endif /* SAMPLER_H_ */ 54 | -------------------------------------------------------------------------------- /vcc/include/vcc/semaphore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef SEMAPHORE_H_ 17 | #define SEMAPHORE_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace semaphore { 23 | 24 | struct semaphore_type : internal::movable_destructible_with_parent { 26 | friend VCC_LIBRARY semaphore_type create(const type::supplier &); 27 | 28 | semaphore_type() = default; 29 | semaphore_type(semaphore_type &&) = default; 30 | semaphore_type(const semaphore_type &) = delete; 31 | semaphore_type &operator=(semaphore_type &&) = default; 32 | semaphore_type &operator=(const semaphore_type &) = delete; 33 | 34 | private: 35 | semaphore_type(VkSemaphore instance, const type::supplier &parent) 36 | : movable_destructible_with_parent(instance, parent) {} 37 | }; 38 | 39 | VCC_LIBRARY semaphore_type create(const type::supplier &device); 40 | 41 | } // namespace semaphore 42 | } // namespace vcc 43 | 44 | #endif /* SEMAPHORE_H_ */ 45 | -------------------------------------------------------------------------------- /vcc/include/vcc/shader_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef SHADER_MODULE_H_ 17 | #define SHADER_MODULE_H_ 18 | 19 | #include 20 | 21 | namespace vcc { 22 | namespace shader_module { 23 | 24 | struct shader_module_type : internal::movable_destructible_with_parent { 26 | 27 | friend VCC_LIBRARY shader_module_type create(const type::supplier &, 28 | std::istream &&); 29 | 30 | shader_module_type() = default; 31 | shader_module_type(shader_module_type &&) = default; 32 | shader_module_type(const shader_module_type &) = delete; 33 | shader_module_type &operator=(shader_module_type &&) = default; 34 | shader_module_type &operator=(const shader_module_type &) = delete; 35 | 36 | private: 37 | shader_module_type(VkShaderModule instance, 38 | const type::supplier &parent) 39 | : movable_destructible_with_parent(instance, parent) {} 40 | }; 41 | 42 | VCC_LIBRARY shader_module_type create(const type::supplier &device, 43 | std::istream &&stream); 44 | 45 | } // namespace shader_module 46 | } // namespace vcc 47 | 48 | 49 | #endif /* SHADER_MODULE_H_ */ 50 | -------------------------------------------------------------------------------- /vcc/src/buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace buffer { 20 | 21 | buffer_type create(const type::supplier &device, 22 | VkBufferCreateFlags flags, VkDeviceSize size, VkBufferUsageFlags usage, 23 | VkSharingMode sharingMode, const std::vector &queueFamilyIndices) { 24 | VkBufferCreateInfo create = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, NULL}; 25 | create.flags = flags; 26 | create.size = size; 27 | create.usage = usage; 28 | create.sharingMode = sharingMode; 29 | create.queueFamilyIndexCount = (uint32_t) queueFamilyIndices.size(); 30 | create.pQueueFamilyIndices = queueFamilyIndices.empty() ? NULL : &queueFamilyIndices.front(); 31 | VkBuffer buffer; 32 | VKCHECK(vkCreateBuffer(internal::get_instance(*device), &create, NULL, &buffer)); 33 | return buffer_type(buffer, device); 34 | } 35 | 36 | } // namespace buffer 37 | } // namespace vcc 38 | 39 | 40 | -------------------------------------------------------------------------------- /vcc/src/buffer_view.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace buffer_view { 20 | 21 | buffer_view_type create(const type::supplier &buffer, 22 | VkFormat format, VkDeviceSize offset, VkDeviceSize range) { 23 | VkBufferViewCreateInfo create = {VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, NULL, 0}; 24 | create.buffer = vcc::internal::get_instance(*buffer); 25 | create.format = format; 26 | create.offset = offset; 27 | create.range = range; 28 | VkBufferView view; 29 | VKCHECK(vkCreateBufferView(internal::get_instance(*internal::get_parent(*buffer)), 30 | &create, NULL, &view)); 31 | return buffer_view_type(view, internal::get_parent(*buffer), buffer); 32 | } 33 | 34 | } // namespace buffer_view 35 | } // namespace vcc 36 | -------------------------------------------------------------------------------- /vcc/src/command_buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace vcc { 22 | namespace command_buffer { 23 | 24 | std::vector allocate( 25 | const type::supplier &device, 26 | const type::supplier &command_pool, 27 | VkCommandBufferLevel level, uint32_t commandBufferCount) { 28 | std::vector buffers(commandBufferCount); 29 | VkCommandBufferAllocateInfo info = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, NULL}; 30 | info.level = level; 31 | info.commandBufferCount = commandBufferCount; 32 | { 33 | std::lock_guard command_pool_lock( 34 | vcc::internal::get_mutex(*command_pool)); 35 | info.commandPool = vcc::internal::get_instance(*command_pool); 36 | VKCHECK(vkAllocateCommandBuffers(vcc::internal::get_instance(*device), 37 | &info, buffers.data())); 38 | } 39 | std::vector command_buffers; 40 | command_buffers.reserve(commandBufferCount); 41 | for (VkCommandBuffer buffer : buffers) { 42 | command_buffers.push_back(command_buffer_type(buffer, command_pool, device)); 43 | } 44 | return std::move(command_buffers); 45 | } 46 | 47 | } // namespace command_buffer 48 | } // namespace vcc 49 | 50 | 51 | -------------------------------------------------------------------------------- /vcc/src/command_pool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace command_pool { 20 | 21 | command_pool_type create(const type::supplier &device, 22 | VkCommandPoolCreateFlags flags, uint32_t queueFamilyIndex) { 23 | VkCommandPoolCreateInfo create = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 24 | NULL}; 25 | create.flags = flags; 26 | create.queueFamilyIndex = queueFamilyIndex; 27 | VkCommandPool pool; 28 | VKCHECK(vkCreateCommandPool(internal::get_instance(*device), &create, NULL, 29 | &pool)); 30 | return command_pool_type(pool, device); 31 | } 32 | 33 | } // namespace command_pool 34 | } // namespace vcc 35 | -------------------------------------------------------------------------------- /vcc/src/descriptor_pool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace descriptor_pool { 20 | 21 | descriptor_pool_type create(const type::supplier &device, 22 | VkDescriptorPoolCreateFlags flags, uint32_t maxSets, 23 | const std::vector &poolSizes) { 24 | VkDescriptorPoolCreateInfo create = { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, NULL}; 25 | create.flags = flags; 26 | create.maxSets = maxSets; 27 | create.poolSizeCount = (uint32_t) poolSizes.size(); 28 | create.pPoolSizes = poolSizes.empty() ? NULL : &poolSizes.front(); 29 | VkDescriptorPool descriptor_pool; 30 | VKCHECK(vkCreateDescriptorPool(vcc::internal::get_instance(*device), &create, NULL, 31 | &descriptor_pool)); 32 | return descriptor_pool_type(descriptor_pool, device, flags); 33 | } 34 | 35 | } // namespace descriptor_pool 36 | } // namespace vcc 37 | 38 | 39 | -------------------------------------------------------------------------------- /vcc/src/descriptor_set_layout.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | namespace vcc { 21 | namespace descriptor_set_layout { 22 | 23 | std::pair, std::vector>> 24 | convert_bindings(const std::vector &bindings) { 25 | std::vector converted_bindings; 26 | std::vector> converted_samplers; 27 | converted_bindings.reserve(bindings.size()); 28 | for (const descriptor_set_layout_binding &binding : bindings) { 29 | VkDescriptorSetLayoutBinding converted_binding; 30 | converted_binding.binding = binding.binding; 31 | converted_binding.descriptorType = binding.descriptorType; 32 | converted_binding.descriptorCount = binding.descriptorCount; 33 | converted_binding.stageFlags = binding.stageFlags; 34 | 35 | std::vector samplers; 36 | samplers.reserve(binding.immutableSamplers.size()); 37 | std::transform(binding.immutableSamplers.begin(), binding.immutableSamplers.end(), 38 | std::back_inserter(samplers), 39 | [](const type::supplier &sampler) { 40 | return internal::get_instance(*sampler); 41 | }); 42 | converted_binding.pImmutableSamplers = samplers.data(); 43 | converted_bindings.emplace_back(converted_binding); 44 | converted_samplers.push_back(std::move(samplers)); 45 | } 46 | return std::make_pair(std::move(converted_bindings), std::move(converted_samplers)); 47 | } 48 | 49 | descriptor_set_layout_type create(const type::supplier &device, 50 | const std::vector &bindings) { 51 | VkDescriptorSetLayoutCreateInfo create = { 52 | VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, NULL, 0 }; 53 | create.bindingCount = (uint32_t) bindings.size(); 54 | std::vector converted_bindings; 55 | std::vector> converted_samplers; 56 | std::tie(converted_bindings, converted_samplers) = (convert_bindings(bindings)); 57 | create.pBindings = converted_bindings.data(); 58 | VkDescriptorSetLayout layout; 59 | VKCHECK(vkCreateDescriptorSetLayout(internal::get_instance(*device), &create, NULL, &layout)); 60 | return descriptor_set_layout_type(layout, device); 61 | } 62 | 63 | } // namespace descriptor_set_layout 64 | } // namespace vcc 65 | -------------------------------------------------------------------------------- /vcc/src/device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | namespace vcc { 21 | namespace device { 22 | 23 | std::vector convert(const std::vector &queue_create_info) { 24 | std::vector converted; 25 | converted.reserve(queue_create_info.size()); 26 | std::transform(queue_create_info.begin(), queue_create_info.end(), std::back_inserter(converted), 27 | [](const queue_create_info_type &info) { 28 | VkDeviceQueueCreateInfo converted_info = {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, NULL, 0}; 29 | converted_info.pQueuePriorities = info.queuePriorities.empty() ? NULL : &info.queuePriorities.front(); 30 | converted_info.queueCount = (uint32_t)info.queuePriorities.size(); 31 | converted_info.queueFamilyIndex = info.queueFamilyIndex; 32 | return converted_info; 33 | }); 34 | return converted; 35 | } 36 | 37 | device_type create(VkPhysicalDevice physical_device, const std::vector &queue_create_info, 38 | const std::set &layers, const std::set &extensions, 39 | const VkPhysicalDeviceFeatures &features) { 40 | VkDeviceCreateInfo create_info = {VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, NULL, 0}; 41 | const std::vector converted(convert(queue_create_info)); 42 | create_info.queueCreateInfoCount = (uint32_t)converted.size(); 43 | create_info.pQueueCreateInfos = converted.empty() ? NULL : &converted.front(); 44 | create_info.enabledLayerCount = (uint32_t)layers.size(); 45 | const std::vector layer_pointers(util::to_pointers(layers)); 46 | create_info.ppEnabledLayerNames = layers.empty() ? NULL : &layer_pointers.front(); 47 | create_info.enabledExtensionCount = (uint32_t) extensions.size(); 48 | const std::vector extension_pointers(util::to_pointers(extensions)); 49 | create_info.ppEnabledExtensionNames = extension_pointers.empty() ? NULL : &extension_pointers.front(); 50 | create_info.pEnabledFeatures = &features; 51 | VkDevice device; 52 | VKCHECK(vkCreateDevice(physical_device, &create_info, NULL, &device)); 53 | return device_type(device, physical_device); 54 | } 55 | 56 | void wait_idle(const device_type &device) { 57 | VKCHECK(vkDeviceWaitIdle(internal::get_instance(device))); 58 | } 59 | 60 | } // namespace device 61 | } // namespace vcc 62 | -------------------------------------------------------------------------------- /vcc/src/event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace event { 20 | 21 | event_type create(const type::supplier &device) { 22 | VkEventCreateInfo create = {VK_STRUCTURE_TYPE_EVENT_CREATE_INFO, NULL, 0}; 23 | VkEvent event; 24 | VKCHECK(vkCreateEvent(internal::get_instance(*device), &create, NULL, &event)); 25 | return event_type(event, device); 26 | } 27 | 28 | VkResult status(const event_type &event) { 29 | return vkGetEventStatus(internal::get_instance(*internal::get_parent(event)), 30 | internal::get_instance(event)); 31 | } 32 | 33 | void set(const event_type &event) { 34 | std::lock_guard lock(internal::get_mutex(event)); 35 | VKCHECK(vkSetEvent(internal::get_instance(*internal::get_parent(event)), 36 | internal::get_instance(event))); 37 | } 38 | 39 | void reset(const event_type &event) { 40 | std::lock_guard lock(internal::get_mutex(event)); 41 | VKCHECK(vkResetEvent(internal::get_instance(*internal::get_parent(event)), 42 | internal::get_instance(event))); 43 | } 44 | 45 | } // namespace event 46 | } // namespace vcc 47 | 48 | 49 | -------------------------------------------------------------------------------- /vcc/src/fence.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace fence { 20 | 21 | fence_type create(const type::supplier &device, 22 | VkFenceCreateFlags flags) { 23 | VkFenceCreateInfo create = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, NULL}; 24 | create.flags = flags; 25 | VkFence fence; 26 | VKCHECK(vkCreateFence(internal::get_instance(*device), &create, NULL, &fence)); 27 | return fence_type(fence, device); 28 | } 29 | 30 | VkResult wait(const device::device_type &device, 31 | const std::vector> &fences, 32 | bool wait_all, uint64_t timeout) { 33 | std::vector converted_fences; 34 | converted_fences.reserve(fences.size()); 35 | for (const fence_type &fence : fences) { 36 | converted_fences.push_back(internal::get_instance(fence)); 37 | } 38 | VkResult result = vkWaitForFences(internal::get_instance(device), 39 | (uint32_t)fences.size(), converted_fences.data(), !!wait_all, timeout); 40 | if (result != VK_TIMEOUT && result != VK_SUCCESS) { 41 | VKCHECK(result); 42 | } 43 | return result; 44 | } 45 | 46 | VkResult wait(const device::device_type &device, 47 | const std::vector> &fences, 48 | bool wait_all, 49 | std::chrono::nanoseconds timeout) { 50 | return wait(device, fences, wait_all, timeout.count()); 51 | } 52 | 53 | VkResult wait(const device::device_type &device, 54 | const std::vector> &fences, bool wait_all) { 55 | return wait(device, fences, wait_all, UINT64_MAX); 56 | } 57 | 58 | void reset(const device::device_type &device, 59 | const std::vector> &fences) { 60 | std::vector converted_fences; 61 | converted_fences.reserve(fences.size()); 62 | for (const fence_type &fence : fences) { 63 | converted_fences.push_back(internal::get_instance(fence)); 64 | } 65 | std::vector> locks; 66 | locks.reserve(fences.size()); 67 | for (const fence_type &fence : fences) { 68 | locks.emplace_back(internal::get_mutex(fence), std::defer_lock); 69 | } 70 | util::lock(locks); 71 | VKCHECK(vkResetFences(internal::get_instance(device), uint32_t(fences.size()), 72 | converted_fences.data())); 73 | } 74 | 75 | } // namespace fence 76 | } // namespace vcc 77 | -------------------------------------------------------------------------------- /vcc/src/framebuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | namespace vcc { 21 | namespace framebuffer { 22 | 23 | framebuffer_type create(const type::supplier &device, 24 | const type::supplier &render_pass, 25 | const std::vector> &image_views, 26 | VkExtent2D extent, uint32_t layers) { 27 | 28 | VkFramebufferCreateInfo create = { 29 | VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, NULL, 0 }; 30 | create.renderPass = internal::get_instance(*render_pass); 31 | create.attachmentCount = (uint32_t) image_views.size(); 32 | std::vector converted_image_views; 33 | converted_image_views.reserve(image_views.size()); 34 | std::transform(image_views.begin(), image_views.end(), 35 | std::back_inserter(converted_image_views), 36 | [](const type::supplier &image_view) { 37 | return internal::get_instance(*image_view); 38 | }); 39 | create.pAttachments = &converted_image_views.front(); 40 | create.width = extent.width; 41 | create.height = extent.height; 42 | create.layers = layers; 43 | VkFramebuffer framebuffer; 44 | VKCHECK(vkCreateFramebuffer(internal::get_instance(*device), &create, NULL, &framebuffer)); 45 | return framebuffer_type(framebuffer, device, render_pass, image_views); 46 | } 47 | 48 | } // namespace framebuffer 49 | } // namespace vcc 50 | -------------------------------------------------------------------------------- /vcc/src/image_view.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace image_view { 20 | 21 | image_view_type create(const type::supplier &image, 22 | VkImageViewType viewType, VkFormat format, 23 | const VkComponentMapping &components, 24 | const VkImageSubresourceRange &subresourceRange) { 25 | VkImageViewCreateInfo create = {VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, 26 | NULL, 0}; 27 | create.image = vcc::internal::get_instance(*image); 28 | create.viewType = viewType; 29 | create.format = format; 30 | create.components = components; 31 | create.subresourceRange = subresourceRange; 32 | VkImageView image_view; 33 | VKCHECK(vkCreateImageView(internal::get_instance(*internal::get_parent(*image)), &create, NULL, 34 | &image_view)); 35 | return image_view_type(image_view, internal::get_parent(*image), image); 36 | } 37 | 38 | VkImageViewType view_type_from_image_type(VkImageType image_type) { 39 | switch (image_type) { 40 | case VK_IMAGE_TYPE_1D: 41 | return VK_IMAGE_VIEW_TYPE_1D; 42 | case VK_IMAGE_TYPE_2D: 43 | return VK_IMAGE_VIEW_TYPE_2D; 44 | case VK_IMAGE_TYPE_3D: 45 | return VK_IMAGE_VIEW_TYPE_3D; 46 | default: 47 | throw vcc_exception("Unknown VkImageType"); 48 | } 49 | } 50 | 51 | image_view_type create(const type::supplier &image, 52 | const VkImageSubresourceRange &subresourceRange) { 53 | return create(image, view_type_from_image_type(image::get_type(*image)), 54 | image::get_format(*image), 55 | { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, 56 | VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }, 57 | subresourceRange); 58 | } 59 | 60 | } // namespace image_view 61 | } // namespace vcc 62 | -------------------------------------------------------------------------------- /vcc/src/input_buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #define NOMINMAX 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace vcc { 24 | namespace input_buffer { 25 | 26 | bool flush(const input_buffer_type &buffer) { 27 | if (type::dirty(buffer.serialize)) { 28 | std::unique_lock lock(buffer.mutex); 29 | if (type::dirty(buffer.serialize)) { 30 | const memory::map_type map(memory::map( 31 | vcc::internal::get_memory(buffer.buffer), 32 | vcc::internal::get_offset(buffer.buffer), 33 | type::size(buffer.serialize))); 34 | type::flush(buffer.serialize, (uint8_t *)map.data); 35 | return true; 36 | } 37 | } 38 | return false; 39 | } 40 | 41 | bool flush(const queue::queue_type &queue, const input_buffer_type &buffer) { 42 | if (flush(buffer)) { 43 | std::unique_lock lock(buffer.mutex); 44 | type::supplier device(vcc::internal::get_parent(buffer.buffer)); 45 | command_pool::command_pool_type command_pool(command_pool::create(device, 46 | VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queue::get_family_index(queue))); 47 | command_buffer::command_buffer_type command_buffer(std::move(command_buffer::allocate( 48 | device, std::ref(command_pool), VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1).front())); 49 | command::compile( 50 | vcc::command::build(std::ref(command_buffer), 51 | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, VK_FALSE, 0, 0), 52 | command::pipeline_barrier{ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 53 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, {}, 54 | { 55 | command::buffer_memory_barrier_type{ 56 | VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT, 57 | VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED, 58 | std::ref(buffer.buffer) } 59 | }, {} 60 | }); 61 | // Must block until our command finish executing. 62 | fence::fence_type fence(vcc::fence::create(device)); 63 | queue::submit(queue, {}, { command_buffer }, {}, fence); 64 | fence::wait(*device, { fence }, true); 65 | return true; 66 | } else { 67 | return false; 68 | } 69 | } 70 | 71 | } // namespace input_buffer 72 | } // namespace vcc 73 | -------------------------------------------------------------------------------- /vcc/src/instance.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace instance { 20 | 21 | instance_type create(const std::set &layers, const std::set &extensions) { 22 | VkInstanceCreateInfo create_info = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, NULL, 0, 23 | NULL}; 24 | create_info.enabledLayerCount = (uint32_t) layers.size(); 25 | const std::vector layers_pointers(util::to_pointers(layers)); 26 | create_info.ppEnabledLayerNames = layers_pointers.empty() ? NULL : &layers_pointers.front(); 27 | const std::vector extensions_pointers(util::to_pointers(extensions)); 28 | create_info.enabledExtensionCount = (uint32_t) extensions.size(); 29 | create_info.ppEnabledExtensionNames = extensions_pointers.empty() ? NULL : &extensions_pointers.front(); 30 | VkInstance instance; 31 | VKCHECK(vkCreateInstance(&create_info, NULL, &instance)); 32 | return instance_type(instance); 33 | } 34 | 35 | } // namespace instance 36 | } // namespace vcc 37 | 38 | 39 | -------------------------------------------------------------------------------- /vcc/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | /*int main(int argc, const char **argv) { 27 | 28 | auto instance(vcc::instance::create({}, {})); 29 | auto device_enumerate(vcc::physical_device::enumerate(std::ref(instance))); 30 | auto device(std::make_shared(vcc::device::create(device_enumerate.front(), {}, {}, {}, 31 | vcc::physical_device::features(device_enumerate.front())))); 32 | auto shader_module(vcc::shader_module::create(device, std::ifstream("shader.file"))); 33 | return 0; 34 | } 35 | */ 36 | -------------------------------------------------------------------------------- /vcc/src/physical_device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace physical_device { 20 | 21 | std::vector enumerate(const instance::instance_type &instance) { 22 | uint32_t count; 23 | VKCHECK(vkEnumeratePhysicalDevices(internal::get_instance(instance), &count, NULL)); 24 | std::vector devices(count, VK_NULL_HANDLE); 25 | VKCHECK(vkEnumeratePhysicalDevices(internal::get_instance(instance), 26 | &count, devices.data())); 27 | return std::move(devices); 28 | } 29 | 30 | VkPhysicalDeviceMemoryProperties memory_properties(VkPhysicalDevice physical_device) { 31 | VkPhysicalDeviceMemoryProperties properties; 32 | vkGetPhysicalDeviceMemoryProperties(physical_device, &properties); 33 | return properties; 34 | } 35 | 36 | std::vector queue_famility_properties(VkPhysicalDevice physical_device) { 37 | uint32_t count; 38 | vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &count, NULL); 39 | std::vector properties(count); 40 | vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &count, &properties.front()); 41 | return std::move(properties); 42 | } 43 | 44 | uint32_t get_queue_family_properties_with_flag(const std::vector &properties, VkQueueFlags flags) { 45 | for (std::size_t i = 0; i < properties.size(); ++i) { 46 | const VkQueueFamilyProperties &p(properties[i]); 47 | if ((p.queueFlags & flags) == flags) { 48 | return uint32_t(i); 49 | } 50 | } 51 | throw vcc_exception("No queue family found with the given properties."); 52 | } 53 | 54 | } // namespace physical_device 55 | } // namespace vcc 56 | -------------------------------------------------------------------------------- /vcc/src/pipeline_cache.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | namespace vcc { 21 | namespace pipeline_cache { 22 | 23 | pipeline_cache_type create(const type::supplier &device, 24 | const std::string &data) { 25 | VkPipelineCacheCreateInfo create = {VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO, NULL, 0}; 26 | // TODO(gardell): Support 27 | create.initialDataSize = data.size(); 28 | create.pInitialData = &data[0]; 29 | VkPipelineCache cache; 30 | VKCHECK(vkCreatePipelineCache(internal::get_instance(*device), &create, NULL, &cache)); 31 | return pipeline_cache_type(cache, device); 32 | } 33 | 34 | std::string serialize(const pipeline_cache_type &pipeline_cache) { 35 | size_t data_size; 36 | VKCHECK(vkGetPipelineCacheData( 37 | internal::get_instance(*internal::get_parent(pipeline_cache)), 38 | internal::get_instance(pipeline_cache), &data_size, NULL)); 39 | std::string string(data_size, 0); 40 | VKCHECK(vkGetPipelineCacheData( 41 | internal::get_instance(*internal::get_parent(pipeline_cache)), 42 | internal::get_instance(pipeline_cache), &data_size, &string[0])); 43 | return std::move(string); 44 | } 45 | 46 | void merge(const pipeline_cache_type &pipeline_cache, 47 | const std::vector> &source_caches) { 48 | std::vector caches; 49 | caches.reserve(source_caches.size()); 50 | std::transform(source_caches.begin(), source_caches.end(), std::back_inserter(caches), 51 | [](const type::supplier &cache){ 52 | return internal::get_instance(*cache); 53 | }); 54 | std::lock_guard lock(internal::get_mutex(pipeline_cache)); 55 | VKCHECK(vkMergePipelineCaches(internal::get_instance(*internal::get_parent(pipeline_cache)), 56 | internal::get_instance(pipeline_cache), (uint32_t) caches.size(), &caches.front())); 57 | } 58 | 59 | } // namespace pipeline_cache 60 | } // namespace vcc 61 | -------------------------------------------------------------------------------- /vcc/src/sampler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace sampler { 20 | 21 | sampler_type create(const type::supplier &device, 22 | VkFilter magFilter, VkFilter minFilter, VkSamplerMipmapMode mipmapMode, 23 | VkSamplerAddressMode addressModeU, VkSamplerAddressMode addressModeV, 24 | VkSamplerAddressMode addressModeW, float mipLodBias, 25 | VkBool32 anisotropyEnable, float maxAnisotropy, VkBool32 compareEnable, 26 | VkCompareOp compareOp, float minLod, float maxLod, 27 | VkBorderColor borderColor, VkBool32 unnormalizedCoordinates) { 28 | VkSamplerCreateInfo create = {VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, NULL, 0}; 29 | create.magFilter = magFilter; 30 | create.minFilter = minFilter; 31 | create.mipmapMode = mipmapMode; 32 | create.addressModeU = addressModeU; 33 | create.addressModeV = addressModeV; 34 | create.addressModeW = addressModeW; 35 | create.mipLodBias = mipLodBias; 36 | //create.anisotropyEnable = anisotropyEnable; 37 | create.maxAnisotropy = maxAnisotropy; 38 | create.compareEnable = compareEnable; 39 | create.compareOp = compareOp; 40 | create.minLod = minLod; 41 | create.maxLod = maxLod; 42 | create.borderColor = borderColor; 43 | create.unnormalizedCoordinates = unnormalizedCoordinates; 44 | 45 | VkSampler sampler; 46 | VKCHECK(vkCreateSampler(internal::get_instance(*device), &create, NULL, &sampler)); 47 | return sampler_type(sampler, device); 48 | } 49 | 50 | } // namespace sampler 51 | } // namespace vcc 52 | -------------------------------------------------------------------------------- /vcc/src/semaphore.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | namespace vcc { 19 | namespace semaphore { 20 | 21 | semaphore_type create(const type::supplier &device) { 22 | VkSemaphoreCreateInfo create = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, 23 | NULL, 0}; 24 | VkSemaphore semaphore; 25 | VKCHECK(vkCreateSemaphore(internal::get_instance(*device), &create, NULL, &semaphore)); 26 | return semaphore_type(semaphore, device); 27 | } 28 | 29 | } // namespace semaphore 30 | } // namespace vcc 31 | -------------------------------------------------------------------------------- /vcc/src/shader_module.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | 20 | namespace vcc { 21 | namespace shader_module { 22 | 23 | shader_module_type create(const type::supplier &device, 24 | std::istream &&stream) { 25 | std::ostringstream ss; 26 | ss << stream.rdbuf(); 27 | const std::string string(ss.str()); 28 | VkShaderModuleCreateInfo create = {VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, NULL}; 29 | create.pCode = (const uint32_t *) string.c_str(); 30 | assert(stream); 31 | assert(string.size() % 4 == 0); 32 | create.codeSize = string.size(); 33 | 34 | VkShaderModule shader_module; 35 | VKCHECK(vkCreateShaderModule(internal::get_instance(*device), &create, NULL, &shader_module)); 36 | return shader_module_type(shader_module, device); 37 | } 38 | 39 | } // namespace shader_module 40 | } // namespace vcc 41 | 42 | 43 | --------------------------------------------------------------------------------