summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Rodrigo Locatti2019-11-13 02:16:22 -0300
committerGravatar GitHub2019-11-13 02:16:22 -0300
commitcf770a68a528cdb7f3a5483f6d17eeb924e37b7e (patch)
tree6406933e26e9fbe255a04b4c0810d21b05815494 /src
parentUpdate CONTRIBUTING.md (diff)
parentvideo_core: Enable sign conversion warnings (diff)
downloadyuzu-cf770a68a528cdb7f3a5483f6d17eeb924e37b7e.tar.gz
yuzu-cf770a68a528cdb7f3a5483f6d17eeb924e37b7e.tar.xz
yuzu-cf770a68a528cdb7f3a5483f6d17eeb924e37b7e.zip
Merge pull request #3084 from ReinUsesLisp/cast-warnings
video_core: Treat implicit conversions as errors
Diffstat (limited to 'src')
-rw-r--r--src/video_core/CMakeLists.txt6
-rw-r--r--src/video_core/engines/maxwell_3d.cpp3
-rw-r--r--src/video_core/engines/shader_bytecode.h12
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp2
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp6
-rw-r--r--src/video_core/shader/decode.cpp4
-rw-r--r--src/video_core/shader/shader_ir.h6
-rw-r--r--src/video_core/textures/astc.cpp73
-rw-r--r--src/video_core/textures/texture.h7
-rw-r--r--src/video_core/video_core.cpp2
10 files changed, 68 insertions, 53 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index c911c6ec4..45d8eaf23 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -180,3 +180,9 @@ target_link_libraries(video_core PRIVATE glad)
180if (ENABLE_VULKAN) 180if (ENABLE_VULKAN)
181 target_link_libraries(video_core PRIVATE sirit) 181 target_link_libraries(video_core PRIVATE sirit)
182endif() 182endif()
183
184if (MSVC)
185 target_compile_options(video_core PRIVATE /we4267)
186else()
187 target_compile_options(video_core PRIVATE -Werror=conversion -Wno-error=sign-conversion)
188endif()
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index 2bed6cb38..42ce49a4d 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -261,7 +261,8 @@ void Maxwell3D::CallMacroMethod(u32 method, std::size_t num_parameters, const u3
261 executing_macro = 0; 261 executing_macro = 0;
262 262
263 // Lookup the macro offset 263 // Lookup the macro offset
264 const u32 entry = ((method - MacroRegistersStart) >> 1) % macro_positions.size(); 264 const u32 entry =
265 ((method - MacroRegistersStart) >> 1) % static_cast<u32>(macro_positions.size());
265 266
266 // Execute the current macro. 267 // Execute the current macro.
267 macro_interpreter.Execute(macro_positions[entry], num_parameters, parameters); 268 macro_interpreter.Execute(macro_positions[entry], num_parameters, parameters);
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h
index 8f6bc76eb..78d6886fb 100644
--- a/src/video_core/engines/shader_bytecode.h
+++ b/src/video_core/engines/shader_bytecode.h
@@ -1478,7 +1478,8 @@ union Instruction {
1478 u32 value = static_cast<u32>(target); 1478 u32 value = static_cast<u32>(target);
1479 // The branch offset is relative to the next instruction and is stored in bytes, so 1479 // The branch offset is relative to the next instruction and is stored in bytes, so
1480 // divide it by the size of an instruction and add 1 to it. 1480 // divide it by the size of an instruction and add 1 to it.
1481 return static_cast<s32>((value ^ mask) - mask) / sizeof(Instruction) + 1; 1481 return static_cast<s32>((value ^ mask) - mask) / static_cast<s32>(sizeof(Instruction)) +
1482 1;
1482 } 1483 }
1483 } bra; 1484 } bra;
1484 1485
@@ -1492,7 +1493,8 @@ union Instruction {
1492 u32 value = static_cast<u32>(target); 1493 u32 value = static_cast<u32>(target);
1493 // The branch offset is relative to the next instruction and is stored in bytes, so 1494 // The branch offset is relative to the next instruction and is stored in bytes, so
1494 // divide it by the size of an instruction and add 1 to it. 1495 // divide it by the size of an instruction and add 1 to it.
1495 return static_cast<s32>((value ^ mask) - mask) / sizeof(Instruction) + 1; 1496 return static_cast<s32>((value ^ mask) - mask) / static_cast<s32>(sizeof(Instruction)) +
1497 1;
1496 } 1498 }
1497 } brx; 1499 } brx;
1498 1500
@@ -1851,11 +1853,11 @@ private:
1851 const std::size_t bit_position = opcode_bitsize - i - 1; 1853 const std::size_t bit_position = opcode_bitsize - i - 1;
1852 switch (bitstring[i]) { 1854 switch (bitstring[i]) {
1853 case '0': 1855 case '0':
1854 mask |= 1 << bit_position; 1856 mask |= static_cast<u16>(1U << bit_position);
1855 break; 1857 break;
1856 case '1': 1858 case '1':
1857 expect |= 1 << bit_position; 1859 expect |= static_cast<u16>(1U << bit_position);
1858 mask |= 1 << bit_position; 1860 mask |= static_cast<u16>(1U << bit_position);
1859 break; 1861 break;
1860 default: 1862 default:
1861 // Ignore 1863 // Ignore
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index e560d70d5..e43ba9d6b 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -375,7 +375,7 @@ void RasterizerOpenGL::ConfigureFramebuffers() {
375 fbkey.color_attachments[index] = GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index); 375 fbkey.color_attachments[index] = GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index);
376 fbkey.colors[index] = std::move(color_surface); 376 fbkey.colors[index] = std::move(color_surface);
377 } 377 }
378 fbkey.colors_count = regs.rt_control.count; 378 fbkey.colors_count = static_cast<u16>(regs.rt_control.count);
379 379
380 if (depth_surface) { 380 if (depth_surface) {
381 // Assume that a surface will be written to if it is used as a framebuffer, even if 381 // Assume that a surface will be written to if it is used as a framebuffer, even if
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 4bbd17b12..7646cbb0e 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -323,10 +323,12 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x,
323 // (e.g. handheld mode) on a 1920x1080 framebuffer. 323 // (e.g. handheld mode) on a 1920x1080 framebuffer.
324 f32 scale_u = 1.f, scale_v = 1.f; 324 f32 scale_u = 1.f, scale_v = 1.f;
325 if (framebuffer_crop_rect.GetWidth() > 0) { 325 if (framebuffer_crop_rect.GetWidth() > 0) {
326 scale_u = static_cast<f32>(framebuffer_crop_rect.GetWidth()) / screen_info.texture.width; 326 scale_u = static_cast<f32>(framebuffer_crop_rect.GetWidth()) /
327 static_cast<f32>(screen_info.texture.width);
327 } 328 }
328 if (framebuffer_crop_rect.GetHeight() > 0) { 329 if (framebuffer_crop_rect.GetHeight() > 0) {
329 scale_v = static_cast<f32>(framebuffer_crop_rect.GetHeight()) / screen_info.texture.height; 330 scale_v = static_cast<f32>(framebuffer_crop_rect.GetHeight()) /
331 static_cast<f32>(screen_info.texture.height);
330 } 332 }
331 333
332 std::array<ScreenRectVertex, 4> vertices = {{ 334 std::array<ScreenRectVertex, 4> vertices = {{
diff --git a/src/video_core/shader/decode.cpp b/src/video_core/shader/decode.cpp
index 21fb9cb83..22c3e5120 100644
--- a/src/video_core/shader/decode.cpp
+++ b/src/video_core/shader/decode.cpp
@@ -154,10 +154,10 @@ void ShaderIR::Decode() {
154 LOG_CRITICAL(HW_GPU, "Unknown decompilation mode!"); 154 LOG_CRITICAL(HW_GPU, "Unknown decompilation mode!");
155 [[fallthrough]]; 155 [[fallthrough]];
156 case CompileDepth::BruteForce: { 156 case CompileDepth::BruteForce: {
157 const auto shader_end = static_cast<u32>(program_code.size());
157 coverage_begin = main_offset; 158 coverage_begin = main_offset;
158 const std::size_t shader_end = program_code.size();
159 coverage_end = shader_end; 159 coverage_end = shader_end;
160 for (u32 label = main_offset; label < shader_end; label++) { 160 for (u32 label = main_offset; label < shader_end; ++label) {
161 basic_blocks.insert({label, DecodeRange(label, label + 1)}); 161 basic_blocks.insert({label, DecodeRange(label, label + 1)});
162 } 162 }
163 break; 163 break;
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h
index 26c8fde22..76a849818 100644
--- a/src/video_core/shader/shader_ir.h
+++ b/src/video_core/shader/shader_ir.h
@@ -49,7 +49,7 @@ public:
49 } 49 }
50 50
51 u32 GetSize() const { 51 u32 GetSize() const {
52 return max_offset + sizeof(float); 52 return max_offset + static_cast<u32>(sizeof(float));
53 } 53 }
54 54
55 u32 GetMaxOffset() const { 55 u32 GetMaxOffset() const {
@@ -165,8 +165,8 @@ public:
165 return program_manager.GetVariables(); 165 return program_manager.GetVariables();
166 } 166 }
167 167
168 u32 ConvertAddressToNvidiaSpace(const u32 address) const { 168 u32 ConvertAddressToNvidiaSpace(u32 address) const {
169 return (address - main_offset) * sizeof(Tegra::Shader::Instruction); 169 return (address - main_offset) * static_cast<u32>(sizeof(Tegra::Shader::Instruction));
170 } 170 }
171 171
172 /// Returns a condition code evaluated from internal flags 172 /// Returns a condition code evaluated from internal flags
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp
index 58b608a36..33bd31865 100644
--- a/src/video_core/textures/astc.cpp
+++ b/src/video_core/textures/astc.cpp
@@ -92,11 +92,11 @@ private:
92 const unsigned int mask = 1 << m_NextBit++; 92 const unsigned int mask = 1 << m_NextBit++;
93 93
94 // clear the bit 94 // clear the bit
95 *m_CurByte &= ~mask; 95 *m_CurByte &= static_cast<unsigned char>(~mask);
96 96
97 // Write the bit, if necessary 97 // Write the bit, if necessary
98 if (b) 98 if (b)
99 *m_CurByte |= mask; 99 *m_CurByte |= static_cast<unsigned char>(mask);
100 100
101 // Next byte? 101 // Next byte?
102 if (m_NextBit >= 8) { 102 if (m_NextBit >= 8) {
@@ -137,7 +137,7 @@ public:
137 } 137 }
138 138
139 uint64_t mask = (1 << (end - start + 1)) - 1; 139 uint64_t mask = (1 << (end - start + 1)) - 1;
140 return (m_Bits >> start) & mask; 140 return (m_Bits >> start) & static_cast<IntType>(mask);
141 } 141 }
142 142
143private: 143private:
@@ -656,7 +656,7 @@ static IntType Replicate(const IntType& val, uint32_t numBits, uint32_t toBit) {
656 return 0; 656 return 0;
657 if (toBit == 0) 657 if (toBit == 0)
658 return 0; 658 return 0;
659 IntType v = val & ((1 << numBits) - 1); 659 IntType v = val & static_cast<IntType>((1 << numBits) - 1);
660 IntType res = v; 660 IntType res = v;
661 uint32_t reslen = numBits; 661 uint32_t reslen = numBits;
662 while (reslen < toBit) { 662 while (reslen < toBit) {
@@ -666,8 +666,8 @@ static IntType Replicate(const IntType& val, uint32_t numBits, uint32_t toBit) {
666 comp = numBits - newshift; 666 comp = numBits - newshift;
667 numBits = newshift; 667 numBits = newshift;
668 } 668 }
669 res <<= numBits; 669 res = static_cast<IntType>(res << numBits);
670 res |= v >> comp; 670 res = static_cast<IntType>(res | (v >> comp));
671 reslen += numBits; 671 reslen += numBits;
672 } 672 }
673 return res; 673 return res;
@@ -714,7 +714,7 @@ public:
714 // Do nothing 714 // Do nothing
715 return val; 715 return val;
716 } else if (oldDepth == 0 && newDepth != 0) { 716 } else if (oldDepth == 0 && newDepth != 0) {
717 return (1 << newDepth) - 1; 717 return static_cast<ChannelType>((1 << newDepth) - 1);
718 } else if (newDepth > oldDepth) { 718 } else if (newDepth > oldDepth) {
719 return Replicate(val, oldDepth, newDepth); 719 return Replicate(val, oldDepth, newDepth);
720 } else { 720 } else {
@@ -722,10 +722,11 @@ public:
722 if (newDepth == 0) { 722 if (newDepth == 0) {
723 return 0xFF; 723 return 0xFF;
724 } else { 724 } else {
725 uint8_t bitsWasted = oldDepth - newDepth; 725 uint8_t bitsWasted = static_cast<uint8_t>(oldDepth - newDepth);
726 uint16_t v = static_cast<uint16_t>(val); 726 uint16_t v = static_cast<uint16_t>(val);
727 v = (v + (1 << (bitsWasted - 1))) >> bitsWasted; 727 v = static_cast<uint16_t>((v + (1 << (bitsWasted - 1))) >> bitsWasted);
728 v = ::std::min<uint16_t>(::std::max<uint16_t>(0, v), (1 << newDepth) - 1); 728 v = ::std::min<uint16_t>(::std::max<uint16_t>(0, v),
729 static_cast<uint16_t>((1 << newDepth) - 1));
729 return static_cast<uint8_t>(v); 730 return static_cast<uint8_t>(v);
730 } 731 }
731 } 732 }
@@ -1191,18 +1192,18 @@ static uint32_t SelectPartition(int32_t seed, int32_t x, int32_t y, int32_t z,
1191 uint8_t seed11 = static_cast<uint8_t>((rnum >> 26) & 0xF); 1192 uint8_t seed11 = static_cast<uint8_t>((rnum >> 26) & 0xF);
1192 uint8_t seed12 = static_cast<uint8_t>(((rnum >> 30) | (rnum << 2)) & 0xF); 1193 uint8_t seed12 = static_cast<uint8_t>(((rnum >> 30) | (rnum << 2)) & 0xF);
1193 1194
1194 seed1 *= seed1; 1195 seed1 = static_cast<uint8_t>(seed1 * seed1);
1195 seed2 *= seed2; 1196 seed2 = static_cast<uint8_t>(seed2 * seed2);
1196 seed3 *= seed3; 1197 seed3 = static_cast<uint8_t>(seed3 * seed3);
1197 seed4 *= seed4; 1198 seed4 = static_cast<uint8_t>(seed4 * seed4);
1198 seed5 *= seed5; 1199 seed5 = static_cast<uint8_t>(seed5 * seed5);
1199 seed6 *= seed6; 1200 seed6 = static_cast<uint8_t>(seed6 * seed6);
1200 seed7 *= seed7; 1201 seed7 = static_cast<uint8_t>(seed7 * seed7);
1201 seed8 *= seed8; 1202 seed8 = static_cast<uint8_t>(seed8 * seed8);
1202 seed9 *= seed9; 1203 seed9 = static_cast<uint8_t>(seed9 * seed9);
1203 seed10 *= seed10; 1204 seed10 = static_cast<uint8_t>(seed10 * seed10);
1204 seed11 *= seed11; 1205 seed11 = static_cast<uint8_t>(seed11 * seed11);
1205 seed12 *= seed12; 1206 seed12 = static_cast<uint8_t>(seed12 * seed12);
1206 1207
1207 int32_t sh1, sh2, sh3; 1208 int32_t sh1, sh2, sh3;
1208 if (seed & 1) { 1209 if (seed & 1) {
@@ -1214,18 +1215,18 @@ static uint32_t SelectPartition(int32_t seed, int32_t x, int32_t y, int32_t z,
1214 } 1215 }
1215 sh3 = (seed & 0x10) ? sh1 : sh2; 1216 sh3 = (seed & 0x10) ? sh1 : sh2;
1216 1217
1217 seed1 >>= sh1; 1218 seed1 = static_cast<uint8_t>(seed1 >> sh1);
1218 seed2 >>= sh2; 1219 seed2 = static_cast<uint8_t>(seed2 >> sh2);
1219 seed3 >>= sh1; 1220 seed3 = static_cast<uint8_t>(seed3 >> sh1);
1220 seed4 >>= sh2; 1221 seed4 = static_cast<uint8_t>(seed4 >> sh2);
1221 seed5 >>= sh1; 1222 seed5 = static_cast<uint8_t>(seed5 >> sh1);
1222 seed6 >>= sh2; 1223 seed6 = static_cast<uint8_t>(seed6 >> sh2);
1223 seed7 >>= sh1; 1224 seed7 = static_cast<uint8_t>(seed7 >> sh1);
1224 seed8 >>= sh2; 1225 seed8 = static_cast<uint8_t>(seed8 >> sh2);
1225 seed9 >>= sh3; 1226 seed9 = static_cast<uint8_t>(seed9 >> sh3);
1226 seed10 >>= sh3; 1227 seed10 = static_cast<uint8_t>(seed10 >> sh3);
1227 seed11 >>= sh3; 1228 seed11 = static_cast<uint8_t>(seed11 >> sh3);
1228 seed12 >>= sh3; 1229 seed12 = static_cast<uint8_t>(seed12 >> sh3);
1229 1230
1230 int32_t a = seed1 * x + seed2 * y + seed11 * z + (rnum >> 14); 1231 int32_t a = seed1 * x + seed2 * y + seed11 * z + (rnum >> 14);
1231 int32_t b = seed3 * x + seed4 * y + seed12 * z + (rnum >> 10); 1232 int32_t b = seed3 * x + seed4 * y + seed12 * z + (rnum >> 10);
@@ -1558,7 +1559,9 @@ static void DecompressBlock(const uint8_t inBuf[16], const uint32_t blockWidth,
1558 1559
1559 // Make sure that higher non-texel bits are set to zero 1560 // Make sure that higher non-texel bits are set to zero
1560 const uint32_t clearByteStart = (weightParams.GetPackedBitSize() >> 3) + 1; 1561 const uint32_t clearByteStart = (weightParams.GetPackedBitSize() >> 3) + 1;
1561 texelWeightData[clearByteStart - 1] &= (1 << (weightParams.GetPackedBitSize() % 8)) - 1; 1562 texelWeightData[clearByteStart - 1] =
1563 texelWeightData[clearByteStart - 1] &
1564 static_cast<uint8_t>((1 << (weightParams.GetPackedBitSize() % 8)) - 1);
1562 memset(texelWeightData + clearByteStart, 0, 16 - clearByteStart); 1565 memset(texelWeightData + clearByteStart, 0, 16 - clearByteStart);
1563 1566
1564 std::vector<IntegerEncodedValue> texelWeightValues; 1567 std::vector<IntegerEncodedValue> texelWeightValues;
diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h
index 27c8ce975..8e82c6748 100644
--- a/src/video_core/textures/texture.h
+++ b/src/video_core/textures/texture.h
@@ -342,13 +342,14 @@ struct TSCEntry {
342 float GetLodBias() const { 342 float GetLodBias() const {
343 // Sign extend the 13-bit value. 343 // Sign extend the 13-bit value.
344 constexpr u32 mask = 1U << (13 - 1); 344 constexpr u32 mask = 1U << (13 - 1);
345 return static_cast<s32>((mip_lod_bias ^ mask) - mask) / 256.0f; 345 return static_cast<float>(static_cast<s32>((mip_lod_bias ^ mask) - mask)) / 256.0f;
346 } 346 }
347 347
348 std::array<float, 4> GetBorderColor() const { 348 std::array<float, 4> GetBorderColor() const {
349 if (srgb_conversion) { 349 if (srgb_conversion) {
350 return {srgb_border_color_r / 255.0f, srgb_border_color_g / 255.0f, 350 return {static_cast<float>(srgb_border_color_r) / 255.0f,
351 srgb_border_color_b / 255.0f, border_color[3]}; 351 static_cast<float>(srgb_border_color_g) / 255.0f,
352 static_cast<float>(srgb_border_color_b) / 255.0f, border_color[3]};
352 } 353 }
353 return border_color; 354 return border_color;
354 } 355 }
diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp
index 60cda0ca3..8e947394c 100644
--- a/src/video_core/video_core.cpp
+++ b/src/video_core/video_core.cpp
@@ -28,7 +28,7 @@ std::unique_ptr<Tegra::GPU> CreateGPU(Core::System& system) {
28 28
29u16 GetResolutionScaleFactor(const RendererBase& renderer) { 29u16 GetResolutionScaleFactor(const RendererBase& renderer) {
30 return static_cast<u16>( 30 return static_cast<u16>(
31 Settings::values.resolution_factor 31 Settings::values.resolution_factor != 0
32 ? Settings::values.resolution_factor 32 ? Settings::values.resolution_factor
33 : renderer.GetRenderWindow().GetFramebufferLayout().GetScalingRatio()); 33 : renderer.GetRenderWindow().GetFramebufferLayout().GetScalingRatio());
34} 34}