summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/textures/astc.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/video_core/textures/astc.cpp b/src/video_core/textures/astc.cpp
index f62d5c987..365bde2f1 100644
--- a/src/video_core/textures/astc.cpp
+++ b/src/video_core/textures/astc.cpp
@@ -759,10 +759,10 @@ public:
759 // significant bits when going from larger to smaller bit depth 759 // significant bits when going from larger to smaller bit depth
760 // or by repeating the most significant bits when going from 760 // or by repeating the most significant bits when going from
761 // smaller to larger bit depths. 761 // smaller to larger bit depths.
762 void ChangeBitDepth(const u8 (&depth)[4]) { 762 void ChangeBitDepth() {
763 for (u32 i = 0; i < 4; i++) { 763 for (u32 i = 0; i < 4; i++) {
764 Component(i) = ChangeBitDepth(Component(i), m_BitDepth[i], depth[i]); 764 Component(i) = ChangeBitDepth(Component(i), m_BitDepth[i]);
765 m_BitDepth[i] = depth[i]; 765 m_BitDepth[i] = 8;
766 } 766 }
767 } 767 }
768 768
@@ -774,28 +774,23 @@ public:
774 774
775 // Changes the bit depth of a single component. See the comment 775 // Changes the bit depth of a single component. See the comment
776 // above for how we do this. 776 // above for how we do this.
777 static ChannelType ChangeBitDepth(Pixel::ChannelType val, u8 oldDepth, u8 newDepth) { 777 static ChannelType ChangeBitDepth(Pixel::ChannelType val, u8 oldDepth) {
778 assert(newDepth <= 8);
779 assert(oldDepth <= 8); 778 assert(oldDepth <= 8);
780 779
781 if (oldDepth == newDepth) { 780 if (oldDepth == 8) {
782 // Do nothing 781 // Do nothing
783 return val; 782 return val;
784 } else if (oldDepth == 0 && newDepth != 0) { 783 } else if (oldDepth == 0) {
785 return static_cast<ChannelType>((1 << newDepth) - 1); 784 return static_cast<ChannelType>((1 << 8) - 1);
786 } else if (newDepth > oldDepth) { 785 } else if (8 > oldDepth) {
787 return Replicate(val, oldDepth, newDepth); 786 return static_cast<ChannelType>(FastReplicateTo8(static_cast<u32>(val), oldDepth));
788 } else { 787 } else {
789 // oldDepth > newDepth 788 // oldDepth > newDepth
790 if (newDepth == 0) { 789 const u8 bitsWasted = static_cast<u8>(oldDepth - 8);
791 return 0xFF; 790 u16 v = static_cast<u16>(val);
792 } else { 791 v = static_cast<u16>((v + (1 << (bitsWasted - 1))) >> bitsWasted);
793 u8 bitsWasted = static_cast<u8>(oldDepth - newDepth); 792 v = ::std::min<u16>(::std::max<u16>(0, v), static_cast<u16>((1 << 8) - 1));
794 u16 v = static_cast<u16>(val); 793 return static_cast<u8>(v);
795 v = static_cast<u16>((v + (1 << (bitsWasted - 1))) >> bitsWasted);
796 v = ::std::min<u16>(::std::max<u16>(0, v), static_cast<u16>((1 << newDepth) - 1));
797 return static_cast<u8>(v);
798 }
799 } 794 }
800 795
801 assert(false && "We shouldn't get here."); 796 assert(false && "We shouldn't get here.");
@@ -845,8 +840,7 @@ public:
845 // up in the most-significant byte. 840 // up in the most-significant byte.
846 u32 Pack() const { 841 u32 Pack() const {
847 Pixel eightBit(*this); 842 Pixel eightBit(*this);
848 const u8 eightBitDepth[4] = {8, 8, 8, 8}; 843 eightBit.ChangeBitDepth();
849 eightBit.ChangeBitDepth(eightBitDepth);
850 844
851 u32 r = 0; 845 u32 r = 0;
852 r |= eightBit.A(); 846 r |= eightBit.A();