Skip to content
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ build_xcode.nosync/
.github/copilot-instructions.md
scop
!examples/scop
**/*.entitlements
__cmake_systeminformation/
29 changes: 9 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

cmake_minimum_required(VERSION 3.22)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(FetchContent)

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
Expand Down Expand Up @@ -67,14 +65,21 @@ if (APPLE AND GFX_BUILD_METAL)
endif()

if (GFX_BUILD_VULKAN)
set(VULKAN_FIND_PACKAGE_ARGS 1.4.321.0)
if(APPLE)
list(APPEND VULKAN_FIND_PACKAGE_ARGS COMPONENTS MoltenVK)
endif()
FetchContent_Declare(Vulkan
GIT_REPOSITORY https://github.com/KhronosGroup/Vulkan-Headers.git
GIT_TAG vulkan-sdk-1.4.321.0
GIT_SHALLOW 1
GIT_PROGRESS TRUE
FIND_PACKAGE_ARGS
FIND_PACKAGE_ARGS ${VULKAN_FIND_PACKAGE_ARGS}
)
FetchContent_MakeAvailable(Vulkan)
if (NOT Vulkan_FOUND)
message(WARNING "Vulkan was not found. Only the build dependencies were fetched; the program may fail at runtime.")
endif()
endif()

if (NOT GFX_BUILD_METAL AND NOT GFX_BUILD_VULKAN)
Expand Down Expand Up @@ -155,6 +160,7 @@ endif()

if (GFX_BUILD_METAL)
target_compile_definitions(Graphics PUBLIC "GFX_BUILD_METAL")
target_compile_options(Graphics PRIVATE "-fobjc-arc")
endif()

if (GFX_BUILD_VULKAN)
Expand Down Expand Up @@ -186,23 +192,6 @@ endif()

add_subdirectory("tools")

if (GFX_BUILD_METAL)
set(GFX_SHADER_SLIB "${CMAKE_CURRENT_BINARY_DIR}/shaders/gfx.slib")
file(GLOB GFX_SHADER_SRCS "shaders/*.slang")
add_custom_command(
OUTPUT ${GFX_SHADER_SLIB}
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/shaders"
COMMAND $<TARGET_FILE:gfxsc> -t metal -o ${GFX_SHADER_SLIB} ${GFX_SHADER_SRCS}
DEPENDS gfxsc ${GFX_SHADER_SRCS}
COMMENT "Building gfx shaders"
VERBATIM
)
add_custom_target(gfx_shaders ALL DEPENDS ${GFX_SHADER_SLIB})
set_target_properties(gfx_shaders PROPERTIES FOLDER "shaders")
target_compile_definitions(Graphics PRIVATE "GFX_SHADER_SLIB=\"${GFX_SHADER_SLIB}\"")
add_dependencies(Graphics gfx_shaders)
endif()

if(GFX_BUILD_EXAMPLES)
add_subdirectory("examples")
endif()
Expand Down
77 changes: 0 additions & 77 deletions cmake/find_slang.cmake

This file was deleted.

19 changes: 19 additions & 0 deletions examples/imgui_usage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,22 @@ endif()
target_compile_definitions(imgui_usage PRIVATE "GLFW_INCLUDE_NONE")

target_link_libraries(imgui_usage PRIVATE Graphics imgui)

if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
set(CODESIGN_IDENTITY "-" CACHE STRING "Codesigning identity for imgui_usage")

set(IMGUI_USAGE_ENTITLEMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/imgui_usage.entitlements")
if(EXISTS "${IMGUI_USAGE_ENTITLEMENTS_FILE}")
add_custom_command(TARGET imgui_usage POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force --entitlements \"${IMGUI_USAGE_ENTITLEMENTS_FILE}\" \"$<TARGET_FILE:imgui_usage>\" >/dev/null 2>&1"
COMMENT "Codesigning imgui_usage (with entitlements) [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
else()
add_custom_command(TARGET imgui_usage POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force \"$<TARGET_FILE:imgui_usage>\" >/dev/null 2>&1"
COMMENT "Codesigning imgui_usage [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
endif()
endif()
19 changes: 19 additions & 0 deletions examples/mc_cube/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,22 @@ target_compile_definitions(mc_cube PRIVATE "GLFW_INCLUDE_NONE")

target_link_libraries(mc_cube PRIVATE Graphics glm::glm imgui stb_image)
add_dependencies(mc_cube mc_cube_shader)

if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
set(CODESIGN_IDENTITY "-" CACHE STRING "Codesigning identity for mc_cube")

set(MC_CUBE_ENTITLEMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/mc_cube.entitlements")
if(EXISTS "${MC_CUBE_ENTITLEMENTS_FILE}")
add_custom_command(TARGET mc_cube POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force --entitlements \"${MC_CUBE_ENTITLEMENTS_FILE}\" \"$<TARGET_FILE:mc_cube>\" >/dev/null 2>&1"
COMMENT "Codesigning mc_cube (with entitlements) [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
else()
add_custom_command(TARGET mc_cube POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force \"$<TARGET_FILE:mc_cube>\" >/dev/null 2>&1"
COMMENT "Codesigning mc_cube [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
endif()
endif()
19 changes: 19 additions & 0 deletions examples/multiBuffer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,22 @@ target_compile_definitions(multiBuffer PRIVATE "GLFW_INCLUDE_NONE")

target_link_libraries(multiBuffer PRIVATE Graphics glfw glm::glm)
add_dependencies(multiBuffer multiBuffer_shader)

if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
set(CODESIGN_IDENTITY "-" CACHE STRING "Codesigning identity for multiBuffer")

set(multiBuffer_ENTITLEMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/multiBuffer.entitlements")
if(EXISTS "${MULTIBUFFER_ENTITLEMENTS_FILE}")
add_custom_command(TARGET multiBuffer POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force --entitlements \"${MULTIBUFFER_ENTITLEMENTS_FILE}\" \"$<TARGET_FILE:multiBuffer>\" >/dev/null 2>&1"
COMMENT "Codesigning multiBuffer (with entitlements) [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
else()
add_custom_command(TARGET multiBuffer POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force \"$<TARGET_FILE:multiBuffer>\" >/dev/null 2>&1"
COMMENT "Codesigning multiBuffer [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
endif()
endif()
19 changes: 19 additions & 0 deletions examples/scop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,22 @@ else()
target_link_libraries(scop PRIVATE Graphics glm::glm imgui stb_image assimp::assimp)
endif()
add_dependencies(scop flat_color_shader textured_shader scop_shader)

if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
set(CODESIGN_IDENTITY "-" CACHE STRING "Codesigning identity")

set(SCOP_ENTITLEMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/scop.entitlements")
if(EXISTS "${SCOP_ENTITLEMENTS_FILE}")
add_custom_command(TARGET scop POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force --entitlements \"${SCOP_ENTITLEMENTS_FILE}\" \"$<TARGET_FILE:scop>\" >/dev/null 2>&1"
COMMENT "Codesigning scop (with entitlements) [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
else()
add_custom_command(TARGET scop POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force \"$<TARGET_FILE:scop>\" >/dev/null 2>&1"
COMMENT "Codesigning scop [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
endif()
endif()
4 changes: 2 additions & 2 deletions examples/scop/scop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include <string_view>
#include <stdexcept>
#include <string>
#include <functional>
#include <functional> // IWYU pragma: keep

#if __XCODE__
#include <unistd.h>
Expand Down Expand Up @@ -256,7 +256,7 @@ int main(int argc, char** argv)
scopMaterial->setTextureStrength(textureStrengthTarget);
}
#else
static scop::Light* lightAttachedToCamera = nullptr;
static scop::Light* lightAttachedToCamera = light.get();
if (lightAttachedToCamera != nullptr)
lightAttachedToCamera->setPosition(camera->position());
#endif
Expand Down
19 changes: 19 additions & 0 deletions examples/triangle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,22 @@ target_compile_definitions(triangle PRIVATE "GLFW_INCLUDE_NONE")

target_link_libraries(triangle PRIVATE Graphics glfw glm::glm)
add_dependencies(triangle triangle_shader)

if(APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
set(CODESIGN_IDENTITY "-" CACHE STRING "Codesigning identity for triangle")

set(triangle_ENTITLEMENTS_FILE "${CMAKE_CURRENT_SOURCE_DIR}/triangle.entitlements")
if(EXISTS "${TRIANGLE_ENTITLEMENTS_FILE}")
add_custom_command(TARGET triangle POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force --entitlements \"${TRIANGLE_ENTITLEMENTS_FILE}\" \"$<TARGET_FILE:triangle>\" >/dev/null 2>&1"
COMMENT "Codesigning triangle (with entitlements) [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
else()
add_custom_command(TARGET triangle POST_BUILD
COMMAND /bin/sh -c "codesign --sign \"${CODESIGN_IDENTITY}\" --force \"$<TARGET_FILE:triangle>\" >/dev/null 2>&1"
COMMENT "Codesigning triangle [identity: ${CODESIGN_IDENTITY}]"
VERBATIM
)
endif()
endif()
5 changes: 2 additions & 3 deletions examples/triangle/triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class Application

if (m_lastCommandBuffers.at(m_frameIdx) != nullptr) {
m_device->waitCommandBuffer(*m_lastCommandBuffers.at(m_frameIdx));
m_lastCommandBuffers.at(m_frameIdx).reset();
m_commandBufferPools.at(m_frameIdx)->reset();
}

Expand Down Expand Up @@ -199,7 +198,7 @@ class Application
commandBuffer->endRenderPass();
commandBuffer->presentDrawable(drawable);

m_lastCommandBuffers.at(m_frameIdx) = commandBuffer;
m_lastCommandBuffers.at(m_frameIdx) = commandBuffer.get();
m_device->submitCommandBuffers(commandBuffer);

m_frameIdx = (m_frameIdx + 1) % maxFrameInFlight;
Expand All @@ -222,7 +221,7 @@ class Application
std::shared_ptr<gfx::Buffer> m_vertexBuffer;
uint8_t m_frameIdx = 0;
std::array<std::unique_ptr<gfx::CommandBufferPool>, maxFrameInFlight> m_commandBufferPools;
std::array<std::shared_ptr<gfx::CommandBuffer>, maxFrameInFlight> m_lastCommandBuffers = {};
std::array<gfx::CommandBuffer*, maxFrameInFlight> m_lastCommandBuffers = {};
};

int main()
Expand Down
50 changes: 0 additions & 50 deletions shaders/imgui_metal.slang

This file was deleted.

8 changes: 6 additions & 2 deletions src/Metal/MetalBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "Graphics/Buffer.hpp"
#include "Graphics/Enums.hpp"

#if !defined(__OBJC__)
#error this file can only by used in objective c
#endif

namespace gfx
{

Expand All @@ -33,9 +37,9 @@ class MetalBuffer : public Buffer

void setContent(const void* data, size_t size) override;

const id<MTLBuffer>& mtlBuffer() const { return m_mtlBuffer; }
inline id<MTLBuffer> mtlBuffer() const { return m_mtlBuffer; }

~MetalBuffer() override;
~MetalBuffer() override = default;

protected:
void* contentVoid() override;
Expand Down
Loading