Skip to content
Open
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
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "-Wall -Werror -Wformat-security -Wno-deprecated-volatile -fPIC")
set(CMAKE_CXX_FLAGS "-Wall -Wformat-security -Wno-deprecated-volatile -fPIC")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g3 -ggdb3 -Og")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb3 -O0")
Expand All @@ -97,7 +97,12 @@ endif()

set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(PROJECT_OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_INSTALL_RPATH $ORIGIN)
if(APPLE)
set(CMAKE_INSTALL_RPATH "@executable_path;/usr/local/lib")
elseif(UNIX)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()

set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)

# Put RUNTIME and LIBRARY outputs into a folder where we can run them without installing
Expand Down
40 changes: 40 additions & 0 deletions assets/scripts/tests/scene-reload.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
x.PhysicsFPS 120
g.LogicFPS 120
loadscene test1
screenshot reload-before1.png
stepgraphics
steplogic
stepphysics
stepgraphics 120
screenshot reload-before2.png
stepgraphics
assert_position test1:animbox 0 1.5 -4.875

reloadscene
screenshot reload-after1.png
stepgraphics
assert_position test1:animbox 0 1.5 -4.875
steplogic
stepphysics
stepgraphics

reloadscene
reloadscene
reloadscene
reloadscene
screenshot reload-after2.png
stepgraphics
assert_position test1:animbox 0 1.5 -4.875
steplogic 2700
stepphysics 2
stepgraphics 120
screenshot reload-after3.png
stepgraphics
assert_position test1:animbox 0 1.5 -4.875
stepphysics 120
assert_position test1:animbox 0 2 -4.875
stepphysics 120
assert_position test1:animbox 0 5 -4.875
stepgraphics 120
screenshot reload-after4.png
stepgraphics
7 changes: 7 additions & 0 deletions shaders/lib/util.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ vec2 bilinearMix(vec2 v00, vec2 v10, vec2 v01, vec2 v11, vec2 alpha) {
return mix(x1, x2, alpha.y);
}

uint FlattenIndex(ivec3 pos, ivec3 gridSize) {
uint x = pos.x;
uint y = pos.y * gridSize.x;
uint z = pos.z * gridSize.x * gridSize.y;
return x + y + z;
}

#include "color_util.glsl"
#include "spatial_util.glsl"

Expand Down
14 changes: 14 additions & 0 deletions shaders/lib/voxel_trace_debug.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@

#extension GL_EXT_nonuniform_qualifier : enable

uint FlattenIndex2(ivec3 pos, ivec3 gridSize) {
uint x = pos.x;
uint y = pos.y * gridSize.x;
uint z = pos.z * gridSize.x * gridSize.y;
return x + y + z;
}
float GetVoxelNearest(vec3 position, int level, out vec3 radiance) {
// uint count = imageLoad(fillCounters, ivec3(position)).r;
// int fillIndex = int(position.x) * voxelInfo.gridSize.y * voxelInfo.gridSize.z + int(position.y) * voxelInfo.gridSize.z + int(position.z);
// uint count = fillCounters[fillIndex];
vec4 radianceData = texelFetch(voxelRadiance, ivec3(position) >> level, level);
vec4 normalData = texelFetch(voxelNormals, ivec3(position) >> level, level);
// radiance = vec3(length(normalData.xyz / normalData.w));
radiance = radianceData.rgb; // abs(normalData.xyz);
// radiance = vec3(count);
return radianceData.a;
}

