summaryrefslogtreecommitdiff
path: root/src/video_core/shader/decode
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-09-25 09:53:18 -0400
committerGravatar FernandoS272019-10-25 09:01:30 -0400
commit33fcec3502f5dd5a99b7a8337128b7c99bfba908 (patch)
tree4f41d09678600fc3e12708f8a4f8ae2f05c37ad1 /src/video_core/shader/decode
parentShader_IR: Implement Fast BRX and allow multi-branches in the CFG. (diff)
downloadyuzu-33fcec3502f5dd5a99b7a8337128b7c99bfba908.tar.gz
yuzu-33fcec3502f5dd5a99b7a8337128b7c99bfba908.tar.xz
yuzu-33fcec3502f5dd5a99b7a8337128b7c99bfba908.zip
Shader_IR: allow lookup of texture samplers within the shader_ir for instructions that don't provide it
Diffstat (limited to 'src/video_core/shader/decode')
-rw-r--r--src/video_core/shader/decode/texture.cpp72
1 files changed, 54 insertions, 18 deletions
diff --git a/src/video_core/shader/decode/texture.cpp b/src/video_core/shader/decode/texture.cpp
index 0b934a069..c369e23ad 100644
--- a/src/video_core/shader/decode/texture.cpp
+++ b/src/video_core/shader/decode/texture.cpp
@@ -141,7 +141,7 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) {
141 const Node component = Immediate(static_cast<u32>(instr.tld4s.component)); 141 const Node component = Immediate(static_cast<u32>(instr.tld4s.component));
142 142
143 const auto& sampler = 143 const auto& sampler =
144 GetSampler(instr.sampler, TextureType::Texture2D, false, depth_compare); 144 GetSampler(instr.sampler, {{TextureType::Texture2D, false, depth_compare}});
145 145
146 Node4 values; 146 Node4 values;
147 for (u32 element = 0; element < values.size(); ++element) { 147 for (u32 element = 0; element < values.size(); ++element) {
@@ -165,10 +165,7 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) {
165 // Sadly, not all texture instructions specify the type of texture their sampler 165 // Sadly, not all texture instructions specify the type of texture their sampler
166 // uses. This must be fixed at a later instance. 166 // uses. This must be fixed at a later instance.
167 const auto& sampler = 167 const auto& sampler =
168 is_bindless 168 is_bindless ? GetBindlessSampler(instr.gpr8, {}) : GetSampler(instr.sampler, {});
169 ? GetBindlessSampler(instr.gpr8, Tegra::Shader::TextureType::Texture2D, false,
170 false)
171 : GetSampler(instr.sampler, Tegra::Shader::TextureType::Texture2D, false, false);
172 169
173 u32 indexer = 0; 170 u32 indexer = 0;
174 switch (instr.txq.query_type) { 171 switch (instr.txq.query_type) {
@@ -207,9 +204,9 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) {
207 204
208 auto texture_type = instr.tmml.texture_type.Value(); 205 auto texture_type = instr.tmml.texture_type.Value();
209 const bool is_array = instr.tmml.array != 0; 206 const bool is_array = instr.tmml.array != 0;
210 const auto& sampler = is_bindless 207 const auto& sampler =
211 ? GetBindlessSampler(instr.gpr20, texture_type, is_array, false) 208 is_bindless ? GetBindlessSampler(instr.gpr20, {{texture_type, is_array, false}})
212 : GetSampler(instr.sampler, texture_type, is_array, false); 209 : GetSampler(instr.sampler, {{texture_type, is_array, false}});
213 210
214 std::vector<Node> coords; 211 std::vector<Node> coords;
215 212
@@ -285,10 +282,30 @@ u32 ShaderIR::DecodeTexture(NodeBlock& bb, u32 pc) {
285 return pc; 282 return pc;
286} 283}
287 284
288const Sampler& ShaderIR::GetSampler(const Tegra::Shader::Sampler& sampler, TextureType type, 285const Sampler& ShaderIR::GetSampler(const Tegra::Shader::Sampler& sampler,
289 bool is_array, bool is_shadow) { 286 std::optional<SamplerInfo> sampler_info) {
290 const auto offset = static_cast<std::size_t>(sampler.index.Value()); 287 const auto offset = static_cast<std::size_t>(sampler.index.Value());
291 288
289 Tegra::Shader::TextureType type;
290 bool is_array;
291 bool is_shadow;
292 if (sampler_info) {
293 type = sampler_info->type;
294 is_array = sampler_info->is_array;
295 is_shadow = sampler_info->is_shadow;
296 } else {
297 auto sampler = locker.ObtainBoundSampler(offset);
298 if (sampler) {
299 type = sampler->texture_type.Value();
300 is_array = sampler->is_array.Value() != 0;
301 is_shadow = sampler->is_shadow.Value() != 0;
302 } else {
303 type = Tegra::Shader::TextureType::Texture2D;
304 is_array = false;
305 is_shadow = false;
306 }
307 }
308
292 // If this sampler has already been used, return the existing mapping. 309 // If this sampler has already been used, return the existing mapping.
293 const auto itr = 310 const auto itr =
294 std::find_if(used_samplers.begin(), used_samplers.end(), 311 std::find_if(used_samplers.begin(), used_samplers.end(),
@@ -305,13 +322,32 @@ const Sampler& ShaderIR::GetSampler(const Tegra::Shader::Sampler& sampler, Textu
305 return *used_samplers.emplace(entry).first; 322 return *used_samplers.emplace(entry).first;
306} 323}
307 324
308const Sampler& ShaderIR::GetBindlessSampler(const Tegra::Shader::Register& reg, TextureType type, 325const Sampler& ShaderIR::GetBindlessSampler(const Tegra::Shader::Register& reg,
309 bool is_array, bool is_shadow) { 326 std::optional<SamplerInfo> sampler_info) {
310 const Node sampler_register = GetRegister(reg); 327 const Node sampler_register = GetRegister(reg);
311 const auto [base_sampler, cbuf_index, cbuf_offset] = 328 const auto [base_sampler, cbuf_index, cbuf_offset] =
312 TrackCbuf(sampler_register, global_code, static_cast<s64>(global_code.size())); 329 TrackCbuf(sampler_register, global_code, static_cast<s64>(global_code.size()));
313 ASSERT(base_sampler != nullptr); 330 ASSERT(base_sampler != nullptr);
314 const auto cbuf_key = (static_cast<u64>(cbuf_index) << 32) | static_cast<u64>(cbuf_offset); 331 const auto cbuf_key = (static_cast<u64>(cbuf_index) << 32) | static_cast<u64>(cbuf_offset);
332 Tegra::Shader::TextureType type;
333 bool is_array;
334 bool is_shadow;
335 if (sampler_info) {
336 type = sampler_info->type;
337 is_array = sampler_info->is_array;
338 is_shadow = sampler_info->is_shadow;
339 } else {
340 auto sampler = locker.ObtainBindlessSampler(cbuf_index, cbuf_offset);
341 if (sampler) {
342 type = sampler->texture_type.Value();
343 is_array = sampler->is_array.Value() != 0;
344 is_shadow = sampler->is_shadow.Value() != 0;
345 } else {
346 type = Tegra::Shader::TextureType::Texture2D;
347 is_array = false;
348 is_shadow = false;
349 }
350 }
315 351
316 // If this sampler has already been used, return the existing mapping. 352 // If this sampler has already been used, return the existing mapping.
317 const auto itr = 353 const auto itr =
@@ -411,9 +447,9 @@ Node4 ShaderIR::GetTextureCode(Instruction instr, TextureType texture_type,
411 (texture_type == TextureType::TextureCube && is_array && is_shadow), 447 (texture_type == TextureType::TextureCube && is_array && is_shadow),
412 "This method is not supported."); 448 "This method is not supported.");
413 449
414 const auto& sampler = is_bindless 450 const auto& sampler =
415 ? GetBindlessSampler(*bindless_reg, texture_type, is_array, is_shadow) 451 is_bindless ? GetBindlessSampler(*bindless_reg, {{texture_type, is_array, is_shadow}})
416 : GetSampler(instr.sampler, texture_type, is_array, is_shadow); 452 : GetSampler(instr.sampler, {{texture_type, is_array, is_shadow}});
417 453
418 const bool lod_needed = process_mode == TextureProcessMode::LZ || 454 const bool lod_needed = process_mode == TextureProcessMode::LZ ||
419 process_mode == TextureProcessMode::LL || 455 process_mode == TextureProcessMode::LL ||
@@ -577,7 +613,7 @@ Node4 ShaderIR::GetTld4Code(Instruction instr, TextureType texture_type, bool de
577 dc = GetRegister(parameter_register++); 613 dc = GetRegister(parameter_register++);
578 } 614 }
579 615
580 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, depth_compare); 616 const auto& sampler = GetSampler(instr.sampler, {{texture_type, is_array, depth_compare}});
581 617
582 Node4 values; 618 Node4 values;
583 for (u32 element = 0; element < values.size(); ++element) { 619 for (u32 element = 0; element < values.size(); ++element) {
@@ -610,7 +646,7 @@ Node4 ShaderIR::GetTldCode(Tegra::Shader::Instruction instr) {
610 // const Node aoffi_register{is_aoffi ? GetRegister(gpr20_cursor++) : nullptr}; 646 // const Node aoffi_register{is_aoffi ? GetRegister(gpr20_cursor++) : nullptr};
611 // const Node multisample{is_multisample ? GetRegister(gpr20_cursor++) : nullptr}; 647 // const Node multisample{is_multisample ? GetRegister(gpr20_cursor++) : nullptr};
612 648
613 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, false); 649 const auto& sampler = GetSampler(instr.sampler, {{texture_type, is_array, false}});
614 650
615 Node4 values; 651 Node4 values;
616 for (u32 element = 0; element < values.size(); ++element) { 652 for (u32 element = 0; element < values.size(); ++element) {
@@ -646,7 +682,7 @@ Node4 ShaderIR::GetTldsCode(Instruction instr, TextureType texture_type, bool is
646 // When lod is used always is in gpr20 682 // When lod is used always is in gpr20
647 const Node lod = lod_enabled ? GetRegister(instr.gpr20) : Immediate(0); 683 const Node lod = lod_enabled ? GetRegister(instr.gpr20) : Immediate(0);
648 684
649 const auto& sampler = GetSampler(instr.sampler, texture_type, is_array, false); 685 const auto& sampler = GetSampler(instr.sampler, {{texture_type, is_array, false}});
650 686
651 Node4 values; 687 Node4 values;
652 for (u32 element = 0; element < values.size(); ++element) { 688 for (u32 element = 0; element < values.size(); ++element) {