@carbonenginejs/runtime 0.1.0-alpha.6 → 0.1.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @carbonenginejs/runtime might be problematic. Click here for more details.
- package/dist/global/consts/effectPaths.js +4 -1
- package/dist/global/consts/effectPaths.js.map +1 -1
- package/dist/global/consts/index.js +1 -1
- package/dist/global/index.js +1 -1
- package/dist/index.js +3 -3
- package/dist/resource/format/carbonEffect/carbonEffectBackendBlock.js +19 -2
- package/dist/resource/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
- package/dist/resource/format/index.js +1 -1
- package/dist/resource/formats/hlsl/core/carbonTypedViews.js +121 -65
- package/dist/resource/formats/hlsl/core/carbonTypedViews.js.map +1 -1
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js +10 -7
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
- package/dist/resource/formats/webgpu/core/effectBackendBodySet.js +3 -1
- package/dist/resource/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
- package/dist/resource/formats/webgpu/core/packageEffect.js +5 -0
- package/dist/resource/formats/webgpu/core/packageEffect.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/emitWgsl.js +20 -0
- package/dist/resource/formats/webgpu/core/wgsl/emitWgsl.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/emulatedAddressing.js +93 -4
- package/dist/resource/formats/webgpu/core/wgsl/emulatedAddressing.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/lowerBindingLayout.js +74 -64
- package/dist/resource/formats/webgpu/core/wgsl/lowerBindingLayout.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/lowerFragmentProgram.js +16 -7
- package/dist/resource/formats/webgpu/core/wgsl/lowerFragmentProgram.js.map +1 -1
- package/dist/resource/formats/webgpu/core/wgsl/wgslTypedViews.js +69 -27
- package/dist/resource/formats/webgpu/core/wgsl/wgslTypedViews.js.map +1 -1
- package/dist/resource/geometry/registerGeometryResources.js +10 -1
- package/dist/resource/geometry/registerGeometryResources.js.map +1 -1
- package/dist/sof/EveSOFDNA.js +4 -2
- package/dist/sof/EveSOFDNA.js.map +1 -1
- package/dist/sof/EveSOFDataMgr.js +83 -69
- package/dist/sof/EveSOFDataMgr.js.map +1 -1
- package/dist/trinity/core/Tr2Denoiser.js +6 -1
- package/dist/trinity/core/Tr2Denoiser.js.map +1 -1
- package/dist/trinity/core/Tr2ShadowMap.js +7 -2
- package/dist/trinity/core/Tr2ShadowMap.js.map +1 -1
- package/dist/trinity/core/context/Tr2RenderContext.js +43 -0
- package/dist/trinity/core/context/Tr2RenderContext.js.map +1 -1
- package/dist/trinity/core/device/Tr2GpuStructuredBuffer.js +134 -0
- package/dist/trinity/core/device/Tr2GpuStructuredBuffer.js.map +1 -0
- package/dist/trinity/core/index.js +1 -0
- package/dist/trinity/core/index.js.map +1 -1
- package/dist/trinity/core/lighting/Tr2LightManager.js +410 -124
- package/dist/trinity/core/lighting/Tr2LightManager.js.map +1 -1
- package/dist/trinity/eve/effect/lensflare/EveLensflare.js +303 -312
- package/dist/trinity/eve/effect/lensflare/EveLensflare.js.map +1 -1
- package/dist/trinity/eve/effect/lensflare/EveOccluder.js +117 -0
- package/dist/trinity/eve/effect/lensflare/EveOccluder.js.map +1 -0
- package/dist/trinity/eve/index.js +1 -0
- package/dist/trinity/eve/index.js.map +1 -1
- package/dist/trinity/eve/scene/EveSpaceScene.js +286 -6
- package/dist/trinity/eve/scene/EveSpaceScene.js.map +1 -1
- package/dist/trinity/eve/scene/EveSpaceSceneRenderDriver.js +212 -32
- package/dist/trinity/eve/scene/EveSpaceSceneRenderDriver.js.map +1 -1
- package/dist/trinity/generated/eve/effect/index.js +0 -1
- package/dist/trinity/generated/eve/effect/index.js.map +1 -1
- package/dist/trinity/generated/eve/index.js +0 -1
- package/dist/trinity/generated/eve/index.js.map +1 -1
- package/dist/trinity/generated/index.js +0 -2
- package/dist/trinity/generated/index.js.map +1 -1
- package/dist/trinity/generated/trinityCore/index.js +0 -1
- package/dist/trinity/generated/trinityCore/index.js.map +1 -1
- package/dist/trinity/index.js +2 -2
- package/dist/trinity/postProcess/Tr2PostProcessRenderer.js +4 -1
- package/dist/trinity/postProcess/Tr2PostProcessRenderer.js.map +1 -1
- package/dist/trinity/postProcess/Tr2SSAO.js +282 -21
- package/dist/trinity/postProcess/Tr2SSAO.js.map +1 -1
- package/dist/trinity/shader/parameter/Tr2RuntimeTextureParameter.js +71 -53
- package/dist/trinity/shader/parameter/Tr2RuntimeTextureParameter.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuRenderContextAL.js +81 -18
- package/dist/trinityal/webgpu/CjsWebgpuRenderContextAL.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuResourceSetAL.js +46 -4
- package/dist/trinityal/webgpu/CjsWebgpuResourceSetAL.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuShaderAL.js +32 -1
- package/dist/trinityal/webgpu/CjsWebgpuShaderAL.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuShaderProgramAL.js +27 -0
- package/dist/trinityal/webgpu/CjsWebgpuShaderProgramAL.js.map +1 -1
- package/dist/trinityal/webgpu/CjsWebgpuTextureAL.js +29 -4
- package/dist/trinityal/webgpu/CjsWebgpuTextureAL.js.map +1 -1
- package/dist/trinityal/webgpu/core/CjsWebgpuPsoDescription.js +32 -2
- package/dist/trinityal/webgpu/core/CjsWebgpuPsoDescription.js.map +1 -1
- package/dist/trinityal/webgpu/core/CjsWebgpuUtils.js +57 -5
- package/dist/trinityal/webgpu/core/CjsWebgpuUtils.js.map +1 -1
- package/dist/trinityal/webgpu/core/CjsWebgpuWorkQueue.js +111 -5
- package/dist/trinityal/webgpu/core/CjsWebgpuWorkQueue.js.map +1 -1
- package/docs/trinity/reference/classes/generated.md +20 -20
- package/docs/trinity/reference/classes/post-process.md +1 -1
- package/package.json +1 -1
- package/dist/trinity/generated/eve/effect/EveOccluder.js +0 -38
- package/dist/trinity/generated/eve/effect/EveOccluder.js.map +0 -1
- package/dist/trinity/generated/trinityCore/Tr2GpuStructuredBuffer.js +0 -48
- package/dist/trinity/generated/trinityCore/Tr2GpuStructuredBuffer.js.map +0 -1
|
@@ -4,12 +4,13 @@ import { CjsParameter as _CjsParameter } from './CjsParameter.js';
|
|
|
4
4
|
import { ITriEffectResourceParameter } from './ITriEffectResourceParameter.js';
|
|
5
5
|
import { ResourceFlags } from './ITr2EffectValue.js';
|
|
6
6
|
import { Tr2ColorSpace } from '#consts/render-context';
|
|
7
|
+
import { RealizeTexture } from '../../core/Tr2ImageIOHelpers.js';
|
|
7
8
|
|
|
8
9
|
let _initProto, _initClass, _init_texture, _init_extra_texture, _init_name, _init_extra_name, _init_uavMipLevel, _init_extra_uavMipLevel;
|
|
9
10
|
|
|
10
|
-
/**
|
|
11
|
-
* A named texture slot fed by a runtime-supplied texture provider rather than an
|
|
12
|
-
* authored res path.
|
|
11
|
+
/**
|
|
12
|
+
* A named texture slot fed by a runtime-supplied texture provider rather than an
|
|
13
|
+
* authored res path.
|
|
13
14
|
*/
|
|
14
15
|
let _Tr2RuntimeTexturePar;
|
|
15
16
|
class Tr2RuntimeTextureParameter extends _CjsParameter {
|
|
@@ -20,24 +21,24 @@ class Tr2RuntimeTextureParameter extends _CjsParameter {
|
|
|
20
21
|
} = _applyDecs2311(this, [type.define({
|
|
21
22
|
className: "Tr2RuntimeTextureParameter",
|
|
22
23
|
family: "shader"
|
|
23
|
-
}), carbon.inherit(ITriEffectResourceParameter)], [[[edit, edit.notify, edit, edit.readwrite, edit, edit.persist, void 0, type.objectRef("ITr2TextureProvider")], 16, "texture"], [[edit, edit.readwrite, edit, edit.persist, type, type.string], 16, "name"], [[edit, edit.readwrite, edit, edit.persist, type, type.uint32], 16, "uavMipLevel"], [[carbon, carbon.method, impl, impl.adapted], 18, "__init__"], [[carbon, carbon.method, impl, impl.implemented], 18, "Create"], [[carbon, carbon.method, impl, impl.implemented], 18, "GetParameterName"], [[carbon, carbon.method, impl, impl.adapted], 18, "GetHashValue"], [[carbon, carbon.method, impl, impl.adapted, void 0, impl.reason("JS dispatches the native hook using the exposed member name; existing class-owned rendering/resource adaptations remain unchanged.")], 18, "OnModified"], [[carbon, carbon.method, impl, impl.adapted], 18, "RebuildEffectHandles"], [[carbon, carbon.method, impl, impl.
|
|
24
|
+
}), carbon.inherit(ITriEffectResourceParameter)], [[[edit, edit.notify, edit, edit.readwrite, edit, edit.persist, void 0, type.objectRef("ITr2TextureProvider")], 16, "texture"], [[edit, edit.readwrite, edit, edit.persist, type, type.string], 16, "name"], [[edit, edit.readwrite, edit, edit.persist, type, type.uint32], 16, "uavMipLevel"], [[carbon, carbon.method, impl, impl.adapted], 18, "__init__"], [[carbon, carbon.method, impl, impl.implemented], 18, "Create"], [[carbon, carbon.method, impl, impl.implemented], 18, "GetParameterName"], [[carbon, carbon.method, impl, impl.adapted], 18, "GetHashValue"], [[carbon, carbon.method, impl, impl.adapted, void 0, impl.reason("JS dispatches the native hook using the exposed member name; existing class-owned rendering/resource adaptations remain unchanged.")], 18, "OnModified"], [[carbon, carbon.method, impl, impl.adapted], 18, "RebuildEffectHandles"], [[carbon, carbon.method, impl, impl.adapted], 18, "CopyToResourceSet"], [[carbon, carbon.method, impl, impl.implemented], 18, "ApplyUav"], [[carbon, carbon.method, impl, impl.implemented], 18, "SetTextureProvider"], [[carbon, carbon.method, impl, impl.implemented], 18, "GetTextureProvider"], [[carbon, carbon.method, impl, impl.implemented], 18, "SetUavMipLevel"], [[carbon, carbon.method, impl, impl.implemented], 18, "OnAddedToMaterial"], [[carbon, carbon.method, impl, impl.implemented], 18, "OnRemovedFromMaterial"]], 0, void 0, _CjsParameter));
|
|
24
25
|
}
|
|
25
26
|
texture = (_initProto(this), _init_texture(this, null));
|
|
26
27
|
name = (_init_extra_texture(this), _init_name(this, ""));
|
|
27
28
|
uavMipLevel = (_init_extra_name(this), _init_uavMipLevel(this, 0));
|
|
28
29
|
#materials = (_init_extra_uavMipLevel(this), []);
|
|
29
30
|
|
|
30
|
-
/**
|
|
31
|
-
* Blue construction form: forwards the name, provider and UAV mip level to
|
|
32
|
-
* Create.
|
|
31
|
+
/**
|
|
32
|
+
* Blue construction form: forwards the name, provider and UAV mip level to
|
|
33
|
+
* Create.
|
|
33
34
|
*/
|
|
34
35
|
__init__(name = "", texture = null, uavMipLevel = 0) {
|
|
35
36
|
this.Create(name, texture, uavMipLevel);
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
/**
|
|
39
|
-
* Assigns name, texture provider and UAV mip level together, notifying only
|
|
40
|
-
* when at least one of them actually changed; returns whether it did.
|
|
39
|
+
/**
|
|
40
|
+
* Assigns name, texture provider and UAV mip level together, notifying only
|
|
41
|
+
* when at least one of them actually changed; returns whether it did.
|
|
41
42
|
*/
|
|
42
43
|
Create(name, texture, uavMipLevel = 0) {
|
|
43
44
|
const nextName = String(name);
|
|
@@ -66,18 +67,18 @@ class Tr2RuntimeTextureParameter extends _CjsParameter {
|
|
|
66
67
|
return _CjsParameter.hashFnv1Identity(this.texture, startingHash);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
/**
|
|
70
|
-
* Invalidates the resource sets of every material this parameter is attached
|
|
71
|
-
* to.
|
|
70
|
+
/**
|
|
71
|
+
* Invalidates the resource sets of every material this parameter is attached
|
|
72
|
+
* to.
|
|
72
73
|
*/
|
|
73
74
|
OnModified(propertyName) {
|
|
74
75
|
if (propertyName === "texture") this.#invalidateResourceSets();
|
|
75
76
|
return true;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
/**
|
|
79
|
-
* Deliberately does nothing: Carbon caches the effect resource type here for
|
|
80
|
-
* later resource-set binding, which the Trinity layer leaves to engine adapters.
|
|
79
|
+
/**
|
|
80
|
+
* Deliberately does nothing: Carbon caches the effect resource type here for
|
|
81
|
+
* later resource-set binding, which the Trinity layer leaves to engine adapters.
|
|
81
82
|
*/
|
|
82
83
|
RebuildEffectHandles(_effectRes) {
|
|
83
84
|
|
|
@@ -85,39 +86,56 @@ class Tr2RuntimeTextureParameter extends _CjsParameter {
|
|
|
85
86
|
// binding. Not ported yet.
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
/**
|
|
89
|
-
* Carbon `CopyToResourceSet` (`Tr2RuntimeTextureParameter.cpp:30-46`): the
|
|
90
|
-
* provider's texture as a shader resource. With none, a null binding, which
|
|
91
|
-
* a backend fills with its placeholder as Carbon's fallback texture.
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
89
|
+
/**
|
|
90
|
+
* Carbon `CopyToResourceSet` (`Tr2RuntimeTextureParameter.cpp:30-46`): the
|
|
91
|
+
* provider's texture as a shader resource. With none, a null binding, which
|
|
92
|
+
* a backend fills with its placeholder as Carbon's fallback texture.
|
|
93
|
+
*
|
|
94
|
+
* Adapted: a provider that is a loaded texture resource has its texture
|
|
95
|
+
* made here, on first bind, through the trailing `renderContext`
|
|
96
|
+
* (`RealizeTexture`), as `TriTextureParameter` and `TriVariable` do; Carbon
|
|
97
|
+
* made it at load. Without this, a `TriTextureRes` handed to
|
|
98
|
+
* `Tr2Effect.SetParameter` (CORTAO's lookup table) bound the placeholder
|
|
99
|
+
* forever.
|
|
100
|
+
*
|
|
101
|
+
* @param {object} resourceDesc A `Tr2ResourceSetDescriptionAL`.
|
|
102
|
+
* @param {number} stage A `ShaderType`.
|
|
103
|
+
* @param {number} registerIndex The register.
|
|
104
|
+
* @param {number} [flags] A `ResourceFlags` word; bit 0 is sRGB.
|
|
105
|
+
* @param {object} [renderContext] The context a resource's texture is made through.
|
|
106
|
+
* @returns {boolean} Whether the slot took the binding.
|
|
98
107
|
*/
|
|
99
|
-
CopyToResourceSet(resourceDesc, stage, registerIndex, flags = 0) {
|
|
108
|
+
CopyToResourceSet(resourceDesc, stage, registerIndex, flags = 0, renderContext = null) {
|
|
100
109
|
const colorSpace = flags & ResourceFlags.RESOURCE_FLAG_SRGB ? Tr2ColorSpace.COLOR_SPACE_SRGB : Tr2ColorSpace.COLOR_SPACE_LINEAR;
|
|
101
|
-
return resourceDesc.SetSrv(stage, registerIndex, this.
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
return resourceDesc.SetSrv(stage, registerIndex, this._Texture(renderContext), colorSpace);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The provider's texture, realized through the context if it is a resource that has loaded but not yet been created; null otherwise. */
|
|
114
|
+
_Texture(renderContext) {
|
|
115
|
+
const provider = this.texture;
|
|
116
|
+
if (!provider) return null;
|
|
117
|
+
const texture = provider.GetTexture();
|
|
118
|
+
if (texture || !renderContext || typeof provider.IsPrepared !== "function") return texture;
|
|
119
|
+
return RealizeTexture(provider, renderContext);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Carbon `ApplyUav` (`Tr2RuntimeTextureParameter.cpp:49-60`): the
|
|
124
|
+
* provider's texture as an unordered-access view at this parameter's mip.
|
|
125
|
+
*
|
|
126
|
+
* @param {object} resourceDesc A `Tr2ResourceSetDescriptionAL`.
|
|
127
|
+
* @param {number} stage A `ShaderType`.
|
|
128
|
+
* @param {number} registerIndex The register.
|
|
129
|
+
* @returns {boolean} Whether the slot took the binding.
|
|
112
130
|
*/
|
|
113
131
|
ApplyUav(resourceDesc, stage, registerIndex) {
|
|
114
132
|
const texture = this.texture ? this.texture.GetTexture() : null;
|
|
115
133
|
return texture ? resourceDesc.SetUav(stage, registerIndex, texture, this.uavMipLevel) : resourceDesc.SetUav(stage, registerIndex, null);
|
|
116
134
|
}
|
|
117
135
|
|
|
118
|
-
/**
|
|
119
|
-
* Swaps the texture provider and notifies owners; returns false when it is
|
|
120
|
-
* already the same object.
|
|
136
|
+
/**
|
|
137
|
+
* Swaps the texture provider and notifies owners; returns false when it is
|
|
138
|
+
* already the same object.
|
|
121
139
|
*/
|
|
122
140
|
SetTextureProvider(texture) {
|
|
123
141
|
if (this.texture === texture) {
|
|
@@ -131,25 +149,25 @@ class Tr2RuntimeTextureParameter extends _CjsParameter {
|
|
|
131
149
|
return true;
|
|
132
150
|
}
|
|
133
151
|
|
|
134
|
-
/**
|
|
135
|
-
* The attached provider, or null; this package holds the reference but never
|
|
136
|
-
* resolves or uploads it.
|
|
152
|
+
/**
|
|
153
|
+
* The attached provider, or null; this package holds the reference but never
|
|
154
|
+
* resolves or uploads it.
|
|
137
155
|
*/
|
|
138
156
|
GetTextureProvider() {
|
|
139
157
|
return this.texture;
|
|
140
158
|
}
|
|
141
159
|
|
|
142
|
-
/**
|
|
143
|
-
* Sets the mip level to use when this texture is bound as an unordered-access
|
|
144
|
-
* view, coerced to uint32.
|
|
160
|
+
/**
|
|
161
|
+
* Sets the mip level to use when this texture is bound as an unordered-access
|
|
162
|
+
* view, coerced to uint32.
|
|
145
163
|
*/
|
|
146
164
|
SetUavMipLevel(mipLevel) {
|
|
147
165
|
this.uavMipLevel = mipLevel >>> 0;
|
|
148
166
|
}
|
|
149
167
|
|
|
150
|
-
/**
|
|
151
|
-
* Registers a material to be invalidated when this parameter changes;
|
|
152
|
-
* duplicates are ignored.
|
|
168
|
+
/**
|
|
169
|
+
* Registers a material to be invalidated when this parameter changes;
|
|
170
|
+
* duplicates are ignored.
|
|
153
171
|
*/
|
|
154
172
|
OnAddedToMaterial(material) {
|
|
155
173
|
if (!this.#materials.includes(material)) {
|
|
@@ -157,9 +175,9 @@ class Tr2RuntimeTextureParameter extends _CjsParameter {
|
|
|
157
175
|
}
|
|
158
176
|
}
|
|
159
177
|
|
|
160
|
-
/**
|
|
161
|
-
* Drops a material from the tracked list, so later texture swaps no longer
|
|
162
|
-
* invalidate its resource sets.
|
|
178
|
+
/**
|
|
179
|
+
* Drops a material from the tracked list, so later texture swaps no longer
|
|
180
|
+
* invalidate its resource sets.
|
|
163
181
|
*/
|
|
164
182
|
OnRemovedFromMaterial(material) {
|
|
165
183
|
const index = this.#materials.indexOf(material);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tr2RuntimeTextureParameter.js","sources":["../../../../../src/trinity/shader/parameter/Tr2RuntimeTextureParameter.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Parameter/Tr2RuntimeTextureParameter.h\r\n// Source: trinity/trinity/Shader/Parameter/Tr2RuntimeTextureParameter.cpp\r\n// Source: trinity/trinity/Shader/Parameter/Tr2RuntimeTextureParameter_Blue.cpp\r\nimport { carbon, impl, edit, type } from \"#schema\";\r\nimport { CjsParameter } from \"./CjsParameter.js\";\r\nimport { ITriEffectResourceParameter } from \"./ITriEffectResourceParameter.js\";\r\nimport { ResourceFlags } from \"./ITr2EffectValue.js\";\r\nimport { Tr2ColorSpace } from \"#consts/render-context\";\r\n\r\n\r\n/**\r\n * A named texture slot fed by a runtime-supplied texture provider rather than an\r\n * authored res path.\r\n */\r\n@type.define({\r\n className: \"Tr2RuntimeTextureParameter\",\r\n family: \"shader\"\r\n})\r\n@carbon.inherit(ITriEffectResourceParameter)\r\nexport class Tr2RuntimeTextureParameter extends CjsParameter\r\n{\r\n @edit.notify\r\n @edit.readwrite\r\n @edit.persist\r\n @type.objectRef(\"ITr2TextureProvider\")\r\n texture = null;\r\n\r\n @edit.readwrite\r\n @edit.persist\r\n @type.string\r\n name = \"\";\r\n\r\n @edit.readwrite\r\n @edit.persist\r\n @type.uint32\r\n uavMipLevel = 0;\r\n\r\n #materials = [];\r\n\r\n /**\r\n * Blue construction form: forwards the name, provider and UAV mip level to\r\n * Create.\r\n */\r\n @carbon.method\r\n @impl.adapted\r\n __init__(name = \"\", texture = null, uavMipLevel = 0)\r\n {\r\n this.Create(name, texture, uavMipLevel);\r\n }\r\n\r\n /**\r\n * Assigns name, texture provider and UAV mip level together, notifying only\r\n * when at least one of them actually changed; returns whether it did.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n Create(name, texture, uavMipLevel = 0)\r\n {\r\n const nextName = String(name);\r\n const nextMipLevel = uavMipLevel >>> 0;\r\n const changed = this.name !== nextName || this.texture !== texture || this.uavMipLevel !== nextMipLevel;\r\n if (!changed)\r\n {\r\n return false;\r\n }\r\n this.name = nextName;\r\n this.texture = texture;\r\n this.uavMipLevel = nextMipLevel;\r\n this.UpdateValues({ property: \"texture\", source: this });\r\n return true;\r\n }\r\n\r\n /** The shader resource name this texture binds to. */\r\n @carbon.method\r\n @impl.implemented\r\n GetParameterName()\r\n {\r\n return this.name;\r\n }\r\n\r\n /** Content hash: the texture provider's identity (Carbon hashes its pointer). */\r\n @carbon.method\r\n @impl.adapted\r\n GetHashValue(startingHash = CjsParameter.FNV1_INITIAL)\r\n {\r\n return CjsParameter.hashFnv1Identity(this.texture, startingHash);\r\n }\r\n\r\n /**\r\n * Invalidates the resource sets of every material this parameter is attached\r\n * to.\r\n */\r\n @carbon.method\r\n @impl.adapted\r\n @impl.reason(\"JS dispatches the native hook using the exposed member name; existing class-owned rendering/resource adaptations remain unchanged.\")\r\n OnModified(propertyName)\r\n {\r\n if (propertyName === \"texture\") this.#invalidateResourceSets();\r\n return true;\r\n }\r\n\r\n /**\r\n * Deliberately does nothing: Carbon caches the effect resource type here for\r\n * later resource-set binding, which the Trinity layer leaves to engine adapters.\r\n */\r\n @carbon.method\r\n @impl.adapted\r\n RebuildEffectHandles(_effectRes)\r\n {\r\n\r\n // Carbon caches the effect resource type here for later resource-set\r\n // binding. Not ported yet.\r\n }\r\n\r\n /**\r\n * Carbon `CopyToResourceSet` (`Tr2RuntimeTextureParameter.cpp:30-46`): the\r\n * provider's texture as a shader resource. With none, a null binding, which\r\n * a backend fills with its placeholder as Carbon's fallback texture.\r\n *\r\n * @param {object} resourceDesc A `Tr2ResourceSetDescriptionAL`.\r\n * @param {number} stage A `ShaderType`.\r\n * @param {number} registerIndex The register.\r\n * @param {number} [flags] A `ResourceFlags` word; bit 0 is sRGB.\r\n * @returns {boolean} Whether the slot took the binding.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n CopyToResourceSet(resourceDesc, stage, registerIndex, flags = 0)\r\n {\r\n const colorSpace = (flags & ResourceFlags.RESOURCE_FLAG_SRGB)\r\n ? Tr2ColorSpace.COLOR_SPACE_SRGB\r\n : Tr2ColorSpace.COLOR_SPACE_LINEAR;\r\n\r\n return resourceDesc.SetSrv(stage, registerIndex, this.texture ? this.texture.GetTexture() : null, colorSpace);\r\n }\r\n\r\n /**\r\n * Carbon `ApplyUav` (`Tr2RuntimeTextureParameter.cpp:49-60`): the\r\n * provider's texture as an unordered-access view at this parameter's mip.\r\n *\r\n * @param {object} resourceDesc A `Tr2ResourceSetDescriptionAL`.\r\n * @param {number} stage A `ShaderType`.\r\n * @param {number} registerIndex The register.\r\n * @returns {boolean} Whether the slot took the binding.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n ApplyUav(resourceDesc, stage, registerIndex)\r\n {\r\n const texture = this.texture ? this.texture.GetTexture() : null;\r\n\r\n return texture\r\n ? resourceDesc.SetUav(stage, registerIndex, texture, this.uavMipLevel)\r\n : resourceDesc.SetUav(stage, registerIndex, null);\r\n }\r\n\r\n /**\r\n * Swaps the texture provider and notifies owners; returns false when it is\r\n * already the same object.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n SetTextureProvider(texture)\r\n {\r\n if (this.texture === texture)\r\n {\r\n return false;\r\n }\r\n this.texture = texture;\r\n this.UpdateValues({ property: \"texture\", source: this });\r\n return true;\r\n }\r\n\r\n /**\r\n * The attached provider, or null; this package holds the reference but never\r\n * resolves or uploads it.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n GetTextureProvider()\r\n {\r\n return this.texture;\r\n }\r\n\r\n /**\r\n * Sets the mip level to use when this texture is bound as an unordered-access\r\n * view, coerced to uint32.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n SetUavMipLevel(mipLevel)\r\n {\r\n this.uavMipLevel = mipLevel >>> 0;\r\n }\r\n\r\n /**\r\n * Registers a material to be invalidated when this parameter changes;\r\n * duplicates are ignored.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n OnAddedToMaterial(material)\r\n {\r\n if (!this.#materials.includes(material))\r\n {\r\n this.#materials.push(material);\r\n }\r\n }\r\n\r\n /**\r\n * Drops a material from the tracked list, so later texture swaps no longer\r\n * invalidate its resource sets.\r\n */\r\n @carbon.method\r\n @impl.implemented\r\n OnRemovedFromMaterial(material)\r\n {\r\n const index = this.#materials.indexOf(material);\r\n if (index >= 0)\r\n {\r\n this.#materials.splice(index, 1);\r\n }\r\n }\r\n\r\n /** Invalidates the resource sets of every attached material. */\r\n #invalidateResourceSets()\r\n {\r\n for (const material of this.#materials)\r\n {\r\n material?.InvalidateResourceSets?.();\r\n }\r\n }\r\n}\r\n"],"names":["_Tr2RuntimeTexturePar","Tr2RuntimeTextureParameter","CjsParameter","e","_init_texture","_init_extra_texture","_init_name","_init_extra_name","_init_uavMipLevel","_init_extra_uavMipLevel","_initProto","c","_initClass","_applyDecs","type","define","className","family","carbon","inherit","ITriEffectResourceParameter","edit","notify","readwrite","persist","objectRef","string","uint32","method","impl","adapted","implemented","reason","texture","name","uavMipLevel","__init__","Create","nextName","String","nextMipLevel","changed","UpdateValues","property","source","GetParameterName","GetHashValue","startingHash","FNV1_INITIAL","hashFnv1Identity","OnModified","propertyName","RebuildEffectHandles","_effectRes","CopyToResourceSet","resourceDesc","stage","registerIndex","flags","colorSpace","ResourceFlags","RESOURCE_FLAG_SRGB","Tr2ColorSpace","COLOR_SPACE_SRGB","COLOR_SPACE_LINEAR","SetSrv","GetTexture","ApplyUav","SetUav","SetTextureProvider","GetTextureProvider","SetUavMipLevel","mipLevel","OnAddedToMaterial","material","includes","push","OnRemovedFromMaterial","index","indexOf","splice","#invalidateResourceSets","InvalidateResourceSets"],"mappings":";;;;;;;;;AAUA;AACA;AACA;AAC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CAAC;AAClC,IAAA;AACF,EAAA;;AAEA;EACA,uBAAuBG,GACvB;AACE,IAAA,KAAK,MAAMP,QAAQ,IAAI,IAAI,CAAC,UAAU,EACtC;MACEA,QAAQ,EAAEQ,sBAAsB,IAAI;AACtC,IAAA;AACF,EAAA;AAAC,EAAA;IAAAtE,UAAA,EAAA;AAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"Tr2RuntimeTextureParameter.js","sources":["../../../../../src/trinity/shader/parameter/Tr2RuntimeTextureParameter.js"],"sourcesContent":["// Source: trinity/trinity/Shader/Parameter/Tr2RuntimeTextureParameter.h\n// Source: trinity/trinity/Shader/Parameter/Tr2RuntimeTextureParameter.cpp\n// Source: trinity/trinity/Shader/Parameter/Tr2RuntimeTextureParameter_Blue.cpp\nimport { carbon, impl, edit, type } from \"#schema\";\nimport { CjsParameter } from \"./CjsParameter.js\";\nimport { ITriEffectResourceParameter } from \"./ITriEffectResourceParameter.js\";\nimport { ResourceFlags } from \"./ITr2EffectValue.js\";\nimport { Tr2ColorSpace } from \"#consts/render-context\";\nimport { RealizeTexture } from \"../../core/Tr2ImageIOHelpers.js\";\n\n\n/**\n * A named texture slot fed by a runtime-supplied texture provider rather than an\n * authored res path.\n */\n@type.define({\n className: \"Tr2RuntimeTextureParameter\",\n family: \"shader\"\n})\n@carbon.inherit(ITriEffectResourceParameter)\nexport class Tr2RuntimeTextureParameter extends CjsParameter\n{\n @edit.notify\n @edit.readwrite\n @edit.persist\n @type.objectRef(\"ITr2TextureProvider\")\n texture = null;\n\n @edit.readwrite\n @edit.persist\n @type.string\n name = \"\";\n\n @edit.readwrite\n @edit.persist\n @type.uint32\n uavMipLevel = 0;\n\n #materials = [];\n\n /**\n * Blue construction form: forwards the name, provider and UAV mip level to\n * Create.\n */\n @carbon.method\n @impl.adapted\n __init__(name = \"\", texture = null, uavMipLevel = 0)\n {\n this.Create(name, texture, uavMipLevel);\n }\n\n /**\n * Assigns name, texture provider and UAV mip level together, notifying only\n * when at least one of them actually changed; returns whether it did.\n */\n @carbon.method\n @impl.implemented\n Create(name, texture, uavMipLevel = 0)\n {\n const nextName = String(name);\n const nextMipLevel = uavMipLevel >>> 0;\n const changed = this.name !== nextName || this.texture !== texture || this.uavMipLevel !== nextMipLevel;\n if (!changed)\n {\n return false;\n }\n this.name = nextName;\n this.texture = texture;\n this.uavMipLevel = nextMipLevel;\n this.UpdateValues({ property: \"texture\", source: this });\n return true;\n }\n\n /** The shader resource name this texture binds to. */\n @carbon.method\n @impl.implemented\n GetParameterName()\n {\n return this.name;\n }\n\n /** Content hash: the texture provider's identity (Carbon hashes its pointer). */\n @carbon.method\n @impl.adapted\n GetHashValue(startingHash = CjsParameter.FNV1_INITIAL)\n {\n return CjsParameter.hashFnv1Identity(this.texture, startingHash);\n }\n\n /**\n * Invalidates the resource sets of every material this parameter is attached\n * to.\n */\n @carbon.method\n @impl.adapted\n @impl.reason(\"JS dispatches the native hook using the exposed member name; existing class-owned rendering/resource adaptations remain unchanged.\")\n OnModified(propertyName)\n {\n if (propertyName === \"texture\") this.#invalidateResourceSets();\n return true;\n }\n\n /**\n * Deliberately does nothing: Carbon caches the effect resource type here for\n * later resource-set binding, which the Trinity layer leaves to engine adapters.\n */\n @carbon.method\n @impl.adapted\n RebuildEffectHandles(_effectRes)\n {\n\n // Carbon caches the effect resource type here for later resource-set\n // binding. Not ported yet.\n }\n\n /**\n * Carbon `CopyToResourceSet` (`Tr2RuntimeTextureParameter.cpp:30-46`): the\n * provider's texture as a shader resource. With none, a null binding, which\n * a backend fills with its placeholder as Carbon's fallback texture.\n *\n * Adapted: a provider that is a loaded texture resource has its texture\n * made here, on first bind, through the trailing `renderContext`\n * (`RealizeTexture`), as `TriTextureParameter` and `TriVariable` do; Carbon\n * made it at load. Without this, a `TriTextureRes` handed to\n * `Tr2Effect.SetParameter` (CORTAO's lookup table) bound the placeholder\n * forever.\n *\n * @param {object} resourceDesc A `Tr2ResourceSetDescriptionAL`.\n * @param {number} stage A `ShaderType`.\n * @param {number} registerIndex The register.\n * @param {number} [flags] A `ResourceFlags` word; bit 0 is sRGB.\n * @param {object} [renderContext] The context a resource's texture is made through.\n * @returns {boolean} Whether the slot took the binding.\n */\n @carbon.method\n @impl.adapted\n CopyToResourceSet(resourceDesc, stage, registerIndex, flags = 0, renderContext = null)\n {\n const colorSpace = (flags & ResourceFlags.RESOURCE_FLAG_SRGB)\n ? Tr2ColorSpace.COLOR_SPACE_SRGB\n : Tr2ColorSpace.COLOR_SPACE_LINEAR;\n\n return resourceDesc.SetSrv(stage, registerIndex, this._Texture(renderContext), colorSpace);\n }\n\n /** The provider's texture, realized through the context if it is a resource that has loaded but not yet been created; null otherwise. */\n _Texture(renderContext)\n {\n const provider = this.texture;\n\n if (!provider) return null;\n\n const texture = provider.GetTexture();\n\n if (texture || !renderContext || typeof provider.IsPrepared !== \"function\") return texture;\n\n return RealizeTexture(provider, renderContext);\n }\n\n /**\n * Carbon `ApplyUav` (`Tr2RuntimeTextureParameter.cpp:49-60`): the\n * provider's texture as an unordered-access view at this parameter's mip.\n *\n * @param {object} resourceDesc A `Tr2ResourceSetDescriptionAL`.\n * @param {number} stage A `ShaderType`.\n * @param {number} registerIndex The register.\n * @returns {boolean} Whether the slot took the binding.\n */\n @carbon.method\n @impl.implemented\n ApplyUav(resourceDesc, stage, registerIndex)\n {\n const texture = this.texture ? this.texture.GetTexture() : null;\n\n return texture\n ? resourceDesc.SetUav(stage, registerIndex, texture, this.uavMipLevel)\n : resourceDesc.SetUav(stage, registerIndex, null);\n }\n\n /**\n * Swaps the texture provider and notifies owners; returns false when it is\n * already the same object.\n */\n @carbon.method\n @impl.implemented\n SetTextureProvider(texture)\n {\n if (this.texture === texture)\n {\n return false;\n }\n this.texture = texture;\n this.UpdateValues({ property: \"texture\", source: this });\n return true;\n }\n\n /**\n * The attached provider, or null; this package holds the reference but never\n * resolves or uploads it.\n */\n @carbon.method\n @impl.implemented\n GetTextureProvider()\n {\n return this.texture;\n }\n\n /**\n * Sets the mip level to use when this texture is bound as an unordered-access\n * view, coerced to uint32.\n */\n @carbon.method\n @impl.implemented\n SetUavMipLevel(mipLevel)\n {\n this.uavMipLevel = mipLevel >>> 0;\n }\n\n /**\n * Registers a material to be invalidated when this parameter changes;\n * duplicates are ignored.\n */\n @carbon.method\n @impl.implemented\n OnAddedToMaterial(material)\n {\n if (!this.#materials.includes(material))\n {\n this.#materials.push(material);\n }\n }\n\n /**\n * Drops a material from the tracked list, so later texture swaps no longer\n * invalidate its resource sets.\n */\n @carbon.method\n @impl.implemented\n OnRemovedFromMaterial(material)\n {\n const index = this.#materials.indexOf(material);\n if (index >= 0)\n {\n this.#materials.splice(index, 1);\n }\n }\n\n /** Invalidates the resource sets of every attached material. */\n #invalidateResourceSets()\n {\n for (const material of this.#materials)\n {\n material?.InvalidateResourceSets?.();\n }\n }\n}\n"],"names":["_Tr2RuntimeTexturePar","Tr2RuntimeTextureParameter","CjsParameter","e","_init_texture","_init_extra_texture","_init_name","_init_extra_name","_init_uavMipLevel","_init_extra_uavMipLevel","_initProto","c","_initClass","_applyDecs","type","define","className","family","carbon","inherit","ITriEffectResourceParameter","edit","notify","readwrite","persist","objectRef","string","uint32","method","impl","adapted","implemented","reason","texture","name","uavMipLevel","__init__","Create","nextName","String","nextMipLevel","changed","UpdateValues","property","source","GetParameterName","GetHashValue","startingHash","FNV1_INITIAL","hashFnv1Identity","OnModified","propertyName","RebuildEffectHandles","_effectRes","CopyToResourceSet","resourceDesc","stage","registerIndex","flags","renderContext","colorSpace","ResourceFlags","RESOURCE_FLAG_SRGB","Tr2ColorSpace","COLOR_SPACE_SRGB","COLOR_SPACE_LINEAR","SetSrv","_Texture","provider","GetTexture","IsPrepared","RealizeTexture","ApplyUav","SetUav","SetTextureProvider","GetTextureProvider","SetUavMipLevel","mipLevel","OnAddedToMaterial","material","includes","push","OnRemovedFromMaterial","index","indexOf","splice","#invalidateResourceSets","InvalidateResourceSets"],"mappings":";;;;;;;;;;AAWA;AACA;AACA;AACA;AA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ACA;EAGEC,iBAAiBA,CAACC,QAAQ,EAC1B;IACE,IAAI,CAAC,IAAI,CAAC,UAAU,CAACC,QAAQ,CAACD,QAAQ,CAAC,EACvC;AACE,MAAA,IAAI,CAAC,UAAU,CAACE,IAAI,CAACF,QAAQ,CAAC;AAChC,IAAA;AACF,EAAA;;AAEA;AACF;AACA;AACA;EAGEG,qBAAqBA,CAACH,QAAQ,EAC9B;IACE,MAAMI,KAAK,GAAG,IAAI,CAAC,UAAU,CAACC,OAAO,CAACL,QAAQ,CAAC;IAC/C,IAAII,KAAK,IAAI,CAAC,EACd;MACE,IAAI,CAAC,UAAU,CAACE,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;AAClC,IAAA;AACF,EAAA;;AAEA;EACA,uBAAuBG,GACvB;AACE,IAAA,KAAK,MAAMP,QAAQ,IAAI,IAAI,CAAC,UAAU,EACtC;MACEA,QAAQ,EAAEQ,sBAAsB,IAAI;AACtC,IAAA;AACF,EAAA;AAAC,EAAA;IAAA3E,UAAA,EAAA;AAAA;AACH;;;;"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { applyDecs2311 as _applyDecs2311 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { impl, CjsSchema } from '#schema';
|
|
3
3
|
import { Tr2ResourceSetAL } from '../Tr2ResourceSetAL/Tr2ResourceSetAL.js';
|
|
4
|
-
import { Topology, PixelFormat, ShaderType, Tr2LoadAction, Tr2StoreAction, UpscalingResult, UpscalingSetting, UpscalingTechnique } from '#consts/render-context';
|
|
4
|
+
import { Topology, PixelFormat, ShaderType, Tr2LoadAction, Tr2StoreAction, RenderState, UpscalingResult, UpscalingSetting, UpscalingTechnique } from '#consts/render-context';
|
|
5
5
|
import { Tr2DrawUPHelper, Failed, Tr2VertexLayoutALStub, Tr2ConstantUsageAL, ALResult, Tr2ColorAttachment, Tr2DepthAttachment, resolveBindingPlan } from '#trinityal';
|
|
6
6
|
import { CjsWebgpuWorkQueue } from './core/CjsWebgpuWorkQueue.js';
|
|
7
7
|
import { CjsWebgpuMipGenerator } from './core/CjsWebgpuMipGenerator.js';
|
|
8
8
|
import { CjsWebgpuBufferAL } from './CjsWebgpuBufferAL.js';
|
|
9
9
|
import { CjsWebgpuConstantBufferAL } from './CjsWebgpuConstantBufferAL.js';
|
|
10
|
+
import { CARBON_BACKEND_ADDRESS_MODES_SYMBOL } from '#resource/format';
|
|
10
11
|
import { CjsWebgpuSamplerStateAL } from './CjsWebgpuSamplerStateAL.js';
|
|
11
12
|
import { CjsWebgpuResourceSetAL } from './CjsWebgpuResourceSetAL.js';
|
|
12
13
|
import { CjsWebgpuTextureAL } from './CjsWebgpuTextureAL.js';
|
|
@@ -834,6 +835,10 @@ class CjsWebgpuRenderContextAL {
|
|
|
834
835
|
this._viewport = viewport ? {
|
|
835
836
|
...viewport
|
|
836
837
|
} : null;
|
|
838
|
+
|
|
839
|
+
// Metal hands every viewport to its work queue (`Tr2RenderContextMetal.mm:1180-1186`).
|
|
840
|
+
// A viewport without depth bounds has Tr2Viewport's defaults, 0 and 1.
|
|
841
|
+
if (viewport) this._workQueue.SetViewport(viewport.x, viewport.y, viewport.width, viewport.height, viewport.minZ ?? 0, viewport.maxZ ?? 1);
|
|
837
842
|
return true;
|
|
838
843
|
}
|
|
839
844
|
|
|
@@ -848,9 +853,11 @@ class CjsWebgpuRenderContextAL {
|
|
|
848
853
|
* Clears the bound attachments.
|
|
849
854
|
*
|
|
850
855
|
* A CLEAR IS A LOAD OPERATION, not a command. WebGPU has no mid-pass clear,
|
|
851
|
-
* so this ends the current pass and
|
|
852
|
-
*
|
|
853
|
-
*
|
|
856
|
+
* so this ends the current pass and makes the clear the next one's load
|
|
857
|
+
* actions, ON THE ATTACHMENTS BOUND NOW: Metal's `ClearAttachment`
|
|
858
|
+
* (`MetalWorkQueue.mm:2845-2881`). Binding other targets first runs the
|
|
859
|
+
* clear in a pass of its own, so it never lands on them; a pending hint
|
|
860
|
+
* wins, and the clear is ignored.
|
|
854
861
|
*
|
|
855
862
|
* CARBON'S FLAGS AND SLOT (`Tr2RenderContextMetal.mm:297-351`): the colour
|
|
856
863
|
* clear names ONE slot, and depth is cleared only when asked. Every other
|
|
@@ -877,7 +884,7 @@ class CjsWebgpuRenderContextAL {
|
|
|
877
884
|
colors.push(clearTarget && index === slot ? new Tr2ColorAttachment(Tr2LoadAction.CLEAR, Tr2StoreAction.STORE, options.color ?? 0) : new Tr2ColorAttachment(Tr2LoadAction.LOAD, Tr2StoreAction.STORE));
|
|
878
885
|
});
|
|
879
886
|
const depth = attachments.depth ? clearDepth ? new Tr2DepthAttachment(Tr2LoadAction.CLEAR, Tr2StoreAction.STORE, Number(options.depth ?? 1)) : new Tr2DepthAttachment(Tr2LoadAction.LOAD, Tr2StoreAction.STORE) : null;
|
|
880
|
-
this._workQueue.
|
|
887
|
+
this._Record(this._workQueue.ClearAttachment(colors, depth));
|
|
881
888
|
return true;
|
|
882
889
|
}
|
|
883
890
|
|
|
@@ -1151,6 +1158,13 @@ class CjsWebgpuRenderContextAL {
|
|
|
1151
1158
|
if (this._renderStates.get(key) === value >>> 0) return true;
|
|
1152
1159
|
this._renderStates.set(key, value >>> 0);
|
|
1153
1160
|
this._pipelineDirty = true;
|
|
1161
|
+
|
|
1162
|
+
// Depth clip is honoured where the device can: the shadow cascades draw
|
|
1163
|
+
// with it off, so a caster in front of the light's near plane still
|
|
1164
|
+
// writes depth. Without depth-clip-control it stays on.
|
|
1165
|
+
if (key === RenderState.RS_DEPTH_CLIP_ENABLE) {
|
|
1166
|
+
this._psoDescription.unclippedDepth = value === 0 && this._webgpu.GetDevice().features.has("depth-clip-control");
|
|
1167
|
+
}
|
|
1154
1168
|
return true;
|
|
1155
1169
|
}
|
|
1156
1170
|
|
|
@@ -1451,6 +1465,8 @@ class CjsWebgpuRenderContextAL {
|
|
|
1451
1465
|
const keyParts = [program.GetIdentity(), group, setId];
|
|
1452
1466
|
const resolved = [];
|
|
1453
1467
|
const dynamicOffsets = [];
|
|
1468
|
+
// Each storage dummy in the group its own (GetDummyStorageTexture).
|
|
1469
|
+
let storageDummies = 0;
|
|
1454
1470
|
for (const binding of bindings) {
|
|
1455
1471
|
if (binding.group !== group) continue;
|
|
1456
1472
|
let resource;
|
|
@@ -1463,7 +1479,7 @@ class CjsWebgpuRenderContextAL {
|
|
|
1463
1479
|
// drawn through one program share one bind group and differ only in
|
|
1464
1480
|
// their offsets, which is the whole economy of the arena.
|
|
1465
1481
|
const size = binding.buffer.minBindingSize ?? 16;
|
|
1466
|
-
const constantBuffer = this._ConstantBufferFor(binding);
|
|
1482
|
+
const constantBuffer = binding.generatedSymbol === CARBON_BACKEND_ADDRESS_MODES_SYMBOL ? this._AddressModesBuffer(entries ? set : null, size) : this._ConstantBufferFor(binding);
|
|
1467
1483
|
if (constantBuffer) {
|
|
1468
1484
|
const region = this.UploadConstants(constantBuffer, size);
|
|
1469
1485
|
resource = {
|
|
@@ -1486,7 +1502,7 @@ class CjsWebgpuRenderContextAL {
|
|
|
1486
1502
|
}
|
|
1487
1503
|
} else {
|
|
1488
1504
|
resource = entries ? entries.get(`${group}:${binding.binding}`) ?? null : null;
|
|
1489
|
-
resource ??= this._DummyFor(binding);
|
|
1505
|
+
resource ??= this._DummyFor(binding, binding.storageTexture ? storageDummies++ : 0);
|
|
1490
1506
|
}
|
|
1491
1507
|
resolved.push({
|
|
1492
1508
|
binding: binding.binding,
|
|
@@ -1591,11 +1607,40 @@ class CjsWebgpuRenderContextAL {
|
|
|
1591
1607
|
return null;
|
|
1592
1608
|
}
|
|
1593
1609
|
|
|
1594
|
-
/**
|
|
1595
|
-
|
|
1610
|
+
/**
|
|
1611
|
+
* The emulated-addressing modes buffer: WebGPU has no border or mirror-once
|
|
1612
|
+
* address mode, so a translated shader tests them from this buffer
|
|
1613
|
+
* (`emulatedAddressing.js`). It is the backend's own, not the effect's, and
|
|
1614
|
+
* is filled here, per draw, from the sampler states the resource set binds,
|
|
1615
|
+
* so an override that rebinds a sampler is what the shader reads.
|
|
1616
|
+
*
|
|
1617
|
+
* @param {object|null} set The draw's `CjsWebgpuResourceSetAL`, or null.
|
|
1618
|
+
* @param {number} size The binding's size in bytes, a vec4 per sampler register.
|
|
1619
|
+
* @returns {object} The constant buffer, filled.
|
|
1620
|
+
*/
|
|
1621
|
+
_AddressModesBuffer(set, size) {
|
|
1622
|
+
if (!this._addressModes?.IsValid() || this._addressModes.GetSize() < size) {
|
|
1623
|
+
this._addressModes = new CjsWebgpuConstantBufferAL();
|
|
1624
|
+
this._addressModes.Create(size, Tr2ConstantUsageAL.REUSABLE, null, this);
|
|
1625
|
+
}
|
|
1626
|
+
const {
|
|
1627
|
+
data
|
|
1628
|
+
} = this._addressModes.Lock(this);
|
|
1629
|
+
const modes = set ? set.GetAddressModes(size / 16) : new Float32Array(size / 4);
|
|
1630
|
+
data.fill(0);
|
|
1631
|
+
data.set(new Uint8Array(modes.buffer, modes.byteOffset, modes.byteLength));
|
|
1632
|
+
this._addressModes.Unlock(this);
|
|
1633
|
+
return this._addressModes;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
/** The emulated-addressing modes buffer, made on first need. */
|
|
1637
|
+
_addressModes = null;
|
|
1638
|
+
|
|
1639
|
+
/** Metal's dummy for a slot no set filled; `storageIndex` picks a storage dummy of its own. */
|
|
1640
|
+
_DummyFor(binding, storageIndex = 0) {
|
|
1596
1641
|
if (binding.sampler) return this.GetDummySampler();
|
|
1597
1642
|
if (binding.texture) return this.GetDummyTexture(binding.texture.viewDimension ?? "2d");
|
|
1598
|
-
if (binding.storageTexture) return this.GetDummyStorageTexture(binding.storageTexture.format, binding.storageTexture.viewDimension);
|
|
1643
|
+
if (binding.storageTexture) return this.GetDummyStorageTexture(binding.storageTexture.format, binding.storageTexture.viewDimension, storageIndex);
|
|
1599
1644
|
return {
|
|
1600
1645
|
buffer: this.GetNullBuffer(binding.buffer?.minBindingSize ?? 16, "STORAGE")
|
|
1601
1646
|
};
|
|
@@ -1648,14 +1693,17 @@ class CjsWebgpuRenderContextAL {
|
|
|
1648
1693
|
*
|
|
1649
1694
|
* D3D binds a null UAV and drops its writes; WebGPU has no null binding and
|
|
1650
1695
|
* checks the view's format against the layout, so the stand-in is one per
|
|
1651
|
-
* format and dimension, written to and never read.
|
|
1696
|
+
* format and dimension, written to and never read. And one per `index`:
|
|
1697
|
+
* WebGPU refuses two writable bindings of one texture in a dispatch, so a
|
|
1698
|
+
* set needing several asks for distinct ones.
|
|
1652
1699
|
*
|
|
1653
1700
|
* @param {string} format The binding's `storageTexture.format`.
|
|
1654
1701
|
* @param {string} viewDimension The binding's `storageTexture.viewDimension`.
|
|
1702
|
+
* @param {number} [index] Which of that kind, for a set needing several.
|
|
1655
1703
|
* @returns {object} A `GPUTextureView`.
|
|
1656
1704
|
*/
|
|
1657
|
-
GetDummyStorageTexture(format, viewDimension) {
|
|
1658
|
-
const key = `${format}:${viewDimension}`;
|
|
1705
|
+
GetDummyStorageTexture(format, viewDimension, index = 0) {
|
|
1706
|
+
const key = `${format}:${viewDimension}:${index}`;
|
|
1659
1707
|
const existing = this._dummies.storageTextures.get(key);
|
|
1660
1708
|
if (existing) return existing;
|
|
1661
1709
|
const usage = this._webgpu.GetTextureUsage();
|
|
@@ -1779,7 +1827,10 @@ class CjsWebgpuRenderContextAL {
|
|
|
1779
1827
|
fragment: {
|
|
1780
1828
|
module: fragmentModule,
|
|
1781
1829
|
entryPoint: WEBGPU_ENTRY_POINT,
|
|
1782
|
-
targets: recipe.fragment.targets
|
|
1830
|
+
targets: recipe.fragment.targets,
|
|
1831
|
+
...(recipe.fragment.constants ? {
|
|
1832
|
+
constants: recipe.fragment.constants
|
|
1833
|
+
} : {})
|
|
1783
1834
|
}
|
|
1784
1835
|
} : {})
|
|
1785
1836
|
};
|
|
@@ -1807,11 +1858,13 @@ class CjsWebgpuRenderContextAL {
|
|
|
1807
1858
|
if (this._IsCanvasPass()) {
|
|
1808
1859
|
if (!this._renderTarget) {
|
|
1809
1860
|
this._psoDescription.colorFormats = [];
|
|
1861
|
+
this._psoDescription.unormTargets = [];
|
|
1810
1862
|
this._psoDescription.depthFormat = null;
|
|
1811
1863
|
this._psoDescription.sampleCount = 1;
|
|
1812
1864
|
return;
|
|
1813
1865
|
}
|
|
1814
1866
|
this._psoDescription.colorFormats = [this._renderTarget.GetFormat()];
|
|
1867
|
+
this._psoDescription.unormTargets = [];
|
|
1815
1868
|
this._psoDescription.depthFormat = this._renderTarget.GetDepthFormat();
|
|
1816
1869
|
this._psoDescription.sampleCount = this._renderTarget.GetSampleCount();
|
|
1817
1870
|
return;
|
|
@@ -1819,6 +1872,7 @@ class CjsWebgpuRenderContextAL {
|
|
|
1819
1872
|
const formats = this._boundRenderTargets.map(target => target ? target.GetDeviceFormat() : null);
|
|
1820
1873
|
while (formats.length && !formats[formats.length - 1]) formats.pop();
|
|
1821
1874
|
this._psoDescription.colorFormats = formats;
|
|
1875
|
+
this._psoDescription.unormTargets = this._boundRenderTargets.map(target => Boolean(target && target.IsUnormSubstitute()));
|
|
1822
1876
|
this._psoDescription.depthFormat = this._depthStencil ? this._depthStencil.GetDeviceFormat() : null;
|
|
1823
1877
|
this._psoDescription.sampleCount = 1;
|
|
1824
1878
|
}
|
|
@@ -2148,14 +2202,23 @@ class CjsWebgpuRenderContextAL {
|
|
|
2148
2202
|
/**
|
|
2149
2203
|
* Binds depth read-only, so it can be sampled while still testing.
|
|
2150
2204
|
*
|
|
2151
|
-
*
|
|
2152
|
-
*
|
|
2153
|
-
*
|
|
2154
|
-
*
|
|
2205
|
+
* TURNING IT ON REFRESHES THE BOUND DEPTH'S FLOAT SHADOW. Carbon enables it
|
|
2206
|
+
* exactly where a pass is about to read the depth it has written with the
|
|
2207
|
+
* depth still bound: SSAO, the light lists, the lens-flare queries
|
|
2208
|
+
* (EveSpaceSceneRenderDriver.cpp:365, 543, 589). Shaders here read the
|
|
2209
|
+
* r32float shadow (`CjsWebgpuTextureAL._depthShadow`), which otherwise
|
|
2210
|
+
* refreshes only when the depth is unbound (`SetDepthStencil`), so without
|
|
2211
|
+
* this they read the previous frame's depth. The copy ends the open pass.
|
|
2212
|
+
*
|
|
2213
|
+
* The flag itself is STORED, NOT YET APPLIED. WebGPU expresses it as
|
|
2214
|
+
* `depthReadOnly` on the render-pass descriptor, which `_Descriptor`
|
|
2215
|
+
* builds; wiring it there is a pass-descriptor change rather than a state
|
|
2216
|
+
* one, and the flag has to exist before it can be read.
|
|
2155
2217
|
*
|
|
2156
2218
|
* @param {boolean} enable Whether depth is read-only.
|
|
2157
2219
|
*/
|
|
2158
2220
|
SetReadOnlyDepth(enable) {
|
|
2221
|
+
if (enable && !this._readOnlyDepth && this._depthStencil) this._Record(this._workQueue.CopyDepthShadow(this._depthStencil));
|
|
2159
2222
|
this._readOnlyDepth = !!enable;
|
|
2160
2223
|
}
|
|
2161
2224
|
|