From 899ffdbb3dfdd3424fe2bbf69731ebb2623892ba Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Sun, 16 Feb 2020 13:07:20 +0100 Subject: [PATCH] cleanup --- .github/workflows/build.yml | 2 +- src/animation/editor/controller_editor.cpp | 4 +- src/animation/property_animation.cpp | 4 +- src/editor/profiler_ui.cpp | 2 +- src/engine/lua_api.cpp | 2 +- src/engine/page_allocator.cpp | 4 +- src/engine/reflection.h | 4 +- src/engine/win/debug.cpp | 8 ++-- src/engine/win/os.cpp | 2 +- src/gui/gui_scene.cpp | 3 ++ src/lua_script/lua_script_system.cpp | 4 +- src/physics/physics_scene.cpp | 2 +- src/renderer/editor/fbx_importer.cpp | 20 +++++----- src/renderer/editor/ofbx.cpp | 5 +-- src/renderer/editor/plugins.cpp | 10 ++--- src/renderer/gpu/gpu.cpp | 4 +- src/renderer/gpu/gpu.h | 5 ++- src/renderer/particle_system.cpp | 46 +++++++++++----------- src/renderer/particle_system.h | 2 +- src/renderer/pipeline.cpp | 42 ++++++++++++++------ src/renderer/pipeline.h | 6 +-- src/renderer/terrain.cpp | 2 +- src/renderer/texture.cpp | 2 +- 23 files changed, 100 insertions(+), 85 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 890aa9d84..bb067080d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,4 +62,4 @@ jobs: cd tmp/gmake pvs-studio-analyzer trace -- make -j EXTRA_WARNINGS=1 pvs-studio-analyzer analyze -e ../../../src/renderer/editor/miniz.c -e ../../../external -l ../../../pvs-studio.lic -o pvs-studio.log - plog-converter -a 'GA:1,2;OP:1' -d V730 -t errorfile -w pvs-studio.log + plog-converter -a 'GA:1,2;OP:1' -d V730,V1001 -t errorfile -w pvs-studio.log diff --git a/src/animation/editor/controller_editor.cpp b/src/animation/editor/controller_editor.cpp index cb7b9a1ed..4725249e9 100644 --- a/src/animation/editor/controller_editor.cpp +++ b/src/animation/editor/controller_editor.cpp @@ -476,7 +476,7 @@ void ControllerEditor::onWindowGUI() { } ImGui::EndCombo(); } - for (u32 j = ik.bones_count - 2; j != 0xffFFffFF; --j) { + for (u32 j = ik.bones_count - 2; j != 0xffFFffFF; --j) { //-V621 auto iter = m_model->getBoneIndex(ik.bones[j]); if (iter.isValid()) { ImGui::Text("%s", m_model->getBone(iter.value()).name.c_str()); @@ -516,7 +516,7 @@ void ControllerEditor::onWindowGUI() { } } - if (m_controller->m_ik_count < (u32)lengthOf(m_controller->m_ik->bones) && ImGui::Button("Add chain")) { + if (m_controller->m_ik_count < (u32)lengthOf(m_controller->m_ik[0].bones) && ImGui::Button("Add chain")) { m_controller->m_ik[m_controller->m_ik_count].bones_count = 1; m_controller->m_ik[m_controller->m_ik_count].bones[0] = 0; ++m_controller->m_ik_count; diff --git a/src/animation/property_animation.cpp b/src/animation/property_animation.cpp index 04f94b4c2..fc3f82f61 100644 --- a/src/animation/property_animation.cpp +++ b/src/animation/property_animation.cpp @@ -68,8 +68,8 @@ bool PropertyAnimation::load(u64 size, const u8* mem) curve.frames.resize(keys_count); curve.values.resize(keys_count); for (int j = 0; j < keys_count; ++j) { - serializer.read(Ref(curve.frames[i])); - serializer.read(Ref(curve.values[i])); + serializer.read(Ref(curve.frames[j])); + serializer.read(Ref(curve.values[j])); } } return true; diff --git a/src/editor/profiler_ui.cpp b/src/editor/profiler_ui.cpp index 419546c6d..19b15278c 100644 --- a/src/editor/profiler_ui.cpp +++ b/src/editor/profiler_ui.cpp @@ -718,7 +718,7 @@ void ProfilerUIImpl::onGUICPUProfiler() const u32 color = header.type == Profiler::EventType::END_FIBER_WAIT ? 0xffff0000 : 0xff00ff00; dl->AddRect(ImVec2(x - 2, y - 2), ImVec2(x + 2, y + 2), color); const bool mouse_hovered = ImGui::IsMouseHoveringRect(ImVec2(x - 2, y - 2), ImVec2(x + 2, y + 2)); - if (mouse_hovered || is_begin && hovered_signal.signal == r.job_system_signal) { + if (mouse_hovered || (is_begin && hovered_signal.signal == r.job_system_signal)) { hovered_signal.signal = r.job_system_signal; hovered_signal.x = x; hovered_signal.y = y; diff --git a/src/engine/lua_api.cpp b/src/engine/lua_api.cpp index e562a1fb6..9dfc8750c 100644 --- a/src/engine/lua_api.cpp +++ b/src/engine/lua_api.cpp @@ -872,7 +872,7 @@ static int LUA_instantiatePrefab(lua_State* L) if (!prefab) { luaL_argerror(L, 4, "Unknown prefab."); } - if (!prefab->isReady()) { + if (!prefab->isReady()) { //-V1004 luaL_error(L, "Prefab '%s' is not ready, preload it.", prefab->getPath().c_str()); } EntityMap entity_map(engine->getAllocator()); diff --git a/src/engine/page_allocator.cpp b/src/engine/page_allocator.cpp index 31edd84eb..b7f333b02 100644 --- a/src/engine/page_allocator.cpp +++ b/src/engine/page_allocator.cpp @@ -15,7 +15,7 @@ PageAllocator::~PageAllocator() void* p = free_pages; while (p) { void* tmp = p; - memcpy(&p, p, sizeof(p)); + memcpy(&p, p, sizeof(p)); //-V579 OS::memRelease(tmp); } } @@ -39,7 +39,7 @@ void* PageAllocator::allocate(bool lock) ++allocated_count; if (free_pages) { void* tmp = free_pages; - memcpy(&free_pages, free_pages, sizeof(free_pages)); + memcpy(&free_pages, free_pages, sizeof(free_pages)); //-V579 if (lock) mutex.exit(); return tmp; } diff --git a/src/engine/reflection.h b/src/engine/reflection.h index 84cc24dcf..87f0d7f2c 100644 --- a/src/engine/reflection.h +++ b/src/engine/reflection.h @@ -717,7 +717,7 @@ struct ConstArrayProperty : IArrayProperty void addItem(ComponentUID cmp, int index) const override { ASSERT(false); } - void removeItem(ComponentUID cmp, int index) const override { ASSERT(false); } + void removeItem(ComponentUID cmp, int index) const override { ASSERT(false); } //-V524 int getCount(ComponentUID cmp) const override @@ -763,7 +763,7 @@ namespace internal #if defined(_MSC_VER) && !defined(__clang__) static const size_t size = sizeof(__FUNCTION__) - FRONT_SIZE - BACK_SIZE; static char typeName[size] = {}; - memcpy(typeName, __FUNCTION__ + FRONT_SIZE, size - 1u); + memcpy(typeName, __FUNCTION__ + FRONT_SIZE, size - 1u); //-V594 #else static const size_t size = sizeof(__PRETTY_FUNCTION__) - FRONT_SIZE - BACK_SIZE; static char typeName[size] = {}; diff --git a/src/engine/win/debug.cpp b/src/engine/win/debug.cpp index a2c13b599..90cc57e78 100644 --- a/src/engine/win/debug.cpp +++ b/src/engine/win/debug.cpp @@ -128,7 +128,7 @@ StackNode* StackTree::getParent(StackNode* node) bool StackTree::getFunction(StackNode* node, Span out, Ref line) { HANDLE process = GetCurrentProcess(); - u8 symbol_mem[sizeof(SYMBOL_INFO) + 256 * sizeof(char)] = {}; + alignas(SYMBOL_INFO) u8 symbol_mem[sizeof(SYMBOL_INFO) + 256 * sizeof(char)] = {}; SYMBOL_INFO* symbol = reinterpret_cast(symbol_mem); symbol->MaxNameLen = 255; symbol->SizeOfStruct = sizeof(SYMBOL_INFO); @@ -154,7 +154,7 @@ void StackTree::printCallstack(StackNode* node) while (node) { HANDLE process = GetCurrentProcess(); - u8 symbol_mem[sizeof(SYMBOL_INFO) + 256 * sizeof(char)]; + alignas(SYMBOL_INFO) u8 symbol_mem[sizeof(SYMBOL_INFO) + 256 * sizeof(char)]; SYMBOL_INFO* symbol = reinterpret_cast(symbol_mem); memset(symbol_mem, 0, sizeof(symbol_mem)); symbol->MaxNameLen = 255; @@ -298,7 +298,7 @@ void Allocator::checkLeaks() AllocationInfo* info = m_root; while (info != last_sentinel) { - StaticString<2048> tmp("\nAllocation size : ", info->size, " , memory ", (u64)(info + sizeof(info)), "\n"); + StaticString<2048> tmp("\nAllocation size : ", info->size, " , memory ", (u64)(info + sizeof(info)), "\n"); //-V568 OutputDebugString(tmp); m_stack_tree.printCallstack(info->stack_leaf); info = info->next; @@ -677,7 +677,7 @@ static void getStack(CONTEXT& context, Span out) { BOOL result; STACKFRAME64 stack; - char symbol_mem[sizeof(IMAGEHLP_SYMBOL64) + 256]; + alignas(IMAGEHLP_SYMBOL64) char symbol_mem[sizeof(IMAGEHLP_SYMBOL64) + 256]; IMAGEHLP_SYMBOL64* symbol = (IMAGEHLP_SYMBOL64*)symbol_mem; char name[256]; copyString(out, "Crash callstack:\n"); diff --git a/src/engine/win/os.cpp b/src/engine/win/os.cpp index 9a160e30a..2f7596e49 100644 --- a/src/engine/win/os.cpp +++ b/src/engine/win/os.cpp @@ -356,7 +356,7 @@ static void processEvents() HRAWINPUT hRawInput = (HRAWINPUT)msg.lParam; UINT dataSize; GetRawInputData(hRawInput, RID_INPUT, NULL, &dataSize, sizeof(RAWINPUTHEADER)); - char dataBuf[1024]; + alignas(RAWINPUT) char dataBuf[1024]; if (dataSize == 0 || dataSize > sizeof(dataBuf)) break; GetRawInputData(hRawInput, RID_INPUT, dataBuf, &dataSize, sizeof(RAWINPUTHEADER)); diff --git a/src/gui/gui_scene.cpp b/src/gui/gui_scene.cpp index 230d87fe3..7fc9efeed 100644 --- a/src/gui/gui_scene.cpp +++ b/src/gui/gui_scene.cpp @@ -808,6 +808,9 @@ struct GUISceneImpl final : public GUIScene handleKeyboardButtonEvent(event); } break; + case InputSystem::Event::DEVICE_ADDED: + case InputSystem::Event::DEVICE_REMOVED: + break; } } } diff --git a/src/lua_script/lua_script_system.cpp b/src/lua_script/lua_script_system.cpp index e263fed7e..e86555d3f 100644 --- a/src/lua_script/lua_script_system.cpp +++ b/src/lua_script/lua_script_system.cpp @@ -273,7 +273,7 @@ namespace Lumix lua_setfenv(script.m_state, -2); m_scene.m_current_script_instance = &script; - errors = errors || lua_pcall(script.m_state, 0, 0, 0) != 0; // [env] + errors = lua_pcall(script.m_state, 0, 0, 0) != 0; // [env] if (errors) { logError("Lua Script") << script.m_script->getPath() << ": " @@ -999,7 +999,7 @@ namespace Lumix ASSERT(lua_type(script.m_state, -1) == LUA_TTABLE); lua_setfenv(script.m_state, -2); - errors = errors || lua_pcall(state, 0, 0, 0) != 0; + errors = lua_pcall(state, 0, 0, 0) != 0; if (errors) { diff --git a/src/physics/physics_scene.cpp b/src/physics/physics_scene.cpp index f684c6ff6..2ead69270 100644 --- a/src/physics/physics_scene.cpp +++ b/src/physics/physics_scene.cpp @@ -3052,7 +3052,7 @@ struct PhysicsSceneImpl final : public PhysicsScene for (int i = index; i < count; ++i) { PxShape* shape = getShape(entity, i, type); - shape->userData = (void*)(intptr_t)(i + 1); + shape->userData = (void*)(intptr_t)(i + 1); //-V1028 } } diff --git a/src/renderer/editor/fbx_importer.cpp b/src/renderer/editor/fbx_importer.cpp index e1b61a067..3abfdd21c 100644 --- a/src/renderer/editor/fbx_importer.cpp +++ b/src/renderer/editor/fbx_importer.cpp @@ -508,7 +508,7 @@ void FBXImporter::postprocessMeshes(const ImportConfig& cfg, const char* path) Array subblobs(allocator); subblobs.reserve(vertex_count); - const int* materials = geom->getMaterials(); + const int* geom_materials = geom->getMaterials(); Array computed_tangents(allocator); if (!tangents && normals && uvs) { computeTangents(computed_tangents, vertex_count, vertices, normals, uvs); @@ -517,7 +517,7 @@ void FBXImporter::postprocessMeshes(const ImportConfig& cfg, const char* path) for (int i = 0; i < vertex_count; ++i) { - if (materials && materials[i / 3] != material_idx) continue; + if (geom_materials && geom_materials[i / 3] != material_idx) continue; blob.clear(); ofbx::Vec3 cp = vertices[i]; @@ -576,7 +576,7 @@ static int detectMeshLOD(const FBXImporter::ImportMesh& mesh) { char mesh_name[256]; FBXImporter::getImportMeshName(mesh, mesh_name); - const char* lod_str = stristr(mesh_name, "_LOD"); + lod_str = stristr(mesh_name, "_LOD"); if (!lod_str) return 0; } @@ -1132,7 +1132,7 @@ static void fill(const ofbx::Object& bone, double anim_len, const ofbx::Animatio static bool shouldSample(u32 keyframe_count, float anim_len, float fps, u32 data_size) { const u32 sampled_frame_count = u32(anim_len * fps); const u32 sampled_size = sampled_frame_count * data_size; - const u32 time_size = sizeof(sizeof(u16)); + const u32 time_size = sizeof(u16); const u32 keyframed_size = keyframe_count * (data_size + time_size); // * 4 / 3 -> prefer sampled even when a bit bigger, since sampled tracks are faster @@ -1189,19 +1189,19 @@ void FBXImporter::writeAnimations(const char* src, const ImportConfig& cfg) const ofbx::AnimationStack* stack = anim.fbx; const ofbx::AnimationLayer* layer = stack->getLayer(0); - const ofbx::IScene& scene = *anim.scene; - const float fps = scene.getSceneFrameRate(); - const ofbx::TakeInfo* take_info = scene.getTakeInfo(stack->name); + ASSERT(anim.scene == scene); + const float fps = scene->getSceneFrameRate(); + const ofbx::TakeInfo* take_info = scene->getTakeInfo(stack->name); if(!take_info && startsWith(stack->name, "AnimStack::")) { - take_info = scene.getTakeInfo(stack->name + 11); + take_info = scene->getTakeInfo(stack->name + 11); } double anim_len; if (take_info) { anim_len = take_info->local_time_to - take_info->local_time_from; } - else if(scene.getGlobalSettings()) { - anim_len = scene.getGlobalSettings()->TimeSpanStop; + else if(scene->getGlobalSettings()) { + anim_len = scene->getGlobalSettings()->TimeSpanStop; } else { logError("Renderer") << "Unsupported animation in " << src; diff --git a/src/renderer/editor/ofbx.cpp b/src/renderer/editor/ofbx.cpp index 0fa46c00c..5dd7ba9b4 100644 --- a/src/renderer/editor/ofbx.cpp +++ b/src/renderer/editor/ofbx.cpp @@ -544,7 +544,7 @@ static OptionalError readProperty(Cursor* cursor) OptionalError length = read(cursor); OptionalError encoding = read(cursor); OptionalError comp_len = read(cursor); - if (length.isError() | encoding.isError() | comp_len.isError()) return Error(); + if (length.isError() | encoding.isError() | comp_len.isError()) return Error(); //-V792 if (cursor->current + comp_len.getValue() > cursor->end) return Error("Reading past the end"); cursor->current += comp_len.getValue(); break; @@ -984,7 +984,6 @@ struct MeshImpl : Mesh { MeshImpl(const Scene& _scene, const IElement& _element) : Mesh(_scene, _element) - , scene(_scene) { is_node = true; } @@ -1018,7 +1017,6 @@ struct MeshImpl : Mesh const Pose* pose = nullptr; const Geometry* geometry = nullptr; - const Scene& scene; std::vector materials; }; @@ -2315,7 +2313,6 @@ static OptionalError parseGeometryTangents( if (!layer_tangent_element ) { layer_tangent_element = findChild(element, "LayerElementTangent"); } - layer_tangent_element = findChild(element, "LayerElementTangent"); if (layer_tangent_element) { std::vector tmp; diff --git a/src/renderer/editor/plugins.cpp b/src/renderer/editor/plugins.cpp index eeb24c3e1..de50f859b 100644 --- a/src/renderer/editor/plugins.cpp +++ b/src/renderer/editor/plugins.cpp @@ -491,7 +491,7 @@ struct MaterialPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0, 0, 0, 0)); ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0, 0, 0, 0)); ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0)); - bool is_node_open = ImGui::TreeNodeEx((const void*)(intptr_t)(i + 1), + bool is_node_open = ImGui::TreeNodeEx((const void*)(intptr_t)(i + 1), //-V1028 ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_Framed, "%s", ""); @@ -674,7 +674,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin FBXImporter importer(plugin->m_app); AssetCompiler& compiler = plugin->m_app.getAssetCompiler(); - const char* path = data->path[0] == '/' ? data->path.data + 1 : data->path; + const char* path = data->path[0] == '/' ? data->path.data + 1 : data->path.data; importer.setSource(path, true); if(data->meta.split) { @@ -2656,7 +2656,7 @@ struct LightProbeGridPlugin final : public PropertyGrid::IPlugin { v.x = (&m_result[i].coefs[c0].x)[c00]; v.y = (&m_result[i].coefs[c1].x)[c10]; v.z = (&m_result[i].coefs[c2].x)[c20]; - v.w = (&m_result[i].coefs[c3].x)[c30]; + v.w = (&m_result[i].coefs[c3].x)[c30]; //-V557 file.write(&v, sizeof(v)); } } @@ -2891,7 +2891,7 @@ struct EnvironmentProbePlugin final : public PropertyGrid::IPlugin if (universe->hasComponent(job.entity, ENVIRONMENT_PROBE_TYPE)) { RenderScene* scene = (RenderScene*)universe->getScene(ENVIRONMENT_PROBE_TYPE); EnvironmentProbe& p = scene->getEnvironmentProbe(job.entity); - static_assert(sizeof(p.sh_coefs == job.sh.coefs)); + static_assert(sizeof(p.sh_coefs) == sizeof(job.sh.coefs)); memcpy(p.sh_coefs, job.sh.coefs, sizeof(p.sh_coefs)); } @@ -3252,7 +3252,7 @@ struct RenderInterfaceImpl final : public RenderInterfaceBase void addDebugCube(const DVec3& pos, const Vec3& dir, const Vec3& up, const Vec3& right, u32 color) override { - m_render_scene->addDebugCube(pos, dir, right, up, color); + m_render_scene->addDebugCube(pos, dir, up, right, color); } diff --git a/src/renderer/gpu/gpu.cpp b/src/renderer/gpu/gpu.cpp index 55a4381ce..83b3247ea 100644 --- a/src/renderer/gpu/gpu.cpp +++ b/src/renderer/gpu/gpu.cpp @@ -461,8 +461,6 @@ static LoadInfo* getDXT10LoadInfo(const Header& hdr, const DXT10Header& dxt10_hd { switch(dxt10_hdr.dxgi_format) { case DxgiFormat::B8G8R8A8_UNORM_SRGB: - return &loadInfoBGRA8; - break; case DxgiFormat::B8G8R8A8_UNORM: return &loadInfoBGRA8; break; @@ -2019,7 +2017,7 @@ bool createProgram(ProgramHandle prog, const VertexDecl& decl, const char** srcs case ShaderType::GEOMETRY: shader_type = GL_GEOMETRY_SHADER; break; case ShaderType::FRAGMENT: shader_type = GL_FRAGMENT_SHADER; break; case ShaderType::VERTEX: shader_type = GL_VERTEX_SHADER; break; - default: ASSERT(0); break; + default: ASSERT(false); return false; } const GLuint shd = glCreateShader(shader_type); combined_srcs[0] = R"#( diff --git a/src/renderer/gpu/gpu.h b/src/renderer/gpu/gpu.h index 2c6fbc5b5..9e041fb5a 100644 --- a/src/renderer/gpu/gpu.h +++ b/src/renderer/gpu/gpu.h @@ -286,9 +286,10 @@ inline u32 getBytesPerPixel(gpu::TextureFormat format) { return 8; case gpu::TextureFormat::RGBA32F: return 16; + default: + ASSERT(false); + return 0; } - ASSERT(false); - return 0; } } // namespace gpu diff --git a/src/renderer/particle_system.cpp b/src/renderer/particle_system.cpp index 77dfd093a..034dac277 100644 --- a/src/renderer/particle_system.cpp +++ b/src/renderer/particle_system.cpp @@ -469,7 +469,7 @@ void ParticleEmitter::emit(const float* args) ++m_particles_count; return; case Instructions::MOV: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); u8 dst_idx = blob.read(); ASSERT(dst_type == Compiler::DataStream::CHANNEL); const float value = readSingleValue(blob); @@ -477,7 +477,7 @@ void ParticleEmitter::emit(const float* args) break; } case Instructions::RAND: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); ASSERT(dst_type == Compiler::DataStream::CHANNEL); u8 dst_idx = blob.read(); @@ -569,7 +569,7 @@ static float4* getStream(const ParticleEmitter& emitter , float4* register_mem) { switch(type) { - case Compiler::DataStream::CHANNEL: return (float4*)emitter.getChannelData(idx); + case Compiler::DataStream::CHANNEL: return (float4*)emitter.getChannelData(idx); //-V1032 case Compiler::DataStream::REGISTER: return register_mem + particles_count * idx; default: ASSERT(false); return nullptr; } @@ -609,11 +609,11 @@ void ParticleEmitter::update(float dt) case Instructions::END: goto end; case Instructions::MUL: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto arg0_type = blob.read(); + const Compiler::DataStream::Type arg0_type = blob.read(); const u8 arg0_idx = blob.read(); - const auto arg1_type = blob.read(); + const Compiler::DataStream::Type arg1_type = blob.read(); const float4* arg0 = getStream(*this, arg0_type, arg0_idx, m_particles_count, reg_mem.begin()); float4* result = getStream(*this, dst_type, dst_idx, m_particles_count, reg_mem.begin()); @@ -637,9 +637,9 @@ void ParticleEmitter::update(float dt) break; } case Instructions::MOV: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto src_type = blob.read(); + const Compiler::DataStream::Type src_type = blob.read(); const u8 src_idx = blob.read(); float4* result = getStream(*this, dst_type, dst_idx, m_particles_count, reg_mem.begin()); @@ -663,11 +663,11 @@ void ParticleEmitter::update(float dt) break; } case Instructions::ADD: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto arg0_type = blob.read(); + const Compiler::DataStream::Type arg0_type = blob.read(); const u8 arg0_idx = blob.read(); - const auto arg1_type = blob.read(); + const Compiler::DataStream::Type arg1_type = blob.read(); const u8 arg1_idx = blob.read(); // TODO @@ -694,9 +694,9 @@ void ParticleEmitter::update(float dt) break; } case Instructions::COS: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto arg_type = blob.read(); + const Compiler::DataStream::Type arg_type = blob.read(); const u8 arg_idx = blob.read(); const float* arg = (float*)getStream(*this, arg_type, arg_idx, m_particles_count, reg_mem.begin()); @@ -709,9 +709,9 @@ void ParticleEmitter::update(float dt) break; } case Instructions::SIN: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto arg_type = blob.read(); + const Compiler::DataStream::Type arg_type = blob.read(); const u8 arg_idx = blob.read(); const float* arg = (float*)getStream(*this, arg_type, arg_idx, m_particles_count, reg_mem.begin()); @@ -772,9 +772,9 @@ void ParticleEmitter::fillInstanceData(const DVec3& cam_pos, float* data) case Instructions::END: return; case Instructions::SIN: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto arg_type = blob.read(); + const Compiler::DataStream::Type arg_type = blob.read(); const u8 arg_idx = blob.read(); const float* arg = (float*)getStream(*this, arg_type, arg_idx, m_particles_count, reg_mem.begin()) + offset; @@ -787,9 +787,9 @@ void ParticleEmitter::fillInstanceData(const DVec3& cam_pos, float* data) break; } case Instructions::COS: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto arg_type = blob.read(); + const Compiler::DataStream::Type arg_type = blob.read(); const u8 arg_idx = blob.read(); const float* arg = (float*)getStream(*this, arg_type, arg_idx, m_particles_count, reg_mem.begin()) + offset; @@ -802,11 +802,11 @@ void ParticleEmitter::fillInstanceData(const DVec3& cam_pos, float* data) break; } case Instructions::MUL: { - const auto dst_type = blob.read(); + const Compiler::DataStream::Type dst_type = blob.read(); const u8 dst_idx = blob.read(); - const auto arg0_type = blob.read(); + const Compiler::DataStream::Type arg0_type = blob.read(); const u8 arg0_idx = blob.read(); - const auto arg1_type = blob.read(); + const Compiler::DataStream::Type arg1_type = blob.read(); float4* result = getStream(*this, dst_type, dst_idx, m_particles_count, reg_mem.begin()) + (offset >> 2); const float4* arg0 = getStream(*this, arg0_type, arg0_idx, m_particles_count, reg_mem.begin()) + (offset >> 2); @@ -831,7 +831,7 @@ void ParticleEmitter::fillInstanceData(const DVec3& cam_pos, float* data) } case Instructions::OUTPUT: { const int stride = m_resource->getOutputsCount(); - const auto arg_type = blob.read(); + const Compiler::DataStream::Type arg_type = blob.read(); const u8 arg_idx = blob.read(); const float* arg = (float*)getStream(*this, arg_type, arg_idx, m_particles_count, reg_mem.begin()) + offset; float* dst = data + output_idx + offset * stride; diff --git a/src/renderer/particle_system.h b/src/renderer/particle_system.h index c1d8e782a..fedd8383b 100644 --- a/src/renderer/particle_system.h +++ b/src/renderer/particle_system.h @@ -74,7 +74,7 @@ public: private: struct Channel { - float* data = nullptr; + alignas(16) float* data = nullptr; u32 name = 0; }; diff --git a/src/renderer/pipeline.cpp b/src/renderer/pipeline.cpp index 5fc641fc9..358e3a433 100644 --- a/src/renderer/pipeline.cpp +++ b/src/renderer/pipeline.cpp @@ -1300,20 +1300,27 @@ struct PipelineImpl final : Pipeline lua_pop(L, 1); luaL_error(L, "Frustum is not a table"); } - float* points = cp.frustum.xs; if(!LuaWrapper::checkField(L, -1, "origin", &cp.frustum.origin)) { lua_pop(L, 1); luaL_error(L, "Frustum without origin"); } - for (int i = 0; i < 32 + 24; ++i) { - lua_rawgeti(L, -1, i + 1); - if(!LuaWrapper::isType(L, -1)) { - lua_pop(L, 2); - luaL_error(L, "Frustum must contain exactly 24 floats"); + auto load_floats = [L](float* data, int count, int offset) { + for (int i = 0; i < count; ++i) { + lua_rawgeti(L, -1, offset + i + 1); + if(!LuaWrapper::isType(L, -1)) { + lua_pop(L, 2); + luaL_error(L, "Invalid frustum"); + } + data[i] = LuaWrapper::toType(L, -1); + lua_pop(L, 1); } - points[i] = LuaWrapper::toType(L, -1); - lua_pop(L, 1); - } + }; + load_floats(cp.frustum.xs, (int)Frustum::Planes::COUNT, 0); + load_floats(cp.frustum.ys, (int)Frustum::Planes::COUNT, (int)Frustum::Planes::COUNT); + load_floats(cp.frustum.zs, (int)Frustum::Planes::COUNT, (int)Frustum::Planes::COUNT * 2); + load_floats(cp.frustum.ds, (int)Frustum::Planes::COUNT, (int)Frustum::Planes::COUNT * 3); + load_floats(&cp.frustum.points[0].x, 24, (int)Frustum::Planes::COUNT * 4); + lua_pop(L, 1); cp.frustum.setPlanesFromPoints(); @@ -1822,10 +1829,19 @@ struct PipelineImpl final : Pipeline lua_createtable(L, 32+24, 0); const float* frustum = params.frustum.xs; - for(int i = 0; i < 32+24; ++i) { - LuaWrapper::push(L, frustum[i]); - lua_rawseti(L, -2, i + 1); - } + auto push_floats = [L](const float* values, int count, int offset){ + for(int i = 0; i < count; ++i) { + LuaWrapper::push(L, values[i]); + lua_rawseti(L, -2, offset + i + 1); + } + }; + + push_floats(params.frustum.xs, (int)Frustum::Planes::COUNT, 0); + push_floats(params.frustum.ys, (int)Frustum::Planes::COUNT, (int)Frustum::Planes::COUNT); + push_floats(params.frustum.zs, (int)Frustum::Planes::COUNT, (int)Frustum::Planes::COUNT * 2); + push_floats(params.frustum.ds, (int)Frustum::Planes::COUNT, (int)Frustum::Planes::COUNT * 3); + push_floats(¶ms.frustum.points[0].x, 24, (int)Frustum::Planes::COUNT * 4); + LuaWrapper::push(L, params.frustum.origin); lua_setfield(L, -2, "origin"); lua_setfield(L, -2, "frustum"); diff --git a/src/renderer/pipeline.h b/src/renderer/pipeline.h index 1ccd8e320..57304a2c6 100644 --- a/src/renderer/pipeline.h +++ b/src/renderer/pipeline.h @@ -59,9 +59,9 @@ class LUMIX_RENDERER_API Pipeline public: struct Stats { - int draw_call_count; - int instance_count; - int triangle_count; + u32 draw_call_count; + u32 instance_count; + u32 triangle_count; }; struct CustomCommandHandler diff --git a/src/renderer/terrain.cpp b/src/renderer/terrain.cpp index 2907efea0..24a879faf 100644 --- a/src/renderer/terrain.cpp +++ b/src/renderer/terrain.cpp @@ -595,7 +595,7 @@ RayCastModelHit Terrain::castRay(const DVec3& origin, const Vec3& dir) float next_z = fabs(rel_dir.z) < 0.01f ? hz : ((hz + (rel_dir.z < 0 ? 0 : 1)) * m_scale.x - rel_origin.z) / rel_dir.z; float delta_x = fabsf(rel_dir.x) < 0.01f ? 0 : m_scale.x / fabsf(rel_dir.x); - float delta_z = fabsf(rel_dir.z) < 0.01f ? 0 : m_scale.x / fabsf(rel_dir.z); + float delta_z = fabsf(rel_dir.z) < 0.01f ? 0 : m_scale.z / fabsf(rel_dir.z); int step_x = (int)signum(rel_dir.x); int step_z = (int)signum(rel_dir.z); diff --git a/src/renderer/texture.cpp b/src/renderer/texture.cpp index 2038a3217..c2d3e7409 100644 --- a/src/renderer/texture.cpp +++ b/src/renderer/texture.cpp @@ -126,7 +126,7 @@ u32 Texture::getPixel(float x, float y) const int w3 = (int)(fx1 * fy * 256.0f); int w4 = (int)(fx * fy * 256.0f); - u8 res[4]; + alignas(u32) u8 res[4]; res[0] = (u8)((p1[0] * w1 + p2[0] * w2 + p3[0] * w3 + p4[0] * w4) >> 8); res[1] = (u8)((p1[1] * w1 + p2[1] * w2 + p3[1] * w3 + p4[1] * w4) >> 8); res[2] = (u8)((p1[2] * w1 + p2[2] * w2 + p3[2] * w3 + p4[2] * w4) >> 8);