|
1 | 1 | import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension } from './constants.js'; |
2 | 2 | import { VideoTexture, CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, |
3 | | - RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthTexture |
| 3 | + RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthTexture, |
| 4 | + RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, |
| 5 | + RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format |
4 | 6 | } from 'three'; |
5 | 7 | import WebGPUTextureUtils from './WebGPUTextureUtils.js'; |
6 | 8 |
|
@@ -580,6 +582,32 @@ class WebGPUTextures { |
580 | 582 | if ( format === GPUTextureFormat.BC6HRGBUFloat || format === GPUTextureFormat.BC6HRGBFloat ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (float) |
581 | 583 | if ( format === GPUTextureFormat.BC7RGBAUnorm || format === GPUTextureFormat.BC7RGBAUnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; // BPTC (unorm) |
582 | 584 |
|
| 585 | + if ( format === GPUTextureFormat.ETC2RGB8Unorm || format === GPUTextureFormat.ETC2RGB8UnormSRGB ) return { byteLength: 8, width: 4, height: 4 }; |
| 586 | + if ( format === GPUTextureFormat.ETC2RGB8A1Unorm || format === GPUTextureFormat.ETC2RGB8A1UnormSRGB ) return { byteLength: 8, width: 4, height: 4 }; |
| 587 | + if ( format === GPUTextureFormat.ETC2RGBA8Unorm || format === GPUTextureFormat.ETC2RGBA8UnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; |
| 588 | + if ( format === GPUTextureFormat.EACR11Unorm ) return { byteLength: 8, width: 4, height: 4 }; |
| 589 | + if ( format === GPUTextureFormat.EACR11Snorm ) return { byteLength: 8, width: 4, height: 4 }; |
| 590 | + if ( format === GPUTextureFormat.EACRG11Unorm ) return { byteLength: 16, width: 4, height: 4 }; |
| 591 | + if ( format === GPUTextureFormat.EACRG11Snorm ) return { byteLength: 16, width: 4, height: 4 }; |
| 592 | + |
| 593 | + if ( format === GPUTextureFormat.ASTC4x4Unorm || format === GPUTextureFormat.ASTC4x4UnormSRGB ) return { byteLength: 16, width: 4, height: 4 }; |
| 594 | + if ( format === GPUTextureFormat.ASTC5x4Unorm || format === GPUTextureFormat.ASTC5x4UnormSRGB ) return { byteLength: 16, width: 5, height: 4 }; |
| 595 | + if ( format === GPUTextureFormat.ASTC5x5Unorm || format === GPUTextureFormat.ASTC5x5UnormSRGB ) return { byteLength: 16, width: 5, height: 5 }; |
| 596 | + if ( format === GPUTextureFormat.ASTC6x5Unorm || format === GPUTextureFormat.ASTC6x5UnormSRGB ) return { byteLength: 16, width: 6, height: 5 }; |
| 597 | + if ( format === GPUTextureFormat.ASTC6x6Unorm || format === GPUTextureFormat.ASTC6x6UnormSRGB ) return { byteLength: 16, width: 6, height: 6 }; |
| 598 | + if ( format === GPUTextureFormat.ASTC8x5Unorm || format === GPUTextureFormat.ASTC8x5UnormSRGB ) return { byteLength: 16, width: 8, height: 5 }; |
| 599 | + if ( format === GPUTextureFormat.ASTC8x6Unorm || format === GPUTextureFormat.ASTC8x6UnormSRGB ) return { byteLength: 16, width: 8, height: 6 }; |
| 600 | + if ( format === GPUTextureFormat.ASTC8x8Unorm || format === GPUTextureFormat.ASTC8x8UnormSRGB ) return { byteLength: 16, width: 8, height: 8 }; |
| 601 | + if ( format === GPUTextureFormat.ASTC10x5Unorm || format === GPUTextureFormat.ASTC10x5UnormSRGB ) return { byteLength: 16, width: 10, height: 5 }; |
| 602 | + if ( format === GPUTextureFormat.ASTC10x6Unorm || format === GPUTextureFormat.ASTC10x6UnormSRGB ) return { byteLength: 16, width: 10, height: 6 }; |
| 603 | + if ( format === GPUTextureFormat.ASTC10x8Unorm || format === GPUTextureFormat.ASTC10x8UnormSRGB ) return { byteLength: 16, width: 10, height: 8 }; |
| 604 | + if ( format === GPUTextureFormat.ASTC10x10Unorm || format === GPUTextureFormat.ASTC10x10UnormSRGB ) return { byteLength: 16, width: 10, height: 10 }; |
| 605 | + if ( format === GPUTextureFormat.ASTC12x10Unorm || format === GPUTextureFormat.ASTC12x10UnormSRGB ) return { byteLength: 16, width: 12, height: 10 }; |
| 606 | + if ( format === GPUTextureFormat.ASTC12x12Unorm || format === GPUTextureFormat.ASTC12x12UnormSRGB ) return { byteLength: 16, width: 12, height: 12 }; |
| 607 | + |
| 608 | + |
| 609 | + |
| 610 | + |
583 | 611 | } |
584 | 612 |
|
585 | 613 | _getBytesPerTexel( format ) { |
@@ -622,103 +650,172 @@ class WebGPUTextures { |
622 | 650 |
|
623 | 651 | let formatGPU; |
624 | 652 |
|
625 | | - switch ( format ) { |
| 653 | + if ( texture.isCompressedTexture === true ) { |
626 | 654 |
|
627 | | - case RGBA_S3TC_DXT1_Format: |
628 | | - formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm; |
629 | | - break; |
| 655 | + switch ( format ) { |
630 | 656 |
|
631 | | - case RGBA_S3TC_DXT3_Format: |
632 | | - formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC2RGBAUnormSRGB : GPUTextureFormat.BC2RGBAUnorm; |
633 | | - break; |
| 657 | + case RGBA_S3TC_DXT1_Format: |
| 658 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm; |
| 659 | + break; |
634 | 660 |
|
635 | | - case RGBA_S3TC_DXT5_Format: |
636 | | - formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm; |
637 | | - break; |
| 661 | + case RGBA_S3TC_DXT3_Format: |
| 662 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC2RGBAUnormSRGB : GPUTextureFormat.BC2RGBAUnorm; |
| 663 | + break; |
638 | 664 |
|
639 | | - case RGB_ETC2_Format: |
640 | | - formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm; |
641 | | - break; |
| 665 | + case RGBA_S3TC_DXT5_Format: |
| 666 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm; |
| 667 | + break; |
642 | 668 |
|
643 | | - case RGBA_ETC2_EAC_Format: |
644 | | - formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGBA8UnormSRGB : GPUTextureFormat.ETC2RGBA8Unorm; |
645 | | - break; |
| 669 | + case RGB_ETC2_Format: |
| 670 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm; |
| 671 | + break; |
646 | 672 |
|
647 | | - case DepthFormat: |
648 | | - formatGPU = GPUTextureFormat.Depth32Float; |
649 | | - break; |
| 673 | + case RGBA_ETC2_EAC_Format: |
| 674 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGBA8UnormSRGB : GPUTextureFormat.ETC2RGBA8Unorm; |
| 675 | + break; |
650 | 676 |
|
651 | | - case RGBAFormat: |
| 677 | + case RGBA_ASTC_4x4_Format: |
| 678 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC4x4UnormSRGB : GPUTextureFormat.ASTC4x4Unorm; |
| 679 | + break; |
652 | 680 |
|
653 | | - switch ( type ) { |
| 681 | + case RGBA_ASTC_5x4_Format: |
| 682 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x4UnormSRGB : GPUTextureFormat.ASTC5x4Unorm; |
| 683 | + break; |
654 | 684 |
|
655 | | - case UnsignedByteType: |
656 | | - formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm; |
657 | | - break; |
| 685 | + case RGBA_ASTC_5x5_Format: |
| 686 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x5UnormSRGB : GPUTextureFormat.ASTC5x5Unorm; |
| 687 | + break; |
658 | 688 |
|
659 | | - case HalfFloatType: |
660 | | - formatGPU = GPUTextureFormat.RGBA16Float; |
661 | | - break; |
| 689 | + case RGBA_ASTC_6x5_Format: |
| 690 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x5UnormSRGB : GPUTextureFormat.ASTC6x5Unorm; |
| 691 | + break; |
662 | 692 |
|
663 | | - case FloatType: |
664 | | - formatGPU = GPUTextureFormat.RGBA32Float; |
665 | | - break; |
| 693 | + case RGBA_ASTC_6x6_Format: |
| 694 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x6UnormSRGB : GPUTextureFormat.ASTC6x6Unorm; |
| 695 | + break; |
666 | 696 |
|
667 | | - default: |
668 | | - console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type ); |
| 697 | + case RGBA_ASTC_8x5_Format: |
| 698 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x5UnormSRGB : GPUTextureFormat.ASTC8x5Unorm; |
| 699 | + break; |
669 | 700 |
|
670 | | - } |
| 701 | + case RGBA_ASTC_8x6_Format: |
| 702 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x6UnormSRGB : GPUTextureFormat.ASTC8x6Unorm; |
| 703 | + break; |
671 | 704 |
|
672 | | - break; |
| 705 | + case RGBA_ASTC_8x8_Format: |
| 706 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x8UnormSRGB : GPUTextureFormat.ASTC8x8Unorm; |
| 707 | + break; |
673 | 708 |
|
674 | | - case RedFormat: |
| 709 | + case RGBA_ASTC_10x5_Format: |
| 710 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x5UnormSRGB : GPUTextureFormat.ASTC10x5Unorm; |
| 711 | + break; |
675 | 712 |
|
676 | | - switch ( type ) { |
| 713 | + case RGBA_ASTC_10x6_Format: |
| 714 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x6UnormSRGB : GPUTextureFormat.ASTC10x6Unorm; |
| 715 | + break; |
677 | 716 |
|
678 | | - case UnsignedByteType: |
679 | | - formatGPU = GPUTextureFormat.R8Unorm; |
680 | | - break; |
| 717 | + case RGBA_ASTC_10x8_Format: |
| 718 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x8UnormSRGB : GPUTextureFormat.ASTC10x8Unorm; |
| 719 | + break; |
681 | 720 |
|
682 | | - case HalfFloatType: |
683 | | - formatGPU = GPUTextureFormat.R16Float; |
684 | | - break; |
| 721 | + case RGBA_ASTC_10x10_Format: |
| 722 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x10UnormSRGB : GPUTextureFormat.ASTC10x10Unorm; |
| 723 | + break; |
685 | 724 |
|
686 | | - case FloatType: |
687 | | - formatGPU = GPUTextureFormat.R32Float; |
688 | | - break; |
| 725 | + case RGBA_ASTC_12x10_Format: |
| 726 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x10UnormSRGB : GPUTextureFormat.ASTC12x10Unorm; |
| 727 | + break; |
689 | 728 |
|
690 | | - default: |
691 | | - console.error( 'WebGPURenderer: Unsupported texture type with RedFormat.', type ); |
| 729 | + case RGBA_ASTC_12x12_Format: |
| 730 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x12UnormSRGB : GPUTextureFormat.ASTC12x12Unorm; |
| 731 | + break; |
692 | 732 |
|
693 | | - } |
| 733 | + case DepthFormat: |
| 734 | + formatGPU = GPUTextureFormat.Depth32Float; |
| 735 | + break; |
| 736 | + |
| 737 | + default: |
| 738 | + console.error( 'WebGPURenderer: Unsupported texture format.', format ); |
694 | 739 |
|
695 | | - break; |
| 740 | + } |
| 741 | + |
| 742 | + } else { |
696 | 743 |
|
697 | | - case RGFormat: |
| 744 | + switch ( format ) { |
698 | 745 |
|
699 | | - switch ( type ) { |
| 746 | + case RGBAFormat: |
700 | 747 |
|
701 | | - case UnsignedByteType: |
702 | | - formatGPU = GPUTextureFormat.RG8Unorm; |
703 | | - break; |
| 748 | + switch ( type ) { |
704 | 749 |
|
705 | | - case HalfFloatType: |
706 | | - formatGPU = GPUTextureFormat.RG16Float; |
707 | | - break; |
| 750 | + case UnsignedByteType: |
| 751 | + formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm; |
| 752 | + break; |
708 | 753 |
|
709 | | - case FloatType: |
710 | | - formatGPU = GPUTextureFormat.RG32Float; |
711 | | - break; |
| 754 | + case HalfFloatType: |
| 755 | + formatGPU = GPUTextureFormat.RGBA16Float; |
| 756 | + break; |
712 | 757 |
|
713 | | - default: |
714 | | - console.error( 'WebGPURenderer: Unsupported texture type with RGFormat.', type ); |
| 758 | + case FloatType: |
| 759 | + formatGPU = GPUTextureFormat.RGBA32Float; |
| 760 | + break; |
715 | 761 |
|
716 | | - } |
| 762 | + default: |
| 763 | + console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type ); |
| 764 | + |
| 765 | + } |
| 766 | + |
| 767 | + break; |
| 768 | + |
| 769 | + case RedFormat: |
| 770 | + |
| 771 | + switch ( type ) { |
717 | 772 |
|
718 | | - break; |
| 773 | + case UnsignedByteType: |
| 774 | + formatGPU = GPUTextureFormat.R8Unorm; |
| 775 | + break; |
719 | 776 |
|
720 | | - default: |
721 | | - console.error( 'WebGPURenderer: Unsupported texture format.', format ); |
| 777 | + case HalfFloatType: |
| 778 | + formatGPU = GPUTextureFormat.R16Float; |
| 779 | + break; |
| 780 | + |
| 781 | + case FloatType: |
| 782 | + formatGPU = GPUTextureFormat.R32Float; |
| 783 | + break; |
| 784 | + |
| 785 | + default: |
| 786 | + console.error( 'WebGPURenderer: Unsupported texture type with RedFormat.', type ); |
| 787 | + |
| 788 | + } |
| 789 | + |
| 790 | + break; |
| 791 | + |
| 792 | + case RGFormat: |
| 793 | + |
| 794 | + switch ( type ) { |
| 795 | + |
| 796 | + case UnsignedByteType: |
| 797 | + formatGPU = GPUTextureFormat.RG8Unorm; |
| 798 | + break; |
| 799 | + |
| 800 | + case HalfFloatType: |
| 801 | + formatGPU = GPUTextureFormat.RG16Float; |
| 802 | + break; |
| 803 | + |
| 804 | + case FloatType: |
| 805 | + formatGPU = GPUTextureFormat.RG32Float; |
| 806 | + break; |
| 807 | + |
| 808 | + default: |
| 809 | + console.error( 'WebGPURenderer: Unsupported texture type with RGFormat.', type ); |
| 810 | + |
| 811 | + } |
| 812 | + |
| 813 | + break; |
| 814 | + |
| 815 | + default: |
| 816 | + console.error( 'WebGPURenderer: Unsupported texture format.', format ); |
| 817 | + |
| 818 | + } |
722 | 819 |
|
723 | 820 | } |
724 | 821 |
|
|
0 commit comments