diff options
Diffstat (limited to 'src/video_core/shader/decode')
| -rw-r--r-- | src/video_core/shader/decode/texture.cpp | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/src/video_core/shader/decode/texture.cpp b/src/video_core/shader/decode/texture.cpp index 8f0bb996e..29ebf65ba 100644 --- a/src/video_core/shader/decode/texture.cpp +++ b/src/video_core/shader/decode/texture.cpp | |||
| @@ -357,13 +357,11 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) { | |||
| 357 | return pc; | 357 | return pc; |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | ShaderIR::SamplerInfo ShaderIR::GetSamplerInfo(SamplerInfo info, u32 offset, | 360 | ShaderIR::SamplerInfo ShaderIR::GetSamplerInfo( |
| 361 | std::optional<u32> buffer) { | 361 | SamplerInfo info, std::optional<Tegra::Engines::SamplerDescriptor> sampler) { |
| 362 | if (info.IsComplete()) { | 362 | if (info.IsComplete()) { |
| 363 | return info; | 363 | return info; |
| 364 | } | 364 | } |
| 365 | const auto sampler = buffer ? registry.ObtainBindlessSampler(*buffer, offset) | ||
| 366 | : registry.ObtainBoundSampler(offset); | ||
| 367 | if (!sampler) { | 365 | if (!sampler) { |
| 368 | LOG_WARNING(HW_GPU, "Unknown sampler info"); | 366 | LOG_WARNING(HW_GPU, "Unknown sampler info"); |
| 369 | info.type = info.type.value_or(Tegra::Shader::TextureType::Texture2D); | 367 | info.type = info.type.value_or(Tegra::Shader::TextureType::Texture2D); |
| @@ -381,8 +379,8 @@ ShaderIR::SamplerInfo ShaderIR::GetSamplerInfo(SamplerInfo info, u32 offset, | |||
| 381 | 379 | ||
| 382 | std::optional<Sampler> ShaderIR::GetSampler(Tegra::Shader::Sampler sampler, | 380 | std::optional<Sampler> ShaderIR::GetSampler(Tegra::Shader::Sampler sampler, |
| 383 | SamplerInfo sampler_info) { | 381 | SamplerInfo sampler_info) { |
| 384 | const auto offset = static_cast<u32>(sampler.index.Value()); | 382 | const u32 offset = static_cast<u32>(sampler.index.Value()); |
| 385 | const auto info = GetSamplerInfo(sampler_info, offset); | 383 | const auto info = GetSamplerInfo(sampler_info, registry.ObtainBoundSampler(offset)); |
| 386 | 384 | ||
| 387 | // If this sampler has already been used, return the existing mapping. | 385 | // If this sampler has already been used, return the existing mapping. |
| 388 | const auto it = std::find_if(used_samplers.begin(), used_samplers.end(), | 386 | const auto it = std::find_if(used_samplers.begin(), used_samplers.end(), |
| @@ -404,20 +402,19 @@ std::optional<Sampler> ShaderIR::GetBindlessSampler(Tegra::Shader::Register reg, | |||
| 404 | const Node sampler_register = GetRegister(reg); | 402 | const Node sampler_register = GetRegister(reg); |
| 405 | const auto [base_node, tracked_sampler_info] = | 403 | const auto [base_node, tracked_sampler_info] = |
| 406 | TrackBindlessSampler(sampler_register, global_code, static_cast<s64>(global_code.size())); | 404 | TrackBindlessSampler(sampler_register, global_code, static_cast<s64>(global_code.size())); |
| 407 | ASSERT(base_node != nullptr); | 405 | if (!base_node) { |
| 408 | if (base_node == nullptr) { | 406 | UNREACHABLE(); |
| 409 | return std::nullopt; | 407 | return std::nullopt; |
| 410 | } | 408 | } |
| 411 | 409 | ||
| 412 | if (const auto bindless_sampler_info = | 410 | if (const auto sampler_info = std::get_if<BindlessSamplerNode>(&*tracked_sampler_info)) { |
| 413 | std::get_if<BindlessSamplerNode>(&*tracked_sampler_info)) { | 411 | const u32 buffer = sampler_info->index; |
| 414 | const u32 buffer = bindless_sampler_info->GetIndex(); | 412 | const u32 offset = sampler_info->offset; |
| 415 | const u32 offset = bindless_sampler_info->GetOffset(); | 413 | info = GetSamplerInfo(info, registry.ObtainBindlessSampler(buffer, offset)); |
| 416 | info = GetSamplerInfo(info, offset, buffer); | ||
| 417 | 414 | ||
| 418 | // If this sampler has already been used, return the existing mapping. | 415 | // If this sampler has already been used, return the existing mapping. |
| 419 | const auto it = std::find_if(used_samplers.begin(), used_samplers.end(), | 416 | const auto it = std::find_if(used_samplers.begin(), used_samplers.end(), |
| 420 | [buffer = buffer, offset = offset](const Sampler& entry) { | 417 | [buffer, offset](const Sampler& entry) { |
| 421 | return entry.buffer == buffer && entry.offset == offset; | 418 | return entry.buffer == buffer && entry.offset == offset; |
| 422 | }); | 419 | }); |
| 423 | if (it != used_samplers.end()) { | 420 | if (it != used_samplers.end()) { |
| @@ -431,10 +428,32 @@ std::optional<Sampler> ShaderIR::GetBindlessSampler(Tegra::Shader::Register reg, | |||
| 431 | return used_samplers.emplace_back(next_index, offset, buffer, *info.type, *info.is_array, | 428 | return used_samplers.emplace_back(next_index, offset, buffer, *info.type, *info.is_array, |
| 432 | *info.is_shadow, *info.is_buffer, false); | 429 | *info.is_shadow, *info.is_buffer, false); |
| 433 | } | 430 | } |
| 434 | if (const auto array_sampler_info = std::get_if<ArraySamplerNode>(&*tracked_sampler_info)) { | 431 | if (const auto sampler_info = std::get_if<SeparateSamplerNode>(&*tracked_sampler_info)) { |
| 435 | const u32 base_offset = array_sampler_info->GetBaseOffset() / 4; | 432 | const std::pair indices = sampler_info->indices; |
| 436 | index_var = GetCustomVariable(array_sampler_info->GetIndexVar()); | 433 | const std::pair offsets = sampler_info->offsets; |
| 437 | info = GetSamplerInfo(info, base_offset); | 434 | info = GetSamplerInfo(info, registry.ObtainSeparateSampler(indices, offsets)); |
| 435 | |||
| 436 | // Try to use an already created sampler if it exists | ||
| 437 | const auto it = std::find_if( | ||
| 438 | used_samplers.begin(), used_samplers.end(), [indices, offsets](const Sampler& entry) { | ||
| 439 | return offsets == std::pair{entry.offset, entry.secondary_offset} && | ||
| 440 | indices == std::pair{entry.buffer, entry.secondary_buffer}; | ||
| 441 | }); | ||
| 442 | if (it != used_samplers.end()) { | ||
| 443 | ASSERT(it->is_separated && it->type == info.type && it->is_array == info.is_array && | ||
| 444 | it->is_shadow == info.is_shadow && it->is_buffer == info.is_buffer); | ||
| 445 | return *it; | ||
| 446 | } | ||
| 447 | |||
| 448 | // Otherwise create a new mapping for this sampler | ||
| 449 | const u32 next_index = static_cast<u32>(used_samplers.size()); | ||
| 450 | return used_samplers.emplace_back(next_index, offsets, indices, *info.type, *info.is_array, | ||
| 451 | *info.is_shadow, *info.is_buffer); | ||
| 452 | } | ||
| 453 | if (const auto sampler_info = std::get_if<ArraySamplerNode>(&*tracked_sampler_info)) { | ||
| 454 | const u32 base_offset = sampler_info->base_offset / 4; | ||
| 455 | index_var = GetCustomVariable(sampler_info->bindless_var); | ||
| 456 | info = GetSamplerInfo(info, registry.ObtainBoundSampler(base_offset)); | ||
| 438 | 457 | ||
| 439 | // If this sampler has already been used, return the existing mapping. | 458 | // If this sampler has already been used, return the existing mapping. |
| 440 | const auto it = std::find_if( | 459 | const auto it = std::find_if( |