Skip to content

Project 6: TRUNG LE #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include_directories(external)
include_directories(external/glm)
include_directories(external/gli)
include_directories(base)
include_directories(vulkanBoids)


OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)

Expand Down
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,43 @@ Vulkan Flocking: compute and shading in one pipeline!

**University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 6**

* (TODO) YOUR NAME HERE
Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* Trung Le
* Windows 10 Home, i7-4790 CPU @ 3.60GHz 12GB, GTX 980 Ti (Personal desktop)

### (TODO: Your README)
![](images/vulkan_duck_flock.gif)

Include screenshots, analysis, etc. (Remember, this is public, so don't put
anything here that you don't want to share with the world.)
**THERE SHALL BE DUCKS!**

### Features

_`#define DRAW_POINTS` is used to toggle between drawing just points or drawing the duck's mesh_

On top of the naive flocking, I implemented gtTF mesh loading using tinygltfloader and enabled instancing to draw the duckies. This required some code restructuring to support mesh and instancing. Since Vulkan allows for compute and graphics to share data, I simply just used storageBufferB data as the instancing attribute for the mesh's center. Enjoy!

### Analysis

![](images/vulkan_flock.gif)


- Why do you think Vulkan expects explicit descriptors for things like generating pipelines and commands? HINT: this may relate to something in the comments about some components using pre-allocated GPU memory.

The descriptor layout uses a register array with pre-allocated GPU memory. By being able to specify explicit descriptors, developers can assign descriptor sets binding more effeciently, instead of relying on the driver (as in OpenGL), to copy this register array over everytime one of the binding changes, reducing less overheading in resource binding.

- Describe a situation besides flip-flop buffers in which you may need multiple descriptor sets to fit one descriptor layout.

Swaping textures. Let's say we have a lists of textures for a specific mesh, this list can be bound to a list of descriptor sets in a descriptor layout. When the mesh needs to update its texture, the descriptor set can be swapped to so that the shader can read from a new texture.

- What are some problems to keep in mind when using multiple Vulkan queues?
- take into consideration that different queues may be backed by different hardware
- take into consideration that the same buffer may be used across multiple queues

Since Vulkan only has one graphics queue (graphics queue queue can perform compute function also, but it doesn't have to) but multiple compute queue, we should strategize the workload so that most of the computation can be carried out in the compute queue. Also, since a buffer might be potentially accessed from different queues in parallel, extra caution needs to be done to guard against this. Adding resource access masks (load, store op) and `VkSemaphore` can help prevent this read/write concurrency problem.

- What is one advantage of using compute commands that can share data with a rendering pipeline?

By using compute commands that can share data with the rendering pipeline, we can avoid unncessary memory transfer from device and host. In a CUDA pipeline, the compute data needs to be copied to host, then copied back into the graphics pipeline. This overhead can now be eliminated with Vulkan.

### Credits

* [Vulkan examples and demos](https://github.com/SaschaWillems/Vulkan) by [@SaschaWillems](https://github.com/SaschaWillems)
* [tinygltfloader](https://github.com/syoyo/tinygltfloader) by [@soyoyo](https://github.com/syoyo)
3 changes: 3 additions & 0 deletions base/vulkanexamplebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatur
// Android Vulkan initialization is handled in APP_CMD_INIT_WINDOW event
initVulkan(enableValidation);
#endif

// Create scene
m_scene = new Scene(getAssetPath() + "gltfs/Duck/duck.gltf");
}

VulkanExampleBase::~VulkanExampleBase()
Expand Down
13 changes: 13 additions & 0 deletions base/vulkanexamplebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "vulkanTextureLoader.hpp"
#include "vulkantextoverlay.hpp"
#include "camera.hpp"
#include "scene.h"

// Function pointer for getting physical device fetures to be enabled
typedef VkPhysicalDeviceFeatures (*PFN_GetEnabledFeatures)();
Expand Down Expand Up @@ -164,6 +165,18 @@ class VulkanExampleBase
std::string title = "Vulkan Example";
std::string name = "vulkanExample";

Scene* m_scene;

std::vector<GeometryBuffer> m_geometryBuffers;

/**
* \brief Uniform buffers
*/
VkBuffer m_uniformStagingBuffer;
VkBuffer m_uniformBuffer;
VkDeviceMemory m_uniformStagingBufferMemory;
VkDeviceMemory m_uniformBufferMemory;

struct
{
VkImage image;
Expand Down
14 changes: 14 additions & 0 deletions data/gltfs/Duck/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Duck
## Screenshot

![screenshot](screenshot/screenshot.png)

## License Information

Copyright 2006 Sony Computer Entertainment Inc.

Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:

http://research.scea.com/scea_shared_source_license.html

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
198 changes: 198 additions & 0 deletions data/gltfs/Duck/collada/Duck.dae

Large diffs are not rendered by default.

Binary file added data/gltfs/Duck/collada/DuckCM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/gltfs/Duck/duck.bin
Binary file not shown.
Loading