UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

65 lines (64 loc) 2.98 kB
import { SEMANTIC_POSITION, SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from "../../platform/graphics/constants.js"; import { RenderPassShaderQuad } from "./render-pass-shader-quad.js"; import { ShaderUtils } from "../shader-lib/shader-utils.js"; import { ShaderChunks } from "../shader-lib/shader-chunks.js"; import glslRadixSortCountPS from "../shader-lib/glsl/chunks/radix-sort/radix-sort-count.js"; import glslRadixSortCountQuad from "../shader-lib/glsl/chunks/radix-sort/radix-sort-count-quad.js"; import wgslRadixSortCountPS from "../shader-lib/wgsl/chunks/radix-sort/radix-sort-count.js"; import wgslRadixSortCountQuad from "../shader-lib/wgsl/chunks/radix-sort/radix-sort-count-quad.js"; class RenderPassRadixSortCount extends RenderPassShaderQuad { sourceLinear = false; bitsPerStep = 0; groupSize = 0; currentBit = 0; _dynamicParams = { elementCount: 0, imageElementsLog2: 0 }; constructor(device, sourceLinear, bitsPerStep, groupSize, currentBit) { super(device); this.sourceLinear = sourceLinear; this.bitsPerStep = bitsPerStep; this.groupSize = groupSize; this.currentBit = currentBit; ShaderChunks.get(device, SHADERLANGUAGE_GLSL).set("radixSortCountPS", glslRadixSortCountPS); ShaderChunks.get(device, SHADERLANGUAGE_GLSL).set("radixSortCountQuad", glslRadixSortCountQuad); ShaderChunks.get(device, SHADERLANGUAGE_WGSL).set("radixSortCountPS", wgslRadixSortCountPS); ShaderChunks.get(device, SHADERLANGUAGE_WGSL).set("radixSortCountQuad", wgslRadixSortCountQuad); const defines = /* @__PURE__ */ new Map(); if (sourceLinear) { defines.set("SOURCE_LINEAR", ""); } const shaderName = sourceLinear ? "RadixSortCountShaderLinear" : "RadixSortCountShader"; this.shader = ShaderUtils.createShader(device, { uniqueName: shaderName, attributes: { aPosition: SEMANTIC_POSITION }, vertexChunk: "quadVS", fragmentChunk: "radixSortCountPS", fragmentDefines: defines, fragmentOutputTypes: "float" }); this.keysTextureId = device.scope.resolve("keysTexture"); this.bitsPerStepId = device.scope.resolve("bitsPerStep"); this.groupSizeId = device.scope.resolve("groupSize"); this.elementCountId = device.scope.resolve("elementCount"); this.imageElementsLog2Id = device.scope.resolve("imageElementsLog2"); this.currentBitId = device.scope.resolve("currentBit"); } setKeysTexture(keysTexture) { this._keysTexture = keysTexture; } setDynamicParams(elementCount, imageElementsLog2) { this._dynamicParams.elementCount = elementCount; this._dynamicParams.imageElementsLog2 = imageElementsLog2; } execute() { this.keysTextureId.setValue(this._keysTexture); this.bitsPerStepId.setValue(this.bitsPerStep); this.groupSizeId.setValue(this.groupSize); this.elementCountId.setValue(this._dynamicParams.elementCount); this.imageElementsLog2Id.setValue(this._dynamicParams.imageElementsLog2); this.currentBitId.setValue(this.currentBit); super.execute(); } } export { RenderPassRadixSortCount };