macos support

This commit is contained in:
Zack Buhman 2026-04-21 22:10:34 -05:00
parent 22aa0dd60e
commit 1575b3053a
13 changed files with 101 additions and 33 deletions

View File

@ -7,15 +7,19 @@ OBJARCH = elf64-x86-64
UNAME := $(shell uname -s) UNAME := $(shell uname -s)
OPT += -O3 -march=x86-64-v3 OPT += -Os
OPT += -march=core-avx2
DEBUG = -g DEBUG = -g
CSTD = -std=gnu23 CSTD = -std=gnu17
CXXSTD = -std=gnu++23 CXXSTD = -std=gnu++20
CFLAGS += -Wall -Werror CFLAGS += -Wall -Werror
CFLAGS += -Wfatal-errors CFLAGS += -Wfatal-errors
CFLAGS += -Wno-error=unused-variable -Wno-error=unused-but-set-variable CFLAGS += -Wno-error=unused-variable
#CFLAGS += -Wno-error=unused-but-set-variable
CFLAGS += -Wno-format-security
CFLAGS += -Wno-format
CFLAGS += -Wno-error=unused-function CFLAGS += -Wno-error=unused-function
CFLAGS += -Wno-error=array-bounds CFLAGS += -Wno-error=array-bounds
CFLAGS += -Wno-unknown-pragmas CFLAGS += -Wno-unknown-pragmas
@ -34,7 +38,7 @@ CFLAGS += -fdata-sections
#FLAGS += -fstack-protector -fstack-protector-all -fno-omit-frame-pointer -fsanitize=address #FLAGS += -fstack-protector -fstack-protector-all -fno-omit-frame-pointer -fsanitize=address
LDFLAGS += -lm LDFLAGS += -lm
LDFLAGS += -Wl,--gc-sections #LDFLAGS += -Wl,--gc-sections
#-Wl,--print-gc-sections #-Wl,--print-gc-sections
ifeq ($(UNAME),Linux) ifeq ($(UNAME),Linux)
LDFLAGS += -Wl,-z noexecstack LDFLAGS += -Wl,-z noexecstack
@ -42,6 +46,9 @@ endif
ifeq ($(UNAME),Darwin) ifeq ($(UNAME),Darwin)
LDFLAGS += -framework Foundation -framework Cocoa -framework IOKit -framework AVFoundation -framework CoreVideo -framework CoreAudio -framework CoreMedia -framework CoreHaptics -framework AudioToolbox -framework GameController -framework ForceFeedback -framework Carbon -framework Metal -framework QuartzCore -framework UniformTypeIdentifiers LDFLAGS += -framework Foundation -framework Cocoa -framework IOKit -framework AVFoundation -framework CoreVideo -framework CoreAudio -framework CoreMedia -framework CoreHaptics -framework AudioToolbox -framework GameController -framework ForceFeedback -framework Carbon -framework Metal -framework QuartzCore -framework UniformTypeIdentifiers
LDFLAGS += -lstdc++ LDFLAGS += -lstdc++
#LDFLAGS += ../MoltenVK/MoltenVK/static/MoltenVK.xcframework/macos-arm64_x86_64/libMoltenVK.a
LDFLAGS += -framework IOSurface
LDFLAGS += ../MoltenVK-1.4.0/libMoltenVK.a-x86_64-master.o
endif endif
# src/collada/scene/vulkan.o \ # src/collada/scene/vulkan.o \
@ -56,8 +63,6 @@ endif
OBJS = \ OBJS = \
src/main.o \ src/main.o \
src/view.o \
src/volk/volk.o \
src/file.o \ src/file.o \
src/pack.o \ src/pack.o \
src/dds/validate.o \ src/dds/validate.o \
@ -70,7 +75,6 @@ OBJS = \
src/renpy/interact.o \ src/renpy/interact.o \
src/audio.o src/audio.o
ifeq ($(UNAME),Linux)
ZLIB = ../zlib-1.3.2 ZLIB = ../zlib-1.3.2
CFLAGS += -I$(ZLIB) CFLAGS += -I$(ZLIB)
OBJS += \ OBJS += \
@ -82,11 +86,15 @@ OBJS += \
$(ZLIB)/zutil.o \ $(ZLIB)/zutil.o \
$(ZLIB)/crc32.o \ $(ZLIB)/crc32.o \
$(ZLIB)/adler32.o $(ZLIB)/adler32.o
ifneq ($(UNAME),Darwin)
OBJS += src/volk/volk.o
endif endif
ifeq ($(UNAME),Darwin) ifeq ($(UNAME),Darwin)
LIBS = \ LIBS = \
../SDL3-dist/lib/libSDL3.a ../SDL3-dist/lib/libSDL3.a \
../opus-dist/lib/libopus.a
else else
LIBS = \ LIBS = \
../SDL3-dist/lib64/libSDL3.a \ ../SDL3-dist/lib64/libSDL3.a \
@ -122,8 +130,8 @@ all: main
main: $(OBJS) $(LIBS) main: $(OBJS) $(LIBS)
$(CC) $(ARCH) $(LDFLAGS) $(FLAGS) $(OPT) $(DEBUG) $^ -o $@ $(CC) $(ARCH) $(LDFLAGS) $(FLAGS) $(OPT) $(DEBUG) $^ -o $@
%.spv: %.hlsl #%.spv: %.hlsl
../dxc/bin/dxc -spirv -T lib_6_3 -fspv-target-env=vulkan1.3 $< -Fo $@ # ../dxc/bin/dxc -spirv -T lib_6_3 -fspv-target-env=vulkan1.3 $< -Fo $@
tool/pack_file: tool/pack_file.cpp tool/pack_file: tool/pack_file.cpp
make -C tool pack_file make -C tool pack_file

