Skip to content

Commit 27452d5

Browse files
committed
Formatting
1 parent f4f7851 commit 27452d5

File tree

13 files changed

+121
-155
lines changed

13 files changed

+121
-155
lines changed

.editorconfig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ trim_trailing_whitespace = true
1414
insert_final_newline = true
1515

1616
[*.md]
17-
indent_style = space
1817
indent_size = 3
1918

19+
[*.nix]
20+
indent_size = 2
21+
2022
[*.py]
21-
indent_style = space
22-
indent_size = 4
23+
indent_size = 4
24+
max_line_length = 120

.gitignore

Lines changed: 50 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,50 @@
1-
# Prerequisites
2-
*.d
3-
4-
# Object files
5-
*.o
6-
*.ko
7-
*.obj
8-
*.elf
9-
10-
# Linker output
11-
*.ilk
12-
*.map
13-
*.exp
14-
15-
# Precompiled Headers
16-
*.gch
17-
*.pch
18-
19-
# Libraries
20-
*.lib
21-
*.a
22-
*.la
23-
*.lo
24-
25-
# Shared objects (inc. Windows DLLs)
26-
*.dll
27-
*.so
28-
*.so.*
29-
*.dylib
30-
31-
# Executables
32-
*.exe
33-
*.out
34-
*.app
35-
*.i*86
36-
*.x86_64
37-
*.hex
38-
39-
# Debug files
40-
*.dSYM/
41-
*.su
42-
*.idb
43-
*.pdb
44-
45-
# Kernel Module Compile Results
46-
*.mod*
47-
*.cmd
48-
.tmp_versions/
49-
modules.order
50-
Module.symvers
51-
Mkfile.old
52-
dkms.conf
53-
54-
# CMake files
55-
CMakeCache.txt
56-
cmake_install.cmake
57-
CPackConfig.cmake
58-
_deps/
59-
Makefile
60-
obj/
61-
CMakeFiles/
62-
CPackSourceConfig.cmake
63-
CMakeSettings.json
64-
CTestTestfile.cmake
65-
*_include.cmake
66-
*_tests.cmake
67-
68-
# Build files
69-
.cache/
70-
target/
71-
build/
72-
/.emscripten_cache
73-
74-
!public/
1+
*
2+
3+
!.github/
4+
!assets/
5+
!assets/**/
6+
!.editorconfig
7+
!.gitattributes
8+
!.gitignore
9+
!.gitmodules
10+
!.justfile
11+
!CMakeLists.txt
12+
!.clang-format
13+
!.cmake-format.py
14+
!LICENSE
15+
!README.md
16+
17+
!docs/
18+
!docs/**/
19+
!examples/
20+
!examples/**/
21+
!include/
22+
!include/**/
23+
!scripts/
24+
!scripts/**/
25+
!tests/
26+
!tests/**/
27+
28+
!*.md
29+
!*.svg
30+
!*.png
31+
!*.nix
32+
!*.lock
33+
!*.sh
34+
!*.c
35+
!*.h
36+
!*.cc
37+
!*.hh
38+
!*.cxx
39+
!*.hxx
40+
!*.cpp
41+
!*.hpp
42+
!*.cu
43+
!*.cuh
44+
45+
!public/
46+
!public/**/
47+
!*.mesh
48+
!*.data
49+
!*.js
50+
!*.wasm

.justfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ run *package='bunny':
2626
build *build_type='Release':
2727
@mkdir -p build
2828
@echo "Configuring the build system..."
29-
@cd build && cmake -S .. -B . -DCMAKE_BUILD_TYPE={{build_type}}
29+
@cd build && cmake -S .. -B . -DCMAKE_BUILD_TYPE={{build_type}} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
3030
@echo "Building the project..."
3131
@cd build && cmake --build . -j{{CORES}}
3232

@@ -53,10 +53,9 @@ clean:
5353
@rm -rf target
5454
@if [ -n "${EM_CACHE-}" ]; then rm -rf "$EM_CACHE"; fi
5555

56-
# Run code quality tools
5756
check:
5857
@echo "Running code quality tools..."
59-
@cppcheck --enable=all --suppress=missingInclude --suppress=unusedFunction --error-exitcode=1 include/kiwigl
58+
@cppcheck --error-exitcode=1 --project=build/compile_commands.json -i build/_deps/
6059

6160
# Run code quality tools
6261
test:
@@ -68,7 +67,8 @@ format:
6867
@echo "Formatting..."
6968
@chmod +x ./scripts/format.sh
7069
@./scripts/format.sh format
71-
@cmake-format -i CMakeLists.txt
70+
@cmake-format -i $(find . -name "CMakeLists.txt")
71+
@find . -name "*.nix" -type f -exec nixfmt {} \;
7272

7373
# Generate documentation
7474
docs:

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ else()
8787
FetchContent_MakeAvailable(metal-cpp)
8888

8989
# Add metal-cpp include directories
90-
target_include_directories(${PROJECT_NAME} INTERFACE ${metal-cpp_SOURCE_DIR})
90+
target_include_directories(${PROJECT_NAME}
91+
INTERFACE ${metal-cpp_SOURCE_DIR})
9192

