-
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.
Merge branch 'master' of github.com:taichi-dev/taichi into fix_for_lo…
…op_break
- Loading branch information
Showing
79 changed files
with
2,303 additions
and
575 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
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,30 @@ | ||
#pragma once | ||
|
||
#define GLFW_INCLUDE_NONE | ||
#import <GLFW/glfw3.h> | ||
#define GLFW_EXPOSE_NATIVE_COCOA | ||
#import <GLFW/glfw3native.h> | ||
#include "glm/glm.hpp" | ||
|
||
#include "taichi/rhi/metal/metal_api.h" | ||
#include "taichi/rhi/metal/metal_device.h" | ||
|
||
using namespace taichi::lang; | ||
|
||
class App { | ||
public: | ||
explicit App(int width, int height, const std::string &title); | ||
virtual ~App(); | ||
|
||
virtual std::vector<StreamSemaphore> render_loop( | ||
StreamSemaphore image_available_semaphore) { | ||
return {}; | ||
} | ||
|
||
void run(); | ||
|
||
GLFWwindow *glfw_window; | ||
metal::MetalDevice *device; | ||
|
||
std::unique_ptr<Surface> surface; | ||
}; |
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,77 @@ | ||
#include "common_metal.h" | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
using namespace taichi::lang; | ||
|
||
static void glfw_error_callback(int error, const char *description) { | ||
TI_WARN("GLFW Error {}: {}", error, description); | ||
} | ||
|
||
App::App(int width, int height, const std::string &title) { | ||
TI_INFO("Creating App '{}' of {}x{}", title, width, height); | ||
|
||
TI_ASSERT(metal::is_metal_api_available()); | ||
|
||
device = metal::MetalDevice::create(); | ||
MTLDevice_id mtl_device = device->mtl_device(); | ||
|
||
if (!mtl_device) | ||
TI_ERROR("failed to init Metal Device"); | ||
|
||
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); | ||
if (!glfw_window) { | ||
glfwTerminate(); | ||
TI_ERROR("failed to init GLFW Window"); | ||
} | ||
TI_INFO("Initialized GLFW Window"); | ||
} else { | ||
TI_ERROR("failed to init GLFW"); | ||
} | ||
|
||
SurfaceConfig config; | ||
config.width = width; | ||
config.height = height; | ||
|
||
surface = device->create_surface(config); | ||
|
||
metal::MetalSurface *mtl_surf = | ||
dynamic_cast<metal::MetalSurface *>(surface.get()); | ||
|
||
NSWindow *nswin = glfwGetCocoaWindow(glfw_window); | ||
nswin.contentView.layer = mtl_surf->mtl_layer(); | ||
nswin.contentView.wantsLayer = YES; | ||
} | ||
|
||
App::~App() { | ||
surface.reset(); | ||
glfwDestroyWindow(glfw_window); | ||
glfwTerminate(); | ||
} | ||
|
||
std::vector<uint32_t> frag_spv_bin = | ||
#include "shaders/2_triangle.frag.spv.h" | ||
; | ||
|
||
std::vector<uint32_t> vert_spv_bin = | ||
#include "shaders/2_triangle.vert.spv.h" | ||
; | ||
|
||
void App::run() { | ||
while (!glfwWindowShouldClose(glfw_window)) { | ||
auto image_available_semaphore = surface->acquire_next_image(); | ||
|
||
glfwPollEvents(); | ||
|
||
surface->present_image(render_loop(image_available_semaphore)); | ||
} | ||
} |
File renamed without changes.
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
Oops, something went wrong.