فهرست منبع

WebGPURenderer: More usage of constants.

Mugen87 4 سال پیش
والد
کامیت
4314d79eef

+ 4 - 3
examples/jsm/renderers/webgpu/WebGPUSampledTexture.js

@@ -1,4 +1,5 @@
 import WebGPUBinding from './WebGPUBinding.js';
+import { GPUBindingType, GPUTextureViewDimension } from './constants.js';
 
 class WebGPUSampledTexture extends WebGPUBinding {
 
@@ -6,9 +7,9 @@ class WebGPUSampledTexture extends WebGPUBinding {
 
 		super( name );
 
-		this.dimension = '2d';
+		this.dimension = GPUTextureViewDimension.TwoD;
 
-		this.type = 'sampled-texture';
+		this.type = GPUBindingType.SampledTexture;
 		this.visibility = GPUShaderStage.FRAGMENT;
 
 		this.textureGPU = null; // set by the renderer
@@ -26,7 +27,7 @@ class WebGPUSampledCubeTexture extends WebGPUSampledTexture {
 
 		super( name );
 
-		this.dimension = 'cube';
+		this.dimension = GPUTextureViewDimension.Cube;
 
 		Object.defineProperty( this, 'isSampledCubeTexture', { value: true } );
 

+ 2 - 1
examples/jsm/renderers/webgpu/WebGPUSampler.js

@@ -1,4 +1,5 @@
 import WebGPUBinding from './WebGPUBinding.js';
+import { GPUBindingType } from './constants.js';
 
 class WebGPUSampler extends WebGPUBinding {
 
@@ -6,7 +7,7 @@ class WebGPUSampler extends WebGPUBinding {
 
 		super( name );
 
-		this.type = 'sampler';
+		this.type = GPUBindingType.Sampler;
 		this.visibility = GPUShaderStage.FRAGMENT;
 
 		this.samplerGPU = null; // set by the renderer

+ 2 - 1
examples/jsm/renderers/webgpu/WebGPUStorageBuffer.js

@@ -1,4 +1,5 @@
 import WebGPUBinding from './WebGPUBinding.js';
+import { GPUBindingType } from './constants.js';
 
 class WebGPUStorageBuffer extends WebGPUBinding {
 
@@ -6,7 +7,7 @@ class WebGPUStorageBuffer extends WebGPUBinding {
 
 		super( name );
 
-		this.type = 'storage-buffer';
+		this.type = GPUBindingType.StorageBuffer;
 
 		this.usage = GPUBufferUsage.VERTEX | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST;
 

+ 21 - 1
examples/jsm/renderers/webgpu/WebGPUTextures.js

@@ -1,4 +1,4 @@
-import { GPUTextureFormat, GPUAddressMode, GPUFilterMode } from './constants.js';
+import { GPUTextureFormat, GPUAddressMode, GPUFilterMode, GPUTextureDimension } from './constants.js';
 import { CubeTexture, Texture, NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter, RepeatWrapping, MirroredRepeatWrapping,
 	RGBFormat, RGBAFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, sRGBEncoding
 } from '../../../../build/three.module.js';
@@ -308,6 +308,7 @@ class WebGPUTextures {
 
 		const { width, height, depth } = this._getSize( texture );
 		const needsMipmaps = this._needsMipmaps( texture );
+		const dimension = this._getDimension( texture );
 		const mipLevelCount = this._getMipLevelCount( texture, width, height, needsMipmaps );
 		const format = this._getFormat( texture );
 
@@ -331,6 +332,7 @@ class WebGPUTextures {
 			},
 			mipLevelCount: mipLevelCount,
 			sampleCount: 1,
+			dimension: dimension,
 			format: format,
 			usage: usage
 		};
@@ -505,6 +507,24 @@ class WebGPUTextures {
 
 	}
 
+	_getDimension( texture ) {
+
+		let dimension;
+
+		if ( texture.isDataTexture3D ) {
+
+			dimension = GPUTextureDimension.ThreeD;
+
+		} else {
+
+			dimension = GPUTextureDimension.TwoD;
+
+		}
+
+		return dimension;
+
+	}
+
 	_getFormat( texture ) {
 
 		const format = texture.format;

+ 2 - 1
examples/jsm/renderers/webgpu/WebGPUUniformsGroup.js

@@ -1,4 +1,5 @@
 import WebGPUBinding from './WebGPUBinding.js';
+import { GPUBindingType } from './constants.js';
 
 class WebGPUUniformsGroup extends WebGPUBinding {
 
@@ -12,7 +13,7 @@ class WebGPUUniformsGroup extends WebGPUBinding {
 
 		this.onBeforeUpdate = function () {};
 
-		this.type = 'uniform-buffer';
+		this.type = GPUBindingType.UniformBuffer;
 		this.visibility = GPUShaderStage.VERTEX;
 
 		this.usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;

+ 27 - 0
examples/jsm/renderers/webgpu/constants.js

@@ -220,6 +220,33 @@ export const GPUStencilOperation = {
 	DecrementWrap: 'decrement-wrap'
 };
 
+export const GPUBindingType = {
+	UniformBuffer: 'uniform-buffer',
+	StorageBuffer: 'storage-buffer',
+	ReadonlyStorageBuffer: 'readonly-storage-buffer',
+	Sampler: 'sampler',
+	ComparisonSampler: 'comparison-sampler',
+	SampledTexture: 'sampled-texture',
+	MultisampledTexture: 'multisampled-texture',
+	ReadonlyStorageTexture: 'readonly-storage-texture',
+	WriteonlyStorageTexture: 'writeonly-storage-texture'
+};
+
+export const GPUTextureDimension = {
+	OneD: '1d',
+	TwoD: '2d',
+	ThreeD: '3d'
+};
+
+export const GPUTextureViewDimension = {
+	OneD: '1d',
+	TwoD: '2d',
+	TwoDArray: '2d-array',
+	Cube: 'cube',
+	CubeArray: 'cube-array',
+	ThreeD: '3d'
+};
+
 // @TODO: Move to src/constants.js
 
 export const BlendColorFactor = 211;