View File

@ -1,6 +1,10 @@
#pragma once #pragma once
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "collada/types.h" #include "collada/types.h"
#include "collada/instance_types.h" #include "collada/instance_types.h"
@ -49,7 +53,7 @@ namespace collada::scene {
static constexpr uint32_t uniformBufferDescriptorCount = maxFrames * perFrameDescriptorCount + constantDescriptorCount; static constexpr uint32_t uniformBufferDescriptorCount = maxFrames * perFrameDescriptorCount + constantDescriptorCount;
// +3: linear sampler, shadow sampled image, scene sampled image (array) // +3: linear sampler, shadow sampled image, scene sampled image (array)
static constexpr uint32_t bindingCount = uniformBufferDescriptorCount + 3; static constexpr uint32_t bindingCount = uniformBufferDescriptorCount + 3;
static constexpr int shaderVariantCount = 3; static constexpr int shaderVariantCount = 2;
static constexpr uint32_t maxJointsCount = 128; static constexpr uint32_t maxJointsCount = 128;
// externally initialized, opaque handle // externally initialized, opaque handle

View File

@ -2,8 +2,13 @@
#include <assert.h> #include <assert.h>
#include "dds/dds.h" #ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "dds/dds.h"
namespace dds { namespace dds {
inline constexpr VkFormat dxgi_to_vulkan(DXGI_FORMAT dxgiFormat) inline constexpr VkFormat dxgi_to_vulkan(DXGI_FORMAT dxgiFormat)

View File

@ -1,7 +1,12 @@
#pragma once #pragma once
#include "directxmath/directxmath.h" #ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "directxmath/directxmath.h"
#include "vulkan_helper.h" #include "vulkan_helper.h"
#include "minecraft/vulkan/per_world.h" #include "minecraft/vulkan/per_world.h"

View File

@ -6,6 +6,12 @@
#include "new.h" #include "new.h"
#include "collada/scene/reload.h" #include "collada/scene/reload.h"
#ifdef __APPLE__
#define MTIME(s) ((s).st_mtimespec)
#else
#define MTIME(s) ((s).st_mtim)
#endif
namespace collada::scene { namespace collada::scene {
void reload::load_images(types::descriptor const * const descriptor) void reload::load_images(types::descriptor const * const descriptor)
{ {
@ -37,7 +43,7 @@ namespace collada::scene {
if (ret != 0) if (ret != 0)
break; break;
if (statbuf.st_mtim.tv_sec != imageStats[i].mtime.tv_sec || statbuf.st_mtim.tv_nsec != imageStats[i].mtime.tv_nsec) { if (MTIME(statbuf).tv_sec != imageStats[i].mtime.tv_sec || MTIME(statbuf).tv_nsec != imageStats[i].mtime.tv_nsec) {
if (statbuf.st_size != size) { if (statbuf.st_size != size) {
size = statbuf.st_size; size = statbuf.st_size;
usleep(500); usleep(500);
@ -48,8 +54,8 @@ namespace collada::scene {
reload = true; reload = true;
vulkan.destroy_image(i); vulkan.destroy_image(i);
vulkan.load_image(i, imageStats[i].filenameTGA); vulkan.load_image(i, imageStats[i].filenameTGA);
imageStats[i].mtime.tv_sec = statbuf.st_mtim.tv_sec; imageStats[i].mtime.tv_sec = MTIME(statbuf).tv_sec;
imageStats[i].mtime.tv_nsec = statbuf.st_mtim.tv_nsec; imageStats[i].mtime.tv_nsec = MTIME(statbuf).tv_nsec;
} }
break; break;
} }

View File

@ -4,7 +4,12 @@
#include <assert.h> #include <assert.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "collada/inputs.h" #include "collada/inputs.h"
@ -370,13 +375,13 @@ namespace collada::scene {
.binding = 0, .binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1, .descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT .stageFlags = VK_SHADER_STAGE_VERTEX_BIT// | VK_SHADER_STAGE_GEOMETRY_BIT
}, },
{ {
.binding = 1, .binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
.descriptorCount = 1, .descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_GEOMETRY_BIT .stageFlags = VK_SHADER_STAGE_VERTEX_BIT// | VK_SHADER_STAGE_GEOMETRY_BIT
}, },
{ {
.binding = 2, .binding = 2,
@ -770,7 +775,7 @@ namespace collada::scene {
{ {
VkPushConstantRange pushConstantRanges[1]{ VkPushConstantRange pushConstantRanges[1]{
{ {
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_GEOMETRY_BIT, .stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,// | VK_SHADER_STAGE_GEOMETRY_BIT,
.offset = 0, .offset = 0,
.size = (sizeof (PushConstant)) .size = (sizeof (PushConstant))
} }
@ -805,6 +810,7 @@ namespace collada::scene {
} }
}; };
/*
VkPipelineShaderStageCreateInfo geometryShaderStages[3]{ VkPipelineShaderStageCreateInfo geometryShaderStages[3]{
{ {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
@ -825,6 +831,7 @@ namespace collada::scene {
.pName = "PSGeometryMain" .pName = "PSGeometryMain"
} }
}; };
*/
VkPipelineShaderStageCreateInfo shadowShaderStages[2]{ VkPipelineShaderStageCreateInfo shadowShaderStages[2]{
{ {
@ -972,6 +979,7 @@ namespace collada::scene {
}; };
// geometry // geometry
/*
pipelineCreateInfos[i * shaderVariantCount + 2] = { pipelineCreateInfos[i * shaderVariantCount + 2] = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.pNext = &renderingCreateInfo, .pNext = &renderingCreateInfo,
@ -987,6 +995,7 @@ namespace collada::scene {
.pDynamicState = &dynamicState, .pDynamicState = &dynamicState,
.layout = pipelineLayout .layout = pipelineLayout
}; };
*/
}; };
pipelines = NewM<VkPipeline>(pipelineCount); pipelines = NewM<VkPipeline>(pipelineCount);

View File

@ -2,7 +2,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "directxmath/directxmath.h" #include "directxmath/directxmath.h"

View File

@ -1,7 +1,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "SDL3/SDL.h" #include "SDL3/SDL.h"
#include "SDL3/SDL_vulkan.h" #include "SDL3/SDL_vulkan.h"
@ -16,19 +21,12 @@
#include "minmax.h" #include "minmax.h"
#include "view.h" #include "view.h"
#include "collada/scene.h"
#include "collada/scene/vulkan.h"
#include "minecraft/vulkan.h"
#include "font/outline.h" #include "font/outline.h"
#include "renpy/vulkan.h" #include "renpy/vulkan.h"
#include "renpy/interpreter.h" #include "renpy/interpreter.h"
#include "renpy/interact.h" #include "renpy/interact.h"
#include "renpy/script.h" #include "renpy/script.h"
#include "scenes/shadow_test/shadow_test.h"
#include "scenes/eidelwind/eidelwind.h"
#include "audio.h" #include "audio.h"
VkInstance instance{ VK_NULL_HANDLE }; VkInstance instance{ VK_NULL_HANDLE };
@ -89,6 +87,7 @@ XMMATRIX currentProjection()
return projection * XMMatrixScaling(-1, -1, 1); return projection * XMMatrixScaling(-1, -1, 1);
} }
/*
XMMATRIX currentView(collada::instance_types::node const & camera_node, XMMATRIX currentView(collada::instance_types::node const & camera_node,
collada::instance_types::node const & camera_target_node) collada::instance_types::node const & camera_target_node)
{ {
@ -99,6 +98,7 @@ XMMATRIX currentView(collada::instance_types::node const & camera_node,
XMMATRIX view = XMMatrixLookAtLH(eye, at, up); XMMATRIX view = XMMatrixLookAtLH(eye, at, up);
return view; return view;
} }
*/
float theta = 0; float theta = 0;
@ -351,8 +351,8 @@ void gamepad_update(view & viewState)
float delta_yaw = rightx * -0.035; float delta_yaw = rightx * -0.035;
float delta_pitch = righty * -0.035; float delta_pitch = righty * -0.035;
viewState.applyTransform(delta_forward, delta_strafe, delta_elevation, //viewState.applyTransform(delta_forward, delta_strafe, delta_elevation,
delta_yaw, delta_pitch); //delta_yaw, delta_pitch);
} }
} }
@ -363,7 +363,10 @@ int main()
SDL_InitFlags init_flags = SDL_INIT_VIDEO | SDL_INIT_GAMEPAD | SDL_INIT_AUDIO; SDL_InitFlags init_flags = SDL_INIT_VIDEO | SDL_INIT_GAMEPAD | SDL_INIT_AUDIO;
SDL_CHECK(SDL_Init(init_flags)); SDL_CHECK(SDL_Init(init_flags));
SDL_CHECK(SDL_Vulkan_LoadLibrary(NULL)); SDL_CHECK(SDL_Vulkan_LoadLibrary(NULL));
#ifndef __APPLE__
volkInitialize(); volkInitialize();
#endif
VkApplicationInfo appInfo{ VkApplicationInfo appInfo{
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
@ -382,7 +385,9 @@ int main()
}; };
VK_CHECK(vkCreateInstance(&instanceCreateInfo, nullptr, &instance)); VK_CHECK(vkCreateInstance(&instanceCreateInfo, nullptr, &instance));
#ifndef __APPLE__
volkLoadInstance(instance); volkLoadInstance(instance);
#endif
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// physical device and queue family index // physical device and queue family index
@ -484,7 +489,7 @@ int main()
.dynamicRendering = true, .dynamicRendering = true,
}; };
VkPhysicalDeviceFeatures enabledFeatures{ VkPhysicalDeviceFeatures enabledFeatures{
.geometryShader = true, //.geometryShader = true,
.samplerAnisotropy = true, .samplerAnisotropy = true,
}; };
constexpr uint32_t enabledExtensionCount = 1; constexpr uint32_t enabledExtensionCount = 1;
@ -1050,7 +1055,7 @@ int main()
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR, .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE, .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
//.clearValue{ .color{ 0.0f, 0.0f, 0.2f, 1.0f } } //.clearValue{ .color{ 0.0f, 0.0f, 0.2f, 1.0f } }
.clearValue{ .color{ 0.0f, 0.0f, 0.0f, 0.0f } } .clearValue{ .color{ { 0.0f, 0.0f, 0.0f, 0.0f} } }
}; };
VkRenderingAttachmentInfo depthRenderingAttachmentInfo{ VkRenderingAttachmentInfo depthRenderingAttachmentInfo{
.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO,

View File

@ -1,7 +1,12 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "file.h" #include "file.h"

View File

@ -1,7 +1,12 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "new.h" #include "new.h"

View File

@ -1,6 +1,11 @@
#include <string.h> #include <string.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "dds/validate.h" #include "dds/validate.h"

View File

@ -3,7 +3,13 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h" #include "volk/volk.h"
#endif
#include "vulkan/vulkan.h"
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "minmax.h" #include "minmax.h"

View File

@ -2,4 +2,4 @@ OPT = -O2
CFLAGS = -I../include CFLAGS = -I../include
pack_file: pack_file.cpp pack_file: pack_file.cpp
g++ -o $@ $(OPT) $(CFLAGS) $^ g++ -std=c++11 -o $@ $(OPT) $(CFLAGS) $^