-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdebug.ts
132 lines (113 loc) · 4.57 KB
/
debug.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { WritableBufferBinding } from '../core/bindings/WritableBufferBinding'
import { Renderer } from '../core/renderers/utils'
/**
* Logs all the main commands executed during each {@link core/scenes/Scene.Scene#render | Scene render} calls.
*/
export const logSceneCommands = (renderer: Renderer) => {
const { scene } = renderer
if (!scene) return
const renderCommands = []
scene.computePassEntries.forEach((computePass) => {
renderCommands.push({
command: 'Render ComputePass',
content: computePass.options.label,
})
computePass.material.bindGroups.forEach((bindGroup) => {
bindGroup.bufferBindings.forEach((binding: WritableBufferBinding) => {
if (binding.shouldCopyResult) {
renderCommands.push({
command: `Copy buffer to buffer`,
source: `${binding.name} buffer`,
destination: `${binding.name} result buffer`,
})
}
})
})
})
for (const renderPassEntryType in scene.renderPassEntries) {
let passDrawnCount = 0
scene.renderPassEntries[renderPassEntryType].forEach((renderPassEntry) => {
// early bail if there's nothing to draw
if (!scene.getRenderPassEntryLength(renderPassEntry)) return
const destination = !renderPassEntry.renderPass.options.useColorAttachments
? undefined
: renderPassEntry.renderPass.options.colorAttachments.length === 0 &&
renderPassEntry.renderPass.options.useDepth
? `${renderPassEntry.renderTexture.options.label} depth pass`
: renderPassEntry.renderPass.options.colorAttachments.length > 1
? `${renderPassEntry.renderTexture.options.label} multiple targets`
: renderPassEntry.renderTexture
? `${renderPassEntry.renderTexture.options.label}`
: 'Context current texture'
let descriptor = renderPassEntry.renderPass.options.label
const operations = {
loadOp: renderPassEntry.renderPass.options.useColorAttachments
? renderPassEntryType === 'screen' && passDrawnCount > 0
? 'load'
: renderPassEntry.renderPass.options.loadOp
: undefined,
depthLoadOp: undefined,
sampleCount: renderPassEntry.renderPass.options.sampleCount,
...(renderPassEntry.renderPass.options.qualityRatio !== 1 && {
qualityRatio: renderPassEntry.renderPass.options.qualityRatio,
}),
}
if (renderPassEntry.renderPass.options.useDepth) {
operations.depthLoadOp = renderPassEntry.renderPass.options.depthLoadOp
}
passDrawnCount++
if (renderPassEntry.element) {
if (
renderPassEntry.element.type === 'ShaderPass' &&
!(renderPassEntry.element.inputTarget || renderPassEntry.element.outputTarget)
) {
renderCommands.push({
command: `Copy texture to texture`,
source: destination,
destination: `${renderPassEntry.element.options.label} renderTexture`,
})
operations.loadOp = 'clear'
}
descriptor += ' ' + JSON.stringify(operations)
renderCommands.push({
command: `Render ${renderPassEntry.element.type}`,
source: renderPassEntry.element.options.label,
destination,
descriptor,
})
if (
renderPassEntry.element.type === 'ShaderPass' &&
!renderPassEntry.element.outputTarget &&
renderPassEntry.element.options.copyOutputToRenderTexture
) {
renderCommands.push({
command: `Copy texture to texture`,
source: destination,
destination: `${renderPassEntry.element.options.label} renderTexture`,
})
} else if (renderPassEntry.element.type === 'PingPongPlane') {
renderCommands.push({
command: `Copy texture to texture`,
source: destination,
destination: `${renderPassEntry.element.renderTexture.options.label}`,
})
}
} else if (renderPassEntry.stack) {
descriptor += ' ' + JSON.stringify(operations)
for (const stackType in renderPassEntry.stack) {
for (const objectType in renderPassEntry.stack[stackType]) {
if (renderPassEntry.stack[stackType][objectType].length) {
renderCommands.push({
command: `Render stack (${stackType} ${objectType} objects)`,
source: renderPassEntry.stack[stackType][objectType],
destination,
descriptor,
})
}
}
}
}
})
}
console.table(renderCommands)
}