Skip to content

Commit 98a80a9

Browse files
committed
Fix #145
1 parent e6726cc commit 98a80a9

11 files changed

Lines changed: 190 additions & 113 deletions

File tree

dist/spector.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/spector.bundle.func.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/spector.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { BaseRecorder } from "./baseRecorder";
2+
3+
import { IFunctionInformation } from "../types/functionInformation";
4+
import { ReadProgramHelper } from "../utils/readProgramHelper";
5+
import { IProgramCapture } from "../../shared/capture/programCapture";
6+
7+
export class ProgramRecorder extends BaseRecorder<WebGLProgram> {
8+
protected get objectName(): string {
9+
return "Program";
10+
}
11+
12+
protected getCreateCommandNames(): string[] {
13+
return ["createProgram"];
14+
}
15+
16+
protected getUpdateCommandNames(): string[] {
17+
return ["linkProgram"];
18+
}
19+
20+
protected getDeleteCommandNames(): string[] {
21+
return ["deleteProgram"];
22+
}
23+
24+
protected getBoundInstance(target: WebGLProgram): WebGLProgram {
25+
return target;
26+
}
27+
28+
protected delete(instance: WebGLProgram): number {
29+
const customData = (instance as any).__SPECTOR_Object_CustomData;
30+
if (!customData) {
31+
return 0;
32+
}
33+
34+
return customData.length;
35+
}
36+
37+
protected update(functionInformation: IFunctionInformation, target: WebGLProgram, instance: WebGLProgram): number {
38+
if (functionInformation.arguments.length >= 1 && !functionInformation.arguments[0]) {
39+
return 0;
40+
}
41+
42+
const customData = this.getCustomData(instance);
43+
if (!customData) {
44+
return 0;
45+
}
46+
47+
const previousLength = (instance as any).__SPECTOR_Object_CustomData ? (instance as any).__SPECTOR_Object_CustomData.length : 0;
48+
(instance as any).__SPECTOR_Object_CustomData = customData;
49+
return customData.length - previousLength;
50+
}
51+
52+
private getCustomData(program: WebGLProgram): IProgramCapture {
53+
const context = this.options.context;
54+
const programCapture = ReadProgramHelper.getProgramData(context, program);
55+
return programCapture;
56+
}
57+
}

src/backend/spies/recorderSpy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BufferRecorder } from "../recorders/bufferRecorder";
55
import { RenderBufferRecorder } from "../recorders/renderBufferRecorder";
66
import { Texture2DRecorder } from "../recorders/texture2DRecorder";
77
import { Texture3DRecorder } from "../recorders/texture3DRecorder";
8+
import { ProgramRecorder } from "../recorders/programRecorder";
89
import { IRecorder } from "../recorders/baseRecorder";
910

