From a76ec6fc192a38c1a4d276fabb0e6a0218a0be6d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 22 Oct 2019 23:07:51 +1000 Subject: [PATCH] Compile fixes for GCC --- src/common/bitfield.h | 8 +++----- src/common/cd_image.cpp | 2 +- src/common/cd_xa.cpp | 2 +- src/common/fifo_queue.h | 26 +++++++++++--------------- src/common/state_wrapper.h | 2 +- src/core/bus.h | 2 +- src/core/cdrom.cpp | 8 ++++---- src/core/cpu_core.cpp | 4 ++-- src/core/dma.cpp | 2 +- src/core/gpu.cpp | 9 ++++++--- src/core/gpu.h | 3 ++- src/core/gpu_commands.cpp | 8 +++----- src/core/gpu_hw.cpp | 5 ++--- src/core/gpu_hw_opengl.cpp | 1 - src/core/gte.cpp | 7 ++++--- src/core/mdec.cpp | 4 ++-- src/core/spu.cpp | 2 +- src/core/timers.cpp | 2 +- src/duckstation/sdl_interface.cpp | 2 +- 19 files changed, 47 insertions(+), 52 deletions(-) diff --git a/src/common/bitfield.h b/src/common/bitfield.h index d279e709c..0f4137f8c 100644 --- a/src/common/bitfield.h +++ b/src/common/bitfield.h @@ -10,10 +10,8 @@ template struct BitField { - constexpr BitField() = default; -#ifndef _MSC_VER - BitField& operator=(const BitField& value) = delete; -#endif + // We have to delete the copy assignment operator otherwise we can't use this class in anonymous structs/unions. + BitField& operator=(const BitField& rhs) = delete; constexpr BackingDataType GetMask() const { @@ -138,4 +136,4 @@ struct BitField #ifdef _MSC_VER #pragma warning(pop) -#endif \ No newline at end of file +#endif diff --git a/src/common/cd_image.cpp b/src/common/cd_image.cpp index 4724784c0..1b3d47878 100644 --- a/src/common/cd_image.cpp +++ b/src/common/cd_image.cpp @@ -171,7 +171,7 @@ const CDImage::Index* CDImage::GetIndexForTrackPosition(u32 track_number, LBA tr const Track& track = m_tracks[track_number - 1]; if (track_pos >= track.length) - return false; + return nullptr; return GetIndexForDiscPosition(track.start_lba + track_pos); } diff --git a/src/common/cd_xa.cpp b/src/common/cd_xa.cpp index 4c5ec82ea..fa4b1e044 100644 --- a/src/common/cd_xa.cpp +++ b/src/common/cd_xa.cpp @@ -60,7 +60,7 @@ static void DecodeXA_ADPCMChunks(const u8* chunk_ptr, s16* samples, s32* last_sa constexpr u32 NUM_CHUNKS = 18; constexpr u32 CHUNK_SIZE_IN_BYTES = 128; constexpr u32 WORDS_PER_CHUNK = 28; - constexpr u32 SAMPLES_PER_CHUNK = 28 * (IS_8BIT ? 4 : 8); + constexpr u32 SAMPLES_PER_CHUNK = WORDS_PER_CHUNK * (IS_8BIT ? 4 : 8); for (u32 i = 0; i < NUM_CHUNKS; i++) { diff --git a/src/common/fifo_queue.h b/src/common/fifo_queue.h index 9c4e1575b..f873c5816 100644 --- a/src/common/fifo_queue.h +++ b/src/common/fifo_queue.h @@ -4,11 +4,7 @@ #include #include -#ifdef _MSC_VER -#include // _aligned_malloc -#else -#include -#endif +#include // _aligned_malloc, memalign template class FIFOQueue @@ -35,7 +31,7 @@ public: T& Emplace(Args&&... args) { T& ref = PushAndGetReference(); - new (&ref) T(std::forward(args...)); + new (&ref) T(std::forward(args...)); return ref; } @@ -157,7 +153,7 @@ template class InlineFIFOQueue : public FIFOQueue { public: - InlineFIFOQueue() : FIFOQueue() { m_ptr = m_inline_data; } + InlineFIFOQueue() : FIFOQueue() { this->m_ptr = m_inline_data; } private: T m_inline_data[CAPACITY] = {}; @@ -172,20 +168,20 @@ public: if constexpr (ALIGNMENT > 0) { #ifdef _MSC_VER - m_ptr = static_cast(_aligned_malloc(sizeof(T) * CAPACITY, ALIGNMENT)); + this->m_ptr = static_cast(_aligned_malloc(sizeof(T) * CAPACITY, ALIGNMENT)); #else - m_ptr = static_cast(memalign(ALIGNMENT, sizeof(T) * CAPACITY)); + this->m_ptr = static_cast(memalign(ALIGNMENT, sizeof(T) * CAPACITY)); #endif } else { - m_ptr = static_cast(std::malloc(sizeof(T) * CAPACITY)); + this->m_ptr = static_cast(std::malloc(sizeof(T) * CAPACITY)); } - if (!m_ptr) + if (!this->m_ptr) Panic("Heap allocation failed"); - std::memset(m_ptr, 0, sizeof(T) * CAPACITY); + std::memset(this->m_ptr, 0, sizeof(T) * CAPACITY); } ~HeapFIFOQueue() @@ -193,14 +189,14 @@ public: if constexpr (ALIGNMENT > 0) { #ifdef _MSC_VER - _aligned_free(m_ptr); + _aligned_free(this->m_ptr); #else - free(m_ptr); + free(this->m_ptr); #endif } else { - free(m_ptr); + free(this->m_ptr); } } }; diff --git a/src/common/state_wrapper.h b/src/common/state_wrapper.h index af5d91b90..4a5382f9f 100644 --- a/src/common/state_wrapper.h +++ b/src/common/state_wrapper.h @@ -74,7 +74,7 @@ public: if (m_mode == Mode::Read) { if (m_error || (m_error |= !m_stream->Read2(value_ptr, sizeof(T))) == true) - *value_ptr = {}; + std::memset(value_ptr, 0, sizeof(*value_ptr)); } else { diff --git a/src/core/bus.h b/src/core/bus.h index 8c918876c..24663ec9e 100644 --- a/src/core/bus.h +++ b/src/core/bus.h @@ -229,4 +229,4 @@ private: String m_tty_line_buffer; }; -#include "bus.inl" \ No newline at end of file +#include "bus.inl" diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 2deb5bcb7..f6c0f4378 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -48,8 +48,8 @@ void CDROM::SoftReset() m_location_pending = false; m_filter_file_number = 0; m_filter_channel_number = 0; - m_last_sector_header = {}; - m_last_sector_subheader = {}; + std::memset(&m_last_sector_header, 0, sizeof(m_last_sector_header)); + std::memset(&m_last_sector_subheader, 0, sizeof(m_last_sector_subheader)); m_next_cd_audio_volume_matrix[0][0] = 0x80; m_next_cd_audio_volume_matrix[0][1] = 0x00; @@ -95,8 +95,8 @@ bool CDROM::DoState(StateWrapper& sw) sw.Do(&m_location_pending); sw.Do(&m_filter_file_number); sw.Do(&m_filter_channel_number); - sw.DoPOD(&m_last_sector_header); - sw.DoPOD(&m_last_sector_subheader); + sw.DoBytes(&m_last_sector_header, sizeof(m_last_sector_header)); + sw.DoBytes(&m_last_sector_subheader, sizeof(m_last_sector_subheader)); sw.Do(&m_cd_audio_volume_matrix); sw.Do(&m_next_cd_audio_volume_matrix); sw.Do(&m_xa_last_samples); diff --git a/src/core/cpu_core.cpp b/src/core/cpu_core.cpp index beca734ae..924004ecf 100644 --- a/src/core/cpu_core.cpp +++ b/src/core/cpu_core.cpp @@ -539,7 +539,7 @@ void Core::Execute() m_downcount -= 1; // now executing the instruction we previously fetched - m_current_instruction = m_next_instruction; + m_current_instruction.bits = m_next_instruction.bits; m_current_instruction_pc = m_regs.pc; m_current_instruction_in_branch_delay_slot = m_next_instruction_is_branch_delay_slot; m_current_instruction_was_branch_taken = m_branch_was_taken; @@ -1295,4 +1295,4 @@ void Core::ExecuteCop2Instruction() } } -} // namespace CPU \ No newline at end of file +} // namespace CPU diff --git a/src/core/dma.cpp b/src/core/dma.cpp index c9cdda6ad..8a2d7fb56 100644 --- a/src/core/dma.cpp +++ b/src/core/dma.cpp @@ -31,7 +31,7 @@ bool DMA::Initialize(System* system, Bus* bus, InterruptController* interrupt_co void DMA::Reset() { m_transfer_in_progress = false; - m_state = {}; + std::memset(&m_state, 0, sizeof(m_state)); m_DPCR.bits = 0x07654321; m_DICR.bits = 0; } diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index e3611dadc..2e6ad85cd 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -6,9 +6,12 @@ #include "stb_image_write.h" #include "system.h" #include "timers.h" +#include #include Log_SetChannel(GPU); +const GPU::GP0CommandHandlerTable GPU::s_GP0_command_handler_table = GPU::GenerateGP0CommandHandlerTable(); + GPU::GPU() = default; GPU::~GPU() = default; @@ -32,7 +35,7 @@ void GPU::SoftReset() m_GPUSTAT.bits = 0x14802000; m_drawing_area = {}; m_drawing_offset = {}; - m_crtc_state = {}; + std::memset(&m_crtc_state, 0, sizeof(m_crtc_state)); m_crtc_state.regs.display_address_start = 0; m_crtc_state.regs.horizontal_display_range = 0xC60260; m_crtc_state.regs.vertical_display_range = 0x3FC10; @@ -493,7 +496,7 @@ void GPU::WriteGP0(u32 value) const u32 command = m_GP0_buffer[0] >> 24; if ((this->*s_GP0_command_handler_table[command])(command_ptr, static_cast(m_GP0_buffer.size()))) { - DebugAssert((command_ptr - m_GP0_buffer.data()) == m_GP0_buffer.size()); + DebugAssert(static_cast(command_ptr - m_GP0_buffer.data()) == m_GP0_buffer.size()); m_GP0_buffer.clear(); } @@ -830,4 +833,4 @@ void GPU::DrawDebugStateWindow() ImGui::Text("Interrupt Request: %s", m_GPUSTAT.interrupt_request ? "Yes" : "No"); ImGui::Text("DMA Request: %s", m_GPUSTAT.dma_data_request ? "Yes" : "No"); } -} \ No newline at end of file +} diff --git a/src/core/gpu.h b/src/core/gpu.h index ff8ee967a..d14902745 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -4,6 +4,7 @@ #include "types.h" #include #include +#include #include class StateWrapper; @@ -355,7 +356,7 @@ protected: private: using GP0CommandHandler = bool (GPU::*)(const u32*&, u32); using GP0CommandHandlerTable = std::array; - static constexpr GP0CommandHandlerTable GenerateGP0CommandHandlerTable(); + static GP0CommandHandlerTable GenerateGP0CommandHandlerTable(); // Rendering commands, returns false if not enough data is provided bool HandleUnknownGP0Command(const u32*& command_ptr, u32 command_size); diff --git a/src/core/gpu_commands.cpp b/src/core/gpu_commands.cpp index 86d793b25..b9bead285 100644 --- a/src/core/gpu_commands.cpp +++ b/src/core/gpu_commands.cpp @@ -12,7 +12,7 @@ static constexpr u32 ReplaceZero(u32 value, u32 value_for_zero) return value == 0 ? value_for_zero : value; } -constexpr GPU::GP0CommandHandlerTable GPU::GenerateGP0CommandHandlerTable() +GPU::GP0CommandHandlerTable GPU::GenerateGP0CommandHandlerTable() { GP0CommandHandlerTable table = {}; for (u32 i = 0; i < static_cast(table.size()); i++) @@ -45,8 +45,6 @@ constexpr GPU::GP0CommandHandlerTable GPU::GenerateGP0CommandHandlerTable() return table; } -constexpr GPU::GP0CommandHandlerTable GPU::s_GP0_command_handler_table = GPU::GenerateGP0CommandHandlerTable(); - bool GPU::HandleUnknownGP0Command(const u32*& command_ptr, u32 command_size) { const u32 command = *(command_ptr++) >> 24; @@ -85,7 +83,7 @@ bool GPU::HandleSetDrawModeCommand(const u32*& command_ptr, u32 command_size) // 0..10 bits match GPUSTAT const u32 MASK = ((1 << 11) - 1); - m_GPUSTAT.bits = (m_GPUSTAT.bits & ~MASK) | param & MASK; + m_GPUSTAT.bits = (m_GPUSTAT.bits & ~MASK) | (param & MASK); m_GPUSTAT.texture_disable = (param & (1 << 11)) != 0; m_render_state.texture_x_flip = (param & (1 << 12)) != 0; m_render_state.texture_y_flip = (param & (1 << 13)) != 0; @@ -337,7 +335,7 @@ bool GPU::HandleCopyRectangleVRAMToCPUCommand(const u32*& command_ptr, u32 comma if (m_debug_options.dump_vram_to_cpu_copies) { - DumpVRAMToFile(SmallString::FromFormat("vram_to_cpu_copy_%u.png", s_cpu_to_vram_dump_id++), width, height, + DumpVRAMToFile(SmallString::FromFormat("vram_to_cpu_copy_%u.png", s_vram_to_cpu_dump_id++), width, height, sizeof(u16) * width, temp.data(), true); } diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 74d37f718..f85f2d18f 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -78,7 +78,6 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices, const u32* command m_batch.vertices.push_back(m_batch.vertices.back()); u32 buffer_pos = 1; - const bool textured = rc.texture_enable; const u32 color = rc.color_for_first_vertex; const VertexPosition vp{command_ptr[buffer_pos++]}; const s32 pos_left = vp.x; @@ -520,9 +519,9 @@ void GPU_HW::DispatchRenderCommand(RenderCommand rc, u32 num_vertices, const u32 const u32 max_added_vertices = num_vertices + 2; const bool buffer_overflow = (m_batch.vertices.size() + max_added_vertices) >= MAX_BATCH_VERTEX_COUNT; const bool rc_changed = - m_batch.render_command_bits != rc.bits && m_batch.transparency_enable != rc_transparency_enable || + m_batch.render_command_bits != rc.bits && (m_batch.transparency_enable != rc_transparency_enable || m_batch.texture_enable != rc_texture_enable || m_batch.texture_blending_enable != rc_texture_blend_enable || - m_batch.primitive != rc_primitive; + m_batch.primitive != rc_primitive); const bool restart_line_strip = (rc_primitive == HWRenderBatch::Primitive::LineStrip); const bool needs_flush = !IsFlushed() && (m_render_state.IsTextureColorModeChanged() || m_render_state.IsTransparencyModeChanged() || diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp index a2189c894..e7e6f7379 100644 --- a/src/core/gpu_hw_opengl.cpp +++ b/src/core/gpu_hw_opengl.cpp @@ -515,7 +515,6 @@ void GPU_HW_OpenGL::ReadVRAM(u32 x, u32 y, u32 width, u32 height, void* buffer) // downscaling to 1xIR. if (m_resolution_scale > 1) { - const u32 texture_width = m_vram_texture->GetWidth(); const u32 texture_height = m_vram_texture->GetHeight(); const u32 scaled_x = x * m_resolution_scale; const u32 scaled_y = y * m_resolution_scale; diff --git a/src/core/gte.cpp b/src/core/gte.cpp index a7ad192d7..76462fb6e 100644 --- a/src/core/gte.cpp +++ b/src/core/gte.cpp @@ -50,12 +50,13 @@ void Core::Initialize() {} void Core::Reset() { - m_regs = {}; + std::memset(&m_regs, 0, sizeof(m_regs)); } bool Core::DoState(StateWrapper& sw) { - sw.DoPOD(&m_regs); + sw.DoArray(m_regs.dr32, NUM_DATA_REGS); + sw.DoArray(m_regs.cr32, NUM_CONTROL_REGS); return !sw.HasError(); } @@ -1045,4 +1046,4 @@ void Core::Execute_GPF(Instruction inst) m_regs.FLAG.UpdateError(); } -} // namespace GTE \ No newline at end of file +} // namespace GTE diff --git a/src/core/mdec.cpp b/src/core/mdec.cpp index 9c235b3bf..a390c6e93 100644 --- a/src/core/mdec.cpp +++ b/src/core/mdec.cpp @@ -134,7 +134,7 @@ void MDEC::DMAWrite(const u32* words, u32 word_count) void MDEC::SoftReset() { - m_status = {}; + m_status.bits = 0; m_enable_dma_in = false; m_enable_dma_out = false; m_data_in_fifo.Clear(); @@ -766,4 +766,4 @@ void MDEC::DrawDebugWindow() } ImGui::End(); -} \ No newline at end of file +} diff --git a/src/core/spu.cpp b/src/core/spu.cpp index c74075218..8ae2bcf93 100644 --- a/src/core/spu.cpp +++ b/src/core/spu.cpp @@ -205,7 +205,7 @@ void SPU::WriteRegister(u32 offset, u16 value) { Log_DebugPrintf("SPU control register <- 0x%04X", ZeroExtend32(value)); m_SPUCNT.bits = value; - m_SPUSTAT.mode = m_SPUCNT.mode; + m_SPUSTAT.mode = m_SPUCNT.mode.GetValue(); m_SPUSTAT.dma_read_write_request = m_SPUCNT.ram_transfer_mode >= RAMTransferMode::DMAWrite; if (!m_SPUCNT.irq9_enable) diff --git a/src/core/timers.cpp b/src/core/timers.cpp index 0531773da..1c01bf984 100644 --- a/src/core/timers.cpp +++ b/src/core/timers.cpp @@ -361,7 +361,7 @@ void Timers::DrawDebugWindow() ImGui::NextColumn(); ImGui::Text("%s%s", clock_source_names[i][cs.mode.clock_source], cs.external_counting_enabled ? " (External)" : ""); ImGui::NextColumn(); - ImGui::Text("%s", cs.mode.reached_target ? "Target " : "", cs.mode.reached_overflow ? "Overflow" : ""); + ImGui::Text("%s%s", cs.mode.reached_target ? "Target " : "", cs.mode.reached_overflow ? "Overflow" : ""); ImGui::NextColumn(); ImGui::PopStyleColor(); } diff --git a/src/duckstation/sdl_interface.cpp b/src/duckstation/sdl_interface.cpp index a7aad40c9..4b3689e2a 100644 --- a/src/duckstation/sdl_interface.cpp +++ b/src/duckstation/sdl_interface.cpp @@ -720,7 +720,7 @@ void SDLInterface::DrawPoweredOffWindow() ImVec2(APP_ICON_WIDTH, APP_ICON_HEIGHT)); ImGui::SetCursorPosY(APP_ICON_HEIGHT + 32); - static const ImVec2 button_size(200.0f, 40.0f); + static const ImVec2 button_size(static_cast(BUTTON_WIDTH), static_cast(BUTTON_HEIGHT)); constexpr float button_left = static_cast((WINDOW_WIDTH - BUTTON_WIDTH) / 2); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 8.0f);