Skip to content

Commit

Permalink
WGSLNodeBuilder: Sampler for compute shader (#30033)
Browse files Browse the repository at this point in the history
* Update WGSLNodeBuilder.js

Arrays are not currently taken into account by the wgslTypeLib. However, with the struct extension #29908, arrays will also become important as a type.

* enables the use of samplers in compute shaders

Since textureSampleLevel is usable in compute shaders, this small PR allows sampler to be used in compute shaders for this purpose

* Update WGSLNodeBuilder.js

* Update WGSLNodeBuilder.js
  • Loading branch information
Spiri0 authored Dec 8, 2024
1 parent ed96b8d commit 3a581bf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class WGSLNodeBuilder extends NodeBuilder {

_generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) {

if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false ) {
if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( texture ) === false ) {

return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;

Expand Down Expand Up @@ -592,7 +592,7 @@ class WGSLNodeBuilder extends NodeBuilder {
texture.store = node.isStorageTextureNode === true;
texture.setVisibility( gpuShaderStageLib[ shaderStage ] );

if ( shaderStage === 'fragment' && this.isUnfilterable( node.value ) === false && texture.store === false ) {
if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( node.value ) === false && texture.store === false ) {

const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node, group );
sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
Expand Down Expand Up @@ -1104,7 +1104,7 @@ ${ flowData.code }

const texture = uniform.node.value;

if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true ) {
if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true ) {

if ( this.isSampleCompare( texture ) ) {

Expand Down

0 comments on commit 3a581bf

Please sign in to comment.