diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..149b5351f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.mtl binary +*.obj binary diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..623e0c996 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Issue or enhancement in wgpu-core + url: https://github.com/gfx-rs/wgpu/issues/new/choose + about: Issues with or enhancements for the core logic, validation, or the backends should go here. + - name: Question about wgpu + url: https://github.com/gfx-rs/wgpu-rs/discussions/new + about: Any questions about how to use wgpu should go here. diff --git a/.github/ISSUE_TEMPLATE/other.md b/.github/ISSUE_TEMPLATE/other.md index 52ef2e8a4..ea2d87974 100644 --- a/.github/ISSUE_TEMPLATE/other.md +++ b/.github/ISSUE_TEMPLATE/other.md @@ -4,7 +4,4 @@ about: Strange things you want to tell us title: '' labels: question assignees: '' - --- - - diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4988231b1..4961a9fed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,13 +34,18 @@ jobs: - name: Additional core features run: cargo check --manifest-path wgpu-core/Cargo.toml --features trace --target ${{ env.TARGET }} - webgl_build: + wasm: name: Web Assembly runs-on: ubuntu-18.04 + env: + RUSTFLAGS: --cfg=web_sys_unstable_apis steps: - - uses: actions/checkout@v2 - - run: rustup target add wasm32-unknown-unknown - - run: cargo build --manifest-path wgpu-core/Cargo.toml --target wasm32-unknown-unknown + - uses: actions/checkout@v2 + - run: rustup target add wasm32-unknown-unknown + - name: Check WebGPU + run: cargo check --all-targets --target=wasm32-unknown-unknown + - name: Check WebGL + run: cargo check --all-targets --target=wasm32-unknown-unknown --features webgl build: name: ${{ matrix.name }} @@ -117,6 +122,20 @@ jobs: - if: matrix.channel == 'nightly' run: cargo test -- --nocapture + docs: + runs-on: [ubuntu-18.04] + steps: + - uses: actions/checkout@v2 + - name: Install latest nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + continue-on-error: true + - name: cargo doc + run: cargo --version; cargo doc --no-deps + continue-on-error: true + lint: name: Clippy runs-on: ubuntu-latest @@ -132,3 +151,7 @@ jobs: with: command: clippy args: -- -D warnings + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 000000000..8aaf466b8 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,45 @@ +name: Documentation + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Install latest nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + continue-on-error: true + + - name: Add EGL for OpenGL + run: | + sudo apt-get update -y -qq + sudo apt-get install -y -qq libegl1-mesa-dev + + - name: Build the docs (nightly) + run: | + cargo +nightly doc --lib --all-features + + - name: Build the docs (stable) + run: cargo +stable doc --lib --all-features + if: ${{ failure() }} + + - name: Deploy the docs + uses: JamesIves/github-pages-deploy-action@releases/v3 + with: + ACCESS_TOKEN: ${{ secrets.WEB_DEPLOY }} + FOLDER: target/doc + REPOSITORY_NAME: gfx-rs/wgpu-rs.github.io + BRANCH: master + TARGET_FOLDER: doc diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..b1ebd4c66 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,47 @@ +name: Publish + +on: + push: + branches: + - gecko + +env: + RUSTFLAGS: --cfg=web_sys_unstable_apis + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Install Rust WASM toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: wasm32-unknown-unknown + + - name: Build the examples + run: cargo build --release --target wasm32-unknown-unknown --examples + + - name: Install wasm-bindgen-cli + run: cargo install wasm-bindgen-cli + + - name: Generate JS bindings for the examples + run: | + for i in target/wasm32-unknown-unknown/release/examples/*.wasm; + do + wasm-bindgen --no-typescript --out-dir target/generated --web "$i"; + done + + - name: Deploy the examples + uses: JamesIves/github-pages-deploy-action@releases/v3 + with: + ACCESS_TOKEN: ${{ secrets.WEB_DEPLOY }} + FOLDER: target/generated + REPOSITORY_NAME: gfx-rs/wgpu-rs.github.io + BRANCH: master + TARGET_FOLDER: examples/wasm diff --git a/.gitignore b/.gitignore index c5b453f50..2f516ba67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,17 @@ -/target +# Generated by Cargo +# will have compiled files and executables +/target/ + +# These are backup files generated by rustfmt **/*.rs.bk -#Cargo.lock + +# Other .fuse_hidden* .DS_Store + +# IDE/Editor configuration files .vscode -.vs .idea + +# Output from capture example +wgpu/red.png diff --git a/wgpu/CHANGELOG.md b/wgpu/CHANGELOG.md new file mode 100644 index 000000000..dcfb7660c --- /dev/null +++ b/wgpu/CHANGELOG.md @@ -0,0 +1,19 @@ +# Change Log + +### v0.8 (2021-04-29) +- See https://github.com/gfx-rs/wgpu/blob/v0.8/CHANGELOG.md#v08-2021-04-29 +- Naga is the default shader conversion path on Metal, Vulkan, and OpenGL +- SPIRV-Cross is optionally enabled with "cross" feature +- All of the examples (except "texture-array") now use WGSL + +### v0.7 (2021-01-31) +- See https://github.com/gfx-rs/wgpu/blob/v0.7/CHANGELOG.md#v07-2020-08-30 +- Features: + - (beta) WGSL support + - better error messages +- API changes: + - new `ShaderModuleDescriptor` + - new `RenderEncoder` + +### v0.6.2 (2020-11-24) +- don't panic in the staging belt if the channel is dropped diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml new file mode 100644 index 000000000..af6a99906 --- /dev/null +++ b/wgpu/Cargo.toml @@ -0,0 +1,247 @@ +[package] +name = "wgpu" +version = "0.8.0" +authors = ["wgpu developers"] +edition = "2018" +description = "Rusty WebGPU API wrapper" +homepage = "https://github.com/gfx-rs/wgpu-rs" +repository = "https://github.com/gfx-rs/wgpu-rs" +keywords = ["graphics"] +license = "MPL-2.0" +exclude = ["etc/**/*", "examples/**/*", "tests/**/*", "Cargo.lock", "target/**/*"] + +[package.metadata.docs.rs] +all-features = true + +[lib] + +[features] +default = [] +trace = ["serde", "wgc/trace"] +replay = ["serde", "wgc/replay"] +webgl = ["wgc"] +# Enable SPIRV-Cross +cross = ["wgc/cross"] + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] +package = "wgpu-core" +git = "https://github.com/gfx-rs/wgpu" +rev = "eadaa1b7d8f585761e28445904fe619b180aca0d" +features = ["raw-window-handle"] + +[target.'cfg(target_arch = "wasm32")'.dependencies.wgc] +package = "wgpu-core" +git = "https://github.com/gfx-rs/wgpu" +rev = "eadaa1b7d8f585761e28445904fe619b180aca0d" +features = ["raw-window-handle"] +optional = true + +[dependencies.wgt] +package = "wgpu-types" +git = "https://github.com/gfx-rs/wgpu" +rev = "eadaa1b7d8f585761e28445904fe619b180aca0d" + +[dependencies] +arrayvec = "0.5" +log = "0.4" +parking_lot = "0.11" +raw-window-handle = "0.3" +serde = { version = "1", features = ["derive"], optional = true } +smallvec = "1" + +[dev-dependencies] +bytemuck = { version = "1.4", features = ["derive"] } +cgmath = "0.18" +ddsfile = "0.4" +log = "0.4" +noise = "0.7" +obj = "0.10" +png = "0.16" +rand = { version = "0.7.2", features = ["wasm-bindgen"] } +winit = { version = "0.24", features = ["web-sys"] } + +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +async-executor = "1.0" +pollster = "0.2" +env_logger = "0.8" + +# used to test all the example shaders +[dev-dependencies.naga] +git = "https://github.com/gfx-rs/naga" +tag = "gfx-25" +features = ["wgsl-in"] + +# used to generate SPIR-V for the Web target +[target.'cfg(target_arch = "wasm32")'.dependencies.naga] +git = "https://github.com/gfx-rs/naga" +tag = "gfx-25" +features = ["wgsl-in", "spv-out"] + +[[example]] +name="hello-compute" +path="examples/hello-compute/main.rs" +test = true + +[patch."https://github.com/gfx-rs/wgpu"] +#wgpu-types = { path = "../wgpu/wgpu-types" } +#wgpu-core = { path = "../wgpu/wgpu-core" } + +[patch."https://github.com/gfx-rs/subscriber"] +#wgpu-subscriber = { version = "0.1", path = "../subscriber" } + +[patch."https://github.com/gfx-rs/naga"] +#naga = { path = "../naga" } + +[patch."https://github.com/zakarumych/gpu-descriptor"] +#gpu-descriptor = { path = "../gpu-descriptor/gpu-descriptor" } + +[patch."https://github.com/zakarumych/gpu-alloc"] +#gpu-alloc = { path = "../gpu-alloc/gpu-alloc" } + +[patch."https://github.com/gfx-rs/gfx"] +#gfx-hal = { path = "../gfx/src/hal" } +#gfx-backend-empty = { path = "../gfx/src/backend/empty" } +#gfx-backend-vulkan = { path = "../gfx/src/backend/vulkan" } +#gfx-backend-gl = { path = "../gfx/src/backend/gl" } +#gfx-backend-dx12 = { path = "../gfx/src/backend/dx12" } +#gfx-backend-dx11 = { path = "../gfx/src/backend/dx11" } +#gfx-backend-metal = { path = "../gfx/src/backend/metal" } + +[patch.crates-io] +#web-sys = { path = "../wasm-bindgen/crates/web-sys" } +#js-sys = { path = "../wasm-bindgen/crates/js-sys" } +#wasm-bindgen = { path = "../wasm-bindgen" } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +wasm-bindgen = "0.2.73" # remember to change version in wiki as well +web-sys = { version = "=0.3.50", features = [ + "Document", + "Navigator", + "Node", + "NodeList", + "Gpu", + "GpuAdapter", + "GpuAdapterFeatures", + "GpuAdapterLimits", + "GpuAddressMode", + "GpuBindGroup", + "GpuBindGroupDescriptor", + "GpuBindGroupEntry", + "GpuBindGroupLayout", + "GpuBindGroupLayoutDescriptor", + "GpuBindGroupLayoutEntry", + "GpuBlendComponent", + "GpuBlendFactor", + "GpuBlendOperation", + "GpuBlendState", + "GpuBuffer", + "GpuBufferBinding", + "GpuBufferBindingLayout", + "GpuBufferBindingType", + "GpuBufferDescriptor", + "GpuBufferUsage", + "GpuCanvasContext", + "GpuColorDict", + "GpuColorTargetState", + "GpuColorWrite", + "GpuCommandBuffer", + "GpuCommandBufferDescriptor", + "GpuCommandEncoder", + "GpuCommandEncoderDescriptor", + "GpuCompareFunction", + "GpuCompilationInfo", + "GpuCompilationMessage", + "GpuCompilationMessageType", + "GpuComputePassDescriptor", + "GpuComputePassEncoder", + "GpuComputePipeline", + "GpuComputePipelineDescriptor", + "GpuCullMode", + "GpuDepthStencilState", + "GpuDevice", + "GpuDeviceDescriptor", + "GpuDeviceLostInfo", + "GpuDeviceLostReason", + "GpuErrorFilter", + "GpuExtent3dDict", + "GpuFeatureName", + "GpuFilterMode", + "GpuFragmentState", + "GpuFrontFace", + "GpuImageCopyBuffer", + "GpuImageCopyImageBitmap", + "GpuImageCopyTexture", + "GpuImageDataLayout", + "GpuIndexFormat", + "GpuInputStepMode", + "GpuLoadOp", + "GpuMapMode", + "GpuMultisampleState", + "GpuObjectDescriptorBase", + "GpuOrigin2dDict", + "GpuOrigin3dDict", + "GpuOutOfMemoryError", + "GpuPipelineDescriptorBase", + "GpuPipelineLayout", + "GpuPipelineLayoutDescriptor", + "GpuPipelineStatisticName", + "GpuPowerPreference", + "GpuPrimitiveState", + "GpuPrimitiveTopology", + "GpuProgrammableStage", + "GpuQuerySet", + "GpuQuerySetDescriptor", + "GpuQueryType", + "GpuQueue", + "GpuRenderBundle", + "GpuRenderBundleDescriptor", + "GpuRenderBundleEncoder", + "GpuRenderBundleEncoderDescriptor", + "GpuRenderPassColorAttachment", + "GpuRenderPassDepthStencilAttachment", + "GpuRenderPassDescriptor", + "GpuRenderPassEncoder", + "GpuRenderPipeline", + "GpuRenderPipelineDescriptor", + "GpuRequestAdapterOptions", + "GpuSampler", + "GpuSamplerBindingLayout", + "GpuSamplerBindingType", + "GpuSamplerDescriptor", + "GpuShaderModule", + "GpuShaderModuleDescriptor", + "GpuShaderStage", + "GpuStencilFaceState", + "GpuStencilOperation", + "GpuStorageTextureAccess", + "GpuStorageTextureBindingLayout", + "GpuStoreOp", + "GpuSwapChain", + "GpuSwapChainDescriptor", + "GpuTexture", + "GpuTextureAspect", + "GpuTextureBindingLayout", + "GpuTextureDescriptor", + "GpuTextureDimension", + "GpuTextureFormat", + "GpuTextureSampleType", + "GpuTextureUsage", + "GpuTextureView", + "GpuTextureViewDescriptor", + "GpuTextureViewDimension", + "GpuUncapturedErrorEvent", + "GpuUncapturedErrorEventInit", + "GpuValidationError", + "GpuVertexAttribute", + "GpuVertexBufferLayout", + "GpuVertexFormat", + "GpuVertexState", + "HtmlCanvasElement", + "Window", +]} +js-sys = "0.3.50" +wasm-bindgen-futures = "0.4.23" + +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +console_error_panic_hook = "0.1.6" +console_log = "0.1.2" diff --git a/wgpu/LICENSE b/wgpu/LICENSE new file mode 100644 index 000000000..a612ad981 --- /dev/null +++ b/wgpu/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/wgpu/Makefile b/wgpu/Makefile new file mode 100644 index 000000000..73d1d3b15 --- /dev/null +++ b/wgpu/Makefile @@ -0,0 +1,20 @@ +# This Makefile generates SPIR-V shaders from GLSL shaders in the examples. + +shader_compiler = glslangValidator + +# All input shaders. +glsls = $(wildcard examples/*/*.vert examples/*/*.frag examples/*/*.comp) + +# All SPIR-V targets. +spirvs = $(addsuffix .spv,$(glsls)) + +.PHONY: default +default: $(spirvs) + +# Rule for making a SPIR-V target. +$(spirvs): %.spv: % + $(shader_compiler) -V $< -o $@ + +.PHONY: clean +clean: + rm -f $(spirvs) diff --git a/wgpu/README.md b/wgpu/README.md new file mode 100644 index 000000000..dbc5c9294 --- /dev/null +++ b/wgpu/README.md @@ -0,0 +1,101 @@ + + +# wgpu-rs + +[![Build Status](https://github.com/gfx-rs/wgpu-rs/workflows/CI/badge.svg?branch=master)](https://github.com/gfx-rs/wgpu-rs/actions) +[![Crates.io](https://img.shields.io/crates/v/wgpu.svg)](https://crates.io/crates/wgpu) +[![Docs.rs](https://docs.rs/wgpu/badge.svg)](https://docs.rs/wgpu) + +[![Matrix](https://img.shields.io/badge/Dev_Matrix-%23wgpu%3Amatrix.org-blueviolet.svg)](https://matrix.to/#/#wgpu:matrix.org) +[![Matrix](https://img.shields.io/badge/User_Matrix-%23wgpu--users%3Amatrix.org-blueviolet.svg)](https://matrix.to/#/#wgpu-users:matrix.org) + +wgpu-rs is an idiomatic Rust wrapper over [wgpu-core](https://github.com/gfx-rs/wgpu). It's designed to be suitable for general purpose graphics and computation needs of Rust community. + +wgpu-rs can target both the natively supported backends and WASM directly. + +See our [gallery](https://wgpu.rs/#showcase) and the [wiki page](https://github.com/gfx-rs/wgpu-rs/wiki/Applications-and-Libraries) for the list of libraries and applications using `wgpu-rs`. + +## Usage + +### How to Run Examples + +All examples are located under the [examples](examples) directory. + +These examples use the default syntax for running examples, as found in the [Cargo](https://doc.rust-lang.org/cargo/reference/manifest.html#examples) documentation. For example, to run the `cube` example: + +```bash +cargo run --example cube +``` + +The `hello*` examples show bare-bones setup without any helper code. For `hello-compute`, pass 4 numbers separated by spaces as arguments: + +```bash +cargo run --example hello-compute 1 2 3 4 +``` + +The following environment variables can be used to configure how the framework examples run: + +- `WGPU_BACKEND` + + Options: `vulkan`, `metal`, `dx11`, `dx12`, `gl`, `webgpu` + + If unset a default backend is chosen based on what is supported + by your system. + +- `WGPU_POWER_PREF` + + Options: `low`, `high` + + If unset a low power adapter is preferred. + +#### Run Examples on the Web (`wasm32-unknown-unknown`) + +See [wiki article](https://github.com/gfx-rs/wgpu-rs/wiki/Running-on-the-Web-with-WebGPU-and-WebGL). + +## Logging + +`wgpu-core` uses `tracing` for logging and `wgpu-rs` uses `log` for logging. + +### Simple Setup + +If you just want log messages to show up and to use the chrome tracing infrastructure, +take a dependency on the `wgpu-subscriber` crate then call `initialize_default_subscriber`. It will +set up logging to stdout/stderr based on the `RUST_LOG` environment variable. + +### Manual Conversion + +`tracing` also has tools available to convert all `tracing` events into `log` events and vise versa. + +#### `log` events -> `tracing` events + +The `tracing_log` crate has a `log` logger to translate all events into `tracing` events. Call: + +```rust +tracing_log::LogTracer::init().unwrap() +``` + +#### `tracing` events -> `log` events + +The `tracing` crate has a `log` feature which will automatically use `log` if no subscriber is added: + +```toml +tracing = { version = "0.1", features = ["log"] } +``` + +If you want events to be handled both by `tracing` and `log`, enable the `log-always` feature of `tracing`: + +```toml +tracing = { version = "0.1", features = ["log-always"] } +``` + +## Development + +If you need to test local fixes to gfx or other dependencies, the simplest way is to add a Cargo patch. For example, when working on DX12 backend on Windows, you can check out the latest release branch in the [gfx-hal repository](https://github.com/gfx-rs/gfx) (e.g. currently `hal-0.8`) and add this patch to the end of `Cargo.toml`: + +```toml +[patch."https://github.com/gfx-rs/gfx"] +gfx-backend-dx12 = { path = "../gfx/src/backend/dx12" } +gfx-hal = { path = "../gfx/src/hal" } +``` + +If a version needs to be changed, you need to do `cargo update -p gfx-backend-dx12`. diff --git a/wgpu/bors.toml b/wgpu/bors.toml new file mode 100644 index 000000000..aaa83cfb8 --- /dev/null +++ b/wgpu/bors.toml @@ -0,0 +1,7 @@ +status = [ + "build (macos-10.15)", + "build (ubuntu-18.04)", + "build (windows-2019)", + "wasm", + "docs", +] diff --git a/wgpu/examples/README.md b/wgpu/examples/README.md new file mode 100644 index 000000000..46eeefebd --- /dev/null +++ b/wgpu/examples/README.md @@ -0,0 +1,56 @@ +## Structure + +For the simplest examples without using any helping code (see `framework.rs` here), check out: + - `hello ` for printing adapter information + - `hello-triangle` for graphics and presentation + - `hello-compute` for pure computing + +Notably, `capture` example shows rendering without a surface/window. It reads back the contents and saves them to a file. + +All the examples use [WGSL](https://gpuweb.github.io/gpuweb/wgsl.html) shaders unless specified otherwise. + +All framework-based examples render to the window. + +## Feature matrix +| Feature | boids | bunnymark | cube | mipmap | msaa-line | shadow | skybox | texture-arrays | water | conservative-raster | +| ---------------------------- | ------ | --------- | ------ | ------ | --------- | ------ | ------ | -------------- | ------ | ------------------- | +| vertex attributes | :star: | | :star: | | :star: | :star: | :star: | :star: | :star: | | +| instancing | :star: | | | | | | | | | | +| lines and points | | | | | :star: | | | | | :star: | +| dynamic buffer offsets | | :star: | | | | :star: | | | | | +| implicit layout | | | | :star: | | | | | | | +| sampled color textures | :star: | :star: | :star: | :star: | | | :star: | :star: | :star: | :star: | +| storage textures | :star: | | | | | | | | | | +| binding array | | | | | | | | :star: | | | +| comparison samplers | | | | | | :star: | | | | | +| subresource views | | | | :star: | | :star: | | | | | +| cubemaps | | | | | | | :star: | | | | +| multisampling | | | | | :star: | | | | | | +| off-screen rendering | | | | | | :star: | | | :star: | :star: | +| stencil testing | | | | | | | | | | | +| depth testing | | | | | | :star: | :star: | | :star: | | +| depth biasing | | | | | | :star: | | | | | +| read-only depth | | | | | | | | | :star: | | +| blending | | :star: | :star: | | | | | | :star: | | +| render bundles | | | | | :star: | | | | :star: | | +| compute passes | :star: | | | | | | | | | | +| *optional extensions* | | | | | | | | :star: | | | +| - SPIR-V shaders | | | | | | | | :star: | | | +| - binding indexing | | | | | | | | :star: | | | +| - push constants | | | | | | | | :star: | | | +| - depth clamping | | | | | | :star: | | | | | +| - compressed textures | | | | | | | :star: | | | | +| - polygon mode | | | :star: | | | | | | | | +| - queries | | | | :star: | | | | | | | +| - conservative rasterization | | | | | | | | | | :star: | +| *integrations* | | | | | | | | | | | +| - staging belt | | | | | | | | | | | +| - typed arena | | | | | | | | | | | +| - obj loading | | | | | | | :star: | | | | + +## Hacking + +You can record an API trace any of the framework-based examples by starting them as: +```sh +mkdir -p trace && WGPU_TRACE=trace cargo run --features trace --example +``` diff --git a/wgpu/examples/boids/README.md b/wgpu/examples/boids/README.md new file mode 100644 index 000000000..28c7c88bb --- /dev/null +++ b/wgpu/examples/boids/README.md @@ -0,0 +1,13 @@ +# boids + +Flocking boids example with gpu compute update pass + +## To Run + +``` +cargo run --example boids +``` + +## Screenshots + +![Boids example](./screenshot.png) diff --git a/wgpu/examples/boids/compute.wgsl b/wgpu/examples/boids/compute.wgsl new file mode 100644 index 000000000..bddb260a2 --- /dev/null +++ b/wgpu/examples/boids/compute.wgsl @@ -0,0 +1,108 @@ +struct Particle { + pos : vec2; + vel : vec2; +}; + +[[block]] +struct SimParams { + deltaT : f32; + rule1Distance : f32; + rule2Distance : f32; + rule3Distance : f32; + rule1Scale : f32; + rule2Scale : f32; + rule3Scale : f32; +}; + +[[block]] +struct Particles { + particles : [[stride(16)]] array; +}; + +[[group(0), binding(0)]] var params : SimParams; +[[group(0), binding(1)]] var particlesSrc : [[access(read)]] Particles; +[[group(0), binding(2)]] var particlesDst : [[access(read_write)]] Particles; + +// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp +[[stage(compute), workgroup_size(64)]] +fn main([[builtin(global_invocation_id)]] global_invocation_id: vec3) { + let total = arrayLength(&particlesSrc.particles); + let index = global_invocation_id.x; + if (index >= total) { + return; + } + + var vPos : vec2 = particlesSrc.particles[index].pos; + var vVel : vec2 = particlesSrc.particles[index].vel; + + var cMass : vec2 = vec2(0.0, 0.0); + var cVel : vec2 = vec2(0.0, 0.0); + var colVel : vec2 = vec2(0.0, 0.0); + var cMassCount : i32 = 0; + var cVelCount : i32 = 0; + + var pos : vec2; + var vel : vec2; + var i : u32 = 0u; + loop { + if (i >= total) { + break; + } + if (i == index) { + continue; + } + + pos = particlesSrc.particles[i].pos; + vel = particlesSrc.particles[i].vel; + + if (distance(pos, vPos) < params.rule1Distance) { + cMass = cMass + pos; + cMassCount = cMassCount + 1; + } + if (distance(pos, vPos) < params.rule2Distance) { + colVel = colVel - (pos - vPos); + } + if (distance(pos, vPos) < params.rule3Distance) { + cVel = cVel + vel; + cVelCount = cVelCount + 1; + } + + continuing { + i = i + 1u; + } + } + if (cMassCount > 0) { + cMass = cMass * (1.0 / f32(cMassCount)) - vPos; + } + if (cVelCount > 0) { + cVel = cVel * (1.0 / f32(cVelCount)); + } + + vVel = vVel + (cMass * params.rule1Scale) + + (colVel * params.rule2Scale) + + (cVel * params.rule3Scale); + + // clamp velocity for a more pleasing simulation + vVel = normalize(vVel) * clamp(length(vVel), 0.0, 0.1); + + // kinematic update + vPos = vPos + (vVel * params.deltaT); + + // Wrap around boundary + if (vPos.x < -1.0) { + vPos.x = 1.0; + } + if (vPos.x > 1.0) { + vPos.x = -1.0; + } + if (vPos.y < -1.0) { + vPos.y = 1.0; + } + if (vPos.y > 1.0) { + vPos.y = -1.0; + } + + // Write back + particlesDst.particles[index].pos = vPos; + particlesDst.particles[index].vel = vVel; +} diff --git a/wgpu/examples/boids/draw.wgsl b/wgpu/examples/boids/draw.wgsl new file mode 100644 index 000000000..8980eb7d1 --- /dev/null +++ b/wgpu/examples/boids/draw.wgsl @@ -0,0 +1,18 @@ +[[stage(vertex)]] +fn main( + [[location(0)]] particle_pos: vec2, + [[location(1)]] particle_vel: vec2, + [[location(2)]] position: vec2, +) -> [[builtin(position)]] vec4 { + let angle = -atan2(particle_vel.x, particle_vel.y); + let pos = vec2( + position.x * cos(angle) - position.y * sin(angle), + position.x * sin(angle) + position.y * cos(angle) + ); + return vec4(pos + particle_pos, 0.0, 1.0); +} + +[[stage(fragment)]] +fn main() -> [[location(0)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); +} diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs new file mode 100644 index 000000000..cfd57c23a --- /dev/null +++ b/wgpu/examples/boids/main.rs @@ -0,0 +1,326 @@ +// Flocking boids example with gpu compute update pass +// adapted from https://github.com/austinEng/webgpu-samples/blob/master/src/examples/computeBoids.ts + +use rand::distributions::{Distribution, Uniform}; +use std::{borrow::Cow, mem}; +use wgpu::util::DeviceExt; + +#[path = "../framework.rs"] +mod framework; + +// number of boid particles to simulate + +const NUM_PARTICLES: u32 = 1500; + +// number of single-particle calculations (invocations) in each gpu work group + +const PARTICLES_PER_GROUP: u32 = 64; + +/// Example struct holds references to wgpu resources and frame persistent data +struct Example { + particle_bind_groups: Vec, + particle_buffers: Vec, + vertices_buffer: wgpu::Buffer, + compute_pipeline: wgpu::ComputePipeline, + render_pipeline: wgpu::RenderPipeline, + work_group_count: u32, + frame_num: usize, +} + +impl framework::Example for Example { + /// constructs initial instance of Example struct + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + _queue: &wgpu::Queue, + ) -> Self { + // load and compile the shader + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgt::Backend::Vulkan | wgt::Backend::Metal | wgt::Backend::Gl => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION; + } + _ => {} //TODO + } + let compute_shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("compute.wgsl"))), + flags, + }); + let draw_shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))), + flags, + }); + + // buffer for simulation parameters uniform + + let sim_param_data = [ + 0.04f32, // deltaT + 0.1, // rule1Distance + 0.025, // rule2Distance + 0.025, // rule3Distance + 0.02, // rule1Scale + 0.05, // rule2Scale + 0.005, // rule3Scale + ] + .to_vec(); + let sim_param_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Simulation Parameter Buffer"), + contents: bytemuck::cast_slice(&sim_param_data), + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + }); + + // create compute bind layout group and compute pipeline layout + + let compute_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new( + (sim_param_data.len() * mem::size_of::()) as _, + ), + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStage::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { read_only: true }, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new((NUM_PARTICLES * 16) as _), + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStage::COMPUTE, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { read_only: false }, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new((NUM_PARTICLES * 16) as _), + }, + count: None, + }, + ], + label: None, + }); + let compute_pipeline_layout = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("compute"), + bind_group_layouts: &[&compute_bind_group_layout], + push_constant_ranges: &[], + }); + + // create render pipeline with empty bind group layout + + let render_pipeline_layout = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("render"), + bind_group_layouts: &[], + push_constant_ranges: &[], + }); + + let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&render_pipeline_layout), + vertex: wgpu::VertexState { + module: &draw_shader, + entry_point: "main", + buffers: &[ + wgpu::VertexBufferLayout { + array_stride: 4 * 4, + step_mode: wgpu::InputStepMode::Instance, + attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2], + }, + wgpu::VertexBufferLayout { + array_stride: 2 * 4, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &wgpu::vertex_attr_array![2 => Float32x2], + }, + ], + }, + fragment: Some(wgpu::FragmentState { + module: &draw_shader, + entry_point: "main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState::default(), + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + // create compute pipeline + + let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { + label: Some("Compute pipeline"), + layout: Some(&compute_pipeline_layout), + module: &compute_shader, + entry_point: "main", + }); + + // buffer for the three 2d triangle vertices of each instance + + let vertex_buffer_data = [-0.01f32, -0.02, 0.01, -0.02, 0.00, 0.02]; + let vertices_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Vertex Buffer"), + contents: bytemuck::bytes_of(&vertex_buffer_data), + usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST, + }); + + // buffer for all particles data of type [(posx,posy,velx,vely),...] + + let mut initial_particle_data = vec![0.0f32; (4 * NUM_PARTICLES) as usize]; + let mut rng = rand::thread_rng(); + let unif = Uniform::new_inclusive(-1.0, 1.0); + for particle_instance_chunk in initial_particle_data.chunks_mut(4) { + particle_instance_chunk[0] = unif.sample(&mut rng); // posx + particle_instance_chunk[1] = unif.sample(&mut rng); // posy + particle_instance_chunk[2] = unif.sample(&mut rng) * 0.1; // velx + particle_instance_chunk[3] = unif.sample(&mut rng) * 0.1; // vely + } + + // creates two buffers of particle data each of size NUM_PARTICLES + // the two buffers alternate as dst and src for each frame + + let mut particle_buffers = Vec::::new(); + let mut particle_bind_groups = Vec::::new(); + for i in 0..2 { + particle_buffers.push( + device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some(&format!("Particle Buffer {}", i)), + contents: bytemuck::cast_slice(&initial_particle_data), + usage: wgpu::BufferUsage::VERTEX + | wgpu::BufferUsage::STORAGE + | wgpu::BufferUsage::COPY_DST, + }), + ); + } + + // create two bind groups, one for each buffer as the src + // where the alternate buffer is used as the dst + + for i in 0..2 { + particle_bind_groups.push(device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &compute_bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: sim_param_buffer.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: particle_buffers[i].as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: particle_buffers[(i + 1) % 2].as_entire_binding(), // bind to opposite buffer + }, + ], + label: None, + })); + } + + // calculates number of work groups from PARTICLES_PER_GROUP constant + let work_group_count = + ((NUM_PARTICLES as f32) / (PARTICLES_PER_GROUP as f32)).ceil() as u32; + + // returns Example struct and No encoder commands + + Example { + particle_bind_groups, + particle_buffers, + vertices_buffer, + compute_pipeline, + render_pipeline, + work_group_count, + frame_num: 0, + } + } + + /// update is called for any WindowEvent not handled by the framework + fn update(&mut self, _event: winit::event::WindowEvent) { + //empty + } + + /// resize is called on WindowEvent::Resized events + fn resize( + &mut self, + _sc_desc: &wgpu::SwapChainDescriptor, + _device: &wgpu::Device, + _queue: &wgpu::Queue, + ) { + //empty + } + + /// render is called each frame, dispatching compute groups proportional + /// a TriangleList draw call for all NUM_PARTICLES at 3 vertices each + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + // create render pass descriptor and its color attachments + let color_attachments = [wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: true, + }, + }]; + let render_pass_descriptor = wgpu::RenderPassDescriptor { + label: None, + color_attachments: &color_attachments, + depth_stencil_attachment: None, + }; + + // get command encoder + let mut command_encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + + command_encoder.push_debug_group("compute boid movement"); + { + // compute pass + let mut cpass = + command_encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: None }); + cpass.set_pipeline(&self.compute_pipeline); + cpass.set_bind_group(0, &self.particle_bind_groups[self.frame_num % 2], &[]); + cpass.dispatch(self.work_group_count, 1, 1); + } + command_encoder.pop_debug_group(); + + command_encoder.push_debug_group("render boids"); + { + // render pass + let mut rpass = command_encoder.begin_render_pass(&render_pass_descriptor); + rpass.set_pipeline(&self.render_pipeline); + // render dst particles + rpass.set_vertex_buffer(0, self.particle_buffers[(self.frame_num + 1) % 2].slice(..)); + // the three instance-local vertices + rpass.set_vertex_buffer(1, self.vertices_buffer.slice(..)); + rpass.draw(0..3, 0..NUM_PARTICLES); + } + command_encoder.pop_debug_group(); + + // update frame count + self.frame_num += 1; + + // done + queue.submit(Some(command_encoder.finish())); + } +} + +/// run example +fn main() { + framework::run::("boids"); +} diff --git a/wgpu/examples/boids/screenshot.png b/wgpu/examples/boids/screenshot.png new file mode 100644 index 000000000..e510c1c16 Binary files /dev/null and b/wgpu/examples/boids/screenshot.png differ diff --git a/wgpu/examples/bunnymark/main.rs b/wgpu/examples/bunnymark/main.rs new file mode 100644 index 000000000..acb591f6d --- /dev/null +++ b/wgpu/examples/bunnymark/main.rs @@ -0,0 +1,354 @@ +use bytemuck::{Pod, Zeroable}; +use std::{borrow::Cow, mem}; +use wgpu::util::DeviceExt; + +#[path = "../framework.rs"] +mod framework; + +const MAX_BUNNIES: usize = 1 << 20; +const BUNNY_SIZE: f32 = 0.15 * 256.0; +const GRAVITY: f32 = -9.8 * 100.0; +const MAX_VELOCITY: f32 = 750.0; + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct Globals { + mvp: [[f32; 4]; 4], + size: [f32; 2], + pad: [f32; 2], +} + +#[repr(C, align(256))] +#[derive(Clone, Copy, Zeroable)] +struct Locals { + position: [f32; 2], + velocity: [f32; 2], + color: u32, + _pad: u32, +} + +/// Example struct holds references to wgpu resources and frame persistent data +struct Example { + global_group: wgpu::BindGroup, + local_group: wgpu::BindGroup, + pipeline: wgpu::RenderPipeline, + bunnies: Vec, + local_buffer: wgpu::Buffer, + extent: [u32; 2], +} + +impl framework::Example for Example { + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + _adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) -> Self { + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + flags: wgpu::ShaderFlags::all(), + }); + + let global_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new(mem::size_of::() as _), + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { filterable: true }, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Sampler { + filtering: true, + comparison: false, + }, + count: None, + }, + ], + label: None, + }); + let local_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: wgpu::BufferSize::new(mem::size_of::() as _), + }, + count: None, + }], + label: None, + }); + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[&global_bind_group_layout, &local_bind_group_layout], + push_constant_ranges: &[], + }); + + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + blend: Some(wgpu::BlendState::ALPHA_BLENDING), + write_mask: wgpu::ColorWrite::default(), + }], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleStrip, + ..wgpu::PrimitiveState::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + let texture = { + let img_data = include_bytes!("../../logo.png"); + let decoder = png::Decoder::new(std::io::Cursor::new(img_data)); + let (info, mut reader) = decoder.read_info().unwrap(); + let mut buf = vec![0; info.buffer_size()]; + reader.next_frame(&mut buf).unwrap(); + + let size = wgpu::Extent3d { + width: info.width, + height: info.height, + depth_or_array_layers: 1, + }; + let texture = device.create_texture(&wgpu::TextureDescriptor { + label: None, + size, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Rgba8UnormSrgb, + usage: wgpu::TextureUsage::COPY_DST | wgpu::TextureUsage::SAMPLED, + }); + queue.write_texture( + wgpu::ImageCopyTexture { + texture: &texture, + mip_level: 0, + origin: wgpu::Origin3d::ZERO, + }, + &buf, + wgpu::ImageDataLayout { + offset: 0, + bytes_per_row: std::num::NonZeroU32::new(info.width * 4), + rows_per_image: None, + }, + size, + ); + texture + }; + + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: None, + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Nearest, + mipmap_filter: wgpu::FilterMode::Nearest, + ..Default::default() + }); + + let globals = Globals { + mvp: cgmath::ortho( + 0.0, + sc_desc.width as f32, + 0.0, + sc_desc.height as f32, + -1.0, + 1.0, + ) + .into(), + size: [BUNNY_SIZE; 2], + pad: [0.0; 2], + }; + let global_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("global"), + contents: bytemuck::bytes_of(&globals), + usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM, + }); + let local_buffer = device.create_buffer(&wgpu::BufferDescriptor { + label: Some("local"), + size: (MAX_BUNNIES as wgpu::BufferAddress) * wgpu::BIND_BUFFER_ALIGNMENT, + usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::UNIFORM, + mapped_at_creation: false, + }); + + let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + let global_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &global_bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: global_buffer.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView(&view), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::Sampler(&sampler), + }, + ], + label: None, + }); + let local_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &local_bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { + buffer: &local_buffer, + offset: 0, + size: wgpu::BufferSize::new(mem::size_of::() as _), + }), + }], + label: None, + }); + + Example { + pipeline, + global_group, + local_group, + bunnies: Vec::new(), + local_buffer, + extent: [sc_desc.width, sc_desc.height], + } + } + + fn update(&mut self, event: winit::event::WindowEvent) { + if let winit::event::WindowEvent::KeyboardInput { + input: + winit::event::KeyboardInput { + virtual_keycode: Some(winit::event::VirtualKeyCode::Space), + state: winit::event::ElementState::Pressed, + .. + }, + .. + } = event + { + let spawn_count = 64 + self.bunnies.len() / 2; + let color = rand::random::(); + println!( + "Spawning {} bunnies, total at {}", + spawn_count, + self.bunnies.len() + spawn_count + ); + for _ in 0..spawn_count { + let speed = rand::random::() * MAX_VELOCITY - (MAX_VELOCITY * 0.5); + self.bunnies.push(Locals { + position: [0.0, 0.5 * (self.extent[1] as f32)], + velocity: [speed, 0.0], + color, + _pad: 0, + }); + } + } + } + + fn resize( + &mut self, + _sc_desc: &wgpu::SwapChainDescriptor, + _device: &wgpu::Device, + _queue: &wgpu::Queue, + ) { + //empty + } + + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + let delta = 0.01; + for bunny in self.bunnies.iter_mut() { + bunny.position[0] += bunny.velocity[0] * delta; + bunny.position[1] += bunny.velocity[1] * delta; + bunny.velocity[1] += GRAVITY * delta; + if (bunny.velocity[0] > 0.0 + && bunny.position[0] + 0.5 * BUNNY_SIZE > self.extent[0] as f32) + || (bunny.velocity[0] < 0.0 && bunny.position[0] - 0.5 * BUNNY_SIZE < 0.0) + { + bunny.velocity[0] *= -1.0; + } + if bunny.velocity[1] < 0.0 && bunny.position[1] < 0.5 * BUNNY_SIZE { + bunny.velocity[1] *= -1.0; + } + } + + queue.write_buffer(&self.local_buffer, 0, unsafe { + std::slice::from_raw_parts( + self.bunnies.as_ptr() as *const u8, + self.bunnies.len() * wgpu::BIND_BUFFER_ALIGNMENT as usize, + ) + }); + + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); + { + let clear_color = wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }; + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(clear_color), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + rpass.set_pipeline(&self.pipeline); + rpass.set_bind_group(0, &self.global_group, &[]); + for i in 0..self.bunnies.len() { + let offset = (i as wgpu::DynamicOffset) + * (wgpu::BIND_BUFFER_ALIGNMENT as wgpu::DynamicOffset); + rpass.set_bind_group(1, &self.local_group, &[offset]); + rpass.draw(0..4, 0..1); + } + } + + queue.submit(Some(encoder.finish())); + } +} + +fn main() { + framework::run::("bunnymark"); +} diff --git a/wgpu/examples/bunnymark/shader.wgsl b/wgpu/examples/bunnymark/shader.wgsl new file mode 100644 index 000000000..b8639d1ca --- /dev/null +++ b/wgpu/examples/bunnymark/shader.wgsl @@ -0,0 +1,43 @@ +[[block]] +struct Globals { + mvp: mat4x4; + size: vec2; +}; + +[[block]] +struct Locals { + position: vec2; + velocity: vec2; + color: u32; +}; + +[[group(0), binding(0)]] +var globals: Globals; + +[[group(1), binding(0)]] +var locals: Locals; + +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] tex_coords: vec2; + [[location(1)]] color: vec4; +}; + +[[stage(vertex)]] +fn vs_main([[builtin(vertex_index)]] vi: u32) -> VertexOutput { + let tc = vec2(f32(vi & 1u), 0.5 * f32(vi & 2u)); + let offset = vec2(tc.x * globals.size.x, tc.y * globals.size.y); + let pos = globals.mvp * vec4(locals.position + offset, 0.0, 1.0); + let color = vec4((vec4(locals.color) >> vec4(0u, 8u, 16u, 24u)) & vec4(255u)) / 255.0; + return VertexOutput(pos, tc, color); +} + +[[group(0), binding(1)]] +var texture: texture_2d; +[[group(0), binding(2)]] +var sampler: sampler; + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + return in.color * textureSampleLevel(texture, sampler, in.tex_coords, 0.0); +} diff --git a/wgpu/examples/capture/README.md b/wgpu/examples/capture/README.md new file mode 100644 index 000000000..b9c0ee22b --- /dev/null +++ b/wgpu/examples/capture/README.md @@ -0,0 +1,18 @@ +# capture + +This example shows how to capture an image by rendering it to a texture, copying the texture to +a buffer, and retrieving it from the buffer. + +This could be used for "taking a screenshot," with the added benefit that this method doesn't +require a window to be created. + +## To Run + +``` +cargo run --example capture +open examples/capture/red.png +``` + +## Screenshots + +![Capture example](./screenshot.png) diff --git a/wgpu/examples/capture/main.rs b/wgpu/examples/capture/main.rs new file mode 100644 index 000000000..319dea25a --- /dev/null +++ b/wgpu/examples/capture/main.rs @@ -0,0 +1,248 @@ +use std::env; +/// This example shows how to capture an image by rendering it to a texture, copying the texture to +/// a buffer, and retrieving it from the buffer. This could be used for "taking a screenshot," with +/// the added benefit that this method doesn't require a window to be created. +use std::fs::File; +use std::io::Write; +use std::mem::size_of; +use wgpu::{Buffer, Device}; + +async fn run(png_output_path: &str) { + let args: Vec<_> = env::args().collect(); + let (width, height) = match args.len() { + // 0 on wasm, 1 on desktop + 0 | 1 => (100usize, 200usize), + 3 => (args[1].parse().unwrap(), args[2].parse().unwrap()), + _ => { + println!("Incorrect number of arguments, possible usages:"); + println!("* 0 arguments - uses default width and height of (100, 200)"); + println!("* 2 arguments - uses specified width and height values"); + return; + } + }; + let (device, buffer, buffer_dimensions) = create_red_image_with_dimensions(width, height).await; + create_png(png_output_path, device, buffer, &buffer_dimensions).await; +} + +async fn create_red_image_with_dimensions( + width: usize, + height: usize, +) -> (Device, Buffer, BufferDimensions) { + let adapter = wgpu::Instance::new(wgpu::BackendBit::PRIMARY) + .request_adapter(&wgpu::RequestAdapterOptions::default()) + .await + .unwrap(); + + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: wgpu::Features::empty(), + limits: wgpu::Limits::default(), + }, + None, + ) + .await + .unwrap(); + + // It is a WebGPU requirement that ImageCopyBuffer.layout.bytes_per_row % wgpu::COPY_BYTES_PER_ROW_ALIGNMENT == 0 + // So we calculate padded_bytes_per_row by rounding unpadded_bytes_per_row + // up to the next multiple of wgpu::COPY_BYTES_PER_ROW_ALIGNMENT. + // https://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding + let buffer_dimensions = BufferDimensions::new(width, height); + // The output buffer lets us retrieve the data as an array + let output_buffer = device.create_buffer(&wgpu::BufferDescriptor { + label: None, + size: (buffer_dimensions.padded_bytes_per_row * buffer_dimensions.height) as u64, + usage: wgpu::BufferUsage::MAP_READ | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + let texture_extent = wgpu::Extent3d { + width: buffer_dimensions.width as u32, + height: buffer_dimensions.height as u32, + depth_or_array_layers: 1, + }; + + // The render pipeline renders data into this texture + let texture = device.create_texture(&wgpu::TextureDescriptor { + size: texture_extent, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Rgba8UnormSrgb, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::COPY_SRC, + label: None, + }); + + // Set the background to be red + let command_buffer = { + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &texture.create_view(&wgpu::TextureViewDescriptor::default()), + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::RED), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + + // Copy the data from the texture to the buffer + encoder.copy_texture_to_buffer( + wgpu::ImageCopyTexture { + texture: &texture, + mip_level: 0, + origin: wgpu::Origin3d::ZERO, + }, + wgpu::ImageCopyBuffer { + buffer: &output_buffer, + layout: wgpu::ImageDataLayout { + offset: 0, + bytes_per_row: Some( + std::num::NonZeroU32::new(buffer_dimensions.padded_bytes_per_row as u32) + .unwrap(), + ), + rows_per_image: None, + }, + }, + texture_extent, + ); + + encoder.finish() + }; + + queue.submit(Some(command_buffer)); + (device, output_buffer, buffer_dimensions) +} + +async fn create_png( + png_output_path: &str, + device: Device, + output_buffer: Buffer, + buffer_dimensions: &BufferDimensions, +) { + // Note that we're not calling `.await` here. + let buffer_slice = output_buffer.slice(..); + let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read); + + // Poll the device in a blocking manner so that our future resolves. + // In an actual application, `device.poll(...)` should + // be called in an event loop or on another thread. + device.poll(wgpu::Maintain::Wait); + // If a file system is available, write the buffer as a PNG + let has_file_system_available = cfg!(not(target_arch = "wasm32")); + if !has_file_system_available { + return; + } + + if let Ok(()) = buffer_future.await { + let padded_buffer = buffer_slice.get_mapped_range(); + + let mut png_encoder = png::Encoder::new( + File::create(png_output_path).unwrap(), + buffer_dimensions.width as u32, + buffer_dimensions.height as u32, + ); + png_encoder.set_depth(png::BitDepth::Eight); + png_encoder.set_color(png::ColorType::RGBA); + let mut png_writer = png_encoder + .write_header() + .unwrap() + .into_stream_writer_with_size(buffer_dimensions.unpadded_bytes_per_row); + + // from the padded_buffer we write just the unpadded bytes into the image + for chunk in padded_buffer.chunks(buffer_dimensions.padded_bytes_per_row) { + png_writer + .write_all(&chunk[..buffer_dimensions.unpadded_bytes_per_row]) + .unwrap(); + } + png_writer.finish().unwrap(); + + // With the current interface, we have to make sure all mapped views are + // dropped before we unmap the buffer. + drop(padded_buffer); + + output_buffer.unmap(); + } +} + +struct BufferDimensions { + width: usize, + height: usize, + unpadded_bytes_per_row: usize, + padded_bytes_per_row: usize, +} + +impl BufferDimensions { + fn new(width: usize, height: usize) -> Self { + let bytes_per_pixel = size_of::(); + let unpadded_bytes_per_row = width * bytes_per_pixel; + let align = wgpu::COPY_BYTES_PER_ROW_ALIGNMENT as usize; + let padded_bytes_per_row_padding = (align - unpadded_bytes_per_row % align) % align; + let padded_bytes_per_row = unpadded_bytes_per_row + padded_bytes_per_row_padding; + Self { + width, + height, + unpadded_bytes_per_row, + padded_bytes_per_row, + } + } +} + +fn main() { + #[cfg(not(target_arch = "wasm32"))] + { + env_logger::init(); + pollster::block_on(run("red.png")); + } + #[cfg(target_arch = "wasm32")] + { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + console_log::init().expect("could not initialize logger"); + wasm_bindgen_futures::spawn_local(run("red.png")); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use wgpu::BufferView; + + #[test] + fn ensure_generated_data_matches_expected() { + pollster::block_on(assert_generated_data_matches_expected()); + } + + async fn assert_generated_data_matches_expected() { + let (device, output_buffer, dimensions) = + create_red_image_with_dimensions(100usize, 200usize).await; + let buffer_slice = output_buffer.slice(..); + let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read); + device.poll(wgpu::Maintain::Wait); + buffer_future + .await + .expect("failed to map buffer slice for capture test"); + let padded_buffer = buffer_slice.get_mapped_range(); + let expected_buffer_size = dimensions.padded_bytes_per_row * dimensions.height; + assert_eq!(padded_buffer.len(), expected_buffer_size); + assert_that_content_is_all_red(&dimensions, padded_buffer); + } + + fn assert_that_content_is_all_red(dimensions: &BufferDimensions, padded_buffer: BufferView) { + let red = [0xFFu8, 0, 0, 0xFFu8]; + let single_rgba = 4; + padded_buffer + .chunks(dimensions.padded_bytes_per_row) + .map(|padded_buffer_row| &padded_buffer_row[..dimensions.unpadded_bytes_per_row]) + .for_each(|unpadded_row| { + unpadded_row + .chunks(single_rgba) + .for_each(|chunk| assert_eq!(chunk, &red)) + }); + } +} diff --git a/wgpu/examples/capture/screenshot.png b/wgpu/examples/capture/screenshot.png new file mode 100644 index 000000000..4021a58f6 Binary files /dev/null and b/wgpu/examples/capture/screenshot.png differ diff --git a/wgpu/examples/conservative-raster/README.md b/wgpu/examples/conservative-raster/README.md new file mode 100644 index 000000000..bd157319b --- /dev/null +++ b/wgpu/examples/conservative-raster/README.md @@ -0,0 +1,20 @@ +# conservative-raster + +This example shows how to render with conservative rasterization (native extension with limited support). + +When enabled, any pixel touched by a triangle primitive is rasterized. +This is useful for various advanced techniques, most prominently for implementing realtime voxelization. + +The demonstration here is implemented by rendering a triangle to a low-resolution target and then upscaling it with nearest-neighbor filtering. +The outlines of the triangle are then rendered in the original solution, using the same vertex shader as the triangle. +Pixels only drawn with conservative rasterization enabled are depicted red. + +## To Run + +``` +cargo run --example conservative-raster +``` + +## Screenshots + +![Conservative-raster window](./screenshot.png) diff --git a/wgpu/examples/conservative-raster/main.rs b/wgpu/examples/conservative-raster/main.rs new file mode 100644 index 000000000..763b7e9a7 --- /dev/null +++ b/wgpu/examples/conservative-raster/main.rs @@ -0,0 +1,316 @@ +#[path = "../framework.rs"] +mod framework; + +use std::borrow::Cow; + +const RENDER_TARGET_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; + +struct Example { + low_res_target: wgpu::TextureView, + bind_group_upscale: wgpu::BindGroup, + + pipeline_triangle_conservative: wgpu::RenderPipeline, + pipeline_triangle_regular: wgpu::RenderPipeline, + pipeline_upscale: wgpu::RenderPipeline, + pipeline_lines: Option, + bind_group_layout_upscale: wgpu::BindGroupLayout, +} + +impl Example { + fn create_low_res_target( + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + bind_group_layout_upscale: &wgpu::BindGroupLayout, + ) -> (wgpu::TextureView, wgpu::BindGroup) { + let texture_view = device + .create_texture(&wgpu::TextureDescriptor { + label: Some("Low Resolution Target"), + size: wgpu::Extent3d { + width: sc_desc.width / 16, + height: sc_desc.width / 16, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: RENDER_TARGET_FORMAT, + usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::RENDER_ATTACHMENT, + }) + .create_view(&Default::default()); + + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: Some("Nearest Neighbor Sampler"), + mag_filter: wgpu::FilterMode::Nearest, + min_filter: wgpu::FilterMode::Nearest, + ..Default::default() + }); + + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + label: Some("upscale bind group"), + layout: &bind_group_layout_upscale, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(&texture_view), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(&sampler), + }, + ], + }); + + (texture_view, bind_group) + } +} + +impl framework::Example for Example { + fn required_features() -> wgpu::Features { + wgpu::Features::CONSERVATIVE_RASTERIZATION + } + fn optional_features() -> wgpu::Features { + wgpu::Features::NON_FILL_POLYGON_MODE + } + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + _queue: &wgpu::Queue, + ) -> Self { + let pipeline_layout_empty = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[], + push_constant_ranges: &[], + }); + + let shader_triangle_and_lines = + device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!( + "triangle_and_lines.wgsl" + ))), + flags: wgpu::ShaderFlags::all(), + }); + + let pipeline_triangle_conservative = + device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Conservative Rasterization"), + layout: Some(&pipeline_layout_empty), + vertex: wgpu::VertexState { + module: &shader_triangle_and_lines, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader_triangle_and_lines, + entry_point: "fs_main_red", + targets: &[RENDER_TARGET_FORMAT.into()], + }), + primitive: wgpu::PrimitiveState { + conservative: true, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + let pipeline_triangle_regular = + device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Regular Rasterization"), + layout: Some(&pipeline_layout_empty), + vertex: wgpu::VertexState { + module: &shader_triangle_and_lines, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader_triangle_and_lines, + entry_point: "fs_main_blue", + targets: &[RENDER_TARGET_FORMAT.into()], + }), + primitive: wgpu::PrimitiveState::default(), + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + let pipeline_lines = if adapter + .features() + .contains(wgpu::Features::NON_FILL_POLYGON_MODE) + { + Some( + device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Lines"), + layout: Some(&pipeline_layout_empty), + vertex: wgpu::VertexState { + module: &shader_triangle_and_lines, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader_triangle_and_lines, + entry_point: "fs_main_white", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + polygon_mode: wgpu::PolygonMode::Line, + topology: wgpu::PrimitiveTopology::LineStrip, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }), + ) + } else { + None + }; + + let (pipeline_upscale, bind_group_layout_upscale) = { + let bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("upscale bindgroup"), + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { filterable: false }, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Sampler { + filtering: false, + comparison: false, + }, + count: None, + }, + ], + }); + + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[&bind_group_layout], + push_constant_ranges: &[], + }); + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("upscale.wgsl"))), + flags: wgpu::ShaderFlags::all(), + }); + ( + device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Upscale"), + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState::default(), + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }), + bind_group_layout, + ) + }; + + let (low_res_target, bind_group_upscale) = + Self::create_low_res_target(sc_desc, device, &bind_group_layout_upscale); + + Self { + low_res_target, + bind_group_upscale, + + pipeline_triangle_conservative, + pipeline_triangle_regular, + pipeline_upscale, + pipeline_lines, + bind_group_layout_upscale, + } + } + + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + _queue: &wgpu::Queue, + ) { + let (low_res_target, bind_group_upscale) = + Self::create_low_res_target(sc_desc, device, &self.bind_group_layout_upscale); + self.low_res_target = low_res_target; + self.bind_group_upscale = bind_group_upscale; + } + + fn update(&mut self, _event: winit::event::WindowEvent) {} + + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("primary"), + }); + + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("low resolution"), + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &self.low_res_target, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + + rpass.set_pipeline(&self.pipeline_triangle_conservative); + rpass.draw(0..3, 0..1); + rpass.set_pipeline(&self.pipeline_triangle_regular); + rpass.draw(0..3, 0..1); + } + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("full resolution"), + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + + rpass.set_pipeline(&self.pipeline_upscale); + rpass.set_bind_group(0, &self.bind_group_upscale, &[]); + rpass.draw(0..3, 0..1); + + if let Some(pipeline_lines) = &self.pipeline_lines { + rpass.set_pipeline(pipeline_lines); + rpass.draw(0..4, 0..1); + } + } + + queue.submit(Some(encoder.finish())); + } +} + +fn main() { + framework::run::("conservative-raster"); +} diff --git a/wgpu/examples/conservative-raster/screenshot.png b/wgpu/examples/conservative-raster/screenshot.png new file mode 100644 index 000000000..e227e10e6 Binary files /dev/null and b/wgpu/examples/conservative-raster/screenshot.png differ diff --git a/wgpu/examples/conservative-raster/triangle_and_lines.wgsl b/wgpu/examples/conservative-raster/triangle_and_lines.wgsl new file mode 100644 index 000000000..a553ff4f6 --- /dev/null +++ b/wgpu/examples/conservative-raster/triangle_and_lines.wgsl @@ -0,0 +1,22 @@ +[[stage(vertex)]] +fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> [[builtin(position)]] vec4 { + let i: i32 = i32(vertex_index % 3u); + let x: f32 = f32(i - 1) * 0.75; + let y: f32 = f32((i & 1) * 2 - 1) * 0.75 + x * 0.2 + 0.1; + return vec4(x, y, 0.0, 1.0); +} + +[[stage(fragment)]] +fn fs_main_red() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); +} + +[[stage(fragment)]] +fn fs_main_blue() -> [[location(0)]] vec4 { + return vec4(0.13, 0.31, 0.85, 1.0); // cornflower blue in linear space +} + +[[stage(fragment)]] +fn fs_main_white() -> [[location(0)]] vec4 { + return vec4(1.0, 1.0, 1.0, 1.0); +} \ No newline at end of file diff --git a/wgpu/examples/conservative-raster/upscale.wgsl b/wgpu/examples/conservative-raster/upscale.wgsl new file mode 100644 index 000000000..edb87df17 --- /dev/null +++ b/wgpu/examples/conservative-raster/upscale.wgsl @@ -0,0 +1,24 @@ +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] tex_coords: vec2; +}; + +[[stage(vertex)]] +fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { + let x: f32 = f32(i32(vertex_index & 1u) << 2u) - 1.0; + let y: f32 = f32(i32(vertex_index & 2u) << 1u) - 1.0; + var output: VertexOutput; + output.position = vec4(x, -y, 0.0, 1.0); + output.tex_coords = vec2(x + 1.0, y + 1.0) * 0.5; + return output; +} + +[[group(0), binding(0)]] +var r_color: texture_2d; +[[group(0), binding(1)]] +var r_sampler: sampler; + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + return textureSample(r_color, r_sampler, in.tex_coords); +} \ No newline at end of file diff --git a/wgpu/examples/cube/README.md b/wgpu/examples/cube/README.md new file mode 100644 index 000000000..8b3f32872 --- /dev/null +++ b/wgpu/examples/cube/README.md @@ -0,0 +1,13 @@ +# cube + +This example renders a textured cube. + +## To Run + +``` +cargo run --example cube +``` + +## Screenshots + +![Cube example](./screenshot.png) diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs new file mode 100644 index 000000000..a745791d0 --- /dev/null +++ b/wgpu/examples/cube/main.rs @@ -0,0 +1,393 @@ +#[path = "../framework.rs"] +mod framework; + +use bytemuck::{Pod, Zeroable}; +use std::{borrow::Cow, mem}; +use wgpu::util::DeviceExt; + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct Vertex { + _pos: [f32; 4], + _tex_coord: [f32; 2], +} + +fn vertex(pos: [i8; 3], tc: [i8; 2]) -> Vertex { + Vertex { + _pos: [pos[0] as f32, pos[1] as f32, pos[2] as f32, 1.0], + _tex_coord: [tc[0] as f32, tc[1] as f32], + } +} + +fn create_vertices() -> (Vec, Vec) { + let vertex_data = [ + // top (0, 0, 1) + vertex([-1, -1, 1], [0, 0]), + vertex([1, -1, 1], [1, 0]), + vertex([1, 1, 1], [1, 1]), + vertex([-1, 1, 1], [0, 1]), + // bottom (0, 0, -1) + vertex([-1, 1, -1], [1, 0]), + vertex([1, 1, -1], [0, 0]), + vertex([1, -1, -1], [0, 1]), + vertex([-1, -1, -1], [1, 1]), + // right (1, 0, 0) + vertex([1, -1, -1], [0, 0]), + vertex([1, 1, -1], [1, 0]), + vertex([1, 1, 1], [1, 1]), + vertex([1, -1, 1], [0, 1]), + // left (-1, 0, 0) + vertex([-1, -1, 1], [1, 0]), + vertex([-1, 1, 1], [0, 0]), + vertex([-1, 1, -1], [0, 1]), + vertex([-1, -1, -1], [1, 1]), + // front (0, 1, 0) + vertex([1, 1, -1], [1, 0]), + vertex([-1, 1, -1], [0, 0]), + vertex([-1, 1, 1], [0, 1]), + vertex([1, 1, 1], [1, 1]), + // back (0, -1, 0) + vertex([1, -1, 1], [0, 0]), + vertex([-1, -1, 1], [1, 0]), + vertex([-1, -1, -1], [1, 1]), + vertex([1, -1, -1], [0, 1]), + ]; + + let index_data: &[u16] = &[ + 0, 1, 2, 2, 3, 0, // top + 4, 5, 6, 6, 7, 4, // bottom + 8, 9, 10, 10, 11, 8, // right + 12, 13, 14, 14, 15, 12, // left + 16, 17, 18, 18, 19, 16, // front + 20, 21, 22, 22, 23, 20, // back + ]; + + (vertex_data.to_vec(), index_data.to_vec()) +} + +fn create_texels(size: usize) -> Vec { + (0..size * size) + .map(|id| { + // get high five for recognizing this ;) + let cx = 3.0 * (id % size) as f32 / (size - 1) as f32 - 2.0; + let cy = 2.0 * (id / size) as f32 / (size - 1) as f32 - 1.0; + let (mut x, mut y, mut count) = (cx, cy, 0); + while count < 0xFF && x * x + y * y < 4.0 { + let old_x = x; + x = x * x - y * y + cx; + y = 2.0 * old_x * y + cy; + count += 1; + } + count + }) + .collect() +} + +struct Example { + vertex_buf: wgpu::Buffer, + index_buf: wgpu::Buffer, + index_count: usize, + bind_group: wgpu::BindGroup, + uniform_buf: wgpu::Buffer, + pipeline: wgpu::RenderPipeline, + pipeline_wire: Option, +} + +impl Example { + fn generate_matrix(aspect_ratio: f32) -> cgmath::Matrix4 { + let mx_projection = cgmath::perspective(cgmath::Deg(45f32), aspect_ratio, 1.0, 10.0); + let mx_view = cgmath::Matrix4::look_at_rh( + cgmath::Point3::new(1.5f32, -5.0, 3.0), + cgmath::Point3::new(0f32, 0.0, 0.0), + cgmath::Vector3::unit_z(), + ); + let mx_correction = framework::OPENGL_TO_WGPU_MATRIX; + mx_correction * mx_projection * mx_view + } +} + +impl framework::Example for Example { + fn optional_features() -> wgt::Features { + wgt::Features::NON_FILL_POLYGON_MODE + } + + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) -> Self { + // Create the vertex and index buffers + let vertex_size = mem::size_of::(); + let (vertex_data, index_data) = create_vertices(); + + let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Vertex Buffer"), + contents: bytemuck::cast_slice(&vertex_data), + usage: wgpu::BufferUsage::VERTEX, + }); + + let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Index Buffer"), + contents: bytemuck::cast_slice(&index_data), + usage: wgpu::BufferUsage::INDEX, + }); + + // Create pipeline layout + let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: None, + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new(64), + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + multisampled: false, + sample_type: wgpu::TextureSampleType::Uint, + view_dimension: wgpu::TextureViewDimension::D2, + }, + count: None, + }, + ], + }); + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[&bind_group_layout], + push_constant_ranges: &[], + }); + + // Create the texture + let size = 256u32; + let texels = create_texels(size as usize); + let texture_extent = wgpu::Extent3d { + width: size, + height: size, + depth_or_array_layers: 1, + }; + let texture = device.create_texture(&wgpu::TextureDescriptor { + label: None, + size: texture_extent, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::R8Uint, + usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + }); + let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + queue.write_texture( + wgpu::ImageCopyTexture { + texture: &texture, + mip_level: 0, + origin: wgpu::Origin3d::ZERO, + }, + &texels, + wgpu::ImageDataLayout { + offset: 0, + bytes_per_row: Some(std::num::NonZeroU32::new(size).unwrap()), + rows_per_image: None, + }, + texture_extent, + ); + + // Create other resources + let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32); + let mx_ref: &[f32; 16] = mx_total.as_ref(); + let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Uniform Buffer"), + contents: bytemuck::cast_slice(mx_ref), + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + }); + + // Create bind group + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: uniform_buf.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView(&texture_view), + }, + ], + label: None, + }); + + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgpu::Backend::Metal | wgpu::Backend::Vulkan | wgpu::Backend::Gl => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION + } + _ => (), //TODO + } + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + flags, + }); + + let vertex_buffers = [wgpu::VertexBufferLayout { + array_stride: vertex_size as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &[ + wgpu::VertexAttribute { + format: wgpu::VertexFormat::Float32x4, + offset: 0, + shader_location: 0, + }, + wgpu::VertexAttribute { + format: wgpu::VertexFormat::Float32x2, + offset: 4 * 4, + shader_location: 1, + }, + ], + }]; + + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &vertex_buffers, + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + cull_mode: Some(wgpu::Face::Back), + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + let pipeline_wire = if device + .features() + .contains(wgt::Features::NON_FILL_POLYGON_MODE) + { + let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &vertex_buffers, + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_wire", + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + operation: wgpu::BlendOperation::Add, + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + }, + alpha: wgpu::BlendComponent::REPLACE, + }), + write_mask: wgpu::ColorWrite::ALL, + }], + }), + primitive: wgpu::PrimitiveState { + front_face: wgpu::FrontFace::Ccw, + cull_mode: Some(wgpu::Face::Back), + polygon_mode: wgpu::PolygonMode::Line, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + Some(pipeline_wire) + } else { + None + }; + + // Done + Example { + vertex_buf, + index_buf, + index_count: index_data.len(), + bind_group, + uniform_buf, + pipeline, + pipeline_wire, + } + } + + fn update(&mut self, _event: winit::event::WindowEvent) { + //empty + } + + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + _device: &wgpu::Device, + queue: &wgpu::Queue, + ) { + let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32); + let mx_ref: &[f32; 16] = mx_total.as_ref(); + queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(mx_ref)); + } + + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + rpass.push_debug_group("Prepare data for draw."); + rpass.set_pipeline(&self.pipeline); + rpass.set_bind_group(0, &self.bind_group, &[]); + rpass.set_index_buffer(self.index_buf.slice(..), wgpu::IndexFormat::Uint16); + rpass.set_vertex_buffer(0, self.vertex_buf.slice(..)); + rpass.pop_debug_group(); + rpass.insert_debug_marker("Draw!"); + rpass.draw_indexed(0..self.index_count as u32, 0, 0..1); + if let Some(ref pipe) = self.pipeline_wire { + rpass.set_pipeline(pipe); + rpass.draw_indexed(0..self.index_count as u32, 0, 0..1); + } + } + + queue.submit(Some(encoder.finish())); + } +} + +fn main() { + framework::run::("cube"); +} diff --git a/wgpu/examples/cube/screenshot.png b/wgpu/examples/cube/screenshot.png new file mode 100644 index 000000000..784ffc463 Binary files /dev/null and b/wgpu/examples/cube/screenshot.png differ diff --git a/wgpu/examples/cube/shader.wgsl b/wgpu/examples/cube/shader.wgsl new file mode 100644 index 000000000..58599f284 --- /dev/null +++ b/wgpu/examples/cube/shader.wgsl @@ -0,0 +1,37 @@ +struct VertexOutput { + [[location(0)]] tex_coord: vec2; + [[builtin(position)]] position: vec4; +}; + +[[block]] +struct Locals { + transform: mat4x4; +}; +[[group(0), binding(0)]] +var r_locals: Locals; + +[[stage(vertex)]] +fn vs_main( + [[location(0)]] position: vec4, + [[location(1)]] tex_coord: vec2, +) -> VertexOutput { + var out: VertexOutput; + out.tex_coord = tex_coord; + out.position = r_locals.transform * position; + return out; +} + +[[group(0), binding(1)]] +var r_color: texture_2d; + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + let tex = textureLoad(r_color, vec2(in.tex_coord * 256.0), 0); + let v = f32(tex.x) / 255.0; + return vec4(1.0 - (v * 5.0), 1.0 - (v * 15.0), 1.0 - (v * 50.0), 1.0); +} + +[[stage(fragment)]] +fn fs_wire() -> [[location(0)]] vec4 { + return vec4(0.0, 0.5, 0.0, 0.5); +} diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs new file mode 100644 index 000000000..6f8e875af --- /dev/null +++ b/wgpu/examples/framework.rs @@ -0,0 +1,370 @@ +use std::future::Future; +#[cfg(not(target_arch = "wasm32"))] +use std::time::{Duration, Instant}; +use winit::{ + event::{self, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, +}; + +#[rustfmt::skip] +#[allow(unused)] +pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4 = cgmath::Matrix4::new( + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.0, 0.0, 0.5, 1.0, +); + +#[allow(dead_code)] +pub fn cast_slice(data: &[T]) -> &[u8] { + use std::{mem::size_of, slice::from_raw_parts}; + + unsafe { from_raw_parts(data.as_ptr() as *const u8, data.len() * size_of::()) } +} + +#[allow(dead_code)] +pub enum ShaderStage { + Vertex, + Fragment, + Compute, +} + +pub trait Example: 'static + Sized { + fn optional_features() -> wgpu::Features { + wgpu::Features::empty() + } + fn required_features() -> wgpu::Features { + wgpu::Features::empty() + } + fn required_limits() -> wgpu::Limits { + wgpu::Limits::default() + } + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) -> Self; + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + queue: &wgpu::Queue, + ); + fn update(&mut self, event: WindowEvent); + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + spawner: &Spawner, + ); +} + +struct Setup { + window: winit::window::Window, + event_loop: EventLoop<()>, + instance: wgpu::Instance, + size: winit::dpi::PhysicalSize, + surface: wgpu::Surface, + adapter: wgpu::Adapter, + device: wgpu::Device, + queue: wgpu::Queue, +} + +async fn setup(title: &str) -> Setup { + #[cfg(not(target_arch = "wasm32"))] + { + env_logger::init(); + }; + + let event_loop = EventLoop::new(); + let mut builder = winit::window::WindowBuilder::new(); + builder = builder.with_title(title); + #[cfg(windows_OFF)] // TODO + { + use winit::platform::windows::WindowBuilderExtWindows; + builder = builder.with_no_redirection_bitmap(true); + } + let window = builder.build(&event_loop).unwrap(); + + #[cfg(target_arch = "wasm32")] + { + use winit::platform::web::WindowExtWebSys; + console_log::init().expect("could not initialize logger"); + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + // On wasm, append the canvas to the document body + web_sys::window() + .and_then(|win| win.document()) + .and_then(|doc| doc.body()) + .and_then(|body| { + body.append_child(&web_sys::Element::from(window.canvas())) + .ok() + }) + .expect("couldn't append canvas to document body"); + } + + log::info!("Initializing the surface..."); + + let backend = if let Ok(backend) = std::env::var("WGPU_BACKEND") { + match backend.to_lowercase().as_str() { + "vulkan" => wgpu::BackendBit::VULKAN, + "metal" => wgpu::BackendBit::METAL, + "dx12" => wgpu::BackendBit::DX12, + "dx11" => wgpu::BackendBit::DX11, + "gl" => wgpu::BackendBit::GL, + "webgpu" => wgpu::BackendBit::BROWSER_WEBGPU, + other => panic!("Unknown backend: {}", other), + } + } else { + wgpu::BackendBit::PRIMARY + }; + let power_preference = if let Ok(power_preference) = std::env::var("WGPU_POWER_PREF") { + match power_preference.to_lowercase().as_str() { + "low" => wgpu::PowerPreference::LowPower, + "high" => wgpu::PowerPreference::HighPerformance, + other => panic!("Unknown power preference: {}", other), + } + } else { + wgpu::PowerPreference::default() + }; + let instance = wgpu::Instance::new(backend); + let (size, surface) = unsafe { + let size = window.inner_size(); + let surface = instance.create_surface(&window); + (size, surface) + }; + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions { + power_preference, + compatible_surface: Some(&surface), + }) + .await + .expect("No suitable GPU adapters found on the system!"); + + #[cfg(not(target_arch = "wasm32"))] + { + let adapter_info = adapter.get_info(); + println!("Using {} ({:?})", adapter_info.name, adapter_info.backend); + } + + let optional_features = E::optional_features(); + let required_features = E::required_features(); + let adapter_features = adapter.features(); + assert!( + adapter_features.contains(required_features), + "Adapter does not support required features for this example: {:?}", + required_features - adapter_features + ); + + let needed_limits = E::required_limits(); + + let trace_dir = std::env::var("WGPU_TRACE"); + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: (optional_features & adapter_features) | required_features, + limits: needed_limits, + }, + trace_dir.ok().as_ref().map(std::path::Path::new), + ) + .await + .expect("Unable to find a suitable GPU adapter!"); + + Setup { + window, + event_loop, + instance, + size, + surface, + adapter, + device, + queue, + } +} + +fn start( + Setup { + window, + event_loop, + instance, + size, + surface, + adapter, + device, + queue, + }: Setup, +) { + let spawner = Spawner::new(); + let mut sc_desc = wgpu::SwapChainDescriptor { + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + format: adapter.get_swap_chain_preferred_format(&surface).unwrap(), + width: size.width, + height: size.height, + present_mode: wgpu::PresentMode::Mailbox, + }; + let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); + + log::info!("Initializing the example..."); + let mut example = E::init(&sc_desc, &adapter, &device, &queue); + + #[cfg(not(target_arch = "wasm32"))] + let mut last_update_inst = Instant::now(); + #[cfg(not(target_arch = "wasm32"))] + let mut last_frame_inst = Instant::now(); + #[cfg(not(target_arch = "wasm32"))] + let (mut frame_count, mut accum_time) = (0, 0.0); + + log::info!("Entering render loop..."); + event_loop.run(move |event, _, control_flow| { + let _ = (&instance, &adapter); // force ownership by the closure + *control_flow = if cfg!(feature = "metal-auto-capture") { + ControlFlow::Exit + } else { + ControlFlow::Poll + }; + match event { + event::Event::RedrawEventsCleared => { + #[cfg(not(target_arch = "wasm32"))] + { + // Clamp to some max framerate to avoid busy-looping too much + // (we might be in wgpu::PresentMode::Mailbox, thus discarding superfluous frames) + // + // winit has window.current_monitor().video_modes() but that is a list of all full screen video modes. + // So without extra dependencies it's a bit tricky to get the max refresh rate we can run the window on. + // Therefore we just go with 60fps - sorry 120hz+ folks! + let target_frametime = Duration::from_secs_f64(1.0 / 60.0); + let time_since_last_frame = last_update_inst.elapsed(); + if time_since_last_frame >= target_frametime { + window.request_redraw(); + last_update_inst = Instant::now(); + } else { + *control_flow = ControlFlow::WaitUntil( + Instant::now() + target_frametime - time_since_last_frame, + ); + } + + spawner.run_until_stalled(); + } + + #[cfg(target_arch = "wasm32")] + window.request_redraw(); + } + event::Event::WindowEvent { + event: WindowEvent::Resized(size), + .. + } => { + log::info!("Resizing to {:?}", size); + sc_desc.width = size.width.max(1); + sc_desc.height = size.height.max(1); + example.resize(&sc_desc, &device, &queue); + swap_chain = device.create_swap_chain(&surface, &sc_desc); + } + event::Event::WindowEvent { event, .. } => match event { + WindowEvent::KeyboardInput { + input: + event::KeyboardInput { + virtual_keycode: Some(event::VirtualKeyCode::Escape), + state: event::ElementState::Pressed, + .. + }, + .. + } + | WindowEvent::CloseRequested => { + *control_flow = ControlFlow::Exit; + } + _ => { + example.update(event); + } + }, + event::Event::RedrawRequested(_) => { + #[cfg(not(target_arch = "wasm32"))] + { + accum_time += last_frame_inst.elapsed().as_secs_f32(); + last_frame_inst = Instant::now(); + frame_count += 1; + if frame_count == 100 { + println!( + "Avg frame time {}ms", + accum_time * 1000.0 / frame_count as f32 + ); + accum_time = 0.0; + frame_count = 0; + } + } + + let frame = match swap_chain.get_current_frame() { + Ok(frame) => frame, + Err(_) => { + swap_chain = device.create_swap_chain(&surface, &sc_desc); + swap_chain + .get_current_frame() + .expect("Failed to acquire next swap chain texture!") + } + }; + + example.render(&frame.output, &device, &queue, &spawner); + } + _ => {} + } + }); +} + +#[cfg(not(target_arch = "wasm32"))] +pub struct Spawner<'a> { + executor: async_executor::LocalExecutor<'a>, +} + +#[cfg(not(target_arch = "wasm32"))] +impl<'a> Spawner<'a> { + fn new() -> Self { + Self { + executor: async_executor::LocalExecutor::new(), + } + } + + #[allow(dead_code)] + pub fn spawn_local(&self, future: impl Future + 'a) { + self.executor.spawn(future).detach(); + } + + fn run_until_stalled(&self) { + while self.executor.try_tick() {} + } +} + +#[cfg(target_arch = "wasm32")] +pub struct Spawner {} + +#[cfg(target_arch = "wasm32")] +impl Spawner { + fn new() -> Self { + Self {} + } + + #[allow(dead_code)] + pub fn spawn_local(&self, future: impl Future + 'static) { + wasm_bindgen_futures::spawn_local(future); + } +} + +#[cfg(not(target_arch = "wasm32"))] +pub fn run(title: &str) { + let setup = pollster::block_on(setup::(title)); + start::(setup); +} + +#[cfg(target_arch = "wasm32")] +pub fn run(title: &str) { + let title = title.to_owned(); + wasm_bindgen_futures::spawn_local(async move { + let setup = setup::(&title).await; + start::(setup); + }); +} + +// This allows treating the framework as a standalone example, +// thus avoiding listing the example names in `Cargo.toml`. +#[allow(dead_code)] +fn main() {} diff --git a/wgpu/examples/hello-compute/README.md b/wgpu/examples/hello-compute/README.md new file mode 100644 index 000000000..93eaa4b8c --- /dev/null +++ b/wgpu/examples/hello-compute/README.md @@ -0,0 +1,22 @@ +# hello-compute + +Runs a compute shader to determine the number of iterations of the rules from +Collatz Conjecture + +- If n is even, n = n/2 +- If n is odd, n = 3n+1 + +that it will take to finish and reach the number `1`. + +## To Run + +``` +# Pass in any 4 numbers as arguments +RUST_LOG=hello_compute cargo run --example hello-compute 1 4 3 295 +``` + +## Example Output + +``` +[2020-04-25T11:15:33Z INFO hello_compute] Times: [0, 2, 7, 55] +``` diff --git a/wgpu/examples/hello-compute/main.rs b/wgpu/examples/hello-compute/main.rs new file mode 100644 index 000000000..501b53d61 --- /dev/null +++ b/wgpu/examples/hello-compute/main.rs @@ -0,0 +1,243 @@ +use std::{borrow::Cow, convert::TryInto, str::FromStr}; +use wgpu::util::DeviceExt; + +// Indicates a u32 overflow in an intermediate Collatz value +const OVERFLOW: u32 = 0xffffffff; + +async fn run() { + let numbers = if std::env::args().len() <= 1 { + let default = vec![1, 2, 3, 4]; + println!("No numbers were provided, defaulting to {:?}", default); + default + } else { + std::env::args() + .skip(1) + .map(|s| u32::from_str(&s).expect("You must pass a list of positive integers!")) + .collect() + }; + + let steps = execute_gpu(numbers).await; + + let disp_steps: Vec = steps + .iter() + .map(|&n| match n { + OVERFLOW => "OVERFLOW".to_string(), + _ => n.to_string(), + }) + .collect(); + + println!("Steps: [{}]", disp_steps.join(", ")); + #[cfg(target_arch = "wasm32")] + log::info!("Steps: [{}]", disp_steps.join(", ")); +} + +async fn execute_gpu(numbers: Vec) -> Vec { + // Instantiates instance of WebGPU + let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + + // `request_adapter` instantiates the general connection to the GPU + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions::default()) + .await + .unwrap(); + + // `request_device` instantiates the feature specific connection to the GPU, defining some parameters, + // `features` being the available features. + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: wgpu::Features::empty(), + limits: wgpu::Limits::default(), + }, + None, + ) + .await + .unwrap(); + + // Loads the shader from the SPIR-V file.arrayvec + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgpu::Backend::Vulkan | wgpu::Backend::Metal | wgpu::Backend::Gl => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION; + } + _ => {} + } + let cs_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + flags, + }); + + // Gets the size in bytes of the buffer. + let slice_size = numbers.len() * std::mem::size_of::(); + let size = slice_size as wgpu::BufferAddress; + + // Instantiates buffer without data. + // `usage` of buffer specifies how it can be used: + // `BufferUsage::MAP_READ` allows it to be read (outside the shader). + // `BufferUsage::COPY_DST` allows it to be the destination of the copy. + let staging_buffer = device.create_buffer(&wgpu::BufferDescriptor { + label: None, + size, + usage: wgpu::BufferUsage::MAP_READ | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + // Instantiates buffer with data (`numbers`). + // Usage allowing the buffer to be: + // A storage buffer (can be bound within a bind group and thus available to a shader). + // The destination of a copy. + // The source of a copy. + let storage_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Storage Buffer"), + contents: bytemuck::cast_slice(&numbers), + usage: wgpu::BufferUsage::STORAGE + | wgpu::BufferUsage::COPY_DST + | wgpu::BufferUsage::COPY_SRC, + }); + + // A bind group defines how buffers are accessed by shaders. + // It is to WebGPU what a descriptor set is to Vulkan. + // `binding` here refers to the `binding` of a buffer in the shader (`layout(set = 0, binding = 0) buffer`). + + // A pipeline specifies the operation of a shader + + // Instantiates the pipeline. + let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { + label: None, + layout: None, + module: &cs_module, + entry_point: "main", + }); + + // Instantiates the bind group, once again specifying the binding of buffers. + let bind_group_layout = compute_pipeline.get_bind_group_layout(0); + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + label: None, + layout: &bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: storage_buffer.as_entire_binding(), + }], + }); + + // A command encoder executes one or many pipelines. + // It is to WebGPU what a command buffer is to Vulkan. + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + { + let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: None }); + cpass.set_pipeline(&compute_pipeline); + cpass.set_bind_group(0, &bind_group, &[]); + cpass.insert_debug_marker("compute collatz iterations"); + cpass.dispatch(numbers.len() as u32, 1, 1); // Number of cells to run, the (x,y,z) size of item being processed + } + // Sets adds copy operation to command encoder. + // Will copy data from storage buffer on GPU to staging buffer on CPU. + encoder.copy_buffer_to_buffer(&storage_buffer, 0, &staging_buffer, 0, size); + + // Submits command encoder for processing + queue.submit(Some(encoder.finish())); + + // Note that we're not calling `.await` here. + let buffer_slice = staging_buffer.slice(..); + // Gets the future representing when `staging_buffer` can be read from + let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read); + + // Poll the device in a blocking manner so that our future resolves. + // In an actual application, `device.poll(...)` should + // be called in an event loop or on another thread. + device.poll(wgpu::Maintain::Wait); + + // Awaits until `buffer_future` can be read from + if let Ok(()) = buffer_future.await { + // Gets contents of buffer + let data = buffer_slice.get_mapped_range(); + // Since contents are got in bytes, this converts these bytes back to u32 + let result = data + .chunks_exact(4) + .map(|b| u32::from_ne_bytes(b.try_into().unwrap())) + .collect(); + + // With the current interface, we have to make sure all mapped views are + // dropped before we unmap the buffer. + drop(data); + staging_buffer.unmap(); // Unmaps buffer from memory + // If you are familiar with C++ these 2 lines can be thought of similarly to: + // delete myPointer; + // myPointer = NULL; + // It effectively frees the memory + + // Returns data from buffer + result + } else { + panic!("failed to run compute on gpu!") + } +} + +fn main() { + #[cfg(not(target_arch = "wasm32"))] + { + env_logger::init(); + pollster::block_on(run()); + } + #[cfg(target_arch = "wasm32")] + { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + console_log::init().expect("could not initialize logger"); + wasm_bindgen_futures::spawn_local(run()); + } +} + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tests { + use super::*; + + #[test] + fn test_compute_1() { + let input = vec![1, 2, 3, 4]; + pollster::block_on(assert_execute_gpu(input, vec![0, 1, 7, 2])); + } + + #[test] + fn test_compute_2() { + let input = vec![5, 23, 10, 9]; + pollster::block_on(assert_execute_gpu(input, vec![5, 15, 6, 19])); + } + + #[test] + fn test_compute_overflow() { + let input = vec![77031, 837799, 8400511, 63728127]; + pollster::block_on(assert_execute_gpu( + input, + vec![350, 524, OVERFLOW, OVERFLOW], + )); + } + + #[test] + fn test_multithreaded_compute() { + use std::{sync::mpsc, thread, time::Duration}; + + let thread_count = 8; + + let (tx, rx) = mpsc::channel(); + for _ in 0..thread_count { + let tx = tx.clone(); + thread::spawn(move || { + let input = vec![100, 100, 100]; + pollster::block_on(assert_execute_gpu(input, vec![25, 25, 25])); + tx.send(true).unwrap(); + }); + } + + for _ in 0..thread_count { + rx.recv_timeout(Duration::from_secs(10)) + .expect("A thread never completed."); + } + } + + async fn assert_execute_gpu(input: Vec, expected: Vec) { + assert_eq!(execute_gpu(input).await, expected); + } +} diff --git a/wgpu/examples/hello-compute/shader.wgsl b/wgpu/examples/hello-compute/shader.wgsl new file mode 100644 index 000000000..2ac9b864b --- /dev/null +++ b/wgpu/examples/hello-compute/shader.wgsl @@ -0,0 +1,41 @@ +[[block]] +struct PrimeIndices { + data: [[stride(4)]] array; +}; // this is used as both input and output for convenience + +[[group(0), binding(0)]] +var v_indices: [[access(read_write)]] PrimeIndices; + +// The Collatz Conjecture states that for any integer n: +// If n is even, n = n/2 +// If n is odd, n = 3n+1 +// And repeat this process for each new n, you will always eventually reach 1. +// Though the conjecture has not been proven, no counterexample has ever been found. +// This function returns how many times this recurrence needs to be applied to reach 1. +fn collatz_iterations(n_base: u32) -> u32{ + var n: u32 = n_base; + var i: u32 = 0u; + loop { + if (n <= 1u) { + break; + } + if (n % 2u == 0u) { + n = n / 2u; + } + else { + // Overflow? (i.e. 3*n + 1 > 0xffffffffu?) + if (n >= 1431655765u) { // 0x55555555u + return 4294967295u; // 0xffffffffu + } + + n = 3u * n + 1u; + } + i = i + 1u; + } + return i; +} + +[[stage(compute), workgroup_size(1)]] +fn main([[builtin(global_invocation_id)]] global_id: vec3) { + v_indices.data[global_id.x] = collatz_iterations(v_indices.data[global_id.x]); +} diff --git a/wgpu/examples/hello-triangle/README.md b/wgpu/examples/hello-triangle/README.md new file mode 100644 index 000000000..f53af111a --- /dev/null +++ b/wgpu/examples/hello-triangle/README.md @@ -0,0 +1,13 @@ +# hello-triangle + +This example renders a triangle to a window. + +## To Run + +``` +cargo run --example hello-triangle +``` + +## Screenshots + +![Triangle window](./screenshot.png) diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs new file mode 100644 index 000000000..23d8b3ff6 --- /dev/null +++ b/wgpu/examples/hello-triangle/main.rs @@ -0,0 +1,154 @@ +use std::borrow::Cow; +use winit::{ + event::{Event, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::Window, +}; + +async fn run(event_loop: EventLoop<()>, window: Window) { + let size = window.inner_size(); + let instance = wgpu::Instance::new(wgpu::BackendBit::all()); + let surface = unsafe { instance.create_surface(&window) }; + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::default(), + // Request an adapter which can render to our surface + compatible_surface: Some(&surface), + }) + .await + .expect("Failed to find an appropriate adapter"); + + // Create the logical device and command queue + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: wgpu::Features::empty(), + limits: wgpu::Limits::default(), + }, + None, + ) + .await + .expect("Failed to create device"); + + // Load the shaders from disk + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + flags: wgpu::ShaderFlags::all(), + }); + + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[], + push_constant_ranges: &[], + }); + + let swapchain_format = adapter.get_swap_chain_preferred_format(&surface).unwrap(); + + let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[swapchain_format.into()], + }), + primitive: wgpu::PrimitiveState::default(), + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + let mut sc_desc = wgpu::SwapChainDescriptor { + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + format: swapchain_format, + width: size.width, + height: size.height, + present_mode: wgpu::PresentMode::Mailbox, + }; + + let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); + + event_loop.run(move |event, _, control_flow| { + // Have the closure take ownership of the resources. + // `event_loop.run` never returns, therefore we must do this to ensure + // the resources are properly cleaned up. + let _ = (&instance, &adapter, &shader, &pipeline_layout); + + *control_flow = ControlFlow::Wait; + match event { + Event::WindowEvent { + event: WindowEvent::Resized(size), + .. + } => { + // Recreate the swap chain with the new size + sc_desc.width = size.width; + sc_desc.height = size.height; + swap_chain = device.create_swap_chain(&surface, &sc_desc); + } + Event::RedrawRequested(_) => { + let frame = swap_chain + .get_current_frame() + .expect("Failed to acquire next swap chain texture") + .output; + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + rpass.set_pipeline(&render_pipeline); + rpass.draw(0..3, 0..1); + } + + queue.submit(Some(encoder.finish())); + } + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => *control_flow = ControlFlow::Exit, + _ => {} + } + }); +} + +fn main() { + let event_loop = EventLoop::new(); + let window = winit::window::Window::new(&event_loop).unwrap(); + #[cfg(not(target_arch = "wasm32"))] + { + env_logger::init(); + // Temporarily avoid srgb formats for the swapchain on the web + pollster::block_on(run(event_loop, window)); + } + #[cfg(target_arch = "wasm32")] + { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + console_log::init().expect("could not initialize logger"); + use winit::platform::web::WindowExtWebSys; + // On wasm, append the canvas to the document body + web_sys::window() + .and_then(|win| win.document()) + .and_then(|doc| doc.body()) + .and_then(|body| { + body.append_child(&web_sys::Element::from(window.canvas())) + .ok() + }) + .expect("couldn't append canvas to document body"); + wasm_bindgen_futures::spawn_local(run(event_loop, window)); + } +} diff --git a/wgpu/examples/hello-triangle/screenshot.png b/wgpu/examples/hello-triangle/screenshot.png new file mode 100644 index 000000000..ae8350b9f Binary files /dev/null and b/wgpu/examples/hello-triangle/screenshot.png differ diff --git a/wgpu/examples/hello-triangle/shader.wgsl b/wgpu/examples/hello-triangle/shader.wgsl new file mode 100644 index 000000000..a1ef447d6 --- /dev/null +++ b/wgpu/examples/hello-triangle/shader.wgsl @@ -0,0 +1,11 @@ +[[stage(vertex)]] +fn vs_main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4 { + let x = f32(i32(in_vertex_index) - 1); + let y = f32(i32(in_vertex_index & 1u) * 2 - 1); + return vec4(x, y, 0.0, 1.0); +} + +[[stage(fragment)]] +fn fs_main() -> [[location(0)]] vec4 { + return vec4(1.0, 0.0, 0.0, 1.0); +} diff --git a/wgpu/examples/hello-windows/README.md b/wgpu/examples/hello-windows/README.md new file mode 100644 index 000000000..e45071333 --- /dev/null +++ b/wgpu/examples/hello-windows/README.md @@ -0,0 +1,13 @@ +# hello-windows + +This example renders a set of 16 windows, with a differently colored background + +## To Run + +``` +cargo run --example hello-windows +``` + +## Screenshots + +![16 windows](./screenshot.png) diff --git a/wgpu/examples/hello-windows/main.rs b/wgpu/examples/hello-windows/main.rs new file mode 100644 index 000000000..3e55d6539 --- /dev/null +++ b/wgpu/examples/hello-windows/main.rs @@ -0,0 +1,203 @@ +use std::collections::HashMap; +use winit::{ + event::{Event, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::{Window, WindowId}, +}; + +struct ViewportDesc { + window: Window, + background: wgpu::Color, + surface: wgpu::Surface, +} + +struct Viewport { + desc: ViewportDesc, + sc_desc: wgpu::SwapChainDescriptor, + swap_chain: wgpu::SwapChain, +} + +impl ViewportDesc { + fn new(window: Window, background: wgpu::Color, instance: &wgpu::Instance) -> Self { + let surface = unsafe { instance.create_surface(&window) }; + Self { + window, + background, + surface, + } + } + + fn build(self, adapter: &wgpu::Adapter, device: &wgpu::Device) -> Viewport { + let size = self.window.inner_size(); + + let sc_desc = wgpu::SwapChainDescriptor { + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + format: adapter + .get_swap_chain_preferred_format(&self.surface) + .unwrap(), + width: size.width, + height: size.height, + present_mode: wgpu::PresentMode::Fifo, + }; + + let swap_chain = device.create_swap_chain(&self.surface, &sc_desc); + + Viewport { + desc: self, + sc_desc, + swap_chain, + } + } +} + +impl Viewport { + fn resize(&mut self, device: &wgpu::Device, size: winit::dpi::PhysicalSize) { + self.sc_desc.width = size.width; + self.sc_desc.height = size.height; + self.swap_chain = device.create_swap_chain(&self.desc.surface, &self.sc_desc); + } + fn get_current_frame(&mut self) -> wgpu::SwapChainTexture { + self.swap_chain + .get_current_frame() + .expect("Failed to acquire next swap chain texture") + .output + } +} + +async fn run(event_loop: EventLoop<()>, viewports: Vec<(Window, wgpu::Color)>) { + let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let viewports: Vec<_> = viewports + .into_iter() + .map(|(window, color)| ViewportDesc::new(window, color, &instance)) + .collect(); + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::default(), + // Request an adapter which can render to our surface + compatible_surface: viewports.first().map(|desc| &desc.surface), + }) + .await + .expect("Failed to find an appropriate adapter"); + + // Create the logical device and command queue + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: wgpu::Features::empty(), + limits: wgpu::Limits::default(), + }, + None, + ) + .await + .expect("Failed to create device"); + + let mut viewports: HashMap = viewports + .into_iter() + .map(|desc| (desc.window.id(), desc.build(&adapter, &device))) + .collect(); + + event_loop.run(move |event, _, control_flow| { + // Have the closure take ownership of the resources. + // `event_loop.run` never returns, therefore we must do this to ensure + // the resources are properly cleaned up. + let _ = (&instance, &adapter); + + *control_flow = ControlFlow::Wait; + match event { + Event::WindowEvent { + window_id, + event: WindowEvent::Resized(size), + .. + } => { + // Recreate the swap chain with the new size + if let Some(viewport) = viewports.get_mut(&window_id) { + viewport.resize(&device, size); + } + } + Event::RedrawRequested(window_id) => { + if let Some(viewport) = viewports.get_mut(&window_id) { + let frame = viewport.get_current_frame(); + let mut encoder = device + .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + { + let _rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(viewport.desc.background), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + } + + queue.submit(Some(encoder.finish())); + } + } + Event::WindowEvent { + window_id, + event: WindowEvent::CloseRequested, + .. + } => { + viewports.remove(&window_id); + if viewports.is_empty() { + *control_flow = ControlFlow::Exit + } + } + _ => {} + } + }); +} + +fn main() { + #[cfg(not(target_arch = "wasm32"))] + { + const WINDOW_SIZE: u32 = 128; + const WINDOW_PADDING: u32 = 16; + const WINDOW_TITLEBAR: u32 = 32; + const WINDOW_OFFSET: u32 = WINDOW_SIZE + WINDOW_PADDING; + const ROWS: u32 = 4; + const COLUMNS: u32 = 4; + + let event_loop = EventLoop::new(); + let mut viewports = Vec::with_capacity((ROWS * COLUMNS) as usize); + for row in 0..ROWS { + for column in 0..COLUMNS { + let window = winit::window::WindowBuilder::new() + .with_title(format!("x{}y{}", column, row)) + .with_inner_size(winit::dpi::PhysicalSize::new(WINDOW_SIZE, WINDOW_SIZE)) + .build(&event_loop) + .unwrap(); + window.set_outer_position(winit::dpi::PhysicalPosition::new( + WINDOW_PADDING + column * WINDOW_OFFSET, + WINDOW_PADDING + row * (WINDOW_OFFSET + WINDOW_TITLEBAR), + )); + fn frac(index: u32, max: u32) -> f64 { + index as f64 / max as f64 + } + viewports.push(( + window, + wgpu::Color { + r: frac(row, ROWS), + g: 0.5 - frac(row * column, ROWS * COLUMNS) * 0.5, + b: frac(column, COLUMNS), + a: 1.0, + }, + )) + } + } + + env_logger::init(); + // Temporarily avoid srgb formats for the swapchain on the web + pollster::block_on(run(event_loop, viewports)); + } + #[cfg(target_arch = "wasm32")] + { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + panic!("wasm32 is not supported") + } +} diff --git a/wgpu/examples/hello-windows/screenshot.png b/wgpu/examples/hello-windows/screenshot.png new file mode 100644 index 000000000..202a3c54c Binary files /dev/null and b/wgpu/examples/hello-windows/screenshot.png differ diff --git a/wgpu/examples/hello/README.md b/wgpu/examples/hello/README.md new file mode 100644 index 000000000..a24ad33b2 --- /dev/null +++ b/wgpu/examples/hello/README.md @@ -0,0 +1,16 @@ +# hello + +This example prints output describing the adapter in use. + +## To Run + +``` +cargo run --example hello +``` + +## Example output + +``` +# You might see different output as it depends on your graphics card +AdapterInfo { name: "Intel(R) UHD Graphics 630", vendor: 0, device: 0, device_type: IntegratedGpu, backend: Metal } +``` diff --git a/wgpu/examples/hello/main.rs b/wgpu/examples/hello/main.rs new file mode 100644 index 000000000..8ee08329e --- /dev/null +++ b/wgpu/examples/hello/main.rs @@ -0,0 +1,25 @@ +/// This example shows how to describe the adapter in use. +async fn run() { + #[cfg_attr(target_arch = "wasm32", allow(unused_variables))] + let adapter = wgpu::Instance::new(wgpu::BackendBit::PRIMARY) + .request_adapter(&wgpu::RequestAdapterOptions::default()) + .await + .unwrap(); + + #[cfg(not(target_arch = "wasm32"))] + println!("{:?}", adapter.get_info()) +} + +fn main() { + #[cfg(not(target_arch = "wasm32"))] + { + env_logger::init(); + pollster::block_on(run()); + } + #[cfg(target_arch = "wasm32")] + { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); + console_log::init().expect("could not initialize logger"); + wasm_bindgen_futures::spawn_local(run()); + } +} diff --git a/wgpu/examples/mipmap/README.md b/wgpu/examples/mipmap/README.md new file mode 100644 index 000000000..a50b0ecbf --- /dev/null +++ b/wgpu/examples/mipmap/README.md @@ -0,0 +1,13 @@ +# mipmap + +This example shows how to generate and make use of mipmaps. + +## To Run + +``` +cargo run --example mipmap +``` + +## Screenshots + +![Mip maps](./screenshot.png) diff --git a/wgpu/examples/mipmap/blit.wgsl b/wgpu/examples/mipmap/blit.wgsl new file mode 100644 index 000000000..f8a91dfc5 --- /dev/null +++ b/wgpu/examples/mipmap/blit.wgsl @@ -0,0 +1,32 @@ +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] tex_coords: vec2; +}; + +[[stage(vertex)]] +fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { + var out: VertexOutput; + let x = i32(vertex_index) / 2; + let y = i32(vertex_index) & 1; + let tc = vec2( + f32(x) * 2.0, + f32(y) * 2.0 + ); + out.position = vec4( + tc.x * 2.0 - 1.0, + 1.0 - tc.y * 2.0, + 0.0, 1.0 + ); + out.tex_coords = tc; + return out; +} + +[[group(0), binding(0)]] +var r_color: texture_2d; +[[group(0), binding(1)]] +var r_sampler: sampler; + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + return textureSample(r_color, r_sampler, in.tex_coords); +} diff --git a/wgpu/examples/mipmap/draw.wgsl b/wgpu/examples/mipmap/draw.wgsl new file mode 100644 index 000000000..9cf0eb93a --- /dev/null +++ b/wgpu/examples/mipmap/draw.wgsl @@ -0,0 +1,33 @@ +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] tex_coords: vec2; +}; + +[[block]] +struct Locals { + transform: mat4x4; +}; +[[group(0), binding(0)]] +var r_data: Locals; + +[[stage(vertex)]] +fn vs_main([[builtin(vertex_index)]] vertex_index: u32) -> VertexOutput { + let pos = vec2( + 100.0 * (1.0 - f32(vertex_index & 2u)), + 1000.0 * f32(vertex_index & 1u) + ); + var out: VertexOutput; + out.tex_coords = 0.05 * pos + vec2(0.5, 0.5); + out.position = r_data.transform * vec4(pos, 0.0, 1.0); + return out; +} + +[[group(0), binding(1)]] +var r_color: texture_2d; +[[group(0), binding(2)]] +var r_sampler: sampler; + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + return textureSample(r_color, r_sampler, in.tex_coords); +} diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs new file mode 100644 index 000000000..00f1aacce --- /dev/null +++ b/wgpu/examples/mipmap/main.rs @@ -0,0 +1,489 @@ +#[path = "../framework.rs"] +mod framework; + +use bytemuck::{Pod, Zeroable}; +use std::{borrow::Cow, mem, num::NonZeroU32}; +use wgpu::util::DeviceExt; + +const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb; +const MIP_LEVEL_COUNT: u32 = 9; +const MIP_PASS_COUNT: u32 = MIP_LEVEL_COUNT - 1; + +fn create_texels(size: usize, cx: f32, cy: f32) -> Vec { + use std::iter; + + (0..size * size) + .flat_map(|id| { + // get high five for recognizing this ;) + let mut x = 4.0 * (id % size) as f32 / (size - 1) as f32 - 2.0; + let mut y = 2.0 * (id / size) as f32 / (size - 1) as f32 - 1.0; + let mut count = 0; + while count < 0xFF && x * x + y * y < 4.0 { + let old_x = x; + x = x * x - y * y + cx; + y = 2.0 * old_x * y + cy; + count += 1; + } + iter::once(0xFF - (count * 2) as u8) + .chain(iter::once(0xFF - (count * 5) as u8)) + .chain(iter::once(0xFF - (count * 13) as u8)) + .chain(iter::once(std::u8::MAX)) + }) + .collect() +} + +struct QuerySets { + timestamp: wgpu::QuerySet, + timestamp_period: f32, + pipeline_statistics: wgpu::QuerySet, + data_buffer: wgpu::Buffer, +} + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct TimestampData { + start: u64, + end: u64, +} + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct QueryData { + timestamps: [TimestampData; MIP_PASS_COUNT as usize], + pipeline_queries: [u64; MIP_PASS_COUNT as usize], +} + +struct Example { + bind_group: wgpu::BindGroup, + uniform_buf: wgpu::Buffer, + draw_pipeline: wgpu::RenderPipeline, +} + +impl Example { + fn generate_matrix(aspect_ratio: f32) -> cgmath::Matrix4 { + let mx_projection = cgmath::perspective(cgmath::Deg(45f32), aspect_ratio, 1.0, 1000.0); + let mx_view = cgmath::Matrix4::look_at_rh( + cgmath::Point3::new(0f32, 0.0, 10.0), + cgmath::Point3::new(0f32, 50.0, 0.0), + cgmath::Vector3::unit_z(), + ); + let mx_correction = framework::OPENGL_TO_WGPU_MATRIX; + mx_correction * mx_projection * mx_view + } + + fn generate_mipmaps( + encoder: &mut wgpu::CommandEncoder, + device: &wgpu::Device, + texture: &wgpu::Texture, + query_sets: &Option, + mip_count: u32, + shader_flags: wgpu::ShaderFlags, + ) { + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("blit.wgsl"))), + flags: shader_flags, + }); + + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("blit"), + layout: None, + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[TEXTURE_FORMAT.into()], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleStrip, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + let bind_group_layout = pipeline.get_bind_group_layout(0); + + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: Some("mip"), + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Nearest, + mipmap_filter: wgpu::FilterMode::Nearest, + ..Default::default() + }); + + let views = (0..mip_count) + .map(|mip| { + texture.create_view(&wgpu::TextureViewDescriptor { + label: Some("mip"), + format: None, + dimension: None, + aspect: wgpu::TextureAspect::All, + base_mip_level: mip, + mip_level_count: NonZeroU32::new(1), + base_array_layer: 0, + array_layer_count: None, + }) + }) + .collect::>(); + + for target_mip in 1..mip_count as usize { + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(&views[target_mip - 1]), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(&sampler), + }, + ], + label: None, + }); + + let pipeline_query_index_base = target_mip as u32 - 1; + let timestamp_query_index_base = (target_mip as u32 - 1) * 2; + + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &views[target_mip], + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + if let Some(ref query_sets) = query_sets { + rpass.write_timestamp(&query_sets.timestamp, timestamp_query_index_base); + rpass.begin_pipeline_statistics_query( + &query_sets.pipeline_statistics, + pipeline_query_index_base, + ); + } + rpass.set_pipeline(&pipeline); + rpass.set_bind_group(0, &bind_group, &[]); + rpass.draw(0..4, 0..1); + if let Some(ref query_sets) = query_sets { + rpass.write_timestamp(&query_sets.timestamp, timestamp_query_index_base + 1); + rpass.end_pipeline_statistics_query(); + } + } + + if let Some(ref query_sets) = query_sets { + let timestamp_query_count = MIP_PASS_COUNT * 2; + encoder.resolve_query_set( + &query_sets.timestamp, + 0..timestamp_query_count, + &query_sets.data_buffer, + 0, + ); + encoder.resolve_query_set( + &query_sets.pipeline_statistics, + 0..MIP_PASS_COUNT, + &query_sets.data_buffer, + (timestamp_query_count * mem::size_of::() as u32) as wgpu::BufferAddress, + ); + } + } +} + +impl framework::Example for Example { + fn optional_features() -> wgpu::Features { + wgpu::Features::TIMESTAMP_QUERY | wgpu::Features::PIPELINE_STATISTICS_QUERY + } + + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) -> Self { + let mut init_encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + + // Create the texture + let size = 1 << MIP_LEVEL_COUNT; + let texels = create_texels(size as usize, -0.8, 0.156); + let texture_extent = wgpu::Extent3d { + width: size, + height: size, + depth_or_array_layers: 1, + }; + let texture = device.create_texture(&wgpu::TextureDescriptor { + size: texture_extent, + mip_level_count: MIP_LEVEL_COUNT, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: TEXTURE_FORMAT, + usage: wgpu::TextureUsage::SAMPLED + | wgpu::TextureUsage::RENDER_ATTACHMENT + | wgpu::TextureUsage::COPY_DST, + label: None, + }); + let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + //Note: we could use queue.write_texture instead, and this is what other + // examples do, but here we want to show another way to do this. + let temp_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Temporary Buffer"), + contents: texels.as_slice(), + usage: wgpu::BufferUsage::COPY_SRC, + }); + init_encoder.copy_buffer_to_texture( + wgpu::ImageCopyBuffer { + buffer: &temp_buf, + layout: wgpu::ImageDataLayout { + offset: 0, + bytes_per_row: Some(NonZeroU32::new(4 * size).unwrap()), + rows_per_image: None, + }, + }, + wgpu::ImageCopyTexture { + texture: &texture, + mip_level: 0, + origin: wgpu::Origin3d::ZERO, + }, + texture_extent, + ); + + // Create other resources + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: None, + address_mode_u: wgpu::AddressMode::Repeat, + address_mode_v: wgpu::AddressMode::Repeat, + address_mode_w: wgpu::AddressMode::Repeat, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Linear, + mipmap_filter: wgpu::FilterMode::Linear, + ..Default::default() + }); + let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32); + let mx_ref: &[f32; 16] = mx_total.as_ref(); + let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Uniform Buffer"), + contents: bytemuck::cast_slice(mx_ref), + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + }); + + // Create the render pipeline + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgpu::Backend::Metal | wgpu::Backend::Vulkan => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION + } + _ => (), //TODO + } + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("draw.wgsl"))), + flags, + }); + + let draw_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("draw"), + layout: None, + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleStrip, + front_face: wgpu::FrontFace::Ccw, + cull_mode: Some(wgpu::Face::Back), + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + // Create bind group + let bind_group_layout = draw_pipeline.get_bind_group_layout(0); + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: uniform_buf.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView(&texture_view), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::Sampler(&sampler), + }, + ], + label: None, + }); + + // If both kinds of query are supported, use queries + let query_sets = if device + .features() + .contains(wgpu::Features::TIMESTAMP_QUERY | wgpu::Features::PIPELINE_STATISTICS_QUERY) + { + // For N total mips, it takes N - 1 passes to generate them, and we're measuring those. + let mip_passes = MIP_LEVEL_COUNT - 1; + + // Create the timestamp query set. We need twice as many queries as we have passes, + // as we need a query at the beginning and at the end of the operation. + let timestamp = device.create_query_set(&wgpu::QuerySetDescriptor { + count: mip_passes * 2, + ty: wgpu::QueryType::Timestamp, + }); + // Timestamp queries use an device-specific timestamp unit. We need to figure out how many + // nanoseconds go by for the timestamp to be incremented by one. The period is this value. + let timestamp_period = queue.get_timestamp_period(); + + // We only need one pipeline statistics query per pass. + let pipeline_statistics = device.create_query_set(&wgpu::QuerySetDescriptor { + count: mip_passes, + ty: wgpu::QueryType::PipelineStatistics( + wgpu::PipelineStatisticsTypes::FRAGMENT_SHADER_INVOCATIONS, + ), + }); + + // This databuffer has to store all of the query results, 2 * passes timestamp queries + // and 1 * passes statistics queries. Each query returns a u64 value. + let data_buffer = device.create_buffer(&wgpu::BufferDescriptor { + label: Some("query buffer"), + size: mip_passes as wgpu::BufferAddress + * 3 + * mem::size_of::() as wgpu::BufferAddress, + usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::MAP_READ, + mapped_at_creation: false, + }); + + Some(QuerySets { + timestamp, + timestamp_period, + pipeline_statistics, + data_buffer, + }) + } else { + None + }; + + Self::generate_mipmaps( + &mut init_encoder, + &device, + &texture, + &query_sets, + MIP_LEVEL_COUNT, + flags, + ); + + queue.submit(Some(init_encoder.finish())); + if let Some(ref query_sets) = query_sets { + // We can ignore the future as we're about to wait for the device. + let _ = query_sets + .data_buffer + .slice(..) + .map_async(wgpu::MapMode::Read); + // Wait for device to be done rendering mipmaps + device.poll(wgpu::Maintain::Wait); + // This is guaranteed to be ready. + let view = query_sets.data_buffer.slice(..).get_mapped_range(); + // Convert the raw data into a useful structure + let data: &QueryData = bytemuck::from_bytes(&*view); + // Iterate over the data + for (idx, (timestamp, pipeline)) in data + .timestamps + .iter() + .zip(data.pipeline_queries.iter()) + .enumerate() + { + // Figure out the timestamp differences and multiply by the period to get nanoseconds + let nanoseconds = + (timestamp.end - timestamp.start) as f32 * query_sets.timestamp_period; + // Nanoseconds is a bit small, so lets use microseconds. + let microseconds = nanoseconds / 1000.0; + // Print the data! + println!( + "Generating mip level {} took {:.3} μs and called the fragment shader {} times", + idx + 1, + microseconds, + pipeline + ); + } + } + + Example { + bind_group, + uniform_buf, + draw_pipeline, + } + } + + fn update(&mut self, _event: winit::event::WindowEvent) { + //empty + } + + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + _device: &wgpu::Device, + queue: &wgpu::Queue, + ) { + let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32); + let mx_ref: &[f32; 16] = mx_total.as_ref(); + queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(mx_ref)); + } + + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + { + let clear_color = wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }; + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(clear_color), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + rpass.set_pipeline(&self.draw_pipeline); + rpass.set_bind_group(0, &self.bind_group, &[]); + rpass.draw(0..4, 0..1); + } + + queue.submit(Some(encoder.finish())); + } +} + +fn main() { + framework::run::("mipmap"); +} diff --git a/wgpu/examples/mipmap/screenshot.png b/wgpu/examples/mipmap/screenshot.png new file mode 100644 index 000000000..977732afe Binary files /dev/null and b/wgpu/examples/mipmap/screenshot.png differ diff --git a/wgpu/examples/msaa-line/README.md b/wgpu/examples/msaa-line/README.md new file mode 100644 index 000000000..031236f9d --- /dev/null +++ b/wgpu/examples/msaa-line/README.md @@ -0,0 +1,13 @@ +# msaa-line + +This example shows how to render lines using MSAA. + +## To Run + +``` +cargo run --example msaa-line +``` + +## Screenshots + +![MSAA line](./screenshot.png) diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs new file mode 100644 index 000000000..0f02f089e --- /dev/null +++ b/wgpu/examples/msaa-line/main.rs @@ -0,0 +1,292 @@ +//! The parts of this example enabling MSAA are: +//! * The render pipeline is created with a sample_count > 1. +//! * A new texture with a sample_count > 1 is created and set as the color_attachment instead of the swapchain. +//! * The swapchain is now specified as a resolve_target. +//! +//! The parts of this example enabling LineList are: +//! * Set the primitive_topology to PrimitiveTopology::LineList. +//! * Vertices and Indices describe the two points that make up a line. + +#[path = "../framework.rs"] +mod framework; + +use std::{borrow::Cow, iter}; + +use bytemuck::{Pod, Zeroable}; +use wgpu::util::DeviceExt; + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct Vertex { + _pos: [f32; 2], + _color: [f32; 4], +} + +struct Example { + bundle: wgpu::RenderBundle, + shader: wgpu::ShaderModule, + pipeline_layout: wgpu::PipelineLayout, + multisampled_framebuffer: wgpu::TextureView, + vertex_buffer: wgpu::Buffer, + vertex_count: u32, + sample_count: u32, + rebuild_bundle: bool, + sc_desc: wgpu::SwapChainDescriptor, +} + +impl Example { + fn create_bundle( + device: &wgpu::Device, + sc_desc: &wgpu::SwapChainDescriptor, + shader: &wgpu::ShaderModule, + pipeline_layout: &wgpu::PipelineLayout, + sample_count: u32, + vertex_buffer: &wgpu::Buffer, + vertex_count: u32, + ) -> wgpu::RenderBundle { + log::info!("sample_count: {}", sample_count); + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: shader, + entry_point: "vs_main", + buffers: &[wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4], + }], + }, + fragment: Some(wgpu::FragmentState { + module: shader, + entry_point: "fs_main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::LineList, + front_face: wgpu::FrontFace::Ccw, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState { + count: sample_count, + ..Default::default() + }, + }); + let mut encoder = + device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor { + label: None, + color_formats: &[sc_desc.format], + depth_stencil_format: None, + sample_count, + }); + encoder.set_pipeline(&pipeline); + encoder.set_vertex_buffer(0, vertex_buffer.slice(..)); + encoder.draw(0..vertex_count, 0..1); + encoder.finish(&wgpu::RenderBundleDescriptor { + label: Some("main"), + }) + } + + fn create_multisampled_framebuffer( + device: &wgpu::Device, + sc_desc: &wgpu::SwapChainDescriptor, + sample_count: u32, + ) -> wgpu::TextureView { + let multisampled_texture_extent = wgpu::Extent3d { + width: sc_desc.width, + height: sc_desc.height, + depth_or_array_layers: 1, + }; + let multisampled_frame_descriptor = &wgpu::TextureDescriptor { + size: multisampled_texture_extent, + mip_level_count: 1, + sample_count, + dimension: wgpu::TextureDimension::D2, + format: sc_desc.format, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + label: None, + }; + + device + .create_texture(multisampled_frame_descriptor) + .create_view(&wgpu::TextureViewDescriptor::default()) + } +} + +impl framework::Example for Example { + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + _queue: &wgpu::Queue, + ) -> Self { + log::info!("Press left/right arrow keys to change sample_count."); + let sample_count = 4; + + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgpu::Backend::Metal | wgpu::Backend::Vulkan => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION + } + _ => (), //TODO + } + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + flags, + }); + + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[], + push_constant_ranges: &[], + }); + + let multisampled_framebuffer = + Example::create_multisampled_framebuffer(device, sc_desc, sample_count); + + let mut vertex_data = vec![]; + + let max = 50; + for i in 0..max { + let percent = i as f32 / max as f32; + let (sin, cos) = (percent * 2.0 * std::f32::consts::PI).sin_cos(); + vertex_data.push(Vertex { + _pos: [0.0, 0.0], + _color: [1.0, -sin, cos, 1.0], + }); + vertex_data.push(Vertex { + _pos: [1.0 * cos, 1.0 * sin], + _color: [sin, -cos, 1.0, 1.0], + }); + } + + let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Vertex Buffer"), + contents: bytemuck::cast_slice(&vertex_data), + usage: wgpu::BufferUsage::VERTEX, + }); + let vertex_count = vertex_data.len() as u32; + + let bundle = Example::create_bundle( + device, + &sc_desc, + &shader, + &pipeline_layout, + sample_count, + &vertex_buffer, + vertex_count, + ); + + Example { + bundle, + shader, + pipeline_layout, + multisampled_framebuffer, + vertex_buffer, + vertex_count, + sample_count, + rebuild_bundle: false, + sc_desc: sc_desc.clone(), + } + } + + #[allow(clippy::single_match)] + fn update(&mut self, event: winit::event::WindowEvent) { + match event { + winit::event::WindowEvent::KeyboardInput { input, .. } => { + if let winit::event::ElementState::Pressed = input.state { + match input.virtual_keycode { + // TODO: Switch back to full scans of possible options when we expose + // supported sample counts to the user. + Some(winit::event::VirtualKeyCode::Left) => { + if self.sample_count == 4 { + self.sample_count = 1; + self.rebuild_bundle = true; + } + } + Some(winit::event::VirtualKeyCode::Right) => { + if self.sample_count == 1 { + self.sample_count = 4; + self.rebuild_bundle = true; + } + } + _ => {} + } + } + } + _ => {} + } + } + + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + _queue: &wgpu::Queue, + ) { + self.sc_desc = sc_desc.clone(); + self.multisampled_framebuffer = + Example::create_multisampled_framebuffer(device, sc_desc, self.sample_count); + } + + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + if self.rebuild_bundle { + self.bundle = Example::create_bundle( + device, + &self.sc_desc, + &self.shader, + &self.pipeline_layout, + self.sample_count, + &self.vertex_buffer, + self.vertex_count, + ); + self.multisampled_framebuffer = + Example::create_multisampled_framebuffer(device, &self.sc_desc, self.sample_count); + self.rebuild_bundle = false; + } + + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + { + let ops = wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: true, + }; + let rpass_color_attachment = if self.sample_count == 1 { + wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops, + } + } else { + wgpu::RenderPassColorAttachment { + view: &self.multisampled_framebuffer, + resolve_target: Some(&frame.view), + ops, + } + }; + + encoder + .begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[rpass_color_attachment], + depth_stencil_attachment: None, + }) + .execute_bundles(iter::once(&self.bundle)); + } + + queue.submit(iter::once(encoder.finish())); + } +} + +fn main() { + framework::run::("msaa-line"); +} diff --git a/wgpu/examples/msaa-line/screenshot.png b/wgpu/examples/msaa-line/screenshot.png new file mode 100644 index 000000000..9e4208124 Binary files /dev/null and b/wgpu/examples/msaa-line/screenshot.png differ diff --git a/wgpu/examples/msaa-line/shader.wgsl b/wgpu/examples/msaa-line/shader.wgsl new file mode 100644 index 000000000..8dbce73b3 --- /dev/null +++ b/wgpu/examples/msaa-line/shader.wgsl @@ -0,0 +1,20 @@ +struct VertexOutput { + [[location(0)]] color: vec4; + [[builtin(position)]] position: vec4; +}; + +[[stage(vertex)]] +fn vs_main( + [[location(0)]] position: vec2, + [[location(1)]] color: vec4, +) -> VertexOutput { + var out: VertexOutput; + out.position = vec4(position, 0.0, 1.0); + out.color = color; + return out; +} + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + return in.color; +} diff --git a/wgpu/examples/shadow/README.md b/wgpu/examples/shadow/README.md new file mode 100644 index 000000000..62bc83eed --- /dev/null +++ b/wgpu/examples/shadow/README.md @@ -0,0 +1,13 @@ +# shadow + +This animated example demonstrates shadow mapping. + +## To Run + +``` +cargo run --example shadow +``` + +## Screenshots + +![Shadow mapping](./screenshot.png) diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs new file mode 100644 index 000000000..7b48b846b --- /dev/null +++ b/wgpu/examples/shadow/main.rs @@ -0,0 +1,831 @@ +use std::{borrow::Cow, iter, mem, num::NonZeroU32, ops::Range, rc::Rc}; + +#[path = "../framework.rs"] +mod framework; + +use bytemuck::{Pod, Zeroable}; +use wgpu::util::DeviceExt; + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct Vertex { + _pos: [i8; 4], + _normal: [i8; 4], +} + +fn vertex(pos: [i8; 3], nor: [i8; 3]) -> Vertex { + Vertex { + _pos: [pos[0], pos[1], pos[2], 1], + _normal: [nor[0], nor[1], nor[2], 0], + } +} + +fn create_cube() -> (Vec, Vec) { + let vertex_data = [ + // top (0, 0, 1) + vertex([-1, -1, 1], [0, 0, 1]), + vertex([1, -1, 1], [0, 0, 1]), + vertex([1, 1, 1], [0, 0, 1]), + vertex([-1, 1, 1], [0, 0, 1]), + // bottom (0, 0, -1) + vertex([-1, 1, -1], [0, 0, -1]), + vertex([1, 1, -1], [0, 0, -1]), + vertex([1, -1, -1], [0, 0, -1]), + vertex([-1, -1, -1], [0, 0, -1]), + // right (1, 0, 0) + vertex([1, -1, -1], [1, 0, 0]), + vertex([1, 1, -1], [1, 0, 0]), + vertex([1, 1, 1], [1, 0, 0]), + vertex([1, -1, 1], [1, 0, 0]), + // left (-1, 0, 0) + vertex([-1, -1, 1], [-1, 0, 0]), + vertex([-1, 1, 1], [-1, 0, 0]), + vertex([-1, 1, -1], [-1, 0, 0]), + vertex([-1, -1, -1], [-1, 0, 0]), + // front (0, 1, 0) + vertex([1, 1, -1], [0, 1, 0]), + vertex([-1, 1, -1], [0, 1, 0]), + vertex([-1, 1, 1], [0, 1, 0]), + vertex([1, 1, 1], [0, 1, 0]), + // back (0, -1, 0) + vertex([1, -1, 1], [0, -1, 0]), + vertex([-1, -1, 1], [0, -1, 0]), + vertex([-1, -1, -1], [0, -1, 0]), + vertex([1, -1, -1], [0, -1, 0]), + ]; + + let index_data: &[u16] = &[ + 0, 1, 2, 2, 3, 0, // top + 4, 5, 6, 6, 7, 4, // bottom + 8, 9, 10, 10, 11, 8, // right + 12, 13, 14, 14, 15, 12, // left + 16, 17, 18, 18, 19, 16, // front + 20, 21, 22, 22, 23, 20, // back + ]; + + (vertex_data.to_vec(), index_data.to_vec()) +} + +fn create_plane(size: i8) -> (Vec, Vec) { + let vertex_data = [ + vertex([size, -size, 0], [0, 0, 1]), + vertex([size, size, 0], [0, 0, 1]), + vertex([-size, -size, 0], [0, 0, 1]), + vertex([-size, size, 0], [0, 0, 1]), + ]; + + let index_data: &[u16] = &[0, 1, 2, 2, 1, 3]; + + (vertex_data.to_vec(), index_data.to_vec()) +} + +struct Entity { + mx_world: cgmath::Matrix4, + rotation_speed: f32, + color: wgpu::Color, + vertex_buf: Rc, + index_buf: Rc, + index_format: wgpu::IndexFormat, + index_count: usize, + uniform_offset: wgpu::DynamicOffset, +} + +struct Light { + pos: cgmath::Point3, + color: wgpu::Color, + fov: f32, + depth: Range, + target_view: wgpu::TextureView, +} + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct LightRaw { + proj: [[f32; 4]; 4], + pos: [f32; 4], + color: [f32; 4], +} + +impl Light { + fn to_raw(&self) -> LightRaw { + use cgmath::{Deg, EuclideanSpace, Matrix4, PerspectiveFov, Point3, Vector3}; + + let mx_view = Matrix4::look_at_rh(self.pos, Point3::origin(), Vector3::unit_z()); + let projection = PerspectiveFov { + fovy: Deg(self.fov).into(), + aspect: 1.0, + near: self.depth.start, + far: self.depth.end, + }; + let mx_correction = framework::OPENGL_TO_WGPU_MATRIX; + let mx_view_proj = + mx_correction * cgmath::Matrix4::from(projection.to_perspective()) * mx_view; + LightRaw { + proj: *mx_view_proj.as_ref(), + pos: [self.pos.x, self.pos.y, self.pos.z, 1.0], + color: [ + self.color.r as f32, + self.color.g as f32, + self.color.b as f32, + 1.0, + ], + } + } +} + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct GlobalUniforms { + proj: [[f32; 4]; 4], + num_lights: [u32; 4], +} + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct EntityUniforms { + model: [[f32; 4]; 4], + color: [f32; 4], +} + +struct Pass { + pipeline: wgpu::RenderPipeline, + bind_group: wgpu::BindGroup, + uniform_buf: wgpu::Buffer, +} + +struct Example { + entities: Vec, + lights: Vec, + lights_are_dirty: bool, + shadow_pass: Pass, + forward_pass: Pass, + forward_depth: wgpu::TextureView, + entity_bind_group: wgpu::BindGroup, + light_storage_buf: wgpu::Buffer, + entity_uniform_buf: wgpu::Buffer, +} + +impl Example { + const MAX_LIGHTS: usize = 10; + const SHADOW_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float; + const SHADOW_SIZE: wgpu::Extent3d = wgpu::Extent3d { + width: 512, + height: 512, + depth_or_array_layers: Self::MAX_LIGHTS as u32, + }; + const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float; + + fn generate_matrix(aspect_ratio: f32) -> cgmath::Matrix4 { + let mx_projection = cgmath::perspective(cgmath::Deg(45f32), aspect_ratio, 1.0, 20.0); + let mx_view = cgmath::Matrix4::look_at_rh( + cgmath::Point3::new(3.0f32, -10.0, 6.0), + cgmath::Point3::new(0f32, 0.0, 0.0), + cgmath::Vector3::unit_z(), + ); + let mx_correction = framework::OPENGL_TO_WGPU_MATRIX; + mx_correction * mx_projection * mx_view + } + + fn create_depth_texture( + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + ) -> wgpu::TextureView { + let depth_texture = device.create_texture(&wgpu::TextureDescriptor { + size: wgpu::Extent3d { + width: sc_desc.width, + height: sc_desc.height, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: Self::DEPTH_FORMAT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + label: None, + }); + + depth_texture.create_view(&wgpu::TextureViewDescriptor::default()) + } +} + +impl framework::Example for Example { + fn optional_features() -> wgpu::Features { + wgpu::Features::DEPTH_CLAMPING + } + + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + _queue: &wgpu::Queue, + ) -> Self { + // Create the vertex and index buffers + let vertex_size = mem::size_of::(); + let (cube_vertex_data, cube_index_data) = create_cube(); + let cube_vertex_buf = Rc::new(device.create_buffer_init( + &wgpu::util::BufferInitDescriptor { + label: Some("Cubes Vertex Buffer"), + contents: bytemuck::cast_slice(&cube_vertex_data), + usage: wgpu::BufferUsage::VERTEX, + }, + )); + + let cube_index_buf = Rc::new(device.create_buffer_init( + &wgpu::util::BufferInitDescriptor { + label: Some("Cubes Index Buffer"), + contents: bytemuck::cast_slice(&cube_index_data), + usage: wgpu::BufferUsage::INDEX, + }, + )); + + let (plane_vertex_data, plane_index_data) = create_plane(7); + let plane_vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Plane Vertex Buffer"), + contents: bytemuck::cast_slice(&plane_vertex_data), + usage: wgpu::BufferUsage::VERTEX, + }); + + let plane_index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Plane Index Buffer"), + contents: bytemuck::cast_slice(&plane_index_data), + usage: wgpu::BufferUsage::INDEX, + }); + + struct CubeDesc { + offset: cgmath::Vector3, + angle: f32, + scale: f32, + rotation: f32, + } + let cube_descs = [ + CubeDesc { + offset: cgmath::vec3(-2.0, -2.0, 2.0), + angle: 10.0, + scale: 0.7, + rotation: 0.1, + }, + CubeDesc { + offset: cgmath::vec3(2.0, -2.0, 2.0), + angle: 50.0, + scale: 1.3, + rotation: 0.2, + }, + CubeDesc { + offset: cgmath::vec3(-2.0, 2.0, 2.0), + angle: 140.0, + scale: 1.1, + rotation: 0.3, + }, + CubeDesc { + offset: cgmath::vec3(2.0, 2.0, 2.0), + angle: 210.0, + scale: 0.9, + rotation: 0.4, + }, + ]; + + let entity_uniform_size = mem::size_of::() as wgpu::BufferAddress; + let num_entities = 1 + cube_descs.len() as wgpu::BufferAddress; + assert!(entity_uniform_size <= wgpu::BIND_BUFFER_ALIGNMENT); + //Note: dynamic offsets also have to be aligned to `BIND_BUFFER_ALIGNMENT`. + let entity_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { + label: None, + size: num_entities * wgpu::BIND_BUFFER_ALIGNMENT, + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + let index_format = wgpu::IndexFormat::Uint16; + + let mut entities = vec![{ + use cgmath::SquareMatrix; + Entity { + mx_world: cgmath::Matrix4::identity(), + rotation_speed: 0.0, + color: wgpu::Color::WHITE, + vertex_buf: Rc::new(plane_vertex_buf), + index_buf: Rc::new(plane_index_buf), + index_format, + index_count: plane_index_data.len(), + uniform_offset: 0, + } + }]; + + for (i, cube) in cube_descs.iter().enumerate() { + use cgmath::{Decomposed, Deg, InnerSpace, Quaternion, Rotation3}; + + let transform = Decomposed { + disp: cube.offset, + rot: Quaternion::from_axis_angle(cube.offset.normalize(), Deg(cube.angle)), + scale: cube.scale, + }; + entities.push(Entity { + mx_world: cgmath::Matrix4::from(transform), + rotation_speed: cube.rotation, + color: wgpu::Color::GREEN, + vertex_buf: Rc::clone(&cube_vertex_buf), + index_buf: Rc::clone(&cube_index_buf), + index_format, + index_count: cube_index_data.len(), + uniform_offset: ((i + 1) * wgpu::BIND_BUFFER_ALIGNMENT as usize) as _, + }); + } + + let local_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: wgpu::BufferSize::new(entity_uniform_size), + }, + count: None, + }], + label: None, + }); + let entity_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &local_bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding { + buffer: &entity_uniform_buf, + offset: 0, + size: wgpu::BufferSize::new(entity_uniform_size), + }), + }], + label: None, + }); + + // Create other resources + let shadow_sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: Some("shadow"), + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Linear, + mipmap_filter: wgpu::FilterMode::Nearest, + compare: Some(wgpu::CompareFunction::LessEqual), + ..Default::default() + }); + + let shadow_texture = device.create_texture(&wgpu::TextureDescriptor { + size: Self::SHADOW_SIZE, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: Self::SHADOW_FORMAT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + label: None, + }); + let shadow_view = shadow_texture.create_view(&wgpu::TextureViewDescriptor::default()); + + let mut shadow_target_views = (0..2) + .map(|i| { + Some(shadow_texture.create_view(&wgpu::TextureViewDescriptor { + label: Some("shadow"), + format: None, + dimension: Some(wgpu::TextureViewDimension::D2), + aspect: wgpu::TextureAspect::All, + base_mip_level: 0, + mip_level_count: None, + base_array_layer: i as u32, + array_layer_count: NonZeroU32::new(1), + })) + }) + .collect::>(); + let lights = vec![ + Light { + pos: cgmath::Point3::new(7.0, -5.0, 10.0), + color: wgpu::Color { + r: 0.5, + g: 1.0, + b: 0.5, + a: 1.0, + }, + fov: 60.0, + depth: 1.0..20.0, + target_view: shadow_target_views[0].take().unwrap(), + }, + Light { + pos: cgmath::Point3::new(-5.0, 7.0, 10.0), + color: wgpu::Color { + r: 1.0, + g: 0.5, + b: 0.5, + a: 1.0, + }, + fov: 45.0, + depth: 1.0..20.0, + target_view: shadow_target_views[1].take().unwrap(), + }, + ]; + let light_uniform_size = + (Self::MAX_LIGHTS * mem::size_of::()) as wgpu::BufferAddress; + let light_storage_buf = device.create_buffer(&wgpu::BufferDescriptor { + label: None, + size: light_uniform_size, + usage: wgpu::BufferUsage::STORAGE + | wgpu::BufferUsage::COPY_SRC + | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + let vertex_attr = wgpu::vertex_attr_array![0 => Sint8x4, 1 => Sint8x4]; + let vb_desc = wgpu::VertexBufferLayout { + array_stride: vertex_size as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &vertex_attr, + }; + + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgpu::Backend::Metal | wgpu::Backend::Vulkan => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION; + } + _ => (), //TODO + } + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + flags, + }); + + let shadow_pass = { + let uniform_size = mem::size_of::() as wgpu::BufferAddress; + // Create pipeline layout + let bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: None, + entries: &[wgpu::BindGroupLayoutEntry { + binding: 0, // global + visibility: wgpu::ShaderStage::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new(uniform_size), + }, + count: None, + }], + }); + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("shadow"), + bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout], + push_constant_ranges: &[], + }); + + let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { + label: None, + size: uniform_size, + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + // Create bind group + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: uniform_buf.as_entire_binding(), + }], + label: None, + }); + + // Create the render pipeline + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("shadow"), + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_bake", + buffers: &[vb_desc.clone()], + }, + fragment: None, + primitive: wgpu::PrimitiveState { + topology: wgpu::PrimitiveTopology::TriangleList, + front_face: wgpu::FrontFace::Ccw, + cull_mode: Some(wgpu::Face::Back), + clamp_depth: device.features().contains(wgpu::Features::DEPTH_CLAMPING), + ..Default::default() + }, + depth_stencil: Some(wgpu::DepthStencilState { + format: Self::SHADOW_FORMAT, + depth_write_enabled: true, + depth_compare: wgpu::CompareFunction::LessEqual, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState { + constant: 2, // corresponds to bilinear filtering + slope_scale: 2.0, + clamp: 0.0, + }, + }), + multisample: wgpu::MultisampleState::default(), + }); + + Pass { + pipeline, + bind_group, + uniform_buf, + } + }; + + let forward_pass = { + // Create pipeline layout + let bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, // global + visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new( + mem::size_of::() as _, + ), + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, // lights + visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Storage { read_only: true }, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new(light_uniform_size), + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + multisampled: false, + sample_type: wgpu::TextureSampleType::Depth, + view_dimension: wgpu::TextureViewDimension::D2Array, + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 3, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Sampler { + comparison: true, + filtering: true, + }, + count: None, + }, + ], + label: None, + }); + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("main"), + bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout], + push_constant_ranges: &[], + }); + + let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32); + let forward_uniforms = GlobalUniforms { + proj: *mx_total.as_ref(), + num_lights: [lights.len() as u32, 0, 0, 0], + }; + let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Uniform Buffer"), + contents: bytemuck::bytes_of(&forward_uniforms), + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + }); + + // Create bind group + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: uniform_buf.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: light_storage_buf.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView(&shadow_view), + }, + wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::Sampler(&shadow_sampler), + }, + ], + label: None, + }); + + // Create the render pipeline + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("main"), + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + buffers: &[vb_desc], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + front_face: wgpu::FrontFace::Ccw, + cull_mode: Some(wgpu::Face::Back), + ..Default::default() + }, + depth_stencil: Some(wgpu::DepthStencilState { + format: Self::DEPTH_FORMAT, + depth_write_enabled: true, + depth_compare: wgpu::CompareFunction::Less, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState::default(), + }), + multisample: wgpu::MultisampleState::default(), + }); + + Pass { + pipeline, + bind_group, + uniform_buf, + } + }; + + let forward_depth = Self::create_depth_texture(sc_desc, device); + + Example { + entities, + lights, + lights_are_dirty: true, + shadow_pass, + forward_pass, + forward_depth, + light_storage_buf, + entity_uniform_buf, + entity_bind_group, + } + } + + fn update(&mut self, _event: winit::event::WindowEvent) { + //empty + } + + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) { + // update view-projection matrix + let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32); + let mx_ref: &[f32; 16] = mx_total.as_ref(); + queue.write_buffer( + &self.forward_pass.uniform_buf, + 0, + bytemuck::cast_slice(mx_ref), + ); + + self.forward_depth = Self::create_depth_texture(sc_desc, device); + } + + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + // update uniforms + for entity in self.entities.iter_mut() { + if entity.rotation_speed != 0.0 { + let rotation = cgmath::Matrix4::from_angle_x(cgmath::Deg(entity.rotation_speed)); + entity.mx_world = entity.mx_world * rotation; + } + let data = EntityUniforms { + model: entity.mx_world.into(), + color: [ + entity.color.r as f32, + entity.color.g as f32, + entity.color.b as f32, + entity.color.a as f32, + ], + }; + queue.write_buffer( + &self.entity_uniform_buf, + entity.uniform_offset as wgpu::BufferAddress, + bytemuck::bytes_of(&data), + ); + } + + if self.lights_are_dirty { + self.lights_are_dirty = false; + for (i, light) in self.lights.iter().enumerate() { + queue.write_buffer( + &self.light_storage_buf, + (i * mem::size_of::()) as wgpu::BufferAddress, + bytemuck::bytes_of(&light.to_raw()), + ); + } + } + + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + + encoder.push_debug_group("shadow passes"); + for (i, light) in self.lights.iter().enumerate() { + encoder.push_debug_group(&format!( + "shadow pass {} (light at position {:?})", + i, light.pos + )); + + // The light uniform buffer already has the projection, + // let's just copy it over to the shadow uniform buffer. + encoder.copy_buffer_to_buffer( + &self.light_storage_buf, + (i * mem::size_of::()) as wgpu::BufferAddress, + &self.shadow_pass.uniform_buf, + 0, + 64, + ); + + encoder.insert_debug_marker("render entities"); + { + let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &light.target_view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: true, + }), + stencil_ops: None, + }), + }); + pass.set_pipeline(&self.shadow_pass.pipeline); + pass.set_bind_group(0, &self.shadow_pass.bind_group, &[]); + + for entity in &self.entities { + pass.set_bind_group(1, &self.entity_bind_group, &[entity.uniform_offset]); + pass.set_index_buffer(entity.index_buf.slice(..), entity.index_format); + pass.set_vertex_buffer(0, entity.vertex_buf.slice(..)); + pass.draw_indexed(0..entity.index_count as u32, 0, 0..1); + } + } + + encoder.pop_debug_group(); + } + encoder.pop_debug_group(); + + // forward pass + encoder.push_debug_group("forward rendering pass"); + { + let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }), + store: true, + }, + }], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.forward_depth, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: false, + }), + stencil_ops: None, + }), + }); + pass.set_pipeline(&self.forward_pass.pipeline); + pass.set_bind_group(0, &self.forward_pass.bind_group, &[]); + + for entity in &self.entities { + pass.set_bind_group(1, &self.entity_bind_group, &[entity.uniform_offset]); + pass.set_index_buffer(entity.index_buf.slice(..), entity.index_format); + pass.set_vertex_buffer(0, entity.vertex_buf.slice(..)); + pass.draw_indexed(0..entity.index_count as u32, 0, 0..1); + } + } + encoder.pop_debug_group(); + + queue.submit(iter::once(encoder.finish())); + } +} + +fn main() { + framework::run::("shadow"); +} diff --git a/wgpu/examples/shadow/screenshot.png b/wgpu/examples/shadow/screenshot.png new file mode 100644 index 000000000..ae0782378 Binary files /dev/null and b/wgpu/examples/shadow/screenshot.png differ diff --git a/wgpu/examples/shadow/shader.wgsl b/wgpu/examples/shadow/shader.wgsl new file mode 100644 index 000000000..f7826712e --- /dev/null +++ b/wgpu/examples/shadow/shader.wgsl @@ -0,0 +1,104 @@ +[[block]] +struct Globals { + view_proj: mat4x4; + num_lights: vec4; +}; + +[[group(0), binding(0)]] +var u_globals: Globals; + +[[block]] +struct Entity { + world: mat4x4; + color: vec4; +}; + +[[group(1), binding(0)]] +var u_entity: Entity; + +[[stage(vertex)]] +fn vs_bake([[location(0)]] position: vec4) -> [[builtin(position)]] vec4 { + return u_globals.view_proj * u_entity.world * vec4(position); +} + +struct VertexOutput { + [[builtin(position)]] proj_position: vec4; + [[location(0)]] world_normal: vec3; + [[location(1)]] world_position: vec4; +}; + +[[stage(vertex)]] +fn vs_main( + [[location(0)]] position: vec4, + [[location(1)]] normal: vec4, +) -> VertexOutput { + let w = u_entity.world; + let world_pos = u_entity.world * vec4(position); + var out: VertexOutput; + out.world_normal = mat3x3(w.x.xyz, w.y.xyz, w.z.xyz) * vec3(normal.xyz); + out.world_position = world_pos; + out.proj_position = u_globals.view_proj * world_pos; + return out; +} + +// fragment shader + +struct Light { + proj: mat4x4; + pos: vec4; + color: vec4; +}; + +[[block]] +struct Lights { + data: [[stride(96)]] array; +}; + +[[group(0), binding(1)]] +var s_lights: [[access(read)]] Lights; +[[group(0), binding(2)]] +var t_shadow: texture_depth_2d_array; +[[group(0), binding(3)]] +var sampler_shadow: sampler_comparison; + +fn fetch_shadow(light_id: u32, homogeneous_coords: vec4) -> f32 { + if (homogeneous_coords.w <= 0.0) { + return 1.0; + } + // compensate for the Y-flip difference between the NDC and texture coordinates + let flip_correction = vec2(0.5, -0.5); + // compute texture coordinates for shadow lookup + let proj_correction = 1.0 / homogeneous_coords.w; + let light_local = homogeneous_coords.xy * flip_correction * proj_correction + vec2(0.5, 0.5); + // do the lookup, using HW PCF and comparison + return textureSampleCompare(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z * proj_correction); +} + +let c_ambient: vec3 = vec3(0.05, 0.05, 0.05); +let c_max_lights: u32 = 10u; + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + let normal = normalize(in.world_normal); + // accumulate color + var color: vec3 = c_ambient; + var i: u32 = 0u; + loop { + if (i >= min(u_globals.num_lights.x, c_max_lights)) { + break; + } + let light = s_lights.data[i]; + // project into the light space + let shadow = fetch_shadow(i, light.proj * in.world_position); + // compute Lambertian diffuse term + let light_dir = normalize(light.pos.xyz - in.world_position.xyz); + let diffuse = max(0.0, dot(normal, light_dir)); + // add light contribution + color = color + shadow * diffuse * light.color.xyz; + continuing { + i = i + 1u; + } + } + // multiply the light by material color + return vec4(color, 1.0) * u_entity.color; +} diff --git a/wgpu/examples/skybox/README.md b/wgpu/examples/skybox/README.md new file mode 100644 index 000000000..51dce9d36 --- /dev/null +++ b/wgpu/examples/skybox/README.md @@ -0,0 +1,14 @@ +# skybox + +This animated example demonstrates loading a Wavefront OBJ model, and rendering it with skybox and simple reflections. +It hooks up `winit` mouse controls for camera rotation around the model at the center. + +## To Run + +``` +cargo run --example skybox +``` + +## Screenshots + +![Skybox](./screenshot.png) diff --git a/wgpu/examples/skybox/images/astc.dds b/wgpu/examples/skybox/images/astc.dds new file mode 100644 index 000000000..b1bee88fa Binary files /dev/null and b/wgpu/examples/skybox/images/astc.dds differ diff --git a/wgpu/examples/skybox/images/bc1.dds b/wgpu/examples/skybox/images/bc1.dds new file mode 100644 index 000000000..4a9ec2837 Binary files /dev/null and b/wgpu/examples/skybox/images/bc1.dds differ diff --git a/wgpu/examples/skybox/images/bgra.dds b/wgpu/examples/skybox/images/bgra.dds new file mode 100644 index 000000000..de3135c85 Binary files /dev/null and b/wgpu/examples/skybox/images/bgra.dds differ diff --git a/wgpu/examples/skybox/images/etc2.dds b/wgpu/examples/skybox/images/etc2.dds new file mode 100644 index 000000000..77a3fa0da Binary files /dev/null and b/wgpu/examples/skybox/images/etc2.dds differ diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs new file mode 100644 index 000000000..4ebec3ee1 --- /dev/null +++ b/wgpu/examples/skybox/main.rs @@ -0,0 +1,469 @@ +#[path = "../framework.rs"] +mod framework; + +use bytemuck::{Pod, Zeroable}; +use cgmath::SquareMatrix; +use std::borrow::Cow; +use wgpu::util::DeviceExt; + +const IMAGE_SIZE: u32 = 128; + +#[derive(Clone, Copy, Pod, Zeroable)] +#[repr(C)] +struct Vertex { + pos: [f32; 3], + normal: [f32; 3], +} + +struct Entity { + vertex_count: u32, + vertex_buf: wgpu::Buffer, +} + +// Note: we use the Y=up coordinate space in this example. +struct Camera { + screen_size: (u32, u32), + angle_y: f32, + angle_xz: f32, + dist: f32, +} + +const MODEL_CENTER_Y: f32 = 2.0; + +impl Camera { + fn to_uniform_data(&self) -> [f32; 16 * 3 + 4] { + let aspect = self.screen_size.0 as f32 / self.screen_size.1 as f32; + let mx_projection = cgmath::perspective(cgmath::Deg(45f32), aspect, 1.0, 50.0); + let cam_pos = cgmath::Point3::new( + self.angle_xz.cos() * self.angle_y.sin() * self.dist, + self.angle_xz.sin() * self.dist + MODEL_CENTER_Y, + self.angle_xz.cos() * self.angle_y.cos() * self.dist, + ); + let mx_view = cgmath::Matrix4::look_at_rh( + cam_pos, + cgmath::Point3::new(0f32, MODEL_CENTER_Y, 0.0), + cgmath::Vector3::unit_y(), + ); + let proj = framework::OPENGL_TO_WGPU_MATRIX * mx_projection; + let proj_inv = proj.invert().unwrap(); + let view = framework::OPENGL_TO_WGPU_MATRIX * mx_view; + + let mut raw = [0f32; 16 * 3 + 4]; + raw[..16].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&proj)[..]); + raw[16..32].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&proj_inv)[..]); + raw[32..48].copy_from_slice(&AsRef::<[f32; 16]>::as_ref(&view)[..]); + raw[48..51].copy_from_slice(AsRef::<[f32; 3]>::as_ref(&cam_pos)); + raw[51] = 1.0; + raw + } +} + +pub struct Skybox { + camera: Camera, + sky_pipeline: wgpu::RenderPipeline, + entity_pipeline: wgpu::RenderPipeline, + bind_group: wgpu::BindGroup, + uniform_buf: wgpu::Buffer, + entities: Vec, + depth_view: wgpu::TextureView, + staging_belt: wgpu::util::StagingBelt, +} + +impl Skybox { + const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth24Plus; + + fn create_depth_texture( + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + ) -> wgpu::TextureView { + let depth_texture = device.create_texture(&wgpu::TextureDescriptor { + size: wgpu::Extent3d { + width: sc_desc.width, + height: sc_desc.height, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: Self::DEPTH_FORMAT, + usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + label: None, + }); + + depth_texture.create_view(&wgpu::TextureViewDescriptor::default()) + } +} + +impl framework::Example for Skybox { + fn optional_features() -> wgpu::Features { + wgpu::Features::TEXTURE_COMPRESSION_ASTC_LDR + | wgpu::Features::TEXTURE_COMPRESSION_ETC2 + | wgpu::Features::TEXTURE_COMPRESSION_BC + } + + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) -> Self { + let mut entities = Vec::new(); + { + let source = include_bytes!("models/teslacyberv3.0.obj"); + let data = obj::ObjData::load_buf(&source[..]).unwrap(); + let mut vertices = Vec::new(); + for object in data.objects { + for group in object.groups { + vertices.clear(); + for poly in group.polys { + for end_index in 2..poly.0.len() { + for &index in &[0, end_index - 1, end_index] { + let obj::IndexTuple(position_id, _texture_id, normal_id) = + poly.0[index]; + vertices.push(Vertex { + pos: data.position[position_id], + normal: data.normal[normal_id.unwrap()], + }) + } + } + } + let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Vertex"), + contents: bytemuck::cast_slice(&vertices), + usage: wgpu::BufferUsage::VERTEX, + }); + entities.push(Entity { + vertex_count: vertices.len() as u32, + vertex_buf, + }); + } + } + } + + let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: None, + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: None, + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { filterable: true }, + multisampled: false, + view_dimension: wgpu::TextureViewDimension::Cube, + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Sampler { + comparison: false, + filtering: true, + }, + count: None, + }, + ], + }); + + // Create the render pipeline + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgpu::Backend::Metal | wgpu::Backend::Vulkan => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION + } + _ => (), //TODO + } + let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: None, + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), + flags, + }); + + let camera = Camera { + screen_size: (sc_desc.width, sc_desc.height), + angle_xz: 0.2, + angle_y: 0.2, + dist: 30.0, + }; + let raw_uniforms = camera.to_uniform_data(); + let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Buffer"), + contents: bytemuck::cast_slice(&raw_uniforms), + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + }); + + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: None, + bind_group_layouts: &[&bind_group_layout], + push_constant_ranges: &[], + }); + + // Create the render pipelines + let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Sky"), + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_sky", + buffers: &[], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_sky", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + front_face: wgpu::FrontFace::Cw, + ..Default::default() + }, + depth_stencil: Some(wgpu::DepthStencilState { + format: Self::DEPTH_FORMAT, + depth_write_enabled: false, + depth_compare: wgpu::CompareFunction::LessEqual, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState::default(), + }), + multisample: wgpu::MultisampleState::default(), + }); + let entity_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("Entity"), + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_entity", + buffers: &[wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3], + }], + }, + fragment: Some(wgpu::FragmentState { + module: &shader, + entry_point: "fs_entity", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + front_face: wgpu::FrontFace::Cw, + ..Default::default() + }, + depth_stencil: Some(wgpu::DepthStencilState { + format: Self::DEPTH_FORMAT, + depth_write_enabled: true, + depth_compare: wgpu::CompareFunction::LessEqual, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState::default(), + }), + multisample: wgpu::MultisampleState::default(), + }); + + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: None, + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Linear, + mipmap_filter: wgpu::FilterMode::Linear, + ..Default::default() + }); + + let device_features = device.features(); + + let skybox_format = + if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC_LDR) { + wgpu::TextureFormat::Astc4x4RgbaUnormSrgb + } else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) { + wgpu::TextureFormat::Etc2RgbUnormSrgb + } else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) { + wgpu::TextureFormat::Bc1RgbaUnormSrgb + } else { + wgpu::TextureFormat::Bgra8UnormSrgb + }; + + let size = wgpu::Extent3d { + width: IMAGE_SIZE, + height: IMAGE_SIZE, + depth_or_array_layers: 6, + }; + + let layer_size = wgpu::Extent3d { + depth_or_array_layers: 1, + ..size + }; + let max_mips = layer_size.max_mips(); + + log::debug!( + "Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu", + skybox_format, + IMAGE_SIZE, + IMAGE_SIZE, + max_mips, + ); + + let bytes = match skybox_format { + wgpu::TextureFormat::Astc4x4RgbaUnormSrgb => &include_bytes!("images/astc.dds")[..], + wgpu::TextureFormat::Etc2RgbUnormSrgb => &include_bytes!("images/etc2.dds")[..], + wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("images/bc1.dds")[..], + wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("images/bgra.dds")[..], + _ => unreachable!(), + }; + + let image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap(); + + let texture = device.create_texture_with_data( + &queue, + &wgpu::TextureDescriptor { + size, + mip_level_count: max_mips as u32, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: skybox_format, + usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + label: None, + }, + &image.data, + ); + + let texture_view = texture.create_view(&wgpu::TextureViewDescriptor { + label: None, + dimension: Some(wgpu::TextureViewDimension::Cube), + ..wgpu::TextureViewDescriptor::default() + }); + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: uniform_buf.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView(&texture_view), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::Sampler(&sampler), + }, + ], + label: None, + }); + + let depth_view = Self::create_depth_texture(sc_desc, device); + + Skybox { + camera, + sky_pipeline, + entity_pipeline, + bind_group, + uniform_buf, + entities, + depth_view, + staging_belt: wgpu::util::StagingBelt::new(0x100), + } + } + + #[allow(clippy::single_match)] + fn update(&mut self, event: winit::event::WindowEvent) { + match event { + winit::event::WindowEvent::CursorMoved { position, .. } => { + let norm_x = position.x as f32 / self.camera.screen_size.0 as f32 - 0.5; + let norm_y = position.y as f32 / self.camera.screen_size.1 as f32 - 0.5; + self.camera.angle_y = norm_x * 5.0; + self.camera.angle_xz = norm_y; + } + _ => {} + } + } + + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + _queue: &wgpu::Queue, + ) { + self.depth_view = Self::create_depth_texture(sc_desc, device); + self.camera.screen_size = (sc_desc.width, sc_desc.height); + } + + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + spawner: &framework::Spawner, + ) { + let mut encoder = + device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + + // update rotation + let raw_uniforms = self.camera.to_uniform_data(); + self.staging_belt + .write_buffer( + &mut encoder, + &self.uniform_buf, + 0, + wgpu::BufferSize::new((raw_uniforms.len() * 4) as wgpu::BufferAddress).unwrap(), + device, + ) + .copy_from_slice(bytemuck::cast_slice(&raw_uniforms)); + + self.staging_belt.finish(); + + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }), + store: true, + }, + }], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: false, + }), + stencil_ops: None, + }), + }); + + rpass.set_bind_group(0, &self.bind_group, &[]); + rpass.set_pipeline(&self.entity_pipeline); + + for entity in self.entities.iter() { + rpass.set_vertex_buffer(0, entity.vertex_buf.slice(..)); + rpass.draw(0..entity.vertex_count, 0..1); + } + + rpass.set_pipeline(&self.sky_pipeline); + rpass.draw(0..3, 0..1); + } + + queue.submit(std::iter::once(encoder.finish())); + + let belt_future = self.staging_belt.recall(); + spawner.spawn_local(belt_future); + } +} + +fn main() { + framework::run::("skybox"); +} diff --git a/wgpu/examples/skybox/models/teslacyberv3.0.mtl b/wgpu/examples/skybox/models/teslacyberv3.0.mtl new file mode 100644 index 000000000..1ac971196 --- /dev/null +++ b/wgpu/examples/skybox/models/teslacyberv3.0.mtl @@ -0,0 +1,62 @@ +# Blender MTL File: 'teslacyberv3.0.blend' +# Material Count: 6 + +newmtl Material +Ns 65.476285 +Ka 1.000000 1.000000 1.000000 +Kd 0.411568 0.411568 0.411568 +Ks 0.614679 0.614679 0.614679 +Ke 0.000000 0.000000 0.000000 +Ni 36.750000 +d 1.000000 +illum 3 + +newmtl Материал +Ns 323.999994 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.000000 +d 1.000000 +illum 2 + +newmtl Материал.001 +Ns 900.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.026240 0.026240 0.026240 +Ks 0.000000 0.000000 0.000000 +Ke 0.000000 0.000000 0.000000 +Ni 1.450000 +d 1.000000 +illum 1 + +newmtl Материал.002 +Ns 0.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.031837 0.032429 0.029425 +Ks 0.169725 0.169725 0.169725 +Ke 0.000000 0.000000 0.000000 +Ni 0.000000 +d 1.000000 +illum 2 + +newmtl Материал.003 +Ns 900.000000 +Ka 1.000000 1.000000 1.000000 +Kd 0.023585 0.083235 0.095923 +Ks 1.000000 1.000000 1.000000 +Ke 0.000000 0.000000 0.000000 +Ni 45.049999 +d 1.000000 +illum 3 + +newmtl Материал.004 +Ns 323.999994 +Ka 1.000000 1.000000 1.000000 +Kd 0.800000 0.800000 0.800000 +Ks 0.500000 0.500000 0.500000 +Ke 0.000000 0.000000 0.000000 +Ni 1.000000 +d 1.000000 +illum 2 diff --git a/wgpu/examples/skybox/models/teslacyberv3.0.obj b/wgpu/examples/skybox/models/teslacyberv3.0.obj new file mode 100644 index 000000000..337fe85ca --- /dev/null +++ b/wgpu/examples/skybox/models/teslacyberv3.0.obj @@ -0,0 +1,6617 @@ +# Blender v2.91.2 OBJ File: 'teslacyberv3.0.blend' +# www.blender.org +mtllib teslacyberv3.0.mtl +o Cube +v 1.000000 1.919617 4.732432 +v 1.000000 0.974478 4.635892 +v 1.000000 3.273532 0.658841 +v 1.000000 0.655211 2.310734 +v 0.877517 2.564093 2.887154 +v 1.000000 0.882397 4.314609 +v 1.000000 3.067818 -1.579714 +v 1.000000 0.667890 -2.227377 +v 1.000000 0.785508 -4.214180 +v 1.000000 2.638943 -4.453823 +v 1.000000 0.874439 4.244418 +v 1.000000 0.655517 2.313426 +v 1.000000 1.111976 2.351255 +v 1.000000 1.866242 2.835600 +v 1.000000 1.833448 3.907717 +v 1.000000 1.258289 4.260885 +v 1.000000 0.668172 -2.232137 +v 1.000000 1.196988 -2.260916 +v 1.000000 1.854486 -2.740417 +v 1.000000 1.879915 -3.782969 +v 1.000000 1.335027 -4.186186 +v 1.750241 2.525397 -5.238923 +v 1.750241 1.086208 -5.076335 +v 1.284501 1.919617 4.732432 +v 1.327607 0.971679 4.653199 +v 1.531155 2.563108 2.886828 +v 1.531797 3.067818 -1.579714 +v 1.358472 3.272686 0.658562 +v 1.466385 2.830804 2.109343 +v 1.750241 0.655211 2.182597 +v 1.750241 0.882397 4.314609 +v 1.750241 0.667890 -2.227377 +v 1.697931 2.638943 -4.453823 +v 1.750241 2.485732 -4.434013 +v 1.750241 2.160423 2.167351 +v 1.750241 2.354560 -1.772200 +v 1.818752 0.655211 2.182857 +v 1.819952 0.655517 2.313426 +v 1.819952 0.874439 4.244418 +v 1.750241 0.882397 4.314609 +v 1.750241 1.128912 2.225720 +v 1.819952 1.111976 2.351255 +v 1.750241 1.985622 2.765436 +v 1.819952 1.866242 2.835600 +v 1.750241 1.936693 3.953938 +v 1.819952 1.833448 3.907717 +v 1.750241 1.341437 4.333489 +v 1.819952 1.258289 4.260885 +v 1.750241 0.883422 2.180506 +v 1.750241 1.591581 -4.318402 +v 1.750224 0.785508 -4.214180 +v 1.750241 0.833292 -4.351184 +v 1.820337 0.668172 -2.232137 +v 1.750241 0.667890 -2.048774 +v 1.820337 1.196988 -2.260916 +v 1.793278 1.210958 -2.101550 +v 1.820337 1.854486 -2.740417 +v 1.750241 1.987285 -2.642222 +v 1.820337 1.879915 -3.782969 +v 1.750241 2.014194 -3.854774 +v 1.820337 1.335027 -4.186186 +v 1.750241 1.350402 -4.282620 +v 1.712797 0.888017 2.180506 +v 1.819131 0.883519 2.180886 +v 1.720162 0.917570 -2.072449 +v 1.717040 0.905044 -0.269841 +v 1.750241 0.900970 -0.269841 +v 1.818854 0.655211 2.182597 +v 1.818854 0.667890 -2.048774 +v 1.818854 0.655211 2.182857 +v 1.818854 0.883422 2.180506 +v 1.818854 0.913878 -2.072449 +v 1.818854 0.900970 -0.269841 +v 1.750241 2.253663 0.275267 +v 1.772394 1.127157 2.177967 +v 1.750241 1.213567 -4.300763 +v 1.750241 1.289006 -5.099246 +v 1.750181 1.335027 -4.186186 +v 1.819927 1.289006 -5.099246 +v 1.819927 1.086208 -5.076335 +v 1.819927 0.833292 -4.351184 +v 1.819927 1.213567 -4.300763 +v 1.750215 1.204111 -4.203537 +v 1.750241 0.833292 -4.351184 +v 1.750241 1.213567 -4.300763 +v 1.819927 0.833292 -4.351184 +v 1.819927 1.213567 -4.300763 +v 1.750241 0.784857 -4.213239 +v 1.750241 1.204197 -4.203453 +v 1.819927 0.784857 -4.213239 +v 1.819927 1.204197 -4.203453 +v 1.750241 1.289002 -5.099215 +v 1.750241 1.266550 -4.861531 +v 1.750241 1.372882 -4.864861 +v 1.750241 1.389482 -5.059558 +v 1.704873 1.213566 -4.300773 +v 1.704873 1.350401 -4.282630 +v 1.704814 1.335025 -4.186196 +v 1.704847 1.204110 -4.203547 +v 1.704873 1.289004 -5.099256 +v 1.704873 1.372881 -4.864871 +v 1.704873 1.266549 -4.861541 +v 1.000000 1.335027 -4.186186 +v 1.750181 1.335027 -4.186186 +v 1.704813 1.335027 -4.186186 +v 0.999869 0.785508 -4.214180 +v 1.704605 1.335027 -4.186186 +v 1.781390 1.163258 0.334393 +v 1.715989 0.900825 0.337296 +v 1.597979 2.686126 2.117274 +v 1.695288 2.350152 2.149278 +v 1.568109 2.947990 -1.569140 +v 1.682906 2.571904 -1.628006 +v 1.470975 3.199804 0.572917 +v 1.497593 3.130800 -0.014067 +v 1.688418 2.473200 0.053302 +v 1.689320 2.457031 0.328725 +v 1.488895 3.153348 0.177737 +v 1.562110 2.963541 -1.436855 +v 1.683560 2.560198 -1.428613 +v 1.570283 2.798146 1.780491 +v 1.694388 2.366281 1.874541 +v 1.586019 2.734497 1.971851 +v 1.695039 2.354623 2.073121 +v 1.703611 2.262414 3.349329 +v 1.671976 2.347888 2.072812 +v 1.672225 2.343417 2.148969 +v 1.547219 2.791411 1.780182 +v 1.447912 3.193069 0.572608 +v 1.660496 2.553463 -1.428922 +v 1.665354 2.466465 0.052993 +v 1.474530 3.124065 -0.014376 +v 1.465832 3.146613 0.177428 +v 1.666257 2.450296 0.328416 +v 1.539047 2.956806 -1.437164 +v 1.671325 2.359546 1.874232 +v 1.574915 2.679392 2.116965 +v 1.562956 2.727762 1.971541 +v 1.680548 2.255679 3.349020 +v 1.555592 2.944302 -1.569304 +v 1.670389 2.568216 -1.628170 +v 1.549594 2.959853 -1.437019 +v 1.476379 3.149660 0.177573 +v 1.485076 3.127112 -0.014231 +v 1.675901 2.469512 0.053138 +v 1.676804 2.453343 0.328561 +v 1.671043 2.556510 -1.428777 +v 1.573503 2.730809 1.971686 +v 1.557766 2.794458 1.780327 +v 1.681871 2.362593 1.874377 +v 1.682522 2.350935 2.072957 +v 1.750241 1.263441 4.331896 +v 1.327607 1.287596 4.716530 +v 1.284501 1.284919 4.656356 +v 1.393376 1.287596 4.679573 +v 1.393376 0.971679 4.616242 +v 1.816010 0.882397 4.314609 +v 1.816010 1.263441 4.331896 +v 1.754250 1.258442 4.260794 +v 1.754033 0.874437 4.244418 +v 1.820019 1.258442 4.260794 +v 1.819803 0.874437 4.244418 +v 1.846744 0.800318 3.491142 +v 1.846744 0.720480 3.445081 +v 1.846744 0.706713 3.353942 +v 1.846744 0.769385 3.286355 +v 1.846744 0.861302 3.293214 +v 1.846744 0.913249 3.369355 +v 1.846744 0.886108 3.457441 +v 1.882362 0.798209 3.519400 +v 1.882362 0.697072 3.461051 +v 1.882362 0.679633 3.345598 +v 1.882362 0.759025 3.259980 +v 1.882362 0.875463 3.268670 +v 1.882362 0.941268 3.365122 +v 1.882362 0.906887 3.476708 +v 1.846744 0.792024 3.602285 +v 1.846744 0.628413 3.507893 +v 1.846744 0.600203 3.321125 +v 1.846744 0.728635 3.182619 +v 1.846744 0.916998 3.196676 +v 1.846744 1.023451 3.352709 +v 1.846744 0.967832 3.533221 +v 1.846744 0.658244 3.340309 +v 1.846744 0.677849 3.463600 +v 1.846744 0.683943 3.472385 +v 1.846744 0.792559 3.533928 +v 1.846744 0.553669 3.971039 +v 1.846744 0.431761 3.901965 +v 1.846744 0.780979 2.736408 +v 1.846744 0.920785 2.745747 +v 1.846744 0.879964 3.242204 +v 1.846744 0.755402 3.233883 +v 1.846744 0.745481 3.237870 +v 1.846744 0.661312 3.330068 +v 1.846744 0.288318 2.999900 +v 1.846744 0.382787 2.896419 +v 1.846744 0.783949 2.806544 +v 1.846744 0.908512 2.814866 +v 1.846744 1.241172 3.003353 +v 1.846744 1.312330 3.105928 +v 1.846744 1.372374 3.483531 +v 1.846744 1.336544 3.603119 +v 1.846744 1.078759 3.885496 +v 1.846744 0.962922 3.932045 +v 1.846744 0.581424 3.906559 +v 1.846744 0.472808 3.845017 +v 1.846744 0.254873 3.530860 +v 1.846744 0.235268 3.407569 +v 1.846744 0.345005 3.041307 +v 1.846744 0.429174 2.949109 +v 1.846744 0.879964 3.242204 +v 1.846744 0.755402 3.233883 +v 1.846744 0.960424 3.350050 +v 1.846744 0.889266 3.247475 +v 1.846744 0.926273 3.480196 +v 1.846744 0.962103 3.360608 +v 1.846744 0.803227 3.534641 +v 1.846744 0.919064 3.488092 +v 1.846744 0.683943 3.472385 +v 1.846744 0.792559 3.533928 +v 1.846744 0.658244 3.340309 +v 1.846744 0.677849 3.463600 +v 1.846744 0.745481 3.237870 +v 1.846744 0.661312 3.330068 +v 1.846744 0.165151 3.410984 +v 1.846744 0.187155 3.549363 +v 1.846744 1.401199 3.630465 +v 1.846744 1.441414 3.496242 +v 1.846744 0.962103 3.360608 +v 1.846744 0.926273 3.480196 +v 1.846744 0.919064 3.488092 +v 1.846744 0.803227 3.534641 +v 1.846744 0.981853 3.999644 +v 1.846744 1.111866 3.947399 +v 1.846744 0.889266 3.247475 +v 1.846744 0.960424 3.350050 +v 1.846744 1.374021 3.072428 +v 1.846744 1.294155 2.957301 +v 1.865511 0.904784 3.474123 +v 1.865511 0.803871 3.514674 +v 1.865511 1.359836 3.481223 +v 1.865511 0.942278 3.363063 +v 1.865511 0.267171 3.527500 +v 1.865511 0.694646 3.452786 +v 1.865511 0.677567 3.345380 +v 1.865511 0.248002 3.406949 +v 1.865511 0.699955 3.460439 +v 1.865511 0.480262 3.834674 +v 1.865511 0.586465 3.894849 +v 1.865511 0.794577 3.514053 +v 1.865511 0.911063 3.467244 +v 1.865511 1.324802 3.598153 +v 1.865511 0.906283 2.827418 +v 1.865511 0.784489 2.819282 +v 1.865511 0.762207 3.252665 +v 1.865511 0.870721 3.259914 +v 1.865511 0.753565 3.256138 +v 1.865511 0.437599 2.958678 +v 1.865511 0.680240 3.336458 +v 1.865511 0.355300 3.048827 +v 1.865511 0.959483 3.919768 +v 1.865511 1.072746 3.874254 +v 1.865511 0.878825 3.264505 +v 1.865511 0.940815 3.353865 +v 1.865511 1.301126 3.112011 +v 1.865511 1.231549 3.011716 +v 1.846743 0.808222 2.561027 +v 1.846743 0.967930 2.576757 +v 1.846743 1.121501 2.623343 +v 1.846743 1.263033 2.698993 +v 1.846743 1.387086 2.800801 +v 1.846743 1.488894 2.924854 +v 1.846743 1.564544 3.066386 +v 1.846743 1.611130 3.219956 +v 1.846743 1.626859 3.379664 +v 1.846743 1.611130 3.539372 +v 1.846743 1.564544 3.692943 +v 1.846743 1.488894 3.834475 +v 1.846743 1.387086 3.958528 +v 1.846743 1.263033 4.060336 +v 1.846743 1.121501 4.135986 +v 1.846743 0.967930 4.182571 +v 1.846743 0.808222 4.198301 +v 1.846743 0.648514 4.182571 +v 1.846743 0.494943 4.135986 +v 1.846743 0.353412 4.060336 +v 1.846743 0.229358 3.958528 +v 1.846743 0.127550 3.834475 +v 1.846743 0.051900 3.692943 +v 1.846743 0.005315 3.539372 +v 1.846743 -0.010415 3.379664 +v 1.846743 0.005316 3.219955 +v 1.846743 0.051901 3.066385 +v 1.846743 0.127551 2.924853 +v 1.846743 0.229359 2.800800 +v 1.846743 0.353413 2.698992 +v 1.846743 0.494945 2.623342 +v 1.846743 0.648515 2.576757 +v 1.888794 0.808222 2.638682 +v 1.888794 0.952781 2.652920 +v 1.888794 1.091784 2.695086 +v 1.888794 1.219890 2.763560 +v 1.888794 1.332176 2.855711 +v 1.888794 1.424327 2.967997 +v 1.888794 1.492801 3.096102 +v 1.888794 1.534967 3.235106 +v 1.888794 1.549205 3.379664 +v 1.888794 1.534967 3.524223 +v 1.888794 1.492801 3.663226 +v 1.888794 1.424327 3.791332 +v 1.888794 1.332176 3.903618 +v 1.888794 1.219890 3.995769 +v 1.888794 1.091784 4.064243 +v 1.888794 0.952781 4.106409 +v 1.888794 0.808222 4.120646 +v 1.888794 0.663664 4.106409 +v 1.888794 0.524660 4.064243 +v 1.888794 0.396554 3.995769 +v 1.888794 0.284268 3.903618 +v 1.888794 0.192118 3.791332 +v 1.888794 0.123644 3.663225 +v 1.888794 0.081477 3.524222 +v 1.888794 0.067240 3.379664 +v 1.888794 0.081478 3.235105 +v 1.888794 0.123644 3.096102 +v 1.888794 0.192118 2.967996 +v 1.888794 0.284269 2.855710 +v 1.888794 0.396555 2.763560 +v 1.888794 0.524662 2.695086 +v 1.888794 0.663665 2.652919 +v 1.855595 0.808222 2.738160 +v 1.855595 0.933374 2.750486 +v 1.855595 1.053715 2.786992 +v 1.855595 1.164623 2.846273 +v 1.855595 1.261834 2.926052 +v 1.855595 1.341614 3.023264 +v 1.855595 1.400895 3.134171 +v 1.855595 1.437400 3.254513 +v 1.855595 1.449726 3.379664 +v 1.855595 1.437400 3.504816 +v 1.855595 1.400895 3.625157 +v 1.855595 1.341614 3.736065 +v 1.855595 1.261834 3.833276 +v 1.855595 1.164623 3.913055 +v 1.855595 1.053715 3.972337 +v 1.855595 0.933373 4.008842 +v 1.855595 0.808222 4.021168 +v 1.855595 0.683071 4.008842 +v 1.855595 0.562729 3.972337 +v 1.855595 0.451821 3.913055 +v 1.855595 0.354610 3.833276 +v 1.855595 0.274831 3.736065 +v 1.855595 0.215550 3.625157 +v 1.855595 0.179044 3.504815 +v 1.855595 0.166718 3.379664 +v 1.855595 0.179045 3.254513 +v 1.855595 0.215550 3.134171 +v 1.855595 0.274832 3.023263 +v 1.855595 0.354611 2.926052 +v 1.855595 0.451823 2.846273 +v 1.855595 0.562730 2.786992 +v 1.855595 0.683072 2.750486 +v 1.840194 0.808222 2.876457 +v 1.840194 0.906393 2.886126 +v 1.840194 1.000792 2.914761 +v 1.840194 1.087790 2.961263 +v 1.840194 1.164044 3.023843 +v 1.840194 1.226624 3.100097 +v 1.840194 1.273126 3.187095 +v 1.840194 1.301761 3.281493 +v 1.840194 1.311430 3.379664 +v 1.840194 1.301761 3.477835 +v 1.840194 1.273126 3.572234 +v 1.840194 1.226624 3.659232 +v 1.840194 1.164044 3.735486 +v 1.840194 1.087790 3.798066 +v 1.840194 1.000792 3.844568 +v 1.840194 0.906393 3.873203 +v 1.840194 0.808222 3.882872 +v 1.840194 0.710051 3.873203 +v 1.840194 0.615653 3.844568 +v 1.840194 0.528655 3.798066 +v 1.840194 0.452401 3.735486 +v 1.840194 0.389820 3.659231 +v 1.840194 0.343319 3.572233 +v 1.840194 0.314684 3.477835 +v 1.840194 0.305014 3.379664 +v 1.840194 0.314684 3.281493 +v 1.840194 0.343320 3.187095 +v 1.840194 0.389821 3.100096 +v 1.840194 0.452401 3.023843 +v 1.840194 0.528656 2.961262 +v 1.840194 0.615654 2.914761 +v 1.840194 0.710052 2.886125 +v 1.353033 0.808222 2.561027 +v 1.353033 0.967930 2.576757 +v 1.353033 1.121501 2.623343 +v 1.353033 1.263033 2.698993 +v 1.353033 1.387086 2.800801 +v 1.353033 1.488894 2.924854 +v 1.353033 1.564544 3.066386 +v 1.353033 1.611130 3.219956 +v 1.353033 1.626859 3.379664 +v 1.353033 1.611130 3.539372 +v 1.353033 1.564544 3.692943 +v 1.353033 1.488894 3.834475 +v 1.353033 1.387086 3.958528 +v 1.353033 1.263033 4.060336 +v 1.353033 1.121501 4.135986 +v 1.353033 0.967930 4.182571 +v 1.353033 0.808222 4.198301 +v 1.353033 0.648514 4.182571 +v 1.353033 0.494943 4.135986 +v 1.353033 0.353412 4.060336 +v 1.353033 0.229358 3.958528 +v 1.353033 0.127550 3.834475 +v 1.353033 0.051900 3.692943 +v 1.353033 0.005315 3.539372 +v 1.353033 -0.010415 3.379664 +v 1.353033 0.005316 3.219955 +v 1.353033 0.051901 3.066385 +v 1.353033 0.127551 2.924853 +v 1.353033 0.229359 2.800800 +v 1.353033 0.353413 2.698992 +v 1.353033 0.494945 2.623342 +v 1.353033 0.648515 2.576757 +v 1.846744 0.800318 -3.128476 +v 1.846744 0.720480 -3.174537 +v 1.846744 0.706713 -3.265676 +v 1.846744 0.769385 -3.333263 +v 1.846744 0.861302 -3.326404 +v 1.846744 0.913249 -3.250263 +v 1.846744 0.886108 -3.162177 +v 1.882362 0.798209 -3.100218 +v 1.882362 0.697072 -3.158567 +v 1.882362 0.679633 -3.274020 +v 1.882362 0.759025 -3.359638 +v 1.882362 0.875463 -3.350948 +v 1.882362 0.941268 -3.254496 +v 1.882362 0.906887 -3.142910 +v 1.846744 0.792024 -3.017333 +v 1.846744 0.628413 -3.111725 +v 1.846744 0.600203 -3.298493 +v 1.846744 0.728635 -3.436999 +v 1.846744 0.916998 -3.422941 +v 1.846744 1.023451 -3.266909 +v 1.846744 0.967832 -3.086397 +v 1.846744 0.658244 -3.279309 +v 1.846744 0.677849 -3.156018 +v 1.846744 0.683943 -3.147233 +v 1.846744 0.792559 -3.085690 +v 1.846744 0.553669 -2.648579 +v 1.846744 0.431761 -2.717653 +v 1.846744 0.780979 -3.883210 +v 1.846744 0.920785 -3.873871 +v 1.846744 0.879964 -3.377414 +v 1.846744 0.755402 -3.385735 +v 1.846744 0.745481 -3.381748 +v 1.846744 0.661312 -3.289550 +v 1.846744 0.288318 -3.619718 +v 1.846744 0.382787 -3.723199 +v 1.846744 0.783949 -3.813074 +v 1.846744 0.908512 -3.804752 +v 1.846744 1.241172 -3.616265 +v 1.846744 1.312330 -3.513690 +v 1.846744 1.372374 -3.136086 +v 1.846744 1.336544 -3.016499 +v 1.846744 1.078759 -2.734122 +v 1.846744 0.962922 -2.687573 +v 1.846744 0.581424 -2.713058 +v 1.846744 0.472808 -2.774601 +v 1.846744 0.254873 -3.088758 +v 1.846744 0.235268 -3.212049 +v 1.846744 0.345005 -3.578310 +v 1.846744 0.429174 -3.670509 +v 1.846744 0.879964 -3.377414 +v 1.846744 0.755402 -3.385735 +v 1.846744 0.960424 -3.269568 +v 1.846744 0.889266 -3.372143 +v 1.846744 0.926273 -3.139422 +v 1.846744 0.962103 -3.259010 +v 1.846744 0.803227 -3.084977 +v 1.846744 0.919064 -3.131526 +v 1.846744 0.683943 -3.147233 +v 1.846744 0.792559 -3.085690 +v 1.846744 0.658244 -3.279309 +v 1.846744 0.677849 -3.156018 +v 1.846744 0.745481 -3.381748 +v 1.846744 0.661312 -3.289550 +v 1.846744 0.165151 -3.208634 +v 1.846744 0.187155 -3.070255 +v 1.846744 1.401199 -2.989153 +v 1.846744 1.441414 -3.123376 +v 1.846744 0.962103 -3.259010 +v 1.846744 0.926273 -3.139422 +v 1.846744 0.919064 -3.131526 +v 1.846744 0.803227 -3.084977 +v 1.846744 0.981853 -2.619974 +v 1.846744 1.111866 -2.672219 +v 1.846744 0.889266 -3.372143 +v 1.846744 0.960424 -3.269568 +v 1.846744 1.374021 -3.547190 +v 1.846744 1.294155 -3.662317 +v 1.865511 0.904784 -3.145495 +v 1.865511 0.803871 -3.104944 +v 1.865511 1.359836 -3.138395 +v 1.865511 0.942278 -3.256555 +v 1.865511 0.267171 -3.092118 +v 1.865511 0.694646 -3.166831 +v 1.865511 0.677567 -3.274238 +v 1.865511 0.248002 -3.212669 +v 1.865511 0.699955 -3.159178 +v 1.865511 0.480262 -2.784944 +v 1.865511 0.586465 -2.724769 +v 1.865511 0.794577 -3.105565 +v 1.865511 0.911063 -3.152374 +v 1.865511 1.324802 -3.021465 +v 1.865511 0.906283 -3.792200 +v 1.865511 0.784489 -3.800336 +v 1.865511 0.762207 -3.366953 +v 1.865511 0.870721 -3.359704 +v 1.865511 0.753565 -3.363480 +v 1.865511 0.437599 -3.660940 +v 1.865511 0.680240 -3.283160 +v 1.865511 0.355300 -3.570791 +v 1.865511 0.959483 -2.699850 +v 1.865511 1.072746 -2.745364 +v 1.865511 0.878825 -3.355113 +v 1.865511 0.940815 -3.265753 +v 1.865511 1.301126 -3.507607 +v 1.865511 1.231549 -3.607902 +v 1.846743 0.808222 -4.058591 +v 1.846743 0.967930 -4.042861 +v 1.846743 1.121501 -3.996275 +v 1.846743 1.263033 -3.920625 +v 1.846743 1.387086 -3.818817 +v 1.846743 1.488894 -3.694764 +v 1.846743 1.564544 -3.553232 +v 1.846743 1.611130 -3.399662 +v 1.846743 1.626859 -3.239954 +v 1.846743 1.611130 -3.080245 +v 1.846743 1.564544 -2.926675 +v 1.846743 1.488894 -2.785143 +v 1.846743 1.387086 -2.661090 +v 1.846743 1.263033 -2.559282 +v 1.846743 1.121501 -2.483632 +v 1.846743 0.967930 -2.437047 +v 1.846743 0.808222 -2.421317 +v 1.846743 0.648514 -2.437047 +v 1.846743 0.494943 -2.483632 +v 1.846743 0.353412 -2.559282 +v 1.846743 0.229358 -2.661090 +v 1.846743 0.127550 -2.785143 +v 1.846743 0.051900 -2.926675 +v 1.846743 0.005315 -3.080246 +v 1.846743 -0.010415 -3.239954 +v 1.846743 0.005316 -3.399662 +v 1.846743 0.051901 -3.553233 +v 1.846743 0.127551 -3.694765 +v 1.846743 0.229359 -3.818818 +v 1.846743 0.353413 -3.920626 +v 1.846743 0.494945 -3.996276 +v 1.846743 0.648515 -4.042861 +v 1.888794 0.808222 -3.980936 +v 1.888794 0.952781 -3.966698 +v 1.888794 1.091784 -3.924532 +v 1.888794 1.219890 -3.856058 +v 1.888794 1.332176 -3.763907 +v 1.888794 1.424327 -3.651621 +v 1.888794 1.492801 -3.523515 +v 1.888794 1.534967 -3.384512 +v 1.888794 1.549205 -3.239954 +v 1.888794 1.534967 -3.095395 +v 1.888794 1.492801 -2.956392 +v 1.888794 1.424327 -2.828286 +v 1.888794 1.332176 -2.716000 +v 1.888794 1.219890 -2.623849 +v 1.888794 1.091784 -2.555375 +v 1.888794 0.952781 -2.513209 +v 1.888794 0.808222 -2.498971 +v 1.888794 0.663664 -2.513209 +v 1.888794 0.524660 -2.555375 +v 1.888794 0.396554 -2.623849 +v 1.888794 0.284268 -2.716000 +v 1.888794 0.192118 -2.828286 +v 1.888794 0.123644 -2.956393 +v 1.888794 0.081477 -3.095396 +v 1.888794 0.067240 -3.239954 +v 1.888794 0.081478 -3.384513 +v 1.888794 0.123644 -3.523516 +v 1.888794 0.192118 -3.651622 +v 1.888794 0.284269 -3.763908 +v 1.888794 0.396555 -3.856058 +v 1.888794 0.524662 -3.924532 +v 1.888794 0.663665 -3.966699 +v 1.855595 0.808222 -3.881458 +v 1.855595 0.933374 -3.869132 +v 1.855595 1.053715 -3.832626 +v 1.855595 1.164623 -3.773345 +v 1.855595 1.261834 -3.693566 +v 1.855595 1.341614 -3.596354 +v 1.855595 1.400895 -3.485447 +v 1.855595 1.437400 -3.365105 +v 1.855595 1.449726 -3.239954 +v 1.855595 1.437400 -3.114802 +v 1.855595 1.400895 -2.994461 +v 1.855595 1.341614 -2.883553 +v 1.855595 1.261834 -2.786342 +v 1.855595 1.164623 -2.706563 +v 1.855595 1.053715 -2.647281 +v 1.855595 0.933373 -2.610775 +v 1.855595 0.808222 -2.598450 +v 1.855595 0.683071 -2.610775 +v 1.855595 0.562729 -2.647281 +v 1.855595 0.451821 -2.706563 +v 1.855595 0.354610 -2.786342 +v 1.855595 0.274831 -2.883553 +v 1.855595 0.215550 -2.994461 +v 1.855595 0.179044 -3.114803 +v 1.855595 0.166718 -3.239954 +v 1.855595 0.179045 -3.365105 +v 1.855595 0.215550 -3.485447 +v 1.855595 0.274832 -3.596355 +v 1.855595 0.354611 -3.693566 +v 1.855595 0.451823 -3.773345 +v 1.855595 0.562730 -3.832626 +v 1.855595 0.683072 -3.869132 +v 1.840194 0.808222 -3.743161 +v 1.840194 0.906393 -3.733492 +v 1.840194 1.000792 -3.704857 +v 1.840194 1.087790 -3.658355 +v 1.840194 1.164044 -3.595775 +v 1.840194 1.226624 -3.519521 +v 1.840194 1.273126 -3.432523 +v 1.840194 1.301761 -3.338125 +v 1.840194 1.311430 -3.239954 +v 1.840194 1.301761 -3.141783 +v 1.840194 1.273126 -3.047384 +v 1.840194 1.226624 -2.960386 +v 1.840194 1.164044 -2.884132 +v 1.840194 1.087790 -2.821552 +v 1.840194 1.000792 -2.775050 +v 1.840194 0.906393 -2.746415 +v 1.840194 0.808222 -2.736746 +v 1.840194 0.710051 -2.746415 +v 1.840194 0.615653 -2.775050 +v 1.840194 0.528655 -2.821552 +v 1.840194 0.452401 -2.884132 +v 1.840194 0.389820 -2.960387 +v 1.840194 0.343319 -3.047385 +v 1.840194 0.314684 -3.141783 +v 1.840194 0.305014 -3.239954 +v 1.840194 0.314684 -3.338125 +v 1.840194 0.343320 -3.432523 +v 1.840194 0.389821 -3.519521 +v 1.840194 0.452401 -3.595775 +v 1.840194 0.528656 -3.658356 +v 1.840194 0.615654 -3.704857 +v 1.840194 0.710052 -3.733493 +v 1.353033 0.808222 -4.058591 +v 1.353033 0.967930 -4.042861 +v 1.353033 1.121501 -3.996275 +v 1.353033 1.263033 -3.920625 +v 1.353033 1.387086 -3.818817 +v 1.353033 1.488894 -3.694764 +v 1.353033 1.564544 -3.553232 +v 1.353033 1.611130 -3.399662 +v 1.353033 1.626859 -3.239954 +v 1.353033 1.611130 -3.080245 +v 1.353033 1.564544 -2.926675 +v 1.353033 1.488894 -2.785143 +v 1.353033 1.387086 -2.661090 +v 1.353033 1.263033 -2.559282 +v 1.353033 1.121501 -2.483632 +v 1.353033 0.967930 -2.437047 +v 1.353033 0.808222 -2.421317 +v 1.353033 0.648514 -2.437047 +v 1.353033 0.494943 -2.483632 +v 1.353033 0.353412 -2.559282 +v 1.353033 0.229358 -2.661090 +v 1.353033 0.127550 -2.785143 +v 1.353033 0.051900 -2.926675 +v 1.353033 0.005315 -3.080246 +v 1.353033 -0.010415 -3.239954 +v 1.353033 0.005316 -3.399662 +v 1.353033 0.051901 -3.553233 +v 1.353033 0.127551 -3.694765 +v 1.353033 0.229359 -3.818818 +v 1.353033 0.353413 -3.920626 +v 1.353033 0.494945 -3.996276 +v 1.353033 0.648515 -4.042861 +v 1.750241 2.023547 4.365501 +v 1.284501 1.900495 4.727822 +v 1.750241 1.928161 4.357363 +v 1.284501 1.840112 4.710514 +v 1.269853 1.906111 4.686014 +v 1.735593 2.029163 4.323693 +v 1.735593 1.933777 4.315555 +v 1.269853 1.845728 4.668705 +v -0.014648 1.905965 4.688289 +v -0.014648 1.845915 4.670260 +v 1.301011 0.808222 2.697971 +v 1.301011 0.941214 2.711070 +v 1.301011 1.069095 2.749862 +v 1.301011 1.186951 2.812857 +v 1.301011 1.290252 2.897634 +v 1.301011 1.375030 3.000936 +v 1.301011 1.438025 3.118792 +v 1.301011 1.476817 3.246672 +v 1.301011 1.489915 3.379664 +v 1.301011 1.476817 3.512656 +v 1.301011 1.438025 3.640537 +v 1.301011 1.375030 3.758393 +v 1.301011 1.290252 3.861694 +v 1.301011 1.186951 3.946471 +v 1.301011 1.069095 4.009467 +v 1.301011 0.941214 4.048259 +v 1.301011 0.808222 4.061357 +v 1.301011 0.675230 4.048259 +v 1.301011 0.547349 4.009467 +v 1.301011 0.429494 3.946471 +v 1.301011 0.326192 3.861694 +v 1.301011 0.241415 3.758393 +v 1.301011 0.178420 3.640537 +v 1.301011 0.139627 3.512655 +v 1.301011 0.126529 3.379664 +v 1.301011 0.139628 3.246672 +v 1.301011 0.178420 3.118791 +v 1.301011 0.241416 3.000935 +v 1.301011 0.326193 2.897634 +v 1.301011 0.429495 2.812857 +v 1.301011 0.547351 2.749862 +v 1.301011 0.675231 2.711069 +v 1.591977 0.808222 3.304218 +v -0.159445 0.808222 3.304218 +v -0.159445 0.808222 3.304218 +v 1.591977 0.808222 3.304218 +v -0.159445 0.793497 3.305668 +v 1.591977 0.793497 3.305668 +v -0.159445 0.779338 3.309963 +v 1.591977 0.779338 3.309963 +v -0.159445 0.766289 3.316938 +v 1.591977 0.766289 3.316938 +v -0.159445 0.754852 3.326325 +v 1.591977 0.754852 3.326325 +v -0.159445 0.745465 3.337763 +v 1.591977 0.745465 3.337763 +v -0.159445 0.738490 3.350811 +v 1.591977 0.738490 3.350811 +v -0.159445 0.734195 3.364970 +v 1.591977 0.734195 3.364970 +v -0.159445 0.732745 3.379695 +v 1.591977 0.732745 3.379695 +v -0.159445 0.734195 3.394420 +v 1.591977 0.734195 3.394420 +v -0.159445 0.738490 3.408579 +v 1.591977 0.738490 3.408579 +v -0.159445 0.745465 3.421628 +v 1.591977 0.745465 3.421628 +v -0.159445 0.754852 3.433066 +v 1.591977 0.754852 3.433066 +v -0.159445 0.766289 3.442452 +v 1.591977 0.766289 3.442452 +v -0.159445 0.779338 3.449427 +v 1.591977 0.779338 3.449427 +v -0.159445 0.793497 3.453722 +v 1.591977 0.793497 3.453722 +v -0.159445 0.808222 3.455173 +v 1.591977 0.808222 3.455173 +v -0.159445 0.822947 3.453722 +v 1.591977 0.822947 3.453722 +v -0.159445 0.837106 3.449427 +v 1.591977 0.837106 3.449427 +v -0.159445 0.850155 3.442452 +v 1.591977 0.850155 3.442452 +v -0.159445 0.861593 3.433066 +v 1.591977 0.861593 3.433066 +v -0.159445 0.870979 3.421628 +v 1.591977 0.870979 3.421628 +v -0.159445 0.877954 3.408579 +v 1.591977 0.877954 3.408579 +v -0.159445 0.882249 3.394420 +v 1.591977 0.882249 3.394420 +v -0.159445 0.883700 3.379695 +v 1.591977 0.883700 3.379695 +v -0.159445 0.882249 3.364970 +v 1.591977 0.882249 3.364970 +v -0.159445 0.877954 3.350811 +v 1.591977 0.877954 3.350811 +v -0.159445 0.870979 3.337762 +v 1.591977 0.870979 3.337762 +v -0.159445 0.861593 3.326325 +v 1.591977 0.861593 3.326325 +v -0.159445 0.850155 3.316938 +v 1.591977 0.850155 3.316938 +v -0.159445 0.837106 3.309963 +v 1.591977 0.837106 3.309963 +v -0.159445 0.822947 3.305668 +v 1.591977 0.822947 3.305668 +v -0.159445 0.793497 3.305668 +v 1.591977 0.793497 3.305668 +v -0.159445 0.779338 3.309963 +v 1.591977 0.779338 3.309963 +v -0.159445 0.766289 3.316938 +v 1.591977 0.766289 3.316938 +v -0.159445 0.754852 3.326325 +v 1.591977 0.754852 3.326325 +v -0.159445 0.745465 3.337763 +v 1.591977 0.745465 3.337763 +v -0.159445 0.738490 3.350811 +v 1.591977 0.738490 3.350811 +v -0.159445 0.734195 3.364970 +v 1.591977 0.734195 3.364970 +v -0.159445 0.732745 3.379695 +v 1.591977 0.732745 3.379695 +v -0.159445 0.734195 3.394420 +v 1.591977 0.734195 3.394420 +v -0.159445 0.738490 3.408579 +v 1.591977 0.738490 3.408579 +v -0.159445 0.745465 3.421628 +v 1.591977 0.745465 3.421628 +v -0.159445 0.754852 3.433066 +v 1.591977 0.754852 3.433066 +v -0.159445 0.766289 3.442452 +v 1.591977 0.766289 3.442452 +v -0.159445 0.779338 3.449427 +v 1.591977 0.779338 3.449427 +v -0.159445 0.793497 3.453722 +v 1.591977 0.793497 3.453722 +v -0.159445 0.808222 3.455173 +v 1.591977 0.808222 3.455173 +v -0.159445 0.822947 3.453722 +v 1.591977 0.822947 3.453722 +v -0.159445 0.837106 3.449427 +v 1.591977 0.837106 3.449427 +v -0.159445 0.850155 3.442452 +v 1.591977 0.850155 3.442452 +v -0.159445 0.861593 3.433066 +v 1.591977 0.861593 3.433066 +v -0.159445 0.870979 3.421628 +v 1.591977 0.870979 3.421628 +v -0.159445 0.877954 3.408579 +v 1.591977 0.877954 3.408579 +v -0.159445 0.882249 3.394420 +v 1.591977 0.882249 3.394420 +v -0.159445 0.883700 3.379695 +v 1.591977 0.883700 3.379695 +v -0.159445 0.882249 3.364970 +v 1.591977 0.882249 3.364970 +v -0.159445 0.877954 3.350811 +v 1.591977 0.877954 3.350811 +v -0.159445 0.870979 3.337762 +v 1.591977 0.870979 3.337762 +v -0.159445 0.861593 3.326325 +v 1.591977 0.861593 3.326325 +v -0.159445 0.850155 3.316938 +v 1.591977 0.850155 3.316938 +v -0.159445 0.837106 3.309963 +v 1.591977 0.837106 3.309963 +v -0.159445 0.822947 3.305668 +v 1.591977 0.822947 3.305668 +v 1.591977 0.808222 -3.306741 +v -0.159445 0.808222 -3.306741 +v -0.159445 0.793497 -3.305290 +v 1.591977 0.793497 -3.305290 +v -0.159445 0.779338 -3.300995 +v 1.591977 0.779338 -3.300995 +v -0.159445 0.766289 -3.294020 +v 1.591977 0.766289 -3.294020 +v -0.159445 0.754852 -3.284634 +v 1.591977 0.754852 -3.284634 +v -0.159445 0.745465 -3.273196 +v 1.591977 0.745465 -3.273196 +v -0.159445 0.738490 -3.260147 +v 1.591977 0.738490 -3.260147 +v -0.159445 0.734195 -3.245988 +v 1.591977 0.734195 -3.245988 +v -0.159445 0.732745 -3.231263 +v 1.591977 0.732745 -3.231263 +v -0.159445 0.734195 -3.216538 +v 1.591977 0.734195 -3.216538 +v -0.159445 0.738490 -3.202379 +v 1.591977 0.738490 -3.202379 +v -0.159445 0.745465 -3.189330 +v 1.591977 0.745465 -3.189330 +v -0.159445 0.754852 -3.177893 +v 1.591977 0.754852 -3.177893 +v -0.159445 0.766289 -3.168506 +v 1.591977 0.766289 -3.168506 +v -0.159445 0.779338 -3.161531 +v 1.591977 0.779338 -3.161531 +v -0.159445 0.793497 -3.157236 +v 1.591977 0.793497 -3.157236 +v -0.159445 0.808222 -3.155786 +v 1.591977 0.808222 -3.155786 +v -0.159445 0.822947 -3.157236 +v 1.591977 0.822947 -3.157236 +v -0.159445 0.837106 -3.161531 +v 1.591977 0.837106 -3.161531 +v -0.159445 0.850155 -3.168506 +v 1.591977 0.850155 -3.168506 +v -0.159445 0.861593 -3.177893 +v 1.591977 0.861593 -3.177893 +v -0.159445 0.870979 -3.189330 +v 1.591977 0.870979 -3.189330 +v -0.159445 0.877954 -3.202379 +v 1.591977 0.877954 -3.202379 +v -0.159445 0.882249 -3.216538 +v 1.591977 0.882249 -3.216538 +v -0.159445 0.883700 -3.231263 +v 1.591977 0.883700 -3.231263 +v -0.159445 0.882249 -3.245988 +v 1.591977 0.882249 -3.245988 +v -0.159445 0.877954 -3.260147 +v 1.591977 0.877954 -3.260147 +v -0.159445 0.870979 -3.273196 +v 1.591977 0.870979 -3.273196 +v -0.159445 0.861593 -3.284634 +v 1.591977 0.861593 -3.284634 +v -0.159445 0.850155 -3.294020 +v 1.591977 0.850155 -3.294020 +v -0.159445 0.837106 -3.300995 +v 1.591977 0.837106 -3.300995 +v -0.159445 0.822947 -3.305290 +v 1.591977 0.822947 -3.305290 +v 1.000000 3.301469 0.574261 +v 1.000000 2.051993 4.367670 +v -0.033414 2.565001 2.887454 +v 1.441406 3.301469 0.574261 +v 1.555197 2.833836 2.103204 +v 1.750241 2.051993 4.367670 +v -0.033336 2.550689 2.882889 +v 1.000079 3.259221 0.654277 +v 0.877596 2.549781 2.882589 +v 1.358550 3.258375 0.653997 +v 1.466463 2.816492 2.104779 +v 1.531234 2.548796 2.882264 +v 1.736886 2.482217 -5.209983 +v 1.750241 2.478743 -5.231385 +v 1.750241 2.374938 -5.214535 +v 1.736886 2.378413 -5.193133 +v -0.013355 2.482217 -5.209983 +v -0.013355 2.378412 -5.193133 +v 1.732752 2.482217 -5.209983 +v 1.732752 2.378413 -5.193133 +v 1.732752 2.478743 -5.231385 +v 1.732752 2.374938 -5.214535 +v 1.300982 0.808222 -3.921466 +v 1.300982 0.941178 -3.908370 +v 1.300982 1.069026 -3.869588 +v 1.300982 1.186850 -3.806610 +v 1.300982 1.290124 -3.721855 +v 1.300982 1.374879 -3.618581 +v 1.300982 1.437857 -3.500757 +v 1.300982 1.476639 -3.372910 +v 1.300982 1.489734 -3.239954 +v 1.300982 1.476639 -3.106997 +v 1.300982 1.437857 -2.979151 +v 1.300982 1.374879 -2.861326 +v 1.300982 1.290124 -2.758052 +v 1.300982 1.186850 -2.673297 +v 1.300982 1.069025 -2.610319 +v 1.300982 0.941178 -2.571537 +v 1.300982 0.808222 -2.558442 +v 1.300982 0.675266 -2.571537 +v 1.300982 0.547419 -2.610319 +v 1.300982 0.429594 -2.673297 +v 1.300982 0.326320 -2.758052 +v 1.300982 0.241566 -2.861326 +v 1.300982 0.178587 -2.979151 +v 1.300982 0.139805 -3.106998 +v 1.300982 0.126710 -3.239954 +v 1.300982 0.139806 -3.372911 +v 1.300982 0.178588 -3.500757 +v 1.300982 0.241566 -3.618582 +v 1.300982 0.326321 -3.721856 +v 1.300982 0.429595 -3.806610 +v 1.300982 0.547420 -3.869589 +v 1.300982 0.675267 -3.908370 +v -1.000000 1.919617 4.732432 +v -1.000000 0.974478 4.635892 +v 0.000000 3.301469 0.574261 +v -1.000000 3.273532 0.658841 +v 0.000000 1.086208 -5.076335 +v 0.000000 1.919617 4.732432 +v 0.000000 0.971679 4.663217 +v 0.000000 2.525397 -5.238923 +v -1.000000 0.655211 2.310734 +v 0.000000 0.655211 2.310734 +v -0.877517 2.564093 2.887154 +v 0.000000 2.051993 4.367670 +v 0.000000 0.882397 4.314609 +v -1.000000 0.882397 4.314609 +v 0.000000 3.067818 -1.579714 +v -1.000000 3.067818 -1.579714 +v -1.000000 0.667890 -2.227377 +v 0.000000 0.667890 -2.227377 +v -1.000000 0.785508 -4.214180 +v 0.000000 0.785508 -4.214180 +v 0.000000 2.638943 -4.453823 +v -1.000000 2.638943 -4.453823 +v -1.000000 0.874439 4.244418 +v -1.000000 0.655517 2.313426 +v -1.000000 1.111976 2.351255 +v -1.000000 1.866242 2.835600 +v -1.000000 1.833448 3.907717 +v -1.000000 1.258289 4.260885 +v -1.000000 0.668172 -2.232137 +v -1.000000 1.196988 -2.260916 +v -1.000000 1.854486 -2.740417 +v -1.000000 1.879915 -3.782969 +v -1.000000 1.335027 -4.186186 +v -1.750241 2.525397 -5.238923 +v -1.750241 1.086208 -5.076335 +v -1.284501 1.919617 4.732432 +v -1.327607 0.971679 4.653199 +v -1.531155 2.563108 2.886828 +v -1.531797 3.067818 -1.579714 +v -1.358472 3.272686 0.658562 +v -1.466385 2.830804 2.109343 +v -1.750241 0.655211 2.182597 +v -1.750241 0.882397 4.314609 +v -1.750241 0.667890 -2.227377 +v -1.697931 2.638943 -4.453823 +v -1.750241 2.485732 -4.434013 +v -1.750241 2.160423 2.167351 +v -1.750241 2.354560 -1.772200 +v -1.818752 0.655211 2.182857 +v -1.819952 0.655517 2.313426 +v -1.819952 0.874439 4.244418 +v -1.750241 0.882397 4.314609 +v -1.750241 1.128912 2.225720 +v -1.819952 1.111976 2.351255 +v -1.750241 1.985622 2.765436 +v -1.819952 1.866242 2.835600 +v -1.750241 1.936693 3.953938 +v -1.819952 1.833448 3.907717 +v -1.750241 1.341437 4.333489 +v -1.819952 1.258289 4.260885 +v -1.750241 0.883422 2.180506 +v -1.750241 1.591581 -4.318402 +v -1.750224 0.785508 -4.214180 +v -1.750241 0.833292 -4.351184 +v -1.820337 0.668172 -2.232137 +v -1.750241 0.667890 -2.048774 +v -1.820337 1.196988 -2.260916 +v -1.793278 1.210958 -2.101550 +v -1.820337 1.854486 -2.740417 +v -1.750241 1.987285 -2.642222 +v -1.820337 1.879915 -3.782969 +v -1.750241 2.014194 -3.854774 +v -1.820337 1.335027 -4.186186 +v -1.750241 1.350402 -4.282620 +v -1.712797 0.888017 2.180506 +v -1.819131 0.883519 2.180886 +v -1.720162 0.917570 -2.072449 +v -1.717040 0.905044 -0.269841 +v -1.750241 0.900970 -0.269841 +v -1.818854 0.655211 2.182597 +v -1.818854 0.667890 -2.048774 +v -1.818854 0.655211 2.182857 +v -1.818854 0.883422 2.180506 +v -1.818854 0.913878 -2.072449 +v -1.818854 0.900970 -0.269841 +v -1.750241 2.253663 0.275267 +v -1.772394 1.127157 2.177967 +v -1.750241 1.213567 -4.300763 +v -1.750241 1.289006 -5.099246 +v -1.750181 1.335027 -4.186186 +v -1.819927 1.289006 -5.099246 +v -1.819927 1.086208 -5.076335 +v -1.819927 0.833292 -4.351184 +v -1.819927 1.213567 -4.300763 +v -1.750215 1.204111 -4.203537 +v -1.750241 0.833292 -4.351184 +v -1.750241 1.213567 -4.300763 +v -1.819927 0.833292 -4.351184 +v -1.819927 1.213567 -4.300763 +v -1.750241 0.784857 -4.213239 +v -1.750241 1.204197 -4.203453 +v -1.819927 0.784857 -4.213239 +v -1.819927 1.204197 -4.203453 +v 0.000000 1.288997 -5.099216 +v -1.750241 1.289002 -5.099215 +v 0.000000 1.266547 -4.861532 +v -1.750241 1.266550 -4.861531 +v 0.000000 1.372881 -4.864861 +v -1.750241 1.372882 -4.864861 +v 0.000000 1.389481 -5.059558 +v -1.750241 1.389482 -5.059558 +v -1.704873 1.213566 -4.300773 +v -1.704873 1.350401 -4.282630 +v -1.704814 1.335025 -4.186196 +v -1.704847 1.204110 -4.203547 +v -1.704873 1.289004 -5.099256 +v -1.704873 1.372881 -4.864871 +v -1.704873 1.266549 -4.861541 +v -1.000000 1.335027 -4.186186 +v -1.750181 1.335027 -4.186186 +v -1.704813 1.335027 -4.186186 +v -0.999869 0.785508 -4.214180 +v -1.704605 1.335027 -4.186186 +v -1.781390 1.163258 0.334393 +v -1.715989 0.900825 0.337296 +v -1.597979 2.686126 2.117274 +v -1.695288 2.350152 2.149278 +v -1.568109 2.947990 -1.569140 +v -1.682906 2.571904 -1.628006 +v -1.470975 3.199804 0.572917 +v -1.497593 3.130800 -0.014067 +v -1.688418 2.473200 0.053302 +v -1.689320 2.457031 0.328725 +v -1.488895 3.153348 0.177737 +v -1.562110 2.963541 -1.436855 +v -1.683560 2.560198 -1.428613 +v -1.570283 2.798146 1.780491 +v -1.694388 2.366281 1.874541 +v -1.586019 2.734497 1.971851 +v -1.695039 2.354623 2.073121 +v -1.703611 2.262414 3.349329 +v -1.671976 2.347888 2.072812 +v -1.672225 2.343417 2.148969 +v -1.547219 2.791411 1.780182 +v -1.447912 3.193069 0.572608 +v -1.660496 2.553463 -1.428922 +v -1.665354 2.466465 0.052993 +v -1.474530 3.124065 -0.014376 +v -1.465832 3.146613 0.177428 +v -1.666257 2.450296 0.328416 +v -1.539047 2.956806 -1.437164 +v -1.671325 2.359546 1.874232 +v -1.574915 2.679392 2.116965 +v -1.562956 2.727762 1.971541 +v -1.680548 2.255679 3.349020 +v -1.555592 2.944302 -1.569304 +v -1.670389 2.568216 -1.628170 +v -1.549594 2.959853 -1.437019 +v -1.476379 3.149660 0.177573 +v -1.485076 3.127112 -0.014231 +v -1.675901 2.469512 0.053138 +v -1.676804 2.453343 0.328561 +v -1.671043 2.556510 -1.428777 +v -1.573503 2.730809 1.971686 +v -1.557766 2.794458 1.780327 +v -1.681871 2.362593 1.874377 +v -1.682522 2.350935 2.072957 +v -1.750241 1.263441 4.331896 +v -1.327607 1.287596 4.716530 +v 0.000000 1.287597 4.726548 +v -1.284501 1.284919 4.656356 +v 0.000000 1.291921 4.656356 +v -1.393376 1.287596 4.679573 +v -1.393376 0.971679 4.616242 +v -1.816010 0.882397 4.314609 +v -1.816010 1.263441 4.331896 +v -1.754250 1.258442 4.260794 +v -1.754033 0.874437 4.244418 +v -1.820019 1.258442 4.260794 +v -1.819803 0.874437 4.244418 +v -1.846744 0.800318 3.491142 +v -1.846744 0.720480 3.445081 +v -1.846744 0.706713 3.353942 +v -1.846744 0.769385 3.286355 +v -1.846744 0.861302 3.293214 +v -1.846744 0.913249 3.369355 +v -1.846744 0.886108 3.457441 +v -1.882362 0.798209 3.519400 +v -1.882362 0.697072 3.461051 +v -1.882362 0.679633 3.345598 +v -1.882362 0.759025 3.259980 +v -1.882362 0.875463 3.268670 +v -1.882362 0.941268 3.365122 +v -1.882362 0.906887 3.476708 +v -1.846744 0.792024 3.602285 +v -1.846744 0.628413 3.507893 +v -1.846744 0.600203 3.321125 +v -1.846744 0.728635 3.182619 +v -1.846744 0.916998 3.196676 +v -1.846744 1.023451 3.352709 +v -1.846744 0.967832 3.533221 +v -1.846744 0.658244 3.340309 +v -1.846744 0.677849 3.463600 +v -1.846744 0.683943 3.472385 +v -1.846744 0.792559 3.533928 +v -1.846744 0.553669 3.971039 +v -1.846744 0.431761 3.901965 +v -1.846744 0.780979 2.736408 +v -1.846744 0.920785 2.745747 +v -1.846744 0.879964 3.242204 +v -1.846744 0.755402 3.233883 +v -1.846744 0.745481 3.237870 +v -1.846744 0.661312 3.330068 +v -1.846744 0.288318 2.999900 +v -1.846744 0.382787 2.896419 +v -1.846744 0.783949 2.806544 +v -1.846744 0.908512 2.814866 +v -1.846744 1.241172 3.003353 +v -1.846744 1.312330 3.105928 +v -1.846744 1.372374 3.483531 +v -1.846744 1.336544 3.603119 +v -1.846744 1.078759 3.885496 +v -1.846744 0.962922 3.932045 +v -1.846744 0.581424 3.906559 +v -1.846744 0.472808 3.845017 +v -1.846744 0.254873 3.530860 +v -1.846744 0.235268 3.407569 +v -1.846744 0.345005 3.041307 +v -1.846744 0.429174 2.949109 +v -1.846744 0.879964 3.242204 +v -1.846744 0.755402 3.233883 +v -1.846744 0.960424 3.350050 +v -1.846744 0.889266 3.247475 +v -1.846744 0.926273 3.480196 +v -1.846744 0.962103 3.360608 +v -1.846744 0.803227 3.534641 +v -1.846744 0.919064 3.488092 +v -1.846744 0.683943 3.472385 +v -1.846744 0.792559 3.533928 +v -1.846744 0.658244 3.340309 +v -1.846744 0.677849 3.463600 +v -1.846744 0.745481 3.237870 +v -1.846744 0.661312 3.330068 +v -1.846744 0.165151 3.410984 +v -1.846744 0.187155 3.549363 +v -1.846744 1.401199 3.630465 +v -1.846744 1.441414 3.496242 +v -1.846744 0.962103 3.360608 +v -1.846744 0.926273 3.480196 +v -1.846744 0.919064 3.488092 +v -1.846744 0.803227 3.534641 +v -1.846744 0.981853 3.999644 +v -1.846744 1.111866 3.947399 +v -1.846744 0.889266 3.247475 +v -1.846744 0.960424 3.350050 +v -1.846744 1.374021 3.072428 +v -1.846744 1.294155 2.957301 +v -1.865511 0.904784 3.474123 +v -1.865511 0.803871 3.514674 +v -1.865511 1.359836 3.481223 +v -1.865511 0.942278 3.363063 +v -1.865511 0.267171 3.527500 +v -1.865511 0.694646 3.452786 +v -1.865511 0.677567 3.345380 +v -1.865511 0.248002 3.406949 +v -1.865511 0.699955 3.460439 +v -1.865511 0.480262 3.834674 +v -1.865511 0.586465 3.894849 +v -1.865511 0.794577 3.514053 +v -1.865511 0.911063 3.467244 +v -1.865511 1.324802 3.598153 +v -1.865511 0.906283 2.827418 +v -1.865511 0.784489 2.819282 +v -1.865511 0.762207 3.252665 +v -1.865511 0.870721 3.259914 +v -1.865511 0.753565 3.256138 +v -1.865511 0.437599 2.958678 +v -1.865511 0.680240 3.336458 +v -1.865511 0.355300 3.048827 +v -1.865511 0.959483 3.919768 +v -1.865511 1.072746 3.874254 +v -1.865511 0.878825 3.264505 +v -1.865511 0.940815 3.353865 +v -1.865511 1.301126 3.112011 +v -1.865511 1.231549 3.011716 +v -1.846743 0.808222 2.561027 +v -1.846743 0.967930 2.576757 +v -1.846743 1.121501 2.623343 +v -1.846743 1.263033 2.698993 +v -1.846743 1.387086 2.800801 +v -1.846743 1.488894 2.924854 +v -1.846743 1.564544 3.066386 +v -1.846743 1.611130 3.219956 +v -1.846743 1.626859 3.379664 +v -1.846743 1.611130 3.539372 +v -1.846743 1.564544 3.692943 +v -1.846743 1.488894 3.834475 +v -1.846743 1.387086 3.958528 +v -1.846743 1.263033 4.060336 +v -1.846743 1.121501 4.135986 +v -1.846743 0.967930 4.182571 +v -1.846743 0.808222 4.198301 +v -1.846743 0.648514 4.182571 +v -1.846743 0.494943 4.135986 +v -1.846743 0.353412 4.060336 +v -1.846743 0.229358 3.958528 +v -1.846743 0.127550 3.834475 +v -1.846743 0.051900 3.692943 +v -1.846743 0.005315 3.539372 +v -1.846743 -0.010415 3.379664 +v -1.846743 0.005316 3.219955 +v -1.846743 0.051901 3.066385 +v -1.846743 0.127551 2.924853 +v -1.846743 0.229359 2.800800 +v -1.846743 0.353413 2.698992 +v -1.846743 0.494945 2.623342 +v -1.846743 0.648515 2.576757 +v -1.888794 0.808222 2.638682 +v -1.888794 0.952781 2.652920 +v -1.888794 1.091784 2.695086 +v -1.888794 1.219890 2.763560 +v -1.888794 1.332176 2.855711 +v -1.888794 1.424327 2.967997 +v -1.888794 1.492801 3.096102 +v -1.888794 1.534967 3.235106 +v -1.888794 1.549205 3.379664 +v -1.888794 1.534967 3.524223 +v -1.888794 1.492801 3.663226 +v -1.888794 1.424327 3.791332 +v -1.888794 1.332176 3.903618 +v -1.888794 1.219890 3.995769 +v -1.888794 1.091784 4.064243 +v -1.888794 0.952781 4.106409 +v -1.888794 0.808222 4.120646 +v -1.888794 0.663664 4.106409 +v -1.888794 0.524660 4.064243 +v -1.888794 0.396554 3.995769 +v -1.888794 0.284268 3.903618 +v -1.888794 0.192118 3.791332 +v -1.888794 0.123644 3.663225 +v -1.888794 0.081477 3.524222 +v -1.888794 0.067240 3.379664 +v -1.888794 0.081478 3.235105 +v -1.888794 0.123644 3.096102 +v -1.888794 0.192118 2.967996 +v -1.888794 0.284269 2.855710 +v -1.888794 0.396555 2.763560 +v -1.888794 0.524662 2.695086 +v -1.888794 0.663665 2.652919 +v -1.855595 0.808222 2.738160 +v -1.855595 0.933374 2.750486 +v -1.855595 1.053715 2.786992 +v -1.855595 1.164623 2.846273 +v -1.855595 1.261834 2.926052 +v -1.855595 1.341614 3.023264 +v -1.855595 1.400895 3.134171 +v -1.855595 1.437400 3.254513 +v -1.855595 1.449726 3.379664 +v -1.855595 1.437400 3.504816 +v -1.855595 1.400895 3.625157 +v -1.855595 1.341614 3.736065 +v -1.855595 1.261834 3.833276 +v -1.855595 1.164623 3.913055 +v -1.855595 1.053715 3.972337 +v -1.855595 0.933373 4.008842 +v -1.855595 0.808222 4.021168 +v -1.855595 0.683071 4.008842 +v -1.855595 0.562729 3.972337 +v -1.855595 0.451821 3.913055 +v -1.855595 0.354610 3.833276 +v -1.855595 0.274831 3.736065 +v -1.855595 0.215550 3.625157 +v -1.855595 0.179044 3.504815 +v -1.855595 0.166718 3.379664 +v -1.855595 0.179045 3.254513 +v -1.855595 0.215550 3.134171 +v -1.855595 0.274832 3.023263 +v -1.855595 0.354611 2.926052 +v -1.855595 0.451823 2.846273 +v -1.855595 0.562730 2.786992 +v -1.855595 0.683072 2.750486 +v -1.840194 0.808222 2.876457 +v -1.840194 0.906393 2.886126 +v -1.840194 1.000792 2.914761 +v -1.840194 1.087790 2.961263 +v -1.840194 1.164044 3.023843 +v -1.840194 1.226624 3.100097 +v -1.840194 1.273126 3.187095 +v -1.840194 1.301761 3.281493 +v -1.840194 1.311430 3.379664 +v -1.840194 1.301761 3.477835 +v -1.840194 1.273126 3.572234 +v -1.840194 1.226624 3.659232 +v -1.840194 1.164044 3.735486 +v -1.840194 1.087790 3.798066 +v -1.840194 1.000792 3.844568 +v -1.840194 0.906393 3.873203 +v -1.840194 0.808222 3.882872 +v -1.840194 0.710051 3.873203 +v -1.840194 0.615653 3.844568 +v -1.840194 0.528655 3.798066 +v -1.840194 0.452401 3.735486 +v -1.840194 0.389820 3.659231 +v -1.840194 0.343319 3.572233 +v -1.840194 0.314684 3.477835 +v -1.840194 0.305014 3.379664 +v -1.840194 0.314684 3.281493 +v -1.840194 0.343320 3.187095 +v -1.840194 0.389821 3.100096 +v -1.840194 0.452401 3.023843 +v -1.840194 0.528656 2.961262 +v -1.840194 0.615654 2.914761 +v -1.840194 0.710052 2.886125 +v -1.353033 0.808222 2.561027 +v -1.353033 0.967930 2.576757 +v -1.353033 1.121501 2.623343 +v -1.353033 1.263033 2.698993 +v -1.353033 1.387086 2.800801 +v -1.353033 1.488894 2.924854 +v -1.353033 1.564544 3.066386 +v -1.353033 1.611130 3.219956 +v -1.353033 1.626859 3.379664 +v -1.353033 1.611130 3.539372 +v -1.353033 1.564544 3.692943 +v -1.353033 1.488894 3.834475 +v -1.353033 1.387086 3.958528 +v -1.353033 1.263033 4.060336 +v -1.353033 1.121501 4.135986 +v -1.353033 0.967930 4.182571 +v -1.353033 0.808222 4.198301 +v -1.353033 0.648514 4.182571 +v -1.353033 0.494943 4.135986 +v -1.353033 0.353412 4.060336 +v -1.353033 0.229358 3.958528 +v -1.353033 0.127550 3.834475 +v -1.353033 0.051900 3.692943 +v -1.353033 0.005315 3.539372 +v -1.353033 -0.010415 3.379664 +v -1.353033 0.005316 3.219955 +v -1.353033 0.051901 3.066385 +v -1.353033 0.127551 2.924853 +v -1.353033 0.229359 2.800800 +v -1.353033 0.353413 2.698992 +v -1.353033 0.494945 2.623342 +v -1.353033 0.648515 2.576757 +v -1.846744 0.800318 -3.128476 +v -1.846744 0.720480 -3.174537 +v -1.846744 0.706713 -3.265676 +v -1.846744 0.769385 -3.333263 +v -1.846744 0.861302 -3.326404 +v -1.846744 0.913249 -3.250263 +v -1.846744 0.886108 -3.162177 +v -1.882362 0.798209 -3.100218 +v -1.882362 0.697072 -3.158567 +v -1.882362 0.679633 -3.274020 +v -1.882362 0.759025 -3.359638 +v -1.882362 0.875463 -3.350948 +v -1.882362 0.941268 -3.254496 +v -1.882362 0.906887 -3.142910 +v -1.846744 0.792024 -3.017333 +v -1.846744 0.628413 -3.111725 +v -1.846744 0.600203 -3.298493 +v -1.846744 0.728635 -3.436999 +v -1.846744 0.916998 -3.422941 +v -1.846744 1.023451 -3.266909 +v -1.846744 0.967832 -3.086397 +v -1.846744 0.658244 -3.279309 +v -1.846744 0.677849 -3.156018 +v -1.846744 0.683943 -3.147233 +v -1.846744 0.792559 -3.085690 +v -1.846744 0.553669 -2.648579 +v -1.846744 0.431761 -2.717653 +v -1.846744 0.780979 -3.883210 +v -1.846744 0.920785 -3.873871 +v -1.846744 0.879964 -3.377414 +v -1.846744 0.755402 -3.385735 +v -1.846744 0.745481 -3.381748 +v -1.846744 0.661312 -3.289550 +v -1.846744 0.288318 -3.619718 +v -1.846744 0.382787 -3.723199 +v -1.846744 0.783949 -3.813074 +v -1.846744 0.908512 -3.804752 +v -1.846744 1.241172 -3.616265 +v -1.846744 1.312330 -3.513690 +v -1.846744 1.372374 -3.136086 +v -1.846744 1.336544 -3.016499 +v -1.846744 1.078759 -2.734122 +v -1.846744 0.962922 -2.687573 +v -1.846744 0.581424 -2.713058 +v -1.846744 0.472808 -2.774601 +v -1.846744 0.254873 -3.088758 +v -1.846744 0.235268 -3.212049 +v -1.846744 0.345005 -3.578310 +v -1.846744 0.429174 -3.670509 +v -1.846744 0.879964 -3.377414 +v -1.846744 0.755402 -3.385735 +v -1.846744 0.960424 -3.269568 +v -1.846744 0.889266 -3.372143 +v -1.846744 0.926273 -3.139422 +v -1.846744 0.962103 -3.259010 +v -1.846744 0.803227 -3.084977 +v -1.846744 0.919064 -3.131526 +v -1.846744 0.683943 -3.147233 +v -1.846744 0.792559 -3.085690 +v -1.846744 0.658244 -3.279309 +v -1.846744 0.677849 -3.156018 +v -1.846744 0.745481 -3.381748 +v -1.846744 0.661312 -3.289550 +v -1.846744 0.165151 -3.208634 +v -1.846744 0.187155 -3.070255 +v -1.846744 1.401199 -2.989153 +v -1.846744 1.441414 -3.123376 +v -1.846744 0.962103 -3.259010 +v -1.846744 0.926273 -3.139422 +v -1.846744 0.919064 -3.131526 +v -1.846744 0.803227 -3.084977 +v -1.846744 0.981853 -2.619974 +v -1.846744 1.111866 -2.672219 +v -1.846744 0.889266 -3.372143 +v -1.846744 0.960424 -3.269568 +v -1.846744 1.374021 -3.547190 +v -1.846744 1.294155 -3.662317 +v -1.865511 0.904784 -3.145495 +v -1.865511 0.803871 -3.104944 +v -1.865511 1.359836 -3.138395 +v -1.865511 0.942278 -3.256555 +v -1.865511 0.267171 -3.092118 +v -1.865511 0.694646 -3.166831 +v -1.865511 0.677567 -3.274238 +v -1.865511 0.248002 -3.212669 +v -1.865511 0.699955 -3.159178 +v -1.865511 0.480262 -2.784944 +v -1.865511 0.586465 -2.724769 +v -1.865511 0.794577 -3.105565 +v -1.865511 0.911063 -3.152374 +v -1.865511 1.324802 -3.021465 +v -1.865511 0.906283 -3.792200 +v -1.865511 0.784489 -3.800336 +v -1.865511 0.762207 -3.366953 +v -1.865511 0.870721 -3.359704 +v -1.865511 0.753565 -3.363480 +v -1.865511 0.437599 -3.660940 +v -1.865511 0.680240 -3.283160 +v -1.865511 0.355300 -3.570791 +v -1.865511 0.959483 -2.699850 +v -1.865511 1.072746 -2.745364 +v -1.865511 0.878825 -3.355113 +v -1.865511 0.940815 -3.265753 +v -1.865511 1.301126 -3.507607 +v -1.865511 1.231549 -3.607902 +v -1.846743 0.808222 -4.058591 +v -1.846743 0.967930 -4.042861 +v -1.846743 1.121501 -3.996275 +v -1.846743 1.263033 -3.920625 +v -1.846743 1.387086 -3.818817 +v -1.846743 1.488894 -3.694764 +v -1.846743 1.564544 -3.553232 +v -1.846743 1.611130 -3.399662 +v -1.846743 1.626859 -3.239954 +v -1.846743 1.611130 -3.080245 +v -1.846743 1.564544 -2.926675 +v -1.846743 1.488894 -2.785143 +v -1.846743 1.387086 -2.661090 +v -1.846743 1.263033 -2.559282 +v -1.846743 1.121501 -2.483632 +v -1.846743 0.967930 -2.437047 +v -1.846743 0.808222 -2.421317 +v -1.846743 0.648514 -2.437047 +v -1.846743 0.494943 -2.483632 +v -1.846743 0.353412 -2.559282 +v -1.846743 0.229358 -2.661090 +v -1.846743 0.127550 -2.785143 +v -1.846743 0.051900 -2.926675 +v -1.846743 0.005315 -3.080246 +v -1.846743 -0.010415 -3.239954 +v -1.846743 0.005316 -3.399662 +v -1.846743 0.051901 -3.553233 +v -1.846743 0.127551 -3.694765 +v -1.846743 0.229359 -3.818818 +v -1.846743 0.353413 -3.920626 +v -1.846743 0.494945 -3.996276 +v -1.846743 0.648515 -4.042861 +v -1.888794 0.808222 -3.980936 +v -1.888794 0.952781 -3.966698 +v -1.888794 1.091784 -3.924532 +v -1.888794 1.219890 -3.856058 +v -1.888794 1.332176 -3.763907 +v -1.888794 1.424327 -3.651621 +v -1.888794 1.492801 -3.523515 +v -1.888794 1.534967 -3.384512 +v -1.888794 1.549205 -3.239954 +v -1.888794 1.534967 -3.095395 +v -1.888794 1.492801 -2.956392 +v -1.888794 1.424327 -2.828286 +v -1.888794 1.332176 -2.716000 +v -1.888794 1.219890 -2.623849 +v -1.888794 1.091784 -2.555375 +v -1.888794 0.952781 -2.513209 +v -1.888794 0.808222 -2.498971 +v -1.888794 0.663664 -2.513209 +v -1.888794 0.524660 -2.555375 +v -1.888794 0.396554 -2.623849 +v -1.888794 0.284268 -2.716000 +v -1.888794 0.192118 -2.828286 +v -1.888794 0.123644 -2.956393 +v -1.888794 0.081477 -3.095396 +v -1.888794 0.067240 -3.239954 +v -1.888794 0.081478 -3.384513 +v -1.888794 0.123644 -3.523516 +v -1.888794 0.192118 -3.651622 +v -1.888794 0.284269 -3.763908 +v -1.888794 0.396555 -3.856058 +v -1.888794 0.524662 -3.924532 +v -1.888794 0.663665 -3.966699 +v -1.855595 0.808222 -3.881458 +v -1.855595 0.933374 -3.869132 +v -1.855595 1.053715 -3.832626 +v -1.855595 1.164623 -3.773345 +v -1.855595 1.261834 -3.693566 +v -1.855595 1.341614 -3.596354 +v -1.855595 1.400895 -3.485447 +v -1.855595 1.437400 -3.365105 +v -1.855595 1.449726 -3.239954 +v -1.855595 1.437400 -3.114802 +v -1.855595 1.400895 -2.994461 +v -1.855595 1.341614 -2.883553 +v -1.855595 1.261834 -2.786342 +v -1.855595 1.164623 -2.706563 +v -1.855595 1.053715 -2.647281 +v -1.855595 0.933373 -2.610775 +v -1.855595 0.808222 -2.598450 +v -1.855595 0.683071 -2.610775 +v -1.855595 0.562729 -2.647281 +v -1.855595 0.451821 -2.706563 +v -1.855595 0.354610 -2.786342 +v -1.855595 0.274831 -2.883553 +v -1.855595 0.215550 -2.994461 +v -1.855595 0.179044 -3.114803 +v -1.855595 0.166718 -3.239954 +v -1.855595 0.179045 -3.365105 +v -1.855595 0.215550 -3.485447 +v -1.855595 0.274832 -3.596355 +v -1.855595 0.354611 -3.693566 +v -1.855595 0.451823 -3.773345 +v -1.855595 0.562730 -3.832626 +v -1.855595 0.683072 -3.869132 +v -1.840194 0.808222 -3.743161 +v -1.840194 0.906393 -3.733492 +v -1.840194 1.000792 -3.704857 +v -1.840194 1.087790 -3.658355 +v -1.840194 1.164044 -3.595775 +v -1.840194 1.226624 -3.519521 +v -1.840194 1.273126 -3.432523 +v -1.840194 1.301761 -3.338125 +v -1.840194 1.311430 -3.239954 +v -1.840194 1.301761 -3.141783 +v -1.840194 1.273126 -3.047384 +v -1.840194 1.226624 -2.960386 +v -1.840194 1.164044 -2.884132 +v -1.840194 1.087790 -2.821552 +v -1.840194 1.000792 -2.775050 +v -1.840194 0.906393 -2.746415 +v -1.840194 0.808222 -2.736746 +v -1.840194 0.710051 -2.746415 +v -1.840194 0.615653 -2.775050 +v -1.840194 0.528655 -2.821552 +v -1.840194 0.452401 -2.884132 +v -1.840194 0.389820 -2.960387 +v -1.840194 0.343319 -3.047385 +v -1.840194 0.314684 -3.141783 +v -1.840194 0.305014 -3.239954 +v -1.840194 0.314684 -3.338125 +v -1.840194 0.343320 -3.432523 +v -1.840194 0.389821 -3.519521 +v -1.840194 0.452401 -3.595775 +v -1.840194 0.528656 -3.658356 +v -1.840194 0.615654 -3.704857 +v -1.840194 0.710052 -3.733493 +v -1.353033 0.808222 -4.058591 +v -1.353033 0.967930 -4.042861 +v -1.353033 1.121501 -3.996275 +v -1.353033 1.263033 -3.920625 +v -1.353033 1.387086 -3.818817 +v -1.353033 1.488894 -3.694764 +v -1.353033 1.564544 -3.553232 +v -1.353033 1.611130 -3.399662 +v -1.353033 1.626859 -3.239954 +v -1.353033 1.611130 -3.080245 +v -1.353033 1.564544 -2.926675 +v -1.353033 1.488894 -2.785143 +v -1.353033 1.387086 -2.661090 +v -1.353033 1.263033 -2.559282 +v -1.353033 1.121501 -2.483632 +v -1.353033 0.967930 -2.437047 +v -1.353033 0.808222 -2.421317 +v -1.353033 0.648514 -2.437047 +v -1.353033 0.494943 -2.483632 +v -1.353033 0.353412 -2.559282 +v -1.353033 0.229358 -2.661090 +v -1.353033 0.127550 -2.785143 +v -1.353033 0.051900 -2.926675 +v -1.353033 0.005315 -3.080246 +v -1.353033 -0.010415 -3.239954 +v -1.353033 0.005316 -3.399662 +v -1.353033 0.051901 -3.553233 +v -1.353033 0.127551 -3.694765 +v -1.353033 0.229359 -3.818818 +v -1.353033 0.353413 -3.920626 +v -1.353033 0.494945 -3.996276 +v -1.353033 0.648515 -4.042861 +v -1.750241 2.023547 4.365501 +v -1.284501 1.900495 4.727822 +v -1.750241 1.928161 4.357363 +v -1.284501 1.840112 4.710514 +v 0.000000 1.840300 4.712069 +v 0.000000 1.900349 4.730097 +v -1.269853 1.906111 4.686014 +v -1.735593 2.029163 4.323693 +v -1.735593 1.933777 4.315555 +v -1.269853 1.845728 4.668705 +v 0.014648 1.905965 4.688289 +v 0.014648 1.845915 4.670260 +v -1.301011 0.808222 2.697971 +v -1.301011 0.941214 2.711070 +v -1.301011 1.069095 2.749862 +v -1.301011 1.186951 2.812857 +v -1.301011 1.290252 2.897634 +v -1.301011 1.375030 3.000936 +v -1.301011 1.438025 3.118792 +v -1.301011 1.476817 3.246672 +v -1.301011 1.489915 3.379664 +v -1.301011 1.476817 3.512656 +v -1.301011 1.438025 3.640537 +v -1.301011 1.375030 3.758393 +v -1.301011 1.290252 3.861694 +v -1.301011 1.186951 3.946471 +v -1.301011 1.069095 4.009467 +v -1.301011 0.941214 4.048259 +v -1.301011 0.808222 4.061357 +v -1.301011 0.675230 4.048259 +v -1.301011 0.547349 4.009467 +v -1.301011 0.429494 3.946471 +v -1.301011 0.326192 3.861694 +v -1.301011 0.241415 3.758393 +v -1.301011 0.178420 3.640537 +v -1.301011 0.139627 3.512655 +v -1.301011 0.126529 3.379664 +v -1.301011 0.139628 3.246672 +v -1.301011 0.178420 3.118791 +v -1.301011 0.241416 3.000935 +v -1.301011 0.326193 2.897634 +v -1.301011 0.429495 2.812857 +v -1.301011 0.547351 2.749862 +v -1.301011 0.675231 2.711069 +v -1.591977 0.808222 3.304218 +v 0.159445 0.808222 3.304218 +v 0.159445 0.808222 3.304218 +v -1.591977 0.808222 3.304218 +v 0.159445 0.793497 3.305668 +v -1.591977 0.793497 3.305668 +v 0.159445 0.779338 3.309963 +v -1.591977 0.779338 3.309963 +v 0.159445 0.766289 3.316938 +v -1.591977 0.766289 3.316938 +v 0.159445 0.754852 3.326325 +v -1.591977 0.754852 3.326325 +v 0.159445 0.745465 3.337763 +v -1.591977 0.745465 3.337763 +v 0.159445 0.738490 3.350811 +v -1.591977 0.738490 3.350811 +v 0.159445 0.734195 3.364970 +v -1.591977 0.734195 3.364970 +v 0.159445 0.732745 3.379695 +v -1.591977 0.732745 3.379695 +v 0.159445 0.734195 3.394420 +v -1.591977 0.734195 3.394420 +v 0.159445 0.738490 3.408579 +v -1.591977 0.738490 3.408579 +v 0.159445 0.745465 3.421628 +v -1.591977 0.745465 3.421628 +v 0.159445 0.754852 3.433066 +v -1.591977 0.754852 3.433066 +v 0.159445 0.766289 3.442452 +v -1.591977 0.766289 3.442452 +v 0.159445 0.779338 3.449427 +v -1.591977 0.779338 3.449427 +v 0.159445 0.793497 3.453722 +v -1.591977 0.793497 3.453722 +v 0.159445 0.808222 3.455173 +v -1.591977 0.808222 3.455173 +v 0.159445 0.822947 3.453722 +v -1.591977 0.822947 3.453722 +v 0.159445 0.837106 3.449427 +v -1.591977 0.837106 3.449427 +v 0.159445 0.850155 3.442452 +v -1.591977 0.850155 3.442452 +v 0.159445 0.861593 3.433066 +v -1.591977 0.861593 3.433066 +v 0.159445 0.870979 3.421628 +v -1.591977 0.870979 3.421628 +v 0.159445 0.877954 3.408579 +v -1.591977 0.877954 3.408579 +v 0.159445 0.882249 3.394420 +v -1.591977 0.882249 3.394420 +v 0.159445 0.883700 3.379695 +v -1.591977 0.883700 3.379695 +v 0.159445 0.882249 3.364970 +v -1.591977 0.882249 3.364970 +v 0.159445 0.877954 3.350811 +v -1.591977 0.877954 3.350811 +v 0.159445 0.870979 3.337762 +v -1.591977 0.870979 3.337762 +v 0.159445 0.861593 3.326325 +v -1.591977 0.861593 3.326325 +v 0.159445 0.850155 3.316938 +v -1.591977 0.850155 3.316938 +v 0.159445 0.837106 3.309963 +v -1.591977 0.837106 3.309963 +v 0.159445 0.822947 3.305668 +v -1.591977 0.822947 3.305668 +v 0.159445 0.793497 3.305668 +v -1.591977 0.793497 3.305668 +v 0.159445 0.779338 3.309963 +v -1.591977 0.779338 3.309963 +v 0.159445 0.766289 3.316938 +v -1.591977 0.766289 3.316938 +v 0.159445 0.754852 3.326325 +v -1.591977 0.754852 3.326325 +v 0.159445 0.745465 3.337763 +v -1.591977 0.745465 3.337763 +v 0.159445 0.738490 3.350811 +v -1.591977 0.738490 3.350811 +v 0.159445 0.734195 3.364970 +v -1.591977 0.734195 3.364970 +v 0.159445 0.732745 3.379695 +v -1.591977 0.732745 3.379695 +v 0.159445 0.734195 3.394420 +v -1.591977 0.734195 3.394420 +v 0.159445 0.738490 3.408579 +v -1.591977 0.738490 3.408579 +v 0.159445 0.745465 3.421628 +v -1.591977 0.745465 3.421628 +v 0.159445 0.754852 3.433066 +v -1.591977 0.754852 3.433066 +v 0.159445 0.766289 3.442452 +v -1.591977 0.766289 3.442452 +v 0.159445 0.779338 3.449427 +v -1.591977 0.779338 3.449427 +v 0.159445 0.793497 3.453722 +v -1.591977 0.793497 3.453722 +v 0.159445 0.808222 3.455173 +v -1.591977 0.808222 3.455173 +v 0.159445 0.822947 3.453722 +v -1.591977 0.822947 3.453722 +v 0.159445 0.837106 3.449427 +v -1.591977 0.837106 3.449427 +v 0.159445 0.850155 3.442452 +v -1.591977 0.850155 3.442452 +v 0.159445 0.861593 3.433066 +v -1.591977 0.861593 3.433066 +v 0.159445 0.870979 3.421628 +v -1.591977 0.870979 3.421628 +v 0.159445 0.877954 3.408579 +v -1.591977 0.877954 3.408579 +v 0.159445 0.882249 3.394420 +v -1.591977 0.882249 3.394420 +v 0.159445 0.883700 3.379695 +v -1.591977 0.883700 3.379695 +v 0.159445 0.882249 3.364970 +v -1.591977 0.882249 3.364970 +v 0.159445 0.877954 3.350811 +v -1.591977 0.877954 3.350811 +v 0.159445 0.870979 3.337762 +v -1.591977 0.870979 3.337762 +v 0.159445 0.861593 3.326325 +v -1.591977 0.861593 3.326325 +v 0.159445 0.850155 3.316938 +v -1.591977 0.850155 3.316938 +v 0.159445 0.837106 3.309963 +v -1.591977 0.837106 3.309963 +v 0.159445 0.822947 3.305668 +v -1.591977 0.822947 3.305668 +v -1.591977 0.808222 -3.306741 +v 0.159445 0.808222 -3.306741 +v 0.159445 0.793497 -3.305290 +v -1.591977 0.793497 -3.305290 +v 0.159445 0.779338 -3.300995 +v -1.591977 0.779338 -3.300995 +v 0.159445 0.766289 -3.294020 +v -1.591977 0.766289 -3.294020 +v 0.159445 0.754852 -3.284634 +v -1.591977 0.754852 -3.284634 +v 0.159445 0.745465 -3.273196 +v -1.591977 0.745465 -3.273196 +v 0.159445 0.738490 -3.260147 +v -1.591977 0.738490 -3.260147 +v 0.159445 0.734195 -3.245988 +v -1.591977 0.734195 -3.245988 +v 0.159445 0.732745 -3.231263 +v -1.591977 0.732745 -3.231263 +v 0.159445 0.734195 -3.216538 +v -1.591977 0.734195 -3.216538 +v 0.159445 0.738490 -3.202379 +v -1.591977 0.738490 -3.202379 +v 0.159445 0.745465 -3.189330 +v -1.591977 0.745465 -3.189330 +v 0.159445 0.754852 -3.177893 +v -1.591977 0.754852 -3.177893 +v 0.159445 0.766289 -3.168506 +v -1.591977 0.766289 -3.168506 +v 0.159445 0.779338 -3.161531 +v -1.591977 0.779338 -3.161531 +v 0.159445 0.793497 -3.157236 +v -1.591977 0.793497 -3.157236 +v 0.159445 0.808222 -3.155786 +v -1.591977 0.808222 -3.155786 +v 0.159445 0.822947 -3.157236 +v -1.591977 0.822947 -3.157236 +v 0.159445 0.837106 -3.161531 +v -1.591977 0.837106 -3.161531 +v 0.159445 0.850155 -3.168506 +v -1.591977 0.850155 -3.168506 +v 0.159445 0.861593 -3.177893 +v -1.591977 0.861593 -3.177893 +v 0.159445 0.870979 -3.189330 +v -1.591977 0.870979 -3.189330 +v 0.159445 0.877954 -3.202379 +v -1.591977 0.877954 -3.202379 +v 0.159445 0.882249 -3.216538 +v -1.591977 0.882249 -3.216538 +v 0.159445 0.883700 -3.231263 +v -1.591977 0.883700 -3.231263 +v 0.159445 0.882249 -3.245988 +v -1.591977 0.882249 -3.245988 +v 0.159445 0.877954 -3.260147 +v -1.591977 0.877954 -3.260147 +v 0.159445 0.870979 -3.273196 +v -1.591977 0.870979 -3.273196 +v 0.159445 0.861593 -3.284634 +v -1.591977 0.861593 -3.284634 +v 0.159445 0.850155 -3.294020 +v -1.591977 0.850155 -3.294020 +v 0.159445 0.837106 -3.300995 +v -1.591977 0.837106 -3.300995 +v 0.159445 0.822947 -3.305290 +v -1.591977 0.822947 -3.305290 +v -1.000000 3.301469 0.574261 +v 0.000000 3.274440 0.659141 +v -1.000000 2.051993 4.367670 +v 0.033414 2.565001 2.887454 +v -1.441406 3.301469 0.574261 +v -1.555197 2.833836 2.103204 +v -1.750241 2.051993 4.367670 +v 0.000000 3.260128 0.654576 +v 0.033336 2.550689 2.882889 +v -1.000079 3.259221 0.654277 +v -0.877596 2.549781 2.882589 +v -1.358550 3.258375 0.653997 +v -1.466463 2.816492 2.104779 +v -1.531234 2.548796 2.882264 +v -1.736886 2.482217 -5.209983 +v 0.000000 2.478743 -5.231385 +v -1.750241 2.478743 -5.231385 +v -1.750241 2.374938 -5.214535 +v 0.000000 2.374938 -5.214535 +v -1.736886 2.378413 -5.193133 +v 0.013355 2.482217 -5.209983 +v 0.013355 2.378412 -5.193133 +v -1.732752 2.482217 -5.209983 +v -1.732752 2.378413 -5.193133 +v -1.732752 2.478743 -5.231385 +v -1.732752 2.374938 -5.214535 +v -1.300982 0.808222 -3.921466 +v -1.300982 0.941178 -3.908370 +v -1.300982 1.069026 -3.869588 +v -1.300982 1.186850 -3.806610 +v -1.300982 1.290124 -3.721855 +v -1.300982 1.374879 -3.618581 +v -1.300982 1.437857 -3.500757 +v -1.300982 1.476639 -3.372910 +v -1.300982 1.489734 -3.239954 +v -1.300982 1.476639 -3.106997 +v -1.300982 1.437857 -2.979151 +v -1.300982 1.374879 -2.861326 +v -1.300982 1.290124 -2.758052 +v -1.300982 1.186850 -2.673297 +v -1.300982 1.069025 -2.610319 +v -1.300982 0.941178 -2.571537 +v -1.300982 0.808222 -2.558442 +v -1.300982 0.675266 -2.571537 +v -1.300982 0.547419 -2.610319 +v -1.300982 0.429594 -2.673297 +v -1.300982 0.326320 -2.758052 +v -1.300982 0.241566 -2.861326 +v -1.300982 0.178587 -2.979151 +v -1.300982 0.139805 -3.106998 +v -1.300982 0.126710 -3.239954 +v -1.300982 0.139806 -3.372911 +v -1.300982 0.178588 -3.500757 +v -1.300982 0.241566 -3.618582 +v -1.300982 0.326321 -3.721856 +v -1.300982 0.429595 -3.806610 +v -1.300982 0.547420 -3.869589 +v -1.300982 0.675267 -3.908370 +vt 0.625000 0.562500 +vt 0.750000 0.562500 +vt 0.750000 0.625000 +vt 0.625000 0.625000 +vt 0.625000 0.718750 +vt 0.750000 0.718750 +vt 0.750000 0.750000 +vt 0.625000 0.750000 +vt 0.634972 0.717058 +vt 0.627025 0.717322 +vt 0.627025 0.717322 +vt 0.634972 0.717058 +vt 0.625000 0.531250 +vt 0.625000 0.531250 +vt 0.625000 0.500000 +vt 0.750000 0.500000 +vt 0.750000 0.531250 +vt 0.625000 0.562500 +vt 0.401187 0.631547 +vt 0.400179 0.599791 +vt 0.399847 0.589331 +vt 0.399847 0.589331 +vt 0.401187 0.631547 +vt 0.625000 0.625000 +vt 0.625000 0.687500 +vt 0.608050 0.683263 +vt 0.609106 0.677838 +vt 0.610496 0.670701 +vt 0.619267 0.625660 +vt 0.618006 0.614232 +vt 0.617393 0.608686 +vt 0.612853 0.567544 +vt 0.612431 0.563719 +vt 0.573364 0.564889 +vt 0.573160 0.570629 +vt 0.571643 0.613288 +vt 0.571361 0.621217 +vt 0.569778 0.665715 +vt 0.569575 0.671432 +vt 0.569497 0.673624 +vt 0.547725 0.668181 +vt 0.549154 0.617425 +vt 0.550700 0.562500 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.573335 0.487335 +vt 0.625000 0.875000 +vt 0.623082 0.875000 +vt 0.619949 0.750000 +vt 0.625000 0.750000 +vt 0.375000 0.562500 +vt 0.392651 0.552724 +vt 0.392651 0.552724 +vt 0.375000 0.562500 +vt 0.625000 0.718750 +vt 0.608249 0.700317 +vt 0.375000 0.687500 +vt 0.464470 0.693253 +vt 0.585945 0.708658 +vt 0.547815 0.678340 +vt 0.431207 0.638537 +vt 0.429468 0.638617 +vt 0.614785 0.717473 +vt 0.576437 0.712680 +vt 0.456448 0.697681 +vt 0.422954 0.596439 +vt 0.402059 0.631517 +vt 0.375000 0.625000 +vt 0.375000 0.625000 +vt 0.375000 0.625000 +vt 0.375000 0.625000 +vt 0.401187 0.631547 +vt 0.414347 0.540708 +vt 0.431813 0.469918 +vt 0.292083 0.307140 +vt -0.082886 -0.098011 +vt 0.000000 0.000000 +vt 0.598153 0.500000 +vt 0.611577 0.500000 +vt 0.614933 0.500000 +vt 0.618288 0.500000 +vt 0.439201 0.526572 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt 0.399410 0.529471 +vt 0.375000 0.531250 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt -0.060953 -0.072076 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt 0.734375 0.500000 +vt 0.618288 0.500000 +vt 0.734375 0.500000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.718750 0.500000 +vt 0.000000 0.000000 +vt -0.082886 -0.098011 +vt 0.598153 0.500000 +vt 0.573160 0.570629 +vt 0.571643 0.613288 +vt 0.608249 0.700317 +vt 0.608050 0.683263 +vt 0.569497 0.673624 +vt 0.571361 0.621217 +vt 0.569778 0.665715 +vt 0.619267 0.625660 +vt 0.618006 0.614232 +vt 0.569575 0.671432 +vt 0.609106 0.677838 +vt 0.610496 0.670701 +vt 0.617393 0.608686 +vt 0.612853 0.567544 +vt 0.609106 0.677838 +vt 0.610496 0.670701 +vt 0.612853 0.567544 +vt 0.612431 0.563719 +vt 0.569778 0.665715 +vt 0.569575 0.671432 +vt 0.571643 0.613288 +vt 0.571361 0.621217 +vt 0.618006 0.614232 +vt 0.617393 0.608686 +vt 0.573364 0.564889 +vt 0.573160 0.570629 +vt 0.541659 0.750000 +vt 0.562500 0.875000 +vt 0.500000 0.875000 +vt 0.375000 0.875000 +vt 0.375000 0.750000 +vt 0.375000 0.750000 +vt 0.458317 0.750000 +vt 0.456448 0.697681 +vt 0.375000 0.687500 +vt 0.600988 0.750000 +vt 0.000000 0.000000 +vt 0.444928 0.511667 +vt 0.587121 0.675189 +vt 0.608270 0.875000 +vt 0.600988 0.750000 +vt 0.608270 0.875000 +vt 0.623082 0.875000 +vt 0.619949 0.750000 +vt 0.444928 0.511667 +vt 0.614785 0.717473 +vt 0.576437 0.712680 +vt 0.587121 0.675189 +vt 1.000000 0.500000 +vt 1.000000 1.000000 +vt 0.968750 1.000000 +vt 0.968750 0.500000 +vt 0.937500 1.000000 +vt 0.937500 0.500000 +vt 0.906250 1.000000 +vt 0.906250 0.500000 +vt 0.875000 1.000000 +vt 0.875000 0.500000 +vt 0.843750 1.000000 +vt 0.843750 0.500000 +vt 0.812500 1.000000 +vt 0.812500 0.500000 +vt 0.781250 1.000000 +vt 0.781250 0.500000 +vt 0.750000 1.000000 +vt 0.750000 0.500000 +vt 0.718750 1.000000 +vt 0.718750 0.500000 +vt 0.687500 1.000000 +vt 0.687500 0.500000 +vt 0.656250 1.000000 +vt 0.656250 0.500000 +vt 0.625000 1.000000 +vt 0.625000 0.500000 +vt 0.593750 1.000000 +vt 0.593750 0.500000 +vt 0.562500 1.000000 +vt 0.562500 0.500000 +vt 0.531250 1.000000 +vt 0.531250 0.500000 +vt 0.500000 1.000000 +vt 0.500000 0.500000 +vt 0.468750 1.000000 +vt 0.468750 0.500000 +vt 0.437500 1.000000 +vt 0.437500 0.500000 +vt 0.406250 1.000000 +vt 0.406250 0.500000 +vt 0.375000 1.000000 +vt 0.375000 0.500000 +vt 0.343750 1.000000 +vt 0.343750 0.500000 +vt 0.312500 1.000000 +vt 0.312500 0.500000 +vt 0.281250 1.000000 +vt 0.281250 0.500000 +vt 0.250000 1.000000 +vt 0.250000 0.500000 +vt 0.218750 1.000000 +vt 0.218750 0.500000 +vt 0.187500 1.000000 +vt 0.187500 0.500000 +vt 0.156250 1.000000 +vt 0.156250 0.500000 +vt 0.125000 1.000000 +vt 0.125000 0.500000 +vt 0.093750 1.000000 +vt 0.093750 0.500000 +vt 0.062500 1.000000 +vt 0.062500 0.500000 +vt 0.296822 0.485388 +vt 0.250000 0.490000 +vt 0.203179 0.485389 +vt 0.158156 0.471731 +vt 0.116663 0.449553 +vt 0.080295 0.419706 +vt 0.050447 0.383337 +vt 0.028269 0.341844 +vt 0.014612 0.296822 +vt 0.010000 0.250000 +vt 0.014611 0.203179 +vt 0.028269 0.158156 +vt 0.050447 0.116663 +vt 0.080294 0.080294 +vt 0.116663 0.050447 +vt 0.158156 0.028269 +vt 0.203178 0.014612 +vt 0.250000 0.010000 +vt 0.296822 0.014612 +vt 0.341844 0.028269 +vt 0.383337 0.050447 +vt 0.419706 0.080294 +vt 0.449553 0.116663 +vt 0.471731 0.158156 +vt 0.485388 0.203178 +vt 0.490000 0.250000 +vt 0.485388 0.296822 +vt 0.471731 0.341844 +vt 0.449553 0.383337 +vt 0.419706 0.419706 +vt 0.383337 0.449553 +vt 0.341844 0.471731 +vt 0.031250 1.000000 +vt 0.031250 0.500000 +vt 0.000000 1.000000 +vt 0.000000 0.500000 +vt 0.750000 0.490000 +vt 0.796822 0.485388 +vt 0.841844 0.471731 +vt 0.883337 0.449553 +vt 0.919706 0.419706 +vt 0.949553 0.383337 +vt 0.971731 0.341844 +vt 0.985388 0.296822 +vt 0.990000 0.250000 +vt 0.985388 0.203178 +vt 0.971731 0.158156 +vt 0.949553 0.116663 +vt 0.919706 0.080294 +vt 0.883337 0.050447 +vt 0.841844 0.028269 +vt 0.796822 0.014612 +vt 0.750000 0.010000 +vt 0.703178 0.014612 +vt 0.658156 0.028269 +vt 0.616663 0.050447 +vt 0.580294 0.080294 +vt 0.550447 0.116663 +vt 0.528269 0.158156 +vt 0.514611 0.203179 +vt 0.510000 0.250000 +vt 0.514612 0.296822 +vt 0.528269 0.341844 +vt 0.550447 0.383337 +vt 0.580295 0.419706 +vt 0.616663 0.449553 +vt 0.658156 0.471731 +vt 0.703179 0.485389 +vt 0.740064 0.627288 +vt 0.634667 0.627655 +vt 0.740255 0.716823 +vt 0.627717 0.628001 +vt 0.631519 0.684809 +vt 0.627717 0.628001 +vt 0.631519 0.684809 +vt 0.634667 0.627655 +vt 0.740255 0.716823 +vt 0.740064 0.627288 +vt 0.726562 0.500000 +vt 0.614933 0.500000 +vt 0.614933 0.500000 +vt 0.614933 0.500000 +vt 0.726562 0.500000 +vt 0.618288 0.500000 +vt 0.618288 0.500000 +vt 0.625000 0.562500 +vt 0.625000 0.625000 +vt 0.625000 0.718750 +vt 0.625000 0.750000 +vt 0.634972 0.717058 +vt 0.634972 0.717058 +vt 0.627025 0.717322 +vt 0.627025 0.717322 +vt 0.625000 0.531250 +vt 0.625000 0.500000 +vt 0.625000 0.531250 +vt 0.625000 0.562500 +vt 0.401187 0.631547 +vt 0.401187 0.631547 +vt 0.399847 0.589331 +vt 0.399847 0.589331 +vt 0.400179 0.599791 +vt 0.550700 0.562500 +vt 0.549154 0.617425 +vt 0.547725 0.668181 +vt 0.569497 0.673624 +vt 0.569575 0.671432 +vt 0.569778 0.665715 +vt 0.571361 0.621217 +vt 0.571643 0.613288 +vt 0.573160 0.570629 +vt 0.573364 0.564889 +vt 0.612431 0.563719 +vt 0.612853 0.567544 +vt 0.617393 0.608686 +vt 0.618006 0.614232 +vt 0.619267 0.625660 +vt 0.610496 0.670701 +vt 0.609106 0.677838 +vt 0.608050 0.683263 +vt 0.625000 0.687500 +vt 0.625000 0.625000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.573335 0.487335 +vt 0.625000 0.750000 +vt 0.619949 0.750000 +vt 0.375000 0.562500 +vt 0.375000 0.562500 +vt 0.392651 0.552724 +vt 0.392651 0.552724 +vt 0.625000 0.718750 +vt 0.608249 0.700317 +vt 0.375000 0.687500 +vt 0.456448 0.697681 +vt 0.576437 0.712680 +vt 0.614785 0.717473 +vt 0.429468 0.638617 +vt 0.431207 0.638537 +vt 0.547815 0.678340 +vt 0.585945 0.708658 +vt 0.464470 0.693253 +vt 0.422954 0.596439 +vt 0.375000 0.625000 +vt 0.402059 0.631517 +vt 0.375000 0.625000 +vt 0.375000 0.625000 +vt 0.375000 0.625000 +vt 0.401187 0.631547 +vt 0.000000 0.000000 +vt -0.082886 -0.098011 +vt 0.292083 0.307140 +vt 0.431813 0.469918 +vt 0.414347 0.540708 +vt 0.618288 0.500000 +vt 0.614933 0.500000 +vt 0.611577 0.500000 +vt 0.598153 0.500000 +vt 0.000000 0.000000 +vt 0.439201 0.526572 +vt -0.060953 -0.072076 +vt -0.060953 -0.072076 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.399410 0.529471 +vt 0.375000 0.531250 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt -0.060953 -0.072076 +vt -0.060953 -0.072076 +vt 0.000000 0.000000 +vt 0.734375 0.500000 +vt 0.618288 0.500000 +vt 0.000000 0.000000 +vt -0.082886 -0.098011 +vt 0.000000 0.000000 +vt 0.598153 0.500000 +vt 0.571643 0.613288 +vt 0.573160 0.570629 +vt 0.608050 0.683263 +vt 0.608249 0.700317 +vt 0.569497 0.673624 +vt 0.569778 0.665715 +vt 0.571361 0.621217 +vt 0.618006 0.614232 +vt 0.619267 0.625660 +vt 0.569575 0.671432 +vt 0.609106 0.677838 +vt 0.610496 0.670701 +vt 0.612853 0.567544 +vt 0.617393 0.608686 +vt 0.610496 0.670701 +vt 0.609106 0.677838 +vt 0.612431 0.563719 +vt 0.612853 0.567544 +vt 0.569575 0.671432 +vt 0.569778 0.665715 +vt 0.571361 0.621217 +vt 0.571643 0.613288 +vt 0.617393 0.608686 +vt 0.618006 0.614232 +vt 0.573160 0.570629 +vt 0.573364 0.564889 +vt 0.541659 0.750000 +vt 0.458317 0.750000 +vt 0.375000 0.750000 +vt 0.375000 0.750000 +vt 0.375000 0.687500 +vt 0.456448 0.697681 +vt 0.600988 0.750000 +vt 0.444928 0.511667 +vt 0.000000 0.000000 +vt 0.587121 0.675189 +vt 0.608270 0.875000 +vt 0.600988 0.750000 +vt 0.619949 0.750000 +vt 0.623082 0.875000 +vt 0.444928 0.511667 +vt 0.576437 0.712680 +vt 0.614785 0.717473 +vt 0.587121 0.675189 +vt 1.000000 0.500000 +vt 0.968750 0.500000 +vt 0.968750 1.000000 +vt 1.000000 1.000000 +vt 0.937500 0.500000 +vt 0.937500 1.000000 +vt 0.906250 0.500000 +vt 0.906250 1.000000 +vt 0.875000 0.500000 +vt 0.875000 1.000000 +vt 0.843750 0.500000 +vt 0.843750 1.000000 +vt 0.812500 0.500000 +vt 0.812500 1.000000 +vt 0.781250 0.500000 +vt 0.781250 1.000000 +vt 0.750000 0.500000 +vt 0.750000 1.000000 +vt 0.718750 0.500000 +vt 0.718750 1.000000 +vt 0.687500 0.500000 +vt 0.687500 1.000000 +vt 0.656250 0.500000 +vt 0.656250 1.000000 +vt 0.625000 0.500000 +vt 0.625000 1.000000 +vt 0.593750 0.500000 +vt 0.593750 1.000000 +vt 0.562500 0.500000 +vt 0.562500 1.000000 +vt 0.531250 0.500000 +vt 0.531250 1.000000 +vt 0.500000 0.500000 +vt 0.500000 1.000000 +vt 0.468750 0.500000 +vt 0.468750 1.000000 +vt 0.437500 0.500000 +vt 0.437500 1.000000 +vt 0.406250 0.500000 +vt 0.406250 1.000000 +vt 0.375000 0.500000 +vt 0.375000 1.000000 +vt 0.343750 0.500000 +vt 0.343750 1.000000 +vt 0.312500 0.500000 +vt 0.312500 1.000000 +vt 0.281250 0.500000 +vt 0.281250 1.000000 +vt 0.250000 0.500000 +vt 0.250000 1.000000 +vt 0.218750 0.500000 +vt 0.218750 1.000000 +vt 0.187500 0.500000 +vt 0.187500 1.000000 +vt 0.156250 0.500000 +vt 0.156250 1.000000 +vt 0.125000 0.500000 +vt 0.125000 1.000000 +vt 0.093750 0.500000 +vt 0.093750 1.000000 +vt 0.062500 0.500000 +vt 0.062500 1.000000 +vt 0.296822 0.485388 +vt 0.341844 0.471731 +vt 0.383337 0.449553 +vt 0.419706 0.419706 +vt 0.449553 0.383337 +vt 0.471731 0.341844 +vt 0.485388 0.296822 +vt 0.490000 0.250000 +vt 0.485388 0.203178 +vt 0.471731 0.158156 +vt 0.449553 0.116663 +vt 0.419706 0.080294 +vt 0.383337 0.050447 +vt 0.341844 0.028269 +vt 0.296822 0.014612 +vt 0.250000 0.010000 +vt 0.203178 0.014612 +vt 0.158156 0.028269 +vt 0.116663 0.050447 +vt 0.080294 0.080294 +vt 0.050447 0.116663 +vt 0.028269 0.158156 +vt 0.014611 0.203179 +vt 0.010000 0.250000 +vt 0.014612 0.296822 +vt 0.028269 0.341844 +vt 0.050447 0.383337 +vt 0.080295 0.419706 +vt 0.116663 0.449553 +vt 0.158156 0.471731 +vt 0.203179 0.485389 +vt 0.250000 0.490000 +vt 0.031250 0.500000 +vt 0.031250 1.000000 +vt 0.000000 0.500000 +vt 0.000000 1.000000 +vt 0.750000 0.490000 +vt 0.703179 0.485389 +vt 0.658156 0.471731 +vt 0.616663 0.449553 +vt 0.580295 0.419706 +vt 0.550447 0.383337 +vt 0.528269 0.341844 +vt 0.514612 0.296822 +vt 0.510000 0.250000 +vt 0.514611 0.203179 +vt 0.528269 0.158156 +vt 0.550447 0.116663 +vt 0.580294 0.080294 +vt 0.616663 0.050447 +vt 0.658156 0.028269 +vt 0.703178 0.014612 +vt 0.750000 0.010000 +vt 0.796822 0.014612 +vt 0.841844 0.028269 +vt 0.883337 0.050447 +vt 0.919706 0.080294 +vt 0.949553 0.116663 +vt 0.971731 0.158156 +vt 0.985388 0.203178 +vt 0.990000 0.250000 +vt 0.985388 0.296822 +vt 0.971731 0.341844 +vt 0.949553 0.383337 +vt 0.919706 0.419706 +vt 0.883337 0.449553 +vt 0.841844 0.471731 +vt 0.796822 0.485388 +vt 0.634667 0.627655 +vt 0.740255 0.716823 +vt 0.627717 0.628001 +vt 0.631519 0.684809 +vt 0.631519 0.684809 +vt 0.627717 0.628001 +vt 0.634667 0.627655 +vt 0.740255 0.716823 +vt 0.614933 0.500000 +vt 0.614933 0.500000 +vt 0.614933 0.500000 +vt 0.726562 0.500000 +vt 0.618288 0.500000 +vt 0.618288 0.500000 +vt 0.250000 0.687500 +vt 0.375000 0.687500 +vt 0.250000 0.750000 +vt 0.375000 0.625084 +vt 0.428363 0.640586 +vt 0.528979 0.677861 +vt 0.559197 0.708128 +vt 0.450382 0.715365 +vt 0.375000 0.685311 +vt 0.375000 0.531250 +vt 0.439201 0.526572 +vt 0.513412 0.534872 +vt 0.506006 0.552334 +vt 0.431812 0.561420 +vt 0.375000 0.562425 +vt 0.428363 0.640586 +vt 0.528979 0.677861 +vt 0.375000 0.625084 +vt 0.456448 0.697681 +vt 0.456448 0.697681 +vt 0.431812 0.561420 +vt 0.375000 0.562425 +vt 0.450382 0.715365 +vt 0.375000 0.685311 +vt 0.506006 0.552334 +vt 0.513412 0.534872 +vt 0.375000 0.687500 +vt 0.559197 0.708128 +vt 0.375000 0.625000 +vt 0.375000 0.562500 +vt 0.375000 0.562500 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.399847 0.589331 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.410228 0.500000 +vt 0.375000 0.500000 +vt 0.375000 0.500000 +vt 0.410228 0.500000 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt 0.250000 0.500000 +vt 0.375000 0.531250 +vt 0.250000 0.531250 +vt 0.500000 0.500000 +vt 0.517614 0.500000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.571307 0.500000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt 0.399410 0.529471 +vt 0.410228 0.500000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.375000 0.750000 +vt 0.375000 0.687500 +vt 0.458317 0.750000 +vt 0.375000 0.687500 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.375000 0.687500 +vt 0.375000 0.625084 +vt 0.375000 0.685311 +vt 0.450382 0.715365 +vt 0.559197 0.708128 +vt 0.528979 0.677861 +vt 0.428363 0.640586 +vt 0.375000 0.531250 +vt 0.375000 0.562425 +vt 0.431812 0.561420 +vt 0.506006 0.552334 +vt 0.513412 0.534872 +vt 0.439201 0.526572 +vt 0.528979 0.677861 +vt 0.428363 0.640586 +vt 0.375000 0.625084 +vt 0.456448 0.697681 +vt 0.456448 0.697681 +vt 0.375000 0.562425 +vt 0.431812 0.561420 +vt 0.375000 0.685311 +vt 0.450382 0.715365 +vt 0.506006 0.552334 +vt 0.513412 0.534872 +vt 0.375000 0.687500 +vt 0.559197 0.708128 +vt 0.375000 0.625000 +vt 0.375000 0.562500 +vt 0.375000 0.562500 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.399847 0.589331 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.410228 0.500000 +vt 0.375000 0.500000 +vt 0.375000 0.500000 +vt 0.410228 0.500000 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt 0.375000 0.531250 +vt 0.517614 0.500000 +vt 0.000000 0.000000 +vt 0.571307 0.500000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt -0.060953 -0.072076 +vt 0.399410 0.529471 +vt 0.410228 0.500000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.375000 0.750000 +vt 0.458317 0.750000 +vt 0.375000 0.687500 +vt 0.375000 0.687500 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.250000 0.562500 +vt 0.250000 0.625000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.906250 0.500000 +vt 0.906250 1.000000 +vt 0.875000 1.000000 +vt 0.875000 0.500000 +vt 0.296822 0.485388 +vt 0.250000 0.490000 +vt 0.203179 0.485389 +vt 0.158156 0.471731 +vt 0.116663 0.449553 +vt 0.080295 0.419706 +vt 0.050447 0.383337 +vt 0.028269 0.341844 +vt 0.014612 0.296822 +vt 0.010000 0.250000 +vt 0.014611 0.203179 +vt 0.028269 0.158156 +vt 0.050447 0.116663 +vt 0.080294 0.080294 +vt 0.116663 0.050447 +vt 0.158156 0.028269 +vt 0.203178 0.014612 +vt 0.250000 0.010000 +vt 0.296822 0.014612 +vt 0.341844 0.028269 +vt 0.383337 0.050447 +vt 0.419706 0.080294 +vt 0.449553 0.116663 +vt 0.471731 0.158156 +vt 0.485388 0.203178 +vt 0.490000 0.250000 +vt 0.485388 0.296822 +vt 0.471731 0.341844 +vt 0.449553 0.383337 +vt 0.419706 0.419706 +vt 0.383337 0.449553 +vt 0.341844 0.471731 +vt 0.750000 0.490000 +vt 0.796822 0.485388 +vt 0.841844 0.471731 +vt 0.883337 0.449553 +vt 0.919706 0.419706 +vt 0.949553 0.383337 +vt 0.971731 0.341844 +vt 0.985388 0.296822 +vt 0.990000 0.250000 +vt 0.985388 0.203178 +vt 0.971731 0.158156 +vt 0.949553 0.116663 +vt 0.919706 0.080294 +vt 0.883337 0.050447 +vt 0.841844 0.028269 +vt 0.796822 0.014612 +vt 0.750000 0.010000 +vt 0.703178 0.014612 +vt 0.658156 0.028269 +vt 0.616663 0.050447 +vt 0.580294 0.080294 +vt 0.550447 0.116663 +vt 0.528269 0.158156 +vt 0.514611 0.203179 +vt 0.510000 0.250000 +vt 0.514612 0.296822 +vt 0.528269 0.341844 +vt 0.550447 0.383337 +vt 0.580295 0.419706 +vt 0.616663 0.449553 +vt 0.658156 0.471731 +vt 0.703179 0.485389 +vt 0.093750 0.500000 +vt 0.093750 1.000000 +vt 0.062500 1.000000 +vt 0.062500 0.500000 +vt 0.843750 0.500000 +vt 0.843750 1.000000 +vt 0.812500 1.000000 +vt 0.812500 0.500000 +vt 0.125000 0.500000 +vt 0.125000 1.000000 +vt 0.781250 1.000000 +vt 0.781250 0.500000 +vt 0.156250 0.500000 +vt 0.156250 1.000000 +vt 0.750000 1.000000 +vt 0.750000 0.500000 +vt 0.187500 0.500000 +vt 0.187500 1.000000 +vt 0.718750 1.000000 +vt 0.718750 0.500000 +vt 0.218750 0.500000 +vt 0.218750 1.000000 +vt 0.687500 1.000000 +vt 0.687500 0.500000 +vt 0.250000 0.500000 +vt 0.250000 1.000000 +vt 0.656250 1.000000 +vt 0.656250 0.500000 +vt 0.281250 0.500000 +vt 0.281250 1.000000 +vt 0.625000 1.000000 +vt 0.625000 0.500000 +vt 0.312500 0.500000 +vt 0.312500 1.000000 +vt 0.593750 1.000000 +vt 0.593750 0.500000 +vt 0.343750 0.500000 +vt 0.343750 1.000000 +vt 0.562500 1.000000 +vt 0.562500 0.500000 +vt 0.375000 0.500000 +vt 0.375000 1.000000 +vt 0.531250 1.000000 +vt 0.531250 0.500000 +vt 0.406250 0.500000 +vt 0.406250 1.000000 +vt 0.500000 1.000000 +vt 0.500000 0.500000 +vt 0.437500 0.500000 +vt 0.437500 1.000000 +vt 0.468750 1.000000 +vt 0.468750 0.500000 +vt 0.468750 0.500000 +vt 0.468750 1.000000 +vt 0.437500 1.000000 +vt 0.437500 0.500000 +vt 0.500000 0.500000 +vt 0.500000 1.000000 +vt 0.406250 1.000000 +vt 0.406250 0.500000 +vt 0.531250 0.500000 +vt 0.531250 1.000000 +vt 0.375000 1.000000 +vt 0.375000 0.500000 +vt 0.562500 0.500000 +vt 0.562500 1.000000 +vt 0.343750 1.000000 +vt 0.343750 0.500000 +vt 0.593750 0.500000 +vt 0.593750 1.000000 +vt 0.312500 1.000000 +vt 0.312500 0.500000 +vt 0.625000 0.500000 +vt 0.625000 1.000000 +vt 0.281250 1.000000 +vt 0.281250 0.500000 +vt 0.656250 0.500000 +vt 0.656250 1.000000 +vt 0.250000 1.000000 +vt 0.250000 0.500000 +vt 0.687500 0.500000 +vt 0.687500 1.000000 +vt 0.218750 1.000000 +vt 0.218750 0.500000 +vt 0.718750 0.500000 +vt 0.718750 1.000000 +vt 0.187500 1.000000 +vt 0.187500 0.500000 +vt 0.750000 0.500000 +vt 0.750000 1.000000 +vt 0.156250 1.000000 +vt 0.156250 0.500000 +vt 0.781250 0.500000 +vt 0.781250 1.000000 +vt 0.125000 1.000000 +vt 0.125000 0.500000 +vt 0.812500 0.500000 +vt 0.812500 1.000000 +vt 0.093750 1.000000 +vt 0.093750 0.500000 +vt 0.843750 0.500000 +vt 0.843750 1.000000 +vt 0.062500 1.000000 +vt 0.062500 0.500000 +vt 0.875000 0.500000 +vt 0.875000 1.000000 +vt 0.296822 0.485388 +vt 0.250000 0.490000 +vt 0.203179 0.485389 +vt 0.158156 0.471731 +vt 0.116663 0.449553 +vt 0.080295 0.419706 +vt 0.050447 0.383337 +vt 0.028269 0.341844 +vt 0.014612 0.296822 +vt 0.010000 0.250000 +vt 0.014611 0.203179 +vt 0.028269 0.158156 +vt 0.050447 0.116663 +vt 0.080294 0.080294 +vt 0.116663 0.050447 +vt 0.158156 0.028269 +vt 0.203178 0.014612 +vt 0.250000 0.010000 +vt 0.296822 0.014612 +vt 0.341844 0.028269 +vt 0.383337 0.050447 +vt 0.419706 0.080294 +vt 0.449553 0.116663 +vt 0.471731 0.158156 +vt 0.485388 0.203178 +vt 0.490000 0.250000 +vt 0.485388 0.296822 +vt 0.471731 0.341844 +vt 0.449553 0.383337 +vt 0.419706 0.419706 +vt 0.383337 0.449553 +vt 0.341844 0.471731 +vt 0.906250 0.500000 +vt 0.906250 1.000000 +vt 0.750000 0.490000 +vt 0.796822 0.485388 +vt 0.841844 0.471731 +vt 0.883337 0.449553 +vt 0.919706 0.419706 +vt 0.949553 0.383337 +vt 0.971731 0.341844 +vt 0.985388 0.296822 +vt 0.990000 0.250000 +vt 0.985388 0.203178 +vt 0.971731 0.158156 +vt 0.949553 0.116663 +vt 0.919706 0.080294 +vt 0.883337 0.050447 +vt 0.841844 0.028269 +vt 0.796822 0.014612 +vt 0.750000 0.010000 +vt 0.703178 0.014612 +vt 0.658156 0.028269 +vt 0.616663 0.050447 +vt 0.580294 0.080294 +vt 0.550447 0.116663 +vt 0.528269 0.158156 +vt 0.514611 0.203179 +vt 0.510000 0.250000 +vt 0.514612 0.296822 +vt 0.528269 0.341844 +vt 0.550447 0.383337 +vt 0.580295 0.419706 +vt 0.616663 0.449553 +vt 0.658156 0.471731 +vt 0.703179 0.485389 +vt 0.937500 0.500000 +vt 0.937500 1.000000 +vt 0.031250 0.500000 +vt 0.031250 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.500000 +vt 0.968750 0.500000 +vt 0.968750 1.000000 +vt 1.000000 0.500000 +vt 1.000000 1.000000 +vt 0.937500 0.500000 +vt 0.937500 1.000000 +vt 0.031250 0.500000 +vt 0.031250 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.500000 +vt 0.968750 0.500000 +vt 0.968750 1.000000 +vt 1.000000 0.500000 +vt 1.000000 1.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.906250 0.500000 +vt 0.875000 0.500000 +vt 0.875000 1.000000 +vt 0.906250 1.000000 +vt 0.296822 0.485388 +vt 0.341844 0.471731 +vt 0.383337 0.449553 +vt 0.419706 0.419706 +vt 0.449553 0.383337 +vt 0.471731 0.341844 +vt 0.485388 0.296822 +vt 0.490000 0.250000 +vt 0.485388 0.203178 +vt 0.471731 0.158156 +vt 0.449553 0.116663 +vt 0.419706 0.080294 +vt 0.383337 0.050447 +vt 0.341844 0.028269 +vt 0.296822 0.014612 +vt 0.250000 0.010000 +vt 0.203178 0.014612 +vt 0.158156 0.028269 +vt 0.116663 0.050447 +vt 0.080294 0.080294 +vt 0.050447 0.116663 +vt 0.028269 0.158156 +vt 0.014611 0.203179 +vt 0.010000 0.250000 +vt 0.014612 0.296822 +vt 0.028269 0.341844 +vt 0.050447 0.383337 +vt 0.080295 0.419706 +vt 0.116663 0.449553 +vt 0.158156 0.471731 +vt 0.203179 0.485389 +vt 0.250000 0.490000 +vt 0.750000 0.490000 +vt 0.703179 0.485389 +vt 0.658156 0.471731 +vt 0.616663 0.449553 +vt 0.580295 0.419706 +vt 0.550447 0.383337 +vt 0.528269 0.341844 +vt 0.514612 0.296822 +vt 0.510000 0.250000 +vt 0.514611 0.203179 +vt 0.528269 0.158156 +vt 0.550447 0.116663 +vt 0.580294 0.080294 +vt 0.616663 0.050447 +vt 0.658156 0.028269 +vt 0.703178 0.014612 +vt 0.750000 0.010000 +vt 0.796822 0.014612 +vt 0.841844 0.028269 +vt 0.883337 0.050447 +vt 0.919706 0.080294 +vt 0.949553 0.116663 +vt 0.971731 0.158156 +vt 0.985388 0.203178 +vt 0.990000 0.250000 +vt 0.985388 0.296822 +vt 0.971731 0.341844 +vt 0.949553 0.383337 +vt 0.919706 0.419706 +vt 0.883337 0.449553 +vt 0.841844 0.471731 +vt 0.796822 0.485388 +vt 0.093750 0.500000 +vt 0.062500 0.500000 +vt 0.062500 1.000000 +vt 0.093750 1.000000 +vt 0.843750 0.500000 +vt 0.812500 0.500000 +vt 0.812500 1.000000 +vt 0.843750 1.000000 +vt 0.125000 0.500000 +vt 0.125000 1.000000 +vt 0.781250 0.500000 +vt 0.781250 1.000000 +vt 0.156250 0.500000 +vt 0.156250 1.000000 +vt 0.750000 0.500000 +vt 0.750000 1.000000 +vt 0.187500 0.500000 +vt 0.187500 1.000000 +vt 0.718750 0.500000 +vt 0.718750 1.000000 +vt 0.218750 0.500000 +vt 0.218750 1.000000 +vt 0.687500 0.500000 +vt 0.687500 1.000000 +vt 0.250000 0.500000 +vt 0.250000 1.000000 +vt 0.656250 0.500000 +vt 0.656250 1.000000 +vt 0.281250 0.500000 +vt 0.281250 1.000000 +vt 0.625000 0.500000 +vt 0.625000 1.000000 +vt 0.312500 0.500000 +vt 0.312500 1.000000 +vt 0.593750 0.500000 +vt 0.593750 1.000000 +vt 0.343750 0.500000 +vt 0.343750 1.000000 +vt 0.562500 0.500000 +vt 0.562500 1.000000 +vt 0.375000 0.500000 +vt 0.375000 1.000000 +vt 0.531250 0.500000 +vt 0.531250 1.000000 +vt 0.406250 0.500000 +vt 0.406250 1.000000 +vt 0.500000 0.500000 +vt 0.500000 1.000000 +vt 0.437500 0.500000 +vt 0.437500 1.000000 +vt 0.468750 0.500000 +vt 0.468750 1.000000 +vt 0.468750 0.500000 +vt 0.468750 1.000000 +vt 0.437500 0.500000 +vt 0.437500 1.000000 +vt 0.500000 0.500000 +vt 0.500000 1.000000 +vt 0.406250 0.500000 +vt 0.406250 1.000000 +vt 0.531250 0.500000 +vt 0.531250 1.000000 +vt 0.375000 0.500000 +vt 0.375000 1.000000 +vt 0.562500 0.500000 +vt 0.562500 1.000000 +vt 0.343750 0.500000 +vt 0.343750 1.000000 +vt 0.593750 0.500000 +vt 0.593750 1.000000 +vt 0.312500 0.500000 +vt 0.312500 1.000000 +vt 0.625000 0.500000 +vt 0.625000 1.000000 +vt 0.281250 0.500000 +vt 0.281250 1.000000 +vt 0.656250 0.500000 +vt 0.656250 1.000000 +vt 0.250000 0.500000 +vt 0.250000 1.000000 +vt 0.687500 0.500000 +vt 0.687500 1.000000 +vt 0.218750 0.500000 +vt 0.218750 1.000000 +vt 0.718750 0.500000 +vt 0.718750 1.000000 +vt 0.187500 0.500000 +vt 0.187500 1.000000 +vt 0.750000 0.500000 +vt 0.750000 1.000000 +vt 0.156250 0.500000 +vt 0.156250 1.000000 +vt 0.781250 0.500000 +vt 0.781250 1.000000 +vt 0.125000 0.500000 +vt 0.125000 1.000000 +vt 0.812500 0.500000 +vt 0.812500 1.000000 +vt 0.093750 0.500000 +vt 0.093750 1.000000 +vt 0.843750 0.500000 +vt 0.843750 1.000000 +vt 0.062500 0.500000 +vt 0.062500 1.000000 +vt 0.875000 0.500000 +vt 0.875000 1.000000 +vt 0.296822 0.485388 +vt 0.341844 0.471731 +vt 0.383337 0.449553 +vt 0.419706 0.419706 +vt 0.449553 0.383337 +vt 0.471731 0.341844 +vt 0.485388 0.296822 +vt 0.490000 0.250000 +vt 0.485388 0.203178 +vt 0.471731 0.158156 +vt 0.449553 0.116663 +vt 0.419706 0.080294 +vt 0.383337 0.050447 +vt 0.341844 0.028269 +vt 0.296822 0.014612 +vt 0.250000 0.010000 +vt 0.203178 0.014612 +vt 0.158156 0.028269 +vt 0.116663 0.050447 +vt 0.080294 0.080294 +vt 0.050447 0.116663 +vt 0.028269 0.158156 +vt 0.014611 0.203179 +vt 0.010000 0.250000 +vt 0.014612 0.296822 +vt 0.028269 0.341844 +vt 0.050447 0.383337 +vt 0.080295 0.419706 +vt 0.116663 0.449553 +vt 0.158156 0.471731 +vt 0.203179 0.485389 +vt 0.250000 0.490000 +vt 0.906250 0.500000 +vt 0.906250 1.000000 +vt 0.750000 0.490000 +vt 0.703179 0.485389 +vt 0.658156 0.471731 +vt 0.616663 0.449553 +vt 0.580295 0.419706 +vt 0.550447 0.383337 +vt 0.528269 0.341844 +vt 0.514612 0.296822 +vt 0.510000 0.250000 +vt 0.514611 0.203179 +vt 0.528269 0.158156 +vt 0.550447 0.116663 +vt 0.580294 0.080294 +vt 0.616663 0.050447 +vt 0.658156 0.028269 +vt 0.703178 0.014612 +vt 0.750000 0.010000 +vt 0.796822 0.014612 +vt 0.841844 0.028269 +vt 0.883337 0.050447 +vt 0.919706 0.080294 +vt 0.949553 0.116663 +vt 0.971731 0.158156 +vt 0.985388 0.203178 +vt 0.990000 0.250000 +vt 0.985388 0.296822 +vt 0.971731 0.341844 +vt 0.949553 0.383337 +vt 0.919706 0.419706 +vt 0.883337 0.449553 +vt 0.841844 0.471731 +vt 0.796822 0.485388 +vt 0.937500 0.500000 +vt 0.937500 1.000000 +vt 0.031250 0.500000 +vt 0.000000 0.500000 +vt 0.000000 1.000000 +vt 0.031250 1.000000 +vt 0.968750 0.500000 +vt 0.968750 1.000000 +vt 1.000000 0.500000 +vt 1.000000 1.000000 +vt 0.937500 0.500000 +vt 0.937500 1.000000 +vt 0.031250 0.500000 +vt 0.000000 0.500000 +vt 0.000000 1.000000 +vt 0.031250 1.000000 +vt 0.968750 0.500000 +vt 0.968750 1.000000 +vt 1.000000 0.500000 +vt 1.000000 1.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vt 0.000000 0.000000 +vn 0.0000 0.9942 -0.1078 +vn 0.0000 0.9400 0.3411 +vn -0.0000 0.3039 -0.9527 +vn 0.0000 0.9897 -0.1431 +vn 0.0000 0.9890 -0.1476 +vn -0.1218 -0.9925 -0.0071 +vn 0.9589 0.2836 0.0128 +vn 0.9551 0.2959 0.0128 +vn 0.9456 0.3249 0.0160 +vn 0.0009 -0.1780 0.9840 +vn -0.0021 -0.0952 -0.9955 +vn 0.9601 0.2794 0.0138 +vn 0.9999 0.0009 0.0161 +vn 0.9997 0.0252 0.0033 +vn 0.0032 -0.0086 -1.0000 +vn 0.9703 -0.2418 -0.0000 +vn 0.0000 -1.0000 0.0004 +vn 0.0004 0.0103 0.9999 +vn 0.4967 0.0849 -0.8638 +vn 0.9997 0.0248 0.0004 +vn 1.0000 0.0000 0.0000 +vn 0.0000 -0.9875 -0.1575 +vn 0.0000 0.0000 1.0000 +vn 1.0000 -0.0000 0.0002 +vn -1.0000 -0.0000 0.0000 +vn 0.0000 -0.9871 0.1602 +vn -0.0000 -0.9964 -0.0850 +vn 0.0001 -0.9875 -0.1575 +vn 0.0000 -0.9993 -0.0386 +vn -0.2806 0.9581 0.0572 +vn 0.2683 -0.9037 -0.3338 +vn -0.2805 0.9572 0.0719 +vn 0.2766 -0.9529 0.1246 +vn 0.2692 -0.9070 -0.3238 +vn 0.2713 -0.9064 -0.3238 +vn 0.2789 -0.9522 0.1246 +vn -0.2828 0.9575 0.0571 +vn 0.0081 -0.0286 0.9996 +vn -0.9985 0.0027 -0.0554 +vn 0.5899 -0.0526 0.8058 +vn 0.6301 -0.1095 0.7687 +vn 0.0003 0.9911 0.1330 +vn 0.0003 -0.0991 0.9951 +vn -0.0001 -0.9911 -0.1331 +vn -0.0679 0.9854 0.1561 +vn -0.9446 -0.0279 0.3272 +vn 0.1226 -0.9770 -0.1742 +vn 0.0000 -0.0980 -0.9952 +vn 0.0000 -0.2903 -0.9569 +vn 0.0000 -0.4714 -0.8819 +vn 0.0000 -0.6344 -0.7730 +vn 0.0000 -0.7730 -0.6344 +vn 0.0000 -0.8819 -0.4714 +vn 0.0000 -0.9569 -0.2903 +vn 0.0000 -0.9952 -0.0980 +vn 0.0000 -0.9952 0.0980 +vn 0.0000 -0.9569 0.2903 +vn 0.0000 -0.8819 0.4714 +vn 0.0000 -0.7730 0.6344 +vn 0.0000 -0.6344 0.7730 +vn 0.0000 -0.4714 0.8819 +vn 0.0000 -0.2903 0.9569 +vn 0.0000 -0.0980 0.9952 +vn -0.0000 0.0980 0.9952 +vn 0.0000 0.2903 0.9569 +vn 0.0000 0.4714 0.8819 +vn 0.0000 0.6344 0.7730 +vn 0.0000 0.7730 0.6344 +vn 0.0000 0.8819 0.4714 +vn 0.0000 0.9569 0.2903 +vn 0.0000 0.9952 0.0980 +vn 0.0000 0.9952 -0.0980 +vn 0.0000 0.9569 -0.2903 +vn 0.0000 0.8819 -0.4714 +vn -0.0000 0.7730 -0.6344 +vn -0.0000 0.6344 -0.7730 +vn 0.0000 0.4714 -0.8819 +vn 0.0000 0.2903 -0.9569 +vn 0.0000 0.0980 -0.9952 +vn 0.0005 0.9512 0.3085 +vn 0.0005 0.9450 0.3272 +vn -0.0225 0.9557 0.2934 +vn -0.0037 0.9452 0.3264 +vn 0.0007 0.9452 0.3265 +vn 0.0011 0.9478 0.3189 +vn -0.9975 -0.0266 0.0661 +vn 0.0000 -0.3039 0.9527 +vn -0.9969 -0.0288 0.0731 +vn 0.0000 -0.1554 -0.9879 +vn -0.0000 -0.1595 -0.9872 +vn -0.0000 0.9871 -0.1602 +vn 0.0000 -0.1602 -0.9871 +vn 0.0000 0.1602 0.9871 +vn 0.1218 -0.9925 -0.0071 +vn -0.9589 0.2836 0.0128 +vn -0.9551 0.2959 0.0128 +vn -0.9456 0.3249 0.0160 +vn -0.0009 -0.1780 0.9840 +vn 0.0021 -0.0952 -0.9955 +vn -0.9601 0.2794 0.0138 +vn -0.9999 0.0009 0.0161 +vn -0.9997 0.0252 0.0033 +vn -0.0032 -0.0086 -1.0000 +vn -0.9703 -0.2418 -0.0000 +vn -0.0004 0.0103 0.9999 +vn -0.4967 0.0849 -0.8638 +vn -0.9997 0.0248 0.0004 +vn -1.0000 -0.0000 0.0002 +vn -0.0001 -0.9875 -0.1575 +vn 0.2806 0.9581 0.0572 +vn -0.2683 -0.9037 -0.3338 +vn 0.2805 0.9572 0.0719 +vn -0.2766 -0.9529 0.1246 +vn -0.2692 -0.9070 -0.3238 +vn -0.2713 -0.9064 -0.3238 +vn -0.2789 -0.9522 0.1246 +vn 0.2829 0.9575 0.0571 +vn 0.2828 0.9575 0.0571 +vn -0.0081 -0.0286 0.9996 +vn 0.9985 0.0027 -0.0554 +vn -0.5899 -0.0526 0.8058 +vn -0.6301 -0.1096 0.7687 +vn -0.0003 0.9911 0.1330 +vn -0.0003 -0.0991 0.9951 +vn 0.0001 -0.9911 -0.1331 +vn 0.0679 0.9854 0.1561 +vn 0.9446 -0.0279 0.3272 +vn -0.1226 -0.9770 -0.1742 +vn -0.0005 0.9512 0.3085 +vn -0.0005 0.9450 0.3272 +vn 0.0225 0.9557 0.2934 +vn 0.0037 0.9452 0.3264 +vn -0.0007 0.9452 0.3265 +vn -0.0011 0.9478 0.3189 +vn 0.9975 -0.0266 0.0661 +vn 0.9969 -0.0288 0.0731 +vn 0.6221 -0.1262 0.7727 +vn 0.0014 -0.2815 0.9595 +vn -0.6221 -0.1262 0.7727 +vn -0.0014 -0.2815 0.9595 +vn 0.0049 -0.9652 0.2613 +vn 0.0000 -0.5403 0.8415 +vn 0.0000 -0.0826 0.9966 +vn 0.0000 0.9975 -0.0701 +vn 0.0000 -0.0543 -0.9985 +vn 0.0000 0.0429 -0.9991 +vn 0.0000 -0.5892 -0.8080 +vn 0.0000 -0.9997 -0.0244 +vn 0.0000 -0.9936 0.1127 +vn 0.0000 -0.9995 -0.0306 +vn -0.0067 -0.9653 0.2610 +vn 0.0000 -0.5233 -0.8522 +vn 0.9881 0.0890 -0.1256 +vn 0.8631 0.2709 -0.4262 +vn 0.8464 0.5322 0.0192 +vn 0.8198 0.3038 0.4853 +vn 0.7057 -0.0297 0.7079 +vn 0.0003 -1.0000 0.0042 +vn 0.0025 -0.9998 -0.0221 +vn 0.7855 0.1270 0.6057 +vn 0.9488 0.2015 0.2431 +vn 0.8858 0.4639 0.0108 +vn 0.8470 0.3011 -0.4380 +vn 0.0387 0.9992 0.0071 +vn 0.0417 0.9991 0.0071 +vn 0.0000 -1.0000 -0.0030 +vn 1.0000 0.0006 0.0084 +vn 0.0000 -1.0000 -0.0015 +vn 0.0000 -0.1123 -0.9937 +vn 0.0000 -0.9442 -0.3293 +vn 0.0000 0.9956 0.0941 +vn 0.0000 -0.9435 -0.3313 +vn 0.0000 -0.0233 0.9997 +vn 0.0000 0.9954 0.0958 +vn -0.0000 -0.1121 -0.9937 +vn -0.0000 0.9956 0.0940 +vn -0.0000 -0.0313 -0.9995 +vn 0.0001 -0.9956 -0.0940 +vn 1.0000 0.0001 0.0004 +vn -0.0001 0.9956 0.0941 +vn -0.0001 0.9953 0.0968 +vn -0.0020 -0.0231 0.9997 +vn 0.0000 -0.5948 0.8038 +vn 0.0000 -0.1315 0.9913 +vn 0.0084 -0.0395 0.9992 +vn 0.0693 -0.1932 -0.9787 +vn -0.0181 0.0150 0.9997 +vn -0.0812 0.2349 0.9686 +vn -0.0690 0.1924 0.9789 +vn 0.9601 0.2794 0.0122 +vn 0.9572 0.2893 0.0121 +vn 0.9602 0.2790 0.0135 +vn 0.0398 -0.0904 -0.9951 +vn 0.0299 -0.1456 0.9889 +vn 0.0101 0.9986 -0.0516 +vn 0.5988 -0.0920 0.7956 +vn 0.4826 -0.1722 0.8588 +vn 0.1131 -0.9083 0.4027 +vn -0.0273 0.9949 -0.0971 +vn 0.0000 0.0426 -0.9991 +vn 0.9985 -0.0027 0.0554 +vn -0.0027 -0.9999 -0.0117 +vn -0.0073 0.2267 -0.9739 +vn 0.5826 -0.2972 -0.7565 +vn 0.5826 -0.6714 0.4581 +vn 0.5826 0.5960 0.5526 +vn 0.5826 0.4062 -0.7040 +vn 0.5826 -0.7767 -0.2393 +vn 0.5826 -0.0605 0.8105 +vn 0.5826 0.8037 -0.1214 +vn 0.9031 0.0320 -0.4283 +vn 0.9031 -0.4247 0.0642 +vn 0.9031 0.1571 0.3998 +vn 0.9031 0.3548 -0.2421 +vn 0.9031 -0.3150 -0.2921 +vn 0.9031 -0.2146 0.3721 +vn 0.9031 0.4105 0.1265 +vn -0.3821 0.1311 0.9148 +vn 0.6979 -0.3531 0.6231 +vn -0.3821 -0.1591 -0.9103 +vn -0.3821 0.5383 0.7511 +vn 0.6979 0.6861 0.2056 +vn -0.9751 -0.1823 0.1265 +vn -0.3821 -0.2516 0.8892 +vn -0.9751 0.1094 -0.1931 +vn -0.3821 0.7969 0.4678 +vn -0.9751 0.2192 -0.0349 +vn -0.3821 -0.8109 -0.4432 +vn 0.6979 -0.7073 0.1125 +vn -0.3821 0.2788 -0.8811 +vn -0.9751 -0.2126 -0.0637 +vn -0.9751 -0.0148 0.2214 +vn 0.6979 0.0477 -0.7146 +vn -0.3821 -0.6334 0.6729 +vn -0.3821 0.8626 -0.3314 +vn 0.6979 -0.5290 -0.4829 +vn -0.9751 -0.0827 -0.2059 +vn -0.3821 0.6125 -0.6920 +vn -0.3821 -0.8521 0.3577 +vn -0.9751 0.1639 0.1496 +vn 0.6979 0.5885 -0.4082 +vn -0.3821 -0.9210 -0.0757 +vn -0.3821 -0.5150 -0.7673 +vn 0.6979 0.2671 0.6646 +vn -0.3821 0.9229 0.0474 +vn 0.9031 -0.2146 0.3720 +vn -0.0049 -0.9652 0.2613 +vn 0.0067 -0.9653 0.2610 +vn -0.9881 0.0890 -0.1256 +vn -0.8631 0.2709 -0.4262 +vn -0.8464 0.5322 0.0192 +vn -0.8198 0.3038 0.4853 +vn -0.7057 -0.0297 0.7079 +vn -0.0003 -1.0000 0.0042 +vn -0.0025 -0.9998 -0.0221 +vn -0.7855 0.1270 0.6057 +vn -0.9488 0.2015 0.2431 +vn -0.8858 0.4639 0.0108 +vn -0.8471 0.3011 -0.4380 +vn -0.0387 0.9992 0.0071 +vn -0.0417 0.9991 0.0071 +vn -1.0000 0.0006 0.0084 +vn -0.0001 -0.9956 -0.0940 +vn -1.0000 0.0001 0.0004 +vn 0.0001 0.9956 0.0941 +vn 0.0001 0.9953 0.0968 +vn 0.0020 -0.0231 0.9997 +vn -0.0084 -0.0395 0.9992 +vn -0.0693 -0.1932 -0.9787 +vn 0.0181 0.0150 0.9997 +vn 0.0812 0.2349 0.9686 +vn 0.0690 0.1924 0.9789 +vn -0.9601 0.2794 0.0122 +vn -0.9572 0.2893 0.0121 +vn -0.9602 0.2790 0.0135 +vn -0.0398 -0.0904 -0.9951 +vn -0.0299 -0.1456 0.9889 +vn -0.0101 0.9986 -0.0516 +vn -0.5988 -0.0920 0.7956 +vn -0.4826 -0.1722 0.8588 +vn -0.1131 -0.9083 0.4027 +vn 0.0273 0.9949 -0.0971 +vn -0.9985 -0.0027 0.0554 +vn 0.0027 -0.9999 -0.0117 +vn 0.0073 0.2267 -0.9739 +vn -0.5826 -0.2972 -0.7565 +vn -0.5826 -0.6714 0.4581 +vn -0.5826 0.5960 0.5526 +vn -0.5826 0.4062 -0.7040 +vn -0.5826 -0.7767 -0.2393 +vn -0.5826 -0.0605 0.8105 +vn -0.5826 0.8037 -0.1214 +vn -0.9031 0.0320 -0.4283 +vn -0.9031 -0.4247 0.0642 +vn -0.9031 0.1571 0.3998 +vn -0.9031 0.3548 -0.2421 +vn -0.9031 -0.3150 -0.2921 +vn -0.9031 -0.2146 0.3721 +vn -0.9031 0.4105 0.1265 +vn 0.3821 0.1311 0.9148 +vn -0.6979 -0.3531 0.6231 +vn 0.3821 -0.1591 -0.9103 +vn 0.3821 0.5383 0.7511 +vn -0.6979 0.6861 0.2056 +vn 0.9751 -0.1823 0.1265 +vn 0.3821 -0.2516 0.8892 +vn 0.9751 0.1094 -0.1931 +vn 0.3821 0.7969 0.4678 +vn 0.9751 0.2192 -0.0349 +vn 0.3821 -0.8109 -0.4432 +vn -0.6979 -0.7073 0.1125 +vn 0.3821 0.2788 -0.8811 +vn 0.9751 -0.2126 -0.0637 +vn 0.9751 -0.0148 0.2214 +vn -0.6979 0.0477 -0.7146 +vn 0.3821 -0.6334 0.6729 +vn 0.3821 0.8626 -0.3314 +vn -0.6979 -0.5290 -0.4829 +vn 0.9751 -0.0827 -0.2059 +vn 0.3821 0.6125 -0.6920 +vn 0.3821 -0.8521 0.3577 +vn 0.9751 0.1639 0.1496 +vn -0.6979 0.5885 -0.4082 +vn 0.3821 -0.9210 -0.0757 +vn 0.3821 -0.5150 -0.7673 +vn -0.6979 0.2671 0.6646 +vn 0.3821 0.9229 0.0474 +vn -0.9031 -0.2146 0.3720 +vn 0.9590 0.2831 0.0119 +vn 0.9604 0.2784 0.0130 +vn -0.0052 0.9527 0.3039 +vn -0.9590 0.2831 0.0119 +vn -0.9604 0.2784 0.0130 +vn 0.0052 0.9527 0.3039 +vn 0.0000 -0.9995 0.0328 +vn 0.0000 -0.9983 -0.0591 +vn 0.0001 -1.0000 -0.0028 +vn 0.8784 -0.4215 0.2253 +vn 0.8784 0.4756 0.0468 +vn 0.8784 -0.4574 0.1387 +vn 0.8784 0.4574 0.1387 +vn 0.8784 -0.4756 0.0468 +vn 0.8784 0.4215 0.2253 +vn 0.8784 -0.4757 -0.0468 +vn 0.8784 0.3695 0.3032 +vn 0.8784 -0.4574 -0.1387 +vn 0.8784 0.3032 0.3695 +vn 0.8784 -0.4215 -0.2253 +vn 0.8784 0.2253 0.4215 +vn 0.8784 0.0468 -0.4756 +vn 0.8784 -0.3695 -0.3032 +vn 0.8784 0.1387 0.4574 +vn 0.8784 0.1387 -0.4574 +vn 0.8784 -0.3032 -0.3695 +vn 0.8784 0.0468 0.4757 +vn 0.8784 0.2253 -0.4215 +vn 0.8784 -0.2253 -0.4215 +vn 0.8784 -0.0468 0.4757 +vn 0.8784 0.3032 -0.3695 +vn 0.8784 -0.1387 -0.4574 +vn 0.8784 -0.1387 0.4574 +vn 0.8784 0.3695 -0.3032 +vn 0.8784 -0.0468 -0.4757 +vn 0.8784 -0.2253 0.4215 +vn 0.8784 0.4215 -0.2253 +vn 0.8784 -0.3032 0.3695 +vn 0.8784 0.4574 -0.1387 +vn 0.8784 -0.3695 0.3032 +vn 0.8784 0.4757 -0.0468 +vn 0.9481 0.0312 -0.3164 +vn 0.9481 -0.2017 0.2458 +vn 0.9481 0.0923 0.3043 +vn 0.9481 0.0923 -0.3043 +vn 0.9481 -0.2458 0.2017 +vn 0.9481 0.0312 0.3164 +vn 0.9481 0.1499 -0.2804 +vn 0.9481 -0.2804 0.1499 +vn 0.9481 0.2017 -0.2458 +vn 0.9481 -0.3043 0.0923 +vn 0.9481 0.2458 -0.2017 +vn 0.9481 -0.3164 0.0312 +vn 0.9481 0.2804 -0.1499 +vn 0.9481 -0.3164 -0.0312 +vn 0.9481 0.3043 -0.0923 +vn 0.9481 -0.3043 -0.0923 +vn 0.9481 0.3164 -0.0312 +vn 0.9481 -0.2804 -0.1499 +vn 0.9481 0.3164 0.0312 +vn 0.9481 -0.2458 -0.2017 +vn 0.9481 0.3043 0.0923 +vn 0.9481 -0.2017 -0.2458 +vn 0.9481 0.2804 0.1499 +vn 0.9481 -0.1499 -0.2804 +vn 0.9481 -0.0312 0.3164 +vn 0.9481 0.2458 0.2017 +vn 0.9481 -0.0923 -0.3043 +vn 0.9481 -0.0923 0.3043 +vn 0.9481 0.2017 0.2458 +vn 0.9481 -0.0312 -0.3164 +vn 0.9481 -0.1499 0.2804 +vn 0.9481 0.1499 0.2804 +vn 0.9938 0.0705 -0.0860 +vn 0.9938 -0.1064 0.0323 +vn 0.9938 0.0860 -0.0705 +vn 0.9938 -0.1107 0.0109 +vn 0.9938 0.0981 -0.0524 +vn 0.9938 -0.1107 -0.0109 +vn 0.9938 0.1064 -0.0323 +vn 0.9938 -0.1064 -0.0323 +vn 0.9938 0.1107 -0.0109 +vn 0.9938 -0.0981 -0.0524 +vn 0.9938 0.1107 0.0109 +vn 0.9938 -0.0860 -0.0705 +vn 0.9938 0.1064 0.0323 +vn 0.9938 -0.0705 -0.0860 +vn 0.9938 0.0981 0.0524 +vn 0.9938 -0.0524 -0.0981 +vn 0.9938 -0.0109 0.1107 +vn 0.9938 0.0860 0.0705 +vn 0.9938 -0.0323 -0.1064 +vn 0.9938 -0.0323 0.1064 +vn 0.9938 0.0705 0.0860 +vn 0.9938 -0.0109 -0.1107 +vn 0.9938 -0.0524 0.0981 +vn 0.9938 0.0524 0.0981 +vn 0.9938 0.0109 -0.1107 +vn 0.9938 -0.0705 0.0860 +vn 0.9938 0.0323 0.1064 +vn 0.9938 0.0323 -0.1064 +vn 0.9938 -0.0860 0.0705 +vn 0.9938 0.0109 0.1107 +vn 0.9938 0.0524 -0.0981 +vn 0.9938 -0.0981 0.0524 +vn 0.8784 0.4757 0.0468 +vn 0.8784 -0.4757 0.0468 +vn -0.9343 -0.1035 0.3413 +vn -0.9343 0.2757 -0.2262 +vn -0.9343 -0.0350 -0.3549 +vn -0.9343 -0.1681 0.3145 +vn -0.9343 0.3145 -0.1681 +vn -0.9343 -0.2262 0.2757 +vn -0.9343 0.3413 -0.1035 +vn -0.9343 -0.2757 0.2262 +vn -0.9343 0.3549 -0.0350 +vn -0.9343 -0.3145 0.1681 +vn -0.9343 0.3549 0.0350 +vn -0.9343 -0.3413 0.1035 +vn -0.9343 0.3413 0.1035 +vn -0.9343 -0.3549 0.0350 +vn -0.9343 0.3145 0.1681 +vn -0.9343 -0.3549 -0.0350 +vn -0.9343 0.2757 0.2262 +vn -0.9343 -0.3413 -0.1035 +vn -0.9343 0.2262 0.2757 +vn -0.9343 -0.3145 -0.1681 +vn -0.9343 0.1681 0.3145 +vn -0.9343 0.0350 -0.3549 +vn -0.9343 -0.2757 -0.2262 +vn -0.9343 0.1035 0.3413 +vn -0.9343 0.1035 -0.3413 +vn -0.9343 -0.2262 -0.2757 +vn -0.9343 0.0350 0.3549 +vn -0.9343 0.1681 -0.3145 +vn -0.9343 -0.1681 -0.3145 +vn -0.9343 -0.0350 0.3549 +vn -0.9343 0.2262 -0.2757 +vn -0.9343 -0.1035 -0.3413 +vn -0.9343 -0.3547 -0.0349 +vn -0.9343 0.2755 0.2261 +vn -0.9343 -0.3410 -0.1035 +vn -0.9343 0.2261 0.2755 +vn -0.9343 -0.3143 -0.1680 +vn -0.9343 0.1680 0.3143 +vn -0.9343 0.0349 -0.3547 +vn -0.9343 -0.2755 -0.2261 +vn -0.9343 0.1035 0.3410 +vn -0.9343 0.1035 -0.3410 +vn -0.9343 -0.2261 -0.2755 +vn -0.9343 0.0349 0.3547 +vn -0.9343 0.1680 -0.3143 +vn -0.9343 -0.1680 -0.3143 +vn -0.9343 -0.0349 0.3547 +vn -0.9343 0.2261 -0.2755 +vn -0.9343 -0.1034 -0.3410 +vn -0.9343 -0.1034 0.3410 +vn -0.9343 0.2755 -0.2261 +vn -0.9343 -0.0349 -0.3547 +vn -0.9343 -0.1680 0.3143 +vn -0.9343 0.3143 -0.1680 +vn -0.9343 -0.2261 0.2755 +vn -0.9343 0.3410 -0.1035 +vn -0.9343 -0.2755 0.2261 +vn -0.9343 0.3547 -0.0349 +vn -0.9343 -0.3143 0.1680 +vn -0.9343 0.3547 0.0349 +vn -0.9343 -0.3410 0.1035 +vn -0.9343 0.3410 0.1035 +vn -0.9343 -0.3547 0.0349 +vn -0.9343 0.3143 0.1680 +vn -0.0001 -1.0000 -0.0028 +vn -0.8784 -0.4215 0.2253 +vn -0.8784 0.4756 0.0468 +vn -0.8784 -0.4574 0.1387 +vn -0.8784 0.4574 0.1387 +vn -0.8784 -0.4756 0.0468 +vn -0.8784 0.4215 0.2253 +vn -0.8784 -0.4757 -0.0468 +vn -0.8784 0.3695 0.3032 +vn -0.8784 -0.4574 -0.1387 +vn -0.8784 0.3032 0.3695 +vn -0.8784 -0.4215 -0.2253 +vn -0.8784 0.2253 0.4215 +vn -0.8784 0.0468 -0.4757 +vn -0.8784 -0.3695 -0.3032 +vn -0.8784 0.1387 0.4574 +vn -0.8784 0.1387 -0.4574 +vn -0.8784 -0.3032 -0.3695 +vn -0.8784 0.0468 0.4757 +vn -0.8784 0.2253 -0.4215 +vn -0.8784 -0.2253 -0.4215 +vn -0.8784 -0.0468 0.4757 +vn -0.8784 0.3032 -0.3695 +vn -0.8784 -0.1387 -0.4574 +vn -0.8784 -0.1387 0.4574 +vn -0.8784 0.3695 -0.3032 +vn -0.8784 -0.0468 -0.4757 +vn -0.8784 -0.2253 0.4215 +vn -0.8784 0.4215 -0.2253 +vn -0.8784 -0.3032 0.3695 +vn -0.8784 0.4574 -0.1387 +vn -0.8784 -0.3695 0.3032 +vn -0.8784 0.4757 -0.0468 +vn -0.9481 0.0312 -0.3164 +vn -0.9481 -0.2017 0.2458 +vn -0.9481 0.0923 0.3043 +vn -0.9481 0.0923 -0.3043 +vn -0.9481 -0.2458 0.2017 +vn -0.9481 0.0312 0.3164 +vn -0.9481 0.1499 -0.2804 +vn -0.9481 -0.2804 0.1499 +vn -0.9481 0.2017 -0.2458 +vn -0.9481 -0.3043 0.0923 +vn -0.9481 0.2458 -0.2017 +vn -0.9481 -0.3164 0.0312 +vn -0.9481 0.2804 -0.1499 +vn -0.9481 -0.3164 -0.0312 +vn -0.9481 0.3043 -0.0923 +vn -0.9481 -0.3043 -0.0923 +vn -0.9481 0.3164 -0.0312 +vn -0.9481 -0.2804 -0.1499 +vn -0.9481 0.3164 0.0312 +vn -0.9481 -0.2458 -0.2017 +vn -0.9481 0.3043 0.0923 +vn -0.9481 -0.2017 -0.2458 +vn -0.9481 0.2804 0.1499 +vn -0.9481 -0.1499 -0.2804 +vn -0.9481 -0.0312 0.3164 +vn -0.9481 0.2458 0.2017 +vn -0.9481 -0.0923 -0.3043 +vn -0.9481 -0.0923 0.3043 +vn -0.9481 0.2017 0.2458 +vn -0.9481 -0.0312 -0.3164 +vn -0.9481 -0.1499 0.2804 +vn -0.9481 0.1499 0.2804 +vn -0.9938 0.0705 -0.0860 +vn -0.9938 -0.1064 0.0323 +vn -0.9938 0.0860 -0.0705 +vn -0.9938 -0.1107 0.0109 +vn -0.9938 0.0981 -0.0524 +vn -0.9938 -0.1107 -0.0109 +vn -0.9938 0.1064 -0.0323 +vn -0.9938 -0.1064 -0.0323 +vn -0.9938 0.1107 -0.0109 +vn -0.9938 -0.0981 -0.0524 +vn -0.9938 0.1107 0.0109 +vn -0.9938 -0.0860 -0.0705 +vn -0.9938 0.1064 0.0323 +vn -0.9938 -0.0705 -0.0860 +vn -0.9938 0.0981 0.0524 +vn -0.9938 -0.0524 -0.0981 +vn -0.9938 -0.0109 0.1107 +vn -0.9938 0.0860 0.0705 +vn -0.9938 -0.0323 -0.1064 +vn -0.9938 -0.0323 0.1064 +vn -0.9938 0.0705 0.0860 +vn -0.9938 -0.0109 -0.1107 +vn -0.9938 -0.0524 0.0981 +vn -0.9938 0.0524 0.0981 +vn -0.9938 0.0109 -0.1107 +vn -0.9938 -0.0705 0.0860 +vn -0.9938 0.0323 0.1064 +vn -0.9938 0.0323 -0.1064 +vn -0.9938 -0.0860 0.0705 +vn -0.9938 0.0109 0.1107 +vn -0.9938 0.0524 -0.0981 +vn -0.9938 -0.0981 0.0524 +vn -0.8784 0.4757 0.0468 +vn -0.8784 0.0468 -0.4756 +vn 0.9343 -0.1035 0.3413 +vn 0.9343 0.2757 -0.2262 +vn 0.9343 -0.0350 -0.3549 +vn 0.9343 -0.1681 0.3145 +vn 0.9343 0.3145 -0.1681 +vn 0.9343 -0.2262 0.2757 +vn 0.9343 0.3413 -0.1035 +vn 0.9343 -0.2757 0.2262 +vn 0.9343 0.3549 -0.0350 +vn 0.9343 -0.3145 0.1681 +vn 0.9343 0.3549 0.0350 +vn 0.9343 -0.3413 0.1035 +vn 0.9343 0.3413 0.1035 +vn 0.9343 -0.3549 0.0350 +vn 0.9343 0.3145 0.1681 +vn 0.9343 -0.3549 -0.0350 +vn 0.9343 0.2757 0.2262 +vn 0.9343 -0.3413 -0.1035 +vn 0.9343 0.2262 0.2757 +vn 0.9343 -0.3145 -0.1681 +vn 0.9343 0.1681 0.3145 +vn 0.9343 0.0350 -0.3549 +vn 0.9343 -0.2757 -0.2262 +vn 0.9343 0.1035 0.3413 +vn 0.9343 0.1035 -0.3413 +vn 0.9343 -0.2262 -0.2757 +vn 0.9343 0.0350 0.3549 +vn 0.9343 0.1681 -0.3145 +vn 0.9343 -0.1681 -0.3145 +vn 0.9343 -0.0350 0.3549 +vn 0.9343 0.2262 -0.2757 +vn 0.9343 -0.1035 -0.3413 +vn 0.9343 -0.3547 -0.0349 +vn 0.9343 0.2755 0.2261 +vn 0.9343 -0.3410 -0.1035 +vn 0.9343 0.2261 0.2755 +vn 0.9343 -0.3143 -0.1680 +vn 0.9343 0.1680 0.3143 +vn 0.9343 0.0349 -0.3547 +vn 0.9343 -0.2755 -0.2261 +vn 0.9343 0.1035 0.3410 +vn 0.9343 0.1035 -0.3410 +vn 0.9343 -0.2261 -0.2755 +vn 0.9343 0.0349 0.3547 +vn 0.9343 0.1680 -0.3143 +vn 0.9343 -0.1680 -0.3143 +vn 0.9343 -0.0349 0.3547 +vn 0.9343 0.2261 -0.2755 +vn 0.9343 -0.1035 -0.3410 +vn 0.9343 -0.1035 0.3410 +vn 0.9343 0.2755 -0.2261 +vn 0.9343 -0.0349 -0.3547 +vn 0.9343 -0.1680 0.3143 +vn 0.9343 0.3143 -0.1680 +vn 0.9343 -0.2261 0.2755 +vn 0.9343 0.3410 -0.1035 +vn 0.9343 -0.2755 0.2261 +vn 0.9343 0.3547 -0.0349 +vn 0.9343 -0.3143 0.1680 +vn 0.9343 0.3547 0.0349 +vn 0.9343 -0.3410 0.1035 +vn 0.9343 0.3410 0.1035 +vn 0.9343 -0.3547 0.0349 +vn 0.9343 0.3143 0.1680 +usemtl Material +s off +f 7/1/1 995/2/1 983/3/1 927/4/1 +f 928/5/2 992/6/2 986/7/2 1/8/2 +f 5/9/3 26/10/3 938/11/3 935/12/3 +f 10/13/4 33/14/4 22/15/4 988/16/4 1001/17/4 +f 10/13/5 7/1/5 27/18/5 33/14/5 +f 63/19/6 109/20/6 66/21/6 67/22/6 49/23/6 +f 1001/17/5 995/2/5 7/1/5 10/13/5 +f 27/18/7 930/24/7 931/25/7 110/26/7 123/27/7 121/28/7 114/29/7 118/30/7 115/31/7 119/32/7 112/33/7 113/34/7 120/35/7 116/36/7 117/37/7 122/38/7 124/39/7 111/40/7 35/41/7 74/42/7 36/43/7 +f 33/44/8 27/45/8 36/46/8 34/47/8 +f 22/15/9 33/14/9 34/48/9 +f 1/8/10 986/49/10 1696/50/10 694/51/10 24/52/10 +f 54/53/11 65/54/11 72/55/11 69/56/11 +f 7/1/1 927/4/1 930/24/1 27/18/1 +f 928/5/2 1/8/2 24/52/2 932/57/2 +f 932/57/12 35/41/12 111/40/12 125/58/12 110/26/12 931/25/12 +f 31/59/13 47/60/13 45/61/13 43/62/13 41/63/13 75/64/13 35/41/13 932/57/13 693/65/13 695/66/13 152/67/13 +f 75/64/14 108/68/14 74/42/14 35/41/14 +f 63/19/15 64/69/15 37/70/15 +f 109/20/16 108/68/16 75/64/16 63/19/16 +f 37/70/17 30/71/17 68/72/17 70/73/17 +f 63/19/18 37/70/18 70/73/18 71/74/18 +f 75/64/19 41/63/19 64/69/19 63/19/19 +f 74/42/20 108/68/20 56/75/20 58/76/20 60/77/20 62/78/20 50/79/20 34/47/20 36/43/20 +f 34/47/21 50/79/21 62/78/21 94/80/21 95/81/21 941/82/21 940/83/21 22/15/21 +f 62/78/22 61/84/22 78/85/22 +f 76/86/23 52/87/23 84/88/23 85/89/23 +f 83/90/24 51/91/24 52/87/24 76/86/24 +f 52/87/23 81/92/23 86/93/23 84/88/23 +f 82/94/23 76/86/23 85/89/23 87/95/23 +f 81/92/23 82/94/23 87/95/23 86/93/23 +f 85/89/25 84/88/25 88/96/25 89/97/25 +f 1942/98/26 940/83/26 939/99/26 943/100/26 +f 101/101/27 1088/102/27 1090/103/27 95/81/27 +f 62/78/28 78/85/28 98/104/28 97/105/28 +f 94/80/29 62/78/29 97/105/29 101/106/29 +f 66/21/16 65/54/16 56/75/16 108/68/16 109/20/16 +f 116/36/30 120/35/30 130/107/30 131/108/30 +f 110/26/31 125/58/31 139/109/31 137/110/31 +f 125/58/32 111/40/32 127/111/32 139/109/32 +f 122/38/30 117/37/30 134/112/30 136/113/30 +f 118/30/33 114/29/33 129/114/33 133/115/33 +f 111/40/30 124/39/30 126/116/30 127/111/30 +f 123/27/34 110/26/34 137/110/34 138/117/34 +f 114/29/34 121/28/34 128/118/34 129/114/34 +f 119/32/33 115/31/33 132/119/33 135/120/33 +f 121/28/35 123/27/35 148/121/35 149/122/35 +f 112/33/36 119/32/36 142/123/36 140/124/36 +f 124/39/37 122/38/37 150/125/37 151/126/37 +f 117/37/37 116/36/37 145/127/37 146/128/37 +f 115/31/36 118/30/36 143/129/36 144/130/36 +f 120/35/37 113/34/37 141/131/37 147/132/37 +f 154/133/38 1152/134/38 1150/135/38 987/136/38 2/137/38 25/138/38 153/139/38 +f 31/59/39 152/67/39 159/140/39 160/141/39 +f 696/142/40 154/133/40 152/143/40 695/144/40 +f 24/52/41 694/51/41 693/145/41 932/57/41 +f 1695/146/42 696/142/42 700/147/42 702/148/42 +f 696/142/43 1695/146/43 1152/134/43 154/133/43 +f 694/51/44 1696/50/44 701/149/44 697/150/44 +f 696/142/45 695/144/45 699/151/45 700/147/45 +f 695/66/46 693/65/46 698/152/46 699/153/46 +f 693/145/47 694/51/47 697/150/47 698/154/47 +f 737/155/48 738/156/48 740/157/48 739/158/48 +f 739/158/49 740/157/49 742/159/49 741/160/49 +f 741/160/50 742/159/50 744/161/50 743/162/50 +f 743/162/51 744/161/51 746/163/51 745/164/51 +f 745/164/52 746/163/52 748/165/52 747/166/52 +f 747/166/53 748/165/53 750/167/53 749/168/53 +f 749/168/54 750/167/54 752/169/54 751/170/54 +f 751/170/55 752/169/55 754/171/55 753/172/55 +f 753/172/56 754/171/56 756/173/56 755/174/56 +f 755/174/57 756/173/57 758/175/57 757/176/57 +f 757/176/58 758/175/58 760/177/58 759/178/58 +f 759/178/59 760/177/59 762/179/59 761/180/59 +f 761/180/60 762/179/60 764/181/60 763/182/60 +f 763/182/61 764/181/61 766/183/61 765/184/61 +f 765/184/62 766/183/62 768/185/62 767/186/62 +f 767/186/63 768/185/63 770/187/63 769/188/63 +f 769/188/64 770/187/64 772/189/64 771/190/64 +f 771/190/65 772/189/65 774/191/65 773/192/65 +f 773/192/66 774/191/66 776/193/66 775/194/66 +f 775/194/67 776/193/67 778/195/67 777/196/67 +f 777/196/68 778/195/68 780/197/68 779/198/68 +f 779/198/69 780/197/69 782/199/69 781/200/69 +f 781/200/70 782/199/70 784/201/70 783/202/70 +f 783/202/71 784/201/71 786/203/71 785/204/71 +f 785/204/72 786/203/72 788/205/72 787/206/72 +f 787/206/73 788/205/73 790/207/73 789/208/73 +f 789/208/74 790/207/74 792/209/74 791/210/74 +f 791/210/75 792/209/75 794/211/75 793/212/75 +f 793/212/76 794/211/76 796/213/76 795/214/76 +f 795/214/77 796/213/77 798/215/77 797/216/77 +f 740/217/21 738/218/21 800/219/21 798/220/21 796/221/21 794/222/21 792/223/21 790/224/21 788/225/21 786/226/21 784/227/21 782/228/21 780/229/21 778/230/21 776/231/21 774/232/21 772/233/21 770/234/21 768/235/21 766/236/21 764/237/21 762/238/21 760/239/21 758/240/21 756/241/21 754/242/21 752/243/21 750/244/21 748/245/21 746/246/21 744/247/21 742/248/21 +f 797/216/78 798/215/78 800/249/78 799/250/78 +f 799/250/79 800/249/79 738/251/79 737/252/79 +f 737/253/25 739/254/25 741/255/25 743/256/25 745/257/25 747/258/25 749/259/25 751/260/25 753/261/25 755/262/25 757/263/25 759/264/25 761/265/25 763/266/25 765/267/25 767/268/25 769/269/25 771/270/25 773/271/25 775/272/25 777/273/25 779/274/25 781/275/25 783/276/25 785/277/25 787/278/25 789/279/25 791/280/25 793/281/25 795/282/25 797/283/25 799/284/25 +f 1928/285/80 3/286/80 927/4/80 983/3/80 +f 5/9/81 929/287/81 992/6/81 928/5/81 +f 28/288/82 29/289/82 931/25/82 930/24/82 +f 29/289/83 26/10/83 932/57/83 931/25/83 +f 26/10/84 5/9/84 928/5/84 932/57/84 +f 3/286/85 28/288/85 930/24/85 927/4/85 +f 29/289/86 28/288/86 936/290/86 937/291/86 +f 28/288/87 3/286/87 934/292/87 936/290/87 +f 26/10/88 29/289/88 937/291/88 938/11/88 +f 929/287/3 5/9/3 935/12/3 933/293/3 +f 3/286/87 1928/285/87 1934/294/87 934/292/87 +f 1090/103/89 1945/295/89 941/82/89 95/81/89 +f 941/82/26 942/296/26 946/297/26 948/298/26 +f 1942/98/90 988/16/90 22/15/90 940/83/90 +f 941/82/91 1945/295/91 944/299/91 942/296/91 +f 947/300/25 948/298/25 946/297/25 945/301/25 +f 939/99/91 940/83/91 947/300/91 945/301/91 +f 940/83/92 941/82/92 948/298/92 947/300/92 +f 942/296/93 939/99/93 945/301/93 946/297/93 +f 996/302/1 1927/303/1 983/3/1 995/2/1 +f 1929/304/2 981/305/2 986/7/2 992/6/2 +f 991/306/3 1937/307/3 1940/308/3 1018/309/3 +f 1002/310/4 1001/17/4 988/16/4 1014/311/4 1025/312/4 +f 1002/310/5 1025/312/5 1019/313/5 996/302/5 +f 1055/314/94 1041/315/94 1059/316/94 1058/317/94 1105/318/94 +f 1001/17/5 1002/310/5 996/302/5 995/2/5 +f 1019/313/95 1028/319/95 1066/320/95 1027/321/95 1107/322/95 1120/323/95 1118/324/95 1113/325/95 1112/326/95 1116/327/95 1109/328/95 1108/329/95 1115/330/95 1111/331/95 1114/332/95 1110/333/95 1117/334/95 1119/335/95 1106/336/95 1932/337/95 1931/338/95 +f 1025/339/96 1026/340/96 1028/341/96 1019/342/96 +f 1014/311/97 1026/343/97 1025/312/97 +f 981/305/98 1016/344/98 1692/345/98 1696/50/98 986/49/98 +f 1046/346/99 1061/347/99 1064/348/99 1057/349/99 +f 996/302/1 1019/313/1 1931/338/1 1927/303/1 +f 1929/304/2 1933/350/2 1016/344/2 981/305/2 +f 1933/350/100 1932/337/100 1106/336/100 1121/351/100 1107/322/100 1027/321/100 +f 1023/352/101 1148/353/101 1693/354/101 1691/355/101 1933/350/101 1027/321/101 1067/356/101 1033/357/101 1035/358/101 1037/359/101 1039/360/101 +f 1067/356/102 1027/321/102 1066/320/102 1104/361/102 +f 1055/314/103 1029/362/103 1056/363/103 +f 1105/318/104 1055/314/104 1067/356/104 1104/361/104 +f 1029/362/17 1062/364/17 1060/365/17 1022/366/17 +f 1055/314/105 1063/367/105 1062/364/105 1029/362/105 +f 1067/356/106 1055/314/106 1056/363/106 1033/357/106 +f 1066/320/107 1028/319/107 1026/340/107 1042/368/107 1054/369/107 1052/370/107 1050/371/107 1048/372/107 1104/361/107 +f 1026/340/25 1014/311/25 1943/373/25 1944/374/25 1091/375/25 1089/376/25 1054/369/25 1042/368/25 +f 1054/369/22 1070/377/22 1053/378/22 +f 1068/379/23 1077/380/23 1076/381/23 1044/382/23 +f 1075/383/108 1068/379/108 1044/382/108 1043/384/108 +f 1044/382/23 1076/381/23 1078/385/23 1073/386/23 +f 1074/387/23 1079/388/23 1077/380/23 1068/379/23 +f 1073/386/23 1078/385/23 1079/388/23 1074/387/23 +f 1077/380/21 1081/389/21 1080/390/21 1076/381/21 +f 1942/98/26 1947/391/26 1941/392/26 1943/373/26 +f 1097/393/27 1091/375/27 1090/103/27 1088/102/27 +f 1054/369/109 1093/394/109 1094/395/109 1070/377/109 +f 1089/376/29 1097/396/29 1093/394/29 1054/369/29 +f 1058/317/104 1105/318/104 1104/361/104 1048/372/104 1057/349/104 +f 1112/326/110 1127/397/110 1126/398/110 1116/327/110 +f 1106/336/111 1133/399/111 1135/400/111 1121/351/111 +f 1121/351/112 1135/400/112 1123/401/112 1107/322/112 +f 1118/324/110 1132/402/110 1130/403/110 1113/325/110 +f 1114/332/113 1129/404/113 1125/405/113 1110/333/113 +f 1107/322/110 1123/401/110 1122/406/110 1120/323/110 +f 1119/335/114 1134/407/114 1133/399/114 1106/336/114 +f 1110/333/114 1125/405/114 1124/408/114 1117/334/114 +f 1115/330/113 1131/409/113 1128/410/113 1111/331/113 +f 1117/334/115 1145/411/115 1144/412/115 1119/335/115 +f 1108/329/116 1136/413/116 1138/414/116 1115/330/116 +f 1120/323/117 1147/415/117 1146/416/117 1118/324/117 +f 1113/325/118 1142/417/118 1141/418/118 1112/326/118 +f 1111/331/116 1140/419/116 1139/420/116 1114/332/116 +f 1116/327/118 1143/421/118 1137/422/118 1109/328/118 +f 1151/423/119 1149/424/119 1017/425/119 982/426/119 987/136/119 1150/135/119 1152/134/119 +f 1023/352/120 1158/427/120 1157/428/120 1148/353/120 +f 1694/429/121 1693/430/121 1148/431/121 1151/423/121 +f 1016/344/122 1933/350/122 1691/432/122 1692/345/122 +f 1695/146/123 1702/433/123 1700/434/123 1694/429/123 +f 1694/429/124 1151/423/124 1152/134/124 1695/146/124 +f 1692/345/125 1697/435/125 1701/436/125 1696/50/125 +f 1694/429/126 1700/434/126 1699/437/126 1693/430/126 +f 1693/354/127 1699/438/127 1698/439/127 1691/355/127 +f 1691/432/128 1698/440/128 1697/435/128 1692/345/128 +f 1737/441/48 1739/442/48 1740/443/48 1738/444/48 +f 1739/442/49 1741/445/49 1742/446/49 1740/443/49 +f 1741/445/50 1743/447/50 1744/448/50 1742/446/50 +f 1743/447/51 1745/449/51 1746/450/51 1744/448/51 +f 1745/449/52 1747/451/52 1748/452/52 1746/450/52 +f 1747/451/53 1749/453/53 1750/454/53 1748/452/53 +f 1749/453/54 1751/455/54 1752/456/54 1750/454/54 +f 1751/455/55 1753/457/55 1754/458/55 1752/456/55 +f 1753/457/56 1755/459/56 1756/460/56 1754/458/56 +f 1755/459/57 1757/461/57 1758/462/57 1756/460/57 +f 1757/461/58 1759/463/58 1760/464/58 1758/462/58 +f 1759/463/59 1761/465/59 1762/466/59 1760/464/59 +f 1761/465/60 1763/467/60 1764/468/60 1762/466/60 +f 1763/467/61 1765/469/61 1766/470/61 1764/468/61 +f 1765/469/62 1767/471/62 1768/472/62 1766/470/62 +f 1767/471/63 1769/473/63 1770/474/63 1768/472/63 +f 1769/473/64 1771/475/64 1772/476/64 1770/474/64 +f 1771/475/65 1773/477/65 1774/478/65 1772/476/65 +f 1773/477/66 1775/479/66 1776/480/66 1774/478/66 +f 1775/479/67 1777/481/67 1778/482/67 1776/480/67 +f 1777/481/68 1779/483/68 1780/484/68 1778/482/68 +f 1779/483/69 1781/485/69 1782/486/69 1780/484/69 +f 1781/485/70 1783/487/70 1784/488/70 1782/486/70 +f 1783/487/71 1785/489/71 1786/490/71 1784/488/71 +f 1785/489/72 1787/491/72 1788/492/72 1786/490/72 +f 1787/491/73 1789/493/73 1790/494/73 1788/492/73 +f 1789/493/74 1791/495/74 1792/496/74 1790/494/74 +f 1791/495/75 1793/497/75 1794/498/75 1792/496/75 +f 1793/497/76 1795/499/76 1796/500/76 1794/498/76 +f 1795/499/77 1797/501/77 1798/502/77 1796/500/77 +f 1740/503/25 1742/504/25 1744/505/25 1746/506/25 1748/507/25 1750/508/25 1752/509/25 1754/510/25 1756/511/25 1758/512/25 1760/513/25 1762/514/25 1764/515/25 1766/516/25 1768/517/25 1770/518/25 1772/519/25 1774/520/25 1776/521/25 1778/522/25 1780/523/25 1782/524/25 1784/525/25 1786/526/25 1788/527/25 1790/528/25 1792/529/25 1794/530/25 1796/531/25 1798/532/25 1800/533/25 1738/534/25 +f 1797/501/78 1799/535/78 1800/536/78 1798/502/78 +f 1799/535/79 1737/537/79 1738/538/79 1800/536/79 +f 1737/539/21 1799/540/21 1797/541/21 1795/542/21 1793/543/21 1791/544/21 1789/545/21 1787/546/21 1785/547/21 1783/548/21 1781/549/21 1779/550/21 1777/551/21 1775/552/21 1773/553/21 1771/554/21 1769/555/21 1767/556/21 1765/557/21 1763/558/21 1761/559/21 1759/560/21 1757/561/21 1755/562/21 1753/563/21 1751/564/21 1749/565/21 1747/566/21 1745/567/21 1743/568/21 1741/569/21 1739/570/21 +f 1928/285/129 983/3/129 1927/303/129 984/571/129 +f 991/306/130 1929/304/130 992/6/130 1930/572/130 +f 1020/573/131 1931/338/131 1932/337/131 1021/574/131 +f 1021/574/132 1932/337/132 1933/350/132 1018/309/132 +f 1018/309/133 1933/350/133 1929/304/133 991/306/133 +f 984/571/134 1927/303/134 1931/338/134 1020/573/134 +f 1021/574/135 1939/575/135 1938/576/135 1020/573/135 +f 1020/573/87 1938/576/87 1936/577/87 984/571/87 +f 1018/309/136 1940/308/136 1939/575/136 1021/574/136 +f 1930/572/3 1935/578/3 1937/307/3 991/306/3 +f 984/571/87 1936/577/87 1934/294/87 1928/285/87 +f 1090/103/89 1091/375/89 1944/374/89 1945/295/89 +f 1944/374/26 1952/579/26 1950/580/26 1946/581/26 +f 1942/98/90 1943/373/90 1014/311/90 988/16/90 +f 1944/374/91 1946/581/91 1948/582/91 1945/295/91 +f 1951/583/21 1949/584/21 1950/580/21 1952/579/21 +f 1941/392/91 1949/584/91 1951/583/91 1943/373/91 +f 1943/373/92 1951/583/92 1952/579/92 1944/374/92 +f 1946/581/93 1950/580/93 1949/584/93 1941/392/93 +usemtl Материал +f 697/150/137 700/147/137 699/151/137 698/154/137 +f 697/150/138 701/149/138 702/148/138 700/147/138 +f 1697/435/139 1698/440/139 1699/437/139 1700/434/139 +f 1697/435/140 1700/434/140 1702/433/140 1701/436/140 +usemtl Материал.001 +f 993/585/141 6/586/141 2/137/141 987/587/141 +f 12/588/21 13/589/21 14/590/21 15/591/21 16/592/21 11/593/21 +f 9/594/21 21/595/21 20/596/21 19/597/21 18/598/21 17/599/21 +f 14/590/142 13/589/142 42/600/142 44/601/142 +f 13/589/143 12/588/143 38/602/143 42/600/143 +f 152/67/144 158/603/144 161/604/144 159/140/144 +f 17/599/145 18/598/145 55/605/145 53/606/145 +f 11/593/146 16/592/146 48/607/146 39/608/146 +f 18/598/147 19/597/147 57/609/147 55/605/147 +f 19/597/148 20/596/148 59/610/148 57/609/148 +f 6/586/149 11/593/149 39/608/149 40/611/149 31/59/149 +f 15/591/150 14/590/150 44/601/150 46/612/150 +f 2/137/151 6/586/151 31/59/151 25/138/151 +f 16/592/152 15/591/152 46/612/152 48/607/152 +f 37/70/153 64/69/153 41/63/153 42/600/153 38/602/153 +f 41/63/154 43/62/154 44/601/154 42/600/154 +f 43/62/155 45/61/155 46/612/155 44/601/155 +f 45/61/156 47/60/156 48/607/156 46/612/156 +f 47/60/157 40/611/157 39/608/157 48/607/157 +f 12/588/158 4/613/158 30/71/158 37/70/158 38/602/158 +f 8/614/159 17/599/159 53/606/159 54/53/159 32/615/159 +f 72/616/160 55/617/160 56/618/160 65/619/160 +f 55/605/161 57/609/161 58/76/161 56/75/161 +f 57/609/162 59/610/162 60/77/162 58/76/162 +f 59/610/163 61/84/163 62/78/163 60/77/163 +f 69/56/21 72/55/21 73/620/21 71/74/21 70/73/21 68/72/21 +f 65/54/164 66/21/164 73/620/164 72/55/164 +f 66/21/165 109/20/165 63/19/165 71/74/165 73/620/165 +f 30/71/166 54/53/166 69/56/166 68/72/166 +f 69/621/167 53/622/167 55/617/167 72/616/167 +f 69/621/168 54/623/168 53/622/168 +f 79/624/21 82/94/21 81/92/21 80/625/21 +f 23/626/169 77/627/169 79/624/169 80/625/169 +f 52/87/170 23/626/170 80/625/170 81/92/170 +f 77/627/171 76/86/171 82/94/171 79/624/171 +f 84/88/172 86/93/172 90/628/172 88/96/172 +f 89/97/173 88/96/173 90/628/173 91/629/173 +f 87/95/174 85/89/174 89/97/174 91/629/174 +f 86/93/21 87/95/21 91/629/21 90/628/21 +f 985/630/170 23/626/170 52/87/170 51/91/170 106/631/170 9/594/170 1000/632/170 +f 985/630/175 1084/633/175 92/634/175 77/627/175 23/626/175 +f 1086/635/176 102/636/176 92/634/176 1084/633/176 +f 101/106/177 102/637/177 1086/635/177 1088/102/177 +f 77/638/178 93/639/178 102/636/178 100/640/178 +f 96/641/179 97/105/179 98/104/179 99/642/179 +f 96/641/21 100/643/21 102/637/21 101/106/21 97/105/21 +f 76/86/180 77/627/180 100/643/180 96/641/180 +f 83/90/181 76/86/181 96/641/181 99/642/181 +f 99/644/182 88/96/182 89/645/182 83/646/182 +f 61/84/183 59/610/183 105/647/183 104/648/183 78/85/183 +f 99/642/184 98/104/184 107/649/184 103/650/184 +f 106/631/185 51/91/185 99/642/185 103/650/185 +f 20/596/183 103/650/183 107/649/183 59/610/183 +f 149/122/186 150/125/186 136/113/186 128/118/186 +f 130/107/187 147/132/187 142/123/187 135/120/187 +f 151/126/188 148/121/188 138/117/188 126/116/188 +f 143/129/189 133/115/189 134/112/189 146/128/189 +f 143/129/190 146/128/190 145/127/190 144/130/190 +f 142/123/191 147/132/191 141/131/191 140/124/191 +f 148/121/192 151/126/192 150/125/192 149/122/192 +f 131/108/193 132/119/193 144/130/193 145/127/193 +f 113/34/194 112/33/194 140/124/194 141/131/194 +f 152/143/195 154/651/195 153/652/195 +f 156/653/196 157/654/196 158/603/196 155/655/196 +f 153/139/197 25/138/197 156/653/197 155/655/197 +f 25/138/198 31/59/198 157/654/198 156/653/198 +f 152/67/199 153/139/199 155/655/199 158/603/199 +f 160/141/200 159/140/200 161/604/200 162/656/200 +f 158/603/201 157/654/201 162/656/201 161/604/201 +f 157/654/149 31/59/149 160/141/149 162/656/149 +f 154/133/202 153/139/202 1150/135/202 1152/134/202 +f 153/652/203 25/657/203 2/658/203 987/659/203 1150/660/203 +f 163/661/204 169/662/204 176/663/204 170/664/204 +f 168/665/205 167/666/205 174/667/205 175/668/205 +f 166/669/206 165/670/206 172/671/206 173/672/206 +f 164/673/207 163/661/207 170/664/207 171/674/207 +f 169/662/208 168/665/208 175/668/208 176/663/208 +f 167/666/209 166/669/209 173/672/209 174/667/209 +f 165/670/210 164/673/210 171/674/210 172/671/210 +f 174/667/211 173/672/211 180/675/211 181/676/211 +f 172/671/212 171/674/212 178/677/212 179/678/212 +f 170/664/213 176/663/213 183/679/213 177/680/213 +f 175/668/214 174/667/214 181/676/214 182/681/214 +f 173/672/215 172/671/215 179/678/215 180/675/215 +f 171/674/216 170/664/216 177/680/216 178/677/216 +f 176/663/217 175/668/217 182/681/217 183/679/217 +f 202/682/25 201/683/25 214/684/25 217/685/25 +f 210/686/25 209/687/25 222/688/25 225/689/25 +f 206/690/25 205/691/25 218/692/25 221/693/25 +f 198/694/25 211/695/25 224/696/25 213/697/25 +f 184/698/218 226/699/218 247/700/218 246/701/218 +f 208/702/25 207/703/25 220/704/25 223/705/25 +f 204/706/25 203/707/25 216/708/25 219/709/25 +f 204/706/21 219/709/21 232/710/21 235/711/21 +f 206/690/21 221/693/21 187/712/21 188/713/21 +f 205/691/21 204/706/21 235/711/21 234/714/21 +f 207/703/21 206/690/21 188/713/21 189/715/21 +f 218/692/21 205/691/21 234/714/21 233/716/21 +f 198/694/21 213/697/21 193/717/21 190/718/21 +f 219/709/23 218/692/23 233/716/23 232/710/23 +f 200/719/25 199/720/25 212/721/25 215/722/25 +f 187/712/219 186/723/219 248/724/219 251/725/219 +f 227/726/220 185/727/220 245/728/220 244/729/220 +f 239/730/221 236/731/221 264/732/221 267/733/221 +f 230/734/222 231/735/222 252/736/222 243/737/222 +f 238/738/223 239/730/223 267/733/223 266/739/223 +f 229/740/224 230/734/224 243/737/224 242/741/224 +f 221/693/23 220/704/23 186/723/23 187/712/23 +f 215/722/23 214/684/23 237/742/23 236/731/23 +f 220/704/21 207/703/21 189/715/21 186/723/21 +f 214/684/21 201/683/21 238/738/21 237/742/21 +f 223/705/23 222/688/23 184/698/23 185/727/23 +f 201/683/21 200/719/21 239/730/21 238/738/21 +f 222/688/21 209/687/21 226/699/21 184/698/21 +f 211/695/21 210/686/21 196/743/21 197/744/21 +f 200/719/21 215/722/21 236/731/21 239/730/21 +f 209/687/21 208/702/21 227/726/21 226/699/21 +f 210/686/21 225/689/21 195/745/21 196/743/21 +f 208/702/21 223/705/21 185/727/21 227/726/21 +f 225/689/23 224/696/23 194/746/23 195/745/23 +f 203/707/21 202/682/21 229/740/21 228/747/21 +f 224/696/21 211/695/21 197/744/21 194/746/21 +f 202/682/21 217/685/21 230/734/21 229/740/21 +f 213/697/23 212/721/23 192/748/23 193/717/23 +f 217/685/23 216/708/23 231/735/23 230/734/23 +f 212/721/21 199/720/21 191/749/21 192/748/21 +f 216/708/21 203/707/21 228/747/21 231/735/21 +f 199/720/21 198/694/21 190/718/21 191/749/21 +f 261/750/25 260/751/25 258/752/25 259/753/25 +f 257/754/25 254/755/25 255/756/25 256/757/25 +f 250/758/25 251/725/25 248/724/25 249/759/25 +f 246/701/25 247/700/25 244/729/25 245/728/25 +f 242/741/25 243/737/25 252/736/25 253/760/25 +f 241/761/25 262/762/25 263/763/25 240/764/25 +f 265/765/25 266/739/25 267/733/25 264/732/25 +f 189/715/225 188/713/225 250/758/225 249/759/225 +f 186/723/226 189/715/226 249/759/226 248/724/226 +f 226/699/227 227/726/227 244/729/227 247/700/227 +f 188/713/228 187/712/228 251/725/228 250/758/228 +f 185/727/229 184/698/229 246/701/229 245/728/229 +f 231/735/230 228/747/230 253/760/230 252/736/230 +f 228/747/231 229/740/231 242/741/231 253/760/231 +f 191/749/232 190/718/232 255/756/232 254/755/232 +f 193/717/233 192/748/233 257/754/233 256/757/233 +f 194/746/234 197/744/234 259/753/234 258/752/234 +f 233/716/235 234/714/235 262/762/235 241/761/235 +f 195/745/236 194/746/236 258/752/236 260/751/236 +f 234/714/237 235/711/237 263/763/237 262/762/237 +f 196/743/238 195/745/238 260/751/238 261/750/238 +f 235/711/239 232/710/239 240/764/239 263/763/239 +f 197/744/240 196/743/240 261/750/240 259/753/240 +f 236/731/241 237/742/241 265/765/241 264/732/241 +f 192/748/242 191/749/242 254/755/242 257/754/242 +f 237/742/243 238/738/243 266/739/243 265/765/243 +f 232/710/244 233/716/244 241/761/244 240/764/244 +f 190/718/245 193/717/245 256/757/245 255/756/245 +f 164/673/21 165/670/21 166/669/21 167/666/21 168/665/21 169/662/21 163/661/21 +f 428/766/204 434/767/204 441/768/204 435/769/204 +f 433/770/205 432/771/205 439/772/205 440/773/205 +f 431/774/206 430/775/206 437/776/206 438/777/206 +f 429/778/207 428/766/207 435/769/207 436/779/207 +f 434/767/208 433/770/208 440/773/208 441/768/208 +f 432/771/209 431/774/209 438/777/209 439/772/209 +f 430/775/210 429/778/210 436/779/210 437/776/210 +f 439/772/211 438/777/211 445/780/211 446/781/211 +f 437/776/212 436/779/212 443/782/212 444/783/212 +f 435/769/213 441/768/213 448/784/213 442/785/213 +f 440/773/214 439/772/214 446/781/214 447/786/214 +f 438/777/215 437/776/215 444/783/215 445/780/215 +f 436/779/246 435/769/246 442/785/246 443/782/246 +f 441/768/217 440/773/217 447/786/217 448/784/217 +f 467/787/25 466/788/25 479/789/25 482/790/25 +f 475/791/25 474/792/25 487/793/25 490/794/25 +f 471/795/25 470/796/25 483/797/25 486/798/25 +f 463/799/25 476/800/25 489/801/25 478/802/25 +f 449/803/218 491/804/218 512/805/218 511/806/218 +f 473/807/25 472/808/25 485/809/25 488/810/25 +f 469/811/25 468/812/25 481/813/25 484/814/25 +f 469/811/21 484/814/21 497/815/21 500/816/21 +f 471/795/21 486/798/21 452/817/21 453/818/21 +f 470/796/21 469/811/21 500/816/21 499/819/21 +f 472/808/21 471/795/21 453/818/21 454/820/21 +f 483/797/21 470/796/21 499/819/21 498/821/21 +f 463/799/21 478/802/21 458/822/21 455/823/21 +f 484/814/23 483/797/23 498/821/23 497/815/23 +f 465/824/25 464/825/25 477/826/25 480/827/25 +f 452/817/219 451/828/219 513/829/219 516/830/219 +f 492/831/220 450/832/220 510/833/220 509/834/220 +f 504/835/221 501/836/221 529/837/221 532/838/221 +f 495/839/222 496/840/222 517/841/222 508/842/222 +f 503/843/223 504/835/223 532/838/223 531/844/223 +f 494/845/224 495/839/224 508/842/224 507/846/224 +f 486/798/23 485/809/23 451/828/23 452/817/23 +f 480/827/23 479/789/23 502/847/23 501/836/23 +f 485/809/21 472/808/21 454/820/21 451/828/21 +f 479/789/21 466/788/21 503/843/21 502/847/21 +f 488/810/23 487/793/23 449/803/23 450/832/23 +f 466/788/21 465/824/21 504/835/21 503/843/21 +f 487/793/21 474/792/21 491/804/21 449/803/21 +f 476/800/21 475/791/21 461/848/21 462/849/21 +f 465/824/21 480/827/21 501/836/21 504/835/21 +f 474/792/21 473/807/21 492/831/21 491/804/21 +f 475/791/21 490/794/21 460/850/21 461/848/21 +f 473/807/21 488/810/21 450/832/21 492/831/21 +f 490/794/23 489/801/23 459/851/23 460/850/23 +f 468/812/21 467/787/21 494/845/21 493/852/21 +f 489/801/21 476/800/21 462/849/21 459/851/21 +f 467/787/21 482/790/21 495/839/21 494/845/21 +f 478/802/23 477/826/23 457/853/23 458/822/23 +f 482/790/23 481/813/23 496/840/23 495/839/23 +f 477/826/21 464/825/21 456/854/21 457/853/21 +f 481/813/21 468/812/21 493/852/21 496/840/21 +f 464/825/21 463/799/21 455/823/21 456/854/21 +f 526/855/25 525/856/25 523/857/25 524/858/25 +f 522/859/25 519/860/25 520/861/25 521/862/25 +f 515/863/25 516/830/25 513/829/25 514/864/25 +f 511/806/25 512/805/25 509/834/25 510/833/25 +f 507/846/25 508/842/25 517/841/25 518/865/25 +f 506/866/25 527/867/25 528/868/25 505/869/25 +f 530/870/25 531/844/25 532/838/25 529/837/25 +f 454/820/225 453/818/225 515/863/225 514/864/225 +f 451/828/226 454/820/226 514/864/226 513/829/226 +f 491/804/227 492/831/227 509/834/227 512/805/227 +f 453/818/228 452/817/228 516/830/228 515/863/228 +f 450/832/229 449/803/229 511/806/229 510/833/229 +f 496/840/230 493/852/230 518/865/230 517/841/230 +f 493/852/231 494/845/231 507/846/231 518/865/231 +f 456/854/232 455/823/232 520/861/232 519/860/232 +f 458/822/233 457/853/233 522/859/233 521/862/233 +f 459/851/234 462/849/234 524/858/234 523/857/234 +f 498/821/235 499/819/235 527/867/235 506/866/235 +f 460/850/236 459/851/236 523/857/236 525/856/236 +f 499/819/237 500/816/237 528/868/237 527/867/237 +f 461/848/238 460/850/238 525/856/238 526/855/238 +f 500/816/239 497/815/239 505/869/239 528/868/239 +f 462/849/240 461/848/240 526/855/240 524/858/240 +f 501/836/241 502/847/241 530/870/241 529/837/241 +f 457/853/242 456/854/242 519/860/242 522/859/242 +f 502/847/243 503/843/243 531/844/243 530/870/243 +f 497/815/244 498/821/244 506/866/244 505/869/244 +f 455/823/245 458/822/245 521/862/245 520/861/245 +f 429/778/21 430/775/21 431/774/21 432/771/21 433/770/21 434/767/21 428/766/21 +f 993/585/247 987/587/247 982/426/247 994/871/247 +f 1004/872/25 1003/873/25 1008/874/25 1007/875/25 1006/876/25 1005/877/25 +f 999/878/25 1009/879/25 1010/880/25 1011/881/25 1012/882/25 1013/883/25 +f 1006/876/142 1036/884/142 1034/885/142 1005/877/142 +f 1005/877/143 1034/885/143 1030/886/143 1004/872/143 +f 1148/353/144 1157/428/144 1159/887/144 1156/888/144 +f 1009/879/145 1045/889/145 1047/890/145 1010/880/145 +f 1003/873/146 1031/891/146 1040/892/146 1008/874/146 +f 1010/880/147 1047/890/147 1049/893/147 1011/881/147 +f 1011/881/148 1049/893/148 1051/894/148 1012/882/148 +f 994/871/149 1023/352/149 1032/895/149 1031/891/149 1003/873/149 +f 1007/875/150 1038/896/150 1036/884/150 1006/876/150 +f 982/426/248 1017/425/248 1023/352/248 994/871/248 +f 1008/874/152 1040/892/152 1038/896/152 1007/875/152 +f 1029/362/249 1030/886/249 1034/885/249 1033/357/249 1056/363/249 +f 1033/357/250 1034/885/250 1036/884/250 1035/358/250 +f 1035/358/251 1036/884/251 1038/896/251 1037/359/251 +f 1037/359/252 1038/896/252 1040/892/252 1039/360/252 +f 1039/360/253 1040/892/253 1031/891/253 1032/895/253 +f 1004/872/254 1030/886/254 1029/362/254 1022/366/254 989/897/254 +f 997/898/255 1024/899/255 1046/346/255 1045/889/255 1009/879/255 +f 1064/900/256 1057/901/256 1048/902/256 1047/903/256 +f 1047/890/257 1048/372/257 1050/371/257 1049/893/257 +f 1049/893/258 1050/371/258 1052/370/258 1051/894/258 +f 1051/894/259 1052/370/259 1054/369/259 1053/378/259 +f 1061/347/25 1060/365/25 1062/364/25 1063/367/25 1065/904/25 1064/348/25 +f 1057/349/260 1064/348/260 1065/904/260 1058/317/260 +f 1058/317/261 1065/904/261 1063/367/261 1055/314/261 1105/318/261 +f 1022/366/166 1060/365/166 1061/347/166 1046/346/166 +f 1061/905/262 1064/900/262 1047/903/262 1045/906/262 +f 1061/905/168 1045/906/168 1046/907/168 +f 1071/908/25 1072/909/25 1073/386/25 1074/387/25 +f 1015/910/169 1072/909/169 1071/908/169 1069/911/169 +f 1044/382/170 1073/386/170 1072/909/170 1015/910/170 +f 1069/911/171 1071/908/171 1074/387/171 1068/379/171 +f 1076/381/172 1080/390/172 1082/912/172 1078/385/172 +f 1081/389/173 1083/913/173 1082/912/173 1080/390/173 +f 1079/388/174 1083/913/174 1081/389/174 1077/380/174 +f 1078/385/25 1082/912/25 1083/913/25 1079/388/25 +f 985/630/170 1000/632/170 999/878/170 1102/914/170 1043/384/170 1044/382/170 1015/910/170 +f 985/630/175 1015/910/175 1069/911/175 1085/915/175 1084/633/175 +f 1086/635/176 1084/633/176 1085/915/176 1098/916/176 +f 1097/396/177 1088/102/177 1086/635/177 1098/917/177 +f 1069/918/263 1096/919/263 1098/916/263 1087/920/263 +f 1092/921/264 1095/922/264 1094/395/264 1093/394/264 +f 1092/921/25 1093/394/25 1097/396/25 1098/917/25 1096/923/25 +f 1068/379/265 1092/921/265 1096/923/265 1069/911/265 +f 1075/383/266 1095/922/266 1092/921/266 1068/379/266 +f 1095/924/267 1075/925/267 1081/926/267 1080/390/267 +f 1053/378/183 1070/377/183 1100/927/183 1101/928/183 1051/894/183 +f 1095/922/184 1099/929/184 1103/930/184 1094/395/184 +f 1102/914/268 1099/929/268 1095/922/268 1043/384/268 +f 1012/882/183 1051/894/183 1103/930/183 1099/929/183 +f 1145/411/269 1124/408/269 1132/402/269 1146/416/269 +f 1126/398/270 1131/409/270 1138/414/270 1143/421/270 +f 1147/415/271 1122/406/271 1134/407/271 1144/412/271 +f 1139/420/272 1142/417/272 1130/403/272 1129/404/272 +f 1139/420/273 1140/419/273 1141/418/273 1142/417/273 +f 1138/414/274 1136/413/274 1137/422/274 1143/421/274 +f 1144/412/275 1145/411/275 1146/416/275 1147/415/275 +f 1127/397/276 1141/418/276 1140/419/276 1128/410/276 +f 1109/328/277 1137/422/277 1136/413/277 1108/329/277 +f 1148/431/278 1149/931/278 1151/932/278 +f 1154/933/279 1153/934/279 1156/888/279 1155/935/279 +f 1149/424/280 1153/934/280 1154/933/280 1017/425/280 +f 1017/425/281 1154/933/281 1155/935/281 1023/352/281 +f 1148/353/282 1156/888/282 1153/934/282 1149/424/282 +f 1158/427/200 1160/936/200 1159/887/200 1157/428/200 +f 1156/888/283 1159/887/283 1160/936/283 1155/935/283 +f 1155/935/149 1160/936/149 1158/427/149 1023/352/149 +f 1151/423/284 1152/134/284 1150/135/284 1149/424/284 +f 1149/931/285 1150/660/285 987/659/285 982/937/285 1017/938/285 +f 1161/939/286 1168/940/286 1174/941/286 1167/942/286 +f 1166/943/287 1173/944/287 1172/945/287 1165/946/287 +f 1164/947/288 1171/948/288 1170/949/288 1163/950/288 +f 1162/951/289 1169/952/289 1168/940/289 1161/939/289 +f 1167/942/290 1174/941/290 1173/944/290 1166/943/290 +f 1165/946/291 1172/945/291 1171/948/291 1164/947/291 +f 1163/950/292 1170/949/292 1169/952/292 1162/951/292 +f 1172/945/293 1179/953/293 1178/954/293 1171/948/293 +f 1170/949/294 1177/955/294 1176/956/294 1169/952/294 +f 1168/940/295 1175/957/295 1181/958/295 1174/941/295 +f 1173/944/296 1180/959/296 1179/953/296 1172/945/296 +f 1171/948/297 1178/954/297 1177/955/297 1170/949/297 +f 1169/952/298 1176/956/298 1175/957/298 1168/940/298 +f 1174/941/299 1181/958/299 1180/959/299 1173/944/299 +f 1200/960/21 1215/961/21 1212/962/21 1199/963/21 +f 1208/964/21 1223/965/21 1220/966/21 1207/967/21 +f 1204/968/21 1219/969/21 1216/970/21 1203/971/21 +f 1196/972/21 1211/973/21 1222/974/21 1209/975/21 +f 1182/976/300 1244/977/300 1245/978/300 1224/979/300 +f 1206/980/21 1221/981/21 1218/982/21 1205/983/21 +f 1202/984/21 1217/985/21 1214/986/21 1201/987/21 +f 1202/984/25 1233/988/25 1230/989/25 1217/985/25 +f 1204/968/25 1186/990/25 1185/991/25 1219/969/25 +f 1203/971/25 1232/992/25 1233/988/25 1202/984/25 +f 1205/983/25 1187/993/25 1186/990/25 1204/968/25 +f 1216/970/25 1231/994/25 1232/992/25 1203/971/25 +f 1196/972/25 1188/995/25 1191/996/25 1211/973/25 +f 1217/985/23 1230/989/23 1231/994/23 1216/970/23 +f 1198/997/21 1213/998/21 1210/999/21 1197/1000/21 +f 1185/991/301 1249/1001/301 1246/1002/301 1184/1003/301 +f 1225/1004/302 1242/1005/302 1243/1006/302 1183/1007/302 +f 1237/1008/303 1265/1009/303 1262/1010/303 1234/1011/303 +f 1228/1012/304 1241/1013/304 1250/1014/304 1229/1015/304 +f 1236/1016/305 1264/1017/305 1265/1009/305 1237/1008/305 +f 1227/1018/306 1240/1019/306 1241/1013/306 1228/1012/306 +f 1219/969/23 1185/991/23 1184/1003/23 1218/982/23 +f 1213/998/23 1234/1011/23 1235/1020/23 1212/962/23 +f 1218/982/25 1184/1003/25 1187/993/25 1205/983/25 +f 1212/962/25 1235/1020/25 1236/1016/25 1199/963/25 +f 1221/981/23 1183/1007/23 1182/976/23 1220/966/23 +f 1199/963/25 1236/1016/25 1237/1008/25 1198/997/25 +f 1220/966/25 1182/976/25 1224/979/25 1207/967/25 +f 1209/975/25 1195/1021/25 1194/1022/25 1208/964/25 +f 1198/997/25 1237/1008/25 1234/1011/25 1213/998/25 +f 1207/967/25 1224/979/25 1225/1004/25 1206/980/25 +f 1208/964/25 1194/1022/25 1193/1023/25 1223/965/25 +f 1206/980/25 1225/1004/25 1183/1007/25 1221/981/25 +f 1223/965/23 1193/1023/23 1192/1024/23 1222/974/23 +f 1201/987/25 1226/1025/25 1227/1018/25 1200/960/25 +f 1222/974/25 1192/1024/25 1195/1021/25 1209/975/25 +f 1200/960/25 1227/1018/25 1228/1012/25 1215/961/25 +f 1211/973/23 1191/996/23 1190/1026/23 1210/999/23 +f 1215/961/23 1228/1012/23 1229/1015/23 1214/986/23 +f 1210/999/25 1190/1026/25 1189/1027/25 1197/1000/25 +f 1214/986/25 1229/1015/25 1226/1025/25 1201/987/25 +f 1197/1000/25 1189/1027/25 1188/995/25 1196/972/25 +f 1259/1028/21 1257/1029/21 1256/1030/21 1258/1031/21 +f 1255/1032/21 1254/1033/21 1253/1034/21 1252/1035/21 +f 1248/1036/21 1247/1037/21 1246/1002/21 1249/1001/21 +f 1244/977/21 1243/1006/21 1242/1005/21 1245/978/21 +f 1240/1019/21 1251/1038/21 1250/1014/21 1241/1013/21 +f 1239/1039/21 1238/1040/21 1261/1041/21 1260/1042/21 +f 1263/1043/21 1262/1010/21 1265/1009/21 1264/1017/21 +f 1187/993/307 1247/1037/307 1248/1036/307 1186/990/307 +f 1184/1003/308 1246/1002/308 1247/1037/308 1187/993/308 +f 1224/979/309 1245/978/309 1242/1005/309 1225/1004/309 +f 1186/990/310 1248/1036/310 1249/1001/310 1185/991/310 +f 1183/1007/311 1243/1006/311 1244/977/311 1182/976/311 +f 1229/1015/312 1250/1014/312 1251/1038/312 1226/1025/312 +f 1226/1025/313 1251/1038/313 1240/1019/313 1227/1018/313 +f 1189/1027/314 1252/1035/314 1253/1034/314 1188/995/314 +f 1191/996/315 1254/1033/315 1255/1032/315 1190/1026/315 +f 1192/1024/316 1256/1030/316 1257/1029/316 1195/1021/316 +f 1231/994/317 1239/1039/317 1260/1042/317 1232/992/317 +f 1193/1023/318 1258/1031/318 1256/1030/318 1192/1024/318 +f 1232/992/319 1260/1042/319 1261/1041/319 1233/988/319 +f 1194/1022/320 1259/1028/320 1258/1031/320 1193/1023/320 +f 1233/988/321 1261/1041/321 1238/1040/321 1230/989/321 +f 1195/1021/322 1257/1029/322 1259/1028/322 1194/1022/322 +f 1234/1011/323 1262/1010/323 1263/1043/323 1235/1020/323 +f 1190/1026/324 1255/1032/324 1252/1035/324 1189/1027/324 +f 1235/1020/325 1263/1043/325 1264/1017/325 1236/1016/325 +f 1230/989/326 1238/1040/326 1239/1039/326 1231/994/326 +f 1188/995/327 1253/1034/327 1254/1033/327 1191/996/327 +f 1162/951/25 1161/939/25 1167/942/25 1166/943/25 1165/946/25 1164/947/25 1163/950/25 +f 1426/1044/286 1433/1045/286 1439/1046/286 1432/1047/286 +f 1431/1048/287 1438/1049/287 1437/1050/287 1430/1051/287 +f 1429/1052/288 1436/1053/288 1435/1054/288 1428/1055/288 +f 1427/1056/289 1434/1057/289 1433/1045/289 1426/1044/289 +f 1432/1047/290 1439/1046/290 1438/1049/290 1431/1048/290 +f 1430/1051/291 1437/1050/291 1436/1053/291 1429/1052/291 +f 1428/1055/292 1435/1054/292 1434/1057/292 1427/1056/292 +f 1437/1050/293 1444/1058/293 1443/1059/293 1436/1053/293 +f 1435/1054/294 1442/1060/294 1441/1061/294 1434/1057/294 +f 1433/1045/295 1440/1062/295 1446/1063/295 1439/1046/295 +f 1438/1049/296 1445/1064/296 1444/1058/296 1437/1050/296 +f 1436/1053/297 1443/1059/297 1442/1060/297 1435/1054/297 +f 1434/1057/328 1441/1061/328 1440/1062/328 1433/1045/328 +f 1439/1046/299 1446/1063/299 1445/1064/299 1438/1049/299 +f 1465/1065/21 1480/1066/21 1477/1067/21 1464/1068/21 +f 1473/1069/21 1488/1070/21 1485/1071/21 1472/1072/21 +f 1469/1073/21 1484/1074/21 1481/1075/21 1468/1076/21 +f 1461/1077/21 1476/1078/21 1487/1079/21 1474/1080/21 +f 1447/1081/300 1509/1082/300 1510/1083/300 1489/1084/300 +f 1471/1085/21 1486/1086/21 1483/1087/21 1470/1088/21 +f 1467/1089/21 1482/1090/21 1479/1091/21 1466/1092/21 +f 1467/1089/25 1498/1093/25 1495/1094/25 1482/1090/25 +f 1469/1073/25 1451/1095/25 1450/1096/25 1484/1074/25 +f 1468/1076/25 1497/1097/25 1498/1093/25 1467/1089/25 +f 1470/1088/25 1452/1098/25 1451/1095/25 1469/1073/25 +f 1481/1075/25 1496/1099/25 1497/1097/25 1468/1076/25 +f 1461/1077/25 1453/1100/25 1456/1101/25 1476/1078/25 +f 1482/1090/23 1495/1094/23 1496/1099/23 1481/1075/23 +f 1463/1102/21 1478/1103/21 1475/1104/21 1462/1105/21 +f 1450/1096/301 1514/1106/301 1511/1107/301 1449/1108/301 +f 1490/1109/302 1507/1110/302 1508/1111/302 1448/1112/302 +f 1502/1113/303 1530/1114/303 1527/1115/303 1499/1116/303 +f 1493/1117/304 1506/1118/304 1515/1119/304 1494/1120/304 +f 1501/1121/305 1529/1122/305 1530/1114/305 1502/1113/305 +f 1492/1123/306 1505/1124/306 1506/1118/306 1493/1117/306 +f 1484/1074/23 1450/1096/23 1449/1108/23 1483/1087/23 +f 1478/1103/23 1499/1116/23 1500/1125/23 1477/1067/23 +f 1483/1087/25 1449/1108/25 1452/1098/25 1470/1088/25 +f 1477/1067/25 1500/1125/25 1501/1121/25 1464/1068/25 +f 1486/1086/23 1448/1112/23 1447/1081/23 1485/1071/23 +f 1464/1068/25 1501/1121/25 1502/1113/25 1463/1102/25 +f 1485/1071/25 1447/1081/25 1489/1084/25 1472/1072/25 +f 1474/1080/25 1460/1126/25 1459/1127/25 1473/1069/25 +f 1463/1102/25 1502/1113/25 1499/1116/25 1478/1103/25 +f 1472/1072/25 1489/1084/25 1490/1109/25 1471/1085/25 +f 1473/1069/25 1459/1127/25 1458/1128/25 1488/1070/25 +f 1471/1085/25 1490/1109/25 1448/1112/25 1486/1086/25 +f 1488/1070/23 1458/1128/23 1457/1129/23 1487/1079/23 +f 1466/1092/25 1491/1130/25 1492/1123/25 1465/1065/25 +f 1487/1079/25 1457/1129/25 1460/1126/25 1474/1080/25 +f 1465/1065/25 1492/1123/25 1493/1117/25 1480/1066/25 +f 1476/1078/23 1456/1101/23 1455/1131/23 1475/1104/23 +f 1480/1066/23 1493/1117/23 1494/1120/23 1479/1091/23 +f 1475/1104/25 1455/1131/25 1454/1132/25 1462/1105/25 +f 1479/1091/25 1494/1120/25 1491/1130/25 1466/1092/25 +f 1462/1105/25 1454/1132/25 1453/1100/25 1461/1077/25 +f 1524/1133/21 1522/1134/21 1521/1135/21 1523/1136/21 +f 1520/1137/21 1519/1138/21 1518/1139/21 1517/1140/21 +f 1513/1141/21 1512/1142/21 1511/1107/21 1514/1106/21 +f 1509/1082/21 1508/1111/21 1507/1110/21 1510/1083/21 +f 1505/1124/21 1516/1143/21 1515/1119/21 1506/1118/21 +f 1504/1144/21 1503/1145/21 1526/1146/21 1525/1147/21 +f 1528/1148/21 1527/1115/21 1530/1114/21 1529/1122/21 +f 1452/1098/307 1512/1142/307 1513/1141/307 1451/1095/307 +f 1449/1108/308 1511/1107/308 1512/1142/308 1452/1098/308 +f 1489/1084/309 1510/1083/309 1507/1110/309 1490/1109/309 +f 1451/1095/310 1513/1141/310 1514/1106/310 1450/1096/310 +f 1448/1112/311 1508/1111/311 1509/1082/311 1447/1081/311 +f 1494/1120/312 1515/1119/312 1516/1143/312 1491/1130/312 +f 1491/1130/313 1516/1143/313 1505/1124/313 1492/1123/313 +f 1454/1132/314 1517/1140/314 1518/1139/314 1453/1100/314 +f 1456/1101/315 1519/1138/315 1520/1137/315 1455/1131/315 +f 1457/1129/316 1521/1135/316 1522/1134/316 1460/1126/316 +f 1496/1099/317 1504/1144/317 1525/1147/317 1497/1097/317 +f 1458/1128/318 1523/1136/318 1521/1135/318 1457/1129/318 +f 1497/1097/319 1525/1147/319 1526/1146/319 1498/1093/319 +f 1459/1127/320 1524/1133/320 1523/1136/320 1458/1128/320 +f 1498/1093/321 1526/1146/321 1503/1145/321 1495/1094/321 +f 1460/1126/322 1522/1134/322 1524/1133/322 1459/1127/322 +f 1499/1116/323 1527/1115/323 1528/1148/323 1500/1125/323 +f 1455/1131/324 1520/1137/324 1517/1140/324 1454/1132/324 +f 1500/1125/325 1528/1148/325 1529/1122/325 1501/1121/325 +f 1495/1094/326 1503/1145/326 1504/1144/326 1496/1099/326 +f 1453/1100/327 1518/1139/327 1519/1138/327 1456/1101/327 +f 1427/1056/25 1426/1044/25 1432/1047/25 1431/1048/25 1430/1051/25 1429/1052/25 1428/1055/25 +usemtl Материал.003 +f 132/119/329 131/108/329 130/107/329 135/120/329 +f 128/118/330 136/113/330 134/112/330 133/115/330 129/114/330 +f 127/111/12 126/116/12 138/117/12 137/110/12 139/109/12 +f 937/291/331 936/290/331 934/292/331 1934/294/331 933/293/331 935/12/331 938/11/331 +f 1128/410/332 1131/409/332 1126/398/332 1127/397/332 +f 1124/408/333 1125/405/333 1129/404/333 1130/403/333 1132/402/333 +f 1123/401/100 1135/400/100 1133/399/100 1134/407/100 1122/406/100 +f 1939/575/334 1940/308/334 1937/307/334 1935/578/334 1934/294/334 1936/577/334 1938/576/334 +usemtl Материал.002 +f 998/1149/335 8/614/335 4/613/335 12/588/335 11/593/335 6/586/335 993/585/335 990/1150/335 +f 1000/632/336 9/594/336 17/599/336 8/614/336 998/1149/336 +f 4/613/337 8/614/337 32/615/337 54/53/337 30/71/337 +f 289/1151/338 290/1152/338 322/1153/338 321/1154/338 +f 276/1155/339 277/1156/339 309/1157/339 308/1158/339 +f 290/1152/340 291/1159/340 323/1160/340 322/1153/340 +f 277/1156/341 278/1161/341 310/1162/341 309/1157/341 +f 291/1159/342 292/1163/342 324/1164/342 323/1160/342 +f 278/1161/343 279/1165/343 311/1166/343 310/1162/343 +f 292/1163/344 293/1167/344 325/1168/344 324/1164/344 +f 279/1165/345 280/1169/345 312/1170/345 311/1166/345 +f 293/1167/346 294/1171/346 326/1172/346 325/1168/346 +f 280/1169/347 281/1173/347 313/1174/347 312/1170/347 +f 294/1171/348 295/1175/348 327/1176/348 326/1172/348 +f 281/1173/349 282/1177/349 314/1178/349 313/1174/349 +f 268/1179/350 269/1180/350 301/1181/350 300/1182/350 +f 295/1175/351 296/1183/351 328/1184/351 327/1176/351 +f 282/1177/352 283/1185/352 315/1186/352 314/1178/352 +f 269/1180/353 270/1187/353 302/1188/353 301/1181/353 +f 296/1183/354 297/1189/354 329/1190/354 328/1184/354 +f 283/1185/355 284/1191/355 316/1192/355 315/1186/355 +f 270/1187/356 271/1193/356 303/1194/356 302/1188/356 +f 297/1189/357 298/1195/357 330/1196/357 329/1190/357 +f 284/1191/358 285/1197/358 317/1198/358 316/1192/358 +f 271/1193/359 272/1199/359 304/1200/359 303/1194/359 +f 298/1195/360 299/1201/360 331/1202/360 330/1196/360 +f 285/1197/361 286/1203/361 318/1204/361 317/1198/361 +f 272/1199/362 273/1205/362 305/1206/362 304/1200/362 +f 299/1201/363 268/1179/363 300/1182/363 331/1202/363 +f 286/1203/364 287/1207/364 319/1208/364 318/1204/364 +f 273/1205/365 274/1209/365 306/1210/365 305/1206/365 +f 287/1207/366 288/1211/366 320/1212/366 319/1208/366 +f 274/1209/367 275/1213/367 307/1214/367 306/1210/367 +f 288/1211/368 289/1151/368 321/1154/368 320/1212/368 +f 275/1213/369 276/1155/369 308/1158/369 307/1214/369 +f 316/1192/370 317/1198/370 349/1215/370 348/1216/370 +f 303/1194/371 304/1200/371 336/1217/371 335/1218/371 +f 330/1196/372 331/1202/372 363/1219/372 362/1220/372 +f 317/1198/373 318/1204/373 350/1221/373 349/1215/373 +f 304/1200/374 305/1206/374 337/1222/374 336/1217/374 +f 331/1202/375 300/1182/375 332/1223/375 363/1219/375 +f 318/1204/376 319/1208/376 351/1224/376 350/1221/376 +f 305/1206/377 306/1210/377 338/1225/377 337/1222/377 +f 319/1208/378 320/1212/378 352/1226/378 351/1224/378 +f 306/1210/379 307/1214/379 339/1227/379 338/1225/379 +f 320/1212/380 321/1154/380 353/1228/380 352/1226/380 +f 307/1214/381 308/1158/381 340/1229/381 339/1227/381 +f 321/1154/382 322/1153/382 354/1230/382 353/1228/382 +f 308/1158/383 309/1157/383 341/1231/383 340/1229/383 +f 322/1153/384 323/1160/384 355/1232/384 354/1230/384 +f 309/1157/385 310/1162/385 342/1233/385 341/1231/385 +f 323/1160/386 324/1164/386 356/1234/386 355/1232/386 +f 310/1162/387 311/1166/387 343/1235/387 342/1233/387 +f 324/1164/388 325/1168/388 357/1236/388 356/1234/388 +f 311/1166/389 312/1170/389 344/1237/389 343/1235/389 +f 325/1168/390 326/1172/390 358/1238/390 357/1236/390 +f 312/1170/391 313/1174/391 345/1239/391 344/1237/391 +f 326/1172/392 327/1176/392 359/1240/392 358/1238/392 +f 313/1174/393 314/1178/393 346/1241/393 345/1239/393 +f 300/1182/394 301/1181/394 333/1242/394 332/1223/394 +f 327/1176/395 328/1184/395 360/1243/395 359/1240/395 +f 314/1178/396 315/1186/396 347/1244/396 346/1241/396 +f 301/1181/397 302/1188/397 334/1245/397 333/1242/397 +f 328/1184/398 329/1190/398 361/1246/398 360/1243/398 +f 315/1186/399 316/1192/399 348/1216/399 347/1244/399 +f 302/1188/400 303/1194/400 335/1218/400 334/1245/400 +f 329/1190/401 330/1196/401 362/1220/401 361/1246/401 +f 351/1224/402 352/1226/402 384/1247/402 383/1248/402 +f 338/1225/403 339/1227/403 371/1249/403 370/1250/403 +f 352/1226/404 353/1228/404 385/1251/404 384/1247/404 +f 339/1227/405 340/1229/405 372/1252/405 371/1249/405 +f 353/1228/406 354/1230/406 386/1253/406 385/1251/406 +f 340/1229/407 341/1231/407 373/1254/407 372/1252/407 +f 354/1230/408 355/1232/408 387/1255/408 386/1253/408 +f 341/1231/409 342/1233/409 374/1256/409 373/1254/409 +f 355/1232/410 356/1234/410 388/1257/410 387/1255/410 +f 342/1233/411 343/1235/411 375/1258/411 374/1256/411 +f 356/1234/412 357/1236/412 389/1259/412 388/1257/412 +f 343/1235/413 344/1237/413 376/1260/413 375/1258/413 +f 357/1236/414 358/1238/414 390/1261/414 389/1259/414 +f 344/1237/415 345/1239/415 377/1262/415 376/1260/415 +f 358/1238/416 359/1240/416 391/1263/416 390/1261/416 +f 345/1239/417 346/1241/417 378/1264/417 377/1262/417 +f 332/1223/418 333/1242/418 365/1265/418 364/1266/418 +f 359/1240/419 360/1243/419 392/1267/419 391/1263/419 +f 346/1241/420 347/1244/420 379/1268/420 378/1264/420 +f 333/1242/421 334/1245/421 366/1269/421 365/1265/421 +f 360/1243/422 361/1246/422 393/1270/422 392/1267/422 +f 347/1244/423 348/1216/423 380/1271/423 379/1268/423 +f 334/1245/424 335/1218/424 367/1272/424 366/1269/424 +f 361/1246/425 362/1220/425 394/1273/425 393/1270/425 +f 348/1216/426 349/1215/426 381/1274/426 380/1271/426 +f 335/1218/427 336/1217/427 368/1275/427 367/1272/427 +f 362/1220/428 363/1219/428 395/1276/428 394/1273/428 +f 349/1215/429 350/1221/429 382/1277/429 381/1274/429 +f 336/1217/430 337/1222/430 369/1278/430 368/1275/430 +f 363/1219/431 332/1223/431 364/1266/431 395/1276/431 +f 350/1221/432 351/1224/432 383/1248/432 382/1277/432 +f 337/1222/433 338/1225/433 370/1250/433 369/1278/433 +f 290/1152/58 289/1151/58 417/1279/58 418/1280/58 +f 277/1156/71 276/1155/71 404/1281/71 405/1282/71 +f 291/1159/57 290/1152/57 418/1280/57 419/1283/57 +f 278/1161/70 277/1156/70 405/1282/70 406/1284/70 +f 292/1163/56 291/1159/56 419/1283/56 420/1285/56 +f 279/1165/69 278/1161/69 406/1284/69 407/1286/69 +f 293/1167/55 292/1163/55 420/1285/55 421/1287/55 +f 280/1169/68 279/1165/68 407/1286/68 408/1288/68 +f 294/1171/54 293/1167/54 421/1287/54 422/1289/54 +f 281/1173/67 280/1169/67 408/1288/67 409/1290/67 +f 295/1175/53 294/1171/53 422/1289/53 423/1291/53 +f 282/1177/66 281/1173/66 409/1290/66 410/1292/66 +f 269/1180/79 268/1179/79 396/1293/79 397/1294/79 +f 296/1183/52 295/1175/52 423/1291/52 424/1295/52 +f 283/1185/65 282/1177/65 410/1292/65 411/1296/65 +f 270/1187/78 269/1180/78 397/1294/78 398/1297/78 +f 297/1189/51 296/1183/51 424/1295/51 425/1298/51 +f 284/1191/64 283/1185/64 411/1296/64 412/1299/64 +f 271/1193/77 270/1187/77 398/1297/77 399/1300/77 +f 298/1195/50 297/1189/50 425/1298/50 426/1301/50 +f 285/1197/63 284/1191/63 412/1299/63 413/1302/63 +f 272/1199/76 271/1193/76 399/1300/76 400/1303/76 +f 299/1201/49 298/1195/49 426/1301/49 427/1304/49 +f 286/1203/62 285/1197/62 413/1302/62 414/1305/62 +f 273/1205/75 272/1199/75 400/1303/75 401/1306/75 +f 268/1179/48 299/1201/48 427/1304/48 396/1293/48 +f 287/1207/61 286/1203/61 414/1305/61 415/1307/61 +f 274/1209/74 273/1205/74 401/1306/74 402/1308/74 +f 288/1211/60 287/1207/60 415/1307/60 416/1309/60 +f 275/1213/73 274/1209/73 402/1308/73 403/1310/73 +f 289/1151/59 288/1211/59 416/1309/59 417/1279/59 +f 276/1155/72 275/1213/72 403/1310/72 404/1281/72 +f 554/1311/338 555/1312/338 587/1313/338 586/1314/338 +f 541/1315/434 542/1316/434 574/1317/434 573/1318/434 +f 555/1312/340 556/1319/340 588/1320/340 587/1313/340 +f 542/1316/341 543/1321/341 575/1322/341 574/1317/341 +f 556/1319/435 557/1323/435 589/1324/435 588/1320/435 +f 543/1321/343 544/1325/343 576/1326/343 575/1322/343 +f 557/1323/344 558/1327/344 590/1328/344 589/1324/344 +f 544/1325/345 545/1329/345 577/1330/345 576/1326/345 +f 558/1327/346 559/1331/346 591/1332/346 590/1328/346 +f 545/1329/347 546/1333/347 578/1334/347 577/1330/347 +f 559/1331/348 560/1335/348 592/1336/348 591/1332/348 +f 546/1333/349 547/1337/349 579/1338/349 578/1334/349 +f 533/1339/350 534/1340/350 566/1341/350 565/1342/350 +f 560/1335/351 561/1343/351 593/1344/351 592/1336/351 +f 547/1337/352 548/1345/352 580/1346/352 579/1338/352 +f 534/1340/353 535/1347/353 567/1348/353 566/1341/353 +f 561/1343/354 562/1349/354 594/1350/354 593/1344/354 +f 548/1345/355 549/1351/355 581/1352/355 580/1346/355 +f 535/1347/356 536/1353/356 568/1354/356 567/1348/356 +f 562/1349/357 563/1355/357 595/1356/357 594/1350/357 +f 549/1351/358 550/1357/358 582/1358/358 581/1352/358 +f 536/1353/359 537/1359/359 569/1360/359 568/1354/359 +f 563/1355/360 564/1361/360 596/1362/360 595/1356/360 +f 550/1357/361 551/1363/361 583/1364/361 582/1358/361 +f 537/1359/362 538/1365/362 570/1366/362 569/1360/362 +f 564/1361/363 533/1339/363 565/1342/363 596/1362/363 +f 551/1363/364 552/1367/364 584/1368/364 583/1364/364 +f 538/1365/365 539/1369/365 571/1370/365 570/1366/365 +f 552/1367/366 553/1371/366 585/1372/366 584/1368/366 +f 539/1369/367 540/1373/367 572/1374/367 571/1370/367 +f 553/1371/368 554/1311/368 586/1314/368 585/1372/368 +f 540/1373/369 541/1315/369 573/1318/369 572/1374/369 +f 581/1352/370 582/1358/370 614/1375/370 613/1376/370 +f 568/1354/371 569/1360/371 601/1377/371 600/1378/371 +f 595/1356/372 596/1362/372 628/1379/372 627/1380/372 +f 582/1358/373 583/1364/373 615/1381/373 614/1375/373 +f 569/1360/374 570/1366/374 602/1382/374 601/1377/374 +f 596/1362/375 565/1342/375 597/1383/375 628/1379/375 +f 583/1364/376 584/1368/376 616/1384/376 615/1381/376 +f 570/1366/377 571/1370/377 603/1385/377 602/1382/377 +f 584/1368/378 585/1372/378 617/1386/378 616/1384/378 +f 571/1370/379 572/1374/379 604/1387/379 603/1385/379 +f 585/1372/380 586/1314/380 618/1388/380 617/1386/380 +f 572/1374/381 573/1318/381 605/1389/381 604/1387/381 +f 586/1314/382 587/1313/382 619/1390/382 618/1388/382 +f 573/1318/383 574/1317/383 606/1391/383 605/1389/383 +f 587/1313/384 588/1320/384 620/1392/384 619/1390/384 +f 574/1317/385 575/1322/385 607/1393/385 606/1391/385 +f 588/1320/386 589/1324/386 621/1394/386 620/1392/386 +f 575/1322/387 576/1326/387 608/1395/387 607/1393/387 +f 589/1324/388 590/1328/388 622/1396/388 621/1394/388 +f 576/1326/389 577/1330/389 609/1397/389 608/1395/389 +f 590/1328/390 591/1332/390 623/1398/390 622/1396/390 +f 577/1330/391 578/1334/391 610/1399/391 609/1397/391 +f 591/1332/392 592/1336/392 624/1400/392 623/1398/392 +f 578/1334/393 579/1338/393 611/1401/393 610/1399/393 +f 565/1342/394 566/1341/394 598/1402/394 597/1383/394 +f 592/1336/395 593/1344/395 625/1403/395 624/1400/395 +f 579/1338/396 580/1346/396 612/1404/396 611/1401/396 +f 566/1341/397 567/1348/397 599/1405/397 598/1402/397 +f 593/1344/398 594/1350/398 626/1406/398 625/1403/398 +f 580/1346/399 581/1352/399 613/1376/399 612/1404/399 +f 567/1348/400 568/1354/400 600/1378/400 599/1405/400 +f 594/1350/401 595/1356/401 627/1380/401 626/1406/401 +f 616/1384/402 617/1386/402 649/1407/402 648/1408/402 +f 603/1385/403 604/1387/403 636/1409/403 635/1410/403 +f 617/1386/404 618/1388/404 650/1411/404 649/1407/404 +f 604/1387/405 605/1389/405 637/1412/405 636/1409/405 +f 618/1388/406 619/1390/406 651/1413/406 650/1411/406 +f 605/1389/407 606/1391/407 638/1414/407 637/1412/407 +f 619/1390/408 620/1392/408 652/1415/408 651/1413/408 +f 606/1391/409 607/1393/409 639/1416/409 638/1414/409 +f 620/1392/410 621/1394/410 653/1417/410 652/1415/410 +f 607/1393/411 608/1395/411 640/1418/411 639/1416/411 +f 621/1394/412 622/1396/412 654/1419/412 653/1417/412 +f 608/1395/413 609/1397/413 641/1420/413 640/1418/413 +f 622/1396/414 623/1398/414 655/1421/414 654/1419/414 +f 609/1397/415 610/1399/415 642/1422/415 641/1420/415 +f 623/1398/416 624/1400/416 656/1423/416 655/1421/416 +f 610/1399/417 611/1401/417 643/1424/417 642/1422/417 +f 597/1383/418 598/1402/418 630/1425/418 629/1426/418 +f 624/1400/419 625/1403/419 657/1427/419 656/1423/419 +f 611/1401/420 612/1404/420 644/1428/420 643/1424/420 +f 598/1402/421 599/1405/421 631/1429/421 630/1425/421 +f 625/1403/422 626/1406/422 658/1430/422 657/1427/422 +f 612/1404/423 613/1376/423 645/1431/423 644/1428/423 +f 599/1405/424 600/1378/424 632/1432/424 631/1429/424 +f 626/1406/425 627/1380/425 659/1433/425 658/1430/425 +f 613/1376/426 614/1375/426 646/1434/426 645/1431/426 +f 600/1378/427 601/1377/427 633/1435/427 632/1432/427 +f 627/1380/428 628/1379/428 660/1436/428 659/1433/428 +f 614/1375/429 615/1381/429 647/1437/429 646/1434/429 +f 601/1377/430 602/1382/430 634/1438/430 633/1435/430 +f 628/1379/431 597/1383/431 629/1426/431 660/1436/431 +f 615/1381/432 616/1384/432 648/1408/432 647/1437/432 +f 602/1382/433 603/1385/433 635/1410/433 634/1438/433 +f 555/1312/58 554/1311/58 682/1439/58 683/1440/58 +f 542/1316/71 541/1315/71 669/1441/71 670/1442/71 +f 556/1319/57 555/1312/57 683/1440/57 684/1443/57 +f 543/1321/70 542/1316/70 670/1442/70 671/1444/70 +f 557/1323/56 556/1319/56 684/1443/56 685/1445/56 +f 544/1325/69 543/1321/69 671/1444/69 672/1446/69 +f 558/1327/55 557/1323/55 685/1445/55 686/1447/55 +f 545/1329/68 544/1325/68 672/1446/68 673/1448/68 +f 559/1331/54 558/1327/54 686/1447/54 687/1449/54 +f 546/1333/67 545/1329/67 673/1448/67 674/1450/67 +f 560/1335/53 559/1331/53 687/1449/53 688/1451/53 +f 547/1337/66 546/1333/66 674/1450/66 675/1452/66 +f 534/1340/79 533/1339/79 661/1453/79 662/1454/79 +f 561/1343/52 560/1335/52 688/1451/52 689/1455/52 +f 548/1345/65 547/1337/65 675/1452/65 676/1456/65 +f 535/1347/78 534/1340/78 662/1454/78 663/1457/78 +f 562/1349/51 561/1343/51 689/1455/51 690/1458/51 +f 549/1351/64 548/1345/64 676/1456/64 677/1459/64 +f 536/1353/77 535/1347/77 663/1457/77 664/1460/77 +f 563/1355/50 562/1349/50 690/1458/50 691/1461/50 +f 550/1357/63 549/1351/63 677/1459/63 678/1462/63 +f 537/1359/76 536/1353/76 664/1460/76 665/1463/76 +f 564/1361/49 563/1355/49 691/1461/49 692/1464/49 +f 551/1363/62 550/1357/62 678/1462/62 679/1465/62 +f 538/1365/75 537/1359/75 665/1463/75 666/1466/75 +f 533/1339/48 564/1361/48 692/1464/48 661/1453/48 +f 552/1367/61 551/1363/61 679/1465/61 680/1467/61 +f 539/1369/74 538/1365/74 666/1466/74 667/1468/74 +f 553/1371/60 552/1367/60 680/1467/60 681/1469/60 +f 540/1373/73 539/1369/73 667/1468/73 668/1470/73 +f 554/1311/59 553/1371/59 681/1469/59 682/1439/59 +f 541/1315/72 540/1373/72 668/1470/72 669/1441/72 +f 414/1305/436 413/1302/436 720/1471/436 721/1472/436 +f 401/1306/437 400/1303/437 707/1473/437 708/1474/437 +f 396/1293/438 427/1304/438 734/1475/438 703/1476/438 +f 415/1307/439 414/1305/439 721/1472/439 722/1477/439 +f 402/1308/440 401/1306/440 708/1474/440 709/1478/440 +f 416/1309/441 415/1307/441 722/1477/441 723/1479/441 +f 403/1310/442 402/1308/442 709/1478/442 710/1480/442 +f 417/1279/443 416/1309/443 723/1479/443 724/1481/443 +f 404/1281/444 403/1310/444 710/1480/444 711/1482/444 +f 418/1280/445 417/1279/445 724/1481/445 725/1483/445 +f 405/1282/446 404/1281/446 711/1482/446 712/1484/446 +f 419/1283/447 418/1280/447 725/1483/447 726/1485/447 +f 406/1284/448 405/1282/448 712/1484/448 713/1486/448 +f 420/1285/449 419/1283/449 726/1485/449 727/1487/449 +f 407/1286/450 406/1284/450 713/1486/450 714/1488/450 +f 421/1287/451 420/1285/451 727/1487/451 728/1489/451 +f 408/1288/452 407/1286/452 714/1488/452 715/1490/452 +f 422/1289/453 421/1287/453 728/1489/453 729/1491/453 +f 409/1290/454 408/1288/454 715/1490/454 716/1492/454 +f 423/1291/455 422/1289/455 729/1491/455 730/1493/455 +f 410/1292/456 409/1290/456 716/1492/456 717/1494/456 +f 397/1294/457 396/1293/457 703/1476/457 704/1495/457 +f 424/1295/458 423/1291/458 730/1493/458 731/1496/458 +f 411/1296/459 410/1292/459 717/1494/459 718/1497/459 +f 398/1297/460 397/1294/460 704/1495/460 705/1498/460 +f 425/1298/461 424/1295/461 731/1496/461 732/1499/461 +f 412/1299/462 411/1296/462 718/1497/462 719/1500/462 +f 399/1300/463 398/1297/463 705/1498/463 706/1501/463 +f 426/1301/464 425/1298/464 732/1499/464 733/1502/464 +f 413/1302/465 412/1299/465 719/1500/465 720/1471/465 +f 400/1303/466 399/1300/466 706/1501/466 707/1473/466 +f 427/1304/467 426/1301/467 733/1502/467 734/1475/467 +f 704/1495/25 703/1476/25 734/1475/25 733/1502/25 732/1499/25 731/1496/25 730/1493/25 729/1491/25 728/1489/25 727/1487/25 726/1485/25 725/1483/25 724/1481/25 723/1479/25 722/1477/25 721/1472/25 720/1471/25 719/1500/25 718/1497/25 717/1494/25 716/1492/25 715/1490/25 714/1488/25 713/1486/25 712/1484/25 711/1482/25 710/1480/25 709/1478/25 708/1474/25 707/1473/25 706/1501/25 705/1498/25 +f 869/1503/51 870/1504/51 872/1505/51 871/1506/51 +f 802/1507/21 735/1508/21 862/1509/21 860/1510/21 858/1511/21 856/1512/21 854/1513/21 852/1514/21 850/1515/21 848/1516/21 846/1517/21 844/1518/21 842/1519/21 840/1520/21 838/1521/21 836/1522/21 834/1523/21 832/1524/21 830/1525/21 828/1526/21 826/1527/21 824/1528/21 822/1529/21 820/1530/21 818/1531/21 816/1532/21 814/1533/21 812/1534/21 810/1535/21 808/1536/21 806/1537/21 804/1538/21 +f 864/1539/25 865/1540/25 867/1541/25 869/1542/25 871/1543/25 873/1544/25 875/1545/25 877/1546/25 879/1547/25 881/1548/25 883/1549/25 885/1550/25 887/1551/25 889/1552/25 891/1553/25 893/1554/25 895/1555/25 897/1556/25 899/1557/25 901/1558/25 903/1559/25 905/1560/25 907/1561/25 909/1562/25 911/1563/25 913/1564/25 915/1565/25 917/1566/25 919/1567/25 921/1568/25 923/1569/25 925/1570/25 +f 857/1571/77 858/1572/77 860/1573/77 859/1574/77 +f 873/1575/53 874/1576/53 876/1577/53 875/1578/53 +f 855/1579/76 856/1580/76 858/1572/76 857/1571/76 +f 875/1578/54 876/1577/54 878/1581/54 877/1582/54 +f 853/1583/75 854/1584/75 856/1580/75 855/1579/75 +f 877/1582/55 878/1581/55 880/1585/55 879/1586/55 +f 851/1587/74 852/1588/74 854/1584/74 853/1583/74 +f 879/1586/56 880/1585/56 882/1589/56 881/1590/56 +f 849/1591/73 850/1592/73 852/1588/73 851/1587/73 +f 881/1590/57 882/1589/57 884/1593/57 883/1594/57 +f 847/1595/72 848/1596/72 850/1592/72 849/1591/72 +f 883/1594/58 884/1593/58 886/1597/58 885/1598/58 +f 845/1599/71 846/1600/71 848/1596/71 847/1595/71 +f 885/1598/59 886/1597/59 888/1601/59 887/1602/59 +f 843/1603/70 844/1604/70 846/1600/70 845/1599/70 +f 887/1602/60 888/1601/60 890/1605/60 889/1606/60 +f 841/1607/69 842/1608/69 844/1604/69 843/1603/69 +f 889/1606/61 890/1605/61 892/1609/61 891/1610/61 +f 839/1611/68 840/1612/68 842/1608/68 841/1607/68 +f 891/1610/62 892/1609/62 894/1613/62 893/1614/62 +f 837/1615/67 838/1616/67 840/1612/67 839/1611/67 +f 893/1614/63 894/1613/63 896/1617/63 895/1618/63 +f 835/1619/66 836/1620/66 838/1616/66 837/1615/66 +f 895/1618/64 896/1617/64 898/1621/64 897/1622/64 +f 833/1623/65 834/1624/65 836/1620/65 835/1619/65 +f 897/1622/65 898/1621/65 900/1625/65 899/1626/65 +f 831/1627/64 832/1628/64 834/1624/64 833/1623/64 +f 899/1626/66 900/1625/66 902/1629/66 901/1630/66 +f 829/1631/63 830/1632/63 832/1628/63 831/1627/63 +f 901/1630/67 902/1629/67 904/1633/67 903/1634/67 +f 827/1635/62 828/1636/62 830/1632/62 829/1631/62 +f 903/1634/68 904/1633/68 906/1637/68 905/1638/68 +f 825/1639/61 826/1640/61 828/1636/61 827/1635/61 +f 905/1638/69 906/1637/69 908/1641/69 907/1642/69 +f 823/1643/60 824/1644/60 826/1640/60 825/1639/60 +f 907/1642/70 908/1641/70 910/1645/70 909/1646/70 +f 821/1647/59 822/1648/59 824/1644/59 823/1643/59 +f 909/1646/71 910/1645/71 912/1649/71 911/1650/71 +f 819/1651/58 820/1652/58 822/1648/58 821/1647/58 +f 911/1650/72 912/1649/72 914/1653/72 913/1654/72 +f 817/1655/57 818/1656/57 820/1652/57 819/1651/57 +f 913/1654/73 914/1653/73 916/1657/73 915/1658/73 +f 815/1659/56 816/1660/56 818/1656/56 817/1655/56 +f 915/1658/74 916/1657/74 918/1661/74 917/1662/74 +f 813/1663/55 814/1664/55 816/1660/55 815/1659/55 +f 917/1662/75 918/1661/75 920/1665/75 919/1666/75 +f 811/1667/54 812/1668/54 814/1664/54 813/1663/54 +f 919/1666/76 920/1665/76 922/1669/76 921/1670/76 +f 809/1671/53 810/1672/53 812/1668/53 811/1667/53 +f 921/1670/77 922/1669/77 924/1673/77 923/1674/77 +f 807/1675/52 808/1676/52 810/1672/52 809/1671/52 +f 866/1677/21 863/1678/21 926/1679/21 924/1680/21 922/1681/21 920/1682/21 918/1683/21 916/1684/21 914/1685/21 912/1686/21 910/1687/21 908/1688/21 906/1689/21 904/1690/21 902/1691/21 900/1692/21 898/1693/21 896/1694/21 894/1695/21 892/1696/21 890/1697/21 888/1698/21 886/1699/21 884/1700/21 882/1701/21 880/1702/21 878/1703/21 876/1704/21 874/1705/21 872/1706/21 870/1707/21 868/1708/21 +f 805/1709/51 806/1710/51 808/1676/51 807/1675/51 +f 736/1711/25 801/1712/25 803/1713/25 805/1714/25 807/1715/25 809/1716/25 811/1717/25 813/1718/25 815/1719/25 817/1720/25 819/1721/25 821/1722/25 823/1723/25 825/1724/25 827/1725/25 829/1726/25 831/1727/25 833/1728/25 835/1729/25 837/1730/25 839/1731/25 841/1732/25 843/1733/25 845/1734/25 847/1735/25 849/1736/25 851/1737/25 853/1738/25 855/1739/25 857/1740/25 859/1741/25 861/1742/25 +f 803/1743/50 804/1744/50 806/1710/50 805/1709/50 +f 861/1745/79 862/1746/79 735/1747/79 736/1748/79 +f 801/1749/49 802/1750/49 804/1744/49 803/1743/49 +f 736/1751/48 735/1752/48 802/1750/48 801/1749/48 +f 871/1506/52 872/1505/52 874/1576/52 873/1575/52 +f 859/1574/78 860/1573/78 862/1746/78 861/1745/78 +f 867/1753/50 868/1754/50 870/1504/50 869/1503/50 +f 925/1755/79 926/1756/79 863/1757/79 864/1758/79 +f 865/1759/49 866/1760/49 868/1754/49 867/1753/49 +f 864/1761/48 863/1762/48 866/1760/48 865/1759/48 +f 923/1674/78 924/1673/78 926/1756/78 925/1755/78 +f 686/1447/468 685/1445/468 973/1763/468 974/1764/468 +f 673/1448/469 672/1446/469 960/1765/469 961/1766/469 +f 687/1449/470 686/1447/470 974/1764/470 975/1767/470 +f 674/1450/471 673/1448/471 961/1766/471 962/1768/471 +f 688/1451/472 687/1449/472 975/1767/472 976/1769/472 +f 675/1452/473 674/1450/473 962/1768/473 963/1770/473 +f 662/1454/474 661/1453/474 949/1771/474 950/1772/474 +f 689/1455/475 688/1451/475 976/1769/475 977/1773/475 +f 676/1456/476 675/1452/476 963/1770/476 964/1774/476 +f 663/1457/477 662/1454/477 950/1772/477 951/1775/477 +f 690/1458/478 689/1455/478 977/1773/478 978/1776/478 +f 677/1459/479 676/1456/479 964/1774/479 965/1777/479 +f 664/1460/480 663/1457/480 951/1775/480 952/1778/480 +f 691/1461/481 690/1458/481 978/1776/481 979/1779/481 +f 678/1462/482 677/1459/482 965/1777/482 966/1780/482 +f 665/1463/483 664/1460/483 952/1778/483 953/1781/483 +f 692/1464/484 691/1461/484 979/1779/484 980/1782/484 +f 679/1465/485 678/1462/485 966/1780/485 967/1783/485 +f 666/1466/486 665/1463/486 953/1781/486 954/1784/486 +f 661/1453/487 692/1464/487 980/1782/487 949/1771/487 +f 680/1467/488 679/1465/488 967/1783/488 968/1785/488 +f 667/1468/489 666/1466/489 954/1784/489 955/1786/489 +f 681/1469/490 680/1467/490 968/1785/490 969/1787/490 +f 668/1470/491 667/1468/491 955/1786/491 956/1788/491 +f 682/1439/492 681/1469/492 969/1787/492 970/1789/492 +f 669/1441/493 668/1470/493 956/1788/493 957/1790/493 +f 683/1440/494 682/1439/494 970/1789/494 971/1791/494 +f 670/1442/495 669/1441/495 957/1790/495 958/1792/495 +f 684/1443/496 683/1440/496 971/1791/496 972/1793/496 +f 671/1444/497 670/1442/497 958/1792/497 959/1794/497 +f 685/1445/498 684/1443/498 972/1793/498 973/1763/498 +f 672/1446/499 671/1444/499 959/1794/499 960/1765/499 +f 950/1772/25 949/1771/25 980/1782/25 979/1779/25 978/1776/25 977/1773/25 976/1769/25 975/1767/25 974/1764/25 973/1763/25 972/1793/25 971/1791/25 970/1789/25 969/1787/25 968/1785/25 967/1783/25 966/1780/25 965/1777/25 964/1774/25 963/1770/25 962/1768/25 961/1766/25 960/1765/25 959/1794/25 958/1792/25 957/1790/25 956/1788/25 955/1786/25 954/1784/25 953/1781/25 952/1778/25 951/1775/25 +f 998/1149/335 990/1150/335 993/585/335 994/871/335 1003/873/335 1004/872/335 989/897/335 997/898/335 +f 1000/632/336 998/1149/336 997/898/336 1009/879/336 999/878/336 +f 989/897/500 1022/366/500 1046/346/500 1024/899/500 997/898/500 +f 1287/1795/501 1319/1796/501 1320/1797/501 1288/1798/501 +f 1274/1799/502 1306/1800/502 1307/1801/502 1275/1802/502 +f 1288/1798/503 1320/1797/503 1321/1803/503 1289/1804/503 +f 1275/1802/504 1307/1801/504 1308/1805/504 1276/1806/504 +f 1289/1804/505 1321/1803/505 1322/1807/505 1290/1808/505 +f 1276/1806/506 1308/1805/506 1309/1809/506 1277/1810/506 +f 1290/1808/507 1322/1807/507 1323/1811/507 1291/1812/507 +f 1277/1810/508 1309/1809/508 1310/1813/508 1278/1814/508 +f 1291/1812/509 1323/1811/509 1324/1815/509 1292/1816/509 +f 1278/1814/510 1310/1813/510 1311/1817/510 1279/1818/510 +f 1292/1816/511 1324/1815/511 1325/1819/511 1293/1820/511 +f 1279/1818/512 1311/1817/512 1312/1821/512 1280/1822/512 +f 1266/1823/513 1298/1824/513 1299/1825/513 1267/1826/513 +f 1293/1820/514 1325/1819/514 1326/1827/514 1294/1828/514 +f 1280/1822/515 1312/1821/515 1313/1829/515 1281/1830/515 +f 1267/1826/516 1299/1825/516 1300/1831/516 1268/1832/516 +f 1294/1828/517 1326/1827/517 1327/1833/517 1295/1834/517 +f 1281/1830/518 1313/1829/518 1314/1835/518 1282/1836/518 +f 1268/1832/519 1300/1831/519 1301/1837/519 1269/1838/519 +f 1295/1834/520 1327/1833/520 1328/1839/520 1296/1840/520 +f 1282/1836/521 1314/1835/521 1315/1841/521 1283/1842/521 +f 1269/1838/522 1301/1837/522 1302/1843/522 1270/1844/522 +f 1296/1840/523 1328/1839/523 1329/1845/523 1297/1846/523 +f 1283/1842/524 1315/1841/524 1316/1847/524 1284/1848/524 +f 1270/1844/525 1302/1843/525 1303/1849/525 1271/1850/525 +f 1297/1846/526 1329/1845/526 1298/1824/526 1266/1823/526 +f 1284/1848/527 1316/1847/527 1317/1851/527 1285/1852/527 +f 1271/1850/528 1303/1849/528 1304/1853/528 1272/1854/528 +f 1285/1852/529 1317/1851/529 1318/1855/529 1286/1856/529 +f 1272/1854/530 1304/1853/530 1305/1857/530 1273/1858/530 +f 1286/1856/531 1318/1855/531 1319/1796/531 1287/1795/531 +f 1273/1858/532 1305/1857/532 1306/1800/532 1274/1799/532 +f 1314/1835/533 1346/1859/533 1347/1860/533 1315/1841/533 +f 1301/1837/534 1333/1861/534 1334/1862/534 1302/1843/534 +f 1328/1839/535 1360/1863/535 1361/1864/535 1329/1845/535 +f 1315/1841/536 1347/1860/536 1348/1865/536 1316/1847/536 +f 1302/1843/537 1334/1862/537 1335/1866/537 1303/1849/537 +f 1329/1845/538 1361/1864/538 1330/1867/538 1298/1824/538 +f 1316/1847/539 1348/1865/539 1349/1868/539 1317/1851/539 +f 1303/1849/540 1335/1866/540 1336/1869/540 1304/1853/540 +f 1317/1851/541 1349/1868/541 1350/1870/541 1318/1855/541 +f 1304/1853/542 1336/1869/542 1337/1871/542 1305/1857/542 +f 1318/1855/543 1350/1870/543 1351/1872/543 1319/1796/543 +f 1305/1857/544 1337/1871/544 1338/1873/544 1306/1800/544 +f 1319/1796/545 1351/1872/545 1352/1874/545 1320/1797/545 +f 1306/1800/546 1338/1873/546 1339/1875/546 1307/1801/546 +f 1320/1797/547 1352/1874/547 1353/1876/547 1321/1803/547 +f 1307/1801/548 1339/1875/548 1340/1877/548 1308/1805/548 +f 1321/1803/549 1353/1876/549 1354/1878/549 1322/1807/549 +f 1308/1805/550 1340/1877/550 1341/1879/550 1309/1809/550 +f 1322/1807/551 1354/1878/551 1355/1880/551 1323/1811/551 +f 1309/1809/552 1341/1879/552 1342/1881/552 1310/1813/552 +f 1323/1811/553 1355/1880/553 1356/1882/553 1324/1815/553 +f 1310/1813/554 1342/1881/554 1343/1883/554 1311/1817/554 +f 1324/1815/555 1356/1882/555 1357/1884/555 1325/1819/555 +f 1311/1817/556 1343/1883/556 1344/1885/556 1312/1821/556 +f 1298/1824/557 1330/1867/557 1331/1886/557 1299/1825/557 +f 1325/1819/558 1357/1884/558 1358/1887/558 1326/1827/558 +f 1312/1821/559 1344/1885/559 1345/1888/559 1313/1829/559 +f 1299/1825/560 1331/1886/560 1332/1889/560 1300/1831/560 +f 1326/1827/561 1358/1887/561 1359/1890/561 1327/1833/561 +f 1313/1829/562 1345/1888/562 1346/1859/562 1314/1835/562 +f 1300/1831/563 1332/1889/563 1333/1861/563 1301/1837/563 +f 1327/1833/564 1359/1890/564 1360/1863/564 1328/1839/564 +f 1349/1868/565 1381/1891/565 1382/1892/565 1350/1870/565 +f 1336/1869/566 1368/1893/566 1369/1894/566 1337/1871/566 +f 1350/1870/567 1382/1892/567 1383/1895/567 1351/1872/567 +f 1337/1871/568 1369/1894/568 1370/1896/568 1338/1873/568 +f 1351/1872/569 1383/1895/569 1384/1897/569 1352/1874/569 +f 1338/1873/570 1370/1896/570 1371/1898/570 1339/1875/570 +f 1352/1874/571 1384/1897/571 1385/1899/571 1353/1876/571 +f 1339/1875/572 1371/1898/572 1372/1900/572 1340/1877/572 +f 1353/1876/573 1385/1899/573 1386/1901/573 1354/1878/573 +f 1340/1877/574 1372/1900/574 1373/1902/574 1341/1879/574 +f 1354/1878/575 1386/1901/575 1387/1903/575 1355/1880/575 +f 1341/1879/576 1373/1902/576 1374/1904/576 1342/1881/576 +f 1355/1880/577 1387/1903/577 1388/1905/577 1356/1882/577 +f 1342/1881/578 1374/1904/578 1375/1906/578 1343/1883/578 +f 1356/1882/579 1388/1905/579 1389/1907/579 1357/1884/579 +f 1343/1883/580 1375/1906/580 1376/1908/580 1344/1885/580 +f 1330/1867/581 1362/1909/581 1363/1910/581 1331/1886/581 +f 1357/1884/582 1389/1907/582 1390/1911/582 1358/1887/582 +f 1344/1885/583 1376/1908/583 1377/1912/583 1345/1888/583 +f 1331/1886/584 1363/1910/584 1364/1913/584 1332/1889/584 +f 1358/1887/585 1390/1911/585 1391/1914/585 1359/1890/585 +f 1345/1888/586 1377/1912/586 1378/1915/586 1346/1859/586 +f 1332/1889/587 1364/1913/587 1365/1916/587 1333/1861/587 +f 1359/1890/588 1391/1914/588 1392/1917/588 1360/1863/588 +f 1346/1859/589 1378/1915/589 1379/1918/589 1347/1860/589 +f 1333/1861/590 1365/1916/590 1366/1919/590 1334/1862/590 +f 1360/1863/591 1392/1917/591 1393/1920/591 1361/1864/591 +f 1347/1860/592 1379/1918/592 1380/1921/592 1348/1865/592 +f 1334/1862/593 1366/1919/593 1367/1922/593 1335/1866/593 +f 1361/1864/594 1393/1920/594 1362/1909/594 1330/1867/594 +f 1348/1865/595 1380/1921/595 1381/1891/595 1349/1868/595 +f 1335/1866/596 1367/1922/596 1368/1893/596 1336/1869/596 +f 1288/1798/58 1416/1923/58 1415/1924/58 1287/1795/58 +f 1275/1802/71 1403/1925/71 1402/1926/71 1274/1799/71 +f 1289/1804/57 1417/1927/57 1416/1923/57 1288/1798/57 +f 1276/1806/70 1404/1928/70 1403/1925/70 1275/1802/70 +f 1290/1808/56 1418/1929/56 1417/1927/56 1289/1804/56 +f 1277/1810/69 1405/1930/69 1404/1928/69 1276/1806/69 +f 1291/1812/55 1419/1931/55 1418/1929/55 1290/1808/55 +f 1278/1814/68 1406/1932/68 1405/1930/68 1277/1810/68 +f 1292/1816/54 1420/1933/54 1419/1931/54 1291/1812/54 +f 1279/1818/67 1407/1934/67 1406/1932/67 1278/1814/67 +f 1293/1820/53 1421/1935/53 1420/1933/53 1292/1816/53 +f 1280/1822/66 1408/1936/66 1407/1934/66 1279/1818/66 +f 1267/1826/79 1395/1937/79 1394/1938/79 1266/1823/79 +f 1294/1828/52 1422/1939/52 1421/1935/52 1293/1820/52 +f 1281/1830/65 1409/1940/65 1408/1936/65 1280/1822/65 +f 1268/1832/78 1396/1941/78 1395/1937/78 1267/1826/78 +f 1295/1834/51 1423/1942/51 1422/1939/51 1294/1828/51 +f 1282/1836/64 1410/1943/64 1409/1940/64 1281/1830/64 +f 1269/1838/77 1397/1944/77 1396/1941/77 1268/1832/77 +f 1296/1840/50 1424/1945/50 1423/1942/50 1295/1834/50 +f 1283/1842/63 1411/1946/63 1410/1943/63 1282/1836/63 +f 1270/1844/76 1398/1947/76 1397/1944/76 1269/1838/76 +f 1297/1846/49 1425/1948/49 1424/1945/49 1296/1840/49 +f 1284/1848/62 1412/1949/62 1411/1946/62 1283/1842/62 +f 1271/1850/75 1399/1950/75 1398/1947/75 1270/1844/75 +f 1266/1823/48 1394/1938/48 1425/1948/48 1297/1846/48 +f 1285/1852/61 1413/1951/61 1412/1949/61 1284/1848/61 +f 1272/1854/74 1400/1952/74 1399/1950/74 1271/1850/74 +f 1286/1856/60 1414/1953/60 1413/1951/60 1285/1852/60 +f 1273/1858/73 1401/1954/73 1400/1952/73 1272/1854/73 +f 1287/1795/59 1415/1924/59 1414/1953/59 1286/1856/59 +f 1274/1799/72 1402/1926/72 1401/1954/72 1273/1858/72 +f 1552/1955/501 1584/1956/501 1585/1957/501 1553/1958/501 +f 1539/1959/597 1571/1960/597 1572/1961/597 1540/1962/597 +f 1553/1958/503 1585/1957/503 1586/1963/503 1554/1964/503 +f 1540/1962/504 1572/1961/504 1573/1965/504 1541/1966/504 +f 1554/1964/505 1586/1963/505 1587/1967/505 1555/1968/505 +f 1541/1966/506 1573/1965/506 1574/1969/506 1542/1970/506 +f 1555/1968/507 1587/1967/507 1588/1971/507 1556/1972/507 +f 1542/1970/508 1574/1969/508 1575/1973/508 1543/1974/508 +f 1556/1972/509 1588/1971/509 1589/1975/509 1557/1976/509 +f 1543/1974/510 1575/1973/510 1576/1977/510 1544/1978/510 +f 1557/1976/511 1589/1975/511 1590/1979/511 1558/1980/511 +f 1544/1978/512 1576/1977/512 1577/1981/512 1545/1982/512 +f 1531/1983/598 1563/1984/598 1564/1985/598 1532/1986/598 +f 1558/1980/514 1590/1979/514 1591/1987/514 1559/1988/514 +f 1545/1982/515 1577/1981/515 1578/1989/515 1546/1990/515 +f 1532/1986/516 1564/1985/516 1565/1991/516 1533/1992/516 +f 1559/1988/517 1591/1987/517 1592/1993/517 1560/1994/517 +f 1546/1990/518 1578/1989/518 1579/1995/518 1547/1996/518 +f 1533/1992/519 1565/1991/519 1566/1997/519 1534/1998/519 +f 1560/1994/520 1592/1993/520 1593/1999/520 1561/2000/520 +f 1547/1996/521 1579/1995/521 1580/2001/521 1548/2002/521 +f 1534/1998/522 1566/1997/522 1567/2003/522 1535/2004/522 +f 1561/2000/523 1593/1999/523 1594/2005/523 1562/2006/523 +f 1548/2002/524 1580/2001/524 1581/2007/524 1549/2008/524 +f 1535/2004/525 1567/2003/525 1568/2009/525 1536/2010/525 +f 1562/2006/526 1594/2005/526 1563/1984/526 1531/1983/526 +f 1549/2008/527 1581/2007/527 1582/2011/527 1550/2012/527 +f 1536/2010/528 1568/2009/528 1569/2013/528 1537/2014/528 +f 1550/2012/529 1582/2011/529 1583/2015/529 1551/2016/529 +f 1537/2014/530 1569/2013/530 1570/2017/530 1538/2018/530 +f 1551/2016/531 1583/2015/531 1584/1956/531 1552/1955/531 +f 1538/2018/532 1570/2017/532 1571/1960/532 1539/1959/532 +f 1579/1995/533 1611/2019/533 1612/2020/533 1580/2001/533 +f 1566/1997/534 1598/2021/534 1599/2022/534 1567/2003/534 +f 1593/1999/535 1625/2023/535 1626/2024/535 1594/2005/535 +f 1580/2001/536 1612/2020/536 1613/2025/536 1581/2007/536 +f 1567/2003/537 1599/2022/537 1600/2026/537 1568/2009/537 +f 1594/2005/538 1626/2024/538 1595/2027/538 1563/1984/538 +f 1581/2007/539 1613/2025/539 1614/2028/539 1582/2011/539 +f 1568/2009/540 1600/2026/540 1601/2029/540 1569/2013/540 +f 1582/2011/541 1614/2028/541 1615/2030/541 1583/2015/541 +f 1569/2013/542 1601/2029/542 1602/2031/542 1570/2017/542 +f 1583/2015/543 1615/2030/543 1616/2032/543 1584/1956/543 +f 1570/2017/544 1602/2031/544 1603/2033/544 1571/1960/544 +f 1584/1956/545 1616/2032/545 1617/2034/545 1585/1957/545 +f 1571/1960/546 1603/2033/546 1604/2035/546 1572/1961/546 +f 1585/1957/547 1617/2034/547 1618/2036/547 1586/1963/547 +f 1572/1961/548 1604/2035/548 1605/2037/548 1573/1965/548 +f 1586/1963/549 1618/2036/549 1619/2038/549 1587/1967/549 +f 1573/1965/550 1605/2037/550 1606/2039/550 1574/1969/550 +f 1587/1967/551 1619/2038/551 1620/2040/551 1588/1971/551 +f 1574/1969/552 1606/2039/552 1607/2041/552 1575/1973/552 +f 1588/1971/553 1620/2040/553 1621/2042/553 1589/1975/553 +f 1575/1973/554 1607/2041/554 1608/2043/554 1576/1977/554 +f 1589/1975/555 1621/2042/555 1622/2044/555 1590/1979/555 +f 1576/1977/556 1608/2043/556 1609/2045/556 1577/1981/556 +f 1563/1984/557 1595/2027/557 1596/2046/557 1564/1985/557 +f 1590/1979/558 1622/2044/558 1623/2047/558 1591/1987/558 +f 1577/1981/559 1609/2045/559 1610/2048/559 1578/1989/559 +f 1564/1985/560 1596/2046/560 1597/2049/560 1565/1991/560 +f 1591/1987/561 1623/2047/561 1624/2050/561 1592/1993/561 +f 1578/1989/562 1610/2048/562 1611/2019/562 1579/1995/562 +f 1565/1991/563 1597/2049/563 1598/2021/563 1566/1997/563 +f 1592/1993/564 1624/2050/564 1625/2023/564 1593/1999/564 +f 1614/2028/565 1646/2051/565 1647/2052/565 1615/2030/565 +f 1601/2029/566 1633/2053/566 1634/2054/566 1602/2031/566 +f 1615/2030/567 1647/2052/567 1648/2055/567 1616/2032/567 +f 1602/2031/568 1634/2054/568 1635/2056/568 1603/2033/568 +f 1616/2032/569 1648/2055/569 1649/2057/569 1617/2034/569 +f 1603/2033/570 1635/2056/570 1636/2058/570 1604/2035/570 +f 1617/2034/571 1649/2057/571 1650/2059/571 1618/2036/571 +f 1604/2035/572 1636/2058/572 1637/2060/572 1605/2037/572 +f 1618/2036/573 1650/2059/573 1651/2061/573 1619/2038/573 +f 1605/2037/574 1637/2060/574 1638/2062/574 1606/2039/574 +f 1619/2038/575 1651/2061/575 1652/2063/575 1620/2040/575 +f 1606/2039/576 1638/2062/576 1639/2064/576 1607/2041/576 +f 1620/2040/577 1652/2063/577 1653/2065/577 1621/2042/577 +f 1607/2041/578 1639/2064/578 1640/2066/578 1608/2043/578 +f 1621/2042/579 1653/2065/579 1654/2067/579 1622/2044/579 +f 1608/2043/580 1640/2066/580 1641/2068/580 1609/2045/580 +f 1595/2027/581 1627/2069/581 1628/2070/581 1596/2046/581 +f 1622/2044/582 1654/2067/582 1655/2071/582 1623/2047/582 +f 1609/2045/583 1641/2068/583 1642/2072/583 1610/2048/583 +f 1596/2046/584 1628/2070/584 1629/2073/584 1597/2049/584 +f 1623/2047/585 1655/2071/585 1656/2074/585 1624/2050/585 +f 1610/2048/586 1642/2072/586 1643/2075/586 1611/2019/586 +f 1597/2049/587 1629/2073/587 1630/2076/587 1598/2021/587 +f 1624/2050/588 1656/2074/588 1657/2077/588 1625/2023/588 +f 1611/2019/589 1643/2075/589 1644/2078/589 1612/2020/589 +f 1598/2021/590 1630/2076/590 1631/2079/590 1599/2022/590 +f 1625/2023/591 1657/2077/591 1658/2080/591 1626/2024/591 +f 1612/2020/592 1644/2078/592 1645/2081/592 1613/2025/592 +f 1599/2022/593 1631/2079/593 1632/2082/593 1600/2026/593 +f 1626/2024/594 1658/2080/594 1627/2069/594 1595/2027/594 +f 1613/2025/595 1645/2081/595 1646/2051/595 1614/2028/595 +f 1600/2026/596 1632/2082/596 1633/2053/596 1601/2029/596 +f 1553/1958/58 1681/2083/58 1680/2084/58 1552/1955/58 +f 1540/1962/71 1668/2085/71 1667/2086/71 1539/1959/71 +f 1554/1964/57 1682/2087/57 1681/2083/57 1553/1958/57 +f 1541/1966/70 1669/2088/70 1668/2085/70 1540/1962/70 +f 1555/1968/56 1683/2089/56 1682/2087/56 1554/1964/56 +f 1542/1970/69 1670/2090/69 1669/2088/69 1541/1966/69 +f 1556/1972/55 1684/2091/55 1683/2089/55 1555/1968/55 +f 1543/1974/68 1671/2092/68 1670/2090/68 1542/1970/68 +f 1557/1976/54 1685/2093/54 1684/2091/54 1556/1972/54 +f 1544/1978/67 1672/2094/67 1671/2092/67 1543/1974/67 +f 1558/1980/53 1686/2095/53 1685/2093/53 1557/1976/53 +f 1545/1982/66 1673/2096/66 1672/2094/66 1544/1978/66 +f 1532/1986/79 1660/2097/79 1659/2098/79 1531/1983/79 +f 1559/1988/52 1687/2099/52 1686/2095/52 1558/1980/52 +f 1546/1990/65 1674/2100/65 1673/2096/65 1545/1982/65 +f 1533/1992/78 1661/2101/78 1660/2097/78 1532/1986/78 +f 1560/1994/51 1688/2102/51 1687/2099/51 1559/1988/51 +f 1547/1996/64 1675/2103/64 1674/2100/64 1546/1990/64 +f 1534/1998/77 1662/2104/77 1661/2101/77 1533/1992/77 +f 1561/2000/50 1689/2105/50 1688/2102/50 1560/1994/50 +f 1548/2002/63 1676/2106/63 1675/2103/63 1547/1996/63 +f 1535/2004/76 1663/2107/76 1662/2104/76 1534/1998/76 +f 1562/2006/49 1690/2108/49 1689/2105/49 1561/2000/49 +f 1549/2008/62 1677/2109/62 1676/2106/62 1548/2002/62 +f 1536/2010/75 1664/2110/75 1663/2107/75 1535/2004/75 +f 1531/1983/48 1659/2098/48 1690/2108/48 1562/2006/48 +f 1550/2012/61 1678/2111/61 1677/2109/61 1549/2008/61 +f 1537/2014/74 1665/2112/74 1664/2110/74 1536/2010/74 +f 1551/2016/60 1679/2113/60 1678/2111/60 1550/2012/60 +f 1538/2018/73 1666/2114/73 1665/2112/73 1537/2014/73 +f 1552/1955/59 1680/2084/59 1679/2113/59 1551/2016/59 +f 1539/1959/72 1667/2086/72 1666/2114/72 1538/2018/72 +f 1412/1949/599 1721/2115/599 1720/2116/599 1411/1946/599 +f 1399/1950/600 1708/2117/600 1707/2118/600 1398/1947/600 +f 1394/1938/601 1703/2119/601 1734/2120/601 1425/1948/601 +f 1413/1951/602 1722/2121/602 1721/2115/602 1412/1949/602 +f 1400/1952/603 1709/2122/603 1708/2117/603 1399/1950/603 +f 1414/1953/604 1723/2123/604 1722/2121/604 1413/1951/604 +f 1401/1954/605 1710/2124/605 1709/2122/605 1400/1952/605 +f 1415/1924/606 1724/2125/606 1723/2123/606 1414/1953/606 +f 1402/1926/607 1711/2126/607 1710/2124/607 1401/1954/607 +f 1416/1923/608 1725/2127/608 1724/2125/608 1415/1924/608 +f 1403/1925/609 1712/2128/609 1711/2126/609 1402/1926/609 +f 1417/1927/610 1726/2129/610 1725/2127/610 1416/1923/610 +f 1404/1928/611 1713/2130/611 1712/2128/611 1403/1925/611 +f 1418/1929/612 1727/2131/612 1726/2129/612 1417/1927/612 +f 1405/1930/613 1714/2132/613 1713/2130/613 1404/1928/613 +f 1419/1931/614 1728/2133/614 1727/2131/614 1418/1929/614 +f 1406/1932/615 1715/2134/615 1714/2132/615 1405/1930/615 +f 1420/1933/616 1729/2135/616 1728/2133/616 1419/1931/616 +f 1407/1934/617 1716/2136/617 1715/2134/617 1406/1932/617 +f 1421/1935/618 1730/2137/618 1729/2135/618 1420/1933/618 +f 1408/1936/619 1717/2138/619 1716/2136/619 1407/1934/619 +f 1395/1937/620 1704/2139/620 1703/2119/620 1394/1938/620 +f 1422/1939/621 1731/2140/621 1730/2137/621 1421/1935/621 +f 1409/1940/622 1718/2141/622 1717/2138/622 1408/1936/622 +f 1396/1941/623 1705/2142/623 1704/2139/623 1395/1937/623 +f 1423/1942/624 1732/2143/624 1731/2140/624 1422/1939/624 +f 1410/1943/625 1719/2144/625 1718/2141/625 1409/1940/625 +f 1397/1944/626 1706/2145/626 1705/2142/626 1396/1941/626 +f 1424/1945/627 1733/2146/627 1732/2143/627 1423/1942/627 +f 1411/1946/628 1720/2116/628 1719/2144/628 1410/1943/628 +f 1398/1947/629 1707/2118/629 1706/2145/629 1397/1944/629 +f 1425/1948/630 1734/2120/630 1733/2146/630 1424/1945/630 +f 1704/2139/21 1705/2142/21 1706/2145/21 1707/2118/21 1708/2117/21 1709/2122/21 1710/2124/21 1711/2126/21 1712/2128/21 1713/2130/21 1714/2132/21 1715/2134/21 1716/2136/21 1717/2138/21 1718/2141/21 1719/2144/21 1720/2116/21 1721/2115/21 1722/2121/21 1723/2123/21 1724/2125/21 1725/2127/21 1726/2129/21 1727/2131/21 1728/2133/21 1729/2135/21 1730/2137/21 1731/2140/21 1732/2143/21 1733/2146/21 1734/2120/21 1703/2119/21 +f 1869/2147/51 1871/2148/51 1872/2149/51 1870/2150/51 +f 1802/2151/25 1804/2152/25 1806/2153/25 1808/2154/25 1810/2155/25 1812/2156/25 1814/2157/25 1816/2158/25 1818/2159/25 1820/2160/25 1822/2161/25 1824/2162/25 1826/2163/25 1828/2164/25 1830/2165/25 1832/2166/25 1834/2167/25 1836/2168/25 1838/2169/25 1840/2170/25 1842/2171/25 1844/2172/25 1846/2173/25 1848/2174/25 1850/2175/25 1852/2176/25 1854/2177/25 1856/2178/25 1858/2179/25 1860/2180/25 1862/2181/25 1735/2182/25 +f 1864/2183/21 1925/2184/21 1923/2185/21 1921/2186/21 1919/2187/21 1917/2188/21 1915/2189/21 1913/2190/21 1911/2191/21 1909/2192/21 1907/2193/21 1905/2194/21 1903/2195/21 1901/2196/21 1899/2197/21 1897/2198/21 1895/2199/21 1893/2200/21 1891/2201/21 1889/2202/21 1887/2203/21 1885/2204/21 1883/2205/21 1881/2206/21 1879/2207/21 1877/2208/21 1875/2209/21 1873/2210/21 1871/2211/21 1869/2212/21 1867/2213/21 1865/2214/21 +f 1857/2215/77 1859/2216/77 1860/2217/77 1858/2218/77 +f 1873/2219/53 1875/2220/53 1876/2221/53 1874/2222/53 +f 1855/2223/76 1857/2215/76 1858/2218/76 1856/2224/76 +f 1875/2220/54 1877/2225/54 1878/2226/54 1876/2221/54 +f 1853/2227/75 1855/2223/75 1856/2224/75 1854/2228/75 +f 1877/2225/55 1879/2229/55 1880/2230/55 1878/2226/55 +f 1851/2231/74 1853/2227/74 1854/2228/74 1852/2232/74 +f 1879/2229/56 1881/2233/56 1882/2234/56 1880/2230/56 +f 1849/2235/73 1851/2231/73 1852/2232/73 1850/2236/73 +f 1881/2233/57 1883/2237/57 1884/2238/57 1882/2234/57 +f 1847/2239/72 1849/2235/72 1850/2236/72 1848/2240/72 +f 1883/2237/58 1885/2241/58 1886/2242/58 1884/2238/58 +f 1845/2243/71 1847/2239/71 1848/2240/71 1846/2244/71 +f 1885/2241/59 1887/2245/59 1888/2246/59 1886/2242/59 +f 1843/2247/70 1845/2243/70 1846/2244/70 1844/2248/70 +f 1887/2245/60 1889/2249/60 1890/2250/60 1888/2246/60 +f 1841/2251/69 1843/2247/69 1844/2248/69 1842/2252/69 +f 1889/2249/61 1891/2253/61 1892/2254/61 1890/2250/61 +f 1839/2255/68 1841/2251/68 1842/2252/68 1840/2256/68 +f 1891/2253/62 1893/2257/62 1894/2258/62 1892/2254/62 +f 1837/2259/67 1839/2255/67 1840/2256/67 1838/2260/67 +f 1893/2257/63 1895/2261/63 1896/2262/63 1894/2258/63 +f 1835/2263/66 1837/2259/66 1838/2260/66 1836/2264/66 +f 1895/2261/64 1897/2265/64 1898/2266/64 1896/2262/64 +f 1833/2267/65 1835/2263/65 1836/2264/65 1834/2268/65 +f 1897/2265/65 1899/2269/65 1900/2270/65 1898/2266/65 +f 1831/2271/64 1833/2267/64 1834/2268/64 1832/2272/64 +f 1899/2269/66 1901/2273/66 1902/2274/66 1900/2270/66 +f 1829/2275/63 1831/2271/63 1832/2272/63 1830/2276/63 +f 1901/2273/67 1903/2277/67 1904/2278/67 1902/2274/67 +f 1827/2279/62 1829/2275/62 1830/2276/62 1828/2280/62 +f 1903/2277/68 1905/2281/68 1906/2282/68 1904/2278/68 +f 1825/2283/61 1827/2279/61 1828/2280/61 1826/2284/61 +f 1905/2281/69 1907/2285/69 1908/2286/69 1906/2282/69 +f 1823/2287/60 1825/2283/60 1826/2284/60 1824/2288/60 +f 1907/2285/70 1909/2289/70 1910/2290/70 1908/2286/70 +f 1821/2291/59 1823/2287/59 1824/2288/59 1822/2292/59 +f 1909/2289/71 1911/2293/71 1912/2294/71 1910/2290/71 +f 1819/2295/58 1821/2291/58 1822/2292/58 1820/2296/58 +f 1911/2293/72 1913/2297/72 1914/2298/72 1912/2294/72 +f 1817/2299/57 1819/2295/57 1820/2296/57 1818/2300/57 +f 1913/2297/73 1915/2301/73 1916/2302/73 1914/2298/73 +f 1815/2303/56 1817/2299/56 1818/2300/56 1816/2304/56 +f 1915/2301/74 1917/2305/74 1918/2306/74 1916/2302/74 +f 1813/2307/55 1815/2303/55 1816/2304/55 1814/2308/55 +f 1917/2305/75 1919/2309/75 1920/2310/75 1918/2306/75 +f 1811/2311/54 1813/2307/54 1814/2308/54 1812/2312/54 +f 1919/2309/76 1921/2313/76 1922/2314/76 1920/2310/76 +f 1809/2315/53 1811/2311/53 1812/2312/53 1810/2316/53 +f 1921/2313/77 1923/2317/77 1924/2318/77 1922/2314/77 +f 1807/2319/52 1809/2315/52 1810/2316/52 1808/2320/52 +f 1866/2321/25 1868/2322/25 1870/2323/25 1872/2324/25 1874/2325/25 1876/2326/25 1878/2327/25 1880/2328/25 1882/2329/25 1884/2330/25 1886/2331/25 1888/2332/25 1890/2333/25 1892/2334/25 1894/2335/25 1896/2336/25 1898/2337/25 1900/2338/25 1902/2339/25 1904/2340/25 1906/2341/25 1908/2342/25 1910/2343/25 1912/2344/25 1914/2345/25 1916/2346/25 1918/2347/25 1920/2348/25 1922/2349/25 1924/2350/25 1926/2351/25 1863/2352/25 +f 1805/2353/51 1807/2319/51 1808/2320/51 1806/2354/51 +f 1736/2355/21 1861/2356/21 1859/2357/21 1857/2358/21 1855/2359/21 1853/2360/21 1851/2361/21 1849/2362/21 1847/2363/21 1845/2364/21 1843/2365/21 1841/2366/21 1839/2367/21 1837/2368/21 1835/2369/21 1833/2370/21 1831/2371/21 1829/2372/21 1827/2373/21 1825/2374/21 1823/2375/21 1821/2376/21 1819/2377/21 1817/2378/21 1815/2379/21 1813/2380/21 1811/2381/21 1809/2382/21 1807/2383/21 1805/2384/21 1803/2385/21 1801/2386/21 +f 1803/2387/50 1805/2353/50 1806/2354/50 1804/2388/50 +f 1861/2389/79 1736/2390/79 1735/2391/79 1862/2392/79 +f 1801/2393/49 1803/2387/49 1804/2388/49 1802/2394/49 +f 1736/2395/48 1801/2393/48 1802/2394/48 1735/2396/48 +f 1871/2148/52 1873/2219/52 1874/2222/52 1872/2149/52 +f 1859/2216/78 1861/2389/78 1862/2392/78 1860/2217/78 +f 1867/2397/50 1869/2147/50 1870/2150/50 1868/2398/50 +f 1925/2399/79 1864/2400/79 1863/2401/79 1926/2402/79 +f 1865/2403/49 1867/2397/49 1868/2398/49 1866/2404/49 +f 1864/2405/48 1865/2403/48 1866/2404/48 1863/2406/48 +f 1923/2317/78 1925/2399/78 1926/2402/78 1924/2318/78 +f 1684/2091/631 1978/2407/631 1977/2408/631 1683/2089/631 +f 1671/2092/632 1965/2409/632 1964/2410/632 1670/2090/632 +f 1685/2093/633 1979/2411/633 1978/2407/633 1684/2091/633 +f 1672/2094/634 1966/2412/634 1965/2409/634 1671/2092/634 +f 1686/2095/635 1980/2413/635 1979/2411/635 1685/2093/635 +f 1673/2096/636 1967/2414/636 1966/2412/636 1672/2094/636 +f 1660/2097/637 1954/2415/637 1953/2416/637 1659/2098/637 +f 1687/2099/638 1981/2417/638 1980/2413/638 1686/2095/638 +f 1674/2100/639 1968/2418/639 1967/2414/639 1673/2096/639 +f 1661/2101/640 1955/2419/640 1954/2415/640 1660/2097/640 +f 1688/2102/641 1982/2420/641 1981/2417/641 1687/2099/641 +f 1675/2103/642 1969/2421/642 1968/2418/642 1674/2100/642 +f 1662/2104/643 1956/2422/643 1955/2419/643 1661/2101/643 +f 1689/2105/644 1983/2423/644 1982/2420/644 1688/2102/644 +f 1676/2106/645 1970/2424/645 1969/2421/645 1675/2103/645 +f 1663/2107/646 1957/2425/646 1956/2422/646 1662/2104/646 +f 1690/2108/647 1984/2426/647 1983/2423/647 1689/2105/647 +f 1677/2109/648 1971/2427/648 1970/2424/648 1676/2106/648 +f 1664/2110/649 1958/2428/649 1957/2425/649 1663/2107/649 +f 1659/2098/650 1953/2416/650 1984/2426/650 1690/2108/650 +f 1678/2111/651 1972/2429/651 1971/2427/651 1677/2109/651 +f 1665/2112/652 1959/2430/652 1958/2428/652 1664/2110/652 +f 1679/2113/653 1973/2431/653 1972/2429/653 1678/2111/653 +f 1666/2114/654 1960/2432/654 1959/2430/654 1665/2112/654 +f 1680/2084/655 1974/2433/655 1973/2431/655 1679/2113/655 +f 1667/2086/656 1961/2434/656 1960/2432/656 1666/2114/656 +f 1681/2083/657 1975/2435/657 1974/2433/657 1680/2084/657 +f 1668/2085/658 1962/2436/658 1961/2434/658 1667/2086/658 +f 1682/2087/659 1976/2437/659 1975/2435/659 1681/2083/659 +f 1669/2088/660 1963/2438/660 1962/2436/660 1668/2085/660 +f 1683/2089/661 1977/2408/661 1976/2437/661 1682/2087/661 +f 1670/2090/662 1964/2410/662 1963/2438/662 1669/2088/662 +f 1954/2415/21 1955/2419/21 1956/2422/21 1957/2425/21 1958/2428/21 1959/2430/21 1960/2432/21 1961/2434/21 1962/2436/21 1963/2438/21 1964/2410/21 1965/2409/21 1966/2412/21 1967/2414/21 1968/2418/21 1969/2421/21 1970/2424/21 1971/2427/21 1972/2429/21 1973/2431/21 1974/2433/21 1975/2435/21 1976/2437/21 1977/2408/21 1978/2407/21 1979/2411/21 1980/2413/21 1981/2417/21 1982/2420/21 1983/2423/21 1984/2426/21 1953/2416/21 +usemtl Материал.004 +f 944/299/92 943/100/92 939/99/92 942/296/92 +f 1948/582/92 1946/581/92 1941/392/92 1947/391/92 +l 4 990 +l 992 993 +l 995 998 +l 93 92 +l 21 103 +l 105 107 +l 989 990 +l 1087 1085 +l 1013 1099 +l 1101 1103 diff --git a/wgpu/examples/skybox/screenshot.png b/wgpu/examples/skybox/screenshot.png new file mode 100644 index 000000000..db0cb5ba3 Binary files /dev/null and b/wgpu/examples/skybox/screenshot.png differ diff --git a/wgpu/examples/skybox/shader.wgsl b/wgpu/examples/skybox/shader.wgsl new file mode 100644 index 000000000..9d211eed5 --- /dev/null +++ b/wgpu/examples/skybox/shader.wgsl @@ -0,0 +1,78 @@ +struct SkyOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] uv: vec3; +}; + +[[block]] +struct Data { + // from camera to screen + proj: mat4x4; + // from screen to camera + proj_inv: mat4x4; + // from world to camera + view: mat4x4; + // camera position + cam_pos: vec4; +}; +[[group(0), binding(0)]] +var r_data: Data; + +[[stage(vertex)]] +fn vs_sky([[builtin(vertex_index)]] vertex_index: u32) -> SkyOutput { + // hacky way to draw a large triangle + let tmp1 = i32(vertex_index) / 2; + let tmp2 = i32(vertex_index) & 1; + let pos = vec4( + f32(tmp1) * 4.0 - 1.0, + f32(tmp2) * 4.0 - 1.0, + 1.0, + 1.0 + ); + + // transposition = inversion for this orthonormal matrix + let inv_model_view = transpose(mat3x3(r_data.view.x.xyz, r_data.view.y.xyz, r_data.view.z.xyz)); + let unprojected = r_data.proj_inv * pos; + + var out: SkyOutput; + out.uv = inv_model_view * unprojected.xyz; + out.position = pos; + return out; +} + +struct EntityOutput { + [[builtin(position)]] position: vec4; + [[location(1)]] normal: vec3; + [[location(3)]] view: vec3; +}; + +[[stage(vertex)]] +fn vs_entity( + [[location(0)]] pos: vec3, + [[location(1)]] normal: vec3, +) -> EntityOutput { + var out: EntityOutput; + out.normal = normal; + out.view = pos - r_data.cam_pos.xyz; + out.position = r_data.proj * r_data.view * vec4(pos, 1.0); + return out; +} + +[[group(0), binding(1)]] +var r_texture: texture_cube; +[[group(0), binding(2)]] +var r_sampler: sampler; + +[[stage(fragment)]] +fn fs_sky(in: SkyOutput) -> [[location(0)]] vec4 { + return textureSample(r_texture, r_sampler, in.uv); +} + +[[stage(fragment)]] +fn fs_entity(in: EntityOutput) -> [[location(0)]] vec4 { + let incident = normalize(in.view); + let normal = normalize(in.normal); + let reflected = incident - 2.0 * dot(normal, incident) * normal; + + let reflected_color = textureSample(r_texture, r_sampler, reflected); + return vec4(0.1, 0.1, 0.1, 0.1) + 0.5 * reflected_color; +} diff --git a/wgpu/examples/texture-arrays/constant.frag b/wgpu/examples/texture-arrays/constant.frag new file mode 100644 index 000000000..c4cb2894b --- /dev/null +++ b/wgpu/examples/texture-arrays/constant.frag @@ -0,0 +1,19 @@ +#version 450 + +layout(location = 0) in vec2 v_TexCoord; +layout(location = 1) flat in int v_Index; // dynamically non-uniform +layout(location = 0) out vec4 o_Color; + +layout(set = 0, binding = 0) uniform texture2D u_Textures[2]; +layout(set = 0, binding = 1) uniform sampler u_Sampler; + +void main() { + if (v_Index == 0) { + o_Color = vec4(texture(sampler2D(u_Textures[0], u_Sampler), v_TexCoord).rgb, 1.0); + } else if (v_Index == 1) { + o_Color = vec4(texture(sampler2D(u_Textures[1], u_Sampler), v_TexCoord).rgb, 1.0); + } else { + // We need to write something to output color + o_Color = vec4(0.0, 0.0, 1.0, 0.0); + } +} diff --git a/wgpu/examples/texture-arrays/constant.frag.spv b/wgpu/examples/texture-arrays/constant.frag.spv new file mode 100644 index 000000000..cd85dc640 Binary files /dev/null and b/wgpu/examples/texture-arrays/constant.frag.spv differ diff --git a/wgpu/examples/texture-arrays/main.rs b/wgpu/examples/texture-arrays/main.rs new file mode 100644 index 000000000..1bc974d3a --- /dev/null +++ b/wgpu/examples/texture-arrays/main.rs @@ -0,0 +1,332 @@ +#[path = "../framework.rs"] +mod framework; + +use bytemuck::{Pod, Zeroable}; +use std::num::NonZeroU32; +use wgpu::util::DeviceExt; + +#[repr(C)] +#[derive(Clone, Copy, Pod, Zeroable)] +struct Vertex { + _pos: [f32; 2], + _tex_coord: [f32; 2], + _index: u32, +} + +fn vertex(pos: [i8; 2], tc: [i8; 2], index: i8) -> Vertex { + Vertex { + _pos: [pos[0] as f32, pos[1] as f32], + _tex_coord: [tc[0] as f32, tc[1] as f32], + _index: index as u32, + } +} + +fn create_vertices() -> Vec { + vec![ + // left rectangle + vertex([-1, -1], [0, 1], 0), + vertex([-1, 1], [0, 0], 0), + vertex([0, 1], [1, 0], 0), + vertex([0, -1], [1, 1], 0), + // right rectangle + vertex([0, -1], [0, 1], 1), + vertex([0, 1], [0, 0], 1), + vertex([1, 1], [1, 0], 1), + vertex([1, -1], [1, 1], 1), + ] +} + +fn create_indices() -> Vec { + vec![ + // Left rectangle + 0, 1, 2, // 1st + 2, 0, 3, // 2nd + // Right rectangle + 4, 5, 6, // 1st + 6, 4, 7, // 2nd + ] +} + +#[derive(Copy, Clone)] +enum Color { + RED, + GREEN, +} + +fn create_texture_data(color: Color) -> [u8; 4] { + match color { + Color::RED => [255, 0, 0, 255], + Color::GREEN => [0, 255, 0, 255], + } +} + +struct Example { + pipeline: wgpu::RenderPipeline, + bind_group: wgpu::BindGroup, + vertex_buffer: wgpu::Buffer, + index_buffer: wgpu::Buffer, + index_format: wgpu::IndexFormat, + uniform_workaround: bool, +} + +impl framework::Example for Example { + fn optional_features() -> wgpu::Features { + wgpu::Features::UNSIZED_BINDING_ARRAY + | wgpu::Features::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING + | wgpu::Features::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING + | wgpu::Features::PUSH_CONSTANTS + } + fn required_features() -> wgpu::Features { + wgpu::Features::SAMPLED_TEXTURE_BINDING_ARRAY + } + fn required_limits() -> wgpu::Limits { + wgpu::Limits { + max_push_constant_size: 4, + ..wgpu::Limits::default() + } + } + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + _adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) -> Self { + let mut uniform_workaround = false; + let vs_module = device.create_shader_module(&wgpu::include_spirv!("shader.vert.spv")); + let fs_source = match device.features() { + f if f.contains(wgpu::Features::UNSIZED_BINDING_ARRAY) => { + wgpu::include_spirv!("unsized-non-uniform.frag.spv") + } + f if f.contains(wgpu::Features::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING) => { + wgpu::include_spirv!("non-uniform.frag.spv") + } + f if f.contains(wgpu::Features::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING) => { + uniform_workaround = true; + wgpu::include_spirv!("uniform.frag.spv") + } + f if f.contains(wgpu::Features::SAMPLED_TEXTURE_BINDING_ARRAY) => { + wgpu::include_spirv!("constant.frag.spv") + } + _ => unreachable!(), + }; + let fs_module = device.create_shader_module(&fs_source); + + let vertex_size = std::mem::size_of::(); + let vertex_data = create_vertices(); + let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Vertex Buffer"), + contents: bytemuck::cast_slice(&vertex_data), + usage: wgpu::BufferUsage::VERTEX, + }); + + let index_data = create_indices(); + let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Index Buffer"), + contents: bytemuck::cast_slice(&index_data), + usage: wgpu::BufferUsage::INDEX, + }); + + let red_texture_data = create_texture_data(Color::RED); + let green_texture_data = create_texture_data(Color::GREEN); + + let texture_descriptor = wgpu::TextureDescriptor { + size: wgpu::Extent3d::default(), + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Rgba8UnormSrgb, + usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + label: None, + }; + let red_texture = device.create_texture(&wgpu::TextureDescriptor { + label: Some("red"), + ..texture_descriptor + }); + let green_texture = device.create_texture(&wgpu::TextureDescriptor { + label: Some("green"), + ..texture_descriptor + }); + + let red_texture_view = red_texture.create_view(&wgpu::TextureViewDescriptor::default()); + let green_texture_view = green_texture.create_view(&wgpu::TextureViewDescriptor::default()); + + queue.write_texture( + wgpu::ImageCopyTexture { + mip_level: 0, + origin: wgpu::Origin3d::ZERO, + texture: &red_texture, + }, + &red_texture_data, + wgpu::ImageDataLayout { + offset: 0, + bytes_per_row: Some(NonZeroU32::new(4).unwrap()), + rows_per_image: None, + }, + wgpu::Extent3d::default(), + ); + queue.write_texture( + wgpu::ImageCopyTexture { + mip_level: 0, + origin: wgpu::Origin3d::ZERO, + texture: &green_texture, + }, + &green_texture_data, + wgpu::ImageDataLayout { + offset: 0, + bytes_per_row: Some(NonZeroU32::new(4).unwrap()), + rows_per_image: None, + }, + wgpu::Extent3d::default(), + ); + + let sampler = device.create_sampler(&wgpu::SamplerDescriptor::default()); + + let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("bind group layout"), + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + sample_type: wgpu::TextureSampleType::Float { filterable: true }, + view_dimension: wgpu::TextureViewDimension::D2, + multisampled: false, + }, + count: NonZeroU32::new(2), + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Sampler { + comparison: false, + filtering: true, + }, + count: None, + }, + ], + }); + + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureViewArray(&[ + &red_texture_view, + &green_texture_view, + ]), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(&sampler), + }, + ], + layout: &bind_group_layout, + label: Some("bind group"), + }); + + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("main"), + bind_group_layouts: &[&bind_group_layout], + push_constant_ranges: if uniform_workaround { + &[wgpu::PushConstantRange { + stages: wgpu::ShaderStage::FRAGMENT, + range: 0..4, + }] + } else { + &[] + }, + }); + + let index_format = wgpu::IndexFormat::Uint16; + + let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&pipeline_layout), + vertex: wgpu::VertexState { + module: &vs_module, + entry_point: "main", + buffers: &[wgpu::VertexBufferLayout { + array_stride: vertex_size as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Sint32], + }], + }, + fragment: Some(wgpu::FragmentState { + module: &fs_module, + entry_point: "main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + front_face: wgpu::FrontFace::Ccw, + ..Default::default() + }, + depth_stencil: None, + multisample: wgpu::MultisampleState::default(), + }); + + Self { + vertex_buffer, + index_buffer, + index_format, + bind_group, + pipeline, + uniform_workaround, + } + } + fn resize( + &mut self, + _sc_desc: &wgpu::SwapChainDescriptor, + _device: &wgpu::Device, + _queue: &wgpu::Queue, + ) { + // noop + } + fn update(&mut self, _event: winit::event::WindowEvent) { + // noop + } + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("primary"), + }); + + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: true, + }, + }], + depth_stencil_attachment: None, + }); + + rpass.set_pipeline(&self.pipeline); + rpass.set_bind_group(0, &self.bind_group, &[]); + rpass.set_vertex_buffer(0, self.vertex_buffer.slice(..)); + rpass.set_index_buffer(self.index_buffer.slice(..), self.index_format); + if self.uniform_workaround { + rpass.set_push_constants(wgpu::ShaderStage::FRAGMENT, 0, bytemuck::cast_slice(&[0])); + rpass.draw_indexed(0..6, 0, 0..1); + rpass.set_push_constants(wgpu::ShaderStage::FRAGMENT, 0, bytemuck::cast_slice(&[1])); + rpass.draw_indexed(6..12, 0, 0..1); + } else { + rpass.draw_indexed(0..12, 0, 0..1); + } + + drop(rpass); + + queue.submit(Some(encoder.finish())); + } +} + +fn main() { + framework::run::("texture-arrays"); +} diff --git a/wgpu/examples/texture-arrays/non-uniform.frag b/wgpu/examples/texture-arrays/non-uniform.frag new file mode 100644 index 000000000..30cfba0fa --- /dev/null +++ b/wgpu/examples/texture-arrays/non-uniform.frag @@ -0,0 +1,14 @@ +#version 450 + +#extension GL_EXT_nonuniform_qualifier : require + +layout(location = 0) in vec2 v_TexCoord; +layout(location = 1) nonuniformEXT flat in int v_Index; // dynamically non-uniform +layout(location = 0) out vec4 o_Color; + +layout(set = 0, binding = 0) uniform texture2D u_Textures[2]; +layout(set = 0, binding = 1) uniform sampler u_Sampler; + +void main() { + o_Color = vec4(texture(sampler2D(u_Textures[v_Index], u_Sampler), v_TexCoord).rgb, 1.0); +} diff --git a/wgpu/examples/texture-arrays/non-uniform.frag.spv b/wgpu/examples/texture-arrays/non-uniform.frag.spv new file mode 100644 index 000000000..caba8fc91 Binary files /dev/null and b/wgpu/examples/texture-arrays/non-uniform.frag.spv differ diff --git a/wgpu/examples/texture-arrays/shader.vert b/wgpu/examples/texture-arrays/shader.vert new file mode 100644 index 000000000..cd7d2c769 --- /dev/null +++ b/wgpu/examples/texture-arrays/shader.vert @@ -0,0 +1,13 @@ +#version 450 + +layout(location = 0) in vec2 a_Pos; +layout(location = 1) in vec2 a_TexCoord; +layout(location = 2) in int a_Index; +layout(location = 0) out vec2 v_TexCoord; +layout(location = 1) flat out int v_Index; + +void main() { + v_TexCoord = a_TexCoord; + v_Index = a_Index; + gl_Position = vec4(a_Pos, 0.0, 1.0); +} diff --git a/wgpu/examples/texture-arrays/shader.vert.spv b/wgpu/examples/texture-arrays/shader.vert.spv new file mode 100644 index 000000000..c1ca86d7f Binary files /dev/null and b/wgpu/examples/texture-arrays/shader.vert.spv differ diff --git a/wgpu/examples/texture-arrays/uniform.frag b/wgpu/examples/texture-arrays/uniform.frag new file mode 100644 index 000000000..3b7a136b1 --- /dev/null +++ b/wgpu/examples/texture-arrays/uniform.frag @@ -0,0 +1,15 @@ +#version 450 + +layout(location = 0) in vec2 v_TexCoord; +layout(location = 1) flat in int v_Index; // dynamically non-uniform +layout(location = 0) out vec4 o_Color; + +layout(set = 0, binding = 0) uniform texture2D u_Textures[2]; +layout(set = 0, binding = 1) uniform sampler u_Sampler; +layout(push_constant) uniform Uniforms { + int u_Index; // dynamically uniform +}; + +void main() { + o_Color = vec4(texture(sampler2D(u_Textures[u_Index], u_Sampler), v_TexCoord).rgb, 1.0); +} diff --git a/wgpu/examples/texture-arrays/uniform.frag.spv b/wgpu/examples/texture-arrays/uniform.frag.spv new file mode 100644 index 000000000..671a87262 Binary files /dev/null and b/wgpu/examples/texture-arrays/uniform.frag.spv differ diff --git a/wgpu/examples/texture-arrays/unsized-non-uniform.frag b/wgpu/examples/texture-arrays/unsized-non-uniform.frag new file mode 100644 index 000000000..cd6068144 --- /dev/null +++ b/wgpu/examples/texture-arrays/unsized-non-uniform.frag @@ -0,0 +1,14 @@ +#version 450 + +#extension GL_EXT_nonuniform_qualifier : require + +layout(location = 0) in vec2 v_TexCoord; +layout(location = 1) nonuniformEXT flat in int v_Index; // dynamically non-uniform +layout(location = 0) out vec4 o_Color; + +layout(set = 0, binding = 0) uniform texture2D u_Textures[]; +layout(set = 0, binding = 1) uniform sampler u_Sampler; + +void main() { + o_Color = vec4(texture(sampler2D(u_Textures[v_Index], u_Sampler), v_TexCoord).rgb, 1.0); +} diff --git a/wgpu/examples/texture-arrays/unsized-non-uniform.frag.spv b/wgpu/examples/texture-arrays/unsized-non-uniform.frag.spv new file mode 100644 index 000000000..1c0688ff7 Binary files /dev/null and b/wgpu/examples/texture-arrays/unsized-non-uniform.frag.spv differ diff --git a/wgpu/examples/water/README.md b/wgpu/examples/water/README.md new file mode 100644 index 000000000..0c316700c --- /dev/null +++ b/wgpu/examples/water/README.md @@ -0,0 +1,24 @@ +# Water example + +This example renders animated water. + +It demonstrates Read only Depth/Stencil (abbreviated RODS), where a depth/stencil buffer is used as an attachment which is read-only. In this case it's used in the shaders to calculate reflections and depth. + +## Files: +``` +water +├── main.rs ------------------ Main program +├── point_gen.rs ------------- Hexagon point generation +├── README.md ---------------- This readme +├── screenshot.png ----------- Screenshot +├── terrain.wgsl ------------- WGSL Shader for terrain +└── water.wgsl --------------- WGSL Shader for water +``` + +## To run +``` +cargo run --example water +``` + +## Screenshot +![Water example](./screenshot.png) diff --git a/wgpu/examples/water/main.rs b/wgpu/examples/water/main.rs new file mode 100644 index 000000000..789d68977 --- /dev/null +++ b/wgpu/examples/water/main.rs @@ -0,0 +1,799 @@ +#[path = "../framework.rs"] +mod framework; + +mod point_gen; + +use bytemuck::{Pod, Zeroable}; +use cgmath::Point3; +use std::{borrow::Cow, iter, mem}; +use wgpu::util::DeviceExt; + +/// +/// Radius of the terrain. +/// +/// Changing this value will change the size of the +/// water and terrain. Note however, that changes to +/// this value will require modification of the time +/// scale in the `render` method below. +/// +const SIZE: f32 = 10.0; + +/// +/// Location of the camera. +/// Location of light is in terrain/water shaders. +/// +const CAMERA: Point3 = Point3 { + x: -100.0, + y: 50.0, + z: 100.0, +}; + +struct Matrices { + view: cgmath::Matrix4, + flipped_view: cgmath::Matrix4, + projection: cgmath::Matrix4, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] +struct TerrainUniforms { + view_projection: [f32; 16], + clipping_plane: [f32; 4], +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] +struct WaterUniforms { + view: [f32; 16], + projection: [f32; 16], + time_size_width: [f32; 4], + height: [f32; 4], +} + +struct Uniforms { + terrain_normal: TerrainUniforms, + terrain_flipped: TerrainUniforms, + water: WaterUniforms, +} + +struct Example { + water_vertex_buf: wgpu::Buffer, + water_vertex_count: usize, + water_bind_group_layout: wgpu::BindGroupLayout, + water_bind_group: wgpu::BindGroup, + water_uniform_buf: wgpu::Buffer, + water_pipeline: wgpu::RenderPipeline, + + terrain_vertex_buf: wgpu::Buffer, + terrain_vertex_count: usize, + terrain_normal_bind_group: wgpu::BindGroup, + /// + /// Binds to the uniform buffer where the + /// camera has been placed underwater. + /// + terrain_flipped_bind_group: wgpu::BindGroup, + terrain_normal_uniform_buf: wgpu::Buffer, + /// + /// Contains uniform variables where the camera + /// has been placed underwater. + /// + terrain_flipped_uniform_buf: wgpu::Buffer, + terrain_pipeline: wgpu::RenderPipeline, + + reflect_view: wgpu::TextureView, + + depth_buffer: wgpu::TextureView, + + current_frame: usize, + + /// + /// Used to prevent issues when rendering after + /// minimizing the window. + /// + active: Option, +} + +impl Example { + /// + /// Creates the view matrices, and the corrected projection matrix. + /// + fn generate_matrices(aspect_ratio: f32) -> Matrices { + let projection = cgmath::perspective(cgmath::Deg(45f32), aspect_ratio, 10.0, 400.0); + let reg_view = cgmath::Matrix4::look_at_rh( + CAMERA, + cgmath::Point3::new(0f32, 0.0, 0.0), + cgmath::Vector3::unit_y(), //Note that y is up. Differs from other examples. + ); + + let scale = cgmath::Matrix4::from_nonuniform_scale(8.0, 1.5, 8.0); + + let reg_view = reg_view * scale; + + let flipped_view = cgmath::Matrix4::look_at_rh( + cgmath::Point3::new(CAMERA.x, -CAMERA.y, CAMERA.z), + cgmath::Point3::new(0f32, 0.0, 0.0), + cgmath::Vector3::unit_y(), + ); + + let correction = framework::OPENGL_TO_WGPU_MATRIX; + + let flipped_view = flipped_view * scale; + + Matrices { + view: reg_view, + flipped_view, + projection: correction * projection, + } + } + + fn generate_uniforms(width: u32, height: u32) -> Uniforms { + let Matrices { + view, + flipped_view, + projection, + } = Self::generate_matrices(width as f32 / height as f32); + + Uniforms { + terrain_normal: TerrainUniforms { + view_projection: *(projection * view).as_ref(), + clipping_plane: [0.0; 4], + }, + terrain_flipped: TerrainUniforms { + view_projection: *(projection * flipped_view).as_ref(), + clipping_plane: [0., 1., 0., 0.], + }, + water: WaterUniforms { + view: *view.as_ref(), + projection: *projection.as_ref(), + time_size_width: [0.0, 1.0, SIZE * 2.0, width as f32], + height: [height as f32, 0.0, 0.0, 0.0], + }, + } + } + + /// + /// Initializes Uniforms and textures. + /// + fn initialize_resources( + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + queue: &wgpu::Queue, + water_uniforms: &wgpu::Buffer, + terrain_normal_uniforms: &wgpu::Buffer, + terrain_flipped_uniforms: &wgpu::Buffer, + water_bind_group_layout: &wgpu::BindGroupLayout, + ) -> (wgpu::TextureView, wgpu::TextureView, wgpu::BindGroup) { + // Matrices for our projection and view. + // flipped_view is the view from under the water. + let Uniforms { + terrain_normal, + terrain_flipped, + water, + } = Self::generate_uniforms(sc_desc.width, sc_desc.height); + + // Put the uniforms into buffers on the GPU + queue.write_buffer( + terrain_normal_uniforms, + 0, + bytemuck::cast_slice(&[terrain_normal]), + ); + queue.write_buffer( + terrain_flipped_uniforms, + 0, + bytemuck::cast_slice(&[terrain_flipped]), + ); + queue.write_buffer(water_uniforms, 0, bytemuck::cast_slice(&[water])); + + let texture_extent = wgpu::Extent3d { + width: sc_desc.width, + height: sc_desc.height, + depth_or_array_layers: 1, + }; + + let reflection_texture = device.create_texture(&wgpu::TextureDescriptor { + label: Some("Reflection Render Texture"), + size: texture_extent, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: sc_desc.format, + usage: wgpu::TextureUsage::SAMPLED + | wgpu::TextureUsage::COPY_DST + | wgpu::TextureUsage::RENDER_ATTACHMENT, + }); + + let draw_depth_buffer = device.create_texture(&wgpu::TextureDescriptor { + label: Some("Depth Buffer"), + size: texture_extent, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Depth32Float, + usage: wgpu::TextureUsage::SAMPLED + | wgpu::TextureUsage::COPY_DST + | wgpu::TextureUsage::RENDER_ATTACHMENT, + }); + + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + label: Some("Texture Sampler"), + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Nearest, + min_filter: wgpu::FilterMode::Linear, + mipmap_filter: wgpu::FilterMode::Nearest, + ..Default::default() + }); + + let depth_view = draw_depth_buffer.create_view(&wgpu::TextureViewDescriptor::default()); + + let water_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: water_bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: water_uniforms.as_entire_binding(), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::TextureView( + &reflection_texture.create_view(&wgpu::TextureViewDescriptor::default()), + ), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView(&depth_view), + }, + wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::Sampler(&sampler), + }, + ], + label: Some("Water Bind Group"), + }); + + ( + reflection_texture.create_view(&wgpu::TextureViewDescriptor::default()), + depth_view, + water_bind_group, + ) + } +} + +impl framework::Example for Example { + fn init( + sc_desc: &wgpu::SwapChainDescriptor, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) -> Self { + // Size of one water vertex + let water_vertex_size = mem::size_of::(); + + let water_vertices = point_gen::HexWaterMesh::generate(SIZE).generate_points(); + + // Size of one terrain vertex + let terrain_vertex_size = mem::size_of::(); + + // Noise generation + let terrain_noise = noise::OpenSimplex::new(); + + // Random colouration + let mut terrain_random = rand::thread_rng(); + + // Generate terrain. The closure determines what each hexagon will look like. + let terrain = + point_gen::HexTerrainMesh::generate(SIZE, |point| -> point_gen::TerrainVertex { + use noise::NoiseFn; + use rand::Rng; + let noise = terrain_noise.get([point[0] as f64 / 5.0, point[1] as f64 / 5.0]) + 0.1; + + let y = noise as f32 * 8.0; + + // Multiplies a colour by some random amount. + fn mul_arr(mut arr: [u8; 4], by: f32) -> [u8; 4] { + arr[0] = (arr[0] as f32 * by).min(255.0) as u8; + arr[1] = (arr[1] as f32 * by).min(255.0) as u8; + arr[2] = (arr[2] as f32 * by).min(255.0) as u8; + arr + } + + // Under water + const DARK_SAND: [u8; 4] = [235, 175, 71, 255]; + // Coast + const SAND: [u8; 4] = [217, 191, 76, 255]; + // Normal + const GRASS: [u8; 4] = [122, 170, 19, 255]; + // Mountain + const SNOW: [u8; 4] = [175, 224, 237, 255]; + + // Random colouration. + let random = terrain_random.gen::() * 0.2 + 0.9; + + // Choose colour. + let colour = if y <= 0.0 { + DARK_SAND + } else if y <= 0.8 { + SAND + } else if y <= 3.0 { + GRASS + } else { + SNOW + }; + point_gen::TerrainVertex { + position: Point3 { + x: point[0], + y, + z: point[1], + }, + colour: mul_arr(colour, random), + } + }); + + // Generate the buffer data. + let terrain_vertices = terrain.make_buffer_data(); + + // Create the buffers on the GPU to hold the data. + let water_vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Water vertices"), + contents: bytemuck::cast_slice(&water_vertices), + usage: wgpu::BufferUsage::VERTEX, + }); + + let terrain_vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Terrain vertices"), + contents: bytemuck::cast_slice(&terrain_vertices), + usage: wgpu::BufferUsage::VERTEX, + }); + + // Create the bind group layout. This is what our uniforms will look like. + let water_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("Water Bind Group Layout"), + entries: &[ + // Uniform variables such as projection/view. + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new( + mem::size_of::() as _, + ), + }, + count: None, + }, + // Reflection texture. + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + multisampled: false, + sample_type: wgpu::TextureSampleType::Float { filterable: true }, + view_dimension: wgpu::TextureViewDimension::D2, + }, + count: None, + }, + // Depth texture for terrain. + wgpu::BindGroupLayoutEntry { + binding: 2, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Texture { + multisampled: false, + sample_type: wgpu::TextureSampleType::Float { filterable: true }, + view_dimension: wgpu::TextureViewDimension::D2, + }, + count: None, + }, + // Sampler to be able to sample the textures. + wgpu::BindGroupLayoutEntry { + binding: 3, + visibility: wgpu::ShaderStage::FRAGMENT, + ty: wgpu::BindingType::Sampler { + comparison: false, + filtering: true, + }, + count: None, + }, + ], + }); + + let terrain_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + label: Some("Terrain Bind Group Layout"), + entries: &[ + // Regular uniform variables like view/projection. + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStage::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: wgpu::BufferSize::new( + mem::size_of::() as _, + ), + }, + count: None, + }, + ], + }); + + // Create our pipeline layouts. + let water_pipeline_layout = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("water"), + bind_group_layouts: &[&water_bind_group_layout], + push_constant_ranges: &[], + }); + + let terrain_pipeline_layout = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { + label: Some("terrain"), + bind_group_layouts: &[&terrain_bind_group_layout], + push_constant_ranges: &[], + }); + + let water_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { + label: Some("Water Uniforms"), + size: mem::size_of::() as _, + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + let terrain_normal_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { + label: Some("Normal Terrain Uniforms"), + size: mem::size_of::() as _, + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + let terrain_flipped_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { + label: Some("Flipped Terrain Uniforms"), + size: mem::size_of::() as _, + usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + mapped_at_creation: false, + }); + + // Create bind group. + // This puts values behind what was laid out in the bind group layout. + + let (reflect_view, depth_buffer, water_bind_group) = Self::initialize_resources( + sc_desc, + device, + queue, + &water_uniform_buf, + &terrain_normal_uniform_buf, + &terrain_flipped_uniform_buf, + &water_bind_group_layout, + ); + + let terrain_normal_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &terrain_bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: terrain_normal_uniform_buf.as_entire_binding(), + }], + label: Some("Terrain Normal Bind Group"), + }); + let terrain_flipped_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &terrain_bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: terrain_flipped_uniform_buf.as_entire_binding(), + }], + label: Some("Terrain Flipped Bind Group"), + }); + + // Upload/compile them to GPU code. + let mut flags = wgpu::ShaderFlags::VALIDATION; + match adapter.get_info().backend { + wgpu::Backend::Metal | wgpu::Backend::Vulkan => { + flags |= wgpu::ShaderFlags::EXPERIMENTAL_TRANSLATION + } + _ => (), //TODO + } + let terrain_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: Some("terrain"), + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("terrain.wgsl"))), + flags, + }); + let water_module = device.create_shader_module(&wgpu::ShaderModuleDescriptor { + label: Some("water"), + source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("water.wgsl"))), + flags, + }); + + // Create the render pipelines. These describe how the data will flow through the GPU, and what + // constraints and modifiers it will have. + let water_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("water"), + // The "layout" is what uniforms will be needed. + layout: Some(&water_pipeline_layout), + // Vertex shader and input buffers + vertex: wgpu::VertexState { + module: &water_module, + entry_point: "vs_main", + // Layout of our vertices. This should match the structs + // which are uploaded to the GPU. This should also be + // ensured by tagging on either a `#[repr(C)]` onto a + // struct, or a `#[repr(transparent)]` if it only contains + // one item, which is itself `repr(C)`. + buffers: &[wgpu::VertexBufferLayout { + array_stride: water_vertex_size as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4], + }], + }, + // Fragment shader and output targets + fragment: Some(wgpu::FragmentState { + module: &water_module, + entry_point: "fs_main", + // Describes how the colour will be interpolated + // and assigned to the output attachment. + targets: &[wgpu::ColorTargetState { + format: sc_desc.format, + blend: Some(wgpu::BlendState { + color: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::SrcAlpha, + dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + operation: wgpu::BlendOperation::Add, + }, + alpha: wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Max, + }, + }), + write_mask: wgpu::ColorWrite::ALL, + }], + }), + // How the triangles will be rasterized. This is more important + // for the terrain because of the beneath-the water shot. + // This is also dependent on how the triangles are being generated. + primitive: wgpu::PrimitiveState { + // What kind of data are we passing in? + topology: wgpu::PrimitiveTopology::TriangleList, + front_face: wgpu::FrontFace::Cw, + ..Default::default() + }, + // Describes how us writing to the depth/stencil buffer + // will work. Since this is water, we need to read from the + // depth buffer both as a texture in the shader, and as an + // input attachment to do depth-testing. We don't write, so + // depth_write_enabled is set to false. This is called + // RODS or read-only depth stencil. + depth_stencil: Some(wgpu::DepthStencilState { + // We don't use stencil. + format: wgpu::TextureFormat::Depth32Float, + depth_write_enabled: false, + depth_compare: wgpu::CompareFunction::Less, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState::default(), + }), + // No multisampling is used. + multisample: wgpu::MultisampleState::default(), + }); + + // Same idea as the water pipeline. + let terrain_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: Some("terrain"), + layout: Some(&terrain_pipeline_layout), + vertex: wgpu::VertexState { + module: &terrain_module, + entry_point: "vs_main", + buffers: &[wgpu::VertexBufferLayout { + array_stride: terrain_vertex_size as wgpu::BufferAddress, + step_mode: wgpu::InputStepMode::Vertex, + attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Unorm8x4], + }], + }, + fragment: Some(wgpu::FragmentState { + module: &terrain_module, + entry_point: "fs_main", + targets: &[sc_desc.format.into()], + }), + primitive: wgpu::PrimitiveState { + front_face: wgpu::FrontFace::Ccw, + cull_mode: Some(wgpu::Face::Front), + ..Default::default() + }, + depth_stencil: Some(wgpu::DepthStencilState { + format: wgpu::TextureFormat::Depth32Float, + depth_write_enabled: true, + depth_compare: wgpu::CompareFunction::Less, + stencil: wgpu::StencilState::default(), + bias: wgpu::DepthBiasState::default(), + }), + multisample: wgpu::MultisampleState::default(), + }); + + // Done + Example { + water_vertex_buf, + water_vertex_count: water_vertices.len(), + water_bind_group_layout, + water_bind_group, + water_uniform_buf, + water_pipeline, + + terrain_vertex_buf, + terrain_vertex_count: terrain_vertices.len(), + terrain_normal_bind_group, + terrain_flipped_bind_group, + terrain_normal_uniform_buf, + terrain_flipped_uniform_buf, + terrain_pipeline, + + reflect_view, + + depth_buffer, + + current_frame: 0, + + active: Some(0), + } + } + + fn update(&mut self, _event: winit::event::WindowEvent) { + //empty + } + + fn resize( + &mut self, + sc_desc: &wgpu::SwapChainDescriptor, + device: &wgpu::Device, + queue: &wgpu::Queue, + ) { + if sc_desc.width == 0 && sc_desc.height == 0 { + // Stop rendering altogether. + self.active = None; + return; + } + self.active = Some(self.current_frame); + + // Regenerate all of the buffers and textures. + + let (reflect_view, depth_buffer, water_bind_group) = Self::initialize_resources( + sc_desc, + device, + queue, + &self.water_uniform_buf, + &self.terrain_normal_uniform_buf, + &self.terrain_flipped_uniform_buf, + &self.water_bind_group_layout, + ); + self.water_bind_group = water_bind_group; + + self.depth_buffer = depth_buffer; + self.reflect_view = reflect_view; + } + + #[allow(clippy::eq_op)] + fn render( + &mut self, + frame: &wgpu::SwapChainTexture, + device: &wgpu::Device, + queue: &wgpu::Queue, + _spawner: &framework::Spawner, + ) { + // Increment frame count regardless of if we draw. + self.current_frame += 1; + let back_color = wgpu::Color { + r: 161.0 / 255.0, + g: 246.0 / 255.0, + b: 255.0 / 255.0, + a: 1.0, + }; + + // Write the sin/cos values to the uniform buffer for the water. + let (water_sin, water_cos) = ((self.current_frame as f32) / 600.0).sin_cos(); + queue.write_buffer( + &self.water_uniform_buf, + mem::size_of::<[f32; 16]>() as wgpu::BufferAddress * 2, + bytemuck::cast_slice(&[water_sin, water_cos]), + ); + + // Only render valid frames. See resize method. + if let Some(active) = self.active { + if active >= self.current_frame { + return; + } + } else { + return; + } + + // The encoder provides a way to turn our instructions here, into + // a command buffer the GPU can understand. + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("Main Command Encoder"), + }); + + // First pass: render the reflection. + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &self.reflect_view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(back_color), + store: true, + }, + }], + // We still need to use the depth buffer here + // since the pipeline requires it. + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_buffer, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: true, + }), + stencil_ops: None, + }), + }); + rpass.set_pipeline(&self.terrain_pipeline); + rpass.set_bind_group(0, &self.terrain_flipped_bind_group, &[]); + rpass.set_vertex_buffer(0, self.terrain_vertex_buf.slice(..)); + rpass.draw(0..self.terrain_vertex_count as u32, 0..1); + } + // Terrain right side up. This time we need to use the + // depth values, so we must use StoreOp::Store. + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(back_color), + store: true, + }, + }], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_buffer, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: true, + }), + stencil_ops: None, + }), + }); + rpass.set_pipeline(&self.terrain_pipeline); + rpass.set_bind_group(0, &self.terrain_normal_bind_group, &[]); + rpass.set_vertex_buffer(0, self.terrain_vertex_buf.slice(..)); + rpass.draw(0..self.terrain_vertex_count as u32, 0..1); + } + // Render the water. This reads from the depth buffer, but does not write + // to it, so it cannot be in the same render pass. + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Load, + store: true, + }, + }], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_buffer, + depth_ops: None, + stencil_ops: None, + }), + }); + + rpass.set_pipeline(&self.water_pipeline); + rpass.set_bind_group(0, &self.water_bind_group, &[]); + rpass.set_vertex_buffer(0, self.water_vertex_buf.slice(..)); + rpass.draw(0..self.water_vertex_count as u32, 0..1); + } + + queue.submit(iter::once(encoder.finish())); + } +} + +fn main() { + framework::run::("water"); +} diff --git a/wgpu/examples/water/point_gen.rs b/wgpu/examples/water/point_gen.rs new file mode 100644 index 000000000..d14f99751 --- /dev/null +++ b/wgpu/examples/water/point_gen.rs @@ -0,0 +1,286 @@ +//! +//! This module covers generating points in a hexagonal fashion. +//! + +use bytemuck::{Pod, Zeroable}; +use cgmath::{InnerSpace, Point3, Vector3}; +use std::collections::HashMap; + +// The following constants are used in calculations. +// A and B are multiplication factors for x and y. + +/// +/// X multiplication factor. +/// 1.0 / sqrt(2) +/// +const A: f32 = std::f32::consts::FRAC_1_SQRT_2; + +/// +/// Y multiplication factor. +/// sqrt(3) / sqrt(2) == sqrt(1.5) +/// +const B: f32 = SQRT_3 * A; + +/// +/// `sin(45deg)` is used to rotate the points. +/// +const S45: f32 = std::f32::consts::FRAC_1_SQRT_2; +/// +/// `cos(45deg)` is used to rotate the points. +/// +const C45: f32 = S45; + +const SQRT_3: f32 = 1.7320508; + +#[repr(C)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] +pub struct TerrainVertexAttributes { + position: [f32; 3], + normal: [f32; 3], + colour: [u8; 4], +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] +pub struct WaterVertexAttributes { + position: [i16; 2], + offsets: [i8; 4], +} + +/// +/// Represents the center of a single hexagon. +/// +#[derive(Copy, Clone, Debug)] +pub struct TerrainVertex { + pub position: Point3, + pub colour: [u8; 4], +} + +/// +/// Gets the surrounding hexagonal points from a point. +/// +/// +---0---1 +/// | / | | +/// 5---p---2 +/// | | / | +/// 4---3---+ +/// +fn surrounding_hexagonal_points(x: isize, y: isize) -> [(isize, isize); 6] { + [ + (x, y - 1), + (x + 1, y - 1), + (x + 1, y), + (x, y + 1), + (x - 1, y + 1), + (x - 1, y), + ] +} + +fn surrounding_point_values_iter( + hashmap: &HashMap<(isize, isize), T>, + x: isize, + y: isize, + for_each: impl FnMut((&T, &T)), +) { + let points = surrounding_hexagonal_points(x, y); + let points = [ + points[0], points[1], points[2], points[3], points[4], points[5], points[0], + ]; + points + .windows(2) + .map(|x| (hashmap.get(&x[0]), hashmap.get(&x[1]))) + .flat_map(|(a, b)| a.and_then(|x| b.map(|y| (x, y)))) + .for_each(for_each); +} + +/// +/// Used in calculating terrain normals. +/// +pub fn calculate_normal(a: Point3, b: Point3, c: Point3) -> Vector3 { + (b - a).normalize().cross((c - a).normalize()).normalize() +} + +/// +/// Given the radius, how large of a square do we need to make a unit hexagon grid? +/// +fn q_given_r(radius: f32) -> usize { + ((((((4.0 * radius) / SQRT_3) + 1.0).floor() / 2.0).floor() * 2.0) + 1.0) as usize +} + +/// +/// Represents terrain, however it contains the vertices only once. +/// +#[derive(Clone)] +pub struct HexTerrainMesh { + pub vertices: HashMap<(isize, isize), TerrainVertex>, + half_size: isize, +} + +impl HexTerrainMesh { + /// + /// Generates the vertices (or the centers of the hexagons). The colour and height is determined by + /// a function passed in by the user. + /// + pub fn generate(radius: f32, mut gen_vertex: impl FnMut([f32; 2]) -> TerrainVertex) -> Self { + let width = q_given_r(radius); + let half_width = (width / 2) as isize; + let mut map = HashMap::new(); + let mut max = std::f32::NEG_INFINITY; + for i in -half_width..=half_width { + let x_o = i as f32; + for j in -half_width..=half_width { + let y_o = j as f32; + let x = A * (x_o * C45 - y_o * S45); + let z = B * (x_o * S45 + y_o * C45); + if x.hypot(z) < radius { + let vertex = gen_vertex([x, z]); + if vertex.position.y > max { + max = vertex.position.y; + } + map.insert((i, j), vertex); + } + } + } + Self { + vertices: map, + half_size: width as isize / 2, + } + } + + /// + /// Creates the points required to render the mesh. + /// + pub fn make_buffer_data(&self) -> Vec { + let mut vertices = Vec::new(); + fn middle(p1: &TerrainVertex, p2: &TerrainVertex, p: &TerrainVertex) -> Point3 { + Point3 { + x: (p1.position.x + p2.position.x + p.position.x) / 3.0, + y: (p1.position.y + p2.position.y + p.position.y) / 3.0, + z: (p1.position.z + p2.position.z + p.position.z) / 3.0, + } + } + fn half(p1: &TerrainVertex, p2: &TerrainVertex) -> Point3 { + Point3 { + x: (p1.position.x + p2.position.x) / 2.0, + y: (p1.position.y + p2.position.y) / 2.0, + z: (p1.position.z + p2.position.z) / 2.0, + } + } + let mut push_triangle = |p1: &TerrainVertex, + p2: &TerrainVertex, + p: &TerrainVertex, + c: [u8; 4]| { + let m = middle(p1, p2, p); + let ap = half(p1, p); + let bp = half(p2, p); + let p = p.position; + let n1 = calculate_normal(ap, m, p); + let n2 = calculate_normal(m, bp, p); + + vertices.extend( + [ap, m, p, m, bp, p] + .iter() + .zip( + std::iter::repeat::<[f32; 3]>(n1.into()) + .chain(std::iter::repeat::<[f32; 3]>(n2.into())), + ) + .zip(std::iter::repeat(c)) + .map(|((pos, normal), colour)| TerrainVertexAttributes { + position: *pos.as_ref(), + normal, + colour, + }), + ); + }; + for i in -self.half_size..=self.half_size { + for j in -self.half_size..=self.half_size { + if let Some(p) = self.vertices.get(&(i, j)) { + surrounding_point_values_iter(&self.vertices, i, j, |(a, b)| { + push_triangle(a, b, p, p.colour) + }); + } + } + } + vertices + } +} + +/// +/// Water mesh which contains vertex data for the water mesh. +/// +/// It stores the values multiplied and rounded to the +/// nearest whole number to be more efficient with space when +/// sending large meshes to the GPU. +/// +pub struct HexWaterMesh { + pub vertices: HashMap<(isize, isize), [i16; 2]>, + half_size: isize, +} + +impl HexWaterMesh { + pub fn generate(radius: f32) -> Self { + let width = q_given_r(radius); + let half_width = (width / 2) as isize; + let mut map = HashMap::new(); + + for i in -half_width..=half_width { + let x_o = i as f32; + for j in -half_width..=half_width { + let y_o = j as f32; + let x = A * (x_o * C45 - y_o * S45); + let z = B * (x_o * S45 + y_o * C45); + if x.hypot(z) < radius { + let x = (x * 2.0).round() as i16; + let z = ((z / B) * std::f32::consts::SQRT_2).round() as i16; + map.insert((i, j), [x, z]); + } + } + } + Self { + vertices: map, + half_size: half_width, + } + } + /// + /// Generates the points required to render the mesh. + /// + pub fn generate_points(&self) -> Vec { + let mut vertices = Vec::new(); + + fn calculate_differences(a: [i16; 2], b: [i16; 2], c: [i16; 2]) -> [i8; 4] { + [ + (b[0] - a[0]) as i8, + (b[1] - a[1]) as i8, + (c[0] - a[0]) as i8, + (c[1] - a[1]) as i8, + ] + } + + let mut push_triangle = |a: [i16; 2], b: [i16; 2], c: [i16; 2]| { + let bc = calculate_differences(a, b, c); + let ca = calculate_differences(b, c, a); + let ab = calculate_differences(c, a, b); + + vertices.extend( + [a, b, c] + .iter() + .zip([bc, ca, ab].iter()) + .map(|(&position, &offsets)| WaterVertexAttributes { position, offsets }), + ); + }; + + for i in -self.half_size..=self.half_size { + for j in -self.half_size..=self.half_size { + if (i - j) % 3 == 0 { + if let Some(&p) = self.vertices.get(&(i, j)) { + surrounding_point_values_iter(&self.vertices, i, j, |(a, b)| { + push_triangle(*a, *b, p) + }); + } + } + } + } + + vertices + } +} diff --git a/wgpu/examples/water/screenshot.png b/wgpu/examples/water/screenshot.png new file mode 100644 index 000000000..434ebf3f2 Binary files /dev/null and b/wgpu/examples/water/screenshot.png differ diff --git a/wgpu/examples/water/terrain.wgsl b/wgpu/examples/water/terrain.wgsl new file mode 100644 index 000000000..2af261bf4 --- /dev/null +++ b/wgpu/examples/water/terrain.wgsl @@ -0,0 +1,49 @@ +[[block]] +struct Uniforms { + projection_view: mat4x4; + clipping_plane: vec4; +}; + +[[group(0), binding(0)]] +var uniforms: Uniforms; + +let light: vec3 = vec3(150.0, 70.0, 0.0); +let light_colour: vec3 = vec3(1.0, 0.98, 0.82); +let ambient: f32 = 0.2; + +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] colour: vec4; + // Comment this out if using user-clipping planes: + [[location(1)]] clip_dist: f32; +}; + +[[stage(vertex)]] +fn vs_main( + [[location(0)]] position: vec3, + [[location(1)]] normal: vec3, + [[location(2)]] colour: vec4, +) -> VertexOutput { + var out: VertexOutput; + out.position = uniforms.projection_view * vec4(position, 1.0); + + // https://www.desmos.com/calculator/nqgyaf8uvo + let normalized_light_direction = normalize(position - light); + let brightness_diffuse = clamp(dot(normalized_light_direction, normal), 0.2, 1.0); + + out.colour = vec4(max((brightness_diffuse + ambient) * light_colour * colour.rgb, vec3(0.0, 0.0, 0.0)), colour.a); + out.clip_dist = dot(vec4(position, 1.0), uniforms.clipping_plane); + return out; +} + +[[stage(fragment), early_depth_test]] +fn fs_main( + in: VertexOutput, +) -> [[location(0)]] vec4 { + // Comment this out if using user-clipping planes: + if(in.clip_dist < 0.0) { + discard; + } + + return vec4(in.colour.xyz, 1.0); +} diff --git a/wgpu/examples/water/water.wgsl b/wgpu/examples/water/water.wgsl new file mode 100644 index 000000000..0e69955bf --- /dev/null +++ b/wgpu/examples/water/water.wgsl @@ -0,0 +1,252 @@ +[[block]] +struct Uniforms { + view: mat4x4; + projection: mat4x4; + time_size_width: vec4; + viewport_height: f32; +}; +[[group(0), binding(0)]] var uniforms: Uniforms; + +let light_point: vec3 = vec3(150.0, 70.0, 0.0); +let light_colour: vec3 = vec3(1.0, 0.98, 0.82); +let one: vec4 = vec4(1.0, 1.0, 1.0, 1.0); + +let Y_SCL: f32 = 0.86602540378443864676372317075294; +let CURVE_BIAS: f32 = -0.1; +let INV_1_CURVE_BIAS: f32 = 1.11111111111; //1.0 / (1.0 + CURVE_BIAS); + +// +// The following code to calculate simplex 3D +// is from https://github.com/ashima/webgl-noise +// +// Simplex 3D Noise +// by Ian McEwan, Ashima Arts. +// +fn permute(x: vec4) -> vec4 { + var temp: vec4 = 289.0 * one; + return modf(((x*34.0) + one) * x, &temp); +} + +fn taylorInvSqrt(r: vec4) -> vec4 { + return 1.79284291400159 * one - 0.85373472095314 * r; +} + +fn snoise(v: vec3) -> f32 { + let C = vec2(1.0/6.0, 1.0/3.0); + let D = vec4(0.0, 0.5, 1.0, 2.0); + + // First corner + //TODO: use the splat operations when available + let vCy = dot(v, C.yyy); + var i: vec3 = floor(v + vec3(vCy, vCy, vCy)); + let iCx = dot(i, C.xxx); + let x0 = v - i + vec3(iCx, iCx, iCx); + + // Other corners + let g = step(x0.yzx, x0.xyz); + let l = (vec3(1.0, 1.0, 1.0) - g).zxy; + let i1 = min(g, l); + let i2 = max(g, l); + + // x0 = x0 - 0.0 + 0.0 * C.xxx; + // x1 = x0 - i1 + 1.0 * C.xxx; + // x2 = x0 - i2 + 2.0 * C.xxx; + // x3 = x0 - 1.0 + 3.0 * C.xxx; + let x1 = x0 - i1 + C.xxx; + let x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y + let x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y + + // Permutations + var temp: vec3 = 289.0 * one.xyz; + i = modf(i, &temp); + let p = permute( + permute( + permute(i.zzzz + vec4(0.0, i1.z, i2.z, 1.0)) + + i.yyyy + vec4(0.0, i1.y, i2.y, 1.0)) + + i.xxxx + vec4(0.0, i1.x, i2.x, 1.0)); + + // Gradients: 7x7 points over a square, mapped onto an octahedron. + // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) + let n_ = 0.142857142857;// 1.0/7.0 + let ns = n_ * D.wyz - D.xzx; + + let j = p - 49.0 * floor(p * ns.z * ns.z);// mod(p,7*7) + + let x_ = floor(j * ns.z); + let y_ = floor(j - 7.0 * x_);// mod(j,N) + + var x: vec4 = x_ *ns.x + ns.yyyy; + var y: vec4 = y_ *ns.x + ns.yyyy; + let h = one - abs(x) - abs(y); + + let b0 = vec4(x.xy, y.xy); + let b1 = vec4(x.zw, y.zw); + + //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - one; + //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - one; + let s0 = floor(b0)*2.0 + one; + let s1 = floor(b1)*2.0 + one; + let sh = -step(h, 0.0 * one); + + let a0 = b0.xzyw + s0.xzyw*sh.xxyy; + let a1 = b1.xzyw + s1.xzyw*sh.zzww; + + var p0: vec3 = vec3(a0.xy, h.x); + var p1: vec3 = vec3(a0.zw, h.y); + var p2: vec3 = vec3(a1.xy, h.z); + var p3: vec3 = vec3(a1.zw, h.w); + + //Normalise gradients + let norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); + p0 = p0 * norm.x; + p1 = p1 * norm.y; + p2 = p2 * norm.z; + p3 = p3 * norm.w; + + // Mix final noise value + var m: vec4 = max(0.6 * one - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0 * one); + m = m * m; + return 9.0 * dot(m*m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))); +} + +// End of 3D simplex code. + +fn apply_distortion(pos: vec3) -> vec3 { + var perlin_pos: vec3 = pos; + + //Do noise transformation to permit for smooth, + //continuous movement. + + //TODO: we should be able to name them `sin` and `cos`. + let sn = uniforms.time_size_width.x; + let cs = uniforms.time_size_width.y; + let size = uniforms.time_size_width.z; + + // Rotate 90 Z, Move Left Size / 2 + perlin_pos = vec3(perlin_pos.y - perlin_pos.x - size, perlin_pos.x, perlin_pos.z); + + let xcos = perlin_pos.x * cs; + let xsin = perlin_pos.x * sn; + let ycos = perlin_pos.y * cs; + let ysin = perlin_pos.y * sn; + let zcos = perlin_pos.z * cs; + let zsin = perlin_pos.z * sn; + + // Rotate Time Y + let perlin_pos_y = vec3(xcos + zsin, perlin_pos.y, -xsin + xcos); + + // Rotate Time Z + let perlin_pos_z = vec3(xcos - ysin, xsin + ycos, perlin_pos.x); + + // Rotate 90 Y + perlin_pos = vec3(perlin_pos.z - perlin_pos.x, perlin_pos.y, perlin_pos.x); + + // Rotate Time X + let perlin_pos_x = vec3(perlin_pos.x, ycos - zsin, ysin + zcos); + + // Sample at different places for x/y/z to get random-looking water. + return vec3( + //TODO: use splats + pos.x + snoise(perlin_pos_x + 2.0*one.xxx) * 0.4, + pos.y + snoise(perlin_pos_y - 2.0*one.xxx) * 1.8, + pos.z + snoise(perlin_pos_z) * 0.4 + ); +} + +// Multiply the input by the scale values. +fn make_position(original: vec2) -> vec4 { + let interpreted = vec3(original.x * 0.5, 0.0, original.y * Y_SCL); + return vec4(apply_distortion(interpreted), 1.0); +} + +// Create the normal, and apply the curve. Change the Curve Bias above. +fn make_normal(a: vec3, b: vec3, c: vec3) -> vec3 { + let norm = normalize(cross(b - c, a - c)); + let center = (a + b + c) * (1.0 / 3.0); //TODO: use splat + return (normalize(a - center) * CURVE_BIAS + norm) * INV_1_CURVE_BIAS; +} + +// Calculate the fresnel effect. +fn calc_fresnel(view: vec3, normal: vec3) -> f32 { + var refractive: f32 = abs(dot(view, normal)); + refractive = pow(refractive, 1.33333333333); + return refractive; +} + +// Calculate the specular lighting. +fn calc_specular(eye: vec3, normal: vec3, light: vec3) -> f32 { + let light_reflected = reflect(light, normal); + var specular: f32 = max(dot(eye, light_reflected), 0.0); + specular = pow(specular, 10.0); + return specular; +} + +struct VertexOutput { + [[builtin(position)]] position: vec4; + [[location(0)]] f_WaterScreenPos: vec2; + [[location(1)]] f_Fresnel: f32; + [[location(2)]] f_Light: vec3; +}; + +[[stage(vertex)]] +fn vs_main( + [[location(0)]] position: vec2, + [[location(1)]] offsets: vec4, +) -> VertexOutput { + let p_pos = vec2(position); + let b_pos = make_position(p_pos + vec2(offsets.xy)); + let c_pos = make_position(p_pos + vec2(offsets.zw)); + let a_pos = make_position(p_pos); + let original_pos = vec4(p_pos.x * 0.5, 0.0, p_pos.y * Y_SCL, 1.0); + + let vm = uniforms.view; + let transformed_pos = vm * a_pos; + //TODO: use vector splats for division + let water_pos = transformed_pos.xyz * (1.0 / transformed_pos.w); + let normal = make_normal((vm * a_pos).xyz, (vm * b_pos).xyz, (vm * c_pos).xyz); + let eye = normalize(-water_pos); + let transformed_light = vm * vec4(light_point, 1.0); + + var out: VertexOutput; + out.f_Light = light_colour * calc_specular(eye, normal, normalize(water_pos.xyz - (transformed_light.xyz * (1.0 / transformed_light.w)))); + out.f_Fresnel = calc_fresnel(eye, normal); + + let gridpos = uniforms.projection * vm * original_pos; + out.f_WaterScreenPos = (0.5 * gridpos.xy * (1.0 / gridpos.w)) + vec2(0.5, 0.5); + + out.position = uniforms.projection * transformed_pos; + return out; +} + + +let water_colour: vec3 = vec3(0.0, 0.46, 0.95); +let zNear: f32 = 10.0; +let zFar: f32 = 400.0; + +[[group(0), binding(1)]] var reflection: texture_2d; +[[group(0), binding(2)]] var terrain_depth_tex: texture_2d; +[[group(0), binding(3)]] var colour_sampler: sampler; + +fn to_linear_depth(depth: f32) -> f32 { + let z_n: f32 = 2.0 * depth - 1.0; + let z_e: f32 = 2.0 * zNear * zFar / (zFar + zNear - z_n * (zFar - zNear)); + return z_e; +} + +[[stage(fragment)]] +fn fs_main(in: VertexOutput) -> [[location(0)]] vec4 { + let reflection_colour = textureSample(reflection, colour_sampler, in.f_WaterScreenPos.xy).xyz; + + let pixel_depth = to_linear_depth(in.position.z); + let normalized_coords = in.position.xy / vec2(uniforms.time_size_width.w, uniforms.viewport_height); + let terrain_depth = to_linear_depth(textureSample(terrain_depth_tex, colour_sampler, normalized_coords).r); + + let dist = terrain_depth - pixel_depth; + let clamped = pow(smoothStep(0.0, 1.5, dist), 4.8); + + let final_colour = in.f_Light + reflection_colour; + let t = smoothStep(1.0, 5.0, dist) * 0.2; //TODO: splat for mix()? + let depth_colour = mix(final_colour, water_colour, vec3(t, t, t)); + + return vec4(depth_colour, clamped * (1.0 - in.f_Fresnel)); +} diff --git a/wgpu/logo.png b/wgpu/logo.png new file mode 100644 index 000000000..17f35634d Binary files /dev/null and b/wgpu/logo.png differ diff --git a/wgpu/rustfmt.toml b/wgpu/rustfmt.toml new file mode 100644 index 000000000..e69de29bb diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs new file mode 100644 index 000000000..c50a599c3 --- /dev/null +++ b/wgpu/src/backend/direct.rs @@ -0,0 +1,1972 @@ +use crate::{ + backend::{error::ContextError, native_gpu_future}, + AdapterInfo, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BufferBinding, + CommandEncoderDescriptor, ComputePassDescriptor, ComputePipelineDescriptor, + DownlevelProperties, Features, Label, Limits, LoadOp, MapMode, Operations, + PipelineLayoutDescriptor, RenderBundleEncoderDescriptor, RenderPipelineDescriptor, + SamplerDescriptor, ShaderModuleDescriptor, ShaderSource, SwapChainStatus, TextureDescriptor, + TextureFormat, TextureViewDescriptor, +}; + +use arrayvec::ArrayVec; +use parking_lot::Mutex; +use smallvec::SmallVec; +use std::{ + borrow::Cow::Borrowed, + error::Error, + fmt, + future::{ready, Ready}, + marker::PhantomData, + ops::Range, + slice, + sync::Arc, +}; + +const LABEL: &str = "label"; + +pub struct Context(wgc::hub::Global); + +impl Drop for Context { + fn drop(&mut self) { + //nothing + } +} + +impl fmt::Debug for Context { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Context").field("type", &"Native").finish() + } +} + +impl Context { + pub(crate) fn global(&self) -> &wgc::hub::Global { + &self.0 + } + + pub fn enumerate_adapters(&self, backends: wgt::BackendBit) -> Vec { + self.0 + .enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| { + PhantomData + })) + } + + #[cfg(any(target_os = "ios", target_os = "macos"))] + pub unsafe fn create_surface_from_core_animation_layer( + self: &Arc, + layer: *mut std::ffi::c_void, + ) -> crate::Surface { + let id = self.0.instance_create_surface_metal(layer, PhantomData); + crate::Surface { + context: Arc::clone(self), + id, + } + } + + fn handle_error( + &self, + sink_mutex: &Mutex, + cause: impl Error + Send + Sync + 'static, + label_key: &'static str, + label: Label, + string: &'static str, + ) { + let error = ContextError { + string, + cause: Box::new(cause), + label: label.unwrap_or_default().to_string(), + label_key, + }; + let sink = sink_mutex.lock(); + let mut source_opt: Option<&(dyn Error + 'static)> = Some(&error); + while let Some(source) = source_opt { + if let Some(wgc::device::DeviceError::OutOfMemory) = + source.downcast_ref::() + { + return sink.handle_error(crate::Error::OutOfMemoryError { + source: Box::new(error), + }); + } + source_opt = source.source(); + } + + // Otherwise, it is a validation error + sink.handle_error(crate::Error::ValidationError { + description: self.format_error(&error), + source: Box::new(error), + }); + } + + fn handle_error_nolabel( + &self, + sink_mutex: &Mutex, + cause: impl Error + Send + Sync + 'static, + string: &'static str, + ) { + self.handle_error(sink_mutex, cause, "", None, string) + } + + fn handle_error_fatal( + &self, + cause: impl Error + Send + Sync + 'static, + string: &'static str, + ) -> ! { + panic!("Error in {}: {}", string, cause); + } +} + +mod pass_impl { + use super::Context; + use smallvec::SmallVec; + use std::convert::TryInto; + use std::ops::Range; + use wgc::command::{bundle_ffi::*, compute_ffi::*, render_ffi::*}; + + impl crate::ComputePassInner for wgc::command::ComputePass { + fn set_pipeline(&mut self, pipeline: &wgc::id::ComputePipelineId) { + wgpu_compute_pass_set_pipeline(self, *pipeline) + } + fn set_bind_group( + &mut self, + index: u32, + bind_group: &wgc::id::BindGroupId, + offsets: &[wgt::DynamicOffset], + ) { + unsafe { + wgpu_compute_pass_set_bind_group( + self, + index, + *bind_group, + offsets.as_ptr(), + offsets.len(), + ) + } + } + fn set_push_constants(&mut self, offset: u32, data: &[u8]) { + unsafe { + wgpu_compute_pass_set_push_constant( + self, + offset, + data.len().try_into().unwrap(), + data.as_ptr(), + ) + } + } + fn insert_debug_marker(&mut self, label: &str) { + unsafe { + let label = std::ffi::CString::new(label).unwrap(); + wgpu_compute_pass_insert_debug_marker(self, label.as_ptr(), 0); + } + } + + fn push_debug_group(&mut self, group_label: &str) { + unsafe { + let label = std::ffi::CString::new(group_label).unwrap(); + wgpu_compute_pass_push_debug_group(self, label.as_ptr(), 0); + } + } + fn pop_debug_group(&mut self) { + wgpu_compute_pass_pop_debug_group(self); + } + + fn write_timestamp(&mut self, query_set: &wgc::id::QuerySetId, query_index: u32) { + wgpu_compute_pass_write_timestamp(self, *query_set, query_index) + } + + fn begin_pipeline_statistics_query( + &mut self, + query_set: &wgc::id::QuerySetId, + query_index: u32, + ) { + wgpu_compute_pass_begin_pipeline_statistics_query(self, *query_set, query_index) + } + + fn end_pipeline_statistics_query(&mut self) { + wgpu_compute_pass_end_pipeline_statistics_query(self) + } + + fn dispatch(&mut self, x: u32, y: u32, z: u32) { + wgpu_compute_pass_dispatch(self, x, y, z) + } + fn dispatch_indirect( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + ) { + wgpu_compute_pass_dispatch_indirect(self, indirect_buffer.id, indirect_offset) + } + } + + impl crate::RenderInner for wgc::command::RenderPass { + fn set_pipeline(&mut self, pipeline: &wgc::id::RenderPipelineId) { + wgpu_render_pass_set_pipeline(self, *pipeline) + } + fn set_bind_group( + &mut self, + index: u32, + bind_group: &wgc::id::BindGroupId, + offsets: &[wgt::DynamicOffset], + ) { + unsafe { + wgpu_render_pass_set_bind_group( + self, + index, + *bind_group, + offsets.as_ptr(), + offsets.len(), + ) + } + } + fn set_index_buffer( + &mut self, + buffer: &super::Buffer, + index_format: wgt::IndexFormat, + offset: wgt::BufferAddress, + size: Option, + ) { + self.set_index_buffer(buffer.id, index_format, offset, size) + } + fn set_vertex_buffer( + &mut self, + slot: u32, + buffer: &super::Buffer, + offset: wgt::BufferAddress, + size: Option, + ) { + wgpu_render_pass_set_vertex_buffer(self, slot, buffer.id, offset, size) + } + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { + unsafe { + wgpu_render_pass_set_push_constants( + self, + stages, + offset, + data.len().try_into().unwrap(), + data.as_ptr(), + ) + } + } + fn draw(&mut self, vertices: Range, instances: Range) { + wgpu_render_pass_draw( + self, + vertices.end - vertices.start, + instances.end - instances.start, + vertices.start, + instances.start, + ) + } + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + wgpu_render_pass_draw_indexed( + self, + indices.end - indices.start, + instances.end - instances.start, + indices.start, + base_vertex, + instances.start, + ) + } + fn draw_indirect( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + ) { + wgpu_render_pass_draw_indirect(self, indirect_buffer.id, indirect_offset) + } + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + ) { + wgpu_render_pass_draw_indexed_indirect(self, indirect_buffer.id, indirect_offset) + } + fn multi_draw_indirect( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + count: u32, + ) { + wgpu_render_pass_multi_draw_indirect(self, indirect_buffer.id, indirect_offset, count) + } + fn multi_draw_indexed_indirect( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + count: u32, + ) { + wgpu_render_pass_multi_draw_indexed_indirect( + self, + indirect_buffer.id, + indirect_offset, + count, + ) + } + fn multi_draw_indirect_count( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + count_buffer: &super::Buffer, + count_buffer_offset: wgt::BufferAddress, + max_count: u32, + ) { + wgpu_render_pass_multi_draw_indirect_count( + self, + indirect_buffer.id, + indirect_offset, + count_buffer.id, + count_buffer_offset, + max_count, + ) + } + fn multi_draw_indexed_indirect_count( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + count_buffer: &super::Buffer, + count_buffer_offset: wgt::BufferAddress, + max_count: u32, + ) { + wgpu_render_pass_multi_draw_indexed_indirect_count( + self, + indirect_buffer.id, + indirect_offset, + count_buffer.id, + count_buffer_offset, + max_count, + ) + } + } + + impl crate::RenderPassInner for wgc::command::RenderPass { + fn set_blend_constant(&mut self, color: wgt::Color) { + wgpu_render_pass_set_blend_constant(self, &color) + } + fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) { + wgpu_render_pass_set_scissor_rect(self, x, y, width, height) + } + fn set_viewport( + &mut self, + x: f32, + y: f32, + width: f32, + height: f32, + min_depth: f32, + max_depth: f32, + ) { + wgpu_render_pass_set_viewport(self, x, y, width, height, min_depth, max_depth) + } + fn set_stencil_reference(&mut self, reference: u32) { + wgpu_render_pass_set_stencil_reference(self, reference) + } + + fn insert_debug_marker(&mut self, label: &str) { + unsafe { + let label = std::ffi::CString::new(label).unwrap(); + wgpu_render_pass_insert_debug_marker(self, label.as_ptr(), 0); + } + } + + fn push_debug_group(&mut self, group_label: &str) { + unsafe { + let label = std::ffi::CString::new(group_label).unwrap(); + wgpu_render_pass_push_debug_group(self, label.as_ptr(), 0); + } + } + + fn pop_debug_group(&mut self) { + wgpu_render_pass_pop_debug_group(self); + } + + fn write_timestamp(&mut self, query_set: &wgc::id::QuerySetId, query_index: u32) { + wgpu_render_pass_write_timestamp(self, *query_set, query_index) + } + + fn begin_pipeline_statistics_query( + &mut self, + query_set: &wgc::id::QuerySetId, + query_index: u32, + ) { + wgpu_render_pass_begin_pipeline_statistics_query(self, *query_set, query_index) + } + + fn end_pipeline_statistics_query(&mut self) { + wgpu_render_pass_end_pipeline_statistics_query(self) + } + + fn execute_bundles<'a, I: Iterator>( + &mut self, + render_bundles: I, + ) { + let temp_render_bundles = render_bundles.cloned().collect::>(); + unsafe { + wgpu_render_pass_execute_bundles( + self, + temp_render_bundles.as_ptr(), + temp_render_bundles.len(), + ) + } + } + } + + impl crate::RenderInner for wgc::command::RenderBundleEncoder { + fn set_pipeline(&mut self, pipeline: &wgc::id::RenderPipelineId) { + wgpu_render_bundle_set_pipeline(self, *pipeline) + } + fn set_bind_group( + &mut self, + index: u32, + bind_group: &wgc::id::BindGroupId, + offsets: &[wgt::DynamicOffset], + ) { + unsafe { + wgpu_render_bundle_set_bind_group( + self, + index, + *bind_group, + offsets.as_ptr(), + offsets.len(), + ) + } + } + fn set_index_buffer( + &mut self, + buffer: &super::Buffer, + index_format: wgt::IndexFormat, + offset: wgt::BufferAddress, + size: Option, + ) { + self.set_index_buffer(buffer.id, index_format, offset, size) + } + fn set_vertex_buffer( + &mut self, + slot: u32, + buffer: &super::Buffer, + offset: wgt::BufferAddress, + size: Option, + ) { + wgpu_render_bundle_set_vertex_buffer(self, slot, buffer.id, offset, size) + } + + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { + unsafe { + wgpu_render_bundle_set_push_constants( + self, + stages, + offset, + data.len().try_into().unwrap(), + data.as_ptr(), + ) + } + } + fn draw(&mut self, vertices: Range, instances: Range) { + wgpu_render_bundle_draw( + self, + vertices.end - vertices.start, + instances.end - instances.start, + vertices.start, + instances.start, + ) + } + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + wgpu_render_bundle_draw_indexed( + self, + indices.end - indices.start, + instances.end - instances.start, + indices.start, + base_vertex, + instances.start, + ) + } + fn draw_indirect( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + ) { + wgpu_render_bundle_draw_indirect(self, indirect_buffer.id, indirect_offset) + } + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &super::Buffer, + indirect_offset: wgt::BufferAddress, + ) { + wgpu_render_bundle_draw_indexed_indirect(self, indirect_buffer.id, indirect_offset) + } + fn multi_draw_indirect( + &mut self, + _indirect_buffer: &super::Buffer, + _indirect_offset: wgt::BufferAddress, + _count: u32, + ) { + unimplemented!() + } + fn multi_draw_indexed_indirect( + &mut self, + _indirect_buffer: &super::Buffer, + _indirect_offset: wgt::BufferAddress, + _count: u32, + ) { + unimplemented!() + } + fn multi_draw_indirect_count( + &mut self, + _indirect_buffer: &super::Buffer, + _indirect_offset: wgt::BufferAddress, + _count_buffer: &super::Buffer, + _count_buffer_offset: wgt::BufferAddress, + _max_count: u32, + ) { + unimplemented!() + } + fn multi_draw_indexed_indirect_count( + &mut self, + _indirect_buffer: &super::Buffer, + _indirect_offset: wgt::BufferAddress, + _count_buffer: &super::Buffer, + _count_buffer_offset: wgt::BufferAddress, + _max_count: u32, + ) { + unimplemented!() + } + } +} + +fn map_buffer_copy_view(view: crate::ImageCopyBuffer) -> wgc::command::ImageCopyBuffer { + wgc::command::ImageCopyBuffer { + buffer: view.buffer.id.id, + layout: view.layout, + } +} + +fn map_texture_copy_view(view: crate::ImageCopyTexture) -> wgc::command::ImageCopyTexture { + wgc::command::ImageCopyTexture { + texture: view.texture.id.id, + mip_level: view.mip_level, + origin: view.origin, + } +} + +fn map_pass_channel( + ops: Option<&Operations>, +) -> wgc::command::PassChannel { + match ops { + Some(&Operations { + load: LoadOp::Clear(clear_value), + store, + }) => wgc::command::PassChannel { + load_op: wgc::command::LoadOp::Clear, + store_op: if store { + wgc::command::StoreOp::Store + } else { + wgc::command::StoreOp::Clear + }, + clear_value, + read_only: false, + }, + Some(&Operations { + load: LoadOp::Load, + store, + }) => wgc::command::PassChannel { + load_op: wgc::command::LoadOp::Load, + store_op: if store { + wgc::command::StoreOp::Store + } else { + wgc::command::StoreOp::Clear + }, + clear_value: V::default(), + read_only: false, + }, + None => wgc::command::PassChannel { + load_op: wgc::command::LoadOp::Load, + store_op: wgc::command::StoreOp::Store, + clear_value: V::default(), + read_only: true, + }, + } +} + +#[derive(Debug)] +pub(crate) struct Device { + id: wgc::id::DeviceId, + error_sink: ErrorSink, + features: Features, +} + +#[derive(Debug)] +pub(crate) struct Buffer { + id: wgc::id::BufferId, + error_sink: ErrorSink, +} + +#[derive(Debug)] +pub(crate) struct Texture { + id: wgc::id::TextureId, + error_sink: ErrorSink, +} + +#[derive(Debug)] +pub(crate) struct CommandEncoder { + id: wgc::id::CommandEncoderId, + error_sink: ErrorSink, + open: bool, +} + +impl crate::Context for Context { + type AdapterId = wgc::id::AdapterId; + type DeviceId = Device; + type QueueId = wgc::id::QueueId; + type ShaderModuleId = wgc::id::ShaderModuleId; + type BindGroupLayoutId = wgc::id::BindGroupLayoutId; + type BindGroupId = wgc::id::BindGroupId; + type TextureViewId = wgc::id::TextureViewId; + type SamplerId = wgc::id::SamplerId; + type QuerySetId = wgc::id::QuerySetId; + type BufferId = Buffer; + type TextureId = Texture; + type PipelineLayoutId = wgc::id::PipelineLayoutId; + type RenderPipelineId = wgc::id::RenderPipelineId; + type ComputePipelineId = wgc::id::ComputePipelineId; + type CommandEncoderId = CommandEncoder; + type ComputePassId = wgc::command::ComputePass; + type RenderPassId = wgc::command::RenderPass; + type CommandBufferId = wgc::id::CommandBufferId; + type RenderBundleEncoderId = wgc::command::RenderBundleEncoder; + type RenderBundleId = wgc::id::RenderBundleId; + type SurfaceId = wgc::id::SurfaceId; + type SwapChainId = wgc::id::SwapChainId; + + type SwapChainOutputDetail = SwapChainOutputDetail; + + type RequestAdapterFuture = Ready>; + #[allow(clippy::type_complexity)] + type RequestDeviceFuture = + Ready>; + type MapAsyncFuture = native_gpu_future::GpuFuture>; + + fn init(backends: wgt::BackendBit) -> Self { + Self(wgc::hub::Global::new( + "wgpu", + wgc::hub::IdentityManagerFactory, + backends, + )) + } + + fn instance_create_surface( + &self, + handle: &impl raw_window_handle::HasRawWindowHandle, + ) -> Self::SurfaceId { + self.0.instance_create_surface(handle, PhantomData) + } + + fn instance_request_adapter( + &self, + options: &crate::RequestAdapterOptions, + ) -> Self::RequestAdapterFuture { + let id = self.0.request_adapter( + &wgc::instance::RequestAdapterOptions { + power_preference: options.power_preference, + compatible_surface: options.compatible_surface.map(|surface| surface.id), + }, + wgc::instance::AdapterInputs::Mask(wgt::BackendBit::all(), |_| PhantomData), + ); + ready(id.ok()) + } + + fn instance_poll_all_devices(&self, force_wait: bool) { + let global = &self.0; + match global.poll_all_devices(force_wait) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Device::poll"), + } + } + + fn adapter_request_device( + &self, + adapter: &Self::AdapterId, + desc: &crate::DeviceDescriptor, + trace_dir: Option<&std::path::Path>, + ) -> Self::RequestDeviceFuture { + let global = &self.0; + let (device_id, error) = wgc::gfx_select!(*adapter => global.adapter_request_device( + *adapter, + &desc.map_label(|l| l.map(Borrowed)), + trace_dir, + PhantomData + )); + if let Some(err) = error { + self.handle_error_fatal(err, "Adapter::request_device"); + } + let device = Device { + id: device_id, + error_sink: Arc::new(Mutex::new(ErrorSinkRaw::new())), + features: desc.features, + }; + ready(Ok((device, device_id))) + } + + fn adapter_get_swap_chain_preferred_format( + &self, + adapter: &Self::AdapterId, + surface: &Self::SurfaceId, + ) -> Option { + let global = &self.0; + match wgc::gfx_select!(adapter => global.adapter_get_swap_chain_preferred_format(*adapter, *surface)) + { + Ok(swap_chain_preferred_format) => Some(swap_chain_preferred_format), + Err(wgc::instance::GetSwapChainPreferredFormatError::UnsupportedQueueFamily) => None, + Err(err) => self.handle_error_fatal(err, "Adapter::get_swap_chain_preferred_format"), + } + } + + fn adapter_features(&self, adapter: &Self::AdapterId) -> Features { + let global = &self.0; + match wgc::gfx_select!(*adapter => global.adapter_features(*adapter)) { + Ok(features) => features, + Err(err) => self.handle_error_fatal(err, "Adapter::features"), + } + } + + fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits { + let global = &self.0; + match wgc::gfx_select!(*adapter => global.adapter_limits(*adapter)) { + Ok(limits) => limits, + Err(err) => self.handle_error_fatal(err, "Adapter::limits"), + } + } + + fn adapter_downlevel_properties(&self, adapter: &Self::AdapterId) -> DownlevelProperties { + let global = &self.0; + match wgc::gfx_select!(*adapter => global.adapter_downlevel_properties(*adapter)) { + Ok(downlevel) => downlevel, + Err(err) => self.handle_error_fatal(err, "Adapter::downlevel_properties"), + } + } + + fn adapter_get_info(&self, adapter: &wgc::id::AdapterId) -> AdapterInfo { + let global = &self.0; + match wgc::gfx_select!(*adapter => global.adapter_get_info(*adapter)) { + Ok(info) => info, + Err(err) => self.handle_error_fatal(err, "Adapter::get_info"), + } + } + + fn adapter_get_texture_format_features( + &self, + adapter: &Self::AdapterId, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures { + let global = &self.0; + match wgc::gfx_select!(*adapter => global.adapter_get_texture_format_features(*adapter, format)) + { + Ok(info) => info, + Err(err) => self.handle_error_fatal(err, "Adapter::get_texture_format_features"), + } + } + + fn device_features(&self, device: &Self::DeviceId) -> Features { + let global = &self.0; + match wgc::gfx_select!(device.id => global.device_features(device.id)) { + Ok(features) => features, + Err(err) => self.handle_error_fatal(err, "Device::features"), + } + } + + fn device_limits(&self, device: &Self::DeviceId) -> Limits { + let global = &self.0; + match wgc::gfx_select!(device.id => global.device_limits(device.id)) { + Ok(limits) => limits, + Err(err) => self.handle_error_fatal(err, "Device::limits"), + } + } + + fn device_downlevel_properties(&self, device: &Self::DeviceId) -> DownlevelProperties { + let global = &self.0; + match wgc::gfx_select!(device.id => global.device_downlevel_properties(device.id)) { + Ok(limits) => limits, + Err(err) => self.handle_error_fatal(err, "Device::downlevel_properties"), + } + } + + fn device_create_swap_chain( + &self, + device: &Self::DeviceId, + surface: &Self::SurfaceId, + desc: &wgt::SwapChainDescriptor, + ) -> Self::SwapChainId { + let global = &self.0; + let (sc, error) = wgc::gfx_select!(device.id => global.device_create_swap_chain(device.id, *surface, desc)); + match error { + Some(e) => self.handle_error_fatal(e, "Device::create_swap_chain"), + None => sc, + } + } + + fn device_create_shader_module( + &self, + device: &Self::DeviceId, + desc: &ShaderModuleDescriptor, + ) -> Self::ShaderModuleId { + let global = &self.0; + let descriptor = wgc::pipeline::ShaderModuleDescriptor { + label: desc.label.map(Borrowed), + flags: desc.flags, + }; + let source = match desc.source { + ShaderSource::SpirV(ref spv) => wgc::pipeline::ShaderModuleSource::SpirV(Borrowed(spv)), + ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)), + }; + let (id, error) = wgc::gfx_select!( + device.id => global.device_create_shader_module(device.id, &descriptor, source, PhantomData) + ); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_shader_module", + ); + } + id + } + + fn device_create_bind_group_layout( + &self, + device: &Self::DeviceId, + desc: &BindGroupLayoutDescriptor, + ) -> Self::BindGroupLayoutId { + let global = &self.0; + let descriptor = wgc::binding_model::BindGroupLayoutDescriptor { + label: desc.label.map(Borrowed), + entries: Borrowed(desc.entries), + }; + let (id, error) = wgc::gfx_select!( + device.id => global.device_create_bind_group_layout(device.id, &descriptor, PhantomData) + ); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_bind_group_layout", + ); + } + id + } + + fn device_create_bind_group( + &self, + device: &Self::DeviceId, + desc: &BindGroupDescriptor, + ) -> Self::BindGroupId { + use wgc::binding_model as bm; + + let mut arrayed_texture_views = Vec::new(); + if device + .features + .contains(Features::SAMPLED_TEXTURE_BINDING_ARRAY) + { + // gather all the array view IDs first + for entry in desc.entries.iter() { + if let BindingResource::TextureViewArray(array) = entry.resource { + arrayed_texture_views.extend(array.iter().map(|view| view.id)); + } + } + } + let mut remaining_arrayed_texture_views = &arrayed_texture_views[..]; + + let mut arrayed_buffer_bindings = Vec::new(); + if device.features.contains(Features::BUFFER_BINDING_ARRAY) { + // gather all the buffers first + for entry in desc.entries.iter() { + if let BindingResource::BufferArray(array) = entry.resource { + arrayed_buffer_bindings.extend(array.iter().map(|binding| bm::BufferBinding { + buffer_id: binding.buffer.id.id, + offset: binding.offset, + size: binding.size, + })); + } + } + } + let mut remaining_arrayed_buffer_bindings = &arrayed_buffer_bindings[..]; + + let entries = desc + .entries + .iter() + .map(|entry| bm::BindGroupEntry { + binding: entry.binding, + resource: match entry.resource { + BindingResource::Buffer(BufferBinding { + buffer, + offset, + size, + }) => bm::BindingResource::Buffer(bm::BufferBinding { + buffer_id: buffer.id.id, + offset, + size, + }), + BindingResource::BufferArray(array) => { + let slice = &remaining_arrayed_buffer_bindings[..array.len()]; + remaining_arrayed_buffer_bindings = + &remaining_arrayed_buffer_bindings[array.len()..]; + bm::BindingResource::BufferArray(Borrowed(slice)) + } + BindingResource::Sampler(sampler) => bm::BindingResource::Sampler(sampler.id), + BindingResource::TextureView(texture_view) => { + bm::BindingResource::TextureView(texture_view.id) + } + BindingResource::TextureViewArray(array) => { + let slice = &remaining_arrayed_texture_views[..array.len()]; + remaining_arrayed_texture_views = + &remaining_arrayed_texture_views[array.len()..]; + bm::BindingResource::TextureViewArray(Borrowed(slice)) + } + }, + }) + .collect::>(); + let descriptor = bm::BindGroupDescriptor { + label: desc.label.as_ref().map(|label| Borrowed(&label[..])), + layout: desc.layout.id, + entries: Borrowed(&entries), + }; + + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_bind_group( + device.id, + &descriptor, + PhantomData + )); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_bind_group", + ); + } + id + } + + fn device_create_pipeline_layout( + &self, + device: &Self::DeviceId, + desc: &PipelineLayoutDescriptor, + ) -> Self::PipelineLayoutId { + // Limit is always less or equal to wgc::MAX_BIND_GROUPS, so this is always right + // Guards following ArrayVec + assert!( + desc.bind_group_layouts.len() <= wgc::MAX_BIND_GROUPS, + "Bind group layout count {} exceeds device bind group limit {}", + desc.bind_group_layouts.len(), + wgc::MAX_BIND_GROUPS + ); + + let temp_layouts = desc + .bind_group_layouts + .iter() + .map(|bgl| bgl.id) + .collect::>(); + let descriptor = wgc::binding_model::PipelineLayoutDescriptor { + label: desc.label.map(Borrowed), + bind_group_layouts: Borrowed(&temp_layouts), + push_constant_ranges: Borrowed(&desc.push_constant_ranges), + }; + + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_pipeline_layout( + device.id, + &descriptor, + PhantomData + )); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_pipeline_layout", + ); + } + id + } + + fn device_create_render_pipeline( + &self, + device: &Self::DeviceId, + desc: &RenderPipelineDescriptor, + ) -> Self::RenderPipelineId { + use wgc::pipeline as pipe; + + let vertex_buffers: ArrayVec<[_; wgc::device::MAX_VERTEX_BUFFERS]> = desc + .vertex + .buffers + .iter() + .map(|vbuf| pipe::VertexBufferLayout { + array_stride: vbuf.array_stride, + step_mode: vbuf.step_mode, + attributes: Borrowed(vbuf.attributes), + }) + .collect(); + + let implicit_pipeline_ids = match desc.layout { + Some(_) => None, + None => Some(wgc::device::ImplicitPipelineIds { + root_id: PhantomData, + group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS], + }), + }; + let descriptor = pipe::RenderPipelineDescriptor { + label: desc.label.map(Borrowed), + layout: desc.layout.map(|l| l.id), + vertex: pipe::VertexState { + stage: pipe::ProgrammableStageDescriptor { + module: desc.vertex.module.id, + entry_point: Borrowed(desc.vertex.entry_point), + }, + buffers: Borrowed(&vertex_buffers), + }, + primitive: desc.primitive, + depth_stencil: desc.depth_stencil.clone(), + multisample: desc.multisample, + fragment: desc.fragment.as_ref().map(|frag| pipe::FragmentState { + stage: pipe::ProgrammableStageDescriptor { + module: frag.module.id, + entry_point: Borrowed(frag.entry_point), + }, + targets: Borrowed(frag.targets), + }), + }; + + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_render_pipeline( + device.id, + &descriptor, + PhantomData, + implicit_pipeline_ids + )); + if let Some(cause) = error { + if let wgc::pipeline::CreateRenderPipelineError::Internal { stage, ref error } = cause { + log::warn!("Shader translation error for stage {:?}: {}", stage, error); + log::warn!("Please report it to https://github.com/gfx-rs/naga"); + log::warn!("Try enabling `wgpu/cross` feature as a workaround."); + } + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_render_pipeline", + ); + } + id + } + + fn device_create_compute_pipeline( + &self, + device: &Self::DeviceId, + desc: &ComputePipelineDescriptor, + ) -> Self::ComputePipelineId { + use wgc::pipeline as pipe; + + let implicit_pipeline_ids = match desc.layout { + Some(_) => None, + None => Some(wgc::device::ImplicitPipelineIds { + root_id: PhantomData, + group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS], + }), + }; + let descriptor = pipe::ComputePipelineDescriptor { + label: desc.label.map(Borrowed), + layout: desc.layout.map(|l| l.id), + stage: pipe::ProgrammableStageDescriptor { + module: desc.module.id, + entry_point: Borrowed(desc.entry_point), + }, + }; + + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_compute_pipeline( + device.id, + &descriptor, + PhantomData, + implicit_pipeline_ids + )); + if let Some(cause) = error { + if let wgc::pipeline::CreateComputePipelineError::Internal(ref error) = cause { + log::warn!( + "Shader translation error for stage {:?}: {}", + wgt::ShaderStage::COMPUTE, + error + ); + log::warn!("Please report it to https://github.com/gfx-rs/naga"); + log::warn!("Try enabling `wgpu/cross` feature as a workaround."); + } + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_compute_pipeline", + ); + } + id + } + + fn device_create_buffer( + &self, + device: &Self::DeviceId, + desc: &crate::BufferDescriptor<'_>, + ) -> Self::BufferId { + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_buffer( + device.id, + &desc.map_label(|l| l.map(Borrowed)), + PhantomData + )); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_buffer", + ); + } + Buffer { + id, + error_sink: Arc::clone(&device.error_sink), + } + } + + fn device_create_texture( + &self, + device: &Self::DeviceId, + desc: &TextureDescriptor, + ) -> Self::TextureId { + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_texture( + device.id, + &desc.map_label(|l| l.map(Borrowed)), + PhantomData + )); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_texture", + ); + } + Texture { + id, + error_sink: Arc::clone(&device.error_sink), + } + } + + fn device_create_sampler( + &self, + device: &Self::DeviceId, + desc: &SamplerDescriptor, + ) -> Self::SamplerId { + let descriptor = wgc::resource::SamplerDescriptor { + label: desc.label.map(Borrowed), + address_modes: [ + desc.address_mode_u, + desc.address_mode_v, + desc.address_mode_w, + ], + mag_filter: desc.mag_filter, + min_filter: desc.min_filter, + mipmap_filter: desc.mipmap_filter, + lod_min_clamp: desc.lod_min_clamp, + lod_max_clamp: desc.lod_max_clamp, + compare: desc.compare, + anisotropy_clamp: desc.anisotropy_clamp, + border_color: desc.border_color, + }; + + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_sampler( + device.id, + &descriptor, + PhantomData + )); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_sampler", + ); + } + id + } + + fn device_create_query_set( + &self, + device: &Self::DeviceId, + desc: &wgt::QuerySetDescriptor, + ) -> Self::QuerySetId { + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_query_set( + device.id, + &desc, + PhantomData + )); + if let Some(cause) = error { + self.handle_error_nolabel(&device.error_sink, cause, "Device::create_query_set"); + } + id + } + + fn device_create_command_encoder( + &self, + device: &Self::DeviceId, + desc: &CommandEncoderDescriptor, + ) -> Self::CommandEncoderId { + let global = &self.0; + let (id, error) = wgc::gfx_select!(device.id => global.device_create_command_encoder( + device.id, + &desc.map_label(|l| l.map(Borrowed)), + PhantomData + )); + if let Some(cause) = error { + self.handle_error( + &device.error_sink, + cause, + LABEL, + desc.label, + "Device::create_command_encoder", + ); + } + CommandEncoder { + id, + error_sink: Arc::clone(&device.error_sink), + open: true, + } + } + + fn device_create_render_bundle_encoder( + &self, + device: &Self::DeviceId, + desc: &RenderBundleEncoderDescriptor, + ) -> Self::RenderBundleEncoderId { + let descriptor = wgc::command::RenderBundleEncoderDescriptor { + label: desc.label.map(Borrowed), + color_formats: Borrowed(desc.color_formats), + depth_stencil_format: desc.depth_stencil_format, + sample_count: desc.sample_count, + }; + match wgc::command::RenderBundleEncoder::new(&descriptor, device.id, None) { + Ok(id) => id, + Err(e) => panic!("Error in Device::create_render_bundle_encoder: {}", e), + } + } + + fn device_drop(&self, device: &Self::DeviceId) { + #[cfg(not(target_arch = "wasm32"))] + { + let global = &self.0; + match wgc::gfx_select!(device.id => global.device_poll(device.id, true)) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Device::drop"), + } + } + //TODO: make this work in general + #[cfg(not(target_arch = "wasm32"))] + #[cfg(feature = "metal-auto-capture")] + { + let global = &self.0; + wgc::gfx_select!(device.id => global.device_drop(device.id)); + } + } + + fn device_poll(&self, device: &Self::DeviceId, maintain: crate::Maintain) { + let global = &self.0; + match wgc::gfx_select!(device.id => global.device_poll( + device.id, + match maintain { + crate::Maintain::Poll => false, + crate::Maintain::Wait => true, + } + )) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Device::poll"), + } + } + + fn device_on_uncaptured_error( + &self, + device: &Self::DeviceId, + handler: impl crate::UncapturedErrorHandler, + ) { + let mut error_sink = device.error_sink.lock(); + error_sink.uncaptured_handler = Box::new(handler); + } + + fn buffer_map_async( + &self, + buffer: &Self::BufferId, + mode: MapMode, + range: Range, + ) -> Self::MapAsyncFuture { + let (future, completion) = native_gpu_future::new_gpu_future(); + + extern "C" fn buffer_map_future_wrapper( + status: wgc::resource::BufferMapAsyncStatus, + user_data: *mut u8, + ) { + let completion = + unsafe { native_gpu_future::GpuFutureCompletion::from_raw(user_data as _) }; + completion.complete(match status { + wgc::resource::BufferMapAsyncStatus::Success => Ok(()), + _ => Err(crate::BufferAsyncError), + }) + } + + let operation = wgc::resource::BufferMapOperation { + host: match mode { + MapMode::Read => wgc::device::HostMap::Read, + MapMode::Write => wgc::device::HostMap::Write, + }, + callback: buffer_map_future_wrapper, + user_data: completion.into_raw() as _, + }; + + let global = &self.0; + match wgc::gfx_select!(buffer.id => global.buffer_map_async(buffer.id, range, operation)) { + Ok(()) => (), + Err(cause) => self.handle_error_nolabel(&buffer.error_sink, cause, "Buffer::map_async"), + } + future + } + + fn buffer_get_mapped_range( + &self, + buffer: &Self::BufferId, + sub_range: Range, + ) -> BufferMappedRange { + let size = sub_range.end - sub_range.start; + let global = &self.0; + match wgc::gfx_select!(buffer.id => global.buffer_get_mapped_range( + buffer.id, + sub_range.start, + Some(size) + )) { + Ok((ptr, size)) => BufferMappedRange { + ptr, + size: size as usize, + }, + Err(err) => self.handle_error_fatal(err, "Buffer::get_mapped_range"), + } + } + + fn buffer_unmap(&self, buffer: &Self::BufferId) { + let global = &self.0; + match wgc::gfx_select!(buffer.id => global.buffer_unmap(buffer.id)) { + Ok(()) => (), + Err(cause) => { + self.handle_error_nolabel(&buffer.error_sink, cause, "Buffer::buffer_unmap") + } + } + } + + fn swap_chain_get_current_texture_view( + &self, + swap_chain: &Self::SwapChainId, + ) -> ( + Option, + SwapChainStatus, + Self::SwapChainOutputDetail, + ) { + let global = &self.0; + match wgc::gfx_select!( + *swap_chain => global.swap_chain_get_current_texture_view(*swap_chain, PhantomData) + ) { + Ok(wgc::swap_chain::SwapChainOutput { status, view_id }) => ( + view_id, + status, + SwapChainOutputDetail { + swap_chain_id: *swap_chain, + }, + ), + Err(err) => self.handle_error_fatal(err, "SwapChain::get_current_texture_view"), + } + } + + fn swap_chain_present(&self, view: &Self::TextureViewId, detail: &Self::SwapChainOutputDetail) { + let global = &self.0; + match wgc::gfx_select!(*view => global.swap_chain_present(detail.swap_chain_id)) { + Ok(_status) => (), + Err(err) => self.handle_error_fatal(err, "SwapChain::present"), + } + } + + fn texture_create_view( + &self, + texture: &Self::TextureId, + desc: &TextureViewDescriptor, + ) -> Self::TextureViewId { + let descriptor = wgc::resource::TextureViewDescriptor { + label: desc.label.map(Borrowed), + format: desc.format, + dimension: desc.dimension, + range: wgt::ImageSubresourceRange { + aspect: desc.aspect, + base_mip_level: desc.base_mip_level, + mip_level_count: desc.mip_level_count, + base_array_layer: desc.base_array_layer, + array_layer_count: desc.array_layer_count, + }, + }; + let global = &self.0; + let (id, error) = wgc::gfx_select!( + texture.id => global.texture_create_view(texture.id, &descriptor, PhantomData) + ); + if let Some(cause) = error { + self.handle_error( + &texture.error_sink, + cause, + LABEL, + desc.label, + "Texture::create_view", + ); + } + id + } + + fn surface_drop(&self, _surface: &Self::SurfaceId) { + //TODO: swapchain needs to hold the surface alive + //self.0.surface_drop(*surface) + } + + fn adapter_drop(&self, adapter: &Self::AdapterId) { + let global = &self.0; + wgc::gfx_select!(*adapter => global.adapter_drop(*adapter)) + } + + fn buffer_destroy(&self, buffer: &Self::BufferId) { + let global = &self.0; + match wgc::gfx_select!(buffer.id => global.buffer_destroy(buffer.id)) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Buffer::destroy"), + } + } + fn buffer_drop(&self, buffer: &Self::BufferId) { + let global = &self.0; + wgc::gfx_select!(buffer.id => global.buffer_drop(buffer.id, false)) + } + fn texture_destroy(&self, texture: &Self::TextureId) { + let global = &self.0; + match wgc::gfx_select!(texture.id => global.texture_destroy(texture.id)) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Texture::destroy"), + } + } + fn texture_drop(&self, texture: &Self::TextureId) { + let global = &self.0; + wgc::gfx_select!(texture.id => global.texture_drop(texture.id, false)) + } + fn texture_view_drop(&self, texture_view: &Self::TextureViewId) { + let global = &self.0; + match wgc::gfx_select!(*texture_view => global.texture_view_drop(*texture_view, false)) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "TextureView::drop"), + } + } + fn sampler_drop(&self, sampler: &Self::SamplerId) { + let global = &self.0; + wgc::gfx_select!(*sampler => global.sampler_drop(*sampler)) + } + fn query_set_drop(&self, query_set: &Self::QuerySetId) { + let global = &self.0; + wgc::gfx_select!(*query_set => global.query_set_drop(*query_set)) + } + fn bind_group_drop(&self, bind_group: &Self::BindGroupId) { + let global = &self.0; + wgc::gfx_select!(*bind_group => global.bind_group_drop(*bind_group)) + } + fn bind_group_layout_drop(&self, bind_group_layout: &Self::BindGroupLayoutId) { + let global = &self.0; + wgc::gfx_select!(*bind_group_layout => global.bind_group_layout_drop(*bind_group_layout)) + } + fn pipeline_layout_drop(&self, pipeline_layout: &Self::PipelineLayoutId) { + let global = &self.0; + wgc::gfx_select!(*pipeline_layout => global.pipeline_layout_drop(*pipeline_layout)) + } + fn shader_module_drop(&self, shader_module: &Self::ShaderModuleId) { + let global = &self.0; + wgc::gfx_select!(*shader_module => global.shader_module_drop(*shader_module)) + } + fn command_encoder_drop(&self, command_encoder: &Self::CommandEncoderId) { + if command_encoder.open { + let global = &self.0; + wgc::gfx_select!(command_encoder.id => global.command_encoder_drop(command_encoder.id)) + } + } + fn command_buffer_drop(&self, command_buffer: &Self::CommandBufferId) { + let global = &self.0; + wgc::gfx_select!(*command_buffer => global.command_buffer_drop(*command_buffer)) + } + fn render_bundle_drop(&self, render_bundle: &Self::RenderBundleId) { + let global = &self.0; + wgc::gfx_select!(*render_bundle => global.render_bundle_drop(*render_bundle)) + } + fn compute_pipeline_drop(&self, pipeline: &Self::ComputePipelineId) { + let global = &self.0; + wgc::gfx_select!(*pipeline => global.compute_pipeline_drop(*pipeline)) + } + fn render_pipeline_drop(&self, pipeline: &Self::RenderPipelineId) { + let global = &self.0; + wgc::gfx_select!(*pipeline => global.render_pipeline_drop(*pipeline)) + } + + fn compute_pipeline_get_bind_group_layout( + &self, + pipeline: &Self::ComputePipelineId, + index: u32, + ) -> Self::BindGroupLayoutId { + let global = &self.0; + let (id, error) = wgc::gfx_select!(*pipeline => global.compute_pipeline_get_bind_group_layout(*pipeline, index, PhantomData)); + if let Some(err) = error { + panic!("Error reflecting bind group {}: {}", index, err); + } + id + } + fn render_pipeline_get_bind_group_layout( + &self, + pipeline: &Self::RenderPipelineId, + index: u32, + ) -> Self::BindGroupLayoutId { + let global = &self.0; + let (id, error) = wgc::gfx_select!(*pipeline => global.render_pipeline_get_bind_group_layout(*pipeline, index, PhantomData)); + if let Some(err) = error { + panic!("Error reflecting bind group {}: {}", index, err); + } + id + } + + fn command_encoder_copy_buffer_to_buffer( + &self, + encoder: &Self::CommandEncoderId, + source: &Self::BufferId, + source_offset: wgt::BufferAddress, + destination: &Self::BufferId, + destination_offset: wgt::BufferAddress, + copy_size: wgt::BufferAddress, + ) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_copy_buffer_to_buffer( + encoder.id, + source.id, + source_offset, + destination.id, + destination_offset, + copy_size + )) { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::copy_buffer_to_buffer", + ); + } + } + + fn command_encoder_copy_buffer_to_texture( + &self, + encoder: &Self::CommandEncoderId, + source: crate::ImageCopyBuffer, + destination: crate::ImageCopyTexture, + copy_size: wgt::Extent3d, + ) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_copy_buffer_to_texture( + encoder.id, + &map_buffer_copy_view(source), + &map_texture_copy_view(destination), + ©_size + )) { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::copy_buffer_to_texture", + ); + } + } + + fn command_encoder_copy_texture_to_buffer( + &self, + encoder: &Self::CommandEncoderId, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyBuffer, + copy_size: wgt::Extent3d, + ) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_copy_texture_to_buffer( + encoder.id, + &map_texture_copy_view(source), + &map_buffer_copy_view(destination), + ©_size + )) { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::copy_texture_to_buffer", + ); + } + } + + fn command_encoder_copy_texture_to_texture( + &self, + encoder: &Self::CommandEncoderId, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyTexture, + copy_size: wgt::Extent3d, + ) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_copy_texture_to_texture( + encoder.id, + &map_texture_copy_view(source), + &map_texture_copy_view(destination), + ©_size + )) { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::copy_texture_to_texture", + ); + } + } + + fn command_encoder_write_timestamp( + &self, + encoder: &Self::CommandEncoderId, + query_set: &Self::QuerySetId, + query_index: u32, + ) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_write_timestamp( + encoder.id, + *query_set, + query_index + )) { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::write_timestamp", + ); + } + } + + fn command_encoder_resolve_query_set( + &self, + encoder: &Self::CommandEncoderId, + query_set: &Self::QuerySetId, + first_query: u32, + query_count: u32, + destination: &Self::BufferId, + destination_offset: wgt::BufferAddress, + ) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_resolve_query_set( + encoder.id, + *query_set, + first_query, + query_count, + destination.id, + destination_offset + )) { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::resolve_query_set", + ); + } + } + + fn command_encoder_begin_compute_pass( + &self, + encoder: &Self::CommandEncoderId, + desc: &ComputePassDescriptor, + ) -> Self::ComputePassId { + wgc::command::ComputePass::new( + encoder.id, + &wgc::command::ComputePassDescriptor { + label: desc.label.map(Borrowed), + }, + ) + } + + fn command_encoder_end_compute_pass( + &self, + encoder: &Self::CommandEncoderId, + pass: &mut Self::ComputePassId, + ) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!( + encoder.id => global.command_encoder_run_compute_pass(encoder.id, pass) + ) { + let name = wgc::gfx_select!(encoder.id => global.command_buffer_label(encoder.id)); + self.handle_error( + &encoder.error_sink, + cause, + "encoder", + Some(&name), + "a ComputePass", + ); + } + } + + fn command_encoder_begin_render_pass<'a>( + &self, + encoder: &Self::CommandEncoderId, + desc: &crate::RenderPassDescriptor<'a, '_>, + ) -> Self::RenderPassId { + let colors = desc + .color_attachments + .iter() + .map(|ca| wgc::command::RenderPassColorAttachment { + view: ca.view.id, + resolve_target: ca.resolve_target.map(|rt| rt.id), + channel: map_pass_channel(Some(&ca.ops)), + }) + .collect::>(); + + let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| { + wgc::command::RenderPassDepthStencilAttachment { + view: dsa.view.id, + depth: map_pass_channel(dsa.depth_ops.as_ref()), + stencil: map_pass_channel(dsa.stencil_ops.as_ref()), + } + }); + + wgc::command::RenderPass::new( + encoder.id, + &wgc::command::RenderPassDescriptor { + label: desc.label.map(Borrowed), + color_attachments: Borrowed(&colors), + depth_stencil_attachment: depth_stencil.as_ref(), + }, + ) + } + + fn command_encoder_end_render_pass( + &self, + encoder: &Self::CommandEncoderId, + pass: &mut Self::RenderPassId, + ) { + let global = &self.0; + if let Err(cause) = + wgc::gfx_select!(encoder.id => global.command_encoder_run_render_pass(encoder.id, pass)) + { + let name = wgc::gfx_select!(encoder.id => global.command_buffer_label(encoder.id)); + self.handle_error( + &encoder.error_sink, + cause, + "encoder", + Some(&name), + "a RenderPass", + ); + } + } + + fn command_encoder_finish(&self, mut encoder: Self::CommandEncoderId) -> Self::CommandBufferId { + let descriptor = wgt::CommandBufferDescriptor::default(); + encoder.open = false; // prevent the drop + let global = &self.0; + let (id, error) = + wgc::gfx_select!(encoder.id => global.command_encoder_finish(encoder.id, &descriptor)); + if let Some(cause) = error { + self.handle_error_nolabel(&encoder.error_sink, cause, "a CommandEncoder"); + } + id + } + + fn command_encoder_insert_debug_marker(&self, encoder: &Self::CommandEncoderId, label: &str) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_insert_debug_marker(encoder.id, &label)) + { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::insert_debug_marker", + ); + } + } + fn command_encoder_push_debug_group(&self, encoder: &Self::CommandEncoderId, label: &str) { + let global = &self.0; + if let Err(cause) = wgc::gfx_select!(encoder.id => global.command_encoder_push_debug_group(encoder.id, &label)) + { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::push_debug_group", + ); + } + } + fn command_encoder_pop_debug_group(&self, encoder: &Self::CommandEncoderId) { + let global = &self.0; + if let Err(cause) = + wgc::gfx_select!(encoder.id => global.command_encoder_pop_debug_group(encoder.id)) + { + self.handle_error_nolabel( + &encoder.error_sink, + cause, + "CommandEncoder::pop_debug_group", + ); + } + } + + fn render_bundle_encoder_finish( + &self, + encoder: Self::RenderBundleEncoderId, + desc: &crate::RenderBundleDescriptor, + ) -> Self::RenderBundleId { + let global = &self.0; + let (id, error) = wgc::gfx_select!(encoder.parent() => global.render_bundle_encoder_finish( + encoder, + &desc.map_label(|l| l.map(Borrowed)), + PhantomData + )); + if let Some(err) = error { + self.handle_error_fatal(err, "RenderBundleEncoder::finish"); + } + id + } + + fn queue_write_buffer( + &self, + queue: &Self::QueueId, + buffer: &Self::BufferId, + offset: wgt::BufferAddress, + data: &[u8], + ) { + let global = &self.0; + match wgc::gfx_select!( + *queue => global.queue_write_buffer(*queue, buffer.id, offset, data) + ) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Queue::write_buffer"), + } + } + + fn queue_write_texture( + &self, + queue: &Self::QueueId, + texture: crate::ImageCopyTexture, + data: &[u8], + data_layout: wgt::ImageDataLayout, + size: wgt::Extent3d, + ) { + let global = &self.0; + match wgc::gfx_select!(*queue => global.queue_write_texture( + *queue, + &map_texture_copy_view(texture), + data, + &data_layout, + &size + )) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Queue::write_texture"), + } + } + + fn queue_submit>( + &self, + queue: &Self::QueueId, + command_buffers: I, + ) { + let temp_command_buffers = command_buffers.collect::>(); + + let global = &self.0; + match wgc::gfx_select!(*queue => global.queue_submit(*queue, &temp_command_buffers)) { + Ok(()) => (), + Err(err) => self.handle_error_fatal(err, "Queue::submit"), + } + } + + fn queue_get_timestamp_period(&self, queue: &Self::QueueId) -> f32 { + let global = &self.0; + let res = wgc::gfx_select!(queue => global.queue_get_timestamp_period( + *queue + )); + match res { + Ok(v) => v, + Err(cause) => { + self.handle_error_fatal(cause, "Queue::get_timestamp_period"); + } + } + } + + fn device_start_capture(&self, device: &Self::DeviceId) { + let global = &self.0; + wgc::gfx_select!(device.id => global.device_start_capture(device.id)); + } + + fn device_stop_capture(&self, device: &Self::DeviceId) { + let global = &self.0; + wgc::gfx_select!(device.id => global.device_stop_capture(device.id)); + } +} + +#[derive(Debug)] +pub(crate) struct SwapChainOutputDetail { + swap_chain_id: wgc::id::SwapChainId, +} + +type ErrorSink = Arc>; + +struct ErrorSinkRaw { + uncaptured_handler: Box, +} + +impl ErrorSinkRaw { + fn new() -> ErrorSinkRaw { + ErrorSinkRaw { + uncaptured_handler: Box::from(default_error_handler), + } + } + + fn handle_error(&self, err: crate::Error) { + (self.uncaptured_handler)(err); + } +} + +impl fmt::Debug for ErrorSinkRaw { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "ErrorSink") + } +} + +fn default_error_handler(err: crate::Error) { + eprintln!("wgpu error: {}\n", err); + + panic!("Handling wgpu errors as fatal by default"); +} + +#[derive(Debug)] +pub struct BufferMappedRange { + ptr: *mut u8, + size: usize, +} + +unsafe impl Send for BufferMappedRange {} +unsafe impl Sync for BufferMappedRange {} + +impl crate::BufferMappedRangeSlice for BufferMappedRange { + fn slice(&self) -> &[u8] { + unsafe { slice::from_raw_parts(self.ptr, self.size) } + } + + fn slice_mut(&mut self) -> &mut [u8] { + unsafe { slice::from_raw_parts_mut(self.ptr, self.size) } + } +} + +impl Drop for BufferMappedRange { + fn drop(&mut self) { + // Intentionally left blank so that `BufferMappedRange` still + // implements `Drop`, to match the web backend + } +} diff --git a/wgpu/src/backend/error.rs b/wgpu/src/backend/error.rs new file mode 100644 index 000000000..556e42fbf --- /dev/null +++ b/wgpu/src/backend/error.rs @@ -0,0 +1,333 @@ +use std::{error::Error, fmt}; + +#[derive(Debug)] +pub(super) struct ContextError { + pub string: &'static str, + pub cause: Box, + pub label_key: &'static str, + pub label: String, +} + +impl fmt::Display for ContextError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "In {}", self.string) + } +} + +impl Error for ContextError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + Some(self.cause.as_ref()) + } +} + +impl super::Context { + pub(super) fn format_error(&self, err: &(impl Error + 'static)) -> String { + let mut err_descs = vec![self.format_pretty_any(err)]; + + let mut source_opt = err.source(); + while let Some(source) = source_opt { + err_descs.push(self.format_pretty_any(source)); + source_opt = source.source(); + } + + format!("Validation Error\n\nCaused by:\n{}", err_descs.join("")) + } + + fn format_pretty_any(&self, error: &(dyn Error + 'static)) -> String { + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = + error.downcast_ref::() + { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + if let Some(pretty_err) = error.downcast_ref::() { + return pretty_err.fmt_pretty(self); + } + + // default + format_error_line(error.as_display()) + } +} + +pub(super) fn format_error_line(err: &dyn fmt::Display) -> String { + format!(" {}\n", err) +} + +pub(super) fn format_note_line(note: &dyn fmt::Display) -> String { + format!(" note: {}\n", note) +} + +pub(super) fn format_label_line(label_key: &str, label_value: &str) -> String { + if label_key.is_empty() || label_value.is_empty() { + String::new() + } else { + format_note_line(&format!("{} = `{}`", label_key, label_value)) + } +} + +trait AsDisplay { + fn as_display(&self) -> &dyn fmt::Display; +} + +impl AsDisplay for T { + fn as_display(&self) -> &dyn fmt::Display { + self + } +} + +pub trait PrettyError: Error { + fn fmt_pretty(&self, _context: &super::Context) -> String { + format_error_line(self.as_display()) + } +} + +impl PrettyError for ContextError { + fn fmt_pretty(&self, _context: &super::Context) -> String { + format_error_line(self.as_display()) + &format_label_line(self.label_key, &self.label) + } +} + +impl PrettyError for wgc::command::RenderCommandError { + fn fmt_pretty(&self, context: &super::Context) -> String { + let global = context.global(); + let mut ret = format_error_line(self); + match *self { + Self::InvalidBindGroup(id) => { + let name = wgc::gfx_select!(id => global.bind_group_label(id)); + ret.push_str(&format_label_line("bind group", &name)); + } + Self::InvalidPipeline(id) => { + let name = wgc::gfx_select!(id => global.render_pipeline_label(id)); + ret.push_str(&format_label_line("render pipeline", &name)); + } + Self::Buffer(id, ..) | Self::DestroyedBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + ret.push_str(&format_label_line("buffer", &name)); + } + _ => {} + }; + ret + } +} +impl PrettyError for wgc::binding_model::CreateBindGroupError { + fn fmt_pretty(&self, context: &super::Context) -> String { + let global = context.global(); + let mut ret = format_error_line(self); + match *self { + Self::InvalidBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + ret.push_str(&format_label_line("buffer", &name)); + } + Self::InvalidTextureView(id) => { + let name = wgc::gfx_select!(id => global.texture_view_label(id)); + ret.push_str(&format_label_line("texture view", &name)); + } + Self::InvalidSampler(id) => { + let name = wgc::gfx_select!(id => global.sampler_label(id)); + ret.push_str(&format_label_line("sampler", &name)); + } + _ => {} + }; + ret + } +} + +impl PrettyError for wgc::binding_model::CreatePipelineLayoutError { + fn fmt_pretty(&self, context: &super::Context) -> String { + let global = context.global(); + let mut ret = format_error_line(self); + if let Self::InvalidBindGroupLayout(id) = *self { + let name = wgc::gfx_select!(id => global.bind_group_layout_label(id)); + ret.push_str(&format_label_line("bind group layout", &name)); + }; + ret + } +} + +impl PrettyError for wgc::command::ExecutionError { + fn fmt_pretty(&self, context: &super::Context) -> String { + let global = context.global(); + let mut ret = format_error_line(self); + match *self { + Self::DestroyedBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + ret.push_str(&format_label_line("buffer", &name)); + } + Self::Unimplemented(_reason) => {} + }; + ret + } +} + +impl PrettyError for wgc::command::RenderPassErrorInner { + fn fmt_pretty(&self, context: &super::Context) -> String { + let global = context.global(); + let mut ret = format_error_line(self); + if let Self::InvalidAttachment(id) = *self { + let name = wgc::gfx_select!(id => global.texture_view_label(id)); + ret.push_str(&format_label_line("attachment", &name)); + }; + ret + } +} + +impl PrettyError for wgc::command::RenderPassError { + fn fmt_pretty(&self, context: &super::Context) -> String { + // This error is wrapper for the inner error, + // but the scope has useful labels + format_error_line(self) + &self.scope.fmt_pretty(context) + } +} + +impl PrettyError for wgc::command::ComputePassError { + fn fmt_pretty(&self, context: &super::Context) -> String { + // This error is wrapper for the inner error, + // but the scope has useful labels + format_error_line(self) + &self.scope.fmt_pretty(context) + } +} +impl PrettyError for wgc::command::RenderBundleError { + fn fmt_pretty(&self, context: &super::Context) -> String { + // This error is wrapper for the inner error, + // but the scope has useful labels + format_error_line(self) + &self.scope.fmt_pretty(context) + } +} + +impl PrettyError for wgc::command::ComputePassErrorInner { + fn fmt_pretty(&self, context: &super::Context) -> String { + let global = context.global(); + let mut ret = format_error_line(self); + match *self { + Self::InvalidBindGroup(id) => { + let name = wgc::gfx_select!(id => global.bind_group_label(id)); + ret.push_str(&format_label_line("bind group", &name)); + } + Self::InvalidPipeline(id) => { + let name = wgc::gfx_select!(id => global.compute_pipeline_label(id)); + ret.push_str(&format_label_line("pipeline", &name)); + } + Self::InvalidIndirectBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + ret.push_str(&format_label_line("indirect buffer", &name)); + } + _ => {} + }; + ret + } +} + +impl PrettyError for wgc::command::TransferError { + fn fmt_pretty(&self, context: &super::Context) -> String { + let global = context.global(); + let mut ret = format_error_line(self); + match *self { + Self::InvalidBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + ret.push_str(&format_label_line("label", &name)); + } + Self::InvalidTexture(id) => { + let name = wgc::gfx_select!(id => global.texture_label(id)); + ret.push_str(&format_label_line("texture", &name)); + } + // Self::MissingCopySrcUsageFlag(buf_opt, tex_opt) => { + // if let Some(buf) = buf_opt { + // let name = wgc::gfx_select!(buf => global.buffer_label(buf)); + // ret.push_str(&format_label_line("source", &name)); + // } + // if let Some(tex) = tex_opt { + // let name = wgc::gfx_select!(tex => global.texture_label(tex)); + // ret.push_str(&format_label_line("source", &name)); + // } + // } + Self::MissingCopyDstUsageFlag(buf_opt, tex_opt) => { + if let Some(buf) = buf_opt { + let name = wgc::gfx_select!(buf => global.buffer_label(buf)); + ret.push_str(&format_label_line("destination", &name)); + } + if let Some(tex) = tex_opt { + let name = wgc::gfx_select!(tex => global.texture_label(tex)); + ret.push_str(&format_label_line("destination", &name)); + } + } + _ => {} + }; + ret + } +} + +impl PrettyError for wgc::command::PassErrorScope { + fn fmt_pretty(&self, context: &super::Context) -> String { + // This error is not in the error chain, only notes are needed + let global = context.global(); + match *self { + Self::Pass(id) => { + let name = wgc::gfx_select!(id => global.command_buffer_label(id)); + format_label_line("command buffer", &name) + } + Self::SetBindGroup(id) => { + let name = wgc::gfx_select!(id => global.bind_group_label(id)); + format_label_line("bind group", &name) + } + Self::SetPipelineRender(id) => { + let name = wgc::gfx_select!(id => global.render_pipeline_label(id)); + format_label_line("render pipeline", &name) + } + Self::SetPipelineCompute(id) => { + let name = wgc::gfx_select!(id => global.compute_pipeline_label(id)); + format_label_line("compute pipeline", &name) + } + Self::SetVertexBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + format_label_line("buffer", &name) + } + Self::SetIndexBuffer(id) => { + let name = wgc::gfx_select!(id => global.buffer_label(id)); + format_label_line("buffer", &name) + } + Self::Draw { pipeline, .. } => { + if let Some(id) = pipeline { + let name = wgc::gfx_select!(id => global.render_pipeline_label(id)); + format_label_line("render pipeline", &name) + } else { + String::new() + } + } + Self::Dispatch { pipeline, .. } => { + if let Some(id) = pipeline { + let name = wgc::gfx_select!(id => global.compute_pipeline_label(id)); + format_label_line("compute pipeline", &name) + } else { + String::new() + } + } + _ => String::new(), + } + } +} diff --git a/wgpu/src/backend/mod.rs b/wgpu/src/backend/mod.rs new file mode 100644 index 000000000..90001e6ac --- /dev/null +++ b/wgpu/src/backend/mod.rs @@ -0,0 +1,15 @@ +#[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] +mod web; +#[cfg(all(target_arch = "wasm32", not(feature = "webgl")))] +pub(crate) use web::{BufferMappedRange, Context}; + +#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] +mod direct; +#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] +mod error; + +#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] +pub(crate) use direct::{BufferMappedRange, Context}; + +#[cfg(any(not(target_arch = "wasm32"), feature = "webgl"))] +mod native_gpu_future; diff --git a/wgpu/src/backend/native_gpu_future.rs b/wgpu/src/backend/native_gpu_future.rs new file mode 100644 index 000000000..a37b97538 --- /dev/null +++ b/wgpu/src/backend/native_gpu_future.rs @@ -0,0 +1,77 @@ +use parking_lot::Mutex; +use std::future::Future; +use std::pin::Pin; +use std::sync::Arc; +use std::task::{Context, Poll, Waker}; + +enum WakerOrResult { + Waker(Waker), + Result(T), +} + +type GpuFutureData = Mutex>>; + +/// A Future that can poll the wgpu::Device +pub struct GpuFuture { + data: Arc>, +} + +pub enum OpaqueData {} + +//TODO: merge this with `GpuFuture` and avoid `Arc` on the data. +/// A completion handle to set the result on a GpuFuture +pub struct GpuFutureCompletion { + data: Arc>, +} + +impl Future for GpuFuture { + type Output = T; + + fn poll(self: Pin<&mut Self>, context: &mut Context) -> Poll { + let mut waker_or_result = self.into_ref().get_ref().data.lock(); + + match waker_or_result.take() { + Some(WakerOrResult::Result(res)) => Poll::Ready(res), + _ => { + *waker_or_result = Some(WakerOrResult::Waker(context.waker().clone())); + Poll::Pending + } + } + } +} + +impl GpuFutureCompletion { + pub fn complete(self, value: T) { + let mut waker_or_result = self.data.lock(); + + match waker_or_result.replace(WakerOrResult::Result(value)) { + Some(WakerOrResult::Waker(waker)) => waker.wake(), + None => {} + Some(WakerOrResult::Result(_)) => { + // Drop before panicking. Not sure if this is necessary, but it makes me feel better. + drop(waker_or_result); + unreachable!() + } + }; + } + + pub(crate) fn into_raw(self) -> *mut OpaqueData { + Arc::into_raw(self.data) as _ + } + + pub(crate) unsafe fn from_raw(this: *mut OpaqueData) -> Self { + Self { + data: Arc::from_raw(this as _), + } + } +} + +pub(crate) fn new_gpu_future() -> (GpuFuture, GpuFutureCompletion) { + let data = Arc::new(Mutex::new(None)); + ( + GpuFuture { + data: Arc::clone(&data), + }, + GpuFutureCompletion { data }, + ) +} diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs new file mode 100644 index 000000000..ad5513e28 --- /dev/null +++ b/wgpu/src/backend/web.rs @@ -0,0 +1,2063 @@ +use std::{ + fmt, + future::Future, + ops::Range, + pin::Pin, + task::{self, Poll}, +}; +use wasm_bindgen::prelude::*; + +// We need to make a wrapper for some of the handle types returned by the web backend to make them +// implement `Send` and `Sync` to match native. +// +// SAFETY: All webgpu handle types in wasm32 are internally a `JsValue`, and `JsValue` is neither +// Send nor Sync. Currently, wasm32 has no threading support so implementing `Send` or `Sync` for a +// type is (for now) harmless. Eventually wasm32 will support threading, and depending on how this +// is integrated (or not integrated) with values like those in webgpu, this may become unsound. + +#[derive(Clone, Debug)] +pub(crate) struct Sendable(T); +unsafe impl Send for Sendable {} +unsafe impl Sync for Sendable {} + +pub(crate) struct Context(web_sys::Gpu); +unsafe impl Send for Context {} +unsafe impl Sync for Context {} + +impl fmt::Debug for Context { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Context").field("type", &"Web").finish() + } +} + +#[derive(Debug)] +pub(crate) struct ComputePass(web_sys::GpuComputePassEncoder); +#[derive(Debug)] +pub(crate) struct RenderPass(web_sys::GpuRenderPassEncoder); +#[derive(Debug)] +pub(crate) struct RenderBundleEncoder(web_sys::GpuRenderBundleEncoder); + +// We need to assert that any future we return is Send to match the native API. +// +// This is safe on wasm32 *for now*, but similarly to the unsafe Send impls for the handle type +// wrappers, the full story for threading on wasm32 is still unfolding. + +pub(crate) struct MakeSendFuture { + future: F, + map: M, +} + +impl T, T> Future for MakeSendFuture { + type Output = T; + + fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + // This is safe because we have no Drop implementation to violate the Pin requirements and + // do not provide any means of moving the inner future. + unsafe { + let this = self.get_unchecked_mut(); + match Pin::new_unchecked(&mut this.future).poll(cx) { + task::Poll::Ready(value) => task::Poll::Ready((this.map)(value)), + task::Poll::Pending => task::Poll::Pending, + } + } + } +} + +impl MakeSendFuture { + fn new(future: F, map: M) -> Self { + Self { future, map } + } +} + +unsafe impl Send for MakeSendFuture {} + +impl crate::ComputePassInner for ComputePass { + fn set_pipeline(&mut self, pipeline: &Sendable) { + self.0.set_pipeline(&pipeline.0); + } + fn set_bind_group( + &mut self, + index: u32, + bind_group: &Sendable, + offsets: &[wgt::DynamicOffset], + ) { + self.0 + .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length( + index, + &bind_group.0, + offsets, + 0f64, + offsets.len() as u32, + ); + } + + fn set_push_constants(&mut self, _offset: u32, _data: &[u8]) { + panic!("PUSH_CONSTANTS feature must be enabled to call multi_draw_indexed_indirect") + } + + fn insert_debug_marker(&mut self, _label: &str) { + // Not available in gecko yet + // self.0.insert_debug_marker(label); + } + + fn push_debug_group(&mut self, _group_label: &str) { + // Not available in gecko yet + // self.0.push_debug_group(group_label); + } + + fn pop_debug_group(&mut self) { + // Not available in gecko yet + // self.0.pop_debug_group(); + } + + fn dispatch(&mut self, x: u32, y: u32, z: u32) { + self.0.dispatch_with_y_and_z(x, y, z); + } + fn dispatch_indirect( + &mut self, + indirect_buffer: &Sendable, + indirect_offset: wgt::BufferAddress, + ) { + self.0 + .dispatch_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + } + + fn write_timestamp(&mut self, _query_set: &(), _query_index: u32) { + // Not available in gecko yet + } + + fn begin_pipeline_statistics_query(&mut self, _query_set: &(), _query_index: u32) { + // Not available in gecko yet + } + + fn end_pipeline_statistics_query(&mut self) { + // Not available in gecko yet + } +} + +impl crate::RenderInner for RenderPass { + fn set_pipeline(&mut self, pipeline: &Sendable) { + self.0.set_pipeline(&pipeline.0); + } + fn set_bind_group( + &mut self, + index: u32, + bind_group: &Sendable, + offsets: &[wgt::DynamicOffset], + ) { + self.0 + .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length( + index, + &bind_group.0, + offsets, + 0f64, + offsets.len() as u32, + ); + } + fn set_index_buffer( + &mut self, + buffer: &Sendable, + index_format: wgt::IndexFormat, + offset: wgt::BufferAddress, + size: Option, + ) { + let mapped_size = match size { + Some(s) => s.get() as f64, + None => 0f64, + }; + self.0.set_index_buffer_with_f64_and_f64( + &buffer.0, + map_index_format(index_format), + offset as f64, + mapped_size, + ); + } + fn set_vertex_buffer( + &mut self, + slot: u32, + buffer: &Sendable, + offset: wgt::BufferAddress, + size: Option, + ) { + let mapped_size = match size { + Some(s) => s.get() as f64, + None => 0f64, + }; + self.0 + .set_vertex_buffer_with_f64_and_f64(slot, &buffer.0, offset as f64, mapped_size); + } + fn set_push_constants(&mut self, _stages: wgt::ShaderStage, _offset: u32, _data: &[u8]) { + panic!("PUSH_CONSTANTS feature must be enabled to call multi_draw_indexed_indirect") + } + fn draw(&mut self, vertices: Range, instances: Range) { + self.0 + .draw_with_instance_count_and_first_vertex_and_first_instance( + vertices.end - vertices.start, + instances.end - instances.start, + vertices.start, + instances.start, + ); + } + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + self.0 + .draw_indexed_with_instance_count_and_first_index_and_base_vertex_and_first_instance( + indices.end - indices.start, + instances.end - instances.start, + indices.start, + base_vertex, + instances.start, + ); + } + fn draw_indirect( + &mut self, + indirect_buffer: &Sendable, + indirect_offset: wgt::BufferAddress, + ) { + self.0 + .draw_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + } + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &Sendable, + indirect_offset: wgt::BufferAddress, + ) { + self.0 + .draw_indexed_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + } + fn multi_draw_indirect( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count: u32, + ) { + panic!("MULTI_DRAW_INDIRECT feature must be enabled to call multi_draw_indirect") + } + fn multi_draw_indexed_indirect( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count: u32, + ) { + panic!("MULTI_DRAW_INDIRECT feature must be enabled to call multi_draw_indexed_indirect") + } + fn multi_draw_indirect_count( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count_buffer: &Sendable, + _count_buffer_offset: wgt::BufferAddress, + _max_count: u32, + ) { + panic!( + "MULTI_DRAW_INDIRECT_COUNT feature must be enabled to call multi_draw_indirect_count" + ) + } + fn multi_draw_indexed_indirect_count( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count_buffer: &Sendable, + _count_buffer_offset: wgt::BufferAddress, + _max_count: u32, + ) { + panic!("MULTI_DRAW_INDIRECT_COUNT feature must be enabled to call multi_draw_indexed_indirect_count") + } +} + +impl crate::RenderInner for RenderBundleEncoder { + fn set_pipeline(&mut self, pipeline: &Sendable) { + self.0.set_pipeline(&pipeline.0); + } + fn set_bind_group( + &mut self, + index: u32, + bind_group: &Sendable, + offsets: &[wgt::DynamicOffset], + ) { + self.0 + .set_bind_group_with_u32_array_and_f64_and_dynamic_offsets_data_length( + index, + &bind_group.0, + offsets, + 0f64, + offsets.len() as u32, + ); + } + fn set_index_buffer( + &mut self, + buffer: &Sendable, + index_format: wgt::IndexFormat, + offset: wgt::BufferAddress, + size: Option, + ) { + let mapped_size = match size { + Some(s) => s.get() as f64, + None => 0f64, + }; + self.0.set_index_buffer_with_f64_and_f64( + &buffer.0, + map_index_format(index_format), + offset as f64, + mapped_size, + ); + } + fn set_vertex_buffer( + &mut self, + slot: u32, + buffer: &Sendable, + offset: wgt::BufferAddress, + size: Option, + ) { + let mapped_size = match size { + Some(s) => s.get() as f64, + None => 0f64, + }; + self.0 + .set_vertex_buffer_with_f64_and_f64(slot, &buffer.0, offset as f64, mapped_size); + } + fn set_push_constants(&mut self, _stages: wgt::ShaderStage, _offset: u32, _data: &[u8]) { + panic!("PUSH_CONSTANTS feature must be enabled to call multi_draw_indexed_indirect") + } + fn draw(&mut self, vertices: Range, instances: Range) { + self.0 + .draw_with_instance_count_and_first_vertex_and_first_instance( + vertices.end - vertices.start, + instances.end - instances.start, + vertices.start, + instances.start, + ); + } + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + self.0 + .draw_indexed_with_instance_count_and_first_index_and_base_vertex_and_first_instance( + indices.end - indices.start, + instances.end - instances.start, + indices.start, + base_vertex, + instances.start, + ); + } + fn draw_indirect( + &mut self, + indirect_buffer: &Sendable, + indirect_offset: wgt::BufferAddress, + ) { + self.0 + .draw_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + } + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &Sendable, + indirect_offset: wgt::BufferAddress, + ) { + self.0 + .draw_indexed_indirect_with_f64(&indirect_buffer.0, indirect_offset as f64); + } + fn multi_draw_indirect( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count: u32, + ) { + panic!("MULTI_DRAW_INDIRECT feature must be enabled to call multi_draw_indirect") + } + fn multi_draw_indexed_indirect( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count: u32, + ) { + panic!("MULTI_DRAW_INDIRECT feature must be enabled to call multi_draw_indexed_indirect") + } + fn multi_draw_indirect_count( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count_buffer: &Sendable, + _count_buffer_offset: wgt::BufferAddress, + _max_count: u32, + ) { + panic!( + "MULTI_DRAW_INDIRECT_COUNT feature must be enabled to call multi_draw_indirect_count" + ) + } + fn multi_draw_indexed_indirect_count( + &mut self, + _indirect_buffer: &Sendable, + _indirect_offset: wgt::BufferAddress, + _count_buffer: &Sendable, + _count_buffer_offset: wgt::BufferAddress, + _max_count: u32, + ) { + panic!("MULTI_DRAW_INDIRECT_COUNT feature must be enabled to call multi_draw_indexed_indirect_count") + } +} + +impl crate::RenderPassInner for RenderPass { + fn set_blend_constant(&mut self, color: wgt::Color) { + self.0 + .set_blend_color_with_gpu_color_dict(&map_color(color)); + } + fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) { + self.0.set_scissor_rect(x, y, width, height); + } + fn set_viewport( + &mut self, + x: f32, + y: f32, + width: f32, + height: f32, + min_depth: f32, + max_depth: f32, + ) { + self.0 + .set_viewport(x, y, width, height, min_depth, max_depth); + } + fn set_stencil_reference(&mut self, reference: u32) { + self.0.set_stencil_reference(reference); + } + + fn insert_debug_marker(&mut self, _label: &str) { + // Not available in gecko yet + // self.0.insert_debug_marker(label); + } + + fn push_debug_group(&mut self, _group_label: &str) { + // Not available in gecko yet + // self.0.push_debug_group(group_label); + } + + fn pop_debug_group(&mut self) { + // Not available in gecko yet + // self.0.pop_debug_group(); + } + + fn execute_bundles<'a, I: Iterator>>( + &mut self, + render_bundles: I, + ) { + let mapped = render_bundles + .map(|bundle| &bundle.0) + .collect::(); + self.0.execute_bundles(&mapped); + } + + fn write_timestamp(&mut self, _query_set: &(), _query_index: u32) { + // Not available in gecko yet + } + + fn begin_pipeline_statistics_query(&mut self, _query_set: &(), _query_index: u32) { + // Not available in gecko yet + } + + fn end_pipeline_statistics_query(&mut self) { + // Not available in gecko yet + } +} + +fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTextureFormat { + use web_sys::GpuTextureFormat as tf; + use wgt::TextureFormat; + match texture_format { + TextureFormat::R8Unorm => tf::R8unorm, + TextureFormat::R8Snorm => tf::R8snorm, + TextureFormat::R8Uint => tf::R8uint, + TextureFormat::R8Sint => tf::R8sint, + TextureFormat::R16Uint => tf::R16uint, + TextureFormat::R16Sint => tf::R16sint, + TextureFormat::R16Float => tf::R16float, + TextureFormat::Rg8Unorm => tf::Rg8unorm, + TextureFormat::Rg8Snorm => tf::Rg8snorm, + TextureFormat::Rg8Uint => tf::Rg8uint, + TextureFormat::Rg8Sint => tf::Rg8sint, + TextureFormat::R32Uint => tf::R32uint, + TextureFormat::R32Sint => tf::R32sint, + TextureFormat::R32Float => tf::R32float, + TextureFormat::Rg16Uint => tf::Rg16uint, + TextureFormat::Rg16Sint => tf::Rg16sint, + TextureFormat::Rg16Float => tf::Rg16float, + TextureFormat::Rgba8Unorm => tf::Rgba8unorm, + TextureFormat::Rgba8UnormSrgb => tf::Rgba8unormSrgb, + TextureFormat::Rgba8Snorm => tf::Rgba8snorm, + TextureFormat::Rgba8Uint => tf::Rgba8uint, + TextureFormat::Rgba8Sint => tf::Rgba8sint, + TextureFormat::Bgra8Unorm => tf::Bgra8unorm, + TextureFormat::Bgra8UnormSrgb => tf::Bgra8unormSrgb, + TextureFormat::Rgb10a2Unorm => tf::Rgb10a2unorm, + TextureFormat::Rg11b10Float => tf::Rg11b10ufloat, + TextureFormat::Rg32Uint => tf::Rg32uint, + TextureFormat::Rg32Sint => tf::Rg32sint, + TextureFormat::Rg32Float => tf::Rg32float, + TextureFormat::Rgba16Uint => tf::Rgba16uint, + TextureFormat::Rgba16Sint => tf::Rgba16sint, + TextureFormat::Rgba16Float => tf::Rgba16float, + TextureFormat::Rgba32Uint => tf::Rgba32uint, + TextureFormat::Rgba32Sint => tf::Rgba32sint, + TextureFormat::Rgba32Float => tf::Rgba32float, + TextureFormat::Depth32Float => tf::Depth32float, + TextureFormat::Depth24Plus => tf::Depth24plus, + TextureFormat::Depth24PlusStencil8 => tf::Depth24plusStencil8, + _ => unimplemented!(), + } +} + +fn map_texture_format_from_web_sys( + texture_format: web_sys::GpuTextureFormat, +) -> wgt::TextureFormat { + use web_sys::GpuTextureFormat as tf; + use wgt::TextureFormat; + match texture_format { + tf::R8unorm => TextureFormat::R8Unorm, + tf::R8snorm => TextureFormat::R8Snorm, + tf::R8uint => TextureFormat::R8Uint, + tf::R8sint => TextureFormat::R8Sint, + tf::R16uint => TextureFormat::R16Uint, + tf::R16sint => TextureFormat::R16Sint, + tf::R16float => TextureFormat::R16Float, + tf::Rg8unorm => TextureFormat::Rg8Unorm, + tf::Rg8snorm => TextureFormat::Rg8Snorm, + tf::Rg8uint => TextureFormat::Rg8Uint, + tf::Rg8sint => TextureFormat::Rg8Sint, + tf::R32uint => TextureFormat::R32Uint, + tf::R32sint => TextureFormat::R32Sint, + tf::R32float => TextureFormat::R32Float, + tf::Rg16uint => TextureFormat::Rg16Uint, + tf::Rg16sint => TextureFormat::Rg16Sint, + tf::Rg16float => TextureFormat::Rg16Float, + tf::Rgba8unorm => TextureFormat::Rgba8Unorm, + tf::Rgba8unormSrgb => TextureFormat::Rgba8UnormSrgb, + tf::Rgba8snorm => TextureFormat::Rgba8Snorm, + tf::Rgba8uint => TextureFormat::Rgba8Uint, + tf::Rgba8sint => TextureFormat::Rgba8Sint, + tf::Bgra8unorm => TextureFormat::Bgra8Unorm, + tf::Bgra8unormSrgb => TextureFormat::Bgra8UnormSrgb, + tf::Rgb10a2unorm => TextureFormat::Rgb10a2Unorm, + tf::Rg11b10ufloat => TextureFormat::Rg11b10Float, + tf::Rg32uint => TextureFormat::Rg32Uint, + tf::Rg32sint => TextureFormat::Rg32Sint, + tf::Rg32float => TextureFormat::Rg32Float, + tf::Rgba16uint => TextureFormat::Rgba16Uint, + tf::Rgba16sint => TextureFormat::Rgba16Sint, + tf::Rgba16float => TextureFormat::Rgba16Float, + tf::Rgba32uint => TextureFormat::Rgba32Uint, + tf::Rgba32sint => TextureFormat::Rgba32Sint, + tf::Rgba32float => TextureFormat::Rgba32Float, + tf::Depth32float => TextureFormat::Depth32Float, + tf::Depth24plus => TextureFormat::Depth24Plus, + tf::Depth24plusStencil8 => TextureFormat::Depth24PlusStencil8, + _ => unimplemented!(), + } +} + +fn map_texture_component_type( + sample_type: wgt::TextureSampleType, +) -> web_sys::GpuTextureSampleType { + use web_sys::GpuTextureSampleType as ts; + use wgt::TextureSampleType; + match sample_type { + TextureSampleType::Float { filterable: true } => ts::Float, + TextureSampleType::Float { filterable: false } => ts::UnfilterableFloat, + TextureSampleType::Sint => ts::Sint, + TextureSampleType::Uint => ts::Uint, + TextureSampleType::Depth => ts::Depth, + } +} + +fn map_cull_mode(cull_mode: Option) -> web_sys::GpuCullMode { + use web_sys::GpuCullMode as cm; + use wgt::Face; + match cull_mode { + None => cm::None, + Some(Face::Front) => cm::Front, + Some(Face::Back) => cm::Back, + } +} + +fn map_front_face(front_face: wgt::FrontFace) -> web_sys::GpuFrontFace { + use web_sys::GpuFrontFace as ff; + use wgt::FrontFace; + match front_face { + FrontFace::Ccw => ff::Ccw, + FrontFace::Cw => ff::Cw, + } +} + +fn map_primitive_state(primitive: &wgt::PrimitiveState) -> web_sys::GpuPrimitiveState { + use web_sys::GpuPrimitiveTopology as pt; + use wgt::PrimitiveTopology; + + let mut mapped = web_sys::GpuPrimitiveState::new(); + mapped.cull_mode(map_cull_mode(primitive.cull_mode)); + mapped.front_face(map_front_face(primitive.front_face)); + + if let Some(format) = primitive.strip_index_format { + mapped.strip_index_format(map_index_format(format)); + } + + mapped.topology(match primitive.topology { + PrimitiveTopology::PointList => pt::PointList, + PrimitiveTopology::LineList => pt::LineList, + PrimitiveTopology::LineStrip => pt::LineStrip, + PrimitiveTopology::TriangleList => pt::TriangleList, + PrimitiveTopology::TriangleStrip => pt::TriangleStrip, + }); + + //mapped.clamp_depth(primitive.clamp_depth); + + mapped +} + +fn map_compare_function(compare_fn: wgt::CompareFunction) -> web_sys::GpuCompareFunction { + use web_sys::GpuCompareFunction as cf; + use wgt::CompareFunction; + match compare_fn { + CompareFunction::Never => cf::Never, + CompareFunction::Less => cf::Less, + CompareFunction::Equal => cf::Equal, + CompareFunction::LessEqual => cf::LessEqual, + CompareFunction::Greater => cf::Greater, + CompareFunction::NotEqual => cf::NotEqual, + CompareFunction::GreaterEqual => cf::GreaterEqual, + CompareFunction::Always => cf::Always, + } +} + +fn map_stencil_operation(op: wgt::StencilOperation) -> web_sys::GpuStencilOperation { + use web_sys::GpuStencilOperation as so; + use wgt::StencilOperation; + match op { + StencilOperation::Keep => so::Keep, + StencilOperation::Zero => so::Zero, + StencilOperation::Replace => so::Replace, + StencilOperation::Invert => so::Invert, + StencilOperation::IncrementClamp => so::IncrementClamp, + StencilOperation::DecrementClamp => so::DecrementClamp, + StencilOperation::IncrementWrap => so::IncrementWrap, + StencilOperation::DecrementWrap => so::DecrementWrap, + } +} + +fn map_stencil_state_face(desc: &wgt::StencilFaceState) -> web_sys::GpuStencilFaceState { + let mut mapped = web_sys::GpuStencilFaceState::new(); + mapped.compare(map_compare_function(desc.compare)); + mapped.depth_fail_op(map_stencil_operation(desc.depth_fail_op)); + mapped.fail_op(map_stencil_operation(desc.fail_op)); + mapped.pass_op(map_stencil_operation(desc.pass_op)); + mapped +} + +fn map_depth_stencil_state(desc: &wgt::DepthStencilState) -> web_sys::GpuDepthStencilState { + let mut mapped = web_sys::GpuDepthStencilState::new(map_texture_format(desc.format)); + mapped.depth_bias(desc.bias.constant); + mapped.depth_bias_clamp(desc.bias.clamp); + mapped.depth_bias_slope_scale(desc.bias.slope_scale); + mapped.depth_compare(map_compare_function(desc.depth_compare)); + mapped.depth_write_enabled(desc.depth_write_enabled); + mapped.stencil_back(&map_stencil_state_face(&desc.stencil.back)); + mapped.stencil_front(&map_stencil_state_face(&desc.stencil.front)); + mapped.stencil_read_mask(desc.stencil.read_mask); + mapped.stencil_write_mask(desc.stencil.write_mask); + mapped +} + +fn map_blend_component(desc: &wgt::BlendComponent) -> web_sys::GpuBlendComponent { + let mut mapped = web_sys::GpuBlendComponent::new(); + mapped.dst_factor(map_blend_factor(desc.dst_factor)); + mapped.operation(map_blend_operation(desc.operation)); + mapped.src_factor(map_blend_factor(desc.src_factor)); + mapped +} + +fn map_blend_factor(factor: wgt::BlendFactor) -> web_sys::GpuBlendFactor { + use web_sys::GpuBlendFactor as bf; + use wgt::BlendFactor; + match factor { + BlendFactor::Zero => bf::Zero, + BlendFactor::One => bf::One, + BlendFactor::Src => bf::SrcColor, + BlendFactor::OneMinusSrc => bf::OneMinusSrcColor, + BlendFactor::SrcAlpha => bf::SrcAlpha, + BlendFactor::OneMinusSrcAlpha => bf::OneMinusSrcAlpha, + BlendFactor::Dst => bf::DstColor, + BlendFactor::OneMinusDst => bf::OneMinusDstColor, + BlendFactor::DstAlpha => bf::DstAlpha, + BlendFactor::OneMinusDstAlpha => bf::OneMinusDstAlpha, + BlendFactor::SrcAlphaSaturated => bf::SrcAlphaSaturated, + BlendFactor::Constant => bf::BlendColor, + BlendFactor::OneMinusConstant => bf::OneMinusBlendColor, + } +} + +fn map_blend_operation(op: wgt::BlendOperation) -> web_sys::GpuBlendOperation { + use web_sys::GpuBlendOperation as bo; + use wgt::BlendOperation; + match op { + BlendOperation::Add => bo::Add, + BlendOperation::Subtract => bo::Subtract, + BlendOperation::ReverseSubtract => bo::ReverseSubtract, + BlendOperation::Min => bo::Min, + BlendOperation::Max => bo::Max, + } +} + +fn map_index_format(format: wgt::IndexFormat) -> web_sys::GpuIndexFormat { + use web_sys::GpuIndexFormat as f; + use wgt::IndexFormat; + match format { + IndexFormat::Uint16 => f::Uint16, + IndexFormat::Uint32 => f::Uint32, + } +} + +fn map_vertex_format(format: wgt::VertexFormat) -> web_sys::GpuVertexFormat { + use web_sys::GpuVertexFormat as vf; + use wgt::VertexFormat; + match format { + VertexFormat::Uint8x2 => vf::Uint8x2, + VertexFormat::Uint8x4 => vf::Uint8x4, + VertexFormat::Sint8x2 => vf::Sint8x2, + VertexFormat::Sint8x4 => vf::Sint8x4, + VertexFormat::Unorm8x2 => vf::Unorm8x2, + VertexFormat::Unorm8x4 => vf::Unorm8x4, + VertexFormat::Snorm8x2 => vf::Snorm8x2, + VertexFormat::Snorm8x4 => vf::Snorm8x4, + VertexFormat::Uint16x2 => vf::Uint16x2, + VertexFormat::Uint16x4 => vf::Uint16x4, + VertexFormat::Sint16x2 => vf::Sint16x2, + VertexFormat::Sint16x4 => vf::Sint16x4, + VertexFormat::Unorm16x2 => vf::Unorm16x2, + VertexFormat::Unorm16x4 => vf::Unorm16x4, + VertexFormat::Snorm16x2 => vf::Snorm16x2, + VertexFormat::Snorm16x4 => vf::Snorm16x4, + VertexFormat::Float16x2 => vf::Float16x2, + VertexFormat::Float16x4 => vf::Float16x4, + VertexFormat::Float32 => vf::Float32, + VertexFormat::Float32x2 => vf::Float32x2, + VertexFormat::Float32x3 => vf::Float32x3, + VertexFormat::Float32x4 => vf::Float32x4, + VertexFormat::Uint32 => vf::Uint32, + VertexFormat::Uint32x2 => vf::Uint32x2, + VertexFormat::Uint32x3 => vf::Uint32x3, + VertexFormat::Uint32x4 => vf::Uint32x4, + VertexFormat::Sint32 => vf::Sint32, + VertexFormat::Sint32x2 => vf::Sint32x2, + VertexFormat::Sint32x3 => vf::Sint32x3, + VertexFormat::Sint32x4 => vf::Sint32x4, + VertexFormat::Float64 + | VertexFormat::Float64x2 + | VertexFormat::Float64x3 + | VertexFormat::Float64x4 => { + panic!("VERTEX_ATTRIBUTE_64BIT feature must be enabled to use Double formats") + } + } +} + +fn map_input_step_mode(mode: wgt::InputStepMode) -> web_sys::GpuInputStepMode { + use web_sys::GpuInputStepMode as sm; + use wgt::InputStepMode; + match mode { + InputStepMode::Vertex => sm::Vertex, + InputStepMode::Instance => sm::Instance, + } +} + +fn map_extent_3d(extent: wgt::Extent3d) -> web_sys::GpuExtent3dDict { + let mut mapped = web_sys::GpuExtent3dDict::new(extent.width); + mapped.height(extent.height); + mapped.depth_or_array_layers(extent.depth_or_array_layers); + mapped +} + +fn map_origin_3d(origin: wgt::Origin3d) -> web_sys::GpuOrigin3dDict { + let mut mapped = web_sys::GpuOrigin3dDict::new(); + mapped.x(origin.x); + mapped.y(origin.y); + mapped.z(origin.z); + mapped +} + +fn map_texture_dimension(texture_dimension: wgt::TextureDimension) -> web_sys::GpuTextureDimension { + match texture_dimension { + wgt::TextureDimension::D1 => web_sys::GpuTextureDimension::N1d, + wgt::TextureDimension::D2 => web_sys::GpuTextureDimension::N2d, + wgt::TextureDimension::D3 => web_sys::GpuTextureDimension::N3d, + } +} + +fn map_texture_view_dimension( + texture_view_dimension: wgt::TextureViewDimension, +) -> web_sys::GpuTextureViewDimension { + use web_sys::GpuTextureViewDimension as tvd; + match texture_view_dimension { + wgt::TextureViewDimension::D1 => tvd::N1d, + wgt::TextureViewDimension::D2 => tvd::N2d, + wgt::TextureViewDimension::D2Array => tvd::N2dArray, + wgt::TextureViewDimension::Cube => tvd::Cube, + wgt::TextureViewDimension::CubeArray => tvd::CubeArray, + wgt::TextureViewDimension::D3 => tvd::N3d, + } +} + +fn map_buffer_copy_view(view: crate::ImageCopyBuffer) -> web_sys::GpuImageCopyBuffer { + let mut mapped = web_sys::GpuImageCopyBuffer::new(&view.buffer.id.0); + if let Some(bytes_per_row) = view.layout.bytes_per_row { + mapped.bytes_per_row(bytes_per_row.get()); + } + if let Some(rows_per_image) = view.layout.rows_per_image { + mapped.rows_per_image(rows_per_image.get()); + } + mapped.offset(view.layout.offset as f64); + mapped +} + +fn map_texture_copy_view(view: crate::ImageCopyTexture) -> web_sys::GpuImageCopyTexture { + let mut mapped = web_sys::GpuImageCopyTexture::new(&view.texture.id.0); + mapped.mip_level(view.mip_level); + mapped.origin(&map_origin_3d(view.origin)); + mapped +} + +fn map_texture_aspect(aspect: wgt::TextureAspect) -> web_sys::GpuTextureAspect { + match aspect { + wgt::TextureAspect::All => web_sys::GpuTextureAspect::All, + wgt::TextureAspect::StencilOnly => web_sys::GpuTextureAspect::StencilOnly, + wgt::TextureAspect::DepthOnly => web_sys::GpuTextureAspect::DepthOnly, + } +} + +fn map_filter_mode(mode: wgt::FilterMode) -> web_sys::GpuFilterMode { + match mode { + wgt::FilterMode::Nearest => web_sys::GpuFilterMode::Nearest, + wgt::FilterMode::Linear => web_sys::GpuFilterMode::Linear, + } +} + +fn map_address_mode(mode: wgt::AddressMode) -> web_sys::GpuAddressMode { + match mode { + wgt::AddressMode::ClampToEdge => web_sys::GpuAddressMode::ClampToEdge, + wgt::AddressMode::Repeat => web_sys::GpuAddressMode::Repeat, + wgt::AddressMode::MirrorRepeat => web_sys::GpuAddressMode::MirrorRepeat, + wgt::AddressMode::ClampToBorder => panic!("Clamp to border is not supported"), + } +} + +fn map_color(color: wgt::Color) -> web_sys::GpuColorDict { + web_sys::GpuColorDict::new(color.a, color.b, color.g, color.r) +} + +fn map_store_op(store: bool) -> web_sys::GpuStoreOp { + if store { + web_sys::GpuStoreOp::Store + } else { + web_sys::GpuStoreOp::Clear + } +} + +fn map_map_mode(mode: crate::MapMode) -> u32 { + match mode { + crate::MapMode::Read => web_sys::GpuMapMode::READ, + crate::MapMode::Write => web_sys::GpuMapMode::WRITE, + } +} + +type JsFutureResult = Result; + +fn future_request_adapter(result: JsFutureResult) -> Option> { + match result { + Ok(js_value) => Some(Sendable(web_sys::GpuAdapter::from(js_value))), + Err(_) => None, + } +} +fn future_request_device( + result: JsFutureResult, +) -> Result<(Sendable, Sendable), crate::RequestDeviceError> +{ + result + .map(|js_value| { + let device_id = web_sys::GpuDevice::from(js_value); + let queue_id = device_id.queue(); + (Sendable(device_id), Sendable(queue_id)) + }) + .map_err(|_| crate::RequestDeviceError) +} + +fn future_map_async(result: JsFutureResult) -> Result<(), crate::BufferAsyncError> { + result.map(|_| ()).map_err(|_| crate::BufferAsyncError) +} + +impl crate::Context for Context { + type AdapterId = Sendable; + type DeviceId = Sendable; + type QueueId = Sendable; + type ShaderModuleId = Sendable; + type BindGroupLayoutId = Sendable; + type BindGroupId = Sendable; + type TextureViewId = Sendable; + type SamplerId = Sendable; + type BufferId = Sendable; + type TextureId = Sendable; + type QuerySetId = (); //TODO! + type PipelineLayoutId = Sendable; + type RenderPipelineId = Sendable; + type ComputePipelineId = Sendable; + type CommandEncoderId = web_sys::GpuCommandEncoder; + type ComputePassId = ComputePass; + type RenderPassId = RenderPass; + type CommandBufferId = Sendable; + type RenderBundleEncoderId = RenderBundleEncoder; + type RenderBundleId = Sendable; + type SurfaceId = Sendable; + type SwapChainId = Sendable; + + type SwapChainOutputDetail = SwapChainOutputDetail; + + type RequestAdapterFuture = MakeSendFuture< + wasm_bindgen_futures::JsFuture, + fn(JsFutureResult) -> Option, + >; + type RequestDeviceFuture = MakeSendFuture< + wasm_bindgen_futures::JsFuture, + fn(JsFutureResult) -> Result<(Self::DeviceId, Self::QueueId), crate::RequestDeviceError>, + >; + type MapAsyncFuture = MakeSendFuture< + wasm_bindgen_futures::JsFuture, + fn(JsFutureResult) -> Result<(), crate::BufferAsyncError>, + >; + + fn init(_backends: wgt::BackendBit) -> Self { + Context(web_sys::window().unwrap().navigator().gpu()) + } + + fn instance_create_surface( + &self, + handle: &impl raw_window_handle::HasRawWindowHandle, + ) -> Self::SurfaceId { + let canvas_attribute = match handle.raw_window_handle() { + raw_window_handle::RawWindowHandle::Web(web_handle) => web_handle.id, + _ => panic!("expected valid handle for canvas"), + }; + let canvas_node: wasm_bindgen::JsValue = web_sys::window() + .and_then(|win| win.document()) + .and_then(|doc| { + doc.query_selector_all(&format!("[data-raw-handle=\"{}\"]", canvas_attribute)) + .ok() + }) + .and_then(|nodes| nodes.get(0)) + .expect("expected to find single canvas") + .into(); + let canvas_element: web_sys::HtmlCanvasElement = canvas_node.into(); + let context: wasm_bindgen::JsValue = match canvas_element.get_context("gpupresent") { + Ok(Some(ctx)) => ctx.into(), + _ => panic!("expected to get context from canvas"), + }; + Sendable(context.into()) + } + + fn instance_request_adapter( + &self, + options: &crate::RequestAdapterOptions<'_>, + ) -> Self::RequestAdapterFuture { + //TODO: support this check, return `None` if the flag is not set. + // It's not trivial, since we need the Future logic to have this check, + // and currently the Future here has no room for extra parameter `backends`. + //assert!(backends.contains(wgt::BackendBit::BROWSER_WEBGPU)); + let mut mapped_options = web_sys::GpuRequestAdapterOptions::new(); + let mapped_power_preference = match options.power_preference { + wgt::PowerPreference::LowPower => web_sys::GpuPowerPreference::LowPower, + wgt::PowerPreference::HighPerformance => web_sys::GpuPowerPreference::HighPerformance, + }; + mapped_options.power_preference(mapped_power_preference); + let adapter_promise = self.0.request_adapter_with_options(&mapped_options); + + MakeSendFuture::new( + wasm_bindgen_futures::JsFuture::from(adapter_promise), + future_request_adapter, + ) + } + + fn instance_poll_all_devices(&self, _force_wait: bool) { + // Devices are automatically polled. + } + + fn adapter_request_device( + &self, + adapter: &Self::AdapterId, + desc: &crate::DeviceDescriptor, + trace_dir: Option<&std::path::Path>, + ) -> Self::RequestDeviceFuture { + use web_sys::GpuFeatureName as Gfn; + + if trace_dir.is_some() { + //Error: Tracing isn't supported on the Web target + } + assert!( + !desc.features.intersects(crate::Features::ALL_NATIVE), + "The web backend doesn't support any native extensions. Enabled native extensions: {:?}", + desc.features & crate::Features::ALL_NATIVE + ); + + // TODO: non-guaranteed limits + let mut mapped_desc = web_sys::GpuDeviceDescriptor::new(); + + let possible_features = [ + (wgt::Features::DEPTH_CLAMPING, Gfn::DepthClamping), + // TODO (_, Gfn::Depth24unormStencil8), + // TODO (_, Gfn::Depth32floatStencil8), + ( + wgt::Features::PIPELINE_STATISTICS_QUERY, + Gfn::PipelineStatisticsQuery, + ), + ( + wgt::Features::TEXTURE_COMPRESSION_BC, + Gfn::TextureCompressionBc, + ), + (wgt::Features::TIMESTAMP_QUERY, Gfn::TimestampQuery), + ]; + let non_guaranteed_features = possible_features + .iter() + .copied() + .flat_map(|(flag, value)| { + if desc.features.contains(flag) { + Some(JsValue::from(value)) + } else { + None + } + }) + .collect::(); + mapped_desc.non_guaranteed_features(&non_guaranteed_features); + + if let Some(label) = desc.label { + mapped_desc.label(label); + } + + let device_promise = adapter.0.request_device_with_descriptor(&mapped_desc); + + MakeSendFuture::new( + wasm_bindgen_futures::JsFuture::from(device_promise), + future_request_device, + ) + } + + fn adapter_get_swap_chain_preferred_format( + &self, + adapter: &Self::AdapterId, + surface: &Self::SurfaceId, + ) -> Option { + let format = + map_texture_format_from_web_sys(surface.0.get_swap_chain_preferred_format(&adapter.0)); + Some(format) + } + + fn adapter_features(&self, adapter: &Self::AdapterId) -> wgt::Features { + // TODO + let _features = adapter.0.features(); + wgt::Features::empty() + } + + fn adapter_limits(&self, adapter: &Self::AdapterId) -> wgt::Limits { + let limits = adapter.0.limits(); + wgt::Limits { + max_texture_dimension_1d: limits.max_texture_dimension_1d(), + max_texture_dimension_2d: limits.max_texture_dimension_2d(), + max_texture_dimension_3d: limits.max_texture_dimension_3d(), + max_texture_array_layers: limits.max_texture_array_layers(), + max_bind_groups: limits.max_bind_groups(), + max_dynamic_uniform_buffers_per_pipeline_layout: limits + .max_dynamic_uniform_buffers_per_pipeline_layout(), + max_dynamic_storage_buffers_per_pipeline_layout: limits + .max_dynamic_storage_buffers_per_pipeline_layout(), + max_sampled_textures_per_shader_stage: limits.max_sampled_textures_per_shader_stage(), + max_samplers_per_shader_stage: limits.max_samplers_per_shader_stage(), + max_storage_buffers_per_shader_stage: limits.max_storage_buffers_per_shader_stage(), + max_storage_textures_per_shader_stage: limits.max_storage_textures_per_shader_stage(), + max_uniform_buffers_per_shader_stage: limits.max_uniform_buffers_per_shader_stage(), + max_uniform_buffer_binding_size: limits.max_uniform_buffer_binding_size(), + max_storage_buffer_binding_size: limits.max_storage_buffer_binding_size(), + max_vertex_buffers: limits.max_vertex_buffers(), + max_vertex_attributes: limits.max_vertex_attributes(), + max_vertex_buffer_array_stride: limits.max_vertex_buffer_array_stride(), + ..wgt::Limits::default() + } + } + + fn adapter_downlevel_properties(&self, _adapter: &Self::AdapterId) -> wgt::DownlevelProperties { + // WebGPU is assumed to be fully compliant + wgt::DownlevelProperties::default() + } + + fn adapter_get_info(&self, _adapter: &Self::AdapterId) -> wgt::AdapterInfo { + // TODO: web-sys has no way of getting information on adapters + wgt::AdapterInfo { + name: String::new(), + vendor: 0, + device: 0, + device_type: wgt::DeviceType::Other, + backend: wgt::Backend::BrowserWebGpu, + } + } + + fn adapter_get_texture_format_features( + &self, + _adapter: &Self::AdapterId, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures { + format.describe().guaranteed_format_features + } + + fn device_features(&self, _device: &Self::DeviceId) -> wgt::Features { + // TODO + wgt::Features::empty() + } + + fn device_limits(&self, _device: &Self::DeviceId) -> wgt::Limits { + // TODO + wgt::Limits::default() + } + + fn device_downlevel_properties(&self, _device: &Self::DeviceId) -> wgt::DownlevelProperties { + // WebGPU is assumed to be fully compliant + wgt::DownlevelProperties::default() + } + + fn device_create_swap_chain( + &self, + device: &Self::DeviceId, + surface: &Self::SurfaceId, + desc: &wgt::SwapChainDescriptor, + ) -> Self::SwapChainId { + let mut mapped = + web_sys::GpuSwapChainDescriptor::new(&device.0, map_texture_format(desc.format)); + mapped.usage(desc.usage.bits()); + Sendable(surface.0.configure_swap_chain(&mapped)) + } + + fn device_create_shader_module( + &self, + device: &Self::DeviceId, + desc: &crate::ShaderModuleDescriptor, + ) -> Self::ShaderModuleId { + let mut descriptor = match desc.source { + crate::ShaderSource::SpirV(ref spv) => { + web_sys::GpuShaderModuleDescriptor::new(&js_sys::Uint32Array::from(&**spv)) + } + crate::ShaderSource::Wgsl(ref code) => { + use naga::{back::spv, front::wgsl, valid::Validator}; + let module = wgsl::parse_str(code).unwrap(); + let options = spv::Options { + lang_version: (1, 0), + flags: spv::WriterFlags::empty(), + capabilities: None, + }; + let analysis = Validator::new( + naga::valid::ValidationFlags::empty(), + naga::valid::Capabilities::all(), + ) + .validate(&module) + .unwrap(); + let words = spv::write_vec(&module, &analysis, &options).unwrap(); + web_sys::GpuShaderModuleDescriptor::new(&js_sys::Uint32Array::from(&words[..])) + } + }; + if let Some(ref label) = desc.label { + descriptor.label(label); + } + Sendable(device.0.create_shader_module(&descriptor)) + } + + fn device_create_bind_group_layout( + &self, + device: &Self::DeviceId, + desc: &crate::BindGroupLayoutDescriptor, + ) -> Self::BindGroupLayoutId { + let mapped_bindings = desc + .entries + .iter() + .map(|bind| { + let mut mapped_entry = + web_sys::GpuBindGroupLayoutEntry::new(bind.binding, bind.visibility.bits()); + + match bind.ty { + wgt::BindingType::Buffer { + ty, + has_dynamic_offset, + min_binding_size, + } => { + let mut buffer = web_sys::GpuBufferBindingLayout::new(); + buffer.has_dynamic_offset(has_dynamic_offset); + if let Some(size) = min_binding_size { + buffer.min_binding_size(size.get() as f64); + } + buffer.type_(match ty { + wgt::BufferBindingType::Uniform => { + web_sys::GpuBufferBindingType::Uniform + } + wgt::BufferBindingType::Storage { read_only: false } => { + web_sys::GpuBufferBindingType::Storage + } + wgt::BufferBindingType::Storage { read_only: true } => { + web_sys::GpuBufferBindingType::ReadOnlyStorage + } + }); + mapped_entry.buffer(&buffer); + } + wgt::BindingType::Sampler { + comparison, + filtering, + } => { + let mut sampler = web_sys::GpuSamplerBindingLayout::new(); + sampler.type_(match (comparison, filtering) { + (false, false) => web_sys::GpuSamplerBindingType::NonFiltering, + (false, true) => web_sys::GpuSamplerBindingType::Filtering, + (true, _) => web_sys::GpuSamplerBindingType::Comparison, + }); + mapped_entry.sampler(&sampler); + } + wgt::BindingType::Texture { + multisampled, + sample_type, + view_dimension, + } => { + let mut texture = web_sys::GpuTextureBindingLayout::new(); + texture.multisampled(multisampled); + texture.sample_type(map_texture_component_type(sample_type)); + texture.view_dimension(map_texture_view_dimension(view_dimension)); + mapped_entry.texture(&texture); + } + wgt::BindingType::StorageTexture { + access, + format, + view_dimension, + } => { + let mapped_access = match access { + wgt::StorageTextureAccess::ReadOnly => { + web_sys::GpuStorageTextureAccess::ReadOnly + } + wgt::StorageTextureAccess::WriteOnly => { + web_sys::GpuStorageTextureAccess::WriteOnly + } + wgt::StorageTextureAccess::ReadWrite => { + panic!("ReadWrite is not available") + } + }; + let mut storage_texture = web_sys::GpuStorageTextureBindingLayout::new( + mapped_access, + map_texture_format(format), + ); + storage_texture.view_dimension(map_texture_view_dimension(view_dimension)); + mapped_entry.storage_texture(&storage_texture); + } + } + + mapped_entry + }) + .collect::(); + + let mut mapped_desc = web_sys::GpuBindGroupLayoutDescriptor::new(&mapped_bindings); + if let Some(ref label) = desc.label { + mapped_desc.label(label); + } + Sendable(device.0.create_bind_group_layout(&mapped_desc)) + } + + fn device_create_bind_group( + &self, + device: &Self::DeviceId, + desc: &crate::BindGroupDescriptor, + ) -> Self::BindGroupId { + let mapped_entries = desc + .entries + .iter() + .map(|binding| { + let mapped_resource = match binding.resource { + crate::BindingResource::Buffer(crate::BufferBinding { + ref buffer, + offset, + size, + }) => { + let mut mapped_buffer_binding = + web_sys::GpuBufferBinding::new(&buffer.id.0); + mapped_buffer_binding.offset(offset as f64); + if let Some(s) = size { + mapped_buffer_binding.size(s.get() as f64); + } + JsValue::from(mapped_buffer_binding.clone()) + } + crate::BindingResource::BufferArray(..) => { + panic!("Web backend does not support arrays of buffers") + } + crate::BindingResource::Sampler(ref sampler) => { + JsValue::from(sampler.id.0.clone()) + } + crate::BindingResource::TextureView(ref texture_view) => { + JsValue::from(texture_view.id.0.clone()) + } + crate::BindingResource::TextureViewArray(..) => { + panic!("Web backend does not support BINDING_INDEXING extension") + } + }; + + web_sys::GpuBindGroupEntry::new(binding.binding, &mapped_resource) + }) + .collect::(); + + let mut mapped_desc = + web_sys::GpuBindGroupDescriptor::new(&mapped_entries, &desc.layout.id.0); + if let Some(label) = desc.label { + mapped_desc.label(label); + } + Sendable(device.0.create_bind_group(&mapped_desc)) + } + + fn device_create_pipeline_layout( + &self, + device: &Self::DeviceId, + desc: &crate::PipelineLayoutDescriptor, + ) -> Self::PipelineLayoutId { + let temp_layouts = desc + .bind_group_layouts + .iter() + .map(|bgl| bgl.id.0.clone()) + .collect::(); + let mut mapped_desc = web_sys::GpuPipelineLayoutDescriptor::new(&temp_layouts); + if let Some(label) = desc.label { + mapped_desc.label(label); + } + Sendable(device.0.create_pipeline_layout(&mapped_desc)) + } + + fn device_create_render_pipeline( + &self, + device: &Self::DeviceId, + desc: &crate::RenderPipelineDescriptor, + ) -> Self::RenderPipelineId { + let mut mapped_vertex_state = + web_sys::GpuVertexState::new(&desc.vertex.entry_point, &desc.vertex.module.id.0); + + let buffers = desc + .vertex + .buffers + .iter() + .map(|vbuf| { + let mapped_attributes = vbuf + .attributes + .iter() + .map(|attr| { + web_sys::GpuVertexAttribute::new( + map_vertex_format(attr.format), + attr.offset as f64, + attr.shader_location, + ) + }) + .collect::(); + + let mut mapped_vbuf = web_sys::GpuVertexBufferLayout::new( + vbuf.array_stride as f64, + &mapped_attributes, + ); + mapped_vbuf.step_mode(map_input_step_mode(vbuf.step_mode)); + mapped_vbuf + }) + .collect::(); + + mapped_vertex_state.buffers(&buffers); + + let mut mapped_desc = web_sys::GpuRenderPipelineDescriptor::new(&mapped_vertex_state); + + if let Some(label) = desc.label { + mapped_desc.label(label); + } + + if let Some(layout) = desc.layout { + mapped_desc.layout(&layout.id.0); + } + + if let Some(ref depth_stencil) = desc.depth_stencil { + mapped_desc.depth_stencil(&map_depth_stencil_state(depth_stencil)); + } + + if let Some(ref frag) = desc.fragment { + let targets = frag + .targets + .iter() + .map(|target| { + let mapped_format = map_texture_format(target.format); + let mut mapped_color_state = web_sys::GpuColorTargetState::new(mapped_format); + if let Some(ref bs) = target.blend { + let alpha = map_blend_component(&bs.alpha); + let color = map_blend_component(&bs.color); + let mapped_blend_state = web_sys::GpuBlendState::new(&alpha, &color); + mapped_color_state.blend(&mapped_blend_state); + } + mapped_color_state.write_mask(target.write_mask.bits()); + mapped_color_state + }) + .collect::(); + let mapped_fragment_desc = + web_sys::GpuFragmentState::new(&frag.entry_point, &frag.module.id.0, &targets); + mapped_desc.fragment(&mapped_fragment_desc); + } + + let mut mapped_multisample = web_sys::GpuMultisampleState::new(); + mapped_multisample.count(desc.multisample.count); + mapped_multisample.mask(desc.multisample.mask as u32); + mapped_multisample.alpha_to_coverage_enabled(desc.multisample.alpha_to_coverage_enabled); + mapped_desc.multisample(&mapped_multisample); + + let mapped_primitive = map_primitive_state(&desc.primitive); + mapped_desc.primitive(&mapped_primitive); + + Sendable(device.0.create_render_pipeline(&mapped_desc)) + } + + fn device_create_compute_pipeline( + &self, + device: &Self::DeviceId, + desc: &crate::ComputePipelineDescriptor, + ) -> Self::ComputePipelineId { + let mapped_compute_stage = + web_sys::GpuProgrammableStage::new(&desc.entry_point, &desc.module.id.0); + let mut mapped_desc = web_sys::GpuComputePipelineDescriptor::new(&mapped_compute_stage); + if let Some(layout) = desc.layout { + mapped_desc.layout(&layout.id.0); + } + if let Some(label) = desc.label { + mapped_desc.label(label); + } + Sendable(device.0.create_compute_pipeline(&mapped_desc)) + } + + fn device_create_buffer( + &self, + device: &Self::DeviceId, + desc: &crate::BufferDescriptor, + ) -> Self::BufferId { + let mut mapped_desc = + web_sys::GpuBufferDescriptor::new(desc.size as f64, desc.usage.bits()); + mapped_desc.mapped_at_creation(desc.mapped_at_creation); + if let Some(ref label) = desc.label { + mapped_desc.label(label); + } + Sendable(device.0.create_buffer(&mapped_desc)) + } + + fn device_create_texture( + &self, + device: &Self::DeviceId, + desc: &crate::TextureDescriptor, + ) -> Self::TextureId { + let mut mapped_desc = web_sys::GpuTextureDescriptor::new( + map_texture_format(desc.format), + &map_extent_3d(desc.size), + desc.usage.bits(), + ); + if let Some(ref label) = desc.label { + mapped_desc.label(label); + } + mapped_desc.dimension(map_texture_dimension(desc.dimension)); + mapped_desc.mip_level_count(desc.mip_level_count); + mapped_desc.sample_count(desc.sample_count); + Sendable(device.0.create_texture(&mapped_desc)) + } + + fn device_create_sampler( + &self, + device: &Self::DeviceId, + desc: &crate::SamplerDescriptor, + ) -> Self::SamplerId { + let mut mapped_desc = web_sys::GpuSamplerDescriptor::new(); + mapped_desc.address_mode_u(map_address_mode(desc.address_mode_u)); + mapped_desc.address_mode_v(map_address_mode(desc.address_mode_v)); + mapped_desc.address_mode_w(map_address_mode(desc.address_mode_w)); + if let Some(compare) = desc.compare { + mapped_desc.compare(map_compare_function(compare)); + } + mapped_desc.lod_max_clamp(desc.lod_max_clamp); + mapped_desc.lod_min_clamp(desc.lod_min_clamp); + mapped_desc.mag_filter(map_filter_mode(desc.mag_filter)); + mapped_desc.min_filter(map_filter_mode(desc.min_filter)); + mapped_desc.mipmap_filter(map_filter_mode(desc.mipmap_filter)); + // TODO: `max_anisotropy` is not available on `desc` yet + // mapped_desc.max_anisotropy(desc.max_anisotropy); + if let Some(label) = desc.label { + mapped_desc.label(label); + } + Sendable(device.0.create_sampler_with_descriptor(&mapped_desc)) + } + + fn device_create_query_set( + &self, + _device: &Self::DeviceId, + _desc: &wgt::QuerySetDescriptor, + ) -> Self::QuerySetId { + () + } + + fn device_create_command_encoder( + &self, + device: &Self::DeviceId, + desc: &crate::CommandEncoderDescriptor, + ) -> Self::CommandEncoderId { + let mut mapped_desc = web_sys::GpuCommandEncoderDescriptor::new(); + if let Some(ref label) = desc.label { + mapped_desc.label(label); + } + device + .0 + .create_command_encoder_with_descriptor(&mapped_desc) + } + + fn device_create_render_bundle_encoder( + &self, + device: &Self::DeviceId, + desc: &crate::RenderBundleEncoderDescriptor, + ) -> Self::RenderBundleEncoderId { + let mapped_color_formats = desc + .color_formats + .iter() + .map(|cf| wasm_bindgen::JsValue::from(map_texture_format(*cf))) + .collect::(); + let mut mapped_desc = web_sys::GpuRenderBundleEncoderDescriptor::new(&mapped_color_formats); + if let Some(ref label) = desc.label { + mapped_desc.label(label); + } + if let Some(dsf) = desc.depth_stencil_format { + mapped_desc.depth_stencil_format(map_texture_format(dsf)); + } + mapped_desc.sample_count(desc.sample_count); + RenderBundleEncoder(device.0.create_render_bundle_encoder(&mapped_desc)) + } + + fn device_drop(&self, _device: &Self::DeviceId) { + // Device is dropped automatically + } + + fn device_poll(&self, _device: &Self::DeviceId, _maintain: crate::Maintain) { + // Device is polled automatically + } + + fn device_on_uncaptured_error( + &self, + _device: &Self::DeviceId, + _handler: impl crate::UncapturedErrorHandler, + ) { + // TODO: + } + + fn buffer_map_async( + &self, + buffer: &Self::BufferId, + mode: crate::MapMode, + range: Range, + ) -> Self::MapAsyncFuture { + let map_promise = buffer.0.map_async_with_f64_and_f64( + map_map_mode(mode), + range.start as f64, + (range.end - range.start) as f64, + ); + + MakeSendFuture::new( + wasm_bindgen_futures::JsFuture::from(map_promise), + future_map_async, + ) + } + + fn buffer_get_mapped_range( + &self, + buffer: &Self::BufferId, + sub_range: Range, + ) -> BufferMappedRange { + let array_buffer = buffer.0.get_mapped_range_with_f64_and_f64( + sub_range.start as f64, + (sub_range.end - sub_range.start) as f64, + ); + let actual_mapping = js_sys::Uint8Array::new(&array_buffer); + let temporary_mapping = actual_mapping.to_vec(); + BufferMappedRange { + actual_mapping, + temporary_mapping, + } + } + + fn buffer_unmap(&self, buffer: &Self::BufferId) { + buffer.0.unmap(); + } + + fn swap_chain_get_current_texture_view( + &self, + swap_chain: &Self::SwapChainId, + ) -> ( + Option, + wgt::SwapChainStatus, + Self::SwapChainOutputDetail, + ) { + // TODO: Should we pass a descriptor here? + // Or is the default view always correct? + ( + Some(Sendable(swap_chain.0.get_current_texture().create_view())), + wgt::SwapChainStatus::Good, + (), + ) + } + + fn swap_chain_present( + &self, + _view: &Self::TextureViewId, + _detail: &Self::SwapChainOutputDetail, + ) { + // Swapchain is presented automatically + } + + fn texture_create_view( + &self, + texture: &Self::TextureId, + desc: &crate::TextureViewDescriptor, + ) -> Self::TextureViewId { + let mut mapped = web_sys::GpuTextureViewDescriptor::new(); + if let Some(dim) = desc.dimension { + mapped.dimension(map_texture_view_dimension(dim)); + } + if let Some(format) = desc.format { + mapped.format(map_texture_format(format)); + } + mapped.aspect(map_texture_aspect(desc.aspect)); + mapped.base_array_layer(desc.base_array_layer); + if let Some(count) = desc.array_layer_count { + mapped.array_layer_count(count.get()); + } + mapped.base_mip_level(desc.base_mip_level); + if let Some(count) = desc.mip_level_count { + mapped.mip_level_count(count.get()); + } + if let Some(label) = desc.label { + mapped.label(label); + } + Sendable(texture.0.create_view_with_descriptor(&mapped)) + } + + fn surface_drop(&self, _surface: &Self::SurfaceId) { + // Dropped automatically + } + + fn adapter_drop(&self, _adapter: &Self::AdapterId) { + // Dropped automatically + } + + fn buffer_destroy(&self, buffer: &Self::BufferId) { + buffer.0.destroy(); + } + + fn buffer_drop(&self, _buffer: &Self::BufferId) { + // Dropped automatically + } + + fn texture_drop(&self, _texture: &Self::TextureId) { + // Dropped automatically + } + + fn texture_destroy(&self, texture: &Self::TextureId) { + texture.0.destroy(); + } + + fn texture_view_drop(&self, _texture_view: &Self::TextureViewId) { + // Dropped automatically + } + + fn sampler_drop(&self, _sampler: &Self::SamplerId) { + // Dropped automatically + } + + fn query_set_drop(&self, _query_set: &Self::QuerySetId) { + // Dropped automatically + } + + fn bind_group_drop(&self, _bind_group: &Self::BindGroupId) { + // Dropped automatically + } + + fn bind_group_layout_drop(&self, _bind_group_layout: &Self::BindGroupLayoutId) { + // Dropped automatically + } + + fn pipeline_layout_drop(&self, _pipeline_layout: &Self::PipelineLayoutId) { + // Dropped automatically + } + + fn shader_module_drop(&self, _shader_module: &Self::ShaderModuleId) { + // Dropped automatically + } + + fn command_encoder_drop(&self, _command_encoder: &Self::CommandEncoderId) { + // Dropped automatically + } + + fn command_buffer_drop(&self, _command_buffer: &Self::CommandBufferId) { + // Dropped automatically + } + + fn render_bundle_drop(&self, _render_bundle: &Self::RenderBundleId) { + // Dropped automatically + } + + fn compute_pipeline_drop(&self, _pipeline: &Self::ComputePipelineId) { + // Dropped automatically + } + + fn render_pipeline_drop(&self, _pipeline: &Self::RenderPipelineId) { + // Dropped automatically + } + + fn compute_pipeline_get_bind_group_layout( + &self, + pipeline: &Self::ComputePipelineId, + index: u32, + ) -> Self::BindGroupLayoutId { + Sendable(pipeline.0.get_bind_group_layout(index)) + } + + fn render_pipeline_get_bind_group_layout( + &self, + pipeline: &Self::RenderPipelineId, + index: u32, + ) -> Self::BindGroupLayoutId { + Sendable(pipeline.0.get_bind_group_layout(index)) + } + + fn command_encoder_copy_buffer_to_buffer( + &self, + encoder: &Self::CommandEncoderId, + source: &Self::BufferId, + source_offset: wgt::BufferAddress, + destination: &Self::BufferId, + destination_offset: wgt::BufferAddress, + copy_size: wgt::BufferAddress, + ) { + encoder.copy_buffer_to_buffer_with_f64_and_f64_and_f64( + &source.0, + source_offset as f64, + &destination.0, + destination_offset as f64, + copy_size as f64, + ) + } + + fn command_encoder_copy_buffer_to_texture( + &self, + encoder: &Self::CommandEncoderId, + source: crate::ImageCopyBuffer, + destination: crate::ImageCopyTexture, + copy_size: wgt::Extent3d, + ) { + encoder.copy_buffer_to_texture_with_gpu_extent_3d_dict( + &map_buffer_copy_view(source), + &map_texture_copy_view(destination), + &map_extent_3d(copy_size), + ) + } + + fn command_encoder_copy_texture_to_buffer( + &self, + encoder: &Self::CommandEncoderId, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyBuffer, + copy_size: wgt::Extent3d, + ) { + encoder.copy_texture_to_buffer_with_gpu_extent_3d_dict( + &map_texture_copy_view(source), + &map_buffer_copy_view(destination), + &map_extent_3d(copy_size), + ) + } + + fn command_encoder_copy_texture_to_texture( + &self, + encoder: &Self::CommandEncoderId, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyTexture, + copy_size: wgt::Extent3d, + ) { + encoder.copy_texture_to_texture_with_gpu_extent_3d_dict( + &map_texture_copy_view(source), + &map_texture_copy_view(destination), + &map_extent_3d(copy_size), + ) + } + + fn command_encoder_begin_compute_pass( + &self, + encoder: &Self::CommandEncoderId, + desc: &crate::ComputePassDescriptor, + ) -> Self::ComputePassId { + let mut mapped_desc = web_sys::GpuComputePassDescriptor::new(); + if let Some(ref label) = desc.label { + mapped_desc.label(label); + } + ComputePass(encoder.begin_compute_pass_with_descriptor(&mapped_desc)) + } + + fn command_encoder_end_compute_pass( + &self, + _encoder: &Self::CommandEncoderId, + pass: &mut Self::ComputePassId, + ) { + pass.0.end_pass(); + } + + fn command_encoder_begin_render_pass<'a>( + &self, + encoder: &Self::CommandEncoderId, + desc: &crate::RenderPassDescriptor<'a, '_>, + ) -> Self::RenderPassId { + let mapped_color_attachments = desc + .color_attachments + .iter() + .map(|ca| { + let load_value = match ca.ops.load { + crate::LoadOp::Clear(color) => wasm_bindgen::JsValue::from(map_color(color)), + crate::LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load), + }; + + let mut mapped_color_attachment = + web_sys::GpuRenderPassColorAttachment::new(&load_value, &ca.view.id.0); + + if let Some(rt) = ca.resolve_target { + mapped_color_attachment.resolve_target(&rt.id.0); + } + + mapped_color_attachment.store_op(map_store_op(ca.ops.store)); + + mapped_color_attachment + }) + .collect::(); + + let mut mapped_desc = web_sys::GpuRenderPassDescriptor::new(&mapped_color_attachments); + + if let Some(label) = desc.label { + mapped_desc.label(label); + } + + if let Some(dsa) = &desc.depth_stencil_attachment { + let (depth_load_op, depth_store_op) = match dsa.depth_ops { + Some(ref ops) => { + let load_op = match ops.load { + crate::LoadOp::Clear(value) => wasm_bindgen::JsValue::from(value), + crate::LoadOp::Load => { + wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load) + } + }; + (load_op, map_store_op(ops.store)) + } + None => ( + wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load), + web_sys::GpuStoreOp::Store, + ), + }; + let (stencil_load_op, stencil_store_op) = match dsa.stencil_ops { + Some(ref ops) => { + let load_op = match ops.load { + crate::LoadOp::Clear(value) => wasm_bindgen::JsValue::from(value), + crate::LoadOp::Load => { + wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load) + } + }; + (load_op, map_store_op(ops.store)) + } + None => ( + wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load), + web_sys::GpuStoreOp::Store, + ), + }; + let mapped_depth_stencil_attachment = web_sys::GpuRenderPassDepthStencilAttachment::new( + &depth_load_op, + depth_store_op, + &stencil_load_op, + stencil_store_op, + &dsa.view.id.0, + ); + + mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment); + } + + RenderPass(encoder.begin_render_pass(&mapped_desc)) + } + + fn command_encoder_end_render_pass( + &self, + _encoder: &Self::CommandEncoderId, + pass: &mut Self::RenderPassId, + ) { + pass.0.end_pass(); + } + + fn command_encoder_finish(&self, encoder: Self::CommandEncoderId) -> Self::CommandBufferId { + Sendable(match encoder.label() { + Some(ref label) => { + let mut mapped_desc = web_sys::GpuCommandBufferDescriptor::new(); + mapped_desc.label(label); + encoder.finish_with_descriptor(&mapped_desc) + } + None => encoder.finish(), + }) + } + + fn command_encoder_insert_debug_marker(&self, _encoder: &Self::CommandEncoderId, _label: &str) { + // Not available in gecko yet + // encoder.insert_debug_marker(label); + } + + fn command_encoder_push_debug_group(&self, _encoder: &Self::CommandEncoderId, _label: &str) { + // Not available in gecko yet + // encoder.push_debug_group(label); + } + + fn command_encoder_pop_debug_group(&self, _encoder: &Self::CommandEncoderId) { + // Not available in gecko yet + // encoder.pop_debug_group(); + } + + fn command_encoder_write_timestamp( + &self, + _encoder: &Self::CommandEncoderId, + _query_set: &Self::QuerySetId, + _query_index: u32, + ) { + // Not available in gecko yet + } + + fn command_encoder_resolve_query_set( + &self, + _encoder: &Self::CommandEncoderId, + _query_set: &Self::QuerySetId, + _first_query: u32, + _query_count: u32, + _destination: &Self::BufferId, + _destination_offset: wgt::BufferAddress, + ) { + // Not available in gecko yet + } + + fn render_bundle_encoder_finish( + &self, + encoder: Self::RenderBundleEncoderId, + desc: &crate::RenderBundleDescriptor, + ) -> Self::RenderBundleId { + Sendable(match desc.label { + Some(label) => { + let mut mapped_desc = web_sys::GpuRenderBundleDescriptor::new(); + mapped_desc.label(label); + encoder.0.finish_with_descriptor(&mapped_desc) + } + None => encoder.0.finish(), + }) + } + + fn queue_write_buffer( + &self, + queue: &Self::QueueId, + buffer: &Self::BufferId, + offset: wgt::BufferAddress, + data: &[u8], + ) { + /* Skip the copy once gecko allows BufferSource instead of ArrayBuffer + queue.0.write_buffer_with_f64_and_u8_array_and_f64_and_f64( + &buffer.0, + offset as f64, + data, + 0f64, + data.len() as f64, + ); + */ + queue + .0 + .write_buffer_with_f64_and_buffer_source_and_f64_and_f64( + &buffer.0, + offset as f64, + &js_sys::Uint8Array::from(data).buffer(), + 0f64, + data.len() as f64, + ); + } + + fn queue_write_texture( + &self, + queue: &Self::QueueId, + texture: crate::ImageCopyTexture, + data: &[u8], + data_layout: wgt::ImageDataLayout, + size: wgt::Extent3d, + ) { + let mut mapped_data_layout = web_sys::GpuImageDataLayout::new(); + if let Some(bytes_per_row) = data_layout.bytes_per_row { + mapped_data_layout.bytes_per_row(bytes_per_row.get()); + } + if let Some(rows_per_image) = data_layout.rows_per_image { + mapped_data_layout.rows_per_image(rows_per_image.get()); + } + mapped_data_layout.offset(data_layout.offset as f64); + + /* Skip the copy once gecko allows BufferSource instead of ArrayBuffer + queue.0.write_texture_with_u8_array_and_gpu_extent_3d_dict( + &map_texture_copy_view(texture), + data, + &mapped_data_layout, + &map_extent_3d(size), + ); + */ + queue + .0 + .write_texture_with_buffer_source_and_gpu_extent_3d_dict( + &map_texture_copy_view(texture), + &js_sys::Uint8Array::from(data).buffer(), + &mapped_data_layout, + &map_extent_3d(size), + ); + } + + fn queue_submit>( + &self, + queue: &Self::QueueId, + command_buffers: I, + ) { + let temp_command_buffers = command_buffers.map(|i| i.0).collect::(); + + queue.0.submit(&temp_command_buffers); + } + + fn queue_get_timestamp_period(&self, _queue: &Self::QueueId) -> f32 { + 1.0 //TODO + } + + fn device_start_capture(&self, _device: &Self::DeviceId) {} + fn device_stop_capture(&self, _device: &Self::DeviceId) {} +} + +pub(crate) type SwapChainOutputDetail = (); + +#[derive(Debug)] +pub struct BufferMappedRange { + actual_mapping: js_sys::Uint8Array, + temporary_mapping: Vec, +} + +impl crate::BufferMappedRangeSlice for BufferMappedRange { + fn slice(&self) -> &[u8] { + &self.temporary_mapping + } + + fn slice_mut(&mut self) -> &mut [u8] { + &mut self.temporary_mapping + } +} + +impl Drop for BufferMappedRange { + fn drop(&mut self) { + // Copy from the temporary mapping back into the array buffer that was + // originally provided by the browser + let temporary_mapping_slice = self.temporary_mapping.as_slice(); + unsafe { + // Note: no allocations can happen between `view` and `set`, or this + // will break + self.actual_mapping + .set(&js_sys::Uint8Array::view(temporary_mapping_slice), 0); + } + } +} diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs new file mode 100644 index 000000000..328162b08 --- /dev/null +++ b/wgpu/src/lib.rs @@ -0,0 +1,2971 @@ +//! A cross-platform graphics and compute library based on [WebGPU](https://gpuweb.github.io/gpuweb/). +//! +//! To start using the API, create an [`Instance`]. + +#![doc(html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu-rs/master/logo.png")] +#![warn(missing_docs)] + +mod backend; +pub mod util; +#[macro_use] +mod macros; + +use std::{ + borrow::Cow, + error, + fmt::{Debug, Display}, + future::Future, + marker::PhantomData, + num::{NonZeroU32, NonZeroU8}, + ops::{Bound, Range, RangeBounds}, + sync::Arc, + thread, +}; + +use parking_lot::Mutex; + +pub use wgt::{ + AdapterInfo, AddressMode, Backend, BackendBit, BindGroupLayoutEntry, BindingType, + BlendComponent, BlendFactor, BlendOperation, BlendState, BufferAddress, BufferBindingType, + BufferSize, BufferUsage, Color, ColorTargetState, ColorWrite, CommandBufferDescriptor, + CompareFunction, DepthBiasState, DepthStencilState, DeviceType, DownlevelFlags, + DownlevelProperties, DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, + ImageDataLayout, IndexFormat, InputStepMode, Limits, MultisampleState, Origin3d, + PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState, + PrimitiveTopology, PushConstantRange, QuerySetDescriptor, QueryType, SamplerBorderColor, + ShaderFlags, ShaderLocation, ShaderModel, ShaderStage, StencilFaceState, StencilOperation, + StencilState, StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect, + TextureDimension, TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, + TextureSampleType, TextureUsage, TextureViewDimension, VertexAttribute, VertexFormat, + BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, + PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, +}; + +use backend::{BufferMappedRange, Context as C}; + +trait ComputePassInner { + fn set_pipeline(&mut self, pipeline: &Ctx::ComputePipelineId); + fn set_bind_group( + &mut self, + index: u32, + bind_group: &Ctx::BindGroupId, + offsets: &[DynamicOffset], + ); + fn set_push_constants(&mut self, offset: u32, data: &[u8]); + fn insert_debug_marker(&mut self, label: &str); + fn push_debug_group(&mut self, group_label: &str); + fn pop_debug_group(&mut self); + fn write_timestamp(&mut self, query_set: &Ctx::QuerySetId, query_index: u32); + fn begin_pipeline_statistics_query(&mut self, query_set: &Ctx::QuerySetId, query_index: u32); + fn end_pipeline_statistics_query(&mut self); + fn dispatch(&mut self, x: u32, y: u32, z: u32); + fn dispatch_indirect( + &mut self, + indirect_buffer: &Ctx::BufferId, + indirect_offset: BufferAddress, + ); +} + +trait RenderInner { + fn set_pipeline(&mut self, pipeline: &Ctx::RenderPipelineId); + fn set_bind_group( + &mut self, + index: u32, + bind_group: &Ctx::BindGroupId, + offsets: &[DynamicOffset], + ); + fn set_index_buffer( + &mut self, + buffer: &Ctx::BufferId, + index_format: IndexFormat, + offset: BufferAddress, + size: Option, + ); + fn set_vertex_buffer( + &mut self, + slot: u32, + buffer: &Ctx::BufferId, + offset: BufferAddress, + size: Option, + ); + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]); + fn draw(&mut self, vertices: Range, instances: Range); + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range); + fn draw_indirect(&mut self, indirect_buffer: &Ctx::BufferId, indirect_offset: BufferAddress); + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &Ctx::BufferId, + indirect_offset: BufferAddress, + ); + fn multi_draw_indirect( + &mut self, + indirect_buffer: &Ctx::BufferId, + indirect_offset: BufferAddress, + count: u32, + ); + fn multi_draw_indexed_indirect( + &mut self, + indirect_buffer: &Ctx::BufferId, + indirect_offset: BufferAddress, + count: u32, + ); + fn multi_draw_indirect_count( + &mut self, + indirect_buffer: &Ctx::BufferId, + indirect_offset: BufferAddress, + count_buffer: &Ctx::BufferId, + count_buffer_offset: BufferAddress, + max_count: u32, + ); + fn multi_draw_indexed_indirect_count( + &mut self, + indirect_buffer: &Ctx::BufferId, + indirect_offset: BufferAddress, + count_buffer: &Ctx::BufferId, + count_buffer_offset: BufferAddress, + max_count: u32, + ); +} + +trait RenderPassInner: RenderInner { + fn set_blend_constant(&mut self, color: Color); + fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32); + fn set_viewport( + &mut self, + x: f32, + y: f32, + width: f32, + height: f32, + min_depth: f32, + max_depth: f32, + ); + fn set_stencil_reference(&mut self, reference: u32); + fn insert_debug_marker(&mut self, label: &str); + fn push_debug_group(&mut self, group_label: &str); + fn pop_debug_group(&mut self); + fn write_timestamp(&mut self, query_set: &Ctx::QuerySetId, query_index: u32); + fn begin_pipeline_statistics_query(&mut self, query_set: &Ctx::QuerySetId, query_index: u32); + fn end_pipeline_statistics_query(&mut self); + fn execute_bundles<'a, I: Iterator>( + &mut self, + render_bundles: I, + ); +} + +trait Context: Debug + Send + Sized + Sync { + type AdapterId: Debug + Send + Sync + 'static; + type DeviceId: Debug + Send + Sync + 'static; + type QueueId: Debug + Send + Sync + 'static; + type ShaderModuleId: Debug + Send + Sync + 'static; + type BindGroupLayoutId: Debug + Send + Sync + 'static; + type BindGroupId: Debug + Send + Sync + 'static; + type TextureViewId: Debug + Send + Sync + 'static; + type SamplerId: Debug + Send + Sync + 'static; + type BufferId: Debug + Send + Sync + 'static; + type TextureId: Debug + Send + Sync + 'static; + type QuerySetId: Debug + Send + Sync + 'static; + type PipelineLayoutId: Debug + Send + Sync + 'static; + type RenderPipelineId: Debug + Send + Sync + 'static; + type ComputePipelineId: Debug + Send + Sync + 'static; + type CommandEncoderId: Debug; + type ComputePassId: Debug + ComputePassInner; + type RenderPassId: Debug + RenderPassInner; + type CommandBufferId: Debug + Send + Sync; + type RenderBundleEncoderId: Debug + RenderInner; + type RenderBundleId: Debug + Send + Sync + 'static; + type SurfaceId: Debug + Send + Sync + 'static; + type SwapChainId: Debug + Send + Sync + 'static; + + type SwapChainOutputDetail: Send; + + type RequestAdapterFuture: Future> + Send; + type RequestDeviceFuture: Future> + + Send; + type MapAsyncFuture: Future> + Send; + + fn init(backends: BackendBit) -> Self; + fn instance_create_surface( + &self, + handle: &impl raw_window_handle::HasRawWindowHandle, + ) -> Self::SurfaceId; + fn instance_request_adapter( + &self, + options: &RequestAdapterOptions<'_>, + ) -> Self::RequestAdapterFuture; + fn adapter_request_device( + &self, + adapter: &Self::AdapterId, + desc: &DeviceDescriptor, + trace_dir: Option<&std::path::Path>, + ) -> Self::RequestDeviceFuture; + fn instance_poll_all_devices(&self, force_wait: bool); + fn adapter_get_swap_chain_preferred_format( + &self, + adapter: &Self::AdapterId, + surface: &Self::SurfaceId, + ) -> Option; + fn adapter_features(&self, adapter: &Self::AdapterId) -> Features; + fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits; + fn adapter_downlevel_properties(&self, adapter: &Self::AdapterId) -> DownlevelProperties; + fn adapter_get_info(&self, adapter: &Self::AdapterId) -> AdapterInfo; + fn adapter_get_texture_format_features( + &self, + adapter: &Self::AdapterId, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures; + + fn device_features(&self, device: &Self::DeviceId) -> Features; + fn device_limits(&self, device: &Self::DeviceId) -> Limits; + fn device_downlevel_properties(&self, device: &Self::DeviceId) -> DownlevelProperties; + fn device_create_swap_chain( + &self, + device: &Self::DeviceId, + surface: &Self::SurfaceId, + desc: &SwapChainDescriptor, + ) -> Self::SwapChainId; + fn device_create_shader_module( + &self, + device: &Self::DeviceId, + desc: &ShaderModuleDescriptor, + ) -> Self::ShaderModuleId; + fn device_create_bind_group_layout( + &self, + device: &Self::DeviceId, + desc: &BindGroupLayoutDescriptor, + ) -> Self::BindGroupLayoutId; + fn device_create_bind_group( + &self, + device: &Self::DeviceId, + desc: &BindGroupDescriptor, + ) -> Self::BindGroupId; + fn device_create_pipeline_layout( + &self, + device: &Self::DeviceId, + desc: &PipelineLayoutDescriptor, + ) -> Self::PipelineLayoutId; + fn device_create_render_pipeline( + &self, + device: &Self::DeviceId, + desc: &RenderPipelineDescriptor, + ) -> Self::RenderPipelineId; + fn device_create_compute_pipeline( + &self, + device: &Self::DeviceId, + desc: &ComputePipelineDescriptor, + ) -> Self::ComputePipelineId; + fn device_create_buffer( + &self, + device: &Self::DeviceId, + desc: &BufferDescriptor, + ) -> Self::BufferId; + fn device_create_texture( + &self, + device: &Self::DeviceId, + desc: &TextureDescriptor, + ) -> Self::TextureId; + fn device_create_sampler( + &self, + device: &Self::DeviceId, + desc: &SamplerDescriptor, + ) -> Self::SamplerId; + fn device_create_query_set( + &self, + device: &Self::DeviceId, + desc: &QuerySetDescriptor, + ) -> Self::QuerySetId; + fn device_create_command_encoder( + &self, + device: &Self::DeviceId, + desc: &CommandEncoderDescriptor, + ) -> Self::CommandEncoderId; + fn device_create_render_bundle_encoder( + &self, + device: &Self::DeviceId, + desc: &RenderBundleEncoderDescriptor, + ) -> Self::RenderBundleEncoderId; + fn device_drop(&self, device: &Self::DeviceId); + fn device_poll(&self, device: &Self::DeviceId, maintain: Maintain); + fn device_on_uncaptured_error( + &self, + device: &Self::DeviceId, + handler: impl UncapturedErrorHandler, + ); + + fn buffer_map_async( + &self, + buffer: &Self::BufferId, + mode: MapMode, + range: Range, + ) -> Self::MapAsyncFuture; + fn buffer_get_mapped_range( + &self, + buffer: &Self::BufferId, + sub_range: Range, + ) -> BufferMappedRange; + fn buffer_unmap(&self, buffer: &Self::BufferId); + fn swap_chain_get_current_texture_view( + &self, + swap_chain: &Self::SwapChainId, + ) -> ( + Option, + SwapChainStatus, + Self::SwapChainOutputDetail, + ); + fn swap_chain_present(&self, view: &Self::TextureViewId, detail: &Self::SwapChainOutputDetail); + fn texture_create_view( + &self, + texture: &Self::TextureId, + desc: &TextureViewDescriptor, + ) -> Self::TextureViewId; + + fn surface_drop(&self, surface: &Self::SurfaceId); + fn adapter_drop(&self, adapter: &Self::AdapterId); + fn buffer_destroy(&self, buffer: &Self::BufferId); + fn buffer_drop(&self, buffer: &Self::BufferId); + fn texture_destroy(&self, buffer: &Self::TextureId); + fn texture_drop(&self, texture: &Self::TextureId); + fn texture_view_drop(&self, texture_view: &Self::TextureViewId); + fn sampler_drop(&self, sampler: &Self::SamplerId); + fn query_set_drop(&self, query_set: &Self::QuerySetId); + fn bind_group_drop(&self, bind_group: &Self::BindGroupId); + fn bind_group_layout_drop(&self, bind_group_layout: &Self::BindGroupLayoutId); + fn pipeline_layout_drop(&self, pipeline_layout: &Self::PipelineLayoutId); + fn shader_module_drop(&self, shader_module: &Self::ShaderModuleId); + fn command_encoder_drop(&self, command_encoder: &Self::CommandEncoderId); + fn command_buffer_drop(&self, command_buffer: &Self::CommandBufferId); + fn render_bundle_drop(&self, render_bundle: &Self::RenderBundleId); + fn compute_pipeline_drop(&self, pipeline: &Self::ComputePipelineId); + fn render_pipeline_drop(&self, pipeline: &Self::RenderPipelineId); + + fn compute_pipeline_get_bind_group_layout( + &self, + pipeline: &Self::ComputePipelineId, + index: u32, + ) -> Self::BindGroupLayoutId; + fn render_pipeline_get_bind_group_layout( + &self, + pipeline: &Self::RenderPipelineId, + index: u32, + ) -> Self::BindGroupLayoutId; + + fn command_encoder_copy_buffer_to_buffer( + &self, + encoder: &Self::CommandEncoderId, + source: &Self::BufferId, + source_offset: BufferAddress, + destination: &Self::BufferId, + destination_offset: BufferAddress, + copy_size: BufferAddress, + ); + fn command_encoder_copy_buffer_to_texture( + &self, + encoder: &Self::CommandEncoderId, + source: ImageCopyBuffer, + destination: ImageCopyTexture, + copy_size: Extent3d, + ); + fn command_encoder_copy_texture_to_buffer( + &self, + encoder: &Self::CommandEncoderId, + source: ImageCopyTexture, + destination: ImageCopyBuffer, + copy_size: Extent3d, + ); + fn command_encoder_copy_texture_to_texture( + &self, + encoder: &Self::CommandEncoderId, + source: ImageCopyTexture, + destination: ImageCopyTexture, + copy_size: Extent3d, + ); + + fn command_encoder_begin_compute_pass( + &self, + encoder: &Self::CommandEncoderId, + desc: &ComputePassDescriptor, + ) -> Self::ComputePassId; + fn command_encoder_end_compute_pass( + &self, + encoder: &Self::CommandEncoderId, + pass: &mut Self::ComputePassId, + ); + fn command_encoder_begin_render_pass<'a>( + &self, + encoder: &Self::CommandEncoderId, + desc: &RenderPassDescriptor<'a, '_>, + ) -> Self::RenderPassId; + fn command_encoder_end_render_pass( + &self, + encoder: &Self::CommandEncoderId, + pass: &mut Self::RenderPassId, + ); + fn command_encoder_finish(&self, encoder: Self::CommandEncoderId) -> Self::CommandBufferId; + + fn command_encoder_insert_debug_marker(&self, encoder: &Self::CommandEncoderId, label: &str); + fn command_encoder_push_debug_group(&self, encoder: &Self::CommandEncoderId, label: &str); + fn command_encoder_pop_debug_group(&self, encoder: &Self::CommandEncoderId); + + fn command_encoder_write_timestamp( + &self, + encoder: &Self::CommandEncoderId, + query_set: &Self::QuerySetId, + query_index: u32, + ); + fn command_encoder_resolve_query_set( + &self, + encoder: &Self::CommandEncoderId, + query_set: &Self::QuerySetId, + first_query: u32, + query_count: u32, + destination: &Self::BufferId, + destination_offset: BufferAddress, + ); + + fn render_bundle_encoder_finish( + &self, + encoder: Self::RenderBundleEncoderId, + desc: &RenderBundleDescriptor, + ) -> Self::RenderBundleId; + fn queue_write_buffer( + &self, + queue: &Self::QueueId, + buffer: &Self::BufferId, + offset: BufferAddress, + data: &[u8], + ); + fn queue_write_texture( + &self, + queue: &Self::QueueId, + texture: ImageCopyTexture, + data: &[u8], + data_layout: ImageDataLayout, + size: Extent3d, + ); + fn queue_submit>( + &self, + queue: &Self::QueueId, + command_buffers: I, + ); + fn queue_get_timestamp_period(&self, queue: &Self::QueueId) -> f32; + + fn device_start_capture(&self, device: &Self::DeviceId); + fn device_stop_capture(&self, device: &Self::DeviceId); +} + +/// Context for all other wgpu objects. Instance of wgpu. +/// +/// This is the first thing you create when using wgpu. +/// Its primary use is to create [`Adapter`]s and [`Surface`]s. +/// +/// Does not have to be kept alive. +#[derive(Debug)] +pub struct Instance { + context: Arc, +} + +/// Handle to a physical graphics and/or compute device. +/// +/// Adapters can be used to open a connection to the corresponding [`Device`] +/// on the host system by using [`Adapter::request_device`]. +/// +/// Does not have to be kept alive. +#[derive(Debug)] +pub struct Adapter { + context: Arc, + id: ::AdapterId, +} + +impl Drop for Adapter { + fn drop(&mut self) { + if !thread::panicking() { + self.context.adapter_drop(&self.id) + } + } +} + +/// Open connection to a graphics and/or compute device. +/// +/// Responsible for the creation of most rendering and compute resources. +/// These are then used in commands, which are submitted to a [`Queue`]. +/// +/// A device may be requested from an adapter with [`Adapter::request_device`]. +#[derive(Debug)] +pub struct Device { + context: Arc, + id: ::DeviceId, +} + +/// Passed to [`Device::poll`] to control if it should block or not. This has no effect on +/// the web. +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum Maintain { + /// Block + Wait, + /// Don't block + Poll, +} + +/// The main purpose of this struct is to resolve mapped ranges (convert sizes +/// to end points), and to ensure that the sub-ranges don't intersect. +#[derive(Debug)] +struct MapContext { + total_size: BufferAddress, + initial_range: Range, + sub_ranges: Vec>, +} + +impl MapContext { + fn new(total_size: BufferAddress) -> Self { + MapContext { + total_size, + initial_range: 0..0, + sub_ranges: Vec::new(), + } + } + + fn reset(&mut self) { + self.initial_range = 0..0; + + assert!( + self.sub_ranges.is_empty(), + "You cannot unmap a buffer that still has accessible mapped views" + ); + } + + fn add(&mut self, offset: BufferAddress, size: Option) -> BufferAddress { + let end = match size { + Some(s) => offset + s.get(), + None => self.initial_range.end, + }; + assert!(self.initial_range.start <= offset && end <= self.initial_range.end); + for sub in self.sub_ranges.iter() { + assert!( + end <= sub.start || offset >= sub.end, + "Intersecting map range with {:?}", + sub + ); + } + self.sub_ranges.push(offset..end); + end + } + + fn remove(&mut self, offset: BufferAddress, size: Option) { + let end = match size { + Some(s) => offset + s.get(), + None => self.initial_range.end, + }; + + let index = self + .sub_ranges + .iter() + .position(|r| *r == (offset..end)) + .expect("unable to remove range from map context"); + self.sub_ranges.swap_remove(index); + } +} + +/// Handle to a GPU-accessible buffer. +/// +/// Created with [`Device::create_buffer`] or [DeviceExt::create_buffer_init](util::DeviceExt::create_buffer_init) +#[derive(Debug)] +pub struct Buffer { + context: Arc, + id: ::BufferId, + map_context: Mutex, + usage: BufferUsage, +} + +/// Slice into a [`Buffer`]. +/// +/// Created by calling [`Buffer::slice`]. To use the whole buffer, call with unbounded slice: +/// +/// `buffer.slice(..)` +#[derive(Copy, Clone, Debug)] +pub struct BufferSlice<'a> { + buffer: &'a Buffer, + offset: BufferAddress, + size: Option, +} + +/// Handle to a texture on the GPU. +/// +/// Created by calling [`Device::create_texture`] +#[derive(Debug)] +pub struct Texture { + context: Arc, + id: ::TextureId, + owned: bool, +} + +/// Handle to a texture view. +/// +/// A `TextureView` object describes a texture and associated metadata needed by a +/// [`RenderPipeline`] or [`BindGroup`]. +#[derive(Debug)] +pub struct TextureView { + context: Arc, + id: ::TextureViewId, + owned: bool, +} + +/// Handle to a sampler. +/// +/// A `Sampler` object defines how a pipeline will sample from a [`TextureView`]. Samplers define +/// image filters (including anisotropy) and address (wrapping) modes, among other things. See +/// the documentation for [`SamplerDescriptor`] for more information. +#[derive(Debug)] +pub struct Sampler { + context: Arc, + id: ::SamplerId, +} + +impl Drop for Sampler { + fn drop(&mut self) { + if !thread::panicking() { + self.context.sampler_drop(&self.id); + } + } +} + +/// Handle to a presentable surface. +/// +/// A `Surface` represents a platform-specific surface (e.g. a window) onto which rendered images may +/// be presented. A `Surface` may be created with the unsafe function [`Instance::create_surface`]. +#[derive(Debug)] +pub struct Surface { + context: Arc, + id: ::SurfaceId, +} + +impl Drop for Surface { + fn drop(&mut self) { + if !thread::panicking() { + self.context.surface_drop(&self.id) + } + } +} + +/// Handle to a swap chain. +/// +/// A `SwapChain` represents the image or series of images that will be presented to a [`Surface`]. +/// A `SwapChain` may be created with [`Device::create_swap_chain`]. +#[derive(Debug)] +pub struct SwapChain { + context: Arc, + id: ::SwapChainId, +} + +/// Handle to a binding group layout. +/// +/// A `BindGroupLayout` is a handle to the GPU-side layout of a binding group. It can be used to +/// create a [`BindGroupDescriptor`] object, which in turn can be used to create a [`BindGroup`] +/// object with [`Device::create_bind_group`]. A series of `BindGroupLayout`s can also be used to +/// create a [`PipelineLayoutDescriptor`], which can be used to create a [`PipelineLayout`]. +#[derive(Debug)] +pub struct BindGroupLayout { + context: Arc, + id: ::BindGroupLayoutId, +} + +impl Drop for BindGroupLayout { + fn drop(&mut self) { + if !thread::panicking() { + self.context.bind_group_layout_drop(&self.id); + } + } +} + +/// Handle to a binding group. +/// +/// A `BindGroup` represents the set of resources bound to the bindings described by a +/// [`BindGroupLayout`]. It can be created with [`Device::create_bind_group`]. A `BindGroup` can +/// be bound to a particular [`RenderPass`] with [`RenderPass::set_bind_group`], or to a +/// [`ComputePass`] with [`ComputePass::set_bind_group`]. +#[derive(Debug)] +pub struct BindGroup { + context: Arc, + id: ::BindGroupId, +} + +impl Drop for BindGroup { + fn drop(&mut self) { + if !thread::panicking() { + self.context.bind_group_drop(&self.id); + } + } +} + +/// Handle to a compiled shader module. +/// +/// A `ShaderModule` represents a compiled shader module on the GPU. It can be created by passing +/// valid SPIR-V source code to [`Device::create_shader_module`]. Shader modules are used to define +/// programmable stages of a pipeline. +#[derive(Debug)] +pub struct ShaderModule { + context: Arc, + id: ::ShaderModuleId, +} + +impl Drop for ShaderModule { + fn drop(&mut self) { + if !thread::panicking() { + self.context.shader_module_drop(&self.id); + } + } +} + +/// Source of a shader module. +pub enum ShaderSource<'a> { + /// SPIR-V module represented as a slice of words. + /// + /// wgpu will attempt to parse and validate it, but the original binary + /// is passed to `gfx-rs` and `spirv_cross` for translation. + SpirV(Cow<'a, [u32]>), + /// WGSL module as a string slice. + /// + /// wgpu-rs will parse it and use for validation. It will attempt + /// to build a SPIR-V module internally and panic otherwise. + /// + /// Note: WGSL is not yet supported on the Web. + Wgsl(Cow<'a, str>), +} + +/// Descriptor for a shader module. +pub struct ShaderModuleDescriptor<'a> { + /// Debug label of the shader module. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// Source code for the shader. + pub source: ShaderSource<'a>, + /// Shader handling flags. + pub flags: ShaderFlags, +} + +/// Handle to a pipeline layout. +/// +/// A `PipelineLayout` object describes the available binding groups of a pipeline. +#[derive(Debug)] +pub struct PipelineLayout { + context: Arc, + id: ::PipelineLayoutId, +} + +impl Drop for PipelineLayout { + fn drop(&mut self) { + if !thread::panicking() { + self.context.pipeline_layout_drop(&self.id); + } + } +} + +/// Handle to a rendering (graphics) pipeline. +/// +/// A `RenderPipeline` object represents a graphics pipeline and its stages, bindings, vertex +/// buffers and targets. A `RenderPipeline` may be created with [`Device::create_render_pipeline`]. +#[derive(Debug)] +pub struct RenderPipeline { + context: Arc, + id: ::RenderPipelineId, +} + +impl Drop for RenderPipeline { + fn drop(&mut self) { + if !thread::panicking() { + self.context.render_pipeline_drop(&self.id); + } + } +} + +impl RenderPipeline { + /// Get an object representing the bind group layout at a given index. + pub fn get_bind_group_layout(&self, index: u32) -> BindGroupLayout { + let context = Arc::clone(&self.context); + BindGroupLayout { + context, + id: self + .context + .render_pipeline_get_bind_group_layout(&self.id, index), + } + } +} + +/// Handle to a compute pipeline. +/// +/// A `ComputePipeline` object represents a compute pipeline and its single shader stage. +/// A `ComputePipeline` may be created with [`Device::create_compute_pipeline`]. +#[derive(Debug)] +pub struct ComputePipeline { + context: Arc, + id: ::ComputePipelineId, +} + +impl Drop for ComputePipeline { + fn drop(&mut self) { + if !thread::panicking() { + self.context.compute_pipeline_drop(&self.id); + } + } +} + +impl ComputePipeline { + /// Get an object representing the bind group layout at a given index. + pub fn get_bind_group_layout(&self, index: u32) -> BindGroupLayout { + let context = Arc::clone(&self.context); + BindGroupLayout { + context, + id: self + .context + .compute_pipeline_get_bind_group_layout(&self.id, index), + } + } +} + +/// Handle to a command buffer on the GPU. +/// +/// A `CommandBuffer` represents a complete sequence of commands that may be submitted to a command +/// queue with [`Queue::submit`]. A `CommandBuffer` is obtained by recording a series of commands to +/// a [`CommandEncoder`] and then calling [`CommandEncoder::finish`]. +#[derive(Debug)] +pub struct CommandBuffer { + context: Arc, + id: Option<::CommandBufferId>, +} + +impl Drop for CommandBuffer { + fn drop(&mut self) { + if !thread::panicking() { + if let Some(ref id) = self.id { + self.context.command_buffer_drop(id); + } + } + } +} + +/// Encodes a series of GPU operations. +/// +/// A command encoder can record [`RenderPass`]es, [`ComputePass`]es, +/// and transfer operations between driver-managed resources like [`Buffer`]s and [`Texture`]s. +/// +/// When finished recording, call [`CommandEncoder::finish`] to obtain a [`CommandBuffer`] which may +/// be submitted for execution. +#[derive(Debug)] +pub struct CommandEncoder { + context: Arc, + id: Option<::CommandEncoderId>, + /// This type should be !Send !Sync, because it represents an allocation on this thread's + /// command buffer. + _p: PhantomData<*const u8>, +} + +impl Drop for CommandEncoder { + fn drop(&mut self) { + if !thread::panicking() { + if let Some(id) = self.id.take() { + self.context.command_encoder_drop(&id); + } + } + } +} + +/// In-progress recording of a render pass. +#[derive(Debug)] +pub struct RenderPass<'a> { + id: ::RenderPassId, + parent: &'a mut CommandEncoder, +} + +/// In-progress recording of a compute pass. +#[derive(Debug)] +pub struct ComputePass<'a> { + id: ::ComputePassId, + parent: &'a mut CommandEncoder, +} + +/// Encodes a series of GPU operations into a reusable "render bundle". +/// +/// It only supports a handful of render commands, but it makes them reusable. [`RenderBundle`]s +/// can be executed onto a [`CommandEncoder`] using [`RenderPass::execute_bundles`]. +/// +/// Executing a [`RenderBundle`] is often more efficient then issuing the underlying commands manually. +#[derive(Debug)] +pub struct RenderBundleEncoder<'a> { + context: Arc, + id: ::RenderBundleEncoderId, + _parent: &'a Device, + /// This type should be !Send !Sync, because it represents an allocation on this thread's + /// command buffer. + _p: PhantomData<*const u8>, +} + +/// Pre-prepared reusable bundle of GPU operations. +/// +/// It only supports a handful of render commands, but it makes them reusable. [`RenderBundle`]s +/// can be executed onto a [`CommandEncoder`] using [`RenderPass::execute_bundles`]. +/// +/// Executing a [`RenderBundle`] is often more efficient then issuing the underlying commands manually. +#[derive(Debug)] +pub struct RenderBundle { + context: Arc, + id: ::RenderBundleId, +} + +impl Drop for RenderBundle { + fn drop(&mut self) { + if !thread::panicking() { + self.context.render_bundle_drop(&self.id); + } + } +} + +/// Handle to a query set. +pub struct QuerySet { + context: Arc, + id: ::QuerySetId, +} + +impl Drop for QuerySet { + fn drop(&mut self) { + if !thread::panicking() { + self.context.query_set_drop(&self.id); + } + } +} + +/// Handle to a command queue on a device. +/// +/// A `Queue` executes recorded [`CommandBuffer`] objects and provides convenience methods +/// for writing to [buffers](Queue::write_buffer) and [textures](Queue::write_texture). +#[derive(Debug)] +pub struct Queue { + context: Arc, + id: ::QueueId, +} + +/// Resource that can be bound to a pipeline. +#[non_exhaustive] +#[derive(Clone, Debug)] +pub enum BindingResource<'a> { + /// Binding is backed by a buffer. + /// + /// Corresponds to [`wgt::BufferBindingType::Uniform`] and [`wgt::BufferBindingType::Storage`] + /// with [`BindGroupLayoutEntry::count`] set to None. + Buffer(BufferBinding<'a>), + /// Binding is backed by an array of buffers. + /// + /// [`Features::BUFFER_BINDING_ARRAY`] must be supported to use this feature. + /// + /// Corresponds to [`wgt::BufferBindingType::Uniform`] and [`wgt::BufferBindingType::Storage`] + /// with [`BindGroupLayoutEntry::count`] set to Some. + BufferArray(&'a [BufferBinding<'a>]), + /// Binding is a sampler. + /// + /// Corresponds to [`wgt::BindingType::Sampler`] with [`BindGroupLayoutEntry::count`] set to None. + Sampler(&'a Sampler), + /// Binding is backed by a texture. + /// + /// Corresponds to [`wgt::BindingType::Texture`] and [`wgt::BindingType::StorageTexture`] with + /// [`BindGroupLayoutEntry::count`] set to None. + TextureView(&'a TextureView), + /// Binding is backed by an array of textures. + /// + /// [`Features::SAMPLED_TEXTURE_BINDING_ARRAY`] must be supported to use this feature. + /// + /// Corresponds to [`wgt::BindingType::Texture`] and [`wgt::BindingType::StorageTexture`] with + /// [`BindGroupLayoutEntry::count`] set to Some. + TextureViewArray(&'a [&'a TextureView]), +} + +/// Describes the segment of a buffer to bind. +#[derive(Clone, Debug)] +pub struct BufferBinding<'a> { + /// The buffer to bind. + pub buffer: &'a Buffer, + /// Base offset of the buffer. For bindings with `dynamic == true`, this offset + /// will be added to the dynamic offset provided in [`RenderPass::set_bind_group`]. + /// + /// The offset has to be aligned to [`BIND_BUFFER_ALIGNMENT`]. + pub offset: BufferAddress, + /// Size of the binding, or `None` for using the rest of the buffer. + pub size: Option, +} + +/// Operation to perform to the output attachment at the start of a renderpass. +/// +/// The render target must be cleared at least once before its content is loaded. +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "trace", derive(serde::Serialize))] +#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +pub enum LoadOp { + /// Clear with a specified value. + Clear(V), + /// Load from memory. + Load, +} + +impl Default for LoadOp { + fn default() -> Self { + Self::Clear(Default::default()) + } +} + +/// Pair of load and store operations for an attachment aspect. +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] +#[cfg_attr(feature = "trace", derive(serde::Serialize))] +#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +pub struct Operations { + /// How data should be read through this attachment. + pub load: LoadOp, + /// Whether data will be written to through this attachment. + pub store: bool, +} + +impl Default for Operations { + fn default() -> Self { + Self { + load: Default::default(), + store: true, + } + } +} + +/// Describes a color attachment to a [`RenderPass`]. +#[derive(Clone, Debug)] +pub struct RenderPassColorAttachment<'a> { + /// The view to use as an attachment. + pub view: &'a TextureView, + /// The view that will receive the resolved output if multisampling is used. + pub resolve_target: Option<&'a TextureView>, + /// What operations will be performed on this color attachment. + pub ops: Operations, +} + +/// Describes a depth/stencil attachment to a [`RenderPass`]. +#[derive(Clone, Debug)] +pub struct RenderPassDepthStencilAttachment<'a> { + /// The view to use as an attachment. + pub view: &'a TextureView, + /// What operations will be performed on the depth part of the attachment. + pub depth_ops: Option>, + /// What operations will be performed on the stencil part of the attachment. + pub stencil_ops: Option>, +} + +// The underlying types are also exported so that documentation shows up for them + +/// Object label. +pub type Label<'a> = Option<&'a str>; +pub use wgt::RequestAdapterOptions as RequestAdapterOptionsBase; +/// Additional information required when requesting an adapter. +pub type RequestAdapterOptions<'a> = RequestAdapterOptionsBase<&'a Surface>; +/// Describes a [`Device`]. +pub type DeviceDescriptor<'a> = wgt::DeviceDescriptor>; +/// Describes a [`Buffer`]. +pub type BufferDescriptor<'a> = wgt::BufferDescriptor>; +/// Describes a [`CommandEncoder`]. +pub type CommandEncoderDescriptor<'a> = wgt::CommandEncoderDescriptor>; +/// Describes a [`RenderBundle`]. +pub type RenderBundleDescriptor<'a> = wgt::RenderBundleDescriptor>; +/// Describes a [`Texture`]. +pub type TextureDescriptor<'a> = wgt::TextureDescriptor>; + +/// Describes a [`TextureView`]. +#[derive(Clone, Debug, Default, PartialEq)] +pub struct TextureViewDescriptor<'a> { + /// Debug label of the texture view. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// Format of the texture view. At this time, it must be the same as the underlying format of the texture. + pub format: Option, + /// The dimension of the texture view. For 1D textures, this must be `1D`. For 2D textures it must be one of + /// `D2`, `D2Array`, `Cube`, and `CubeArray`. For 3D textures it must be `3D` + pub dimension: Option, + /// Aspect of the texture. Color textures must be [`TextureAspect::All`]. + pub aspect: TextureAspect, + /// Base mip level. + pub base_mip_level: u32, + /// Mip level count. + /// If `Some(count)`, `base_mip_level + count` must be less or equal to underlying texture mip count. + /// If `None`, considered to include the rest of the mipmap levels, but at least 1 in total. + pub mip_level_count: Option, + /// Base array layer. + pub base_array_layer: u32, + /// Layer count. + /// If `Some(count)`, `base_array_layer + count` must be less or equal to the underlying array count. + /// If `None`, considered to include the rest of the array layers, but at least 1 in total. + pub array_layer_count: Option, +} + +/// Describes a pipeline layout. +/// +/// A `PipelineLayoutDescriptor` can be used to create a pipeline layout. +#[derive(Clone, Debug, Default)] +pub struct PipelineLayoutDescriptor<'a> { + /// Debug label of the pipeline layout. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// Bind groups that this pipeline uses. The first entry will provide all the bindings for + /// "set = 0", second entry will provide all the bindings for "set = 1" etc. + pub bind_group_layouts: &'a [&'a BindGroupLayout], + /// Set of push constant ranges this pipeline uses. Each shader stage that uses push constants + /// must define the range in push constant memory that corresponds to its single `layout(push_constant)` + /// uniform block. + /// + /// If this array is non-empty, the [`Features::PUSH_CONSTANTS`] must be enabled. + pub push_constant_ranges: &'a [PushConstantRange], +} + +/// Describes a [`Sampler`] +#[derive(Clone, Debug, PartialEq)] +pub struct SamplerDescriptor<'a> { + /// Debug label of the sampler. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// How to deal with out of bounds accesses in the u (i.e. x) direction + pub address_mode_u: AddressMode, + /// How to deal with out of bounds accesses in the v (i.e. y) direction + pub address_mode_v: AddressMode, + /// How to deal with out of bounds accesses in the w (i.e. z) direction + pub address_mode_w: AddressMode, + /// How to filter the texture when it needs to be magnified (made larger) + pub mag_filter: FilterMode, + /// How to filter the texture when it needs to be minified (made smaller) + pub min_filter: FilterMode, + /// How to filter between mip map levels + pub mipmap_filter: FilterMode, + /// Minimum level of detail (i.e. mip level) to use + pub lod_min_clamp: f32, + /// Maximum level of detail (i.e. mip level) to use + pub lod_max_clamp: f32, + /// If this is enabled, this is a comparison sampler using the given comparison function. + pub compare: Option, + /// Valid values: 1, 2, 4, 8, and 16. + pub anisotropy_clamp: Option, + /// Border color to use when address_mode is [`AddressMode::ClampToBorder`] + pub border_color: Option, +} + +impl Default for SamplerDescriptor<'_> { + fn default() -> Self { + Self { + label: None, + address_mode_u: Default::default(), + address_mode_v: Default::default(), + address_mode_w: Default::default(), + mag_filter: Default::default(), + min_filter: Default::default(), + mipmap_filter: Default::default(), + lod_min_clamp: 0.0, + lod_max_clamp: std::f32::MAX, + compare: None, + anisotropy_clamp: None, + border_color: None, + } + } +} + +/// Bindable resource and the slot to bind it to. +#[derive(Clone, Debug)] +pub struct BindGroupEntry<'a> { + /// Slot for which binding provides resource. Corresponds to an entry of the same + /// binding index in the [`BindGroupLayoutDescriptor`]. + pub binding: u32, + /// Resource to attach to the binding + pub resource: BindingResource<'a>, +} + +/// Describes a group of bindings and the resources to be bound. +#[derive(Clone, Debug)] +pub struct BindGroupDescriptor<'a> { + /// Debug label of the bind group. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// The [`BindGroupLayout`] that corresponds to this bind group. + pub layout: &'a BindGroupLayout, + /// The resources to bind to this bind group. + pub entries: &'a [BindGroupEntry<'a>], +} + +/// Describes the attachments of a render pass. +/// +/// Note: separate lifetimes are needed because the texture views +/// have to live as long as the pass is recorded, while everything else doesn't. +#[derive(Clone, Debug, Default)] +pub struct RenderPassDescriptor<'a, 'b> { + /// Debug label of the render pass. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// The color attachments of the render pass. + pub color_attachments: &'b [RenderPassColorAttachment<'a>], + /// The depth and stencil attachment of the render pass, if any. + pub depth_stencil_attachment: Option>, +} + +/// Describes how the vertex buffer is interpreted. +#[derive(Clone, Debug, Hash, Eq, PartialEq)] +pub struct VertexBufferLayout<'a> { + /// The stride, in bytes, between elements of this buffer. + pub array_stride: BufferAddress, + /// How often this vertex buffer is "stepped" forward. + pub step_mode: InputStepMode, + /// The list of attributes which comprise a single vertex. + pub attributes: &'a [VertexAttribute], +} + +/// Describes the vertex process in a render pipeline. +#[derive(Clone, Debug)] +pub struct VertexState<'a> { + /// The compiled shader module for this stage. + pub module: &'a ShaderModule, + /// The name of the entry point in the compiled shader. There must be a function that returns + /// void with this name in the shader. + pub entry_point: &'a str, + /// The format of any vertex buffers used with this pipeline. + pub buffers: &'a [VertexBufferLayout<'a>], +} + +/// Describes the fragment process in a render pipeline. +#[derive(Clone, Debug)] +pub struct FragmentState<'a> { + /// The compiled shader module for this stage. + pub module: &'a ShaderModule, + /// The name of the entry point in the compiled shader. There must be a function that returns + /// void with this name in the shader. + pub entry_point: &'a str, + /// The color state of the render targets. + pub targets: &'a [ColorTargetState], +} + +/// Describes a render (graphics) pipeline. +#[derive(Clone, Debug)] +pub struct RenderPipelineDescriptor<'a> { + /// Debug label of the pipeline. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// The layout of bind groups for this pipeline. + pub layout: Option<&'a PipelineLayout>, + /// The compiled vertex stage, its entry point, and the input buffers layout. + pub vertex: VertexState<'a>, + /// The properties of the pipeline at the primitive assembly and rasterization level. + pub primitive: PrimitiveState, + /// The effect of draw calls on the depth and stencil aspects of the output target, if any. + pub depth_stencil: Option, + /// The multi-sampling properties of the pipeline. + pub multisample: MultisampleState, + /// The compiled fragment stage, its entry point, and the color targets. + pub fragment: Option>, +} + +/// Describes the attachments of a compute pass. +#[derive(Clone, Debug, Default)] +pub struct ComputePassDescriptor<'a> { + /// Debug label of the compute pass. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, +} + +/// Describes a compute pipeline. +#[derive(Clone, Debug)] +pub struct ComputePipelineDescriptor<'a> { + /// Debug label of the pipeline. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// The layout of bind groups for this pipeline. + pub layout: Option<&'a PipelineLayout>, + /// The compiled shader module for this stage. + pub module: &'a ShaderModule, + /// The name of the entry point in the compiled shader. There must be a function that returns + /// void with this name in the shader. + pub entry_point: &'a str, +} + +pub use wgt::ImageCopyBuffer as ImageCopyBufferBase; +/// View of a buffer which can be used to copy to/from a texture. +pub type ImageCopyBuffer<'a> = ImageCopyBufferBase<&'a Buffer>; + +pub use wgt::ImageCopyTexture as ImageCopyTextureBase; +/// View of a texture which can be used to copy to/from a buffer/texture. +pub type ImageCopyTexture<'a> = ImageCopyTextureBase<&'a Texture>; + +/// Describes a [`BindGroupLayout`]. +#[derive(Clone, Debug)] +pub struct BindGroupLayoutDescriptor<'a> { + /// Debug label of the bind group layout. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + + /// Array of entries in this BindGroupLayout + pub entries: &'a [BindGroupLayoutEntry], +} + +/// Describes a [`RenderBundleEncoder`]. +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +pub struct RenderBundleEncoderDescriptor<'a> { + /// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// The formats of the color attachments that this render bundle is capable to rendering to. This + /// must match the formats of the color attachments in the renderpass this render bundle is executed in. + pub color_formats: &'a [TextureFormat], + /// The formats of the depth attachment that this render bundle is capable to rendering to. This + /// must match the formats of the depth attachments in the renderpass this render bundle is executed in. + pub depth_stencil_format: Option, + /// Sample count this render bundle is capable of rendering to. This must match the pipelines and + /// the renderpasses it is used in. + pub sample_count: u32, +} + +/// Swap chain image that can be rendered to. +#[derive(Debug)] +pub struct SwapChainTexture { + /// Accessible view of the frame. + pub view: TextureView, + detail: ::SwapChainOutputDetail, +} + +/// Result of a successful call to [`SwapChain::get_current_frame`]. +#[derive(Debug)] +pub struct SwapChainFrame { + /// The texture into which the next frame should be rendered. + pub output: SwapChainTexture, + /// `true` if the acquired buffer can still be used for rendering, + /// but should be recreated for maximum performance. + pub suboptimal: bool, +} + +/// Result of an unsuccessful call to [`SwapChain::get_current_frame`]. +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum SwapChainError { + /// A timeout was encountered while trying to acquire the next frame. + Timeout, + /// The underlying surface has changed, and therefore the swap chain must be updated. + Outdated, + /// The swap chain has been lost and needs to be recreated. + Lost, + /// There is no more memory left to allocate a new frame. + OutOfMemory, +} + +impl Display for SwapChainError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", match self { + Self::Timeout => "A timeout was encountered while trying to acquire the next frame", + Self::Outdated => "The underlying surface has changed, and therefore the swap chain must be updated", + Self::Lost => "The swap chain has been lost and needs to be recreated", + Self::OutOfMemory => "There is no more memory left to allocate a new frame", + }) + } +} + +impl error::Error for SwapChainError {} + +impl Instance { + /// Create an new instance of wgpu. + /// + /// # Arguments + /// + /// - `backends` - Controls from which [backends][BackendBit] wgpu will choose + /// during instantiation. + pub fn new(backends: BackendBit) -> Self { + Instance { + context: Arc::new(C::init(backends)), + } + } + + /// Retrieves all available [`Adapter`]s that match the given [`BackendBit`]. + /// + /// # Arguments + /// + /// - `backends` - Backends from which to enumerate adapters. + #[cfg(not(target_arch = "wasm32"))] + pub fn enumerate_adapters(&self, backends: BackendBit) -> impl Iterator { + let context = Arc::clone(&self.context); + self.context + .enumerate_adapters(backends) + .into_iter() + .map(move |id| crate::Adapter { + id, + context: Arc::clone(&context), + }) + } + + /// Retrieves an [`Adapter`] which matches the given [`RequestAdapterOptions`]. + /// + /// Some options are "soft", so treated as non-mandatory. Others are "hard". + /// + /// If no adapters are found that suffice all the "hard" options, `None` is returned. + pub fn request_adapter( + &self, + options: &RequestAdapterOptions, + ) -> impl Future> + Send { + let context = Arc::clone(&self.context); + let adapter = self.context.instance_request_adapter(options); + async move { adapter.await.map(|id| Adapter { context, id }) } + } + + /// Creates a surface from a raw window handle. + /// + /// # Safety + /// + /// - Raw Window Handle must be a valid object to create a surface upon. + pub unsafe fn create_surface( + &self, + window: &W, + ) -> Surface { + Surface { + context: Arc::clone(&self.context), + id: Context::instance_create_surface(&*self.context, window), + } + } + + /// Creates a surface from `CoreAnimationLayer`. + /// + /// # Safety + /// + /// - layer must be a valid object to create a surface upon. + #[cfg(any(target_os = "ios", target_os = "macos"))] + pub unsafe fn create_surface_from_core_animation_layer( + &self, + layer: *mut std::ffi::c_void, + ) -> Surface { + self.context.create_surface_from_core_animation_layer(layer) + } + + /// Polls all devices. + /// If `force_wait` is true and this is not running on the web, + /// then this function will block until all in-flight buffers have been mapped. + pub fn poll_all(&self, force_wait: bool) { + self.context.instance_poll_all_devices(force_wait); + } +} + +impl Adapter { + /// Requests a connection to a physical device, creating a logical device. + /// + /// Returns the [`Device`] together with a [`Queue`] that executes command buffers. + /// + /// # Arguments + /// + /// - `desc` - Description of the features and limits requested from the given device. + /// - `trace_path` - Can be used for API call tracing, if that feature is + /// enabled in `wgpu-core`. + /// + /// # Panics + /// + /// - Features specified by `desc` are not supported by this adapter. + /// - Unsafe features were requested but not enabled when requesting the adapter. + /// - Limits requested exceed the values provided by the adapter. + /// - Adapter does not support all features wgpu requires to safely operate. + pub fn request_device( + &self, + desc: &DeviceDescriptor, + trace_path: Option<&std::path::Path>, + ) -> impl Future> + Send { + let context = Arc::clone(&self.context); + let device = Context::adapter_request_device(&*self.context, &self.id, desc, trace_path); + async move { + device.await.map(|(device_id, queue_id)| { + ( + Device { + context: Arc::clone(&context), + id: device_id, + }, + Queue { + context, + id: queue_id, + }, + ) + }) + } + } + + /// Returns an optimal texture format to use for the [`SwapChain`] with this adapter. + /// + /// Returns None if the surface is incompatible with the adapter. + pub fn get_swap_chain_preferred_format(&self, surface: &Surface) -> Option { + Context::adapter_get_swap_chain_preferred_format(&*self.context, &self.id, &surface.id) + } + + /// List all features that are supported with this adapter. + /// + /// Features must be explicitly requested in [`Adapter::request_device`] in order + /// to use them. + pub fn features(&self) -> Features { + Context::adapter_features(&*self.context, &self.id) + } + + /// List the "best" limits that are supported by this adapter. + /// + /// Limits must be explicitly requested in [`Adapter::request_device`] to set + /// the values that you are allowed to use. + pub fn limits(&self) -> Limits { + Context::adapter_limits(&*self.context, &self.id) + } + + /// Get info about the adapter itself. + pub fn get_info(&self) -> AdapterInfo { + Context::adapter_get_info(&*self.context, &self.id) + } + + /// Returns the features supported for a given texture format by this adapter. + /// + /// Note that the WebGPU spec further restricts the available usages/features. + /// To disable these restrictions on a device, request the [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] feature. + pub fn get_texture_format_features( + &self, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures { + Context::adapter_get_texture_format_features(&*self.context, &self.id, format) + } +} + +impl Device { + /// Check for resource cleanups and mapping callbacks. + /// + /// no-op on the web, device is automatically polled. + pub fn poll(&self, maintain: Maintain) { + Context::device_poll(&*self.context, &self.id, maintain); + } + + /// List all features that may be used with this device. + /// + /// Functions may panic if you use unsupported features. + pub fn features(&self) -> Features { + Context::device_features(&*self.context, &self.id) + } + + /// List all limits that were requested of this device. + /// + /// If any of these limits are exceeded, functions may panic. + pub fn limits(&self) -> Limits { + Context::device_limits(&*self.context, &self.id) + } + + /// Creates a shader module from either SPIR-V or WGSL source code. + pub fn create_shader_module(&self, desc: &ShaderModuleDescriptor) -> ShaderModule { + ShaderModule { + context: Arc::clone(&self.context), + id: Context::device_create_shader_module(&*self.context, &self.id, desc), + } + } + + /// Creates an empty [`CommandEncoder`]. + pub fn create_command_encoder(&self, desc: &CommandEncoderDescriptor) -> CommandEncoder { + CommandEncoder { + context: Arc::clone(&self.context), + id: Some(Context::device_create_command_encoder( + &*self.context, + &self.id, + desc, + )), + _p: Default::default(), + } + } + + /// Creates an empty [`RenderBundleEncoder`]. + pub fn create_render_bundle_encoder( + &self, + desc: &RenderBundleEncoderDescriptor, + ) -> RenderBundleEncoder { + RenderBundleEncoder { + context: Arc::clone(&self.context), + id: Context::device_create_render_bundle_encoder(&*self.context, &self.id, desc), + _parent: self, + _p: Default::default(), + } + } + + /// Creates a new [`BindGroup`]. + pub fn create_bind_group(&self, desc: &BindGroupDescriptor) -> BindGroup { + BindGroup { + context: Arc::clone(&self.context), + id: Context::device_create_bind_group(&*self.context, &self.id, desc), + } + } + + /// Creates a [`BindGroupLayout`]. + pub fn create_bind_group_layout(&self, desc: &BindGroupLayoutDescriptor) -> BindGroupLayout { + BindGroupLayout { + context: Arc::clone(&self.context), + id: Context::device_create_bind_group_layout(&*self.context, &self.id, desc), + } + } + + /// Creates a [`PipelineLayout`]. + pub fn create_pipeline_layout(&self, desc: &PipelineLayoutDescriptor) -> PipelineLayout { + PipelineLayout { + context: Arc::clone(&self.context), + id: Context::device_create_pipeline_layout(&*self.context, &self.id, desc), + } + } + + /// Creates a [`RenderPipeline`]. + pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor) -> RenderPipeline { + RenderPipeline { + context: Arc::clone(&self.context), + id: Context::device_create_render_pipeline(&*self.context, &self.id, desc), + } + } + + /// Creates a [`ComputePipeline`]. + pub fn create_compute_pipeline(&self, desc: &ComputePipelineDescriptor) -> ComputePipeline { + ComputePipeline { + context: Arc::clone(&self.context), + id: Context::device_create_compute_pipeline(&*self.context, &self.id, desc), + } + } + + /// Creates a [`Buffer`]. + pub fn create_buffer(&self, desc: &BufferDescriptor) -> Buffer { + let mut map_context = MapContext::new(desc.size); + if desc.mapped_at_creation { + map_context.initial_range = 0..desc.size; + } + Buffer { + context: Arc::clone(&self.context), + id: Context::device_create_buffer(&*self.context, &self.id, desc), + map_context: Mutex::new(map_context), + usage: desc.usage, + } + } + + /// Creates a new [`Texture`]. + /// + /// `desc` specifies the general format of the texture. + pub fn create_texture(&self, desc: &TextureDescriptor) -> Texture { + Texture { + context: Arc::clone(&self.context), + id: Context::device_create_texture(&*self.context, &self.id, desc), + owned: true, + } + } + + /// Creates a new [`Sampler`]. + /// + /// `desc` specifies the behavior of the sampler. + pub fn create_sampler(&self, desc: &SamplerDescriptor) -> Sampler { + Sampler { + context: Arc::clone(&self.context), + id: Context::device_create_sampler(&*self.context, &self.id, desc), + } + } + + /// Creates a new [`QuerySet`]. + pub fn create_query_set(&self, desc: &QuerySetDescriptor) -> QuerySet { + QuerySet { + context: Arc::clone(&self.context), + id: Context::device_create_query_set(&*self.context, &self.id, desc), + } + } + + /// Create a new [`SwapChain`] which targets `surface`. + /// + /// # Panics + /// + /// - A old [`SwapChainFrame`] is still alive referencing an old swapchain. + /// - Texture format requested is unsupported on the swap chain. + pub fn create_swap_chain(&self, surface: &Surface, desc: &SwapChainDescriptor) -> SwapChain { + SwapChain { + context: Arc::clone(&self.context), + id: Context::device_create_swap_chain(&*self.context, &self.id, &surface.id, desc), + } + } + + /// Set a callback for errors that are not handled in error scopes. + pub fn on_uncaptured_error(&self, handler: impl UncapturedErrorHandler) { + self.context.device_on_uncaptured_error(&self.id, handler); + } + + /// Starts frame capture. + pub fn start_capture(&self) { + Context::device_start_capture(&*self.context, &self.id) + } + + /// Stops frame capture. + pub fn stop_capture(&self) { + Context::device_stop_capture(&*self.context, &self.id) + } +} + +impl Drop for Device { + fn drop(&mut self) { + if !thread::panicking() { + self.context.device_drop(&self.id); + } + } +} + +/// Requesting a device failed. +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct RequestDeviceError; + +impl Display for RequestDeviceError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Requesting a device failed") + } +} + +impl error::Error for RequestDeviceError {} + +/// Error occurred when trying to async map a buffer. +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct BufferAsyncError; + +impl Display for BufferAsyncError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Error occurred when trying to async map a buffer") + } +} + +impl error::Error for BufferAsyncError {} + +/// Type of buffer mapping. +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum MapMode { + /// Map only for reading + Read, + /// Map only for writing + Write, +} + +fn range_to_offset_size>( + bounds: S, +) -> (BufferAddress, Option) { + let offset = match bounds.start_bound() { + Bound::Included(&bound) => bound, + Bound::Excluded(&bound) => bound + 1, + Bound::Unbounded => 0, + }; + let size = match bounds.end_bound() { + Bound::Included(&bound) => Some(bound + 1 - offset), + Bound::Excluded(&bound) => Some(bound - offset), + Bound::Unbounded => None, + } + .map(|size| BufferSize::new(size).expect("Buffer slices can not be empty")); + + (offset, size) +} + +#[cfg(test)] +mod tests { + use crate::BufferSize; + + #[test] + fn range_to_offset_size_works() { + assert_eq!(crate::range_to_offset_size(0..2), (0, BufferSize::new(2))); + assert_eq!(crate::range_to_offset_size(2..5), (2, BufferSize::new(3))); + assert_eq!(crate::range_to_offset_size(..), (0, None)); + assert_eq!(crate::range_to_offset_size(21..), (21, None)); + assert_eq!(crate::range_to_offset_size(0..), (0, None)); + assert_eq!(crate::range_to_offset_size(..21), (0, BufferSize::new(21))); + } + + #[test] + #[should_panic] + fn range_to_offset_size_panics_for_empty_range() { + crate::range_to_offset_size(123..123); + } + + #[test] + #[should_panic] + fn range_to_offset_size_panics_for_unbounded_empty_range() { + crate::range_to_offset_size(..0); + } +} + +trait BufferMappedRangeSlice { + fn slice(&self) -> &[u8]; + fn slice_mut(&mut self) -> &mut [u8]; +} + +/// Read only view into a mapped buffer. +#[derive(Debug)] +pub struct BufferView<'a> { + slice: BufferSlice<'a>, + data: BufferMappedRange, +} + +/// Write only view into mapped buffer. +#[derive(Debug)] +pub struct BufferViewMut<'a> { + slice: BufferSlice<'a>, + data: BufferMappedRange, + readable: bool, +} + +impl std::ops::Deref for BufferView<'_> { + type Target = [u8]; + + fn deref(&self) -> &[u8] { + self.data.slice() + } +} + +impl std::ops::Deref for BufferViewMut<'_> { + type Target = [u8]; + + fn deref(&self) -> &[u8] { + assert!( + self.readable, + "Attempting to read a write-only mapping for buffer {:?}", + self.slice.buffer.id + ); + self.data.slice() + } +} + +impl std::ops::DerefMut for BufferViewMut<'_> { + fn deref_mut(&mut self) -> &mut Self::Target { + self.data.slice_mut() + } +} + +impl AsRef<[u8]> for BufferView<'_> { + fn as_ref(&self) -> &[u8] { + self.data.slice() + } +} + +impl AsMut<[u8]> for BufferViewMut<'_> { + fn as_mut(&mut self) -> &mut [u8] { + self.data.slice_mut() + } +} + +impl Drop for BufferView<'_> { + fn drop(&mut self) { + self.slice + .buffer + .map_context + .lock() + .remove(self.slice.offset, self.slice.size); + } +} + +impl Drop for BufferViewMut<'_> { + fn drop(&mut self) { + self.slice + .buffer + .map_context + .lock() + .remove(self.slice.offset, self.slice.size); + } +} + +impl Buffer { + /// Return the binding view of the entire buffer. + pub fn as_entire_binding(&self) -> BindingResource { + BindingResource::Buffer(self.as_entire_buffer_binding()) + } + + /// Return the binding view of the entire buffer. + pub fn as_entire_buffer_binding(&self) -> BufferBinding { + BufferBinding { + buffer: self, + offset: 0, + size: None, + } + } + + /// Use only a portion of this Buffer for a given operation. Choosing a range with no end + /// will use the rest of the buffer. Using a totally unbounded range will use the entire buffer. + pub fn slice>(&self, bounds: S) -> BufferSlice { + let (offset, size) = range_to_offset_size(bounds); + BufferSlice { + buffer: self, + offset, + size, + } + } + + /// Flushes any pending write operations and unmaps the buffer from host memory. + pub fn unmap(&self) { + self.map_context.lock().reset(); + Context::buffer_unmap(&*self.context, &self.id); + } + + /// Destroy the associated native resources as soon as possible. + pub fn destroy(&self) { + Context::buffer_destroy(&*self.context, &self.id); + } +} + +impl<'a> BufferSlice<'a> { + //TODO: fn slice(&self) -> Self + + /// Map the buffer. Buffer is ready to map once the future is resolved. + /// + /// For the future to complete, `device.poll(...)` must be called elsewhere in the runtime, possibly integrated + /// into an event loop, run on a separate thread, or continually polled in the same task runtime that this + /// future will be run on. + /// + /// It's expected that wgpu will eventually supply its own event loop infrastructure that will be easy to integrate + /// into other event loops, like winit's. + pub fn map_async( + &self, + mode: MapMode, + ) -> impl Future> + Send { + let mut mc = self.buffer.map_context.lock(); + assert_eq!( + mc.initial_range, + 0..0, + "Buffer {:?} is already mapped", + self.buffer.id + ); + let end = match self.size { + Some(s) => self.offset + s.get(), + None => mc.total_size, + }; + mc.initial_range = self.offset..end; + + Context::buffer_map_async( + &*self.buffer.context, + &self.buffer.id, + mode, + self.offset..end, + ) + } + + /// Synchronously and immediately map a buffer for reading. If the buffer is not immediately mappable + /// through [`BufferDescriptor::mapped_at_creation`] or [`BufferSlice::map_async`], will panic. + pub fn get_mapped_range(&self) -> BufferView<'a> { + let end = self.buffer.map_context.lock().add(self.offset, self.size); + let data = Context::buffer_get_mapped_range( + &*self.buffer.context, + &self.buffer.id, + self.offset..end, + ); + BufferView { slice: *self, data } + } + + /// Synchronously and immediately map a buffer for writing. If the buffer is not immediately mappable + /// through [`BufferDescriptor::mapped_at_creation`] or [`BufferSlice::map_async`], will panic. + pub fn get_mapped_range_mut(&self) -> BufferViewMut<'a> { + let end = self.buffer.map_context.lock().add(self.offset, self.size); + let data = Context::buffer_get_mapped_range( + &*self.buffer.context, + &self.buffer.id, + self.offset..end, + ); + BufferViewMut { + slice: *self, + data, + readable: self.buffer.usage.contains(BufferUsage::MAP_READ), + } + } +} + +impl Drop for Buffer { + fn drop(&mut self) { + if !thread::panicking() { + self.context.buffer_drop(&self.id); + } + } +} + +impl Texture { + /// Creates a view of this texture. + pub fn create_view(&self, desc: &TextureViewDescriptor) -> TextureView { + TextureView { + context: Arc::clone(&self.context), + id: Context::texture_create_view(&*self.context, &self.id, desc), + owned: true, + } + } + + /// Destroy the associated native resources as soon as possible. + pub fn destroy(&self) { + Context::texture_destroy(&*self.context, &self.id); + } +} + +impl Drop for Texture { + fn drop(&mut self) { + if self.owned && !thread::panicking() { + self.context.texture_drop(&self.id); + } + } +} + +impl Drop for TextureView { + fn drop(&mut self) { + if self.owned && !thread::panicking() { + self.context.texture_view_drop(&self.id); + } + } +} + +impl CommandEncoder { + /// Finishes recording and returns a [`CommandBuffer`] that can be submitted for execution. + pub fn finish(mut self) -> CommandBuffer { + CommandBuffer { + context: Arc::clone(&self.context), + id: Some(Context::command_encoder_finish( + &*self.context, + self.id.take().unwrap(), + )), + } + } + + /// Begins recording of a render pass. + /// + /// This function returns a [`RenderPass`] object which records a single render pass. + pub fn begin_render_pass<'a>( + &'a mut self, + desc: &RenderPassDescriptor<'a, '_>, + ) -> RenderPass<'a> { + let id = self.id.as_ref().unwrap(); + RenderPass { + id: Context::command_encoder_begin_render_pass(&*self.context, id, desc), + parent: self, + } + } + + /// Begins recording of a compute pass. + /// + /// This function returns a [`ComputePass`] object which records a single compute pass. + pub fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor) -> ComputePass { + let id = self.id.as_ref().unwrap(); + ComputePass { + id: Context::command_encoder_begin_compute_pass(&*self.context, id, desc), + parent: self, + } + } + + /// Copy data from one buffer to another. + /// + /// # Panics + /// + /// - Buffer offsets or copy size not a multiple of [`COPY_BUFFER_ALIGNMENT`]. + /// - Copy would overrun buffer. + pub fn copy_buffer_to_buffer( + &mut self, + source: &Buffer, + source_offset: BufferAddress, + destination: &Buffer, + destination_offset: BufferAddress, + copy_size: BufferAddress, + ) { + Context::command_encoder_copy_buffer_to_buffer( + &*self.context, + self.id.as_ref().unwrap(), + &source.id, + source_offset, + &destination.id, + destination_offset, + copy_size, + ); + } + + /// Copy data from a buffer to a texture. + /// + /// # Panics + /// + /// - Copy would overrun buffer. + /// - Copy would overrun texture. + /// - `source.layout.bytes_per_row` isn't divisible by [`COPY_BYTES_PER_ROW_ALIGNMENT`]. + pub fn copy_buffer_to_texture( + &mut self, + source: ImageCopyBuffer, + destination: ImageCopyTexture, + copy_size: Extent3d, + ) { + Context::command_encoder_copy_buffer_to_texture( + &*self.context, + self.id.as_ref().unwrap(), + source, + destination, + copy_size, + ); + } + + /// Copy data from a texture to a buffer. + /// + /// # Panics + /// + /// - Copy would overrun buffer. + /// - Copy would overrun texture. + /// - `source.layout.bytes_per_row` isn't divisible by [`COPY_BYTES_PER_ROW_ALIGNMENT`]. + pub fn copy_texture_to_buffer( + &mut self, + source: ImageCopyTexture, + destination: ImageCopyBuffer, + copy_size: Extent3d, + ) { + Context::command_encoder_copy_texture_to_buffer( + &*self.context, + self.id.as_ref().unwrap(), + source, + destination, + copy_size, + ); + } + + /// Copy data from one texture to another. + /// + /// # Panics + /// + /// - Textures are not the same type + /// - If a depth texture, or a multisampled texture, the entire texture must be copied + /// - Copy would overrun either texture + pub fn copy_texture_to_texture( + &mut self, + source: ImageCopyTexture, + destination: ImageCopyTexture, + copy_size: Extent3d, + ) { + Context::command_encoder_copy_texture_to_texture( + &*self.context, + self.id.as_ref().unwrap(), + source, + destination, + copy_size, + ); + } + + /// Inserts debug marker. + pub fn insert_debug_marker(&mut self, label: &str) { + let id = self.id.as_ref().unwrap(); + Context::command_encoder_insert_debug_marker(&*self.context, id, label); + } + + /// Start record commands and group it into debug marker group. + pub fn push_debug_group(&mut self, label: &str) { + let id = self.id.as_ref().unwrap(); + Context::command_encoder_push_debug_group(&*self.context, id, label); + } + + /// Stops command recording and creates debug group. + pub fn pop_debug_group(&mut self) { + let id = self.id.as_ref().unwrap(); + Context::command_encoder_pop_debug_group(&*self.context, id); + } +} + +/// [`Features::TIMESTAMP_QUERY`] must be enabled on the device in order to call these functions. +impl CommandEncoder { + /// Issue a timestamp command at this point in the queue. + /// The timestamp will be written to the specified query set, at the specified index. + /// + /// Must be multiplied by [`Device::get_timestamp_period`] to get + /// the value in nanoseconds. Absolute values have no meaning, + /// but timestamps can be subtracted to get the time it takes + /// for a string of operations to complete. + pub fn write_timestamp(&mut self, query_set: &QuerySet, query_index: u32) { + Context::command_encoder_write_timestamp( + &*self.context, + self.id.as_ref().unwrap(), + &query_set.id, + query_index, + ) + } +} + +/// [`Features::TIMESTAMP_QUERY`] or [`Features::PIPELINE_STATISTICS_QUERY`] must be enabled on the device in order to call these functions. +impl CommandEncoder { + /// Resolve a query set, writing the results into the supplied destination buffer. + /// + /// Queries may be between 8 and 40 bytes each. See [`PipelineStatisticsType`] for more information. + pub fn resolve_query_set( + &mut self, + query_set: &QuerySet, + query_range: Range, + destination: &Buffer, + destination_offset: BufferAddress, + ) { + Context::command_encoder_resolve_query_set( + &*self.context, + self.id.as_ref().unwrap(), + &query_set.id, + query_range.start, + query_range.end - query_range.start, + &destination.id, + destination_offset, + ) + } +} + +impl<'a> RenderPass<'a> { + /// Sets the active bind group for a given bind group index. The bind group layout + /// in the active pipeline when any `draw()` function is called must match the layout of this bind group. + /// + /// If the bind group have dynamic offsets, provide them in order of their declaration. + /// These offsets have to be aligned to [`BIND_BUFFER_ALIGNMENT`]. + pub fn set_bind_group( + &mut self, + index: u32, + bind_group: &'a BindGroup, + offsets: &[DynamicOffset], + ) { + RenderInner::set_bind_group(&mut self.id, index, &bind_group.id, offsets) + } + + /// Sets the active render pipeline. + /// + /// Subsequent draw calls will exhibit the behavior defined by `pipeline`. + pub fn set_pipeline(&mut self, pipeline: &'a RenderPipeline) { + RenderInner::set_pipeline(&mut self.id, &pipeline.id) + } + + /// Sets the blend color as used by some of the blending modes. + /// + /// Subsequent blending tests will test against this value. + pub fn set_blend_constant(&mut self, color: Color) { + self.id.set_blend_constant(color) + } + + /// Sets the active index buffer. + /// + /// Subsequent calls to [`draw_indexed`](RenderPass::draw_indexed) on this [`RenderPass`] will + /// use `buffer` as the source index buffer. + pub fn set_index_buffer(&mut self, buffer_slice: BufferSlice<'a>, index_format: IndexFormat) { + RenderInner::set_index_buffer( + &mut self.id, + &buffer_slice.buffer.id, + index_format, + buffer_slice.offset, + buffer_slice.size, + ) + } + + /// Assign a vertex buffer to a slot. + /// + /// Subsequent calls to [`draw`] and [`draw_indexed`] on this + /// [`RenderPass`] will use `buffer` as one of the source vertex buffers. + /// + /// The `slot` refers to the index of the matching descriptor in + /// [`VertexStateDescriptor::vertex_buffers`]. + /// + /// [`draw`]: RenderPass::draw + /// [`draw_indexed`]: RenderPass::draw_indexed + pub fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>) { + RenderInner::set_vertex_buffer( + &mut self.id, + slot, + &buffer_slice.buffer.id, + buffer_slice.offset, + buffer_slice.size, + ) + } + + /// Sets the scissor region. + /// + /// Subsequent draw calls will discard any fragments that fall outside this region. + pub fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) { + self.id.set_scissor_rect(x, y, width, height); + } + + /// Sets the viewport region. + /// + /// Subsequent draw calls will draw any fragments in this region. + pub fn set_viewport(&mut self, x: f32, y: f32, w: f32, h: f32, min_depth: f32, max_depth: f32) { + self.id.set_viewport(x, y, w, h, min_depth, max_depth); + } + + /// Sets the stencil reference. + /// + /// Subsequent stencil tests will test against this value. + pub fn set_stencil_reference(&mut self, reference: u32) { + self.id.set_stencil_reference(reference); + } + + /// Draws primitives from the active vertex buffer(s). + /// + /// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + pub fn draw(&mut self, vertices: Range, instances: Range) { + RenderInner::draw(&mut self.id, vertices, instances) + } + + /// Inserts debug marker. + pub fn insert_debug_marker(&mut self, label: &str) { + self.id.insert_debug_marker(label); + } + + /// Start record commands and group it into debug marker group. + pub fn push_debug_group(&mut self, label: &str) { + self.id.push_debug_group(label); + } + + /// Stops command recording and creates debug group. + pub fn pop_debug_group(&mut self) { + self.id.pop_debug_group(); + } + + /// Draws indexed primitives using the active index buffer and the active vertex buffers. + /// + /// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + pub fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + RenderInner::draw_indexed(&mut self.id, indices, base_vertex, instances); + } + + /// Draws primitives from the active vertex buffer(s) based on the contents of the `indirect_buffer`. + /// + /// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_vertex: u32, // The Index of the first vertex to draw. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + pub fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress) { + self.id.draw_indirect(&indirect_buffer.id, indirect_offset); + } + + /// Draws indexed primitives using the active index buffer and the active vertex buffers, + /// based on the contents of the `indirect_buffer`. + /// + /// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndexedIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_index: u32, // The base index within the index buffer. + /// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + pub fn draw_indexed_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + ) { + self.id + .draw_indexed_indirect(&indirect_buffer.id, indirect_offset); + } + + /// Execute a [render bundle][RenderBundle], which is a set of pre-recorded commands + /// that can be run together. + pub fn execute_bundles>(&mut self, render_bundles: I) { + self.id + .execute_bundles(render_bundles.into_iter().map(|rb| &rb.id)) + } +} + +/// [`Features::MULTI_DRAW_INDIRECT`] must be enabled on the device in order to call these functions. +impl<'a> RenderPass<'a> { + /// Dispatches multiple draw calls from the active vertex buffer(s) based on the contents of the `indirect_buffer`. + /// `count` draw calls are issued. + /// + /// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_vertex: u32, // The Index of the first vertex to draw. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + /// + /// These draw structures are expected to be tightly packed. + pub fn multi_draw_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + count: u32, + ) { + self.id + .multi_draw_indirect(&indirect_buffer.id, indirect_offset, count); + } + + /// Dispatches multiple draw calls from the active index buffer and the active vertex buffers, + /// based on the contents of the `indirect_buffer`. `count` draw calls are issued. + /// + /// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndexedIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_index: u32, // The base index within the index buffer. + /// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + /// + /// These draw structures are expected to be tightly packed. + pub fn multi_draw_indexed_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + count: u32, + ) { + self.id + .multi_draw_indexed_indirect(&indirect_buffer.id, indirect_offset, count); + } +} + +/// [`Features::MULTI_DRAW_INDIRECT_COUNT`] must be enabled on the device in order to call these functions. +impl<'a> RenderPass<'a> { + /// Disptaches multiple draw calls from the active vertex buffer(s) based on the contents of the `indirect_buffer`. + /// The count buffer is read to determine how many draws to issue. + /// + /// The indirect buffer must be long enough to account for `max_count` draws, however only `count` will + /// draws will be read. If `count` is greater than `max_count`, `max_count` will be used. + /// + /// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_vertex: u32, // The Index of the first vertex to draw. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + /// + /// These draw structures are expected to be tightly packed. + /// + /// The structure expected in `count_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndirectCount { + /// count: u32, // Number of draw calls to issue. + /// } + /// ``` + pub fn multi_draw_indirect_count( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + count_buffer: &'a Buffer, + count_offset: BufferAddress, + max_count: u32, + ) { + self.id.multi_draw_indirect_count( + &indirect_buffer.id, + indirect_offset, + &count_buffer.id, + count_offset, + max_count, + ); + } + + /// Dispatches multiple draw calls from the active index buffer and the active vertex buffers, + /// based on the contents of the `indirect_buffer`. The count buffer is read to determine how many draws to issue. + /// + /// The indirect buffer must be long enough to account for `max_count` draws, however only `count` will + /// draws will be read. If `count` is greater than `max_count`, `max_count` will be used. + /// + /// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndexedIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_index: u32, // The base index within the index buffer. + /// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + /// + /// These draw structures are expected to be tightly packed. + /// + /// The structure expected in `count_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndexedIndirectCount { + /// count: u32, // Number of draw calls to issue. + /// } + /// ``` + pub fn multi_draw_indexed_indirect_count( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + count_buffer: &'a Buffer, + count_offset: BufferAddress, + max_count: u32, + ) { + self.id.multi_draw_indexed_indirect_count( + &indirect_buffer.id, + indirect_offset, + &count_buffer.id, + count_offset, + max_count, + ); + } +} + +/// [`Features::PUSH_CONSTANTS`] must be enabled on the device in order to call these functions. +impl<'a> RenderPass<'a> { + /// Set push constant data. + /// + /// Offset is measured in bytes, but must be a multiple of [`PUSH_CONSTANT_ALIGNMENT`]. + /// + /// Data size must be a multiple of 4 and must be aligned to the 4s, so we take an array of u32. + /// For example, with an offset of 4 and an array of `[u32; 3]`, that will write to the range + /// of 4..16. + /// + /// For each byte in the range of push constant data written, the union of the stages of all push constant + /// ranges that covers that byte must be exactly `stages`. There's no good way of explaining this simply, + /// so here are some examples: + /// + /// ```text + /// For the given ranges: + /// - 0..4 Vertex + /// - 4..8 Fragment + /// ``` + /// + /// You would need to upload this in two set_push_constants calls. First for the `Vertex` range, second for the `Fragment` range. + /// + /// ```text + /// For the given ranges: + /// - 0..8 Vertex + /// - 4..12 Fragment + /// ``` + /// + /// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second + /// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12. + pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { + self.id.set_push_constants(stages, offset, data); + } +} + +/// [`Features::TIMESTAMP_QUERY`] must be enabled on the device in order to call these functions. +impl<'a> RenderPass<'a> { + /// Issue a timestamp command at this point in the queue. The + /// timestamp will be written to the specified query set, at the specified index. + /// + /// Must be multiplied by [`Device::get_timestamp_period`] to get + /// the value in nanoseconds. Absolute values have no meaning, + /// but timestamps can be subtracted to get the time it takes + /// for a string of operations to complete. + pub fn write_timestamp(&mut self, query_set: &QuerySet, query_index: u32) { + self.id.write_timestamp(&query_set.id, query_index) + } +} + +/// [`Features::PIPELINE_STATISTICS_QUERY`] must be enabled on the device in order to call these functions. +impl<'a> RenderPass<'a> { + /// Start a pipeline statistics query on this render pass. It can be ended with + /// `end_pipeline_statistics_query`. Pipeline statistics queries may not be nested. + pub fn begin_pipeline_statistics_query(&mut self, query_set: &QuerySet, query_index: u32) { + self.id + .begin_pipeline_statistics_query(&query_set.id, query_index); + } + + /// End the pipeline statistics query on this render pass. It can be started with + /// `begin_pipeline_statistics_query`. Pipeline statistics queries may not be nested. + pub fn end_pipeline_statistics_query(&mut self) { + self.id.end_pipeline_statistics_query(); + } +} + +impl<'a> Drop for RenderPass<'a> { + fn drop(&mut self) { + if !thread::panicking() { + let parent_id = self.parent.id.as_ref().unwrap(); + self.parent + .context + .command_encoder_end_render_pass(parent_id, &mut self.id); + } + } +} + +impl<'a> ComputePass<'a> { + /// Sets the active bind group for a given bind group index. The bind group layout + /// in the active pipeline when the `dispatch()` function is called must match the layout of this bind group. + /// + /// If the bind group have dynamic offsets, provide them in order of their declaration. + /// These offsets have to be aligned to [`BIND_BUFFER_ALIGNMENT`]. + pub fn set_bind_group( + &mut self, + index: u32, + bind_group: &'a BindGroup, + offsets: &[DynamicOffset], + ) { + ComputePassInner::set_bind_group(&mut self.id, index, &bind_group.id, offsets); + } + + /// Sets the active compute pipeline. + pub fn set_pipeline(&mut self, pipeline: &'a ComputePipeline) { + ComputePassInner::set_pipeline(&mut self.id, &pipeline.id); + } + + /// Inserts debug marker. + pub fn insert_debug_marker(&mut self, label: &str) { + self.id.insert_debug_marker(label); + } + + /// Start record commands and group it into debug marker group. + pub fn push_debug_group(&mut self, label: &str) { + self.id.push_debug_group(label); + } + + /// Stops command recording and creates debug group. + pub fn pop_debug_group(&mut self) { + self.id.pop_debug_group(); + } + + /// Dispatches compute work operations. + /// + /// `x`, `y` and `z` denote the number of work groups to dispatch in each dimension. + pub fn dispatch(&mut self, x: u32, y: u32, z: u32) { + ComputePassInner::dispatch(&mut self.id, x, y, z); + } + + /// Dispatches compute work operations, based on the contents of the `indirect_buffer`. + pub fn dispatch_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + ) { + ComputePassInner::dispatch_indirect(&mut self.id, &indirect_buffer.id, indirect_offset); + } +} + +/// [`Features::PUSH_CONSTANTS`] must be enabled on the device in order to call these functions. +impl<'a> ComputePass<'a> { + /// Set push constant data. + /// + /// Offset is measured in bytes, but must be a multiple of [`PUSH_CONSTANT_ALIGNMENT`]. + /// + /// Data size must be a multiple of 4 and must be aligned to the 4s, so we take an array of u32. + /// For example, with an offset of 4 and an array of `[u32; 3]`, that will write to the range + /// of 4..16. + pub fn set_push_constants(&mut self, offset: u32, data: &[u8]) { + self.id.set_push_constants(offset, data); + } +} + +/// [`Features::TIMESTAMP_QUERY`] must be enabled on the device in order to call these functions. +impl<'a> ComputePass<'a> { + /// Issue a timestamp command at this point in the queue. The timestamp will be written to the specified query set, at the specified index. + /// + /// Must be multiplied by [`Device::get_timestamp_period`] to get + /// the value in nanoseconds. Absolute values have no meaning, + /// but timestamps can be subtracted to get the time it takes + /// for a string of operations to complete. + pub fn write_timestamp(&mut self, query_set: &QuerySet, query_index: u32) { + self.id.write_timestamp(&query_set.id, query_index) + } +} + +/// [`Features::PIPELINE_STATISTICS_QUERY`] must be enabled on the device in order to call these functions. +impl<'a> ComputePass<'a> { + /// Start a pipeline statistics query on this render pass. It can be ended with + /// `end_pipeline_statistics_query`. Pipeline statistics queries may not be nested. + pub fn begin_pipeline_statistics_query(&mut self, query_set: &QuerySet, query_index: u32) { + self.id + .begin_pipeline_statistics_query(&query_set.id, query_index); + } + + /// End the pipeline statistics query on this render pass. It can be started with + /// `begin_pipeline_statistics_query`. Pipeline statistics queries may not be nested. + pub fn end_pipeline_statistics_query(&mut self) { + self.id.end_pipeline_statistics_query(); + } +} + +impl<'a> Drop for ComputePass<'a> { + fn drop(&mut self) { + if !thread::panicking() { + let parent_id = self.parent.id.as_ref().unwrap(); + self.parent + .context + .command_encoder_end_compute_pass(parent_id, &mut self.id); + } + } +} + +impl<'a> RenderBundleEncoder<'a> { + /// Finishes recording and returns a [`RenderBundle`] that can be executed in other render passes. + pub fn finish(self, desc: &RenderBundleDescriptor) -> RenderBundle { + RenderBundle { + context: Arc::clone(&self.context), + id: Context::render_bundle_encoder_finish(&*self.context, self.id, desc), + } + } + + /// Sets the active bind group for a given bind group index. The bind group layout + /// in the active pipeline when any `draw()` function is called must match the layout of this bind group. + /// + /// If the bind group have dynamic offsets, provide them in order of their declaration. + pub fn set_bind_group( + &mut self, + index: u32, + bind_group: &'a BindGroup, + offsets: &[DynamicOffset], + ) { + RenderInner::set_bind_group(&mut self.id, index, &bind_group.id, offsets) + } + + /// Sets the active render pipeline. + /// + /// Subsequent draw calls will exhibit the behavior defined by `pipeline`. + pub fn set_pipeline(&mut self, pipeline: &'a RenderPipeline) { + RenderInner::set_pipeline(&mut self.id, &pipeline.id) + } + + /// Sets the active index buffer. + /// + /// Subsequent calls to [`draw_indexed`](RenderBundleEncoder::draw_indexed) on this [`RenderBundleEncoder`] will + /// use `buffer` as the source index buffer. + pub fn set_index_buffer(&mut self, buffer_slice: BufferSlice<'a>, index_format: IndexFormat) { + RenderInner::set_index_buffer( + &mut self.id, + &buffer_slice.buffer.id, + index_format, + buffer_slice.offset, + buffer_slice.size, + ) + } + + /// Assign a vertex buffer to a slot. + /// + /// Subsequent calls to [`draw`] and [`draw_indexed`] on this + /// [`RenderBundleEncoder`] will use `buffer` as one of the source vertex buffers. + /// + /// The `slot` refers to the index of the matching descriptor in + /// [`VertexStateDescriptor::vertex_buffers`]. + /// + /// [`draw`]: RenderBundleEncoder::draw + /// [`draw_indexed`]: RenderBundleEncoder::draw_indexed + pub fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>) { + RenderInner::set_vertex_buffer( + &mut self.id, + slot, + &buffer_slice.buffer.id, + buffer_slice.offset, + buffer_slice.size, + ) + } + + /// Draws primitives from the active vertex buffer(s). + /// + /// The active vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + pub fn draw(&mut self, vertices: Range, instances: Range) { + RenderInner::draw(&mut self.id, vertices, instances) + } + + /// Draws indexed primitives using the active index buffer and the active vertex buffers. + /// + /// The active index buffer can be set with [`RenderBundleEncoder::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + pub fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + RenderInner::draw_indexed(&mut self.id, indices, base_vertex, instances); + } + + /// Draws primitives from the active vertex buffer(s) based on the contents of the `indirect_buffer`. + /// + /// The active vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_vertex: u32, // The Index of the first vertex to draw. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + pub fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress) { + self.id.draw_indirect(&indirect_buffer.id, indirect_offset); + } + + /// Draws indexed primitives using the active index buffer and the active vertex buffers, + /// based on the contents of the `indirect_buffer`. + /// + /// The active index buffer can be set with [`RenderBundleEncoder::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndexedIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_index: u32, // The base index within the index buffer. + /// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + pub fn draw_indexed_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + ) { + self.id + .draw_indexed_indirect(&indirect_buffer.id, indirect_offset); + } +} + +/// [`Features::PUSH_CONSTANTS`] must be enabled on the device in order to call these functions. +impl<'a> RenderBundleEncoder<'a> { + /// Set push constant data. + /// + /// Offset is measured in bytes, but must be a multiple of [`PUSH_CONSTANT_ALIGNMENT`]. + /// + /// Data size must be a multiple of 4 and must be aligned to the 4s, so we take an array of u32. + /// For example, with an offset of 4 and an array of `[u32; 3]`, that will write to the range + /// of 4..16. + /// + /// For each byte in the range of push constant data written, the union of the stages of all push constant + /// ranges that covers that byte must be exactly `stages`. There's no good way of explaining this simply, + /// so here are some examples: + /// + /// ```text + /// For the given ranges: + /// - 0..4 Vertex + /// - 4..8 Fragment + /// ``` + /// + /// You would need to upload this in two set_push_constants calls. First for the `Vertex` range, second for the `Fragment` range. + /// + /// ```text + /// For the given ranges: + /// - 0..8 Vertex + /// - 4..12 Fragment + /// ``` + /// + /// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second + /// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12. + pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { + self.id.set_push_constants(stages, offset, data); + } +} + +impl Queue { + /// Schedule a data write into `buffer` starting at `offset`. + /// + /// This method is intended to have low performance costs. + /// As such, the write is not immediately submitted, and instead enqueued + /// internally to happen at the start of the next `submit()` call. + pub fn write_buffer(&self, buffer: &Buffer, offset: BufferAddress, data: &[u8]) { + Context::queue_write_buffer(&*self.context, &self.id, &buffer.id, offset, data) + } + + /// Schedule a data write into `texture`. + /// + /// This method is intended to have low performance costs. + /// As such, the write is not immediately submitted, and instead enqueued + /// internally to happen at the start of the next `submit()` call. + pub fn write_texture( + &self, + texture: ImageCopyTexture, + data: &[u8], + data_layout: ImageDataLayout, + size: Extent3d, + ) { + Context::queue_write_texture(&*self.context, &self.id, texture, data, data_layout, size) + } + + /// Submits a series of finished command buffers for execution. + pub fn submit>(&self, command_buffers: I) { + Context::queue_submit( + &*self.context, + &self.id, + command_buffers + .into_iter() + .map(|mut comb| comb.id.take().unwrap()), + ); + } + + /// Gets the amount of nanoseconds each tick of a timestamp query represents. + /// + /// Returns zero if timestamp queries are unsupported. + pub fn get_timestamp_period(&self) -> f32 { + Context::queue_get_timestamp_period(&*self.context, &self.id) + } +} + +impl Drop for SwapChainTexture { + fn drop(&mut self) { + if !thread::panicking() { + Context::swap_chain_present(&*self.view.context, &self.view.id, &self.detail); + } + } +} + +impl SwapChain { + /// Returns the next texture to be presented by the swapchain for drawing. + /// + /// When the [`SwapChainFrame`] returned by this method is dropped, the swapchain will present + /// the texture to the associated [`Surface`]. + /// + /// If a SwapChainFrame referencing this surface is alive when the swapchain is recreated, + /// recreating the swapchain will panic. + pub fn get_current_frame(&self) -> Result { + let (view_id, status, detail) = + Context::swap_chain_get_current_texture_view(&*self.context, &self.id); + let output = view_id.map(|id| SwapChainTexture { + view: TextureView { + context: Arc::clone(&self.context), + id, + owned: false, + }, + detail, + }); + + match status { + SwapChainStatus::Good => Ok(SwapChainFrame { + output: output.unwrap(), + suboptimal: false, + }), + SwapChainStatus::Suboptimal => Ok(SwapChainFrame { + output: output.unwrap(), + suboptimal: true, + }), + SwapChainStatus::Timeout => Err(SwapChainError::Timeout), + SwapChainStatus::Outdated => Err(SwapChainError::Outdated), + SwapChainStatus::Lost => Err(SwapChainError::Lost), + } + } +} + +/// Type for the callback of uncaptured error handler +pub trait UncapturedErrorHandler: Fn(Error) + Send + 'static {} +impl UncapturedErrorHandler for T where T: Fn(Error) + Send + 'static {} + +/// Error type +#[derive(Debug)] +pub enum Error { + /// Out of memory error + OutOfMemoryError { + /// + source: Box, + }, + /// Validation error, signifying a bug in code or data + ValidationError { + /// + source: Box, + /// + description: String, + }, +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + match self { + Error::OutOfMemoryError { source } => Some(source.as_ref()), + Error::ValidationError { source, .. } => Some(source.as_ref()), + } + } +} + +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::OutOfMemoryError { .. } => f.write_str("Out of Memory"), + Error::ValidationError { description, .. } => f.write_str(description), + } + } +} diff --git a/wgpu/src/macros.rs b/wgpu/src/macros.rs new file mode 100644 index 000000000..a616ee795 --- /dev/null +++ b/wgpu/src/macros.rs @@ -0,0 +1,74 @@ +//! Convenience macros + +/// Macro to produce an array of [VertexAttribute](crate::VertexAttribute). +/// +/// Output has type: `[VertexAttribute; _]`. Usage is as follows: +/// ``` +/// # use wgpu::vertex_attr_array; +/// let attrs = vertex_attr_array![0 => Float32x2, 1 => Float32, 2 => Uint16x4]; +/// ``` +/// This example specifies a list of three [VertexAttribute](crate::VertexAttribute), +/// each with the given `shader_location` and `format`. +/// Offsets are calculated automatically. +#[macro_export] +macro_rules! vertex_attr_array { + ($($loc:expr => $fmt:ident),* $(,)?) => { + $crate::vertex_attr_array!([] ; 0; $($loc => $fmt ,)*) + }; + ([$($t:expr,)*] ; $off:expr ;) => { [$($t,)*] }; + ([$($t:expr,)*] ; $off:expr ; $loc:expr => $item:ident, $($ll:expr => $ii:ident ,)*) => { + $crate::vertex_attr_array!( + [$($t,)* + $crate::VertexAttribute { + format: $crate::VertexFormat :: $item, + offset: $off, + shader_location: $loc, + },]; + $off + $crate::VertexFormat :: $item.size(); + $($ll => $ii ,)* + ) + }; +} + +#[test] +fn test_vertex_attr_array() { + let attrs = vertex_attr_array![0 => Float32x2, 3 => Uint16x4]; + // VertexAttribute does not support PartialEq, so we cannot test directly + assert_eq!(attrs.len(), 2); + assert_eq!(attrs[0].offset, 0); + assert_eq!(attrs[0].shader_location, 0); + assert_eq!(attrs[1].offset, std::mem::size_of::<(f32, f32)>() as u64); + assert_eq!(attrs[1].shader_location, 3); +} + +/// Macro to load a SPIR-V module statically. +/// +/// It ensures the word alignment as well as the magic number. +#[macro_export] +macro_rules! include_spirv { + ($($token:tt)*) => { + { + //log::info!("including '{}'", $($token)*); + $crate::ShaderModuleDescriptor { + label: Some($($token)*), + source: $crate::util::make_spirv(include_bytes!($($token)*)), + flags: $crate::ShaderFlags::VALIDATION, + } + } + }; +} + +/// Macro to load a WGSL module statically. +#[macro_export] +macro_rules! include_wgsl { + ($($token:tt)*) => { + { + //log::info!("including '{}'", $($token)*); + $crate::ShaderModuleDescriptor { + label: Some($($token)*), + source: $crate::ShaderSource::Wgsl(include_str!($($token)*).into()), + flags: $crate::ShaderFlags::all(), + } + } + }; +} diff --git a/wgpu/src/util/belt.rs b/wgpu/src/util/belt.rs new file mode 100644 index 000000000..d787159e7 --- /dev/null +++ b/wgpu/src/util/belt.rs @@ -0,0 +1,184 @@ +use crate::{ + Buffer, BufferAddress, BufferDescriptor, BufferSize, BufferUsage, BufferViewMut, + CommandEncoder, Device, MapMode, +}; +use std::pin::Pin; +use std::task::{self, Poll}; +use std::{future::Future, sync::mpsc}; + +// Given a vector of futures, poll each in parallel until all are ready. +struct Join { + futures: Vec>, +} + +impl> Future for Join { + type Output = (); + + fn poll(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll { + // This is safe because we have no Drop implementation to violate the Pin requirements and + // do not provide any means of moving the inner futures. + let all_ready = unsafe { + // Poll all remaining futures, removing all that are ready + self.get_unchecked_mut().futures.iter_mut().all(|opt| { + if let Some(future) = opt { + if Pin::new_unchecked(future).poll(cx) == Poll::Ready(()) { + *opt = None; + } + } + + opt.is_none() + }) + }; + + if all_ready { + Poll::Ready(()) + } else { + Poll::Pending + } + } +} + +struct Chunk { + buffer: Buffer, + size: BufferAddress, + offset: BufferAddress, +} + +/// Staging belt is a machine that uploads data. +/// +/// Internally it uses a ring-buffer of staging buffers that are sub-allocated. +/// It has an advantage over `Queue.write_buffer` in a way that it returns a mutable slice, +/// which you can fill to avoid an extra data copy. +/// +/// Using a staging belt is slightly complicated, and generally goes as follows: +/// - Write to buffers that need writing to using `write_buffer`. +/// - Call `finish`. +/// - Submit all command encoders used with `write_buffer`. +/// - Call `recall` +pub struct StagingBelt { + chunk_size: BufferAddress, + /// Chunks that we are actively using for pending transfers at this moment. + active_chunks: Vec, + /// Chunks that have scheduled transfers already. + closed_chunks: Vec, + /// Chunks that are back from the GPU and ready to be used. + free_chunks: Vec, + sender: mpsc::Sender, + receiver: mpsc::Receiver, +} + +impl StagingBelt { + /// Create a new staging belt. + /// + /// The `chunk_size` is the unit of internal buffer allocation. + /// It's better when it's big, but ideally still 1-4 times less than + /// the total amount of data uploaded per submission. + pub fn new(chunk_size: BufferAddress) -> Self { + let (sender, receiver) = mpsc::channel(); + StagingBelt { + chunk_size, + active_chunks: Vec::new(), + closed_chunks: Vec::new(), + free_chunks: Vec::new(), + sender, + receiver, + } + } + + /// Allocate the staging belt slice of `size` to be uploaded into the `target` buffer + /// at the specified offset. + /// + /// The upload will be placed into the provided command encoder. This encoder + /// must be submitted after `finish` is called and before `recall` is called. + pub fn write_buffer( + &mut self, + encoder: &mut CommandEncoder, + target: &Buffer, + offset: BufferAddress, + size: BufferSize, + device: &Device, + ) -> BufferViewMut { + let mut chunk = if let Some(index) = self + .active_chunks + .iter() + .position(|chunk| chunk.offset + size.get() <= chunk.size) + { + self.active_chunks.swap_remove(index) + } else if let Some(index) = self + .free_chunks + .iter() + .position(|chunk| size.get() <= chunk.size) + { + self.free_chunks.swap_remove(index) + } else { + let size = self.chunk_size.max(size.get()); + Chunk { + buffer: device.create_buffer(&BufferDescriptor { + label: Some("staging"), + size, + usage: BufferUsage::MAP_WRITE | BufferUsage::COPY_SRC, + mapped_at_creation: true, + }), + size, + offset: 0, + } + }; + + encoder.copy_buffer_to_buffer(&chunk.buffer, chunk.offset, target, offset, size.get()); + let old_offset = chunk.offset; + chunk.offset += size.get(); + let remainder = chunk.offset % crate::MAP_ALIGNMENT; + if remainder != 0 { + chunk.offset += crate::MAP_ALIGNMENT - remainder; + } + + self.active_chunks.push(chunk); + self.active_chunks + .last() + .unwrap() + .buffer + .slice(old_offset..old_offset + size.get()) + .get_mapped_range_mut() + } + + /// Prepare currently mapped buffers for use in a submission. + /// + /// At this point, all the partially used staging buffers are closed until + /// the GPU is done copying the data from them. + pub fn finish(&mut self) { + for chunk in self.active_chunks.drain(..) { + chunk.buffer.unmap(); + self.closed_chunks.push(chunk); + } + } + + /// Recall all of the closed buffers back to be reused. + /// + /// This has to be called after the command encoders written to `write_buffer` are submitted! + pub fn recall(&mut self) -> impl Future + Send { + while let Ok(mut chunk) = self.receiver.try_recv() { + chunk.offset = 0; + self.free_chunks.push(chunk); + } + + let sender = &self.sender; + let futures = self + .closed_chunks + .drain(..) + .map(|chunk| { + let sender = sender.clone(); + let async_buffer = chunk.buffer.slice(..).map_async(MapMode::Write); + + Some(async move { + // The result is ignored + async_buffer.await.ok(); + + // The only possible error is the other side disconnecting, which is fine + let _ = sender.send(chunk); + }) + }) + .collect::>(); + + Join { futures } + } +} diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs new file mode 100644 index 000000000..605c512cb --- /dev/null +++ b/wgpu/src/util/device.rs @@ -0,0 +1,150 @@ +use std::{convert::TryFrom, num::NonZeroU32}; + +/// Describes a [Buffer](crate::Buffer) when allocating. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct BufferInitDescriptor<'a> { + /// Debug label of a buffer. This will show up in graphics debuggers for easy identification. + pub label: crate::Label<'a>, + /// Contents of a buffer on creation. + pub contents: &'a [u8], + /// Usages of a buffer. If the buffer is used in any way that isn't specified here, the operation + /// will panic. + pub usage: crate::BufferUsage, +} + +/// Utility methods not meant to be in the main API. +pub trait DeviceExt { + /// Creates a [Buffer](crate::Buffer) with data to initialize it. + fn create_buffer_init(&self, desc: &BufferInitDescriptor) -> crate::Buffer; + + /// Upload an entire texture and its mipmaps from a source buffer. + /// + /// Expects all mipmaps to be tightly packed in the data buffer. + /// + /// If the texture is a 2DArray texture, uploads each layer in order, expecting + /// each layer and its mips to be tightly packed. + /// + /// Example: + /// Layer0Mip0 Layer0Mip1 Layer0Mip2 ... Layer1Mip0 Layer1Mip1 Layer1Mip2 ... + fn create_texture_with_data( + &self, + queue: &crate::Queue, + desc: &crate::TextureDescriptor, + data: &[u8], + ) -> crate::Texture; +} + +impl DeviceExt for crate::Device { + fn create_buffer_init(&self, descriptor: &BufferInitDescriptor<'_>) -> crate::Buffer { + // Skip mapping if the buffer is zero sized + if descriptor.contents.is_empty() { + let wgt_descriptor = crate::BufferDescriptor { + label: descriptor.label, + size: 0, + usage: descriptor.usage, + mapped_at_creation: false, + }; + + self.create_buffer(&wgt_descriptor) + } else { + let unpadded_size = descriptor.contents.len() as crate::BufferAddress; + // Valid vulkan usage is + // 1. buffer size must be a multiple of COPY_BUFFER_ALIGNMENT. + // 2. buffer size must be greater than 0. + // Therefore we round the value up to the nearest multiple, and ensure it's at least COPY_BUFFER_ALIGNMENT. + let align_mask = crate::COPY_BUFFER_ALIGNMENT - 1; + let padded_size = + ((unpadded_size + align_mask) & !align_mask).max(crate::COPY_BUFFER_ALIGNMENT); + + let wgt_descriptor = crate::BufferDescriptor { + label: descriptor.label, + size: padded_size, + usage: descriptor.usage, + mapped_at_creation: true, + }; + + let buffer = self.create_buffer(&wgt_descriptor); + + buffer.slice(..).get_mapped_range_mut()[..unpadded_size as usize] + .copy_from_slice(descriptor.contents); + buffer.unmap(); + + buffer + } + } + + fn create_texture_with_data( + &self, + queue: &crate::Queue, + desc: &crate::TextureDescriptor, + data: &[u8], + ) -> crate::Texture { + let texture = self.create_texture(desc); + + let format_info = desc.format.describe(); + + let (layer_iterations, mip_extent) = if desc.dimension == crate::TextureDimension::D3 { + (1, desc.size) + } else { + ( + desc.size.depth_or_array_layers, + crate::Extent3d { + depth_or_array_layers: 1, + ..desc.size + }, + ) + }; + + let mip_level_count = + u8::try_from(desc.mip_level_count).expect("mip level count overflows a u8"); + + let mut binary_offset = 0; + for layer in 0..layer_iterations { + for mip in 0..mip_level_count { + let mip_size = mip_extent.at_mip_level(mip).unwrap(); + + // When uploading mips of compressed textures and the mip is supposed to be + // a size that isn't a multiple of the block size, the mip needs to be uploaded + // as its "physical size" which is the size rounded up to the nearest block size. + let mip_physical = mip_size.physical_size(desc.format); + + // All these calculations are performed on the physical size as that's the + // data that exists in the buffer. + let width_blocks = mip_physical.width / format_info.block_dimensions.0 as u32; + let height_blocks = mip_physical.height / format_info.block_dimensions.1 as u32; + + let bytes_per_row = width_blocks * format_info.block_size as u32; + let data_size = bytes_per_row * height_blocks * mip_extent.depth_or_array_layers; + + let end_offset = binary_offset + data_size as usize; + + queue.write_texture( + crate::ImageCopyTexture { + texture: &texture, + mip_level: mip as u32, + origin: crate::Origin3d { + x: 0, + y: 0, + z: layer, + }, + }, + &data[binary_offset..end_offset], + crate::ImageDataLayout { + offset: 0, + bytes_per_row: Some( + NonZeroU32::new(bytes_per_row).expect("invalid bytes per row"), + ), + rows_per_image: Some( + NonZeroU32::new(mip_physical.height).expect("invalid height"), + ), + }, + mip_physical, + ); + + binary_offset = end_offset; + } + } + + texture + } +} diff --git a/wgpu/src/util/encoder.rs b/wgpu/src/util/encoder.rs new file mode 100644 index 000000000..bc79260fa --- /dev/null +++ b/wgpu/src/util/encoder.rs @@ -0,0 +1,223 @@ +use std::ops::Range; + +use wgt::{BufferAddress, DynamicOffset, IndexFormat}; + +use crate::{BindGroup, Buffer, BufferSlice, RenderBundleEncoder, RenderPass, RenderPipeline}; + +/// Methods shared by `RenderPass` and `RenderBundleEncoder` +pub trait RenderEncoder<'a> { + /// Sets the active bind group for a given bind group index. The bind group layout + /// in the active pipeline when any `draw()` function is called must match the layout of this bind group. + /// + /// If the bind group have dynamic offsets, provide them in order of their declaration. + fn set_bind_group(&mut self, index: u32, bind_group: &'a BindGroup, offsets: &[DynamicOffset]); + + /// Sets the active render pipeline. + /// + /// Subsequent draw calls will exhibit the behavior defined by `pipeline`. + fn set_pipeline(&mut self, pipeline: &'a RenderPipeline); + + /// Sets the active index buffer. + /// + /// Subsequent calls to [`draw_indexed`](RenderBundleEncoder::draw_indexed) on this [`RenderBundleEncoder`] will + /// use `buffer` as the source index buffer. + fn set_index_buffer(&mut self, buffer_slice: BufferSlice<'a>, index_format: IndexFormat); + + /// Assign a vertex buffer to a slot. + /// + /// Subsequent calls to [`draw`] and [`draw_indexed`] on this + /// [`RenderBundleEncoder`] will use `buffer` as one of the source vertex buffers. + /// + /// The `slot` refers to the index of the matching descriptor in + /// [VertexStateDescriptor::vertex_buffers](crate::VertexStateDescriptor::vertex_buffers). + /// + /// [`draw`]: RenderBundleEncoder::draw + /// [`draw_indexed`]: RenderBundleEncoder::draw_indexed + fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>); + + /// Draws primitives from the active vertex buffer(s). + /// + /// The active vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + fn draw(&mut self, vertices: Range, instances: Range); + + /// Draws indexed primitives using the active index buffer and the active vertex buffers. + /// + /// The active index buffer can be set with [`RenderBundleEncoder::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range); + + /// Draws primitives from the active vertex buffer(s) based on the contents of the `indirect_buffer`. + /// + /// The active vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_vertex: u32, // The Index of the first vertex to draw. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress); + + /// Draws indexed primitives using the active index buffer and the active vertex buffers, + /// based on the contents of the `indirect_buffer`. + /// + /// The active index buffer can be set with [`RenderBundleEncoder::set_index_buffer`], while the active + /// vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`]. + /// + /// The structure expected in `indirect_buffer` is the following: + /// + /// ```rust + /// #[repr(C)] + /// struct DrawIndexedIndirect { + /// vertex_count: u32, // The number of vertices to draw. + /// instance_count: u32, // The number of instances to draw. + /// base_index: u32, // The base index within the index buffer. + /// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer. + /// base_instance: u32, // The instance ID of the first instance to draw. + /// } + /// ``` + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + ); + + /// [`wgt::Features::PUSH_CONSTANTS`] must be enabled on the device in order to call this function. + /// + /// Set push constant data. + /// + /// Offset is measured in bytes, but must be a multiple of [`wgt::PUSH_CONSTANT_ALIGNMENT`]. + /// + /// Data size must be a multiple of 4 and must be aligned to the 4s, so we take an array of u32. + /// For example, with an offset of 4 and an array of `[u32; 3]`, that will write to the range + /// of 4..16. + /// + /// For each byte in the range of push constant data written, the union of the stages of all push constant + /// ranges that covers that byte must be exactly `stages`. There's no good way of explaining this simply, + /// so here are some examples: + /// + /// ```text + /// For the given ranges: + /// - 0..4 Vertex + /// - 4..8 Fragment + /// ``` + /// + /// You would need to upload this in two set_push_constants calls. First for the `Vertex` range, second for the `Fragment` range. + /// + /// ```text + /// For the given ranges: + /// - 0..8 Vertex + /// - 4..12 Fragment + /// ``` + /// + /// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second + /// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12. + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]); +} + +impl<'a> RenderEncoder<'a> for RenderPass<'a> { + #[inline(always)] + fn set_bind_group(&mut self, index: u32, bind_group: &'a BindGroup, offsets: &[DynamicOffset]) { + Self::set_bind_group(self, index, bind_group, offsets); + } + + #[inline(always)] + fn set_pipeline(&mut self, pipeline: &'a RenderPipeline) { + Self::set_pipeline(self, pipeline); + } + + #[inline(always)] + fn set_index_buffer(&mut self, buffer_slice: BufferSlice<'a>, index_format: IndexFormat) { + Self::set_index_buffer(self, buffer_slice, index_format); + } + + #[inline(always)] + fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>) { + Self::set_vertex_buffer(self, slot, buffer_slice); + } + + #[inline(always)] + fn draw(&mut self, vertices: Range, instances: Range) { + Self::draw(self, vertices, instances); + } + + #[inline(always)] + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + Self::draw_indexed(self, indices, base_vertex, instances); + } + + #[inline(always)] + fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress) { + Self::draw_indirect(self, indirect_buffer, indirect_offset); + } + + #[inline(always)] + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + ) { + Self::draw_indexed_indirect(self, indirect_buffer, indirect_offset); + } + + #[inline(always)] + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { + Self::set_push_constants(self, stages, offset, data); + } +} + +impl<'a> RenderEncoder<'a> for RenderBundleEncoder<'a> { + #[inline(always)] + fn set_bind_group(&mut self, index: u32, bind_group: &'a BindGroup, offsets: &[DynamicOffset]) { + Self::set_bind_group(self, index, bind_group, offsets); + } + + #[inline(always)] + fn set_pipeline(&mut self, pipeline: &'a RenderPipeline) { + Self::set_pipeline(self, pipeline); + } + + #[inline(always)] + fn set_index_buffer(&mut self, buffer_slice: BufferSlice<'a>, index_format: IndexFormat) { + Self::set_index_buffer(self, buffer_slice, index_format); + } + + #[inline(always)] + fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>) { + Self::set_vertex_buffer(self, slot, buffer_slice); + } + + #[inline(always)] + fn draw(&mut self, vertices: Range, instances: Range) { + Self::draw(self, vertices, instances); + } + + #[inline(always)] + fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { + Self::draw_indexed(self, indices, base_vertex, instances); + } + + #[inline(always)] + fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress) { + Self::draw_indirect(self, indirect_buffer, indirect_offset); + } + + #[inline(always)] + fn draw_indexed_indirect( + &mut self, + indirect_buffer: &'a Buffer, + indirect_offset: BufferAddress, + ) { + Self::draw_indexed_indirect(self, indirect_buffer, indirect_offset); + } + + #[inline(always)] + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { + Self::set_push_constants(self, stages, offset, data); + } +} diff --git a/wgpu/src/util/mod.rs b/wgpu/src/util/mod.rs new file mode 100644 index 000000000..374a7efe3 --- /dev/null +++ b/wgpu/src/util/mod.rs @@ -0,0 +1,102 @@ +//! Utility structures and functions. + +mod belt; +mod device; +mod encoder; + +use std::{ + borrow::Cow, + future::Future, + mem::{align_of, size_of}, + ptr::copy_nonoverlapping, +}; + +pub use belt::StagingBelt; +pub use device::{BufferInitDescriptor, DeviceExt}; +pub use encoder::RenderEncoder; + +/// Treat the given byte slice as a SPIR-V module. +/// +/// # Panic +/// +/// This function panics if: +/// +/// - Input length isn't multiple of 4 +/// - Input is longer than [`usize::max_value`] +/// - SPIR-V magic number is missing from beginning of stream +pub fn make_spirv(data: &[u8]) -> super::ShaderSource { + const MAGIC_NUMBER: u32 = 0x0723_0203; + + assert_eq!( + data.len() % size_of::(), + 0, + "data size is not a multiple of 4" + ); + + //If the data happens to be aligned, directly use the byte array, + // otherwise copy the byte array in an owned vector and use that instead. + let words = if data.as_ptr().align_offset(align_of::()) == 0 { + let (pre, words, post) = unsafe { data.align_to::() }; + debug_assert!(pre.is_empty()); + debug_assert!(post.is_empty()); + Cow::from(words) + } else { + let mut words = vec![0u32; data.len() / size_of::()]; + unsafe { + copy_nonoverlapping(data.as_ptr(), words.as_mut_ptr() as *mut u8, data.len()); + } + Cow::from(words) + }; + + assert_eq!( + words[0], MAGIC_NUMBER, + "wrong magic word {:x}. Make sure you are using a binary SPIRV file.", + words[0] + ); + super::ShaderSource::SpirV(words) +} + +/// CPU accessible buffer used to download data back from the GPU. +pub struct DownloadBuffer(super::Buffer, super::BufferMappedRange); + +impl DownloadBuffer { + /// Asynchronously read the contents of a buffer. + pub fn read_buffer( + device: &super::Device, + queue: &super::Queue, + buffer: &super::BufferSlice, + ) -> impl Future> + Send { + let size = match buffer.size { + Some(size) => size.into(), + None => buffer.buffer.map_context.lock().total_size - buffer.offset, + }; + + let download = device.create_buffer(&super::BufferDescriptor { + size, + usage: super::BufferUsage::COPY_DST | super::BufferUsage::MAP_READ, + mapped_at_creation: false, + label: None, + }); + + let mut encoder = + device.create_command_encoder(&super::CommandEncoderDescriptor { label: None }); + encoder.copy_buffer_to_buffer(buffer.buffer, buffer.offset, &download, 0, size); + let command_buffer: super::CommandBuffer = encoder.finish(); + queue.submit(Some(command_buffer)); + + let fut = download.slice(..).map_async(super::MapMode::Read); + async move { + fut.await?; + let mapped_range = + super::Context::buffer_get_mapped_range(&*download.context, &download.id, 0..size); + Ok(Self(download, mapped_range)) + } + } +} + +impl std::ops::Deref for DownloadBuffer { + type Target = [u8]; + fn deref(&self) -> &[u8] { + super::BufferMappedRangeSlice::slice(&self.1) + } +} diff --git a/wgpu/tests/example-wgsl.rs b/wgpu/tests/example-wgsl.rs new file mode 100644 index 000000000..481eeb919 --- /dev/null +++ b/wgpu/tests/example-wgsl.rs @@ -0,0 +1,52 @@ +use naga::{front::wgsl, valid::Validator}; +use std::{fs, path::PathBuf}; + +#[test] +fn parse_example_wgsl() { + let read_dir = match PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("examples") + .read_dir() + { + Ok(iter) => iter, + Err(e) => { + log::error!("Unable to open the examples folder: {:?}", e); + return; + } + }; + for example_entry in read_dir { + let read_files = match example_entry { + Ok(dir_entry) => match dir_entry.path().read_dir() { + Ok(iter) => iter, + Err(_) => continue, + }, + Err(e) => { + log::warn!("Skipping example: {:?}", e); + continue; + } + }; + for file_entry in read_files { + let shader = match file_entry { + Ok(entry) => match entry.path().extension() { + Some(ostr) if &*ostr == "wgsl" => { + println!("Validating {:?}", entry.path()); + fs::read_to_string(entry.path()).unwrap_or_default() + } + _ => continue, + }, + Err(e) => { + log::warn!("Skipping file: {:?}", e); + continue; + } + }; + + let module = wgsl::parse_str(&shader).unwrap(); + //TODO: re-use the validator + Validator::new( + naga::valid::ValidationFlags::all(), + naga::valid::Capabilities::all(), + ) + .validate(&module) + .unwrap(); + } + } +}