float GetVoxelNearest2(vec3 position, vec3 dir, out vec3 radiance) {
uint count = fillCounters[FlattenIndex(ivec3(position), voxelInfo.gridSize)]; //imageLoad(fillCounters, ivec3(position)).r;
int axis = DominantAxis(dir);
if (axis < 0) {
axis = -axis + 2;
Expand All @@ -28,6 +38,10 @@ float GetVoxelNearest2(vec3 position, vec3 dir, out vec3 radiance) {
}
vec4 voxelData = texelFetch(voxelLayers[axis], ivec3(position), 0);
radiance = voxelData.rgb;
/*float hits = count / 1.0;
radiance.x = hits;
radiance.y = hits;
radiance.z = hits;*/
return voxelData.a;
}

Expand Down
2 changes: 1 addition & 1 deletion shaders/vulkan/lib/exposure_state.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

buffer ExposureState {
readonly buffer ExposureState {
float exposure;
};
7 changes: 5 additions & 2 deletions shaders/vulkan/voxel_debug.frag
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ INCLUDE_LAYOUT(binding = 2)
#include "lib/exposure_state.glsl"

layout(binding = 3) uniform sampler2DArray overlayTex;
layout(binding = 4, r32ui) readonly uniform uimage3D fillCounters;
// layout(binding = 4, r32ui) readonly uniform uimage3D fillCounters;
layout(std430, binding = 4) readonly buffer FillCounters {
uint fillCounters[];
};
layout(binding = 5) uniform sampler3D voxelRadiance;
layout(binding = 6) uniform sampler3D voxelNormals;

layout(set = 1, binding = 0) uniform sampler3D voxelLayers[6];

layout(constant_id = 0) const int DEBUG_MODE = 0;
layout(constant_id = 0) const int DEBUG_MODE = 1;
layout(constant_id = 1) const float BLEND_WEIGHT = 0;
layout(constant_id = 2) const int VOXEL_MIP = 0;

Expand Down
10 changes: 8 additions & 2 deletions shaders/vulkan/voxel_fill.frag
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ layout(set = 2, binding = 0) uniform sampler2D textures[];

#include "../lib/shading.glsl"

layout(binding = 4, r32ui) uniform uimage3D fillCounters;
// layout(binding = 4, r32ui) uniform uimage3D fillCounters;
layout(std430, binding = 4) buffer FillCounters {
uint fillCounters[];
};
layout(binding = 5, rgba16f) writeonly uniform image3D radianceOut;
layout(binding = 6, rgba16f) writeonly uniform image3D normalsOut;

Expand Down Expand Up @@ -103,8 +106,11 @@ void main() {
pixelRadiance = clamp(pixelRadiance, vec3(-8192), vec3(8192));
}

uint bucket = min(FRAGMENT_LIST_COUNT - 1, imageAtomicAdd(fillCounters, ivec3(inVoxelPos), 1));
// uint bucket = min(FRAGMENT_LIST_COUNT - 1, imageAtomicAdd(fillCounters, ivec3(inVoxelPos), 1));
int fillIndex = int(inVoxelPos.x) * voxelInfo.gridSize.y * voxelInfo.gridSize.z + int(inVoxelPos.y) * voxelInfo.gridSize.z + int(inVoxelPos.z);
uint bucket = min(FRAGMENT_LIST_COUNT - 1, atomicAdd(fillCounters[fillIndex], 1));
uint index = atomicAdd(fragmentListMetadata[bucket].count, 1);

if (index >= fragmentListMetadata[bucket].capacity) return;
if (index % MipmapWorkGroupSize == 0) atomicAdd(fragmentListMetadata[bucket].cmd.x, 1);

Expand Down
4 changes: 2 additions & 2 deletions shaders/vulkan/voxel_fill_layer.comp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ layout(binding = 0) uniform VoxelStateUniform {
VoxelState voxelInfo;
};

layout(std430, binding = 1) buffer VoxelFragmentListMetadata {
layout(std430, binding = 1) readonly buffer VoxelFragmentListMetadata {
uint count;
uint capacity;
uint offset;
VkDispatchIndirectCommand cmd;
};

layout(std430, binding = 2) buffer VoxelFragmentList {
layout(std430, binding = 2) readonly buffer VoxelFragmentList {
VoxelFragment fragmentLists[];
};

Expand Down
4 changes: 2 additions & 2 deletions shaders/vulkan/voxel_merge.comp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ layout(local_size_x = 16, local_size_y = 16) in;
layout(binding = 0, rgba16f) uniform image3D voxelRadiance;
layout(binding = 1, rgba16f) uniform image3D voxelNormals;

layout(std430, binding = 2) buffer VoxelFragmentListMetadata {
layout(std430, binding = 2) readonly buffer VoxelFragmentListMetadata {
uint count;
uint capacity;
uint offset;
VkDispatchIndirectCommand cmd;
};

layout(std430, binding = 3) buffer VoxelFragmentList {
layout(std430, binding = 3) readonly buffer VoxelFragmentList {
VoxelFragment fragmentLists[]; // Already bound at +offset
};

Expand Down
4 changes: 2 additions & 2 deletions shaders/vulkan/voxel_merge_layer.comp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ layout(binding = 0) uniform VoxelStateUniform {
VoxelState voxelInfo;
};

layout(std430, binding = 1) buffer VoxelFragmentListMetadata {
layout(std430, binding = 1) readonly buffer VoxelFragmentListMetadata {
uint count;
uint capacity;
uint offset;
VkDispatchIndirectCommand cmd;
};

layout(std430, binding = 2) buffer VoxelFragmentList {
layout(std430, binding = 2) readonly buffer VoxelFragmentList {
VoxelFragment fragmentLists[]; // Already bound at +offset
};

Expand Down
4 changes: 2 additions & 2 deletions shaders/vulkan/voxel_merge_layer_serial.comp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ layout(binding = 0) uniform VoxelStateUniform {
VoxelState voxelInfo;
};

layout(std430, binding = 1) buffer VoxelFragmentListMetadata {
layout(std430, binding = 1) readonly buffer VoxelFragmentListMetadata {
uint count;
uint capacity;
uint offset;
VkDispatchIndirectCommand cmd;
};

layout(std430, binding = 2) buffer VoxelFragmentList {
layout(std430, binding = 2) readonly buffer VoxelFragmentList {
VoxelFragment fragmentLists[]; // Already bound at +offset
};

Expand Down
20 changes: 14 additions & 6 deletions shaders/vulkan/voxel_merge_serial.comp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,32 @@
layout(local_size_x = 1, local_size_y = 1) in;

#include "../lib/voxel_shared.glsl"
#include "../lib/types_common.glsl"

layout(binding = 0, rgba16f) uniform image3D voxelRadiance;
layout(binding = 1, rgba16f) uniform image3D voxelNormals;

layout(std430, binding = 2) buffer VoxelFragmentListMetadata {
layout(std430, binding = 2) readonly buffer VoxelFragmentListMetadata {
uint count;
uint capacity;
uint offset;
VkDispatchIndirectCommand cmd;
};

layout(std430, binding = 3) buffer VoxelFragmentList {
layout(std430, binding = 3) readonly buffer VoxelFragmentList {
VoxelFragment fragmentList[];
};

layout(binding = 4, r32ui) uniform uimage3D fillCounters;
// layout(binding = 4, r32ui) uniform uimage3D fillCounters;
layout(std430, binding = 4) readonly buffer FillCounters {
uint fillCounters[];
};

layout(binding = 8) uniform VoxelStateUniform {
VoxelState voxelInfo;
};

#include "../lib/types_common.glsl"
#include "../lib/util.glsl"
#include "../lib/voxel_shared.glsl"

layout(constant_id = 0) const int FRAGMENT_LIST_COUNT = 1;

Expand All @@ -41,7 +47,9 @@ void main() {
vec4 existingRadiance = imageLoad(voxelRadiance, position);
vec4 existingNormal = imageLoad(voxelNormals, position);

uint overflowCount = imageLoad(fillCounters, position).r - FRAGMENT_LIST_COUNT + 1;
// uint overflowCount = imageLoad(fillCounters, position).r - FRAGMENT_LIST_COUNT + 1;
int fillIndex = int(position.x) * voxelInfo.gridSize.y * voxelInfo.gridSize.z + int(position.y) * voxelInfo.gridSize.z + int(position.z);
uint overflowCount = fillCounters[fillIndex] - FRAGMENT_LIST_COUNT + 1;
float weight = 1.0f / (FRAGMENT_LIST_COUNT + existingRadiance.w - 1);
// isNotLast = true if existingRadiance.w - 1 < overflowCount
float isNotLast = 1 - step(overflowCount, existingRadiance.w - 1);
Expand Down
2 changes: 2 additions & 0 deletions src/codegen/gen_common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ std::string TypeToString() {

auto typeStart = charStart;
auto embeddingSignature = EmbedTypeIntoSignature<T>();

auto structStart = embeddingSignature.find("struct ", charStart);
if (structStart == charStart) typeStart += "struct "s.size();

Expand All @@ -84,6 +85,7 @@ std::string TypeToString() {

auto typeStart = charStart;
auto embeddingSignature = EmbedTypeIntoSignature<T>();

auto enumStart = embeddingSignature.find("enum ", charStart);
if (enumStart == charStart) typeStart += "enum "s.size();
auto classStart = embeddingSignature.find("class ", charStart);
Expand Down
1 change: 1 addition & 0 deletions src/core/console/ConsoleTracy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "console/Console.hh"

#include <unistd.h>
#ifdef _WIN32
#include <windows.h>
#else
Expand Down
6 changes: 3 additions & 3 deletions src/core/ecs/EventQueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ namespace ecs {
return true;
}

bool EventQueue::Add(const Event &event, size_t transactionId) {
bool EventQueue::Add(const Event &event, uint64_t transactionId) {
AsyncEvent asyncEvent(event.name, event.source, event.data);
asyncEvent.transactionId = transactionId;
return Add(asyncEvent);
}

bool EventQueue::Poll(Event &eventOut, size_t transactionId) {
bool EventQueue::Poll(Event &eventOut, uint64_t transactionId) {
bool outputSet = false;
while (!outputSet) {
State s = state.load();
Expand Down Expand Up @@ -291,7 +291,7 @@ namespace ecs {
return s.head == s.tail;
}

size_t EventQueue::Size() {
uint32_t EventQueue::Size() {
State s = state.load();
if (s.head > s.tail) {
return s.tail + events.size() - s.head;
Expand Down
10 changes: 5 additions & 5 deletions src/core/ecs/EventQueue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ namespace ecs {
Entity source;
sp::AsyncPtr<EventData> data;

size_t transactionId = 0;
uint64_t transactionId = 0;

AsyncEvent() {}
AsyncEvent(std::string_view name, const Entity &source, const sp::AsyncPtr<EventData> &data)
Expand Down Expand Up @@ -280,16 +280,16 @@ namespace ecs {
// Returns false if the queue is full
bool Add(const AsyncEvent &event);
// Returns false if the queue is full
bool Add(const Event &event, size_t transactionId = 0);
bool Add(const Event &event, uint64_t transactionId = 0);

// Returns false if the queue is empty
bool Poll(Event &eventOut, size_t transactionId = 0);
bool Poll(Event &eventOut, uint64_t transactionId = 0);

bool Empty();
void Clear();
size_t Size();
uint32_t Size();

size_t Capacity() const {
uint32_t Capacity() const {
return events.size();
}

Expand Down
1 change: 1 addition & 0 deletions src/core/ecs/StructMetadata.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace ecs {

template<typename T>
static inline TypeInfo Lookup() {
// Logf("Lookup: %s", typeid(T).name());
using StrippedT = std::remove_pointer_t<std::decay_t<T>>;
return TypeInfo{
.typeIndex = GetFieldTypeIndex(typeid(std::conditional_t<std::is_function_v<StrippedT>, T, StrippedT>)),
Expand Down
4 changes: 2 additions & 2 deletions src/core/ecs/components/Events.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace ecs {
* A transactionId can be provided to synchronize event visibility with transactions.
* If no transactionId is provided, this event will be immediately visible to all transactions.
*/
size_t Add(const Event &event, size_t transactionId = 0) const;
size_t Add(const AsyncEvent &event) const;
uint64_t Add(const Event &event, uint64_t transactionId = 0) const;
uint64_t Add(const AsyncEvent &event) const;
static bool Poll(Lock<Read<EventInput>> lock, const EventQueueRef &queue, Event &eventOut);

robin_hood::unordered_map<EventName, std::vector<EventQueueWeakRef>, sp::StringHash, sp::StringEqual> events;
Expand Down
3 changes: 0 additions & 3 deletions src/game/game/SceneManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "assets/JsonHelpers.hh"
#include "common/Logging.hh"
#include "common/Tracing.hh"
#include "console/Console.hh"
#include "console/ConsoleBindingManager.hh"
#include "ecs/EcsImpl.hh"
#include "ecs/EntityReferenceManager.hh"
#include "ecs/ScriptManager.hh"
Expand All @@ -23,7 +21,6 @@

#include <algorithm>
#include <filesystem>
#include <fstream>
#include <glm/glm.hpp>
#include <picojson.h>
#include <robin_hood.h>
Expand Down
Loading