summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2016-02-13 21:10:05 -0500
committerGravatar bunnei2016-02-13 21:10:05 -0500
commit0d086616d1af239b8e41b246bea3c1ef85fc907f (patch)
tree0dc7778532b0e2d1c5acd0224266b8a67d961155
parentMerge pull request #1264 from bunnei/fragment-lighting-hw (diff)
parentBitField: Make trivially copyable and remove assignment operator (diff)
downloadyuzu-0d086616d1af239b8e41b246bea3c1ef85fc907f.tar.gz
yuzu-0d086616d1af239b8e41b246bea3c1ef85fc907f.tar.xz
yuzu-0d086616d1af239b8e41b246bea3c1ef85fc907f.zip
Merge pull request #1406 from MerryMage/bitfield2
BitField: Make trivially copyable and remove assignment operator.
-rw-r--r--src/common/bit_field.h44
-rw-r--r--src/common/emu_window.cpp4
-rw-r--r--src/core/hle/kernel/process.cpp2
-rw-r--r--src/core/hle/result.h8
-rw-r--r--src/core/hle/service/cfg/cfg.cpp6
-rw-r--r--src/core/hle/service/gsp_gpu.cpp6
-rw-r--r--src/core/hle/service/hid/hid.cpp2
-rw-r--r--src/core/hle/service/ptm/ptm.cpp4
-rw-r--r--src/core/hle/service/soc_u.cpp12
-rw-r--r--src/core/hw/gpu.cpp16
-rw-r--r--src/video_core/command_processor.cpp4
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp8
12 files changed, 56 insertions, 60 deletions
diff --git a/src/common/bit_field.h b/src/common/bit_field.h
index 66689f398..600e0c70c 100644
--- a/src/common/bit_field.h
+++ b/src/common/bit_field.h
@@ -115,29 +115,24 @@ template<std::size_t position, std::size_t bits, typename T>
115struct BitField 115struct BitField
116{ 116{
117private: 117private:
118 // This constructor might be considered ambiguous: 118 // We hide the copy assigment operator here, because the default copy
119 // Would it initialize the storage or just the bitfield? 119 // assignment would copy the full storage value, rather than just the bits
120 // Hence, delete it. Use the assignment operator to set bitfield values! 120 // relevant to this particular bit field.
121 BitField(T val) = delete; 121 // We don't delete it because we want BitField to be trivially copyable.
122 BitField& operator=(const BitField&) = default;
122 123
123public: 124public:
125 // This constructor and assignment operator might be considered ambiguous:
126 // Would they initialize the storage or just the bitfield?
127 // Hence, delete them. Use the Assign method to set bitfield values!
128 BitField(T val) = delete;
129 BitField& operator=(T val) = delete;
130
124 // Force default constructor to be created 131 // Force default constructor to be created
125 // so that we can use this within unions 132 // so that we can use this within unions
126 BitField() = default; 133 BitField() = default;
127 134
128 // We explicitly delete the copy assigment operator here, because the 135 FORCE_INLINE operator T() const {
129 // default copy assignment would copy the full storage value, rather than
130 // just the bits relevant to this particular bit field.
131 BitField& operator=(const BitField&) = delete;
132
133 FORCE_INLINE BitField& operator=(T val)
134 {
135 Assign(val);
136 return *this;
137 }
138
139 FORCE_INLINE operator T() const
140 {
141 return Value(); 136 return Value();
142 } 137 }
143 138
@@ -145,8 +140,7 @@ public:
145 storage = (storage & ~GetMask()) | (((StorageType)value << position) & GetMask()); 140 storage = (storage & ~GetMask()) | (((StorageType)value << position) & GetMask());
146 } 141 }
147 142
148 FORCE_INLINE T Value() const 143 FORCE_INLINE T Value() const {
149 {
150 if (std::numeric_limits<T>::is_signed) 144 if (std::numeric_limits<T>::is_signed)
151 { 145 {
152 std::size_t shift = 8 * sizeof(T)-bits; 146 std::size_t shift = 8 * sizeof(T)-bits;
@@ -159,8 +153,7 @@ public:
159 } 153 }
160 154
161 // TODO: we may want to change this to explicit operator bool() if it's bug-free in VS2015 155 // TODO: we may want to change this to explicit operator bool() if it's bug-free in VS2015
162 FORCE_INLINE bool ToBool() const 156 FORCE_INLINE bool ToBool() const {
163 {
164 return Value() != 0; 157 return Value() != 0;
165 } 158 }
166 159
@@ -176,8 +169,7 @@ private:
176 // Unsigned version of StorageType 169 // Unsigned version of StorageType
177 typedef typename std::make_unsigned<StorageType>::type StorageTypeU; 170 typedef typename std::make_unsigned<StorageType>::type StorageTypeU;
178 171
179 FORCE_INLINE StorageType GetMask() const 172 FORCE_INLINE StorageType GetMask() const {
180 {
181 return (((StorageTypeU)~0) >> (8 * sizeof(T)-bits)) << position; 173 return (((StorageTypeU)~0) >> (8 * sizeof(T)-bits)) << position;
182 } 174 }
183 175
@@ -189,6 +181,10 @@ private:
189 static_assert(position < 8 * sizeof(T), "Invalid position"); 181 static_assert(position < 8 * sizeof(T), "Invalid position");
190 static_assert(bits <= 8 * sizeof(T), "Invalid number of bits"); 182 static_assert(bits <= 8 * sizeof(T), "Invalid number of bits");
191 static_assert(bits > 0, "Invalid number of bits"); 183 static_assert(bits > 0, "Invalid number of bits");
192 static_assert(std::is_standard_layout<T>::value, "Invalid base type"); 184 static_assert(std::is_pod<T>::value, "Invalid base type");
193}; 185};
194#pragma pack() 186#pragma pack()
187
188#if (__GNUC__ >= 5) || defined __clang__ || defined _MSC_VER
189static_assert(std::is_trivially_copyable<BitField<0, 1, u32>>::value, "BitField must be trivially copyable");
190#endif
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index b69b05cb9..b2807354a 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -55,14 +55,14 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
55 (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); 55 (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top);
56 56
57 touch_pressed = true; 57 touch_pressed = true;
58 pad_state.touch = 1; 58 pad_state.touch.Assign(1);
59} 59}
60 60
61void EmuWindow::TouchReleased() { 61void EmuWindow::TouchReleased() {
62 touch_pressed = false; 62 touch_pressed = false;
63 touch_x = 0; 63 touch_x = 0;
64 touch_y = 0; 64 touch_y = 0;
65 pad_state.touch = 0; 65 pad_state.touch.Assign(0);
66} 66}
67 67
68void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { 68void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index d148efde2..16eb972fb 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -35,7 +35,7 @@ SharedPtr<Process> Process::Create(SharedPtr<CodeSet> code_set) {
35 35
36 process->codeset = std::move(code_set); 36 process->codeset = std::move(code_set);
37 process->flags.raw = 0; 37 process->flags.raw = 0;
38 process->flags.memory_region = MemoryRegion::APPLICATION; 38 process->flags.memory_region.Assign(MemoryRegion::APPLICATION);
39 Memory::InitLegacyAddressSpace(process->vm_manager); 39 Memory::InitLegacyAddressSpace(process->vm_manager);
40 40
41 return process; 41 return process;
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index ea3abb5f6..0fce5988b 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -193,10 +193,10 @@ union ResultCode {
193 explicit ResultCode(u32 raw) : raw(raw) {} 193 explicit ResultCode(u32 raw) : raw(raw) {}
194 ResultCode(ErrorDescription description_, ErrorModule module_, 194 ResultCode(ErrorDescription description_, ErrorModule module_,
195 ErrorSummary summary_, ErrorLevel level_) : raw(0) { 195 ErrorSummary summary_, ErrorLevel level_) : raw(0) {
196 description = description_; 196 description.Assign(description_);
197 module = module_; 197 module.Assign(module_);
198 summary = summary_; 198 summary.Assign(summary_);
199 level = level_; 199 level.Assign(level_);
200 } 200 }
201 201
202 ResultCode& operator=(const ResultCode& o) { raw = o.raw; return *this; } 202 ResultCode& operator=(const ResultCode& o) { raw = o.raw; return *this; }
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp
index 633fe19eb..7556aa6a5 100644
--- a/src/core/hle/service/cfg/cfg.cpp
+++ b/src/core/hle/service/cfg/cfg.cpp
@@ -293,8 +293,8 @@ ResultCode DeleteConfigNANDSaveFile() {
293 293
294ResultCode UpdateConfigNANDSavegame() { 294ResultCode UpdateConfigNANDSavegame() {
295 FileSys::Mode mode = {}; 295 FileSys::Mode mode = {};
296 mode.write_flag = 1; 296 mode.write_flag.Assign(1);
297 mode.create_flag = 1; 297 mode.create_flag.Assign(1);
298 298
299 FileSys::Path path("config"); 299 FileSys::Path path("config");
300 300
@@ -405,7 +405,7 @@ void Init() {
405 405
406 FileSys::Path config_path("config"); 406 FileSys::Path config_path("config");
407 FileSys::Mode open_mode = {}; 407 FileSys::Mode open_mode = {};
408 open_mode.read_flag = 1; 408 open_mode.read_flag.Assign(1);
409 409
410 auto config_result = Service::FS::OpenFileFromArchive(*archive_result, config_path, open_mode); 410 auto config_result = Service::FS::OpenFileFromArchive(*archive_result, config_path, open_mode);
411 411
diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp
index 98b11c798..5838b6d71 100644
--- a/src/core/hle/service/gsp_gpu.cpp
+++ b/src/core/hle/service/gsp_gpu.cpp
@@ -347,7 +347,7 @@ void SignalInterrupt(InterruptId interrupt_id) {
347 FrameBufferUpdate* info = GetFrameBufferInfo(thread_id, screen_id); 347 FrameBufferUpdate* info = GetFrameBufferInfo(thread_id, screen_id);
348 if (info->is_dirty) { 348 if (info->is_dirty) {
349 SetBufferSwap(screen_id, info->framebuffer_info[info->index]); 349 SetBufferSwap(screen_id, info->framebuffer_info[info->index]);
350 info->is_dirty = false; 350 info->is_dirty.Assign(false);
351 } 351 }
352 } 352 }
353 } 353 }
@@ -499,7 +499,7 @@ static void SetLcdForceBlack(Service::Interface* self) {
499 499
500 // Since data is already zeroed, there is no need to explicitly set 500 // Since data is already zeroed, there is no need to explicitly set
501 // the color to black (all zero). 501 // the color to black (all zero).
502 data.is_enabled = enable_black; 502 data.is_enabled.Assign(enable_black);
503 503
504 LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_top), data.raw); // Top LCD 504 LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_top), data.raw); // Top LCD
505 LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_bottom), data.raw); // Bottom LCD 505 LCD::Write(HW::VADDR_LCD + 4 * LCD_REG_INDEX(color_fill_bottom), data.raw); // Bottom LCD
@@ -521,7 +521,7 @@ static void TriggerCmdReqQueue(Service::Interface* self) {
521 ExecuteCommand(command_buffer->commands[i], thread_id); 521 ExecuteCommand(command_buffer->commands[i], thread_id);
522 522
523 // Indicates that command has completed 523 // Indicates that command has completed
524 command_buffer->number_commands = command_buffer->number_commands - 1; 524 command_buffer->number_commands.Assign(command_buffer->number_commands - 1);
525 } 525 }
526 } 526 }
527 527
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 0bed0ce36..11d7e69a1 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -105,7 +105,7 @@ void Update() {
105 bool pressed = false; 105 bool pressed = false;
106 106
107 std::tie(touch_entry->x, touch_entry->y, pressed) = VideoCore::g_emu_window->GetTouchState(); 107 std::tie(touch_entry->x, touch_entry->y, pressed) = VideoCore::g_emu_window->GetTouchState();
108 touch_entry->valid = pressed ? 1 : 0; 108 touch_entry->valid.Assign(pressed ? 1 : 0);
109 109
110 // TODO(bunnei): We're not doing anything with offset 0xA8 + 0x18 of HID SharedMemory, which 110 // TODO(bunnei): We're not doing anything with offset 0xA8 + 0x18 of HID SharedMemory, which
111 // supposedly is "Touch-screen entry, which contains the raw coordinate data prior to being 111 // supposedly is "Touch-screen entry, which contains the raw coordinate data prior to being
diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp
index 22c1093ff..6bdee4d9e 100644
--- a/src/core/hle/service/ptm/ptm.cpp
+++ b/src/core/hle/service/ptm/ptm.cpp
@@ -110,8 +110,8 @@ void Init() {
110 110
111 FileSys::Path gamecoin_path("gamecoin.dat"); 111 FileSys::Path gamecoin_path("gamecoin.dat");
112 FileSys::Mode open_mode = {}; 112 FileSys::Mode open_mode = {};
113 open_mode.write_flag = 1; 113 open_mode.write_flag.Assign(1);
114 open_mode.create_flag = 1; 114 open_mode.create_flag.Assign(1);
115 // Open the file and write the default gamecoin information 115 // Open the file and write the default gamecoin information
116 auto gamecoin_result = Service::FS::OpenFileFromArchive(*archive_result, gamecoin_path, open_mode); 116 auto gamecoin_result = Service::FS::OpenFileFromArchive(*archive_result, gamecoin_path, open_mode);
117 if (gamecoin_result.Succeeded()) { 117 if (gamecoin_result.Succeeded()) {
diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp
index 822b093f4..e603bf794 100644
--- a/src/core/hle/service/soc_u.cpp
+++ b/src/core/hle/service/soc_u.cpp
@@ -178,17 +178,17 @@ struct CTRPollFD {
178 static Events TranslateTo3DS(u32 input_event) { 178 static Events TranslateTo3DS(u32 input_event) {
179 Events ev = {}; 179 Events ev = {};
180 if (input_event & POLLIN) 180 if (input_event & POLLIN)
181 ev.pollin = 1; 181 ev.pollin.Assign(1);
182 if (input_event & POLLPRI) 182 if (input_event & POLLPRI)
183 ev.pollpri = 1; 183 ev.pollpri.Assign(1);
184 if (input_event & POLLHUP) 184 if (input_event & POLLHUP)
185 ev.pollhup = 1; 185 ev.pollhup.Assign(1);
186 if (input_event & POLLERR) 186 if (input_event & POLLERR)
187 ev.pollerr = 1; 187 ev.pollerr.Assign(1);
188 if (input_event & POLLOUT) 188 if (input_event & POLLOUT)
189 ev.pollout = 1; 189 ev.pollout.Assign(1);
190 if (input_event & POLLNVAL) 190 if (input_event & POLLNVAL)
191 ev.pollnval = 1; 191 ev.pollnval.Assign(1);
192 return ev; 192 return ev;
193 } 193 }
194 194
diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp
index 4bd3a632d..c60310586 100644
--- a/src/core/hw/gpu.cpp
+++ b/src/core/hw/gpu.cpp
@@ -146,8 +146,8 @@ inline void Write(u32 addr, const T data) {
146 146
147 // Reset "trigger" flag and set the "finish" flag 147 // Reset "trigger" flag and set the "finish" flag
148 // NOTE: This was confirmed to happen on hardware even if "address_start" is zero. 148 // NOTE: This was confirmed to happen on hardware even if "address_start" is zero.
149 config.trigger = 0; 149 config.trigger.Assign(0);
150 config.finished = 1; 150 config.finished.Assign(1);
151 } 151 }
152 break; 152 break;
153 } 153 }
@@ -444,16 +444,16 @@ void Init() {
444 framebuffer_sub.address_left1 = 0x1848F000; 444 framebuffer_sub.address_left1 = 0x1848F000;
445 framebuffer_sub.address_left2 = 0x184C7800; 445 framebuffer_sub.address_left2 = 0x184C7800;
446 446
447 framebuffer_top.width = 240; 447 framebuffer_top.width.Assign(240);
448 framebuffer_top.height = 400; 448 framebuffer_top.height.Assign(400);
449 framebuffer_top.stride = 3 * 240; 449 framebuffer_top.stride = 3 * 240;
450 framebuffer_top.color_format = Regs::PixelFormat::RGB8; 450 framebuffer_top.color_format.Assign(Regs::PixelFormat::RGB8);
451 framebuffer_top.active_fb = 0; 451 framebuffer_top.active_fb = 0;
452 452
453 framebuffer_sub.width = 240; 453 framebuffer_sub.width.Assign(240);
454 framebuffer_sub.height = 320; 454 framebuffer_sub.height.Assign(320);
455 framebuffer_sub.stride = 3 * 240; 455 framebuffer_sub.stride = 3 * 240;
456 framebuffer_sub.color_format = Regs::PixelFormat::RGB8; 456 framebuffer_sub.color_format.Assign(Regs::PixelFormat::RGB8);
457 framebuffer_sub.active_fb = 0; 457 framebuffer_sub.active_fb = 0;
458 458
459 last_skip_frame = false; 459 last_skip_frame = false;
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index 5dfedfe31..ed20057b5 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -429,7 +429,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
429 uniform.w.ToFloat32()); 429 uniform.w.ToFloat32());
430 430
431 // TODO: Verify that this actually modifies the register! 431 // TODO: Verify that this actually modifies the register!
432 uniform_setup.index = uniform_setup.index + 1; 432 uniform_setup.index.Assign(uniform_setup.index + 1);
433 } 433 }
434 break; 434 break;
435 } 435 }
@@ -478,7 +478,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
478 ASSERT_MSG(lut_config.index < 256, "lut_config.index exceeded maximum value of 255!"); 478 ASSERT_MSG(lut_config.index < 256, "lut_config.index exceeded maximum value of 255!");
479 479
480 g_state.lighting.luts[lut_config.type][lut_config.index].raw = value; 480 g_state.lighting.luts[lut_config.type][lut_config.index].raw = value;
481 lut_config.index = lut_config.index + 1; 481 lut_config.index.Assign(lut_config.index + 1);
482 break; 482 break;
483 } 483 }
484 484
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index 4f66dbd65..6e6fd7335 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -201,11 +201,11 @@ void DumpShader(const std::string& filename, const Regs::ShaderConfig& config, c
201 201
202 if (it == output_info_table.end()) { 202 if (it == output_info_table.end()) {
203 output_info_table.emplace_back(); 203 output_info_table.emplace_back();
204 output_info_table.back().type = type; 204 output_info_table.back().type.Assign(type);
205 output_info_table.back().component_mask = component_mask; 205 output_info_table.back().component_mask.Assign(component_mask);
206 output_info_table.back().id = i; 206 output_info_table.back().id.Assign(i);
207 } else { 207 } else {
208 it->component_mask = it->component_mask | component_mask; 208 it->component_mask.Assign(it->component_mask | component_mask);
209 } 209 }
210 } catch (const std::out_of_range& ) { 210 } catch (const std::out_of_range& ) {
211 DEBUG_ASSERT_MSG(false, "Unknown output attribute mapping"); 211 DEBUG_ASSERT_MSG(false, "Unknown output attribute mapping");