-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit cb42965
Showing
207 changed files
with
56,234 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
cmake-build-* | ||
build/* |
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,14 @@ | ||
cmake_minimum_required(VERSION 3.21) | ||
set(CMAKE_CXX_STANDARD 17) | ||
project(metal_cpp_try) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
option(METAL_CPP_BUILD_EXAMPLES "Build examples" ON) | ||
|
||
add_subdirectory(metal-cmake) # Library definition | ||
|
||
if(METAL_CPP_BUILD_EXAMPLES) | ||
add_subdirectory(examples) # Add targets | ||
endif(METAL_CPP_BUILD_EXAMPLES) | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,16 @@ | ||
# Get all project dir | ||
FILE(GLOB examples ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) | ||
|
||
# For each source file, make an executable | ||
FOREACH(example ${examples}) | ||
|
||
# Get project name and all sources | ||
get_filename_component(example-name ${example} NAME_WE) | ||
|
||
# Create executable and link target | ||
add_executable(${example-name} ${example}) | ||
target_link_libraries(${example-name} METAL_CPP_COMPUTE) | ||
|
||
message(STATUS "adding target: ${example}") | ||
|
||
ENDFOREACH() |
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,41 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
template <typename T> | ||
std::vector<T> read_binary(std::string filename) { | ||
std::vector<T> buffer; | ||
std::ifstream infile(filename, std::ios::binary); | ||
|
||
if (infile) { | ||
// std::cout << "file found: " << filename << std::endl; | ||
infile.seekg(0, std::ios::end); | ||
std::streampos filesize = infile.tellg(); | ||
infile.seekg(0, std::ios::beg); | ||
|
||
buffer = std::vector<T>(filesize / sizeof(T)); | ||
infile.read((char*)&buffer[0], filesize); | ||
} else { | ||
std::cout << "file not found: " << filename << std::endl; | ||
} | ||
|
||
infile.close(); | ||
|
||
return buffer; | ||
} | ||
|
||
template <typename T> | ||
void write_binary(const std::vector<T>& buffer, std::string filename) { | ||
std::ofstream outfile(filename, std::ios::binary); | ||
|
||
if (outfile) { | ||
outfile.write((char*)&buffer[0], sizeof(T) * buffer.size()); | ||
} else { | ||
std::cout << "file not found: " << filename << std::endl; | ||
} | ||
|
||
outfile.close(); | ||
} |
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,62 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <iostream> | ||
|
||
using float3 = std::array<float, 3>; | ||
using float4x3 = std::array<float3, 4>; | ||
using uint4 = std::array<uint32_t, 4>; | ||
|
||
float3 operator-(const float3 & x, const float3 & y) { | ||
return {x[0] - y[0], x[1] - y[1], x[2] - y[2]}; | ||
} | ||
|
||
float4x3 operator-(const float4x3 & x, const float4x3 & y) { | ||
return {x[0] - y[0], x[1] - y[1], x[2] - y[2], x[3] - y[3]}; | ||
} | ||
|
||
float3 operator+(const float3 & x, const float3 & y) { | ||
return {x[0] + y[0], x[1] + y[1], x[2] + y[2]}; | ||
} | ||
|
||
float4x3 operator+(const float4x3 & x, const float4x3 & y) { | ||
return {x[0] + y[0], x[1] + y[1], x[2] + y[2], x[3] + y[3]}; | ||
} | ||
|
||
void operator+=(float3 & x, const float3 & y) { | ||
x[0] += y[0]; | ||
x[1] += y[1]; | ||
x[2] += y[2]; | ||
} | ||
|
||
float3 operator*(const float & scale, const float3 & y) { | ||
return {scale * y[0], scale * y[1], scale * y[2]}; | ||
} | ||
|
||
float4x3 operator*(const float & scale, const float4x3 & A) { | ||
return {scale * A[0], scale * A[1], scale * A[2], scale * A[3]}; | ||
} | ||
|
||
float3 operator/(const float3 & x, const float & scale) { | ||
return {x[0] / scale, x[1] / scale, x[2] / scale}; | ||
} | ||
|
||
float4x3 operator/(const float4x3 & A, const float & scale) { | ||
return {A[0] / scale, A[1] / scale, A[2] / scale, A[3] / scale}; | ||
} | ||
|
||
float dot(const float3 & x, const float3 & y) { | ||
return x[0] * y[0] + x[1] * y[1] + x[2] * y[2]; | ||
} | ||
|
||
float det(const float3 & A0, const float3 & A1, const float3 & A2) { | ||
return A0[0] * A1[1] * A2[2] + A0[1] * A1[2] * A2[0] + | ||
A0[2] * A1[0] * A2[1] - A0[0] * A1[2] * A2[1] - | ||
A0[1] * A1[0] * A2[2] - A0[2] * A1[1] * A2[0]; | ||
} | ||
|
||
|
||
std::ostream& operator<<(std::ostream & out, const float3 & x) { | ||
out << "{" << x[0] << " " << x[1] << " " << x[2] << "}"; | ||
return out; | ||
} |
Oops, something went wrong.