playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
86 lines (85 loc) • 3.47 kB
JavaScript
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 glslRadixSortReorderPS from "../shader-lib/glsl/chunks/radix-sort/radix-sort-reorder.js";
import wgslRadixSortReorderPS from "../shader-lib/wgsl/chunks/radix-sort/radix-sort-reorder.js";
class RenderPassRadixSortReorder extends RenderPassShaderQuad {
sourceLinear = false;
outputLinear = false;
bitsPerStep = 0;
groupSize = 0;
currentBit = 0;
_dynamicParams = { elementCount: 0, imageElementsLog2: 0, imageSize: 0 };
constructor(device, sourceLinear, outputLinear, bitsPerStep, groupSize, currentBit) {
super(device);
this.sourceLinear = sourceLinear;
this.outputLinear = outputLinear;
this.bitsPerStep = bitsPerStep;
this.groupSize = groupSize;
this.currentBit = currentBit;
ShaderChunks.get(device, SHADERLANGUAGE_GLSL).set("radixSortReorderPS", glslRadixSortReorderPS);
ShaderChunks.get(device, SHADERLANGUAGE_WGSL).set("radixSortReorderPS", wgslRadixSortReorderPS);
const defines = /* @__PURE__ */ new Map();
if (sourceLinear) {
defines.set("SOURCE_LINEAR", "");
}
if (outputLinear) {
defines.set("OUTPUT_LINEAR", "");
}
let shaderName = "RadixSortReorderShader";
if (sourceLinear) shaderName += "SourceLinear";
if (outputLinear) shaderName += "OutputLinear";
this.shader = ShaderUtils.createShader(device, {
uniqueName: shaderName,
attributes: { aPosition: SEMANTIC_POSITION },
vertexChunk: "quadVS",
fragmentChunk: "radixSortReorderPS",
fragmentDefines: defines,
fragmentOutputTypes: ["uvec4", "uvec4"]
// MRT: keys (uint) and indices (uint)
});
this.keysTextureId = device.scope.resolve("keysTexture");
if (!sourceLinear) {
this.indicesTextureId = device.scope.resolve("indicesTexture");
}
this.prefixSumsId = device.scope.resolve("prefixSums");
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");
this.imageSizeId = device.scope.resolve("imageSize");
}
setKeysTexture(keysTexture) {
this._keysTexture = keysTexture;
}
setIndicesTexture(indicesTexture) {
this._indicesTexture = indicesTexture;
}
setPrefixSumsTexture(prefixSums) {
this._prefixSums = prefixSums;
}
setDynamicParams(elementCount, imageElementsLog2, imageSize) {
this._dynamicParams.elementCount = elementCount;
this._dynamicParams.imageElementsLog2 = imageElementsLog2;
this._dynamicParams.imageSize = imageSize;
}
execute() {
this.keysTextureId.setValue(this._keysTexture);
if (!this.sourceLinear) {
this.indicesTextureId.setValue(this._indicesTexture);
}
this.prefixSumsId.setValue(this._prefixSums);
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);
this.imageSizeId.setValue(this._dynamicParams.imageSize);
super.execute();
}
}
export {
RenderPassRadixSortReorder
};