This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,22 @@
/// <reference types="@webgpu/types" />
/**
* A class which generates mipmaps for a GPUTexture.
* Thanks to @toji for the original implementation
* https://github.com/toji/web-texture-tool/blob/main/src/webgpu-mipmap-generator.js
* @memberof rendering
* @ignore
*/
export declare class GpuMipmapGenerator {
device: GPUDevice;
sampler: GPUSampler;
pipelines: Record<string, GPURenderPipeline>;
mipmapShaderModule: any;
constructor(device: GPUDevice);
private _getMipmapPipeline;
/**
* Generates mipmaps for the given GPUTexture from the data in level 0.
* @param {module:External.GPUTexture} texture - Texture to generate mipmaps for.
* @returns {module:External.GPUTexture} - The originally passed texture
*/
generateMipmap(texture: GPUTexture): GPUTexture;
}

View File

@@ -0,0 +1,158 @@
'use strict';
"use strict";
class GpuMipmapGenerator {
constructor(device) {
this.device = device;
this.sampler = device.createSampler({ minFilter: "linear" });
this.pipelines = {};
}
_getMipmapPipeline(format) {
let pipeline = this.pipelines[format];
if (!pipeline) {
if (!this.mipmapShaderModule) {
this.mipmapShaderModule = this.device.createShaderModule({
code: (
/* wgsl */
`
var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0));
struct VertexOutput {
@builtin(position) position : vec4<f32>,
@location(0) texCoord : vec2<f32>,
};
@vertex
fn vertexMain(@builtin(vertex_index) vertexIndex : u32) -> VertexOutput {
var output : VertexOutput;
output.texCoord = pos[vertexIndex] * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5);
output.position = vec4<f32>(pos[vertexIndex], 0.0, 1.0);
return output;
}
@group(0) @binding(0) var imgSampler : sampler;
@group(0) @binding(1) var img : texture_2d<f32>;
@fragment
fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> {
return textureSample(img, imgSampler, texCoord);
}
`
)
});
}
pipeline = this.device.createRenderPipeline({
layout: "auto",
vertex: {
module: this.mipmapShaderModule,
entryPoint: "vertexMain"
},
fragment: {
module: this.mipmapShaderModule,
entryPoint: "fragmentMain",
targets: [{ format }]
}
});
this.pipelines[format] = pipeline;
}
return pipeline;
}
/**
* Generates mipmaps for the given GPUTexture from the data in level 0.
* @param {module:External.GPUTexture} texture - Texture to generate mipmaps for.
* @returns {module:External.GPUTexture} - The originally passed texture
*/
generateMipmap(texture) {
const pipeline = this._getMipmapPipeline(texture.format);
if (texture.dimension === "3d" || texture.dimension === "1d") {
throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");
}
let mipTexture = texture;
const arrayLayerCount = texture.depthOrArrayLayers || 1;
const renderToSource = texture.usage & GPUTextureUsage.RENDER_ATTACHMENT;
if (!renderToSource) {
const mipTextureDescriptor = {
size: {
width: Math.ceil(texture.width / 2),
height: Math.ceil(texture.height / 2),
depthOrArrayLayers: arrayLayerCount
},
format: texture.format,
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT,
mipLevelCount: texture.mipLevelCount - 1
};
mipTexture = this.device.createTexture(mipTextureDescriptor);
}
const commandEncoder = this.device.createCommandEncoder({});
const bindGroupLayout = pipeline.getBindGroupLayout(0);
for (let arrayLayer = 0; arrayLayer < arrayLayerCount; ++arrayLayer) {
let srcView = texture.createView({
baseMipLevel: 0,
mipLevelCount: 1,
dimension: "2d",
baseArrayLayer: arrayLayer,
arrayLayerCount: 1
});
let dstMipLevel = renderToSource ? 1 : 0;
for (let i = 1; i < texture.mipLevelCount; ++i) {
const dstView = mipTexture.createView({
baseMipLevel: dstMipLevel++,
mipLevelCount: 1,
dimension: "2d",
baseArrayLayer: arrayLayer,
arrayLayerCount: 1
});
const passEncoder = commandEncoder.beginRenderPass({
colorAttachments: [{
view: dstView,
storeOp: "store",
loadOp: "clear",
clearValue: { r: 0, g: 0, b: 0, a: 0 }
}]
});
const bindGroup = this.device.createBindGroup({
layout: bindGroupLayout,
entries: [{
binding: 0,
resource: this.sampler
}, {
binding: 1,
resource: srcView
}]
});
passEncoder.setPipeline(pipeline);
passEncoder.setBindGroup(0, bindGroup);
passEncoder.draw(3, 1, 0, 0);
passEncoder.end();
srcView = dstView;
}
}
if (!renderToSource) {
const mipLevelSize = {
width: Math.ceil(texture.width / 2),
height: Math.ceil(texture.height / 2),
depthOrArrayLayers: arrayLayerCount
};
for (let i = 1; i < texture.mipLevelCount; ++i) {
commandEncoder.copyTextureToTexture({
texture: mipTexture,
mipLevel: i - 1
}, {
texture,
mipLevel: i
}, mipLevelSize);
mipLevelSize.width = Math.ceil(mipLevelSize.width / 2);
mipLevelSize.height = Math.ceil(mipLevelSize.height / 2);
}
}
this.device.queue.submit([commandEncoder.finish()]);
if (!renderToSource) {
mipTexture.destroy();
}
return texture;
}
}
exports.GpuMipmapGenerator = GpuMipmapGenerator;
//# sourceMappingURL=GpuMipmapGenerator.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,156 @@
"use strict";
class GpuMipmapGenerator {
constructor(device) {
this.device = device;
this.sampler = device.createSampler({ minFilter: "linear" });
this.pipelines = {};
}
_getMipmapPipeline(format) {
let pipeline = this.pipelines[format];
if (!pipeline) {
if (!this.mipmapShaderModule) {
this.mipmapShaderModule = this.device.createShaderModule({
code: (
/* wgsl */
`
var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0));
struct VertexOutput {
@builtin(position) position : vec4<f32>,
@location(0) texCoord : vec2<f32>,
};
@vertex
fn vertexMain(@builtin(vertex_index) vertexIndex : u32) -> VertexOutput {
var output : VertexOutput;
output.texCoord = pos[vertexIndex] * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5);
output.position = vec4<f32>(pos[vertexIndex], 0.0, 1.0);
return output;
}
@group(0) @binding(0) var imgSampler : sampler;
@group(0) @binding(1) var img : texture_2d<f32>;
@fragment
fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> {
return textureSample(img, imgSampler, texCoord);
}
`
)
});
}
pipeline = this.device.createRenderPipeline({
layout: "auto",
vertex: {
module: this.mipmapShaderModule,
entryPoint: "vertexMain"
},
fragment: {
module: this.mipmapShaderModule,
entryPoint: "fragmentMain",
targets: [{ format }]
}
});
this.pipelines[format] = pipeline;
}
return pipeline;
}
/**
* Generates mipmaps for the given GPUTexture from the data in level 0.
* @param {module:External.GPUTexture} texture - Texture to generate mipmaps for.
* @returns {module:External.GPUTexture} - The originally passed texture
*/
generateMipmap(texture) {
const pipeline = this._getMipmapPipeline(texture.format);
if (texture.dimension === "3d" || texture.dimension === "1d") {
throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");
}
let mipTexture = texture;
const arrayLayerCount = texture.depthOrArrayLayers || 1;
const renderToSource = texture.usage & GPUTextureUsage.RENDER_ATTACHMENT;
if (!renderToSource) {
const mipTextureDescriptor = {
size: {
width: Math.ceil(texture.width / 2),
height: Math.ceil(texture.height / 2),
depthOrArrayLayers: arrayLayerCount
},
format: texture.format,
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT,
mipLevelCount: texture.mipLevelCount - 1
};
mipTexture = this.device.createTexture(mipTextureDescriptor);
}
const commandEncoder = this.device.createCommandEncoder({});
const bindGroupLayout = pipeline.getBindGroupLayout(0);
for (let arrayLayer = 0; arrayLayer < arrayLayerCount; ++arrayLayer) {
let srcView = texture.createView({
baseMipLevel: 0,
mipLevelCount: 1,
dimension: "2d",
baseArrayLayer: arrayLayer,
arrayLayerCount: 1
});
let dstMipLevel = renderToSource ? 1 : 0;
for (let i = 1; i < texture.mipLevelCount; ++i) {
const dstView = mipTexture.createView({
baseMipLevel: dstMipLevel++,
mipLevelCount: 1,
dimension: "2d",
baseArrayLayer: arrayLayer,
arrayLayerCount: 1
});
const passEncoder = commandEncoder.beginRenderPass({
colorAttachments: [{
view: dstView,
storeOp: "store",
loadOp: "clear",
clearValue: { r: 0, g: 0, b: 0, a: 0 }
}]
});
const bindGroup = this.device.createBindGroup({
layout: bindGroupLayout,
entries: [{
binding: 0,
resource: this.sampler
}, {
binding: 1,
resource: srcView
}]
});
passEncoder.setPipeline(pipeline);
passEncoder.setBindGroup(0, bindGroup);
passEncoder.draw(3, 1, 0, 0);
passEncoder.end();
srcView = dstView;
}
}
if (!renderToSource) {
const mipLevelSize = {
width: Math.ceil(texture.width / 2),
height: Math.ceil(texture.height / 2),
depthOrArrayLayers: arrayLayerCount
};
for (let i = 1; i < texture.mipLevelCount; ++i) {
commandEncoder.copyTextureToTexture({
texture: mipTexture,
mipLevel: i - 1
}, {
texture,
mipLevel: i
}, mipLevelSize);
mipLevelSize.width = Math.ceil(mipLevelSize.width / 2);
mipLevelSize.height = Math.ceil(mipLevelSize.height / 2);
}
}
this.device.queue.submit([commandEncoder.finish()]);
if (!renderToSource) {
mipTexture.destroy();
}
return texture;
}
}
export { GpuMipmapGenerator };
//# sourceMappingURL=GpuMipmapGenerator.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
import type { TEXTURE_FORMATS } from '../../../shared/texture/const';
export declare function getSupportedGPUCompressedTextureFormats(): Promise<TEXTURE_FORMATS[]>;

