Skip to content

Commit

Permalink
general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Jan 30, 2025
1 parent ed5b4a0 commit ec5758f
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 281 deletions.
15 changes: 7 additions & 8 deletions WickedEngine/shaders/ShaderInterop_Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,15 +653,18 @@ struct alignas(16) ShaderTransform

struct alignas(16) ShaderMeshInstance
{
uint uid;
uint64_t uid;
uint flags; // high 8 bits: user stencilRef
uint layerMask;
uint meshletOffset; // offset in the global meshlet buffer for first subset (for LOD0)

uint geometryOffset; // offset of all geometries for currently active LOD
uint geometryCount; // number of all geometries in currently active LOD
uint meshletOffset; // offset in the global meshlet buffer for first subset (for LOD0)
uint geometryOffset; // offset of all geometries for currently active LOD
uint geometryCount; // number of all geometries in currently active LOD
uint baseGeometryOffset; // offset of all geometries of the instance (if no LODs, then it is equal to geometryOffset)

uint2 rimHighlight; // packed half4
uint baseGeometryCount; // number of all geometries of the instance (if no LODs, then it is equal to geometryCount)
float fadeDistance;

uint2 color; // packed half4
uint2 emissive; // packed half4
Expand All @@ -671,10 +674,6 @@ struct alignas(16) ShaderMeshInstance
int lightmap;
uint alphaTest_size; // packed half2

uint2 rimHighlight; // packed half4
float fadeDistance;
float padding;

float3 center;
float radius;

Expand Down
5 changes: 2 additions & 3 deletions WickedEngine/shaders/ShaderInterop_SurfelGI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ struct Surfel
// This per-surfel structure will store all additional persistent data per surfel that isn't needed at GI lookup
struct SurfelData
{
uint64_t uid;
uint2 primitiveID;
uint bary;
uint uid;

uint bary;
uint raydata; // 24bit rayOffset, 8bit rayCount
uint properties; // 8bit life frames, 8bit recycle frames, 1bit backface normal
float max_inconsistency;
int padding1;

inline uint GetRayOffset() { return raydata & 0xFFFFFF; }
inline uint GetRayCount() { return (raydata >> 24u) & 0xFF; }
Expand Down
18 changes: 12 additions & 6 deletions WickedEngine/wiECS.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ namespace wi::ecs
// The Entity is a global unique persistent identifier within the entity-component system
// It can be stored and used for the duration of the application
// The entity can be a different value on a different run of the application, if it was serialized
// It must be only serialized with the SerializeEntity() function. It will ensure that entities still match with their components correctly after serialization
using Entity = uint32_t;
inline constexpr Entity INVALID_ENTITY = 0;
// It must be only serialized with the SerializeEntity() function if persistence is needed across different program runs,
// this will ensure that entities still match with their components correctly after serialization
using Entity = uint64_t;
inline static constexpr Entity INVALID_ENTITY = 0;
// Runtime can create a new entity with this
inline Entity CreateEntity()
{
Expand Down Expand Up @@ -142,9 +143,14 @@ namespace wi::ecs
// reservedCount : how much components can be held initially before growing the container
ComponentManager(size_t reservedCount = 0)
{
components.reserve(reservedCount);
entities.reserve(reservedCount);
lookup.reserve(reservedCount);
Reserve(reservedCount);
}

inline void Reserve(size_t count)
{
components.reserve(count);
entities.reserve(count);
lookup.reserve(count);
}

// Clear the whole container
Expand Down
6 changes: 3 additions & 3 deletions WickedEngine/wiHairParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace wi
wi::graphics::CommandList cmd
);

mutable bool gpu_initialized = false;
void InitializeGPUDataIfNeeded(wi::graphics::CommandList cmd);

void Draw(
Expand All @@ -69,6 +68,8 @@ namespace wi
wi::graphics::CommandList cmd
) const;

wi::ecs::Entity meshID = wi::ecs::INVALID_ENTITY;

enum FLAGS
{
EMPTY = 0,
Expand All @@ -78,8 +79,6 @@ namespace wi
};
uint32_t _flags = EMPTY;

wi::ecs::Entity meshID = wi::ecs::INVALID_ENTITY;

uint32_t strandCount = 0;
uint32_t segmentCount = 1;
uint32_t randomSeed = 1;
Expand All @@ -106,6 +105,7 @@ namespace wi
mutable bool regenerate_frame = true;
wi::graphics::Format position_format = wi::graphics::Format::R16G16B16A16_UNORM;
mutable bool must_rebuild_blas = true;
mutable bool gpu_initialized = false;

void Serialize(wi::Archive& archive, wi::ecs::EntitySerializer& seri);

Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4417,7 +4417,7 @@ namespace wi::scene
const float dist = std::sqrt(distsq);
const float dist_to_sphere = dist - radius;
object.lod = uint32_t(dist_to_sphere * object.lod_distance_multiplier);
object.lod = std::min(object.lod, mesh.GetLODCount() - 1);
object.lod = std::min(object.lod, uint16_t(mesh.GetLODCount() - 1));
}
}

Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiScene_BindLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4796,7 +4796,7 @@ int MeshComponent_BindLua::SetMeshSubsetMaterialID(lua_State* L)
if (argc >= 2)
{
size_t subsetindex = (uint32_t)wi::lua::SGetLongLong(L, 1);
Entity entity = (uint32_t)wi::lua::SGetLongLong(L, 2);
Entity entity = (Entity)wi::lua::SGetLongLong(L, 2);

const uint32_t lod_count = component->GetLODCount();
for (uint32_t lod = 0; lod < lod_count; ++lod)
Expand Down
Loading

0 comments on commit ec5758f

Please sign in to comment.