123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691 |
- /* eslint-disable babylonjs/available */
- // eslint-disable-next-line @typescript-eslint/naming-convention
- import * as WebGPUConstants from "./webgpuConstants.js";
- import { Scalar } from "../../Maths/math.scalar.js";
- /** @internal */
- export class WebGPUTextureHelper {
- static ComputeNumMipmapLevels(width, height) {
- return Scalar.ILog2(Math.max(width, height)) + 1;
- }
- static GetTextureTypeFromFormat(format) {
- switch (format) {
- // One Component = 8 bits
- case WebGPUConstants.TextureFormat.R8Unorm:
- case WebGPUConstants.TextureFormat.R8Snorm:
- case WebGPUConstants.TextureFormat.R8Uint:
- case WebGPUConstants.TextureFormat.R8Sint:
- case WebGPUConstants.TextureFormat.RG8Unorm:
- case WebGPUConstants.TextureFormat.RG8Snorm:
- case WebGPUConstants.TextureFormat.RG8Uint:
- case WebGPUConstants.TextureFormat.RG8Sint:
- case WebGPUConstants.TextureFormat.RGBA8Unorm:
- case WebGPUConstants.TextureFormat.RGBA8UnormSRGB:
- case WebGPUConstants.TextureFormat.RGBA8Snorm:
- case WebGPUConstants.TextureFormat.RGBA8Uint:
- case WebGPUConstants.TextureFormat.RGBA8Sint:
- case WebGPUConstants.TextureFormat.BGRA8Unorm:
- case WebGPUConstants.TextureFormat.BGRA8UnormSRGB:
- case WebGPUConstants.TextureFormat.RGB10A2UINT: // composite format - let's say it's byte...
- case WebGPUConstants.TextureFormat.RGB10A2Unorm: // composite format - let's say it's byte...
- case WebGPUConstants.TextureFormat.RGB9E5UFloat: // composite format - let's say it's byte...
- case WebGPUConstants.TextureFormat.RG11B10UFloat: // composite format - let's say it's byte...
- case WebGPUConstants.TextureFormat.BC7RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC7RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC6HRGBUFloat:
- case WebGPUConstants.TextureFormat.BC6HRGBFloat:
- case WebGPUConstants.TextureFormat.BC5RGUnorm:
- case WebGPUConstants.TextureFormat.BC5RGSnorm:
- case WebGPUConstants.TextureFormat.BC3RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC3RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC2RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC2RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC4RUnorm:
- case WebGPUConstants.TextureFormat.BC4RSnorm:
- case WebGPUConstants.TextureFormat.BC1RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC1RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.ETC2RGB8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8UnormSRGB:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1UnormSRGB:
- case WebGPUConstants.TextureFormat.ETC2RGBA8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGBA8UnormSRGB:
- case WebGPUConstants.TextureFormat.EACR11Unorm:
- case WebGPUConstants.TextureFormat.EACR11Snorm:
- case WebGPUConstants.TextureFormat.EACRG11Unorm:
- case WebGPUConstants.TextureFormat.EACRG11Snorm:
- case WebGPUConstants.TextureFormat.ASTC4x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC4x4UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC5x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x4UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC5x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC6x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC6x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x8UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x8UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x10UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC12x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x10UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC12x12Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x12UnormSRGB:
- case WebGPUConstants.TextureFormat.Stencil8:
- return 0;
- // One component = 16 bits
- case WebGPUConstants.TextureFormat.R16Uint:
- case WebGPUConstants.TextureFormat.R16Sint:
- case WebGPUConstants.TextureFormat.RG16Uint:
- case WebGPUConstants.TextureFormat.RG16Sint:
- case WebGPUConstants.TextureFormat.RGBA16Uint:
- case WebGPUConstants.TextureFormat.RGBA16Sint:
- case WebGPUConstants.TextureFormat.Depth16Unorm:
- return 5;
- case WebGPUConstants.TextureFormat.R16Float:
- case WebGPUConstants.TextureFormat.RG16Float:
- case WebGPUConstants.TextureFormat.RGBA16Float:
- return 2;
- // One component = 32 bits
- case WebGPUConstants.TextureFormat.R32Uint:
- case WebGPUConstants.TextureFormat.R32Sint:
- case WebGPUConstants.TextureFormat.RG32Uint:
- case WebGPUConstants.TextureFormat.RG32Sint:
- case WebGPUConstants.TextureFormat.RGBA32Uint:
- case WebGPUConstants.TextureFormat.RGBA32Sint:
- return 7;
- case WebGPUConstants.TextureFormat.R32Float:
- case WebGPUConstants.TextureFormat.RG32Float:
- case WebGPUConstants.TextureFormat.RGBA32Float:
- case WebGPUConstants.TextureFormat.Depth32Float:
- case WebGPUConstants.TextureFormat.Depth32FloatStencil8:
- case WebGPUConstants.TextureFormat.Depth24Plus:
- case WebGPUConstants.TextureFormat.Depth24PlusStencil8:
- return 1;
- }
- return 0;
- }
- static GetBlockInformationFromFormat(format) {
- switch (format) {
- // 8 bits formats
- case WebGPUConstants.TextureFormat.R8Unorm:
- case WebGPUConstants.TextureFormat.R8Snorm:
- case WebGPUConstants.TextureFormat.R8Uint:
- case WebGPUConstants.TextureFormat.R8Sint:
- return { width: 1, height: 1, length: 1 };
- // 16 bits formats
- case WebGPUConstants.TextureFormat.R16Uint:
- case WebGPUConstants.TextureFormat.R16Sint:
- case WebGPUConstants.TextureFormat.R16Float:
- case WebGPUConstants.TextureFormat.RG8Unorm:
- case WebGPUConstants.TextureFormat.RG8Snorm:
- case WebGPUConstants.TextureFormat.RG8Uint:
- case WebGPUConstants.TextureFormat.RG8Sint:
- return { width: 1, height: 1, length: 2 };
- // 32 bits formats
- case WebGPUConstants.TextureFormat.R32Uint:
- case WebGPUConstants.TextureFormat.R32Sint:
- case WebGPUConstants.TextureFormat.R32Float:
- case WebGPUConstants.TextureFormat.RG16Uint:
- case WebGPUConstants.TextureFormat.RG16Sint:
- case WebGPUConstants.TextureFormat.RG16Float:
- case WebGPUConstants.TextureFormat.RGBA8Unorm:
- case WebGPUConstants.TextureFormat.RGBA8UnormSRGB:
- case WebGPUConstants.TextureFormat.RGBA8Snorm:
- case WebGPUConstants.TextureFormat.RGBA8Uint:
- case WebGPUConstants.TextureFormat.RGBA8Sint:
- case WebGPUConstants.TextureFormat.BGRA8Unorm:
- case WebGPUConstants.TextureFormat.BGRA8UnormSRGB:
- case WebGPUConstants.TextureFormat.RGB9E5UFloat:
- case WebGPUConstants.TextureFormat.RGB10A2UINT:
- case WebGPUConstants.TextureFormat.RGB10A2Unorm:
- case WebGPUConstants.TextureFormat.RG11B10UFloat:
- return { width: 1, height: 1, length: 4 };
- // 64 bits formats
- case WebGPUConstants.TextureFormat.RG32Uint:
- case WebGPUConstants.TextureFormat.RG32Sint:
- case WebGPUConstants.TextureFormat.RG32Float:
- case WebGPUConstants.TextureFormat.RGBA16Uint:
- case WebGPUConstants.TextureFormat.RGBA16Sint:
- case WebGPUConstants.TextureFormat.RGBA16Float:
- return { width: 1, height: 1, length: 8 };
- // 128 bits formats
- case WebGPUConstants.TextureFormat.RGBA32Uint:
- case WebGPUConstants.TextureFormat.RGBA32Sint:
- case WebGPUConstants.TextureFormat.RGBA32Float:
- return { width: 1, height: 1, length: 16 };
- // Depth and stencil formats
- case WebGPUConstants.TextureFormat.Stencil8:
- // eslint-disable-next-line no-throw-literal
- throw "No fixed size for Stencil8 format!";
- case WebGPUConstants.TextureFormat.Depth16Unorm:
- return { width: 1, height: 1, length: 2 };
- case WebGPUConstants.TextureFormat.Depth24Plus:
- // eslint-disable-next-line no-throw-literal
- throw "No fixed size for Depth24Plus format!";
- case WebGPUConstants.TextureFormat.Depth24PlusStencil8:
- // eslint-disable-next-line no-throw-literal
- throw "No fixed size for Depth24PlusStencil8 format!";
- case WebGPUConstants.TextureFormat.Depth32Float:
- return { width: 1, height: 1, length: 4 };
- case WebGPUConstants.TextureFormat.Depth32FloatStencil8:
- return { width: 1, height: 1, length: 5 };
- // BC compressed formats usable if "texture-compression-bc" is both
- // supported by the device/user agent and enabled in requestDevice.
- case WebGPUConstants.TextureFormat.BC7RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC7RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC6HRGBUFloat:
- case WebGPUConstants.TextureFormat.BC6HRGBFloat:
- case WebGPUConstants.TextureFormat.BC5RGUnorm:
- case WebGPUConstants.TextureFormat.BC5RGSnorm:
- case WebGPUConstants.TextureFormat.BC3RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC3RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC2RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC2RGBAUnormSRGB:
- return { width: 4, height: 4, length: 16 };
- case WebGPUConstants.TextureFormat.BC4RUnorm:
- case WebGPUConstants.TextureFormat.BC4RSnorm:
- case WebGPUConstants.TextureFormat.BC1RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC1RGBAUnormSRGB:
- return { width: 4, height: 4, length: 8 };
- // ETC2 compressed formats usable if "texture-compression-etc2" is both
- // supported by the device/user agent and enabled in requestDevice.
- case WebGPUConstants.TextureFormat.ETC2RGB8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8UnormSRGB:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1UnormSRGB:
- case WebGPUConstants.TextureFormat.EACR11Unorm:
- case WebGPUConstants.TextureFormat.EACR11Snorm:
- return { width: 4, height: 4, length: 8 };
- case WebGPUConstants.TextureFormat.ETC2RGBA8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGBA8UnormSRGB:
- case WebGPUConstants.TextureFormat.EACRG11Unorm:
- case WebGPUConstants.TextureFormat.EACRG11Snorm:
- return { width: 4, height: 4, length: 16 };
- // ASTC compressed formats usable if "texture-compression-astc" is both
- // supported by the device/user agent and enabled in requestDevice.
- case WebGPUConstants.TextureFormat.ASTC4x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC4x4UnormSRGB:
- return { width: 4, height: 4, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC5x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x4UnormSRGB:
- return { width: 5, height: 4, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC5x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x5UnormSRGB:
- return { width: 5, height: 5, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC6x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x5UnormSRGB:
- return { width: 6, height: 5, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC6x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x6UnormSRGB:
- return { width: 6, height: 6, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC8x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x5UnormSRGB:
- return { width: 8, height: 5, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC8x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x6UnormSRGB:
- return { width: 8, height: 6, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC8x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x8UnormSRGB:
- return { width: 8, height: 8, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC10x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x5UnormSRGB:
- return { width: 10, height: 5, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC10x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x6UnormSRGB:
- return { width: 10, height: 6, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC10x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x8UnormSRGB:
- return { width: 10, height: 8, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC10x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x10UnormSRGB:
- return { width: 10, height: 10, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC12x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x10UnormSRGB:
- return { width: 12, height: 10, length: 16 };
- case WebGPUConstants.TextureFormat.ASTC12x12Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x12UnormSRGB:
- return { width: 12, height: 12, length: 16 };
- }
- return { width: 1, height: 1, length: 4 };
- }
- static IsHardwareTexture(texture) {
- return !!texture.release;
- }
- static IsInternalTexture(texture) {
- return !!texture.dispose;
- }
- static IsImageBitmap(imageBitmap) {
- return imageBitmap.close !== undefined;
- }
- static IsImageBitmapArray(imageBitmap) {
- return Array.isArray(imageBitmap) && imageBitmap[0].close !== undefined;
- }
- static IsCompressedFormat(format) {
- switch (format) {
- case WebGPUConstants.TextureFormat.BC7RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC7RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC6HRGBFloat:
- case WebGPUConstants.TextureFormat.BC6HRGBUFloat:
- case WebGPUConstants.TextureFormat.BC5RGSnorm:
- case WebGPUConstants.TextureFormat.BC5RGUnorm:
- case WebGPUConstants.TextureFormat.BC4RSnorm:
- case WebGPUConstants.TextureFormat.BC4RUnorm:
- case WebGPUConstants.TextureFormat.BC3RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC3RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC2RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC2RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC1RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC1RGBAUnorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8UnormSRGB:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1UnormSRGB:
- case WebGPUConstants.TextureFormat.ETC2RGBA8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGBA8UnormSRGB:
- case WebGPUConstants.TextureFormat.EACR11Unorm:
- case WebGPUConstants.TextureFormat.EACR11Snorm:
- case WebGPUConstants.TextureFormat.EACRG11Unorm:
- case WebGPUConstants.TextureFormat.EACRG11Snorm:
- case WebGPUConstants.TextureFormat.ASTC4x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC4x4UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC5x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x4UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC5x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC6x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC6x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x8UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x8UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x10UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC12x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x10UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC12x12Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x12UnormSRGB:
- return true;
- }
- return false;
- }
- static GetWebGPUTextureFormat(type, format, useSRGBBuffer = false) {
- switch (format) {
- case 15:
- return WebGPUConstants.TextureFormat.Depth16Unorm;
- case 16:
- return WebGPUConstants.TextureFormat.Depth24Plus;
- case 13:
- return WebGPUConstants.TextureFormat.Depth24PlusStencil8;
- case 14:
- return WebGPUConstants.TextureFormat.Depth32Float;
- case 18:
- return WebGPUConstants.TextureFormat.Depth32FloatStencil8;
- case 19:
- return WebGPUConstants.TextureFormat.Stencil8;
- case 36492:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.BC7RGBAUnormSRGB : WebGPUConstants.TextureFormat.BC7RGBAUnorm;
- case 36495:
- return WebGPUConstants.TextureFormat.BC6HRGBUFloat;
- case 36494:
- return WebGPUConstants.TextureFormat.BC6HRGBFloat;
- case 33779:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.BC3RGBAUnormSRGB : WebGPUConstants.TextureFormat.BC3RGBAUnorm;
- case 33778:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.BC2RGBAUnormSRGB : WebGPUConstants.TextureFormat.BC2RGBAUnorm;
- case 33777:
- case 33776:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.BC1RGBAUnormSRGB : WebGPUConstants.TextureFormat.BC1RGBAUnorm;
- case 37808:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.ASTC4x4UnormSRGB : WebGPUConstants.TextureFormat.ASTC4x4Unorm;
- case 36196:
- case 37492:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.ETC2RGB8UnormSRGB : WebGPUConstants.TextureFormat.ETC2RGB8Unorm;
- case 37496:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.ETC2RGBA8UnormSRGB : WebGPUConstants.TextureFormat.ETC2RGBA8Unorm;
- }
- switch (type) {
- case 3:
- switch (format) {
- case 6:
- return WebGPUConstants.TextureFormat.R8Snorm;
- case 7:
- return WebGPUConstants.TextureFormat.RG8Snorm;
- case 4:
- // eslint-disable-next-line no-throw-literal
- throw "RGB format not supported in WebGPU";
- case 8:
- return WebGPUConstants.TextureFormat.R8Sint;
- case 9:
- return WebGPUConstants.TextureFormat.RG8Sint;
- case 10:
- // eslint-disable-next-line no-throw-literal
- throw "RGB_INTEGER format not supported in WebGPU";
- case 11:
- return WebGPUConstants.TextureFormat.RGBA8Sint;
- default:
- return WebGPUConstants.TextureFormat.RGBA8Snorm;
- }
- case 0:
- switch (format) {
- case 6:
- return WebGPUConstants.TextureFormat.R8Unorm;
- case 7:
- return WebGPUConstants.TextureFormat.RG8Unorm;
- case 4:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGB format not supported in WebGPU";
- case 5:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.RGBA8UnormSRGB : WebGPUConstants.TextureFormat.RGBA8Unorm;
- case 12:
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.BGRA8UnormSRGB : WebGPUConstants.TextureFormat.BGRA8Unorm;
- case 8:
- return WebGPUConstants.TextureFormat.R8Uint;
- case 9:
- return WebGPUConstants.TextureFormat.RG8Uint;
- case 10:
- // eslint-disable-next-line no-throw-literal
- throw "RGB_INTEGER format not supported in WebGPU";
- case 11:
- return WebGPUConstants.TextureFormat.RGBA8Uint;
- case 0:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_ALPHA format not supported in WebGPU";
- case 1:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_LUMINANCE format not supported in WebGPU";
- case 2:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_LUMINANCE_ALPHA format not supported in WebGPU";
- default:
- return WebGPUConstants.TextureFormat.RGBA8Unorm;
- }
- case 4:
- switch (format) {
- case 8:
- return WebGPUConstants.TextureFormat.R16Sint;
- case 9:
- return WebGPUConstants.TextureFormat.RG16Sint;
- case 10:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGB_INTEGER format not supported in WebGPU";
- case 11:
- return WebGPUConstants.TextureFormat.RGBA16Sint;
- default:
- return WebGPUConstants.TextureFormat.RGBA16Sint;
- }
- case 5:
- switch (format) {
- case 8:
- return WebGPUConstants.TextureFormat.R16Uint;
- case 9:
- return WebGPUConstants.TextureFormat.RG16Uint;
- case 10:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGB_INTEGER format not supported in WebGPU";
- case 11:
- return WebGPUConstants.TextureFormat.RGBA16Uint;
- default:
- return WebGPUConstants.TextureFormat.RGBA16Uint;
- }
- case 6:
- switch (format) {
- case 8:
- return WebGPUConstants.TextureFormat.R32Sint;
- case 9:
- return WebGPUConstants.TextureFormat.RG32Sint;
- case 10:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGB_INTEGER format not supported in WebGPU";
- case 11:
- return WebGPUConstants.TextureFormat.RGBA32Sint;
- default:
- return WebGPUConstants.TextureFormat.RGBA32Sint;
- }
- case 7: // Refers to UNSIGNED_INT
- switch (format) {
- case 8:
- return WebGPUConstants.TextureFormat.R32Uint;
- case 9:
- return WebGPUConstants.TextureFormat.RG32Uint;
- case 10:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGB_INTEGER format not supported in WebGPU";
- case 11:
- return WebGPUConstants.TextureFormat.RGBA32Uint;
- default:
- return WebGPUConstants.TextureFormat.RGBA32Uint;
- }
- case 1:
- switch (format) {
- case 6:
- return WebGPUConstants.TextureFormat.R32Float; // By default. Other possibility is R16Float.
- case 7:
- return WebGPUConstants.TextureFormat.RG32Float; // By default. Other possibility is RG16Float.
- case 4:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGB format not supported in WebGPU";
- case 5:
- return WebGPUConstants.TextureFormat.RGBA32Float; // By default. Other possibility is RGBA16Float.
- default:
- return WebGPUConstants.TextureFormat.RGBA32Float;
- }
- case 2:
- switch (format) {
- case 6:
- return WebGPUConstants.TextureFormat.R16Float;
- case 7:
- return WebGPUConstants.TextureFormat.RG16Float;
- case 4:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGB format not supported in WebGPU";
- case 5:
- return WebGPUConstants.TextureFormat.RGBA16Float;
- default:
- return WebGPUConstants.TextureFormat.RGBA16Float;
- }
- case 10:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTURETYPE_UNSIGNED_SHORT_5_6_5 format not supported in WebGPU";
- case 13:
- switch (format) {
- case 5:
- return WebGPUConstants.TextureFormat.RG11B10UFloat;
- case 11:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGBA_INTEGER format not supported in WebGPU when type is TEXTURETYPE_UNSIGNED_INT_10F_11F_11F_REV";
- default:
- return WebGPUConstants.TextureFormat.RG11B10UFloat;
- }
- case 14:
- switch (format) {
- case 5:
- return WebGPUConstants.TextureFormat.RGB9E5UFloat;
- case 11:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTUREFORMAT_RGBA_INTEGER format not supported in WebGPU when type is TEXTURETYPE_UNSIGNED_INT_5_9_9_9_REV";
- default:
- return WebGPUConstants.TextureFormat.RGB9E5UFloat;
- }
- case 8:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTURETYPE_UNSIGNED_SHORT_4_4_4_4 format not supported in WebGPU";
- case 9:
- // eslint-disable-next-line no-throw-literal
- throw "TEXTURETYPE_UNSIGNED_SHORT_5_5_5_1 format not supported in WebGPU";
- case 11:
- switch (format) {
- case 5:
- return WebGPUConstants.TextureFormat.RGB10A2Unorm;
- case 11:
- return WebGPUConstants.TextureFormat.RGB10A2UINT;
- default:
- return WebGPUConstants.TextureFormat.RGB10A2Unorm;
- }
- }
- return useSRGBBuffer ? WebGPUConstants.TextureFormat.RGBA8UnormSRGB : WebGPUConstants.TextureFormat.RGBA8Unorm;
- }
- static GetNumChannelsFromWebGPUTextureFormat(format) {
- switch (format) {
- case WebGPUConstants.TextureFormat.R8Unorm:
- case WebGPUConstants.TextureFormat.R8Snorm:
- case WebGPUConstants.TextureFormat.R8Uint:
- case WebGPUConstants.TextureFormat.R8Sint:
- case WebGPUConstants.TextureFormat.BC4RUnorm:
- case WebGPUConstants.TextureFormat.BC4RSnorm:
- case WebGPUConstants.TextureFormat.R16Uint:
- case WebGPUConstants.TextureFormat.R16Sint:
- case WebGPUConstants.TextureFormat.Depth16Unorm:
- case WebGPUConstants.TextureFormat.R16Float:
- case WebGPUConstants.TextureFormat.R32Uint:
- case WebGPUConstants.TextureFormat.R32Sint:
- case WebGPUConstants.TextureFormat.R32Float:
- case WebGPUConstants.TextureFormat.Depth32Float:
- case WebGPUConstants.TextureFormat.Stencil8:
- case WebGPUConstants.TextureFormat.Depth24Plus:
- case WebGPUConstants.TextureFormat.EACR11Unorm:
- case WebGPUConstants.TextureFormat.EACR11Snorm:
- return 1;
- case WebGPUConstants.TextureFormat.RG8Unorm:
- case WebGPUConstants.TextureFormat.RG8Snorm:
- case WebGPUConstants.TextureFormat.RG8Uint:
- case WebGPUConstants.TextureFormat.RG8Sint:
- case WebGPUConstants.TextureFormat.Depth32FloatStencil8:
- case WebGPUConstants.TextureFormat.BC5RGUnorm:
- case WebGPUConstants.TextureFormat.BC5RGSnorm:
- case WebGPUConstants.TextureFormat.RG16Uint:
- case WebGPUConstants.TextureFormat.RG16Sint:
- case WebGPUConstants.TextureFormat.RG16Float:
- case WebGPUConstants.TextureFormat.RG32Uint:
- case WebGPUConstants.TextureFormat.RG32Sint:
- case WebGPUConstants.TextureFormat.RG32Float:
- case WebGPUConstants.TextureFormat.Depth24PlusStencil8:
- case WebGPUConstants.TextureFormat.EACRG11Unorm:
- case WebGPUConstants.TextureFormat.EACRG11Snorm:
- return 2;
- case WebGPUConstants.TextureFormat.RGB9E5UFloat:
- case WebGPUConstants.TextureFormat.RG11B10UFloat:
- case WebGPUConstants.TextureFormat.BC6HRGBUFloat:
- case WebGPUConstants.TextureFormat.BC6HRGBFloat:
- case WebGPUConstants.TextureFormat.ETC2RGB8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8UnormSRGB:
- return 3;
- case WebGPUConstants.TextureFormat.RGBA8Unorm:
- case WebGPUConstants.TextureFormat.RGBA8UnormSRGB:
- case WebGPUConstants.TextureFormat.RGBA8Snorm:
- case WebGPUConstants.TextureFormat.RGBA8Uint:
- case WebGPUConstants.TextureFormat.RGBA8Sint:
- case WebGPUConstants.TextureFormat.BGRA8Unorm:
- case WebGPUConstants.TextureFormat.BGRA8UnormSRGB:
- case WebGPUConstants.TextureFormat.RGB10A2UINT:
- case WebGPUConstants.TextureFormat.RGB10A2Unorm:
- case WebGPUConstants.TextureFormat.BC7RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC7RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC3RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC3RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC2RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC2RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.BC1RGBAUnorm:
- case WebGPUConstants.TextureFormat.BC1RGBAUnormSRGB:
- case WebGPUConstants.TextureFormat.RGBA16Uint:
- case WebGPUConstants.TextureFormat.RGBA16Sint:
- case WebGPUConstants.TextureFormat.RGBA16Float:
- case WebGPUConstants.TextureFormat.RGBA32Uint:
- case WebGPUConstants.TextureFormat.RGBA32Sint:
- case WebGPUConstants.TextureFormat.RGBA32Float:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGB8A1UnormSRGB:
- case WebGPUConstants.TextureFormat.ETC2RGBA8Unorm:
- case WebGPUConstants.TextureFormat.ETC2RGBA8UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC4x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC4x4UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC5x4Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x4UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC5x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC5x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC6x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC6x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC6x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC8x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC8x8UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x5Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x5UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x6Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x6UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x8Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x8UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC10x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC10x10UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC12x10Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x10UnormSRGB:
- case WebGPUConstants.TextureFormat.ASTC12x12Unorm:
- case WebGPUConstants.TextureFormat.ASTC12x12UnormSRGB:
- return 4;
- }
- // eslint-disable-next-line no-throw-literal
- throw `Unknown format ${format}!`;
- }
- static HasStencilAspect(format) {
- switch (format) {
- case WebGPUConstants.TextureFormat.Stencil8:
- case WebGPUConstants.TextureFormat.Depth32FloatStencil8:
- case WebGPUConstants.TextureFormat.Depth24PlusStencil8:
- return true;
- }
- return false;
- }
- static HasDepthAndStencilAspects(format) {
- switch (format) {
- case WebGPUConstants.TextureFormat.Depth32FloatStencil8:
- case WebGPUConstants.TextureFormat.Depth24PlusStencil8:
- return true;
- }
- return false;
- }
- static GetDepthFormatOnly(format) {
- switch (format) {
- case WebGPUConstants.TextureFormat.Depth16Unorm:
- return WebGPUConstants.TextureFormat.Depth16Unorm;
- case WebGPUConstants.TextureFormat.Depth24Plus:
- return WebGPUConstants.TextureFormat.Depth24Plus;
- case WebGPUConstants.TextureFormat.Depth24PlusStencil8:
- return WebGPUConstants.TextureFormat.Depth24Plus;
- case WebGPUConstants.TextureFormat.Depth32Float:
- return WebGPUConstants.TextureFormat.Depth32Float;
- case WebGPUConstants.TextureFormat.Depth32FloatStencil8:
- return WebGPUConstants.TextureFormat.Depth32Float;
- }
- return format;
- }
- static GetSample(sampleCount) {
- // WebGPU only supports 1 or 4
- return sampleCount > 1 ? 4 : 1;
- }
- }
- //# sourceMappingURL=webgpuTextureHelper.js.map
|