1011
export class RecorderSpy {
@@ -50,6 +51,7 @@ export class RecorderSpy {
5051
new RenderBufferRecorder(this.contextInformation),
5152
new Texture2DRecorder(this.contextInformation),
5253
new Texture3DRecorder(this.contextInformation),
54+
new ProgramRecorder(this.contextInformation),
5355
);
5456

5557
for (const recorder of this.recorders) {

src/backend/states/drawCalls/drawCallState.ts

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Program } from "../../webGlObjects/webGlObjects";
88
import { IContextInformation } from "../../types/contextInformation";
99
import { IRenderBufferRecorderData } from "../../recorders/renderBufferRecorder";
1010
import { IBufferRecorderData } from "../../recorders/bufferRecorder";
11+
import { ReadProgramHelper } from "../../utils/readProgramHelper";
1112

1213
export class DrawCallState extends BaseState {
1314
public static readonly stateName = "DrawCall";
@@ -66,24 +67,20 @@ export class DrawCallState extends BaseState {
6667

6768
this.currentState.frameBuffer = this.readFrameBufferFromContext();
6869

70+
const programCapture = program.__SPECTOR_Object_CustomData ?
71+
program.__SPECTOR_Object_CustomData :
72+
ReadProgramHelper.getProgramData(this.context, program);
73+
6974
this.currentState.programStatus = {
70-
program: this.getSpectorData(program),
71-
DELETE_STATUS: this.context.getProgramParameter(program, WebGlConstants.DELETE_STATUS.value),
72-
LINK_STATUS: this.context.getProgramParameter(program, WebGlConstants.LINK_STATUS.value),
73-
VALIDATE_STATUS: this.context.getProgramParameter(program, WebGlConstants.VALIDATE_STATUS.value),
74-
RECOMPILABLE: ProgramRecompilerHelper.isBuildableProgram(program),
75+
...programCapture.programStatus
7576
};
76-
77+
this.currentState.programStatus.program = this.getSpectorData(program);
78+
this.currentState.programStatus.RECOMPILABLE = ProgramRecompilerHelper.isBuildableProgram(program);
7779
if (this.currentState.programStatus.RECOMPILABLE) {
7880
Program.saveInGlobalStore(program);
7981
}
8082

81-
const shaders = this.context.getAttachedShaders(program);
82-
this.currentState.shaders = [];
83-
for (const shader of shaders) {
84-
const shaderState = this.readShaderFromContext(shader);
85-
this.currentState.shaders.push(shaderState);
86-
}
83+
this.currentState.shaders = programCapture.shaders;
8784

8885
const attributes = this.context.getProgramParameter(program, WebGlConstants.ACTIVE_ATTRIBUTES.value);
8986
this.currentState.attributes = [];
@@ -256,29 +253,6 @@ export class DrawCallState extends BaseState {
256253
return attachmentState;
257254
}
258255

259-
protected readShaderFromContext(shader: WebGLShader): {} {
260-
const source = this.context.getShaderSource(shader);
261-
const spectorData = this.getSpectorData(shader);
262-
263-
const nameInMetadata = (shader && (shader as any).__SPECTOR_Metadata && (shader as any).__SPECTOR_Metadata.name);
264-
let name = nameInMetadata ? (shader as any).__SPECTOR_Metadata.name :
265-
this.readNameFromShaderSource(source);
266-
267-
if (!name) {
268-
name = (this.context.getShaderParameter(shader, WebGlConstants.SHADER_TYPE.value) === WebGlConstants.FRAGMENT_SHADER.value) ?
269-
"Fragment" : "Vertex";
270-
}
271-
272-
return {
273-
shader: spectorData,
274-
COMPILE_STATUS: this.context.getShaderParameter(shader, WebGlConstants.COMPILE_STATUS.value),
275-
DELETE_STATUS: this.context.getShaderParameter(shader, WebGlConstants.DELETE_STATUS.value),
276-
SHADER_TYPE: this.getWebGlConstant(this.context.getShaderParameter(shader, WebGlConstants.SHADER_TYPE.value)),
277-
source,
278-
name,
279-
};
280-
}
281-
282256
protected readAttributeFromContext(program: WebGLProgram, activeAttributeIndex: number): {} {
283257
const info = this.context.getActiveAttrib(program, activeAttributeIndex);
284258
const location = this.context.getAttribLocation(program, info.name);
@@ -544,45 +518,4 @@ export class DrawCallState extends BaseState {
544518
const constant = WebGlConstantsByValue[value];
545519
return constant ? constant.name : value;
546520
}
547-
548-
// Thx to https://github.com/spite/ShaderEditorExtension/blob/7b9483fdf5c417573906bae4139ca8bc7b8a49ca/src/panel.js#L689
549-
// This helps displaying SHADER_NAME used in the extension.
550-
private readNameFromShaderSource(source: string): string {
551-
try {
552-
let name = "";
553-
let match;
554-
555-
const shaderNameRegex = /#define[\s]+SHADER_NAME[\s]+([\S]+)(\n|$)/gi;
556-
match = shaderNameRegex.exec(source);
557-
if (match !== null) {
558-
if (match.index === shaderNameRegex.lastIndex) {
559-
shaderNameRegex.lastIndex++;
560-
}
561-
name = match[1];
562-
}
563-
564-
if (name === "") {
565-
// #define SHADER_NAME_B64 44K344Kn44O844OA44O8
566-
// #define SHADER_NAME_B64 8J+YjvCfmIE=
567-
const shaderName64Regex = /#define[\s]+SHADER_NAME_B64[\s]+([\S]+)(\n|$)/gi;
568-
match = shaderName64Regex.exec(source);
569-
if (match !== null) {
570-
if (match.index === shaderName64Regex.lastIndex) {
571-
shaderName64Regex.lastIndex++;
572-
}
573-
574-
name = match[1];
575-
}
576-
577-
if (name) {
578-
name = decodeURIComponent(atob(name));
579-
}
580-
}
581-
582-
return name;
583-
}
584-
catch (e) {
585-
return null;
586-
}
587-
}
588521
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { WebGlConstants, WebGlConstantsByValue } from "../types/webglConstants";
2+
import { WebGLRenderingContexts } from "../types/contextInformation";
3+
import { IProgramCapture, IShaderCapture } from "../../shared/capture/programCapture";
4+
5+
export class ReadProgramHelper {
6+
public static getProgramData(context: WebGLRenderingContexts, program: WebGLProgram): IProgramCapture {
7+
const programStatus = {
8+
LINK_STATUS: context.getProgramParameter(program, WebGlConstants.LINK_STATUS.value),
9+
VALIDATE_STATUS: context.getProgramParameter(program, WebGlConstants.VALIDATE_STATUS.value),
10+
};
11+
12+
const webGLshaders = context.getAttachedShaders(program);
13+
const shaders = new Array(2);
14+
15+
let length = 0;
16+
for (const shader of webGLshaders) {
17+
const shaderState = this.readShaderFromContext(context, shader);
18+
length += shaderState.source.length;
19+
20+
if (shaderState.fragment) {
21+
shaders[1] = shaderState;
22+
}
23+
else {
24+
shaders[0] = shaderState;
25+
}
26+
}
27+
28+
return {
29+
programStatus,
30+
shaders,
31+
length,
32+
};
33+
}
34+
35+
private static readShaderFromContext(context: WebGLRenderingContexts, shader: WebGLShader): IShaderCapture {
36+
const source = context.getShaderSource(shader);
37+
38+
const shaderTypeValue = context.getShaderParameter(shader, WebGlConstants.SHADER_TYPE.value);
39+
const isFragment = shaderTypeValue === WebGlConstants.FRAGMENT_SHADER.value;
40+
41+
const nameInMetadata = (shader && (shader as any).__SPECTOR_Metadata && (shader as any).__SPECTOR_Metadata.name);
42+
let name = nameInMetadata ?
43+
(shader as any).__SPECTOR_Metadata.name :
44+
this.readNameFromShaderSource(source);
45+
46+
if (!name) {
47+
name = (isFragment) ? "Fragment" : "Vertex";
48+
}
49+
50+
return {
51+
COMPILE_STATUS: context.getShaderParameter(shader, WebGlConstants.COMPILE_STATUS.value),
52+
fragment: isFragment,
53+
name,
54+
source,
55+
};
56+
}
57+
58+
// Thx to https://github.com/spite/ShaderEditorExtension/blob/7b9483fdf5c417573906bae4139ca8bc7b8a49ca/src/panel.js#L689
59+
// This helps displaying SHADER_NAME used in the extension.
60+
private static readNameFromShaderSource(source: string): string {
61+
try {
62+
let name = "";
63+
let match;
64+
65+
const shaderNameRegex = /#define[\s]+SHADER_NAME[\s]+([\S]+)(\n|$)/gi;
66+
match = shaderNameRegex.exec(source);
67+
if (match !== null) {
68+
if (match.index === shaderNameRegex.lastIndex) {
69+
shaderNameRegex.lastIndex++;
70+
}
71+
name = match[1];
72+
}
73+
74+
if (name === "") {
75+
// #define SHADER_NAME_B64 44K344Kn44O844OA44O8
76+
// #define SHADER_NAME_B64 8J+YjvCfmIE=
77+
const shaderName64Regex = /#define[\s]+SHADER_NAME_B64[\s]+([\S]+)(\n|$)/gi;
78+
match = shaderName64Regex.exec(source);
79+
if (match !== null) {
80+
if (match.index === shaderName64Regex.lastIndex) {
81+
shaderName64Regex.lastIndex++;
82+
}
83+
84+
name = match[1];
85+
}
86+
87+
if (name) {
88+
name = decodeURIComponent(atob(name));
89+
}
90+
}
91+
92+
return name;
93+
}
94+
catch (e) {
95+
return null;
96+
}
97+
}
98+
}

src/embeddedFrontend/resultView/JSON/jsonSourceItemComponent.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/embeddedFrontend/resultView/resultView.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { JSONContentComponent } from "./JSON/jsonContentComponent";
1515
import { JSONGroupComponent } from "./JSON/jsonGroupComponent";
1616
import { JSONItemComponent } from "./JSON/jsonItemComponent";
1717
import { JSONImageItemComponent } from "./JSON/jsonImageItemComponent";
18-
import { JSONSourceItemComponent } from "./JSON/jsonSourceItemComponent";
1918
import { JSONHelpItemComponent } from "./JSON/jsonHelpItemComponent";
2019
import { JSONVisualStateItemComponent } from "./JSON/jsonVisualStateItemComponent";
2120
import { ResultViewMenuComponent, IResultViewMenuState, MenuStatus } from "./menu/resultViewMenuComponent";
@@ -48,7 +47,6 @@ export class ResultView {
4847
private readonly jsonGroupComponent: JSONGroupComponent;
4948
private readonly jsonItemComponent: JSONItemComponent;
5049
private readonly jsonImageItemComponent: JSONImageItemComponent;
51-
private readonly jsonSourceItemComponent: JSONSourceItemComponent;
5250
private readonly jsonHelpItemComponent: JSONHelpItemComponent;
5351
private readonly jsonVisualStateItemComponent: JSONVisualStateItemComponent;
5452
private readonly resultViewMenuComponent: ResultViewMenuComponent;
@@ -107,7 +105,6 @@ export class ResultView {
107105
this.jsonGroupComponent = new JSONGroupComponent();
108106
this.jsonItemComponent = new JSONItemComponent();
109107
this.jsonImageItemComponent = new JSONImageItemComponent();
110-
this.jsonSourceItemComponent = new JSONSourceItemComponent();
111108
this.jsonHelpItemComponent = new JSONHelpItemComponent();
112109
this.jsonVisualStateItemComponent = new JSONVisualStateItemComponent();
113110
this.resultViewMenuComponent = new ResultViewMenuComponent();
@@ -166,9 +163,6 @@ export class ResultView {
166163
sourceVertex: sourceCodeState.state.sourceVertex,
167164
});
168165
});
169-
this.jsonSourceItemComponent.onOpenSourceClicked.add((sourceEventArg) => {
170-
this.openShader(sourceEventArg.state.value === "FRAGMENT_SHADER");
171-
});
172166

173167
this.updateViewState();
174168
}
@@ -400,18 +394,12 @@ export class ResultView {
400394
}
401395

402396
for (const key in json) {
403-
if (key === "VisualState" || key === "analyserName") {
397+
if (key === "VisualState" || key === "analyserName" || key === "source") {
404398
continue;
405399
}
406400

407401
const value = json[key];
408-
if (key === "source") {
409-
this.mvx.addChildState(parentGroupId, {
410-
key,
411-
value: json["SHADER_TYPE"],
412-
}, this.jsonSourceItemComponent);
413-
}
414-
else if (key === "visual") {
402+
if (key === "visual") {
415403
for (const target in value) {
416404
if (value.hasOwnProperty(target) && value[target]) {
417405
this.mvx.addChildState(parentGroupId, {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface IShaderCapture {
2+
COMPILE_STATUS: boolean;
3+
fragment: boolean;
4+
name: string;
5+
source: string;
6+
}
7+
8+
export interface IProgramStatus {
9+
LINK_STATUS: boolean;
10+
VALIDATE_STATUS: boolean;
11+
}
12+
13+
export interface IProgramCapture {
14+
programStatus: IProgramStatus;
15+
shaders: IShaderCapture[];
16+
length: number;
17+
}

0 commit comments

Comments
 (0)