macos wip

This commit is contained in:
Zack Buhman 2026-04-21 22:10:34 -05:00
parent 5a0299d9dd
commit 8a09d5701c
13 changed files with 63 additions and 39 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 += -O0
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
@ -23,6 +27,9 @@ CFLAGS += -fno-strict-aliasing
CFLAGS += -I./include CFLAGS += -I./include
CFLAGS += -I./data CFLAGS += -I./data
CFLAGS += -I../SDL3-dist/include CFLAGS += -I../SDL3-dist/include
ifeq ($(UNAME),Darwin)
CFLAGS += -I../MoltenVK/MoltenVK/include
endif
CFLAGS += -fpic CFLAGS += -fpic
CFLAGS += -ffunction-sections CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections CFLAGS += -fdata-sections
@ -30,7 +37,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
@ -38,6 +45,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 \
@ -52,8 +62,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 \
@ -65,10 +73,6 @@ OBJS = \
src/renpy/interpreter.o \ src/renpy/interpreter.o \
src/renpy/interact.o src/renpy/interact.o
WORLDS = \
data/minecraft/midnightmeadow/inthash.o \
data/minecraft/grandlecturn/inthash.o
SCENES = \ SCENES = \
data/scenes/shadow_test/shadow_test.o \ data/scenes/shadow_test/shadow_test.o \
data/scenes/eidelwind/eidelwind.o data/scenes/eidelwind/eidelwind.o
@ -98,8 +102,8 @@ all: main
main: $(OBJS) $(LIBS) $(SCENES) $(WORLDS) main: $(OBJS) $(LIBS) $(SCENES) $(WORLDS)
$(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,7 @@
#pragma once #pragma once
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.h"
#include "collada/types.h" #include "collada/types.h"
#include "collada/instance_types.h" #include "collada/instance_types.h"
@ -49,7 +50,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

@ -3,7 +3,8 @@
#include <assert.h> #include <assert.h>
#include "dds/dds.h" #include "dds/dds.h"
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.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,8 @@
#pragma once #pragma once
#include "directxmath/directxmath.h" #include "directxmath/directxmath.h"
#include "volk/volk.h" #include "vulkan/vulkan.h"
//#include "volk/volk.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,8 @@
#include <assert.h> #include <assert.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.h"
#include "vulkan/vk_enum_string_helper.h" #include "vulkan/vk_enum_string_helper.h"
#include "collada/inputs.h" #include "collada/inputs.h"
@ -370,13 +371,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 +771,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 +806,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 +827,7 @@ namespace collada::scene {
.pName = "PSGeometryMain" .pName = "PSGeometryMain"
} }
}; };
*/
VkPipelineShaderStageCreateInfo shadowShaderStages[2]{ VkPipelineShaderStageCreateInfo shadowShaderStages[2]{
{ {
@ -972,6 +975,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 +991,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,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.h"
#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,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.h"
#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"
@ -19,7 +20,7 @@
#include "collada/scene.h" #include "collada/scene.h"
#include "collada/scene/vulkan.h" #include "collada/scene/vulkan.h"
#include "minecraft/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"
@ -348,8 +349,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);
} }
} }
@ -357,7 +358,7 @@ int main()
{ {
SDL_CHECK(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)); SDL_CHECK(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD));
SDL_CHECK(SDL_Vulkan_LoadLibrary(NULL)); SDL_CHECK(SDL_Vulkan_LoadLibrary(NULL));
volkInitialize(); //volkInitialize();
VkApplicationInfo appInfo{ VkApplicationInfo appInfo{
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
@ -376,7 +377,7 @@ int main()
}; };
VK_CHECK(vkCreateInstance(&instanceCreateInfo, nullptr, &instance)); VK_CHECK(vkCreateInstance(&instanceCreateInfo, nullptr, &instance));
volkLoadInstance(instance); //volkLoadInstance(instance);
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// physical device and queue family index // physical device and queue family index
@ -478,7 +479,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;
@ -1040,7 +1041,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,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.h"
#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,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.h"
#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,7 @@
#include <string.h> #include <string.h>
#include "volk/volk.h" //#include "volk/volk.h"
#include "vulkan/vulkan.h"
#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,8 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include "volk/volk.h" //#include "volk/volk.h"
#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) $^