diff options
| author | 2019-05-19 02:27:00 -0400 | |
|---|---|---|
| committer | 2019-05-19 02:46:38 -0400 | |
| commit | f417be9d3be297f5f4ccdf5d31b80394cfdb6c69 (patch) | |
| tree | 5c92eeb08f7c1643b9b3474cd88761c06b4cfe01 /src | |
| parent | Merge pull request #2457 from lioncash/about (diff) | |
| download | yuzu-f417be9d3be297f5f4ccdf5d31b80394cfdb6c69.tar.gz yuzu-f417be9d3be297f5f4ccdf5d31b80394cfdb6c69.tar.xz yuzu-f417be9d3be297f5f4ccdf5d31b80394cfdb6c69.zip | |
gl_shader_disk_cache: Special-case boolean handling
Booleans don't have a guaranteed size, but we still want to have them
integrate into the disk cache system without needing to actually use a
different type. We can do this by supplying non-template overloads for
the bool type.
Non-template overloads always have precedence during function
resolution, so this is safe to provide.
This gets rid of the need to smatter ternary conditionals, as well as
the need to use u8 types to store the value in.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | 43 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.h | 18 |
2 files changed, 37 insertions, 24 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 254c0d499..1ba16d4ca 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | |||
| @@ -303,12 +303,12 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn | |||
| 303 | for (u32 i = 0; i < const_buffers_count; ++i) { | 303 | for (u32 i = 0; i < const_buffers_count; ++i) { |
| 304 | u32 max_offset{}; | 304 | u32 max_offset{}; |
| 305 | u32 index{}; | 305 | u32 index{}; |
| 306 | u8 is_indirect{}; | 306 | bool is_indirect{}; |
| 307 | if (!LoadObjectFromPrecompiled(max_offset) || !LoadObjectFromPrecompiled(index) || | 307 | if (!LoadObjectFromPrecompiled(max_offset) || !LoadObjectFromPrecompiled(index) || |
| 308 | !LoadObjectFromPrecompiled(is_indirect)) { | 308 | !LoadObjectFromPrecompiled(is_indirect)) { |
| 309 | return {}; | 309 | return {}; |
| 310 | } | 310 | } |
| 311 | entry.entries.const_buffers.emplace_back(max_offset, is_indirect != 0, index); | 311 | entry.entries.const_buffers.emplace_back(max_offset, is_indirect, index); |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | u32 samplers_count{}; | 314 | u32 samplers_count{}; |
| @@ -320,18 +320,17 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn | |||
| 320 | u64 offset{}; | 320 | u64 offset{}; |
| 321 | u64 index{}; | 321 | u64 index{}; |
| 322 | u32 type{}; | 322 | u32 type{}; |
| 323 | u8 is_array{}; | 323 | bool is_array{}; |
| 324 | u8 is_shadow{}; | 324 | bool is_shadow{}; |
| 325 | u8 is_bindless{}; | 325 | bool is_bindless{}; |
| 326 | if (!LoadObjectFromPrecompiled(offset) || !LoadObjectFromPrecompiled(index) || | 326 | if (!LoadObjectFromPrecompiled(offset) || !LoadObjectFromPrecompiled(index) || |
| 327 | !LoadObjectFromPrecompiled(type) || !LoadObjectFromPrecompiled(is_array) || | 327 | !LoadObjectFromPrecompiled(type) || !LoadObjectFromPrecompiled(is_array) || |
| 328 | !LoadObjectFromPrecompiled(is_shadow) || !LoadObjectFromPrecompiled(is_bindless)) { | 328 | !LoadObjectFromPrecompiled(is_shadow) || !LoadObjectFromPrecompiled(is_bindless)) { |
| 329 | return {}; | 329 | return {}; |
| 330 | } | 330 | } |
| 331 | entry.entries.samplers.emplace_back(static_cast<std::size_t>(offset), | 331 | entry.entries.samplers.emplace_back( |
| 332 | static_cast<std::size_t>(index), | 332 | static_cast<std::size_t>(offset), static_cast<std::size_t>(index), |
| 333 | static_cast<Tegra::Shader::TextureType>(type), | 333 | static_cast<Tegra::Shader::TextureType>(type), is_array, is_shadow, is_bindless); |
| 334 | is_array != 0, is_shadow != 0, is_bindless != 0); | ||
| 335 | } | 334 | } |
| 336 | 335 | ||
| 337 | u32 global_memory_count{}; | 336 | u32 global_memory_count{}; |
| @@ -342,21 +341,20 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn | |||
| 342 | for (u32 i = 0; i < global_memory_count; ++i) { | 341 | for (u32 i = 0; i < global_memory_count; ++i) { |
| 343 | u32 cbuf_index{}; | 342 | u32 cbuf_index{}; |
| 344 | u32 cbuf_offset{}; | 343 | u32 cbuf_offset{}; |
| 345 | u8 is_read{}; | 344 | bool is_read{}; |
| 346 | u8 is_written{}; | 345 | bool is_written{}; |
| 347 | if (!LoadObjectFromPrecompiled(cbuf_index) || !LoadObjectFromPrecompiled(cbuf_offset) || | 346 | if (!LoadObjectFromPrecompiled(cbuf_index) || !LoadObjectFromPrecompiled(cbuf_offset) || |
| 348 | !LoadObjectFromPrecompiled(is_read) || !LoadObjectFromPrecompiled(is_written)) { | 347 | !LoadObjectFromPrecompiled(is_read) || !LoadObjectFromPrecompiled(is_written)) { |
| 349 | return {}; | 348 | return {}; |
| 350 | } | 349 | } |
| 351 | entry.entries.global_memory_entries.emplace_back(cbuf_index, cbuf_offset, is_read != 0, | 350 | entry.entries.global_memory_entries.emplace_back(cbuf_index, cbuf_offset, is_read, |
| 352 | is_written != 0); | 351 | is_written); |
| 353 | } | 352 | } |
| 354 | 353 | ||
| 355 | for (auto& clip_distance : entry.entries.clip_distances) { | 354 | for (auto& clip_distance : entry.entries.clip_distances) { |
| 356 | u8 clip_distance_raw{}; | 355 | if (!LoadObjectFromPrecompiled(clip_distance)) { |
| 357 | if (!LoadObjectFromPrecompiled(clip_distance_raw)) | ||
| 358 | return {}; | 356 | return {}; |
| 359 | clip_distance = clip_distance_raw != 0; | 357 | } |
| 360 | } | 358 | } |
| 361 | 359 | ||
| 362 | u64 shader_length{}; | 360 | u64 shader_length{}; |
| @@ -384,7 +382,7 @@ bool ShaderDiskCacheOpenGL::SaveDecompiledFile(u64 unique_identifier, const std: | |||
| 384 | for (const auto& cbuf : entries.const_buffers) { | 382 | for (const auto& cbuf : entries.const_buffers) { |
| 385 | if (!SaveObjectToPrecompiled(static_cast<u32>(cbuf.GetMaxOffset())) || | 383 | if (!SaveObjectToPrecompiled(static_cast<u32>(cbuf.GetMaxOffset())) || |
| 386 | !SaveObjectToPrecompiled(static_cast<u32>(cbuf.GetIndex())) || | 384 | !SaveObjectToPrecompiled(static_cast<u32>(cbuf.GetIndex())) || |
| 387 | !SaveObjectToPrecompiled(static_cast<u8>(cbuf.IsIndirect() ? 1 : 0))) { | 385 | !SaveObjectToPrecompiled(cbuf.IsIndirect())) { |
| 388 | return false; | 386 | return false; |
| 389 | } | 387 | } |
| 390 | } | 388 | } |
| @@ -396,9 +394,9 @@ bool ShaderDiskCacheOpenGL::SaveDecompiledFile(u64 unique_identifier, const std: | |||
| 396 | if (!SaveObjectToPrecompiled(static_cast<u64>(sampler.GetOffset())) || | 394 | if (!SaveObjectToPrecompiled(static_cast<u64>(sampler.GetOffset())) || |
| 397 | !SaveObjectToPrecompiled(static_cast<u64>(sampler.GetIndex())) || | 395 | !SaveObjectToPrecompiled(static_cast<u64>(sampler.GetIndex())) || |
| 398 | !SaveObjectToPrecompiled(static_cast<u32>(sampler.GetType())) || | 396 | !SaveObjectToPrecompiled(static_cast<u32>(sampler.GetType())) || |
| 399 | !SaveObjectToPrecompiled(static_cast<u8>(sampler.IsArray() ? 1 : 0)) || | 397 | !SaveObjectToPrecompiled(sampler.IsArray()) || |
| 400 | !SaveObjectToPrecompiled(static_cast<u8>(sampler.IsShadow() ? 1 : 0)) || | 398 | !SaveObjectToPrecompiled(sampler.IsShadow()) || |
| 401 | !SaveObjectToPrecompiled(static_cast<u8>(sampler.IsBindless() ? 1 : 0))) { | 399 | !SaveObjectToPrecompiled(sampler.IsBindless())) { |
| 402 | return false; | 400 | return false; |
| 403 | } | 401 | } |
| 404 | } | 402 | } |
| @@ -409,14 +407,13 @@ bool ShaderDiskCacheOpenGL::SaveDecompiledFile(u64 unique_identifier, const std: | |||
| 409 | for (const auto& gmem : entries.global_memory_entries) { | 407 | for (const auto& gmem : entries.global_memory_entries) { |
| 410 | if (!SaveObjectToPrecompiled(static_cast<u32>(gmem.GetCbufIndex())) || | 408 | if (!SaveObjectToPrecompiled(static_cast<u32>(gmem.GetCbufIndex())) || |
| 411 | !SaveObjectToPrecompiled(static_cast<u32>(gmem.GetCbufOffset())) || | 409 | !SaveObjectToPrecompiled(static_cast<u32>(gmem.GetCbufOffset())) || |
| 412 | !SaveObjectToPrecompiled(static_cast<u8>(gmem.IsRead() ? 1 : 0)) || | 410 | !SaveObjectToPrecompiled(gmem.IsRead()) || !SaveObjectToPrecompiled(gmem.IsWritten())) { |
| 413 | !SaveObjectToPrecompiled(static_cast<u8>(gmem.IsWritten() ? 1 : 0))) { | ||
| 414 | return false; | 411 | return false; |
| 415 | } | 412 | } |
| 416 | } | 413 | } |
| 417 | 414 | ||
| 418 | for (const bool clip_distance : entries.clip_distances) { | 415 | for (const bool clip_distance : entries.clip_distances) { |
| 419 | if (!SaveObjectToPrecompiled(static_cast<u8>(clip_distance ? 1 : 0))) { | 416 | if (!SaveObjectToPrecompiled(clip_distance)) { |
| 420 | return false; | 417 | return false; |
| 421 | } | 418 | } |
| 422 | } | 419 | } |
diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.h b/src/video_core/renderer_opengl/gl_shader_disk_cache.h index 0142b2e3b..34d4bd637 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h | |||
| @@ -259,12 +259,28 @@ private: | |||
| 259 | return SaveArrayToPrecompiled(&object, 1); | 259 | return SaveArrayToPrecompiled(&object, 1); |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | bool SaveObjectToPrecompiled(bool object) { | ||
| 263 | const auto value = static_cast<u8>(object); | ||
| 264 | return SaveArrayToPrecompiled(&value, 1); | ||
| 265 | } | ||
| 266 | |||
| 262 | template <typename T> | 267 | template <typename T> |
| 263 | bool LoadObjectFromPrecompiled(T& object) { | 268 | bool LoadObjectFromPrecompiled(T& object) { |
| 264 | return LoadArrayFromPrecompiled(&object, 1); | 269 | return LoadArrayFromPrecompiled(&object, 1); |
| 265 | } | 270 | } |
| 266 | 271 | ||
| 267 | // Copre system | 272 | bool LoadObjectFromPrecompiled(bool& object) { |
| 273 | u8 value; | ||
| 274 | const bool read_ok = LoadArrayFromPrecompiled(&value, 1); | ||
| 275 | if (!read_ok) { | ||
| 276 | return false; | ||
| 277 | } | ||
| 278 | |||
| 279 | object = value != 0; | ||
| 280 | return true; | ||
| 281 | } | ||
| 282 | |||
| 283 | // Core system | ||
| 268 | Core::System& system; | 284 | Core::System& system; |
| 269 | // Stored transferable shaders | 285 | // Stored transferable shaders |
| 270 | std::map<u64, std::unordered_set<ShaderDiskCacheUsage>> transferable; | 286 | std::map<u64, std::unordered_set<ShaderDiskCacheUsage>> transferable; |