UNPKG

@absulit/points

Version:

A Generative Art library made in WebGPU

75 lines (65 loc) 2.17 kB
/** The idea here is that the columns are the current stage of the storage being checked at entries and dynamic bindings, and the rows are the stage where the storage should show; the table then matches both. The thing to remember here is, if the storage is required in any combination, then the fragment stage (if is included) then there the storage must be read access mode; if there's no vertex then the storage during fragment can be read_write. Compute is always read_write. | storage \ current| COMPUTE | VERTEX | FRAGMENT | --------------------------|:-----------|:----------|----------:| | compute, vertex, fragment | read_write | read | read | compute | read_write | | | vertex | | read | | fragment | | | read_write | compute, vertex | read_write | read | | compute, fragment | read_write | | read_write | vertex, fragment | | read | read * @module storage-accessmode * @ignore */ const R = 'r'; const RW = 'rw'; const { COMPUTE, VERTEX, FRAGMENT } = GPUShaderStage; const cache = { [COMPUTE | VERTEX | FRAGMENT]: { [COMPUTE]: RW, [VERTEX]: R, [FRAGMENT]: R },// [COMPUTE]: { [COMPUTE]: RW, [VERTEX]: null, [FRAGMENT]: null }, [VERTEX]: { [COMPUTE]: null, [VERTEX]: R, [FRAGMENT]: null }, [FRAGMENT]: { [COMPUTE]: null, [VERTEX]: null, [FRAGMENT]: RW },// [COMPUTE | VERTEX]: { [COMPUTE]: RW, [VERTEX]: R, [FRAGMENT]: null }, [COMPUTE | FRAGMENT]: { [COMPUTE]: RW, [VERTEX]: null, [FRAGMENT]: RW },// [VERTEX | FRAGMENT]: { [COMPUTE]: null, [VERTEX]: R, [FRAGMENT]: R }, } export default function getStorageAccessMode(currentStage, storageShaderTypes) { return cache[storageShaderTypes][currentStage]; } export const bindingModes = { [R]: 'read', [RW]: 'read_write' }; export const entriesModes = { [R]: 'read-only-storage', [RW]: 'storage' };