-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
105 changed files
with
2,269 additions
and
789 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
Related issue = # | ||
Issue: # | ||
|
||
<!-- | ||
Thank you for your contribution! | ||
If it is your first time contributing to Taichi, please read our Contributor Guidelines: | ||
https://docs.taichi-lang.org/docs/contributor_guide | ||
- Please always prepend your PR title with tags such as [CUDA], [Lang], [Doc], [Example]. For a complete list of valid PR tags, please check out https://github.com/taichi-dev/taichi/blob/master/misc/prtags.json. | ||
- Use upper-case tags (e.g., [Metal]) for PRs that change public APIs. Otherwise, please use lower-case tags (e.g., [metal]). | ||
- More details: https://docs.taichi-lang.org/docs/contributor_guide#pr-title-format-and-tags | ||
- Please fill in the issue number that this PR relates to. | ||
- If your PR fixes the issue **completely**, use the `close` or `fixes` prefix so that GitHub automatically closes the issue when the PR is merged. For example, | ||
Related issue = close #2345 | ||
- If the PR does not belong to any existing issue, free to leave it blank. | ||
--> | ||
### Brief Summary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// C++ wrapper of Taichi C-API | ||
#pragma once | ||
#include <cstring> | ||
#include <list> | ||
#include <vector> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
macro(make_sample executable_name src_file) | ||
add_executable(${executable_name}) | ||
set_property(TARGET ${executable_name} PROPERTY CXX_STANDARD 17) | ||
set_property(TARGET ${executable_name} PROPERTY C_STANDARD 17) | ||
target_sources(${executable_name} PRIVATE ${src_file} "common.h") | ||
target_include_directories(${executable_name} | ||
PRIVATE | ||
${PROJECT_SOURCE_DIR} | ||
|
||
${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include | ||
${PROJECT_SOURCE_DIR}/external/eigen | ||
${PROJECT_SOURCE_DIR}/external/FP16/include | ||
${PROJECT_SOURCE_DIR}/external/SPIRV-Reflect | ||
${PROJECT_SOURCE_DIR}/external/spdlog/include | ||
${LLVM_INCLUDE_DIRS} | ||
|
||
${PROJECT_SOURCE_DIR}/external/volk | ||
${PROJECT_SOURCE_DIR}/external/Vulkan-Headers/include | ||
${PROJECT_SOURCE_DIR}/external/glfw/include | ||
${PROJECT_SOURCE_DIR}/external/glm | ||
${PROJECT_SOURCE_DIR}/external/imgui | ||
) | ||
target_include_directories(${executable_name} SYSTEM | ||
PUBLIC | ||
${PROJECT_SOURCE_DIR}/external/VulkanMemoryAllocator/include | ||
) | ||
target_link_libraries(${executable_name} taichi_c_api glfw) | ||
endmacro() | ||
|
||
make_sample(sample_1_window sample_1_window.cpp) | ||
make_sample(sample_2_triangle sample_2_triangle.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#pragma once | ||
|
||
#include "taichi/rhi/vulkan/vulkan_device.h" | ||
#include "taichi/rhi/vulkan/vulkan_common.h" | ||
#include "taichi/rhi/vulkan/vulkan_loader.h" | ||
#include "taichi/rhi/vulkan/vulkan_device_creator.h" | ||
|
||
#define GLFW_INCLUDE_NONE | ||
#include "GLFW/glfw3.h" | ||
#include "glm/glm.hpp" | ||
|
||
using namespace taichi::lang; | ||
|
||
static void glfw_error_callback(int code, const char *description) { | ||
TI_WARN("GLFW Error {}: {}", code, description); | ||
} | ||
|
||
std::vector<std::string> get_required_instance_extensions() { | ||
std::vector<std::string> extensions; | ||
|
||
uint32_t glfw_ext_count = 0; | ||
const char **glfw_extensions; | ||
glfw_extensions = glfwGetRequiredInstanceExtensions(&glfw_ext_count); | ||
|
||
for (int i = 0; i < glfw_ext_count; ++i) { | ||
extensions.push_back(glfw_extensions[i]); | ||
} | ||
// VulkanDeviceCreator will check that these are supported | ||
extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); | ||
|
||
return extensions; | ||
} | ||
|
||
std::vector<std::string> get_required_device_extensions() { | ||
static std::vector<std::string> extensions{ | ||
VK_KHR_SWAPCHAIN_EXTENSION_NAME, | ||
}; | ||
|
||
return extensions; | ||
} | ||
|
||
class App { | ||
public: | ||
App(int width, int height, const std::string &title) { | ||
TI_INFO("Creating App '{}' of {}x{}", title, width, height); | ||
|
||
TI_ASSERT(taichi::lang::vulkan::is_vulkan_api_available()); | ||
|
||
if (glfwInit()) { | ||
TI_INFO("Initialized GLFW"); | ||
|
||
glfwSetErrorCallback(glfw_error_callback); | ||
|
||
glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE); | ||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); | ||
glfw_window = | ||
glfwCreateWindow(width, height, "Sample Window", nullptr, nullptr); | ||
|
||
TI_INFO("Initialized GLFWWindow"); | ||
} else { | ||
TI_ERROR("failed to init GLFW"); | ||
} | ||
|
||
{ | ||
vulkan::VulkanDeviceCreator::Params evd_params; | ||
evd_params.api_version = std::nullopt; | ||
evd_params.additional_instance_extensions = | ||
get_required_instance_extensions(); | ||
evd_params.additional_device_extensions = | ||
get_required_device_extensions(); | ||
evd_params.is_for_ui = true; | ||
evd_params.surface_creator = [&](VkInstance instance) -> VkSurfaceKHR { | ||
VkSurfaceKHR surface = VK_NULL_HANDLE; | ||
|
||
if (glfwCreateWindowSurface(instance, glfw_window, nullptr, &surface) != | ||
VK_SUCCESS) { | ||
TI_ERROR("failed to create window surface!"); | ||
} | ||
return surface; | ||
}; | ||
evd_params.enable_validation_layer = true; | ||
|
||
device_creator = | ||
std::make_unique<vulkan::VulkanDeviceCreator>(evd_params); | ||
device = device_creator->device(); | ||
|
||
TI_INFO("Initialized VulkanDevice"); | ||
} | ||
|
||
{ | ||
SurfaceConfig config; | ||
config.window_handle = glfw_window; | ||
config.native_surface_handle = device_creator->get_surface(); | ||
|
||
surface = device->create_surface(config); | ||
} | ||
} | ||
|
||
virtual ~App() { | ||
surface.reset(); | ||
device_creator.reset(); | ||
glfwDestroyWindow(glfw_window); | ||
glfwTerminate(); | ||
} | ||
|
||
virtual std::vector<StreamSemaphore> render_loop( | ||
StreamSemaphore image_available_semaphore) { | ||
return {}; | ||
} | ||
|
||
void run() { | ||
while (!glfwWindowShouldClose(glfw_window)) { | ||
auto image_available_semaphore = surface->acquire_next_image(); | ||
|
||
glfwPollEvents(); | ||
|
||
surface->present_image(render_loop(image_available_semaphore)); | ||
} | ||
} | ||
|
||
public: | ||
// Owned | ||
GLFWwindow *glfw_window; | ||
std::unique_ptr<vulkan::VulkanDeviceCreator> device_creator; | ||
std::unique_ptr<Surface> surface; | ||
|
||
// Weak references | ||
vulkan::VulkanDevice *device; | ||
}; |
Oops, something went wrong.