diff options
| author | 2020-09-22 17:31:53 -0400 | |
|---|---|---|
| committer | 2020-09-22 17:32:33 -0400 | |
| commit | ff45c3957858cdf189b73e11550da06fe4337b8e (patch) | |
| tree | 288ff1cc4677d6511ed8cc7e1b0db20ce2d2590f /src/video_core | |
| parent | Merge pull request #4697 from lioncash/copy5 (diff) | |
| download | yuzu-ff45c3957858cdf189b73e11550da06fe4337b8e.tar.gz yuzu-ff45c3957858cdf189b73e11550da06fe4337b8e.tar.xz yuzu-ff45c3957858cdf189b73e11550da06fe4337b8e.zip | |
General: Make use of std::nullopt where applicable
Allows some implementations to avoid completely zeroing out the internal
buffer of the optional, and instead only set the validity byte within
the structure.
This also makes it consistent how we return empty optionals.
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/macro/macro.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/memory_manager.cpp | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 12 | ||||
| -rw-r--r-- | src/video_core/shader/ast.h | 25 | ||||
| -rw-r--r-- | src/video_core/shader/track.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_base.cpp | 10 |
7 files changed, 29 insertions, 32 deletions
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 33854445f..57ebc785f 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -597,7 +597,7 @@ std::optional<u64> Maxwell3D::GetQueryResult() { | |||
| 597 | // Deferred. | 597 | // Deferred. |
| 598 | rasterizer->Query(regs.query.QueryAddress(), VideoCore::QueryType::SamplesPassed, | 598 | rasterizer->Query(regs.query.QueryAddress(), VideoCore::QueryType::SamplesPassed, |
| 599 | system.GPU().GetTicks()); | 599 | system.GPU().GetTicks()); |
| 600 | return {}; | 600 | return std::nullopt; |
| 601 | default: | 601 | default: |
| 602 | LOG_DEBUG(HW_GPU, "Unimplemented query select type {}", | 602 | LOG_DEBUG(HW_GPU, "Unimplemented query select type {}", |
| 603 | static_cast<u32>(regs.query.query_get.select.Value())); | 603 | static_cast<u32>(regs.query.query_get.select.Value())); |
diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp index a50e7b4e0..cd21a2112 100644 --- a/src/video_core/macro/macro.cpp +++ b/src/video_core/macro/macro.cpp | |||
| @@ -36,7 +36,7 @@ void MacroEngine::Execute(Engines::Maxwell3D& maxwell3d, u32 method, | |||
| 36 | } | 36 | } |
| 37 | } else { | 37 | } else { |
| 38 | // Macro not compiled, check if it's uploaded and if so, compile it | 38 | // Macro not compiled, check if it's uploaded and if so, compile it |
| 39 | std::optional<u32> mid_method = std::nullopt; | 39 | std::optional<u32> mid_method; |
| 40 | const auto macro_code = uploaded_macro_code.find(method); | 40 | const auto macro_code = uploaded_macro_code.find(method); |
| 41 | if (macro_code == uploaded_macro_code.end()) { | 41 | if (macro_code == uploaded_macro_code.end()) { |
| 42 | for (const auto& [method_base, code] : uploaded_macro_code) { | 42 | for (const auto& [method_base, code] : uploaded_macro_code) { |
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index 16b2aaa27..02cf53d15 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp | |||
| @@ -58,7 +58,7 @@ void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) { | |||
| 58 | std::optional<GPUVAddr> MemoryManager::AllocateFixed(GPUVAddr gpu_addr, std::size_t size) { | 58 | std::optional<GPUVAddr> MemoryManager::AllocateFixed(GPUVAddr gpu_addr, std::size_t size) { |
| 59 | for (u64 offset{}; offset < size; offset += page_size) { | 59 | for (u64 offset{}; offset < size; offset += page_size) { |
| 60 | if (!GetPageEntry(gpu_addr + offset).IsUnmapped()) { | 60 | if (!GetPageEntry(gpu_addr + offset).IsUnmapped()) { |
| 61 | return {}; | 61 | return std::nullopt; |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | 64 | ||
| @@ -135,13 +135,13 @@ std::optional<GPUVAddr> MemoryManager::FindFreeRange(std::size_t size, std::size | |||
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | return {}; | 138 | return std::nullopt; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) const { | 141 | std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) const { |
| 142 | const auto page_entry{GetPageEntry(gpu_addr)}; | 142 | const auto page_entry{GetPageEntry(gpu_addr)}; |
| 143 | if (!page_entry.IsValid()) { | 143 | if (!page_entry.IsValid()) { |
| 144 | return {}; | 144 | return std::nullopt; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | return page_entry.ToAddress() + (gpu_addr & page_mask); | 147 | return page_entry.ToAddress() + (gpu_addr & page_mask); |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index ce3a65122..bbb8fb095 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -813,7 +813,7 @@ private: | |||
| 813 | const u8 location = static_cast<u8>(static_cast<u32>(index) * 4 + element); | 813 | const u8 location = static_cast<u8>(static_cast<u32>(index) * 4 + element); |
| 814 | const auto it = transform_feedback.find(location); | 814 | const auto it = transform_feedback.find(location); |
| 815 | if (it == transform_feedback.end()) { | 815 | if (it == transform_feedback.end()) { |
| 816 | return {}; | 816 | return std::nullopt; |
| 817 | } | 817 | } |
| 818 | return it->second.components; | 818 | return it->second.components; |
| 819 | } | 819 | } |
| @@ -1295,21 +1295,21 @@ private: | |||
| 1295 | switch (element) { | 1295 | switch (element) { |
| 1296 | case 0: | 1296 | case 0: |
| 1297 | UNIMPLEMENTED(); | 1297 | UNIMPLEMENTED(); |
| 1298 | return {}; | 1298 | return std::nullopt; |
| 1299 | case 1: | 1299 | case 1: |
| 1300 | if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) { | 1300 | if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) { |
| 1301 | return {}; | 1301 | return std::nullopt; |
| 1302 | } | 1302 | } |
| 1303 | return {{"gl_Layer", Type::Int}}; | 1303 | return {{"gl_Layer", Type::Int}}; |
| 1304 | case 2: | 1304 | case 2: |
| 1305 | if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) { | 1305 | if (stage == ShaderType::Vertex && !device.HasVertexViewportLayer()) { |
| 1306 | return {}; | 1306 | return std::nullopt; |
| 1307 | } | 1307 | } |
| 1308 | return {{"gl_ViewportIndex", Type::Int}}; | 1308 | return {{"gl_ViewportIndex", Type::Int}}; |
| 1309 | case 3: | 1309 | case 3: |
| 1310 | return {{"gl_PointSize", Type::Float}}; | 1310 | return {{"gl_PointSize", Type::Float}}; |
| 1311 | } | 1311 | } |
| 1312 | return {}; | 1312 | return std::nullopt; |
| 1313 | case Attribute::Index::FrontColor: | 1313 | case Attribute::Index::FrontColor: |
| 1314 | return {{"gl_FrontColor"s + GetSwizzle(element), Type::Float}}; | 1314 | return {{"gl_FrontColor"s + GetSwizzle(element), Type::Float}}; |
| 1315 | case Attribute::Index::FrontSecondaryColor: | 1315 | case Attribute::Index::FrontSecondaryColor: |
| @@ -1332,7 +1332,7 @@ private: | |||
| 1332 | Type::Float}}; | 1332 | Type::Float}}; |
| 1333 | } | 1333 | } |
| 1334 | UNIMPLEMENTED_MSG("Unhandled output attribute: {}", static_cast<u32>(attribute)); | 1334 | UNIMPLEMENTED_MSG("Unhandled output attribute: {}", static_cast<u32>(attribute)); |
| 1335 | return {}; | 1335 | return std::nullopt; |
| 1336 | } | 1336 | } |
| 1337 | } | 1337 | } |
| 1338 | 1338 | ||
diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index cca13bcde..8e5a22ab3 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h | |||
| @@ -199,55 +199,48 @@ public: | |||
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | std::optional<u32> GetGotoLabel() const { | 201 | std::optional<u32> GetGotoLabel() const { |
| 202 | auto inner = std::get_if<ASTGoto>(&data); | 202 | if (const auto* inner = std::get_if<ASTGoto>(&data)) { |
| 203 | if (inner) { | ||
| 204 | return {inner->label}; | 203 | return {inner->label}; |
| 205 | } | 204 | } |
| 206 | return {}; | 205 | return std::nullopt; |
| 207 | } | 206 | } |
| 208 | 207 | ||
| 209 | Expr GetGotoCondition() const { | 208 | Expr GetGotoCondition() const { |
| 210 | auto inner = std::get_if<ASTGoto>(&data); | 209 | if (const auto* inner = std::get_if<ASTGoto>(&data)) { |
| 211 | if (inner) { | ||
| 212 | return inner->condition; | 210 | return inner->condition; |
| 213 | } | 211 | } |
| 214 | return nullptr; | 212 | return nullptr; |
| 215 | } | 213 | } |
| 216 | 214 | ||
| 217 | void MarkLabelUnused() { | 215 | void MarkLabelUnused() { |
| 218 | auto inner = std::get_if<ASTLabel>(&data); | 216 | if (auto* inner = std::get_if<ASTLabel>(&data)) { |
| 219 | if (inner) { | ||
| 220 | inner->unused = true; | 217 | inner->unused = true; |
| 221 | } | 218 | } |
| 222 | } | 219 | } |
| 223 | 220 | ||
| 224 | bool IsLabelUnused() const { | 221 | bool IsLabelUnused() const { |
| 225 | auto inner = std::get_if<ASTLabel>(&data); | 222 | if (const auto* inner = std::get_if<ASTLabel>(&data)) { |
| 226 | if (inner) { | ||
| 227 | return inner->unused; | 223 | return inner->unused; |
| 228 | } | 224 | } |
| 229 | return true; | 225 | return true; |
| 230 | } | 226 | } |
| 231 | 227 | ||
| 232 | std::optional<u32> GetLabelIndex() const { | 228 | std::optional<u32> GetLabelIndex() const { |
| 233 | auto inner = std::get_if<ASTLabel>(&data); | 229 | if (const auto* inner = std::get_if<ASTLabel>(&data)) { |
| 234 | if (inner) { | ||
| 235 | return {inner->index}; | 230 | return {inner->index}; |
| 236 | } | 231 | } |
| 237 | return {}; | 232 | return std::nullopt; |
| 238 | } | 233 | } |
| 239 | 234 | ||
| 240 | Expr GetIfCondition() const { | 235 | Expr GetIfCondition() const { |
| 241 | auto inner = std::get_if<ASTIfThen>(&data); | 236 | if (const auto* inner = std::get_if<ASTIfThen>(&data)) { |
| 242 | if (inner) { | ||
| 243 | return inner->condition; | 237 | return inner->condition; |
| 244 | } | 238 | } |
| 245 | return nullptr; | 239 | return nullptr; |
| 246 | } | 240 | } |
| 247 | 241 | ||
| 248 | void SetGotoCondition(Expr new_condition) { | 242 | void SetGotoCondition(Expr new_condition) { |
| 249 | auto inner = std::get_if<ASTGoto>(&data); | 243 | if (auto* inner = std::get_if<ASTGoto>(&data)) { |
| 250 | if (inner) { | ||
| 251 | inner->condition = std::move(new_condition); | 244 | inner->condition = std::move(new_condition); |
| 252 | } | 245 | } |
| 253 | } | 246 | } |
diff --git a/src/video_core/shader/track.cpp b/src/video_core/shader/track.cpp index d5ed81442..6be3ea92b 100644 --- a/src/video_core/shader/track.cpp +++ b/src/video_core/shader/track.cpp | |||
| @@ -205,12 +205,12 @@ std::optional<u32> ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, | |||
| 205 | const auto result = TrackRegister(&std::get<GprNode>(*tracked), code, cursor - 1); | 205 | const auto result = TrackRegister(&std::get<GprNode>(*tracked), code, cursor - 1); |
| 206 | const auto& found = result.first; | 206 | const auto& found = result.first; |
| 207 | if (!found) { | 207 | if (!found) { |
| 208 | return {}; | 208 | return std::nullopt; |
| 209 | } | 209 | } |
| 210 | if (const auto immediate = std::get_if<ImmediateNode>(&*found)) { | 210 | if (const auto immediate = std::get_if<ImmediateNode>(&*found)) { |
| 211 | return immediate->GetValue(); | 211 | return immediate->GetValue(); |
| 212 | } | 212 | } |
| 213 | return {}; | 213 | return std::nullopt; |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, | 216 | std::pair<Node, s64> ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, |
diff --git a/src/video_core/texture_cache/surface_base.cpp b/src/video_core/texture_cache/surface_base.cpp index dfcf36e0b..b44c09d71 100644 --- a/src/video_core/texture_cache/surface_base.cpp +++ b/src/video_core/texture_cache/surface_base.cpp | |||
| @@ -115,20 +115,24 @@ std::optional<std::pair<u32, u32>> SurfaceBaseImpl::GetLayerMipmap( | |||
| 115 | if (gpu_addr == candidate_gpu_addr) { | 115 | if (gpu_addr == candidate_gpu_addr) { |
| 116 | return {{0, 0}}; | 116 | return {{0, 0}}; |
| 117 | } | 117 | } |
| 118 | |||
| 118 | if (candidate_gpu_addr < gpu_addr) { | 119 | if (candidate_gpu_addr < gpu_addr) { |
| 119 | return {}; | 120 | return std::nullopt; |
| 120 | } | 121 | } |
| 122 | |||
| 121 | const auto relative_address{static_cast<GPUVAddr>(candidate_gpu_addr - gpu_addr)}; | 123 | const auto relative_address{static_cast<GPUVAddr>(candidate_gpu_addr - gpu_addr)}; |
| 122 | const auto layer{static_cast<u32>(relative_address / layer_size)}; | 124 | const auto layer{static_cast<u32>(relative_address / layer_size)}; |
| 123 | if (layer >= params.depth) { | 125 | if (layer >= params.depth) { |
| 124 | return {}; | 126 | return std::nullopt; |
| 125 | } | 127 | } |
| 128 | |||
| 126 | const GPUVAddr mipmap_address = relative_address - layer_size * layer; | 129 | const GPUVAddr mipmap_address = relative_address - layer_size * layer; |
| 127 | const auto mipmap_it = | 130 | const auto mipmap_it = |
| 128 | Common::BinaryFind(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address); | 131 | Common::BinaryFind(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address); |
| 129 | if (mipmap_it == mipmap_offsets.end()) { | 132 | if (mipmap_it == mipmap_offsets.end()) { |
| 130 | return {}; | 133 | return std::nullopt; |
| 131 | } | 134 | } |
| 135 | |||
| 132 | const auto level{static_cast<u32>(std::distance(mipmap_offsets.begin(), mipmap_it))}; | 136 | const auto level{static_cast<u32>(std::distance(mipmap_offsets.begin(), mipmap_it))}; |
| 133 | return std::make_pair(layer, level); | 137 | return std::make_pair(layer, level); |
| 134 | } | 138 | } |