Skip to content

Commit

Permalink
enables the use of samplers in compute shaders
Browse files Browse the repository at this point in the history
Since textureSampleLevel is usable in compute shaders, this small PR allows sampler to be used in compute shaders for this purpose
  • Loading branch information
Spiri0 authored Dec 4, 2024
1 parent 75ddd00 commit 8f2e365
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 @@ -244,7 +244,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 @@ -613,7 +613,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 @@ -1125,7 +1125,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 8f2e365

Please sign in to comment.