Compare commits

..

4 Commits

Author SHA1 Message Date
c1558d99ee audio: implement stop/fadeout 2026-05-27 21:05:20 -05:00
8203e1f2f4 audio: more tracks 2026-05-27 19:38:53 -05:00
ac6b6138d4 audio: looped tracks 2026-05-27 16:54:51 -05:00
ae0b7526a5 self-compression 2026-05-26 22:50:10 -05:00
13 changed files with 42 additions and 105 deletions

View File

@ -7,19 +7,15 @@ OBJARCH = elf64-x86-64
UNAME := $(shell uname -s) UNAME := $(shell uname -s)
OPT += -Os OPT += -O3 -march=x86-64-v3
OPT += -march=core-avx2
DEBUG = -g DEBUG = -g
CSTD = -std=gnu17 CSTD = -std=gnu23
CXXSTD = -std=gnu++20 CXXSTD = -std=gnu++23
CFLAGS += -Wall -Werror CFLAGS += -Wall -Werror
CFLAGS += -Wfatal-errors CFLAGS += -Wfatal-errors
CFLAGS += -Wno-error=unused-variable CFLAGS += -Wno-error=unused-variable -Wno-error=unused-but-set-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
@ -27,9 +23,6 @@ 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 += -I../opus-dist/include CFLAGS += -I../opus-dist/include
CFLAGS += -fpic CFLAGS += -fpic
CFLAGS += -ffunction-sections CFLAGS += -ffunction-sections
@ -38,7 +31,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
@ -46,9 +39,6 @@ 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 \
@ -63,6 +53,8 @@ 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 \
@ -75,6 +67,7 @@ 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 += \
@ -86,15 +79,19 @@ 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
WORLDS = \
data/minecraft/midnightmeadow/inthash.o \
data/minecraft/grandlecturn/inthash.o
SCENES = \
data/scenes/shadow_test/shadow_test.o \
data/scenes/eidelwind/eidelwind.o
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 \
@ -127,11 +124,11 @@ all: main
%.opus.bin: %.pcm %.opus.bin: %.pcm
./tools/opus_encode $< $@ ./tools/opus_encode $< $@
main: $(OBJS) $(LIBS) 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,10 +1,6 @@
#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"
@ -53,7 +49,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 = 2; static constexpr int shaderVariantCount = 3;
static constexpr uint32_t maxJointsCount = 128; static constexpr uint32_t maxJointsCount = 128;
// externally initialized, opaque handle // externally initialized, opaque handle

View File

@ -2,13 +2,8 @@
#include <assert.h> #include <assert.h>
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h"
#endif
#include "dds/dds.h" #include "dds/dds.h"
#include "volk/volk.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,12 +1,7 @@
#pragma once #pragma once
#ifdef __APPLE__
#include "vulkan/vulkan.h"
#else
#include "volk/volk.h"
#endif
#include "directxmath/directxmath.h" #include "directxmath/directxmath.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,12 +6,6 @@
#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)
{ {
@ -43,7 +37,7 @@ namespace collada::scene {
if (ret != 0) if (ret != 0)
break; break;
if (MTIME(statbuf).tv_sec != imageStats[i].mtime.tv_sec || MTIME(statbuf).tv_nsec != imageStats[i].mtime.tv_nsec) { if (statbuf.st_mtim.tv_sec != imageStats[i].mtime.tv_sec || statbuf.st_mtim.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);
@ -54,8 +48,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 = MTIME(statbuf).tv_sec; imageStats[i].mtime.tv_sec = statbuf.st_mtim.tv_sec;
imageStats[i].mtime.tv_nsec = MTIME(statbuf).tv_nsec; imageStats[i].mtime.tv_nsec = statbuf.st_mtim.tv_nsec;
} }
break; break;
} }

View File

@ -4,12 +4,7 @@
#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"
@ -375,13 +370,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,
@ -775,7 +770,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))
} }
@ -810,7 +805,6 @@ 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,
@ -831,7 +825,6 @@ namespace collada::scene {
.pName = "PSGeometryMain" .pName = "PSGeometryMain"
} }
}; };
*/
VkPipelineShaderStageCreateInfo shadowShaderStages[2]{ VkPipelineShaderStageCreateInfo shadowShaderStages[2]{
{ {
@ -979,7 +972,6 @@ 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,
@ -995,7 +987,6 @@ namespace collada::scene {
.pDynamicState = &dynamicState, .pDynamicState = &dynamicState,
.layout = pipelineLayout .layout = pipelineLayout
}; };
*/
}; };
pipelines = NewM<VkPipeline>(pipelineCount); pipelines = NewM<VkPipeline>(pipelineCount);

View File

@ -2,12 +2,7 @@
#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,12 +1,7 @@
#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"
@ -21,12 +16,19 @@
#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 };
@ -87,7 +89,6 @@ 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)
{ {
@ -98,7 +99,6 @@ 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,10 +363,7 @@ 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,
@ -385,9 +382,7 @@ 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
@ -489,7 +484,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;
@ -1055,7 +1050,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,12 +1,7 @@
#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,12 +1,7 @@
#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,11 +1,6 @@
#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,13 +3,7 @@
#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++ -std=c++11 -o $@ $(OPT) $(CFLAGS) $^ g++ -o $@ $(OPT) $(CFLAGS) $^