9293
target_link_libraries(
9394
${PROJECT_NAME} INTERFACE "-framework Metal" "-framework Foundation"
@@ -130,7 +131,6 @@ if(BENCHMARK)
130131
target_compile_definitions(${PROJECT_NAME} PRIVATE BENCHMARK_MODE)
131132
else()
132133
# Fetch SDL3
133-
include(FetchContent)
134134
FetchContent_Declare(
135135
SDL3
136136
GIT_REPOSITORY https://github.com/libsdl-org/SDL.git

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ else()
44
add_subdirectory(bunny)
55
add_subdirectory(cube)
66
add_subdirectory(f22)
7-
endif()
7+
endif()

examples/bunny/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ target_include_directories(${EXECUTABLE_NAME} PUBLIC ${PROJECT_INCLUDES})
88
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${PROJECT_NAME})
99

1010
# Setting our output directory
11-
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
12-
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/target/release/"
13-
OUTPUT_NAME ${EXECUTABLE_NAME}
14-
)
11+
set_target_properties(
12+
${EXECUTABLE_NAME}
13+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/target/release/"
14+
OUTPUT_NAME ${EXECUTABLE_NAME})

examples/cube/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ target_include_directories(${EXECUTABLE_NAME} PUBLIC ${PROJECT_INCLUDES})
88
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${PROJECT_NAME})
99

1010
# Setting our output directory
11-
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
12-
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/target/release/"
13-
OUTPUT_NAME ${EXECUTABLE_NAME}
14-
)
11+
set_target_properties(
12+
${EXECUTABLE_NAME}
13+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/target/release/"
14+
OUTPUT_NAME ${EXECUTABLE_NAME})

examples/f22/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ target_include_directories(${EXECUTABLE_NAME} PUBLIC ${PROJECT_INCLUDES})
88
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${PROJECT_NAME})
99

1010
# Setting our output directory
11-
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
12-
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/target/release/"
13-
OUTPUT_NAME ${EXECUTABLE_NAME}
14-
)
11+
set_target_properties(
12+
${EXECUTABLE_NAME}
13+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/target/release/"
14+
OUTPUT_NAME ${EXECUTABLE_NAME})

examples/web/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${PROJECT_NAME})
99

1010
set(ASSETS_DIR ${CMAKE_SOURCE_DIR}/assets)
1111
message(STATUS "ASSETS_DIR: ${ASSETS_DIR}")
12-
target_link_options(${EXECUTABLE_NAME} PRIVATE
13-
"--preload-file" "${ASSETS_DIR}@/assets")
12+
target_link_options(${EXECUTABLE_NAME} PRIVATE "--preload-file"
13+
"${ASSETS_DIR}@/assets")
1414

1515
# Setting our output directory
16-
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
17-
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/target/release/web/"
18-
OUTPUT_NAME ${EXECUTABLE_NAME}
19-
)
16+
set_target_properties(
17+
${EXECUTABLE_NAME}
18+
PROPERTIES RUNTIME_OUTPUT_DIRECTORY
19+
"${PROJECT_SOURCE_DIR}/target/release/web/" OUTPUT_NAME
20+
${EXECUTABLE_NAME})

include/kiwigl/graphics/display.cuh

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "../geometry/vector.hpp"
1010

