init
This commit is contained in:
commit
606abdd86f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
target
|
212
Cargo.lock
generated
Normal file
212
Cargo.lock
generated
Normal file
|
@ -0,0 +1,212 @@
|
||||||
|
[root]
|
||||||
|
name = "vk_loader"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ash"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"vk_loader 0.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cmake"
|
||||||
|
version = "0.1.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "enum_primitive"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "example"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"ash 0.1.0",
|
||||||
|
"glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"vk_loader 0.1.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gcc"
|
||||||
|
version = "0.3.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glfw"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"enum_primitive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"glfw-sys 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glfw-sys"
|
||||||
|
version = "3.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "1.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num"
|
||||||
|
version = "0.1.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-complex 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-bigint"
|
||||||
|
version = "0.1.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-complex"
|
||||||
|
version = "0.1.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-iter"
|
||||||
|
version = "0.1.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-rational"
|
||||||
|
version = "0.1.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.1.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-serialize"
|
||||||
|
version = "0.3.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shared_library"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||||
|
"checksum cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "dfcf5bcece56ef953b8ea042509e9dcbdfe97820b7e20d86beb53df30ed94978"
|
||||||
|
"checksum enum_primitive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f79eff5be92a4d7d5bddf7daa7d650717ea71628634efe6ca7bcda85b2183c23"
|
||||||
|
"checksum gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb000abd6df9df4c637f75190297ebe56c1d7e66b56bbf3b4aa7aece15f61a2"
|
||||||
|
"checksum glfw 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b14e68c4ccefdf293ecb65390a5761971b83fcfc54d153a5b73d438327633965"
|
||||||
|
"checksum glfw-sys 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eaff144079cb22d6f17009e29e87c02f5fd6c4669093ce12b0b2faa6027f0d23"
|
||||||
|
"checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f"
|
||||||
|
"checksum libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "23e3757828fa702a20072c37ff47938e9dd331b92fac6e223d26d4b7a55f7ee2"
|
||||||
|
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
|
||||||
|
"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
|
||||||
|
"checksum num 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "d2ee34a0338c16ae67afb55824aaf8852700eb0f77ccd977807ccb7606b295f6"
|
||||||
|
"checksum num-bigint 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "fbc450723a2fe91d332a29edd8660e099b937d29e1a3ebe914e0da3f77ac1ad3"
|
||||||
|
"checksum num-complex 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "8aabbc079e1855ce8415141fee0ebebf171f56505373b3a966e2716ad7c0e555"
|
||||||
|
"checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92"
|
||||||
|
"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c"
|
||||||
|
"checksum num-rational 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "48cdcc9ff4ae2a8296805ac15af88b3d88ce62128ded0cb74ffb63a587502a84"
|
||||||
|
"checksum num-traits 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "95e58eac34596aac30ab134c8a8da9aa2dc99caa4b4b4838e6fc6e298016278f"
|
||||||
|
"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
|
||||||
|
"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b"
|
||||||
|
"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f"
|
||||||
|
"checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a"
|
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"vk_loader",
|
||||||
|
"ash",
|
||||||
|
"examples",
|
||||||
|
]
|
67
LICENSE-APACHE
Normal file
67
LICENSE-APACHE
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
Apache License
|
||||||
|
|
||||||
|
Version 2.0, January 2004
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||||
|
|
||||||
|
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||||
|
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||||
|
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||||
|
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
Copyright 2016 Maik Klein
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
25
LICENSE-MIT
Normal file
25
LICENSE-MIT
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
Copyright (c) 2016 ASH
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any
|
||||||
|
person obtaining a copy of this software and associated
|
||||||
|
documentation files (the "Software"), to deal in the
|
||||||
|
Software without restriction, including without
|
||||||
|
limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software
|
||||||
|
is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice
|
||||||
|
shall be included in all copies or substantial portions
|
||||||
|
of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||||
|
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||||
|
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#ASH
|
||||||
|
|
||||||
|
An experimental wrapper for Vulkan. This library is not stable use [Vulkano](https://github.com/tomaka/vulkano) instead.
|
||||||
|
|
||||||
|
The main goal for this library is to familiarize myself with Vulkan.
|
11
ash/Cargo.toml
Normal file
11
ash/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "ash"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["maik klein <maikklein@googlemail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
lazy_static = "0.2.1"
|
||||||
|
shared_library = "0.1.5"
|
||||||
|
glfw = "0.9.1"
|
||||||
|
|
||||||
|
vk_loader = { version = "0.1.0", path = "../vk_loader"}
|
75
ash/src/extensions.rs
Normal file
75
ash/src/extensions.rs
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
use vk_loader as vk;
|
||||||
|
use std::ffi::{CString, CStr};
|
||||||
|
macro_rules! extensions {
|
||||||
|
($struct_name: ident, $struct_name_prop: ident, $($name: ident => $str_name: expr,)*) => {
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct $struct_name {
|
||||||
|
$(
|
||||||
|
pub $name: bool,
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
impl $struct_name {
|
||||||
|
pub fn empty() -> $struct_name {
|
||||||
|
$struct_name{
|
||||||
|
$(
|
||||||
|
$name: false,
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn extension_list(&self) -> Vec<CString>{
|
||||||
|
let mut vec = Vec::new();
|
||||||
|
$(
|
||||||
|
if self.$name{
|
||||||
|
vec.push(CString::new($str_name).unwrap());
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
vec
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn subset_of(&self, other: &$struct_name) -> bool{
|
||||||
|
$(!self.$name | other.$name)&&+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct $struct_name_prop {
|
||||||
|
pub ext_props: Vec<vk::ExtensionProperties>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<$struct_name_prop> for $struct_name{
|
||||||
|
fn from(ep: $struct_name_prop) -> $struct_name{
|
||||||
|
let mut ext = $struct_name::empty();
|
||||||
|
for ext_prop in ep.ext_props.iter() {
|
||||||
|
let name = unsafe{
|
||||||
|
CStr::from_ptr(ext_prop.extensionName.as_ptr()).to_str().unwrap()
|
||||||
|
};
|
||||||
|
$(
|
||||||
|
if name == $str_name {
|
||||||
|
ext.$name = true;
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
ext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions!{
|
||||||
|
InstanceExtension,
|
||||||
|
InstanceExtensionProperties,
|
||||||
|
khr_surface => "VK_KHR_surface",
|
||||||
|
khr_display => "VK_KHR_display",
|
||||||
|
khr_xlib_surface => "VK_KHR_xlib_surface",
|
||||||
|
khr_xcb_surface => "VK_KHR_xcb_surface",
|
||||||
|
khr_wayland_surface => "VK_KHR_wayland_surface",
|
||||||
|
khr_mir_surface => "VK_KHR_mir_surface",
|
||||||
|
khr_android_surface => "VK_KHR_android_surface",
|
||||||
|
khr_win32_surface => "VK_KHR_win32_surface",
|
||||||
|
khr_ext_debug_report => "VK_EXT_debug_report",
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions! {
|
||||||
|
DeviceExtension,
|
||||||
|
DeviceExtensionProperties,
|
||||||
|
khr_swapchain => "VK_KHR_swapchain",
|
||||||
|
khr_display_swapchain => "VK_KHR_display_swapchain",
|
||||||
|
}
|
115
ash/src/feature.rs
Normal file
115
ash/src/feature.rs
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
use vk_loader as vk;
|
||||||
|
use std::fmt;
|
||||||
|
macro_rules! features{
|
||||||
|
($($name: ident => $vk: ident,)+) => {
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct Features{
|
||||||
|
$(
|
||||||
|
pub $name: bool,
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
impl Features{
|
||||||
|
pub fn empty() -> Features{
|
||||||
|
Features{
|
||||||
|
$(
|
||||||
|
$name: false,
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn subset(&self, other: &Self) -> bool{
|
||||||
|
$((!self.$name | other.$name))&&+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Probably just impl From with a cast?
|
||||||
|
impl From<vk::PhysicalDeviceFeatures> for Features{
|
||||||
|
fn from(features: vk::PhysicalDeviceFeatures) -> Features {
|
||||||
|
Features{
|
||||||
|
$(
|
||||||
|
$name: features.$vk != 0,
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Features> for vk::PhysicalDeviceFeatures {
|
||||||
|
fn from(features: Features) -> vk::PhysicalDeviceFeatures {
|
||||||
|
vk::PhysicalDeviceFeatures{
|
||||||
|
$(
|
||||||
|
$vk: features.$name as u32,
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Features {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
|
||||||
|
$(
|
||||||
|
if self.$name {
|
||||||
|
try!(writeln!(f, "{},", stringify!($name)));
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
writeln!(f, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
features!{
|
||||||
|
robust_buffer_access => robustBufferAccess,
|
||||||
|
full_draw_index_uint32 => fullDrawIndexUint32,
|
||||||
|
image_cube_array => imageCubeArray,
|
||||||
|
independent_blend => independentBlend,
|
||||||
|
geometry_shader => geometryShader,
|
||||||
|
tessellation_shader => tessellationShader,
|
||||||
|
sample_rate_shading => sampleRateShading,
|
||||||
|
dual_src_blend => dualSrcBlend,
|
||||||
|
logic_op => logicOp,
|
||||||
|
multi_draw_indirect => multiDrawIndirect,
|
||||||
|
draw_indirect_first_instance => drawIndirectFirstInstance,
|
||||||
|
depth_clamp => depthClamp,
|
||||||
|
depth_bias_clamp => depthBiasClamp,
|
||||||
|
fill_mode_non_solid => fillModeNonSolid,
|
||||||
|
depth_bounds => depthBounds,
|
||||||
|
wide_lines => wideLines,
|
||||||
|
large_points => largePoints,
|
||||||
|
alpha_to_one => alphaToOne,
|
||||||
|
multi_viewport => multiViewport,
|
||||||
|
sampler_anisotropy => samplerAnisotropy,
|
||||||
|
texture_compression_etc2 => textureCompressionETC2,
|
||||||
|
texture_compression_astc_ldr => textureCompressionASTC_LDR,
|
||||||
|
texture_compression_bc => textureCompressionBC,
|
||||||
|
occlusion_query_precise => occlusionQueryPrecise,
|
||||||
|
pipeline_statistics_query => pipelineStatisticsQuery,
|
||||||
|
vertex_pipeline_stores_and_atomics => vertexPipelineStoresAndAtomics,
|
||||||
|
fragment_stores_and_atomics => fragmentStoresAndAtomics,
|
||||||
|
shader_tessellation_and_geometry_point_size => shaderTessellationAndGeometryPointSize,
|
||||||
|
shader_image_gather_extended => shaderImageGatherExtended,
|
||||||
|
shader_storage_image_extended_formats => shaderStorageImageExtendedFormats,
|
||||||
|
shader_storage_image_multisample => shaderStorageImageMultisample,
|
||||||
|
shader_storage_image_read_without_format => shaderStorageImageReadWithoutFormat,
|
||||||
|
shader_storage_image_write_without_format => shaderStorageImageWriteWithoutFormat,
|
||||||
|
shader_uniform_buffer_array_dynamic_indexing => shaderUniformBufferArrayDynamicIndexing,
|
||||||
|
shader_sampled_image_array_dynamic_indexing => shaderSampledImageArrayDynamicIndexing,
|
||||||
|
shader_storage_buffer_array_dynamic_indexing => shaderStorageBufferArrayDynamicIndexing,
|
||||||
|
shader_storage_image_array_dynamic_indexing => shaderStorageImageArrayDynamicIndexing,
|
||||||
|
shader_clip_distance => shaderClipDistance,
|
||||||
|
shader_cull_distance => shaderCullDistance,
|
||||||
|
shaderf3264 => shaderf3264,
|
||||||
|
shader_int64 => shaderInt64,
|
||||||
|
shader_int16 => shaderInt16,
|
||||||
|
shader_resource_residency => shaderResourceResidency,
|
||||||
|
shader_resource_min_lod => shaderResourceMinLod,
|
||||||
|
sparse_binding => sparseBinding,
|
||||||
|
sparse_residency_buffer => sparseResidencyBuffer,
|
||||||
|
sparse_residency_image_2d => sparseResidencyImage2D,
|
||||||
|
sparse_residency_image_3d => sparseResidencyImage3D,
|
||||||
|
sparse_residency2_samples => sparseResidency2Samples,
|
||||||
|
sparse_residency4_samples => sparseResidency4Samples,
|
||||||
|
sparse_residency8_samples => sparseResidency8Samples,
|
||||||
|
sparse_residency16_samples => sparseResidency16Samples,
|
||||||
|
sparse_residency_aliased => sparseResidencyAliased,
|
||||||
|
variable_multisample_rate => variableMultisampleRate,
|
||||||
|
inherited_queries => inheritedQueries,
|
||||||
|
}
|
371
ash/src/instance.rs
Normal file
371
ash/src/instance.rs
Normal file
|
@ -0,0 +1,371 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
use std::ptr;
|
||||||
|
use std::ffi::*;
|
||||||
|
|
||||||
|
use std::error;
|
||||||
|
use std::fmt;
|
||||||
|
use std::mem;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use vk_loader as vk;
|
||||||
|
use feature;
|
||||||
|
use load;
|
||||||
|
use extensions::*;
|
||||||
|
use std::os::raw::*;
|
||||||
|
use std::cell::Cell;
|
||||||
|
use surface;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct PhysicalDevice {
|
||||||
|
ip: vk::InstancePointers,
|
||||||
|
handle: vk::PhysicalDevice,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DebugCallback {
|
||||||
|
handle: vk::DebugReportCallbackEXT,
|
||||||
|
f: *mut Fn(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PhysicalDevice {
|
||||||
|
pub fn has_surface_support(&self, index: u32, surface: &Surface) -> bool {
|
||||||
|
unsafe {
|
||||||
|
let mut output: u32 = mem::uninitialized();
|
||||||
|
self.ip.GetPhysicalDeviceSurfaceSupportKHR(self.handle,
|
||||||
|
index,
|
||||||
|
surface.handle,
|
||||||
|
&mut output);
|
||||||
|
output != 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_physical_device_infos(&self) -> PhysicalDeviceInfos {
|
||||||
|
PhysicalDeviceInfos {
|
||||||
|
properties: self.get_physical_device_properties(),
|
||||||
|
queue_families: self.get_queue_families(),
|
||||||
|
memory: self.get_memory_properties(),
|
||||||
|
features: self.get_device_features(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_physical_device_properties(&self) -> vk::PhysicalDeviceProperties {
|
||||||
|
unsafe {
|
||||||
|
let mut device_prop: vk::PhysicalDeviceProperties = mem::uninitialized();
|
||||||
|
self.ip.GetPhysicalDeviceProperties(self.handle, &mut device_prop);
|
||||||
|
device_prop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_queue_families(&self) -> Vec<vk::QueueFamilyProperties> {
|
||||||
|
unsafe {
|
||||||
|
let mut queue_count = 0;
|
||||||
|
self.ip
|
||||||
|
.GetPhysicalDeviceQueueFamilyProperties(self.handle,
|
||||||
|
&mut queue_count,
|
||||||
|
ptr::null_mut());
|
||||||
|
let mut queue_families_vec = Vec::with_capacity(queue_count as usize);
|
||||||
|
self.ip
|
||||||
|
.GetPhysicalDeviceQueueFamilyProperties(self.handle,
|
||||||
|
&mut queue_count,
|
||||||
|
queue_families_vec.as_mut_ptr());
|
||||||
|
queue_families_vec.set_len(queue_count as usize);
|
||||||
|
queue_families_vec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_memory_properties(&self) -> vk::PhysicalDeviceMemoryProperties {
|
||||||
|
unsafe {
|
||||||
|
let mut output = mem::uninitialized();
|
||||||
|
self.ip.GetPhysicalDeviceMemoryProperties(self.handle, &mut output);
|
||||||
|
output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_device_features(&self) -> feature::Features {
|
||||||
|
let available_features: vk::PhysicalDeviceFeatures = unsafe {
|
||||||
|
let mut output = mem::uninitialized();
|
||||||
|
self.ip.GetPhysicalDeviceFeatures(self.handle, &mut output);
|
||||||
|
output
|
||||||
|
};
|
||||||
|
feature::Features::from(available_features)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_device(&self,
|
||||||
|
present: u32,
|
||||||
|
ext: &DeviceExtension,
|
||||||
|
features: &feature::Features)
|
||||||
|
-> Device {
|
||||||
|
let f = vk::PhysicalDeviceFeatures::from(*features);
|
||||||
|
let priorities = [1.0];
|
||||||
|
let queue_info = vk::DeviceQueueCreateInfo {
|
||||||
|
sType: vk::STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
||||||
|
pNext: ptr::null(),
|
||||||
|
flags: 0,
|
||||||
|
queueFamilyIndex: present,
|
||||||
|
pQueuePriorities: priorities.as_ptr(),
|
||||||
|
queueCount: priorities.len() as u32,
|
||||||
|
};
|
||||||
|
|
||||||
|
let create_info = vk::DeviceCreateInfo {
|
||||||
|
sType: vk::STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
|
pNext: ptr::null(),
|
||||||
|
flags: 0,
|
||||||
|
queueCreateInfoCount: 1,
|
||||||
|
pQueueCreateInfos: &queue_info,
|
||||||
|
enabledLayerCount: 0,
|
||||||
|
ppEnabledLayerNames: ptr::null(),
|
||||||
|
enabledExtensionCount: 0,
|
||||||
|
ppEnabledExtensionNames: ptr::null(),
|
||||||
|
pEnabledFeatures: ptr::null(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut vk_device = unsafe { mem::uninitialized() };
|
||||||
|
unsafe {
|
||||||
|
assert!(self.ip.CreateDevice(self.handle, &create_info, ptr::null(), &mut vk_device) ==
|
||||||
|
0,
|
||||||
|
"device");
|
||||||
|
}
|
||||||
|
let dp = vk::DevicePointers::load(|name| {
|
||||||
|
unsafe { self.ip.GetDeviceProcAddr(vk_device, name.as_ptr()) as *const _ }
|
||||||
|
});
|
||||||
|
Device {
|
||||||
|
dp: dp,
|
||||||
|
device: vk_device,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PhysicalDeviceInfos {
|
||||||
|
pub properties: vk::PhysicalDeviceProperties,
|
||||||
|
pub queue_families: Vec<vk::QueueFamilyProperties>,
|
||||||
|
pub memory: vk::PhysicalDeviceMemoryProperties,
|
||||||
|
pub features: feature::Features,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PhysicalDeviceInfos {
|
||||||
|
fn has_surface_support(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Instance {
|
||||||
|
pub instance: vk::Instance,
|
||||||
|
pub ip: vk::InstancePointers,
|
||||||
|
callback: Option<DebugCallback>,
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for Instance {}
|
||||||
|
unsafe impl Sync for Instance {}
|
||||||
|
|
||||||
|
impl Drop for Instance {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
if let Some(ref callback) = self.callback {
|
||||||
|
self.ip.DestroyDebugReportCallbackEXT(self.instance, callback.handle, ptr::null());
|
||||||
|
Box::from_raw(callback.f);
|
||||||
|
}
|
||||||
|
self.ip.DestroyInstance(self.instance, ptr::null());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ApplicationInfo {
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Surface<'r> {
|
||||||
|
instance: &'r Instance,
|
||||||
|
handle: vk::SurfaceKHR,
|
||||||
|
}
|
||||||
|
impl<'r> Drop for Surface<'r> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
self.instance.ip.DestroySurfaceKHR(self.instance.instance, self.handle, ptr::null());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Instance {
|
||||||
|
pub fn create_surface<S: surface::Surface>(&self, s: &S) -> Surface {
|
||||||
|
Surface {
|
||||||
|
instance: self,
|
||||||
|
handle: s.create_surface(self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extenstion_properties() -> InstanceExtension {
|
||||||
|
let entry_points = load::entry_points().unwrap();
|
||||||
|
let extension_props = unsafe {
|
||||||
|
let mut num = 0;
|
||||||
|
entry_points.EnumerateInstanceExtensionProperties(ptr::null(), &mut num, ptr::null_mut());
|
||||||
|
let mut data = Vec::with_capacity(num as usize);
|
||||||
|
entry_points.EnumerateInstanceExtensionProperties(ptr::null(), &mut num, data.as_mut_ptr());
|
||||||
|
data.set_len(num as usize);
|
||||||
|
InstanceExtensionProperties { ext_props: data }
|
||||||
|
};
|
||||||
|
extension_props.into()
|
||||||
|
}
|
||||||
|
pub fn device_extension_properties(&self, device: vk::PhysicalDevice) -> DeviceExtension {
|
||||||
|
let extension_props = unsafe {
|
||||||
|
let mut num = 0;
|
||||||
|
self.ip
|
||||||
|
.EnumerateDeviceExtensionProperties(device, ptr::null(), &mut num, ptr::null_mut());
|
||||||
|
let mut data = Vec::with_capacity(num as usize);
|
||||||
|
self.ip.EnumerateDeviceExtensionProperties(device,
|
||||||
|
ptr::null(),
|
||||||
|
&mut num,
|
||||||
|
data.as_mut_ptr());
|
||||||
|
data.set_len(num as usize);
|
||||||
|
DeviceExtensionProperties { ext_props: data }
|
||||||
|
};
|
||||||
|
extension_props.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new<F: Fn(String) + 'static>(app_info: &ApplicationInfo,
|
||||||
|
extensions: &InstanceExtension,
|
||||||
|
f: F)
|
||||||
|
-> Instance {
|
||||||
|
let entry_points = load::entry_points().unwrap();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let mut num = 0;
|
||||||
|
entry_points.EnumerateInstanceLayerProperties(&mut num, ptr::null_mut());
|
||||||
|
|
||||||
|
let mut v = Vec::with_capacity(num as usize);
|
||||||
|
entry_points.EnumerateInstanceLayerProperties(&mut num, v.as_mut_ptr());
|
||||||
|
v.set_len(num as usize);
|
||||||
|
|
||||||
|
for p in v {
|
||||||
|
// println!("layer {}", CStr::from_ptr(p.layerName.as_ptr()).to_str().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let layername = CString::new("VK_LAYER_LUNARG_standard_validation").unwrap();
|
||||||
|
let layer = [layername.as_ptr()];
|
||||||
|
|
||||||
|
let c = CString::new(app_info.name.clone()).unwrap();
|
||||||
|
let raw_name = c.as_ptr();
|
||||||
|
let appinfo = vk::ApplicationInfo {
|
||||||
|
pApplicationName: raw_name,
|
||||||
|
sType: vk::STRUCTURE_TYPE_APPLICATION_INFO,
|
||||||
|
pNext: ptr::null(),
|
||||||
|
applicationVersion: 0,
|
||||||
|
pEngineName: raw_name,
|
||||||
|
engineVersion: 0,
|
||||||
|
apiVersion: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let extension_list = extensions.extension_list();
|
||||||
|
let extension_list_raw =
|
||||||
|
extension_list.iter().map(|extension| extension.as_ptr()).collect::<Vec<_>>();
|
||||||
|
let create_info = vk::InstanceCreateInfo {
|
||||||
|
sType: vk::STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
||||||
|
pApplicationInfo: &appinfo,
|
||||||
|
pNext: ptr::null(),
|
||||||
|
ppEnabledLayerNames: layer.as_ptr(),
|
||||||
|
enabledLayerCount: layer.len() as u32,
|
||||||
|
ppEnabledExtensionNames: extension_list_raw.as_ptr(),
|
||||||
|
enabledExtensionCount: extension_list_raw.len() as u32,
|
||||||
|
flags: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut instance: vk::Instance = unsafe { mem::uninitialized() };
|
||||||
|
unsafe {
|
||||||
|
entry_points.CreateInstance(&create_info, ptr::null(), &mut instance);
|
||||||
|
}
|
||||||
|
let vk: vk::InstancePointers = {
|
||||||
|
let f = load::static_functions().unwrap();
|
||||||
|
vk::InstancePointers::load(|name| unsafe {
|
||||||
|
mem::transmute(f.GetInstanceProcAddr(instance, name.as_ptr()))
|
||||||
|
})
|
||||||
|
};
|
||||||
|
extern "system" fn debug_callback<F: Fn(String)>(flags: vk::DebugReportFlagsEXT,
|
||||||
|
obj: vk::DebugReportObjectTypeEXT,
|
||||||
|
u: u64,
|
||||||
|
u1: usize,
|
||||||
|
i: i32,
|
||||||
|
chars: *const c_char,
|
||||||
|
chars1: *const c_char,
|
||||||
|
data: *mut c_void)
|
||||||
|
-> u32 {
|
||||||
|
unsafe {
|
||||||
|
let f = &*(data as *mut F);
|
||||||
|
f(CStr::from_ptr(chars).to_str().unwrap().to_owned());
|
||||||
|
f(CStr::from_ptr(chars1).to_str().unwrap().to_owned());
|
||||||
|
}
|
||||||
|
1
|
||||||
|
}
|
||||||
|
let raw_boxed_f = Box::into_raw(Box::new(f));
|
||||||
|
let debug = vk::DebugReportCallbackCreateInfoEXT {
|
||||||
|
sType: 1000011000,
|
||||||
|
pNext: ptr::null(),
|
||||||
|
flags: vk::DEBUG_REPORT_ERROR_BIT_EXT | vk::DEBUG_REPORT_WARNING_BIT_EXT,
|
||||||
|
pfnCallback: debug_callback::<F>,
|
||||||
|
pUserData: raw_boxed_f as *mut c_void,
|
||||||
|
};
|
||||||
|
let callback = unsafe {
|
||||||
|
let mut callback: vk::DebugReportCallbackEXT = mem::uninitialized();
|
||||||
|
|
||||||
|
assert!(vk.CreateDebugReportCallbackEXT(instance,
|
||||||
|
&debug,
|
||||||
|
ptr::null(),
|
||||||
|
&mut callback) == 0,
|
||||||
|
"Debug");
|
||||||
|
|
||||||
|
DebugCallback {
|
||||||
|
f: raw_boxed_f,
|
||||||
|
handle: callback,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Instance {
|
||||||
|
ip: vk,
|
||||||
|
instance: instance,
|
||||||
|
callback: Some(callback),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_pysical_devices(&self) -> Vec<PhysicalDevice> {
|
||||||
|
unsafe {
|
||||||
|
let mut num = 0;
|
||||||
|
self.ip
|
||||||
|
.EnumeratePhysicalDevices(self.instance, &mut num, ptr::null_mut());
|
||||||
|
let mut physical_devices = Vec::<vk::PhysicalDevice>::with_capacity(num as usize);
|
||||||
|
self.ip
|
||||||
|
.EnumeratePhysicalDevices(self.instance, &mut num, physical_devices.as_mut_ptr());
|
||||||
|
physical_devices.set_len(num as usize);
|
||||||
|
physical_devices.into_iter()
|
||||||
|
.map(|handle| {
|
||||||
|
PhysicalDevice {
|
||||||
|
ip: self.ip.clone(),
|
||||||
|
handle: handle,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Queue {
|
||||||
|
handle: vk::Queue,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Device {
|
||||||
|
dp: vk::DevicePointers,
|
||||||
|
device: vk::Device,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Device {
|
||||||
|
pub fn get_device_queue(&self, family: u32, index: u32) -> Queue {
|
||||||
|
unsafe {
|
||||||
|
let mut queue = mem::uninitialized();
|
||||||
|
self.dp.GetDeviceQueue(self.device, family, index, &mut queue);
|
||||||
|
Queue { handle: queue }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for Device {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
self.dp.DestroyDevice(self.device, ptr::null());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
ash/src/lib.rs
Normal file
11
ash/src/lib.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#[macro_use]
|
||||||
|
extern crate lazy_static;
|
||||||
|
extern crate shared_library;
|
||||||
|
extern crate vk_loader;
|
||||||
|
extern crate glfw;
|
||||||
|
|
||||||
|
pub mod load;
|
||||||
|
pub mod extensions;
|
||||||
|
pub mod surface;
|
||||||
|
pub mod instance;
|
||||||
|
pub mod feature;
|
117
ash/src/load.rs
Normal file
117
ash/src/load.rs
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
// Copyright (c) 2016 The vulkano developers
|
||||||
|
// Licensed under the Apache License, Version 2.0
|
||||||
|
// <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT
|
||||||
|
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
|
||||||
|
// at your option. All files in the project carrying such
|
||||||
|
// notice may not be copied, modified, or distributed except
|
||||||
|
// according to those terms.
|
||||||
|
|
||||||
|
use std::error;
|
||||||
|
use std::fmt;
|
||||||
|
use std::mem;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
|
use shared_library;
|
||||||
|
use vk_loader as vk;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref VK_LIB: Result<shared_library::dynamic_library::DynamicLibrary, LoadingError> = {
|
||||||
|
#[cfg(windows)] fn get_path() -> &'static Path { Path::new("vulkan-1.dll") }
|
||||||
|
#[cfg(all(unix, not(target_os = "android")))] fn get_path() -> &'static Path { Path::new("libvulkan.so.1") }
|
||||||
|
#[cfg(target_os = "android")] fn get_path() -> &'static Path { Path::new("libvulkan.so") }
|
||||||
|
let path = get_path();
|
||||||
|
shared_library::dynamic_library::DynamicLibrary::open(Some(path))
|
||||||
|
.map_err(|err| LoadingError::LibraryLoadFailure(err))
|
||||||
|
};
|
||||||
|
|
||||||
|
static ref VK_STATIC: Result<vk::Static, LoadingError> = {
|
||||||
|
match *VK_LIB {
|
||||||
|
Ok(ref lib) => {
|
||||||
|
let mut err = None;
|
||||||
|
let result = vk::Static::load(|name| unsafe {
|
||||||
|
let name = name.to_str().unwrap();
|
||||||
|
match lib.symbol(name) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(_) => { // TODO: return error?
|
||||||
|
err = Some(LoadingError::MissingEntryPoint(name.to_owned()));
|
||||||
|
ptr::null()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(err) = err {
|
||||||
|
Err(err)
|
||||||
|
} else {
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(ref err) => Err(err.clone()),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static ref VK_ENTRY: Result<vk::EntryPoints, LoadingError> = {
|
||||||
|
match *VK_STATIC {
|
||||||
|
Ok(ref lib) => {
|
||||||
|
// At this point we assume that if one of the functions fails to load, it is an
|
||||||
|
// implementation bug and not a real-life situation that could be handled by
|
||||||
|
// an error.
|
||||||
|
Ok(vk::EntryPoints::load(|name| unsafe {
|
||||||
|
mem::transmute(lib.GetInstanceProcAddr(0, name.as_ptr()))
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
Err(ref err) => Err(err.clone()),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the collection of static functions from the Vulkan loader, or an error if failed to
|
||||||
|
/// open the loader.
|
||||||
|
pub fn static_functions() -> Result<&'static vk::Static, LoadingError> {
|
||||||
|
VK_STATIC.as_ref().map_err(|err| err.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the collection of Vulkan entry points from the Vulkan loader, or an error if failed to
|
||||||
|
/// open the loader.
|
||||||
|
pub fn entry_points() -> Result<&'static vk::EntryPoints, LoadingError> {
|
||||||
|
VK_ENTRY.as_ref().map_err(|err| err.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Error that can happen when loading the Vulkan loader.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum LoadingError {
|
||||||
|
/// Failed to load the Vulkan shared library.
|
||||||
|
LibraryLoadFailure(String), /* TODO: meh for error type, but this needs changes in shared_library */
|
||||||
|
|
||||||
|
/// One of the entry points required to be supported by the Vulkan implementation is missing.
|
||||||
|
MissingEntryPoint(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl error::Error for LoadingError {
|
||||||
|
#[inline]
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
match *self {
|
||||||
|
LoadingError::LibraryLoadFailure(_) => "failed to load the Vulkan shared library",
|
||||||
|
LoadingError::MissingEntryPoint(_) => {
|
||||||
|
"one of the entry points required to be supported by the Vulkan implementation \
|
||||||
|
is missing"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[inline]
|
||||||
|
// fn cause(&self) -> Option<&error::Error> {
|
||||||
|
// match *self {
|
||||||
|
// LoadingError::LibraryLoadFailure(ref err) => Some(err),
|
||||||
|
// _ => None
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for LoadingError {
|
||||||
|
#[inline]
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
write!(fmt, "{}", error::Error::description(self))
|
||||||
|
}
|
||||||
|
}
|
28
ash/src/surface.rs
Normal file
28
ash/src/surface.rs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
use vk_loader as vk;
|
||||||
|
use glfw::*;
|
||||||
|
use std::mem;
|
||||||
|
use instance::Instance;
|
||||||
|
use std::ptr;
|
||||||
|
use std::os::raw::c_void;
|
||||||
|
pub trait Surface {
|
||||||
|
fn create_surface(&self, inst: &Instance) -> vk::SurfaceKHR;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Surface for Window {
|
||||||
|
fn create_surface(&self, inst: &Instance) -> vk::SurfaceKHR {
|
||||||
|
unsafe {
|
||||||
|
let x11_display = self.glfw.get_x11_display();
|
||||||
|
let x11_window = self.get_x11_window();
|
||||||
|
let mut surface: vk::SurfaceKHR = mem::uninitialized();
|
||||||
|
let create_info = vk::XlibSurfaceCreateInfoKHR {
|
||||||
|
sType: vk::STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
|
||||||
|
pNext: ptr::null(),
|
||||||
|
flags: 0,
|
||||||
|
window: x11_window as *mut c_void,
|
||||||
|
dpy: x11_display as *mut c_void,
|
||||||
|
};
|
||||||
|
inst.ip.CreateXlibSurfaceKHR(inst.instance, &create_info, ptr::null(), &mut surface);
|
||||||
|
surface
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
examples/Cargo.toml
Normal file
9
examples/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "example"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["maik klein <maikklein@googlemail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
glfw = "0.9.1"
|
||||||
|
vk_loader = { version = "0.1.0", path = "../vk_loader"}
|
||||||
|
ash = { version = "0.1.0", path = "../ash"}
|
45
examples/src/main.rs
Normal file
45
examples/src/main.rs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
extern crate ash;
|
||||||
|
extern crate vk_loader;
|
||||||
|
extern crate glfw;
|
||||||
|
|
||||||
|
use ash::instance::*;
|
||||||
|
use vk_loader as vk;
|
||||||
|
use ash::extensions::*;
|
||||||
|
use glfw::*;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::thread;
|
||||||
|
fn main() {
|
||||||
|
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
|
||||||
|
|
||||||
|
let (mut window, events) =
|
||||||
|
glfw.create_window(300, 300, "Hello this is window", glfw::WindowMode::Windowed)
|
||||||
|
.expect("Failed to create GLFW window.");
|
||||||
|
|
||||||
|
let ext = Instance::extenstion_properties();
|
||||||
|
let app_info = ApplicationInfo { name: "Test".to_owned() };
|
||||||
|
let instance = Arc::new(Instance::new(&app_info, &ext, |s| println!("{}", s)));
|
||||||
|
let surface = instance.create_surface(&window);
|
||||||
|
let pdevices = instance.get_pysical_devices();
|
||||||
|
let device_infos: Vec<PhysicalDeviceInfos> =
|
||||||
|
pdevices.iter().map(|pd| pd.get_physical_device_infos()).collect();
|
||||||
|
let suiteable_devices: Vec<_> = device_infos.iter().filter(|infos| true).collect();
|
||||||
|
assert!(suiteable_devices.len() > 0);
|
||||||
|
let pdevice = pdevices[0].clone();
|
||||||
|
let dext = DeviceExtension { khr_swapchain: true, ..DeviceExtension::empty() };
|
||||||
|
let features = device_infos[0].features;
|
||||||
|
let index = device_infos[0]
|
||||||
|
.queue_families
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|&(index, q)| {
|
||||||
|
q.queueCount > 0 && (q.queueFlags & vk::QUEUE_GRAPHICS_BIT) != 0 &&
|
||||||
|
pdevice.has_surface_support(index as u32, &surface)
|
||||||
|
})
|
||||||
|
.map(|(index, q)| index)
|
||||||
|
.nth(0)
|
||||||
|
.expect("Unable to find suitable device") as u32;
|
||||||
|
let ldevice = pdevice.create_device(index, &dext, &features);
|
||||||
|
|
||||||
|
let q = ldevice.get_device_queue(index, 0);
|
||||||
|
}
|
1
vk_loader/.gitignore
vendored
Normal file
1
vk_loader/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
target
|
38
vk_loader/Cargo.lock
generated
Normal file
38
vk_loader/Cargo.lock
generated
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
[root]
|
||||||
|
name = "rvk"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"vk-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shared_library"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vk-sys"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
"checksum lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f"
|
||||||
|
"checksum libc 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "23e3757828fa702a20072c37ff47938e9dd331b92fac6e223d26d4b7a55f7ee2"
|
||||||
|
"checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a"
|
||||||
|
"checksum vk-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19fac1055c66087e0a0ccfae6aeed561ab8efb5f3759229615007c9b148108af"
|
8
vk_loader/Cargo.toml
Normal file
8
vk_loader/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "vk_loader"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["maik klein <maikklein@googlemail.com>"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
shared_library = "0.1.5"
|
2604
vk_loader/src/lib.rs
Normal file
2604
vk_loader/src/lib.rs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue