|
@@ -106,7 +106,7 @@ class WebGPUTextureUtils {
|
|
|
const { width, height, depth, levels } = options;
|
|
|
|
|
|
const dimension = this._getDimension( texture );
|
|
|
- const format = texture.internalFormat || this._getFormat( texture );
|
|
|
+ const format = texture.internalFormat || getFormat( texture, this.device );
|
|
|
|
|
|
const sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1;
|
|
|
const primarySampleCount = texture.isRenderTargetTexture ? 1 : sampleCount;
|
|
@@ -649,237 +649,237 @@ class WebGPUTextureUtils {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _getFormat( texture ) {
|
|
|
+}
|
|
|
|
|
|
- const format = texture.format;
|
|
|
- const type = texture.type;
|
|
|
- const colorSpace = texture.colorSpace;
|
|
|
+export function getFormat( texture, device = null ) {
|
|
|
|
|
|
- let formatGPU;
|
|
|
+ const format = texture.format;
|
|
|
+ const type = texture.type;
|
|
|
+ const colorSpace = texture.colorSpace;
|
|
|
|
|
|
- if ( /*texture.isRenderTargetTexture === true ||*/ texture.isFramebufferTexture === true ) {
|
|
|
+ let formatGPU;
|
|
|
|
|
|
- formatGPU = GPUTextureFormat.BGRA8Unorm;
|
|
|
+ if ( /*texture.isRenderTargetTexture === true ||*/ texture.isFramebufferTexture === true ) {
|
|
|
|
|
|
- } else if ( texture.isCompressedTexture === true ) {
|
|
|
+ formatGPU = GPUTextureFormat.BGRA8Unorm;
|
|
|
|
|
|
- switch ( format ) {
|
|
|
+ } else if ( texture.isCompressedTexture === true ) {
|
|
|
|
|
|
- case RGBA_S3TC_DXT1_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm;
|
|
|
- break;
|
|
|
+ switch ( format ) {
|
|
|
|
|
|
- case RGBA_S3TC_DXT3_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC2RGBAUnormSRGB : GPUTextureFormat.BC2RGBAUnorm;
|
|
|
- break;
|
|
|
+ case RGBA_S3TC_DXT1_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_S3TC_DXT5_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
|
|
|
- break;
|
|
|
+ case RGBA_S3TC_DXT3_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC2RGBAUnormSRGB : GPUTextureFormat.BC2RGBAUnorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGB_ETC2_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_S3TC_DXT5_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ETC2_EAC_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGBA8UnormSRGB : GPUTextureFormat.ETC2RGBA8Unorm;
|
|
|
- break;
|
|
|
+ case RGB_ETC2_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_4x4_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC4x4UnormSRGB : GPUTextureFormat.ASTC4x4Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ETC2_EAC_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ETC2RGBA8UnormSRGB : GPUTextureFormat.ETC2RGBA8Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_5x4_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x4UnormSRGB : GPUTextureFormat.ASTC5x4Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_4x4_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC4x4UnormSRGB : GPUTextureFormat.ASTC4x4Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_5x5_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x5UnormSRGB : GPUTextureFormat.ASTC5x5Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_5x4_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x4UnormSRGB : GPUTextureFormat.ASTC5x4Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_6x5_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x5UnormSRGB : GPUTextureFormat.ASTC6x5Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_5x5_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC5x5UnormSRGB : GPUTextureFormat.ASTC5x5Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_6x6_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x6UnormSRGB : GPUTextureFormat.ASTC6x6Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_6x5_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x5UnormSRGB : GPUTextureFormat.ASTC6x5Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_8x5_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x5UnormSRGB : GPUTextureFormat.ASTC8x5Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_6x6_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC6x6UnormSRGB : GPUTextureFormat.ASTC6x6Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_8x6_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x6UnormSRGB : GPUTextureFormat.ASTC8x6Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_8x5_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x5UnormSRGB : GPUTextureFormat.ASTC8x5Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_8x8_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x8UnormSRGB : GPUTextureFormat.ASTC8x8Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_8x6_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x6UnormSRGB : GPUTextureFormat.ASTC8x6Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_10x5_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x5UnormSRGB : GPUTextureFormat.ASTC10x5Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_8x8_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC8x8UnormSRGB : GPUTextureFormat.ASTC8x8Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_10x6_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x6UnormSRGB : GPUTextureFormat.ASTC10x6Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_10x5_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x5UnormSRGB : GPUTextureFormat.ASTC10x5Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_10x8_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x8UnormSRGB : GPUTextureFormat.ASTC10x8Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_10x6_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x6UnormSRGB : GPUTextureFormat.ASTC10x6Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_10x10_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x10UnormSRGB : GPUTextureFormat.ASTC10x10Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_10x8_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x8UnormSRGB : GPUTextureFormat.ASTC10x8Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_12x10_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x10UnormSRGB : GPUTextureFormat.ASTC12x10Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_10x10_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC10x10UnormSRGB : GPUTextureFormat.ASTC10x10Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case RGBA_ASTC_12x12_Format:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x12UnormSRGB : GPUTextureFormat.ASTC12x12Unorm;
|
|
|
- break;
|
|
|
+ case RGBA_ASTC_12x10_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x10UnormSRGB : GPUTextureFormat.ASTC12x10Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- console.error( 'WebGPURenderer: Unsupported texture format.', format );
|
|
|
+ case RGBA_ASTC_12x12_Format:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.ASTC12x12UnormSRGB : GPUTextureFormat.ASTC12x12Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture format.', format );
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- switch ( format ) {
|
|
|
+ } else {
|
|
|
|
|
|
- case RGBAFormat:
|
|
|
+ switch ( format ) {
|
|
|
|
|
|
- switch ( type ) {
|
|
|
+ case RGBAFormat:
|
|
|
|
|
|
- case UnsignedByteType:
|
|
|
- formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm;
|
|
|
- break;
|
|
|
+ switch ( type ) {
|
|
|
|
|
|
- case HalfFloatType:
|
|
|
- formatGPU = GPUTextureFormat.RGBA16Float;
|
|
|
- break;
|
|
|
+ case UnsignedByteType:
|
|
|
+ formatGPU = ( colorSpace === SRGBColorSpace ) ? GPUTextureFormat.RGBA8UnormSRGB : GPUTextureFormat.RGBA8Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case FloatType:
|
|
|
- formatGPU = GPUTextureFormat.RGBA32Float;
|
|
|
- break;
|
|
|
+ case HalfFloatType:
|
|
|
+ formatGPU = GPUTextureFormat.RGBA16Float;
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type );
|
|
|
+ case FloatType:
|
|
|
+ formatGPU = GPUTextureFormat.RGBA32Float;
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with RGBAFormat.', type );
|
|
|
|
|
|
- break;
|
|
|
+ }
|
|
|
|
|
|
- case RedFormat:
|
|
|
+ break;
|
|
|
|
|
|
- switch ( type ) {
|
|
|
+ case RedFormat:
|
|
|
|
|
|
- case UnsignedByteType:
|
|
|
- formatGPU = GPUTextureFormat.R8Unorm;
|
|
|
- break;
|
|
|
+ switch ( type ) {
|
|
|
|
|
|
- case HalfFloatType:
|
|
|
- formatGPU = GPUTextureFormat.R16Float;
|
|
|
- break;
|
|
|
+ case UnsignedByteType:
|
|
|
+ formatGPU = GPUTextureFormat.R8Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case FloatType:
|
|
|
- formatGPU = GPUTextureFormat.R32Float;
|
|
|
- break;
|
|
|
+ case HalfFloatType:
|
|
|
+ formatGPU = GPUTextureFormat.R16Float;
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- console.error( 'WebGPURenderer: Unsupported texture type with RedFormat.', type );
|
|
|
+ case FloatType:
|
|
|
+ formatGPU = GPUTextureFormat.R32Float;
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with RedFormat.', type );
|
|
|
|
|
|
- break;
|
|
|
+ }
|
|
|
|
|
|
- case RGFormat:
|
|
|
+ break;
|
|
|
|
|
|
- switch ( type ) {
|
|
|
+ case RGFormat:
|
|
|
|
|
|
- case UnsignedByteType:
|
|
|
- formatGPU = GPUTextureFormat.RG8Unorm;
|
|
|
- break;
|
|
|
+ switch ( type ) {
|
|
|
|
|
|
- case HalfFloatType:
|
|
|
- formatGPU = GPUTextureFormat.RG16Float;
|
|
|
- break;
|
|
|
+ case UnsignedByteType:
|
|
|
+ formatGPU = GPUTextureFormat.RG8Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case FloatType:
|
|
|
- formatGPU = GPUTextureFormat.RG32Float;
|
|
|
- break;
|
|
|
+ case HalfFloatType:
|
|
|
+ formatGPU = GPUTextureFormat.RG16Float;
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- console.error( 'WebGPURenderer: Unsupported texture type with RGFormat.', type );
|
|
|
+ case FloatType:
|
|
|
+ formatGPU = GPUTextureFormat.RG32Float;
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with RGFormat.', type );
|
|
|
|
|
|
- break;
|
|
|
+ }
|
|
|
|
|
|
- case DepthFormat:
|
|
|
+ break;
|
|
|
|
|
|
- switch ( type ) {
|
|
|
+ case DepthFormat:
|
|
|
|
|
|
- case UnsignedShortType:
|
|
|
- formatGPU = GPUTextureFormat.Depth16Unorm;
|
|
|
- break;
|
|
|
+ switch ( type ) {
|
|
|
|
|
|
- case UnsignedIntType:
|
|
|
- formatGPU = GPUTextureFormat.Depth24Plus;
|
|
|
- break;
|
|
|
+ case UnsignedShortType:
|
|
|
+ formatGPU = GPUTextureFormat.Depth16Unorm;
|
|
|
+ break;
|
|
|
|
|
|
- case FloatType:
|
|
|
- formatGPU = GPUTextureFormat.Depth32Float;
|
|
|
- break;
|
|
|
+ case UnsignedIntType:
|
|
|
+ formatGPU = GPUTextureFormat.Depth24Plus;
|
|
|
+ break;
|
|
|
|
|
|
- default:
|
|
|
- console.error( 'WebGPURenderer: Unsupported texture type with DepthFormat.', type );
|
|
|
+ case FloatType:
|
|
|
+ formatGPU = GPUTextureFormat.Depth32Float;
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with DepthFormat.', type );
|
|
|
|
|
|
- break;
|
|
|
+ }
|
|
|
|
|
|
- case DepthStencilFormat:
|
|
|
+ break;
|
|
|
|
|
|
- switch ( type ) {
|
|
|
+ case DepthStencilFormat:
|
|
|
|
|
|
- case UnsignedInt248Type:
|
|
|
- formatGPU = GPUTextureFormat.Depth24PlusStencil8;
|
|
|
- break;
|
|
|
+ switch ( type ) {
|
|
|
|
|
|
- case FloatType:
|
|
|
+ case UnsignedInt248Type:
|
|
|
+ formatGPU = GPUTextureFormat.Depth24PlusStencil8;
|
|
|
+ break;
|
|
|
|
|
|
- if ( this.device.features.has( GPUFeatureName.Depth32FloatStencil8 ) === false ) {
|
|
|
+ case FloatType:
|
|
|
|
|
|
- console.error( 'WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.' );
|
|
|
+ if ( device && device.features.has( GPUFeatureName.Depth32FloatStencil8 ) === false ) {
|
|
|
|
|
|
- }
|
|
|
+ console.error( 'WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.' );
|
|
|
|
|
|
- formatGPU = GPUTextureFormat.Depth32FloatStencil8;
|
|
|
+ }
|
|
|
|
|
|
- break;
|
|
|
+ formatGPU = GPUTextureFormat.Depth32FloatStencil8;
|
|
|
|
|
|
- default:
|
|
|
- console.error( 'WebGPURenderer: Unsupported texture type with DepthStencilFormat.', type );
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture type with DepthStencilFormat.', type );
|
|
|
|
|
|
- break;
|
|
|
+ }
|
|
|
|
|
|
- default:
|
|
|
- console.error( 'WebGPURenderer: Unsupported texture format.', format );
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
+ default:
|
|
|
+ console.error( 'WebGPURenderer: Unsupported texture format.', format );
|
|
|
|
|
|
}
|
|
|
|
|
|
- return formatGPU;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ return formatGPU;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default WebGPUTextureUtils;
|