1111
namespace kiwigl {
12-
__device__ __host__ void cudaRotate(
13-
Vector3D* vertex, double roll, double pitch, double yaw) {
12+
__device__ __host__ void cudaRotate(Vector3D* vertex, double roll, double pitch, double yaw) {
1413
// Roll (rotation around X-axis)
1514
double cosR = cos(roll);
1615
double sinR = sin(roll);
@@ -36,8 +35,7 @@ __device__ __host__ void cudaRotate(
3635
vertex->y = y * cosY + x * sinY;
3736
}
3837

39-
__device__ __host__ void cudaTranslate3D(
40-
Vector3D* vertex, double x, double y, double z) {
38+
__device__ __host__ void cudaTranslate3D(Vector3D* vertex, double x, double y, double z) {
4139
vertex->x += x;
4240
vertex->y += y;
4341
vertex->z += z;
@@ -48,22 +46,19 @@ __device__ __host__ void cudaTranslate2D(Vector2D* vertex, double x, double y) {
4846
vertex->y += y;
4947
}
5048

51-
__device__ __host__ void cudaScale(
52-
Vector3D* vertex, double x, double y, double z) {
49+
__device__ __host__ void cudaScale(Vector3D* vertex, double x, double y, double z) {
5350
vertex->x *= x;
5451
vertex->y *= y;
5552
vertex->z *= z;
5653
}
5754

58-
__device__ __host__ void cudaProject(
59-
const Vector3D* vertex, Vector2D* projectedVertex) {
55+
__device__ __host__ void cudaProject(const Vector3D* vertex, Vector2D* projectedVertex) {
6056
projectedVertex->x = (vertex->x * FOV) / vertex->z;
6157
projectedVertex->y = (vertex->y * FOV) / vertex->z;
6258
}
6359

64-
__global__ void transformVerticesKernel(Face* faces, Vector3D* vertices,
65-
Triangle* projectedTriangles, Vector3D rotation, Vector3D camera, int width,
66-
int height, int numFaces) {
60+
__global__ void transformVerticesKernel(Face* faces, Vector3D* vertices, Triangle* projectedTriangles,
61+
Vector3D rotation, Vector3D camera, int width, int height, int numFaces) {
6762
int idx = blockIdx.x * blockDim.x + threadIdx.x;
6863
if (idx >= numFaces) return;
6964

@@ -92,28 +87,23 @@ __global__ void transformVerticesKernel(Face* faces, Vector3D* vertices,
9287

9388
void Display::InitalizeCuda() {
9489
// Allocate memory on the device
95-
cudaError_t err =
96-
cudaMalloc((void**)&d_faces, mesh.faces.size() * sizeof(Face));
90+
cudaError_t err = cudaMalloc((void**)&d_faces, mesh.faces.size() * sizeof(Face));
9791
if (err != cudaSuccess) {
98-
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(err), __FILE__,
99-
__LINE__);
92+
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(err), __FILE__, __LINE__);
10093
exit(EXIT_FAILURE);
10194
}
102-
err =
103-
cudaMalloc((void**)&d_vertices, mesh.vertices.size() * sizeof(Vector3D));
95+
err = cudaMalloc((void**)&d_vertices, mesh.vertices.size() * sizeof(Vector3D));
10496
if (err != cudaSuccess) {
105-
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(err), __FILE__,
106-
__LINE__);
97+
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(err), __FILE__, __LINE__);
10798
exit(EXIT_FAILURE);
10899
}
109-
err = cudaMalloc(
110-
(void**)&d_projectedTriangles, mesh.faces.size() * sizeof(Triangle));
100+
err = cudaMalloc((void**)&d_projectedTriangles, mesh.faces.size() * sizeof(Triangle));
111101
if (err != cudaSuccess) {
112-
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(err), __FILE__,
113-
__LINE__);
102+
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(err), __FILE__, __LINE__);
114103
exit(EXIT_FAILURE);
115104
}
116105
}
106+
117107
void Display::FreeCuda() {
118108
if (d_faces != nullptr) {
119109
cudaFree(d_faces);
@@ -128,34 +118,30 @@ void Display::FreeCuda() {
128118
d_projectedTriangles = nullptr;
129119
}
130120
}
121+
131122
void Display::LaunchCuda(int width, int height) {
132123
// Copy faces to device
133-
cudaMemcpy(d_faces, mesh.faces.data(), mesh.faces.size() * sizeof(Face),
134-
cudaMemcpyHostToDevice);
135-
cudaMemcpy(d_vertices, mesh.vertices.data(),
136-
mesh.vertices.size() * sizeof(Vector3D), cudaMemcpyHostToDevice);
124+
cudaMemcpy(d_faces, mesh.faces.data(), mesh.faces.size() * sizeof(Face), cudaMemcpyHostToDevice);
125+
cudaMemcpy(d_vertices, mesh.vertices.data(), mesh.vertices.size() * sizeof(Vector3D), cudaMemcpyHostToDevice);
137126

138127
// Launch kernel
139128
dim3 threadsPerBlock(256, 1, 1);
140-
dim3 blocksPerGrid(
141-
(mesh.faces.size() + threadsPerBlock.x - 1) / threadsPerBlock.x, 1, 1);
142-
transformVerticesKernel<<<blocksPerGrid, threadsPerBlock>>>(d_faces,
143-
d_vertices, d_projectedTriangles, rotation, camera, width, height,
144-
mesh.faces.size());
129+
dim3 blocksPerGrid((mesh.faces.size() + threadsPerBlock.x - 1) / threadsPerBlock.x, 1, 1);
130+
transformVerticesKernel<<<blocksPerGrid, threadsPerBlock>>>(d_faces, d_vertices, d_projectedTriangles, rotation,
131+
camera, width, height, mesh.faces.size());
145132

146133
// Synchronize to ensure all operations are complete
147134
cudaDeviceSynchronize();
148135

149136
// Copy projected triangles back to host
150-
cudaMemcpy(projectedTriangles.data(), d_projectedTriangles,
151-
mesh.faces.size() * sizeof(Triangle), cudaMemcpyDeviceToHost);
137+
cudaMemcpy(projectedTriangles.data(), d_projectedTriangles, mesh.faces.size() * sizeof(Triangle),
138+
cudaMemcpyDeviceToHost);
152139

153140
// Check for CUDA errors
154141
cudaError_t cudaStatus = cudaGetLastError();
155142
if (cudaStatus != cudaSuccess) {
156-
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(cudaStatus),
157-
__FILE__, __LINE__);
143+
fprintf(stderr, "%s in %s at line %d\n", cudaGetErrorString(cudaStatus), __FILE__, __LINE__);
158144
exit(EXIT_FAILURE);
159145
}
160146
}
161-
} // namespace kiwigl
147+
} // namespace kiwigl

0 commit comments

Comments
 (0)