diff options
Diffstat (limited to 'src/shader_recompiler/ir_opt/texture_pass.cpp')
| -rw-r--r-- | src/shader_recompiler/ir_opt/texture_pass.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp index d374c976a..100437f0e 100644 --- a/src/shader_recompiler/ir_opt/texture_pass.cpp +++ b/src/shader_recompiler/ir_opt/texture_pass.cpp | |||
| @@ -372,6 +372,10 @@ TexturePixelFormat ReadTexturePixelFormat(Environment& env, const ConstBufferAdd | |||
| 372 | return env.ReadTexturePixelFormat(GetTextureHandle(env, cbuf)); | 372 | return env.ReadTexturePixelFormat(GetTextureHandle(env, cbuf)); |
| 373 | } | 373 | } |
| 374 | 374 | ||
| 375 | bool IsTexturePixelFormatInteger(Environment& env, const ConstBufferAddr& cbuf) { | ||
| 376 | return env.IsTexturePixelFormatInteger(GetTextureHandle(env, cbuf)); | ||
| 377 | } | ||
| 378 | |||
| 375 | class Descriptors { | 379 | class Descriptors { |
| 376 | public: | 380 | public: |
| 377 | explicit Descriptors(TextureBufferDescriptors& texture_buffer_descriptors_, | 381 | explicit Descriptors(TextureBufferDescriptors& texture_buffer_descriptors_, |
| @@ -403,6 +407,7 @@ public: | |||
| 403 | })}; | 407 | })}; |
| 404 | image_buffer_descriptors[index].is_written |= desc.is_written; | 408 | image_buffer_descriptors[index].is_written |= desc.is_written; |
| 405 | image_buffer_descriptors[index].is_read |= desc.is_read; | 409 | image_buffer_descriptors[index].is_read |= desc.is_read; |
| 410 | image_buffer_descriptors[index].is_integer |= desc.is_integer; | ||
| 406 | return index; | 411 | return index; |
| 407 | } | 412 | } |
| 408 | 413 | ||
| @@ -432,6 +437,7 @@ public: | |||
| 432 | })}; | 437 | })}; |
| 433 | image_descriptors[index].is_written |= desc.is_written; | 438 | image_descriptors[index].is_written |= desc.is_written; |
| 434 | image_descriptors[index].is_read |= desc.is_read; | 439 | image_descriptors[index].is_read |= desc.is_read; |
| 440 | image_descriptors[index].is_integer |= desc.is_integer; | ||
| 435 | return index; | 441 | return index; |
| 436 | } | 442 | } |
| 437 | 443 | ||
| @@ -469,6 +475,20 @@ void PatchImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) { | |||
| 469 | ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 1)))))); | 475 | ir.FPRecip(ir.ConvertUToF(32, 32, ir.CompositeExtract(texture_size, 1)))))); |
| 470 | } | 476 | } |
| 471 | 477 | ||
| 478 | bool IsPixelFormatSNorm(TexturePixelFormat pixel_format) { | ||
| 479 | switch (pixel_format) { | ||
| 480 | case TexturePixelFormat::A8B8G8R8_SNORM: | ||
| 481 | case TexturePixelFormat::R8G8_SNORM: | ||
| 482 | case TexturePixelFormat::R8_SNORM: | ||
| 483 | case TexturePixelFormat::R16G16B16A16_SNORM: | ||
| 484 | case TexturePixelFormat::R16G16_SNORM: | ||
| 485 | case TexturePixelFormat::R16_SNORM: | ||
| 486 | return true; | ||
| 487 | default: | ||
| 488 | return false; | ||
| 489 | } | ||
| 490 | } | ||
| 491 | |||
| 472 | void PatchTexelFetch(IR::Block& block, IR::Inst& inst, TexturePixelFormat pixel_format) { | 492 | void PatchTexelFetch(IR::Block& block, IR::Inst& inst, TexturePixelFormat pixel_format) { |
| 473 | const auto it{IR::Block::InstructionList::s_iterator_to(inst)}; | 493 | const auto it{IR::Block::InstructionList::s_iterator_to(inst)}; |
| 474 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | 494 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; |
| @@ -587,11 +607,13 @@ void TexturePass(Environment& env, IR::Program& program, const HostTranslateInfo | |||
| 587 | } | 607 | } |
| 588 | const bool is_written{inst->GetOpcode() != IR::Opcode::ImageRead}; | 608 | const bool is_written{inst->GetOpcode() != IR::Opcode::ImageRead}; |
| 589 | const bool is_read{inst->GetOpcode() != IR::Opcode::ImageWrite}; | 609 | const bool is_read{inst->GetOpcode() != IR::Opcode::ImageWrite}; |
| 610 | const bool is_integer{IsTexturePixelFormatInteger(env, cbuf)}; | ||
| 590 | if (flags.type == TextureType::Buffer) { | 611 | if (flags.type == TextureType::Buffer) { |
| 591 | index = descriptors.Add(ImageBufferDescriptor{ | 612 | index = descriptors.Add(ImageBufferDescriptor{ |
| 592 | .format = flags.image_format, | 613 | .format = flags.image_format, |
| 593 | .is_written = is_written, | 614 | .is_written = is_written, |
| 594 | .is_read = is_read, | 615 | .is_read = is_read, |
| 616 | .is_integer = is_integer, | ||
| 595 | .cbuf_index = cbuf.index, | 617 | .cbuf_index = cbuf.index, |
| 596 | .cbuf_offset = cbuf.offset, | 618 | .cbuf_offset = cbuf.offset, |
| 597 | .count = cbuf.count, | 619 | .count = cbuf.count, |
| @@ -603,6 +625,7 @@ void TexturePass(Environment& env, IR::Program& program, const HostTranslateInfo | |||
| 603 | .format = flags.image_format, | 625 | .format = flags.image_format, |
| 604 | .is_written = is_written, | 626 | .is_written = is_written, |
| 605 | .is_read = is_read, | 627 | .is_read = is_read, |
| 628 | .is_integer = is_integer, | ||
| 606 | .cbuf_index = cbuf.index, | 629 | .cbuf_index = cbuf.index, |
| 607 | .cbuf_offset = cbuf.offset, | 630 | .cbuf_offset = cbuf.offset, |
| 608 | .count = cbuf.count, | 631 | .count = cbuf.count, |
| @@ -658,7 +681,7 @@ void TexturePass(Environment& env, IR::Program& program, const HostTranslateInfo | |||
| 658 | if (!host_info.support_snorm_render_buffer && inst->GetOpcode() == IR::Opcode::ImageFetch && | 681 | if (!host_info.support_snorm_render_buffer && inst->GetOpcode() == IR::Opcode::ImageFetch && |
| 659 | flags.type == TextureType::Buffer) { | 682 | flags.type == TextureType::Buffer) { |
| 660 | const auto pixel_format = ReadTexturePixelFormat(env, cbuf); | 683 | const auto pixel_format = ReadTexturePixelFormat(env, cbuf); |
| 661 | if (pixel_format != TexturePixelFormat::OTHER) { | 684 | if (IsPixelFormatSNorm(pixel_format)) { |
| 662 | PatchTexelFetch(*texture_inst.block, *texture_inst.inst, pixel_format); | 685 | PatchTexelFetch(*texture_inst.block, *texture_inst.inst, pixel_format); |
| 663 | } | 686 | } |
| 664 | } | 687 | } |