View File

@@ -0,0 +1,81 @@
'use strict';
var adapter = require('../../../../../environment/adapter.js');
"use strict";
let supportedGPUCompressedTextureFormats;
async function getSupportedGPUCompressedTextureFormats() {
if (supportedGPUCompressedTextureFormats)
return supportedGPUCompressedTextureFormats;
const adapter$1 = await adapter.DOMAdapter.get().getNavigator().gpu.requestAdapter();
supportedGPUCompressedTextureFormats = [
...adapter$1.features.has("texture-compression-bc") ? [
// BC compressed formats usable if "texture-compression-bc" is both
// supported by the device/user agent and enabled in requestDevice.
"bc1-rgba-unorm",
"bc1-rgba-unorm-srgb",
"bc2-rgba-unorm",
"bc2-rgba-unorm-srgb",
"bc3-rgba-unorm",
"bc3-rgba-unorm-srgb",
"bc4-r-unorm",
"bc4-r-snorm",
"bc5-rg-unorm",
"bc5-rg-snorm",
"bc6h-rgb-ufloat",
"bc6h-rgb-float",
"bc7-rgba-unorm",
"bc7-rgba-unorm-srgb"
] : [],
...adapter$1.features.has("texture-compression-etc2") ? [
// ETC2 compressed formats usable if "texture-compression-etc2" is both
// supported by the device/user agent and enabled in requestDevice.
"etc2-rgb8unorm",
"etc2-rgb8unorm-srgb",
"etc2-rgb8a1unorm",
"etc2-rgb8a1unorm-srgb",
"etc2-rgba8unorm",
"etc2-rgba8unorm-srgb",
"eac-r11unorm",
"eac-r11snorm",
"eac-rg11unorm",
"eac-rg11snorm"
] : [],
...adapter$1.features.has("texture-compression-astc") ? [
// ASTC compressed formats usable if "texture-compression-astc" is both
// supported by the device/user agent and enabled in requestDevice.
"astc-4x4-unorm",
"astc-4x4-unorm-srgb",
"astc-5x4-unorm",
"astc-5x4-unorm-srgb",
"astc-5x5-unorm",
"astc-5x5-unorm-srgb",
"astc-6x5-unorm",
"astc-6x5-unorm-srgb",
"astc-6x6-unorm",
"astc-6x6-unorm-srgb",
"astc-8x5-unorm",
"astc-8x5-unorm-srgb",
"astc-8x6-unorm",
"astc-8x6-unorm-srgb",
"astc-8x8-unorm",
"astc-8x8-unorm-srgb",
"astc-10x5-unorm",
"astc-10x5-unorm-srgb",
"astc-10x6-unorm",
"astc-10x6-unorm-srgb",
"astc-10x8-unorm",
"astc-10x8-unorm-srgb",
"astc-10x10-unorm",
"astc-10x10-unorm-srgb",
"astc-12x10-unorm",
"astc-12x10-unorm-srgb",
"astc-12x12-unorm",
"astc-12x12-unorm-srgb"
] : []
];
return supportedGPUCompressedTextureFormats;
}
exports.getSupportedGPUCompressedTextureFormats = getSupportedGPUCompressedTextureFormats;
//# sourceMappingURL=getSupportedGPUCompressedTextureFormats.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getSupportedGPUCompressedTextureFormats.js","sources":["../../../../../../src/rendering/renderers/gpu/texture/utils/getSupportedGPUCompressedTextureFormats.ts"],"sourcesContent":["import { DOMAdapter } from '../../../../../environment/adapter';\n\nimport type { TEXTURE_FORMATS } from '../../../shared/texture/const';\n\nlet supportedGPUCompressedTextureFormats: TEXTURE_FORMATS[];\n\nexport async function getSupportedGPUCompressedTextureFormats(): Promise<TEXTURE_FORMATS[]>\n{\n if (supportedGPUCompressedTextureFormats) return supportedGPUCompressedTextureFormats;\n\n const adapter = await DOMAdapter.get().getNavigator().gpu.requestAdapter();\n\n supportedGPUCompressedTextureFormats = [\n ...adapter.features.has('texture-compression-bc') ? [\n // BC compressed formats usable if \"texture-compression-bc\" is both\n // supported by the device/user agent and enabled in requestDevice.\n 'bc1-rgba-unorm',\n 'bc1-rgba-unorm-srgb',\n 'bc2-rgba-unorm',\n 'bc2-rgba-unorm-srgb',\n 'bc3-rgba-unorm',\n 'bc3-rgba-unorm-srgb',\n 'bc4-r-unorm',\n 'bc4-r-snorm',\n 'bc5-rg-unorm',\n 'bc5-rg-snorm',\n 'bc6h-rgb-ufloat',\n 'bc6h-rgb-float',\n 'bc7-rgba-unorm',\n 'bc7-rgba-unorm-srgb',\n ] : [],\n ...adapter.features.has('texture-compression-etc2') ? [\n // ETC2 compressed formats usable if \"texture-compression-etc2\" is both\n // supported by the device/user agent and enabled in requestDevice.\n 'etc2-rgb8unorm',\n 'etc2-rgb8unorm-srgb',\n 'etc2-rgb8a1unorm',\n 'etc2-rgb8a1unorm-srgb',\n 'etc2-rgba8unorm',\n 'etc2-rgba8unorm-srgb',\n 'eac-r11unorm',\n 'eac-r11snorm',\n 'eac-rg11unorm',\n 'eac-rg11snorm',\n ] : [],\n ...adapter.features.has('texture-compression-astc') ? [\n // ASTC compressed formats usable if \"texture-compression-astc\" is both\n // supported by the device/user agent and enabled in requestDevice.\n 'astc-4x4-unorm',\n 'astc-4x4-unorm-srgb',\n 'astc-5x4-unorm',\n 'astc-5x4-unorm-srgb',\n 'astc-5x5-unorm',\n 'astc-5x5-unorm-srgb',\n 'astc-6x5-unorm',\n 'astc-6x5-unorm-srgb',\n 'astc-6x6-unorm',\n 'astc-6x6-unorm-srgb',\n 'astc-8x5-unorm',\n 'astc-8x5-unorm-srgb',\n 'astc-8x6-unorm',\n 'astc-8x6-unorm-srgb',\n 'astc-8x8-unorm',\n 'astc-8x8-unorm-srgb',\n 'astc-10x5-unorm',\n 'astc-10x5-unorm-srgb',\n 'astc-10x6-unorm',\n 'astc-10x6-unorm-srgb',\n 'astc-10x8-unorm',\n 'astc-10x8-unorm-srgb',\n 'astc-10x10-unorm',\n 'astc-10x10-unorm-srgb',\n 'astc-12x10-unorm',\n 'astc-12x10-unorm-srgb',\n 'astc-12x12-unorm',\n 'astc-12x12-unorm-srgb',\n ] : [],\n ] as TEXTURE_FORMATS[];\n\n return supportedGPUCompressedTextureFormats;\n}\n"],"names":["adapter","DOMAdapter"],"mappings":";;;;;AAIA,IAAI,oCAAA,CAAA;AAEJ,eAAsB,uCACtB,GAAA;AACI,EAAI,IAAA,oCAAA;AAAsC,IAAO,OAAA,oCAAA,CAAA;AAEjD,EAAM,MAAAA,SAAA,GAAU,MAAMC,kBAAW,CAAA,GAAA,GAAM,YAAa,EAAA,CAAE,IAAI,cAAe,EAAA,CAAA;AAEzE,EAAuC,oCAAA,GAAA;AAAA,IACnC,GAAGD,SAAA,CAAQ,QAAS,CAAA,GAAA,CAAI,wBAAwB,CAAI,GAAA;AAAA;AAAA;AAAA,MAGhD,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,aAAA;AAAA,MACA,aAAA;AAAA,MACA,cAAA;AAAA,MACA,cAAA;AAAA,MACA,iBAAA;AAAA,MACA,gBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,QACA,EAAC;AAAA,IACL,GAAGA,SAAA,CAAQ,QAAS,CAAA,GAAA,CAAI,0BAA0B,CAAI,GAAA;AAAA;AAAA;AAAA,MAGlD,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,cAAA;AAAA,MACA,cAAA;AAAA,MACA,eAAA;AAAA,MACA,eAAA;AAAA,QACA,EAAC;AAAA,IACL,GAAGA,SAAA,CAAQ,QAAS,CAAA,GAAA,CAAI,0BAA0B,CAAI,GAAA;AAAA;AAAA;AAAA,MAGlD,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,QACA,EAAC;AAAA,GACT,CAAA;AAEA,EAAO,OAAA,oCAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,79 @@
import { DOMAdapter } from '../../../../../environment/adapter.mjs';
"use strict";
let supportedGPUCompressedTextureFormats;
async function getSupportedGPUCompressedTextureFormats() {
if (supportedGPUCompressedTextureFormats)
return supportedGPUCompressedTextureFormats;
const adapter = await DOMAdapter.get().getNavigator().gpu.requestAdapter();
supportedGPUCompressedTextureFormats = [
...adapter.features.has("texture-compression-bc") ? [
// BC compressed formats usable if "texture-compression-bc" is both
// supported by the device/user agent and enabled in requestDevice.
"bc1-rgba-unorm",
"bc1-rgba-unorm-srgb",
"bc2-rgba-unorm",
"bc2-rgba-unorm-srgb",
"bc3-rgba-unorm",
"bc3-rgba-unorm-srgb",
"bc4-r-unorm",
"bc4-r-snorm",
"bc5-rg-unorm",
"bc5-rg-snorm",
"bc6h-rgb-ufloat",
"bc6h-rgb-float",
"bc7-rgba-unorm",
"bc7-rgba-unorm-srgb"
] : [],
...adapter.features.has("texture-compression-etc2") ? [
// ETC2 compressed formats usable if "texture-compression-etc2" is both
// supported by the device/user agent and enabled in requestDevice.
"etc2-rgb8unorm",
"etc2-rgb8unorm-srgb",
"etc2-rgb8a1unorm",
"etc2-rgb8a1unorm-srgb",
"etc2-rgba8unorm",
"etc2-rgba8unorm-srgb",
"eac-r11unorm",
"eac-r11snorm",
"eac-rg11unorm",
"eac-rg11snorm"
] : [],
...adapter.features.has("texture-compression-astc") ? [
// ASTC compressed formats usable if "texture-compression-astc" is both
// supported by the device/user agent and enabled in requestDevice.
"astc-4x4-unorm",
"astc-4x4-unorm-srgb",
"astc-5x4-unorm",
"astc-5x4-unorm-srgb",
"astc-5x5-unorm",
"astc-5x5-unorm-srgb",
"astc-6x5-unorm",
"astc-6x5-unorm-srgb",
"astc-6x6-unorm",
"astc-6x6-unorm-srgb",
"astc-8x5-unorm",
"astc-8x5-unorm-srgb",
"astc-8x6-unorm",
"astc-8x6-unorm-srgb",
"astc-8x8-unorm",
"astc-8x8-unorm-srgb",
"astc-10x5-unorm",
"astc-10x5-unorm-srgb",
"astc-10x6-unorm",
"astc-10x6-unorm-srgb",
"astc-10x8-unorm",
"astc-10x8-unorm-srgb",
"astc-10x10-unorm",
"astc-10x10-unorm-srgb",
"astc-12x10-unorm",
"astc-12x10-unorm-srgb",
"astc-12x12-unorm",
"astc-12x12-unorm-srgb"
] : []
];
return supportedGPUCompressedTextureFormats;
}
export { getSupportedGPUCompressedTextureFormats };
//# sourceMappingURL=getSupportedGPUCompressedTextureFormats.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getSupportedGPUCompressedTextureFormats.mjs","sources":["../../../../../../src/rendering/renderers/gpu/texture/utils/getSupportedGPUCompressedTextureFormats.ts"],"sourcesContent":["import { DOMAdapter } from '../../../../../environment/adapter';\n\nimport type { TEXTURE_FORMATS } from '../../../shared/texture/const';\n\nlet supportedGPUCompressedTextureFormats: TEXTURE_FORMATS[];\n\nexport async function getSupportedGPUCompressedTextureFormats(): Promise<TEXTURE_FORMATS[]>\n{\n if (supportedGPUCompressedTextureFormats) return supportedGPUCompressedTextureFormats;\n\n const adapter = await DOMAdapter.get().getNavigator().gpu.requestAdapter();\n\n supportedGPUCompressedTextureFormats = [\n ...adapter.features.has('texture-compression-bc') ? [\n // BC compressed formats usable if \"texture-compression-bc\" is both\n // supported by the device/user agent and enabled in requestDevice.\n 'bc1-rgba-unorm',\n 'bc1-rgba-unorm-srgb',\n 'bc2-rgba-unorm',\n 'bc2-rgba-unorm-srgb',\n 'bc3-rgba-unorm',\n 'bc3-rgba-unorm-srgb',\n 'bc4-r-unorm',\n 'bc4-r-snorm',\n 'bc5-rg-unorm',\n 'bc5-rg-snorm',\n 'bc6h-rgb-ufloat',\n 'bc6h-rgb-float',\n 'bc7-rgba-unorm',\n 'bc7-rgba-unorm-srgb',\n ] : [],\n ...adapter.features.has('texture-compression-etc2') ? [\n // ETC2 compressed formats usable if \"texture-compression-etc2\" is both\n // supported by the device/user agent and enabled in requestDevice.\n 'etc2-rgb8unorm',\n 'etc2-rgb8unorm-srgb',\n 'etc2-rgb8a1unorm',\n 'etc2-rgb8a1unorm-srgb',\n 'etc2-rgba8unorm',\n 'etc2-rgba8unorm-srgb',\n 'eac-r11unorm',\n 'eac-r11snorm',\n 'eac-rg11unorm',\n 'eac-rg11snorm',\n ] : [],\n ...adapter.features.has('texture-compression-astc') ? [\n // ASTC compressed formats usable if \"texture-compression-astc\" is both\n // supported by the device/user agent and enabled in requestDevice.\n 'astc-4x4-unorm',\n 'astc-4x4-unorm-srgb',\n 'astc-5x4-unorm',\n 'astc-5x4-unorm-srgb',\n 'astc-5x5-unorm',\n 'astc-5x5-unorm-srgb',\n 'astc-6x5-unorm',\n 'astc-6x5-unorm-srgb',\n 'astc-6x6-unorm',\n 'astc-6x6-unorm-srgb',\n 'astc-8x5-unorm',\n 'astc-8x5-unorm-srgb',\n 'astc-8x6-unorm',\n 'astc-8x6-unorm-srgb',\n 'astc-8x8-unorm',\n 'astc-8x8-unorm-srgb',\n 'astc-10x5-unorm',\n 'astc-10x5-unorm-srgb',\n 'astc-10x6-unorm',\n 'astc-10x6-unorm-srgb',\n 'astc-10x8-unorm',\n 'astc-10x8-unorm-srgb',\n 'astc-10x10-unorm',\n 'astc-10x10-unorm-srgb',\n 'astc-12x10-unorm',\n 'astc-12x10-unorm-srgb',\n 'astc-12x12-unorm',\n 'astc-12x12-unorm-srgb',\n ] : [],\n ] as TEXTURE_FORMATS[];\n\n return supportedGPUCompressedTextureFormats;\n}\n"],"names":[],"mappings":";;;AAIA,IAAI,oCAAA,CAAA;AAEJ,eAAsB,uCACtB,GAAA;AACI,EAAI,IAAA,oCAAA;AAAsC,IAAO,OAAA,oCAAA,CAAA;AAEjD,EAAM,MAAA,OAAA,GAAU,MAAM,UAAW,CAAA,GAAA,GAAM,YAAa,EAAA,CAAE,IAAI,cAAe,EAAA,CAAA;AAEzE,EAAuC,oCAAA,GAAA;AAAA,IACnC,GAAG,OAAA,CAAQ,QAAS,CAAA,GAAA,CAAI,wBAAwB,CAAI,GAAA;AAAA;AAAA;AAAA,MAGhD,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,aAAA;AAAA,MACA,aAAA;AAAA,MACA,cAAA;AAAA,MACA,cAAA;AAAA,MACA,iBAAA;AAAA,MACA,gBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,QACA,EAAC;AAAA,IACL,GAAG,OAAA,CAAQ,QAAS,CAAA,GAAA,CAAI,0BAA0B,CAAI,GAAA;AAAA;AAAA;AAAA,MAGlD,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,cAAA;AAAA,MACA,cAAA;AAAA,MACA,eAAA;AAAA,MACA,eAAA;AAAA,QACA,EAAC;AAAA,IACL,GAAG,OAAA,CAAQ,QAAS,CAAA,GAAA,CAAI,0BAA0B,CAAI,GAAA;AAAA;AAAA;AAAA,MAGlD,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,gBAAA;AAAA,MACA,qBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,iBAAA;AAAA,MACA,sBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,kBAAA;AAAA,MACA,uBAAA;AAAA,QACA,EAAC;AAAA,GACT,CAAA;AAEA,EAAO,OAAA,oCAAA,CAAA;AACX;;;;"}