xgpu
Version:
XGPU is an extendable library for WebGPU that provides a higher-level, easy-to-use interface for building rendering engines or processing numeric data. It handles automatic data binding, buffer alignment, variable declarations in shaders, and more. XGPU i
584 lines • 1.29 MB
JSON
{
"xGPU": {
"BuiltIns": [
{
"objectType": "class",
"name": "BuiltIns",
"filePath": "xGPU.BuiltIns",
"statics": {
"properties": {
"public": [
{
"objectType": "property",
"name": "vertexInputs",
"type": "{ vertexIndex: { builtin: string; type: string; }; instanceIndex: { builtin: string; type: string; }; }",
"visibility": "public",
"rawText": "public static vertexInputs = {\r\n vertexIndex: { builtin: \"@builtin(vertex_index)\", type: \"u32\" },\r\n instanceIndex: { builtin: \"@builtin(instance_index)\", type: \"u32\" },\r\n }"
},
{
"objectType": "property",
"name": "vertexOutputs",
"type": "{ position: { builtin: string; type: string; }; Float: { type: string; vsOut: boolean; }; Vec2: { type: string; vsOut: boolean; }; Vec3: { type: string; vsOut: boolean; }; Vec4: { type: string; vsOut: boolean; }; }",
"visibility": "public",
"rawText": "public static vertexOutputs = {\r\n position: { builtin: \"@builtin(position)\", type: \"vec4<f32>\" },\r\n Float: { type: \"f32\", vsOut: true },\r\n Vec2: { type: \"vec2<f32>\", vsOut: true },\r\n Vec3: { type: \"vec3<f32>\", vsOut: true },\r\n Vec4: { type: \"vec4<f32>\", vsOut: true },\r\n\r\n }"
},
{
"objectType": "property",
"name": "vertexDebug",
"type": "{ Float: (instanceId?: number, vertexId?: number) => { vertexId: number; instanceId: number; type: string; __debug: boolean; }; Vec2: (instanceId?: number, vertexId?: number) => { vertexId: number; instanceId: number; type: string; __debug: boolean; }; ... 15 more ...; Matrix4x4Array: (len?: number, instanceId?: num...",
"visibility": "public",
"rawText": "public static vertexDebug = {\r\n\r\n Float: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"f32\", __debug: true }\r\n },\r\n Vec2: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec2<f32>\", __debug: true }\r\n },\r\n Vec3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec3<f32>\", __debug: true }\r\n },\r\n Vec4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec4<f32>\", __debug: true }\r\n },\r\n Int: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"i32\", __debug: true }\r\n },\r\n IVec2: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec2<i32>\", __debug: true }\r\n },\r\n IVec3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec3<i32>\", __debug: true }\r\n },\r\n IVec4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec4<i32>\", __debug: true }\r\n },\r\n Uint: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"uint\", __debug: true }\r\n },\r\n UVec2: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec2<u32>\", __debug: true }\r\n },\r\n UVec3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec3<u32>\", __debug: true }\r\n },\r\n UVec4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec4<uf32>\", __debug: true }\r\n },\r\n Matrix3x3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"mat3x3<f32>\", __debug: true }\r\n },\r\n Matrix4x4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"mat4x4<f32>\", __debug: true }\r\n },\r\n\r\n Vec4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<vec4<f32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"f32\" }\r\n },\r\n IVec4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<vec4<i32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"i32\" }\r\n },\r\n UVec4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<vec4<u32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"u32\" }\r\n },\r\n Matrix4x4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<mat4x4<f32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"mat4\" }\r\n }\r\n }"
},
{
"objectType": "property",
"name": "fragmentInputs",
"type": "{ frontFacing: { builtin: string; type: string; }; fragDepth: { builtin: string; type: string; }; sampleIndex: { builtin: string; type: string; }; sampleMask: { builtin: string; type: string; }; }",
"visibility": "public",
"rawText": "public static fragmentInputs = {\r\n frontFacing: { builtin: \"@builtin(front_facing)\", type: \"bool\" },\r\n fragDepth: { builtin: \"@builtin(frag_depth)\", type: \"f32\" },\r\n sampleIndex: { builtin: \"@builtin(sample_index)\", type: \"u32\" },\r\n sampleMask: { builtin: \"@builtin(sample_mask)\", type: \"u32\" },\r\n }"
},
{
"objectType": "property",
"name": "fragmentOutputs",
"type": "{ color: { builtin: string; type: string; }; }",
"visibility": "public",
"rawText": "public static fragmentOutputs = {\r\n color: { builtin: \"@location(0)\", type: \"vec4<f32>\" }\r\n }"
},
{
"objectType": "property",
"name": "computeInputs",
"type": "{ localInvocationId: { builtin: string; type: string; }; localInvocationIndex: { builtin: string; type: string; }; globalInvocationId: { builtin: string; type: string; }; workgroupId: { builtin: string; type: string; }; numWorkgroup: { ...; }; }",
"visibility": "public",
"rawText": "public static computeInputs = {\r\n localInvocationId: { builtin: \"@builtin(local_invocation_id)\", type: \"vec3<u32>\" },\r\n localInvocationIndex: { builtin: \"@builtin(local_invocation_index)\", type: \"u32\" },\r\n globalInvocationId: { builtin: \"@builtin(global_invocation_id)\", type: \"vec3<u32>\" },\r\n workgroupId: { builtin: \"@builtin(workgroup_id)\", type: \"vec3<u32>\" },\r\n numWorkgroup: { builtin: \"@builtin(num_workgroup)\", type: \"vec3<u32>\" },\r\n }"
},
{
"objectType": "property",
"name": "computeOutputs",
"type": "{ result: { builtin: string; type: string; }; }",
"visibility": "public",
"rawText": "public static computeOutputs = {\r\n result: { builtin: \"@location(0)\", type: \"???\" }\r\n }"
}
]
},
"methods": {
"public": [
{
"objectType": "method",
"name": "__initDebug",
"returnType": "void",
"visibility": "public",
"rawText": "public static __initDebug() {\r\n let o: any;\r\n\r\n /*\r\n I set the value directly to the function in order to be able to write \r\n BuiltIns.vertexDebug.Float //=> implicit {vertexId:0,instanceId:0}\r\n and BuiltIns.vertexDebug.Float(vertexId,instanceId)\r\n */\r\n\r\n for (let z in this.vertexDebug) {\r\n o = this.vertexDebug[z]();\r\n this.vertexDebug[z].isArray = !!o.isArray;\r\n this.vertexDebug[z].len = o.len;\r\n this.vertexDebug[z].primitiveType = o.primitiveType;\r\n this.vertexDebug[z].type = o.type;\r\n this.vertexDebug[z].__debug = true;\r\n }\r\n\r\n }"
}
]
}
},
"rawText": "export class BuiltIns {\r\n\r\n public static vertexInputs = {\r\n vertexIndex: { builtin: \"@builtin(vertex_index)\", type: \"u32\" },\r\n instanceIndex: { builtin: \"@builtin(instance_index)\", type: \"u32\" },\r\n }\r\n\r\n public static vertexOutputs = {\r\n position: { builtin: \"@builtin(position)\", type: \"vec4<f32>\" },\r\n Float: { type: \"f32\", vsOut: true },\r\n Vec2: { type: \"vec2<f32>\", vsOut: true },\r\n Vec3: { type: \"vec3<f32>\", vsOut: true },\r\n Vec4: { type: \"vec4<f32>\", vsOut: true },\r\n\r\n }\r\n\r\n\r\n\r\n public static vertexDebug = {\r\n\r\n Float: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"f32\", __debug: true }\r\n },\r\n Vec2: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec2<f32>\", __debug: true }\r\n },\r\n Vec3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec3<f32>\", __debug: true }\r\n },\r\n Vec4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec4<f32>\", __debug: true }\r\n },\r\n Int: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"i32\", __debug: true }\r\n },\r\n IVec2: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec2<i32>\", __debug: true }\r\n },\r\n IVec3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec3<i32>\", __debug: true }\r\n },\r\n IVec4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec4<i32>\", __debug: true }\r\n },\r\n Uint: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"uint\", __debug: true }\r\n },\r\n UVec2: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec2<u32>\", __debug: true }\r\n },\r\n UVec3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec3<u32>\", __debug: true }\r\n },\r\n UVec4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"vec4<uf32>\", __debug: true }\r\n },\r\n Matrix3x3: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"mat3x3<f32>\", __debug: true }\r\n },\r\n Matrix4x4: (instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"mat4x4<f32>\", __debug: true }\r\n },\r\n\r\n Vec4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<vec4<f32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"f32\" }\r\n },\r\n IVec4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<vec4<i32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"i32\" }\r\n },\r\n UVec4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<vec4<u32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"u32\" }\r\n },\r\n Matrix4x4Array: (len: number = 1, instanceId: number = 0, vertexId: number = 0) => {\r\n return { vertexId, instanceId, type: \"array<mat4x4<f32>,\" + len + \">\", __debug: true, len, isArray: true, primitiveType: \"mat4\" }\r\n }\r\n }\r\n\r\n public static __initDebug() {\r\n let o: any;\r\n\r\n /*\r\n I set the value directly to the function in order to be able to write \r\n BuiltIns.vertexDebug.Float //=> implicit {vertexId:0,instanceId:0}\r\n and BuiltIns.vertexDebug.Float(vertexId,instanceId)\r\n */\r\n\r\n for (let z in this.vertexDebug) {\r\n o = this.vertexDebug[z]();\r\n this.vertexDebug[z].isArray = !!o.isArray;\r\n this.vertexDebug[z].len = o.len;\r\n this.vertexDebug[z].primitiveType = o.primitiveType;\r\n this.vertexDebug[z].type = o.type;\r\n this.vertexDebug[z].__debug = true;\r\n }\r\n\r\n }\r\n\r\n\r\n //----\r\n\r\n public static fragmentInputs = {\r\n frontFacing: { builtin: \"@builtin(front_facing)\", type: \"bool\" },\r\n fragDepth: { builtin: \"@builtin(frag_depth)\", type: \"f32\" },\r\n sampleIndex: { builtin: \"@builtin(sample_index)\", type: \"u32\" },\r\n sampleMask: { builtin: \"@builtin(sample_mask)\", type: \"u32\" },\r\n }\r\n\r\n public static fragmentOutputs = {\r\n color: { builtin: \"@location(0)\", type: \"vec4<f32>\" }\r\n }\r\n\r\n //----\r\n\r\n public static computeInputs = {\r\n localInvocationId: { builtin: \"@builtin(local_invocation_id)\", type: \"vec3<u32>\" },\r\n localInvocationIndex: { builtin: \"@builtin(local_invocation_index)\", type: \"u32\" },\r\n globalInvocationId: { builtin: \"@builtin(global_invocation_id)\", type: \"vec3<u32>\" },\r\n workgroupId: { builtin: \"@builtin(workgroup_id)\", type: \"vec3<u32>\" },\r\n numWorkgroup: { builtin: \"@builtin(num_workgroup)\", type: \"vec3<u32>\" },\r\n }\r\n\r\n public static computeOutputs = {\r\n result: { builtin: \"@location(0)\", type: \"???\" }\r\n }\r\n}"
},
{
"objectType": "type",
"name": "BuiltIns_vertexInputs",
"type": "{ vertexIndex: { builtin: string; type: string; }; instanceIndex: { builtin: string; type: string; }; }",
"rawText": "type BuiltIns_vertexInputs = typeof BuiltIns.vertexInputs;"
},
{
"objectType": "type",
"name": "BuiltIns_vertexOutputs",
"type": "{ position: { builtin: string; type: string; }; Float: { type: string; vsOut: boolean; }; Vec2: { type: string; vsOut: boolean; }; Vec3: { type: string; vsOut: boolean; }; Vec4: { type: string; vsOut: boolean; }; }",
"rawText": "type BuiltIns_vertexOutputs = typeof BuiltIns.vertexOutputs;"
},
{
"objectType": "type",
"name": "BuiltIns_fragmentInputs",
"type": "{ frontFacing: { builtin: string; type: string; }; fragDepth: { builtin: string; type: string; }; sampleIndex: { builtin: string; type: string; }; sampleMask: { builtin: string; type: string; }; }",
"rawText": "type BuiltIns_fragmentInputs = typeof BuiltIns.fragmentInputs;"
},
{
"objectType": "type",
"name": "BuiltIns_fragmentOutputs",
"type": "{ color: { builtin: string; type: string; }; }",
"rawText": "type BuiltIns_fragmentOutputs = typeof BuiltIns.fragmentOutputs;"
},
{
"objectType": "type",
"name": "BuiltIns_computeInputs",
"type": "{ localInvocationId: { builtin: string; type: string; }; localInvocationIndex: { builtin: string; type: string; }; globalInvocationId: { builtin: string; type: string; }; workgroupId: { builtin: string; type: string; }; numWorkgroup: { ...; }; }",
"rawText": "type BuiltIns_computeInputs = typeof BuiltIns.computeInputs;"
},
{
"objectType": "type",
"name": "BuiltIns_computeOutputs",
"type": "{ result: { builtin: string; type: string; }; }",
"rawText": "type BuiltIns_computeOutputs = typeof BuiltIns.computeOutputs;"
},
{
"objectType": "type",
"name": "VertexShaderInput",
"type": "VertexShaderInput",
"rawText": "export type VertexShaderInput = (\r\n BuiltIns_vertexInputs[\"vertexIndex\"] |\r\n BuiltIns_vertexInputs[\"instanceIndex\"]\r\n);"
},
{
"objectType": "type",
"name": "VertexShaderOutput",
"type": "VertexShaderOutput",
"rawText": "export type VertexShaderOutput = (\r\n BuiltIns_vertexOutputs[\"position\"] |\r\n BuiltIns_vertexOutputs[\"Float\"] |\r\n BuiltIns_vertexOutputs[\"Vec2\"] |\r\n BuiltIns_vertexOutputs[\"Vec3\"] |\r\n BuiltIns_vertexOutputs[\"Vec4\"] /*|\r\n BuiltIns_vertexOutputs[\"Int\"] |\r\n BuiltIns_vertexOutputs[\"IVec2\"] |\r\n BuiltIns_vertexOutputs[\"IVec3\"] |\r\n BuiltIns_vertexOutputs[\"IVec4\"] |\r\n BuiltIns_vertexOutputs[\"Uint\"] |\r\n BuiltIns_vertexOutputs[\"UVec2\"] |\r\n BuiltIns_vertexOutputs[\"UVec3\"] |\r\n BuiltIns_vertexOutputs[\"UVec4\"]*/\r\n);"
},
{
"objectType": "type",
"name": "FragmentShaderInput",
"type": "FragmentShaderInput",
"rawText": "export type FragmentShaderInput = (\r\n BuiltIns_fragmentInputs[\"frontFacing\"] |\r\n BuiltIns_fragmentInputs[\"fragDepth\"] |\r\n BuiltIns_fragmentInputs[\"sampleIndex\"] |\r\n BuiltIns_fragmentInputs[\"sampleMask\"]\r\n);"
},
{
"objectType": "type",
"name": "FragmentShaderOutputs",
"type": "{ builtin: string; type: string; }",
"rawText": "export type FragmentShaderOutputs = BuiltIns_fragmentOutputs[\"color\"];"
},
{
"objectType": "type",
"name": "ComputeShaderInput",
"type": "ComputeShaderInput",
"rawText": "export type ComputeShaderInput = (\r\n BuiltIns_computeInputs[\"localInvocationId\"] |\r\n BuiltIns_computeInputs[\"localInvocationIndex\"] |\r\n BuiltIns_computeInputs[\"globalInvocationId\"] |\r\n BuiltIns_computeInputs[\"workgroupId\"] |\r\n BuiltIns_computeInputs[\"numWorkgroup\"]\r\n);"
},
{
"objectType": "type",
"name": "ComputeShaderOutputs",
"type": "{ builtin: string; type: string; }",
"rawText": "export type ComputeShaderOutputs = BuiltIns_computeOutputs[\"result\"];"
}
],
"EventDispatcher": [
{
"objectType": "class",
"name": "EventDispatcher",
"filePath": "xGPU.EventDispatcher",
"properties": {
"protected": [
{
"objectType": "property",
"name": "eventListeners",
"type": "any",
"visibility": "protected",
"rawText": "protected eventListeners: any = {};"
}
]
},
"methods": {
"public": [
{
"objectType": "method",
"name": "addEventListener",
"returnType": "void",
"params": [
{
"name": "eventName",
"type": "string"
},
{
"name": "callback",
"type": "(data?: any) => void"
},
{
"name": "removeListenerAfterDispatch",
"type": "boolean"
}
],
"visibility": "public",
"rawText": "public addEventListener(eventName: string, callback: ( data?: any) => void, removeListenerAfterDispatch: boolean = false) {\r\n if (!this.eventListeners[eventName]) this.eventListeners[eventName] = [];\r\n if (removeListenerAfterDispatch) (callback as any).removeAfter = true;\r\n this.eventListeners[eventName].push(callback);\r\n }"
},
{
"objectType": "method",
"name": "removeEventListener",
"returnType": "void",
"params": [
{
"name": "eventName",
"type": "string"
},
{
"name": "callback",
"type": "(dispatcher: EventDispatcher, data?: any) => void"
}
],
"visibility": "public",
"rawText": "public removeEventListener(eventName: string, callback: (dispatcher: EventDispatcher, data?: any) => void) {\r\n if (this.eventListeners[eventName]) {\r\n const id = this.eventListeners[eventName].indexOf(callback);\r\n if (id != -1) {\r\n this.eventListeners[eventName].splice(id, 1);\r\n }\r\n }\r\n }"
},
{
"objectType": "method",
"name": "clearEvents",
"returnType": "void",
"params": [
{
"name": "eventName",
"type": "any"
}
],
"visibility": "public",
"rawText": "public clearEvents(eventName) {\r\n this.addEventListener[eventName] = [];\r\n }"
},
{
"objectType": "method",
"name": "hasEventListener",
"returnType": "boolean",
"params": [
{
"name": "eventName",
"type": "any"
}
],
"visibility": "public",
"rawText": "public hasEventListener(eventName): boolean { return !!this.eventListeners[eventName] }"
},
{
"objectType": "method",
"name": "dispatchEvent",
"returnType": "void",
"params": [
{
"name": "eventName",
"type": "string"
},
{
"name": "eventData",
"type": "any"
}
],
"visibility": "public",
"rawText": "public dispatchEvent(eventName: string, eventData?: any) {\r\n if (this.eventListeners[eventName]) {\r\n\r\n const t = [...this.eventListeners[eventName]];\r\n t.forEach(callback => {\r\n callback( eventData);\r\n if ((callback as any).removeAfter) this.removeEventListener(eventName, callback);\r\n });\r\n }\r\n }"
}
]
},
"constructor": {
"objectType": "constructor",
"name": "constructor",
"rawText": "constructor() {\r\n\r\n }"
},
"rawText": "export class EventDispatcher {\r\n\r\n protected eventListeners: any = {};\r\n\r\n constructor() {\r\n\r\n }\r\n\r\n public addEventListener(eventName: string, callback: ( data?: any) => void, removeListenerAfterDispatch: boolean = false) {\r\n if (!this.eventListeners[eventName]) this.eventListeners[eventName] = [];\r\n if (removeListenerAfterDispatch) (callback as any).removeAfter = true;\r\n this.eventListeners[eventName].push(callback);\r\n }\r\n public removeEventListener(eventName: string, callback: (dispatcher: EventDispatcher, data?: any) => void) {\r\n if (this.eventListeners[eventName]) {\r\n const id = this.eventListeners[eventName].indexOf(callback);\r\n if (id != -1) {\r\n this.eventListeners[eventName].splice(id, 1);\r\n }\r\n }\r\n }\r\n public clearEvents(eventName) {\r\n this.addEventListener[eventName] = [];\r\n }\r\n public hasEventListener(eventName): boolean { return !!this.eventListeners[eventName] }\r\n\r\n public dispatchEvent(eventName: string, eventData?: any) {\r\n if (this.eventListeners[eventName]) {\r\n\r\n const t = [...this.eventListeners[eventName]];\r\n t.forEach(callback => {\r\n callback( eventData);\r\n if ((callback as any).removeAfter) this.removeEventListener(eventName, callback);\r\n });\r\n }\r\n }\r\n}"
}
],
"GPURenderer": [
{
"objectType": "class",
"name": "GPURenderer",
"filePath": "xGPU.GPURenderer",
"extends": [
"EventDispatcher"
],
"implements": [
"IRenderer"
],
"properties": {
"public": [
{
"objectType": "property",
"name": "frameId",
"type": "number",
"visibility": "public",
"rawText": "public frameId: number = 0;"
},
{
"objectType": "property",
"name": "renderPipelines",
"type": "RenderPipeline[]",
"visibility": "public",
"rawText": "public renderPipelines: RenderPipeline[] = [];"
},
{
"objectType": "property",
"name": "resized",
"type": "boolean",
"visibility": "public",
"rawText": "public get resized(): boolean { return this.dimensionChanged; }",
"get": true
},
{
"objectType": "property",
"name": "firstPipeline",
"type": "RenderPipeline",
"visibility": "public",
"rawText": "public get firstPipeline(): RenderPipeline { return this.renderPipelines[0]; }",
"get": true
},
{
"objectType": "property",
"name": "texture",
"type": "GPUTexture",
"visibility": "public",
"rawText": "public get texture(): GPUTexture { return this.ctx.getCurrentTexture() }",
"get": true
},
{
"objectType": "property",
"name": "view",
"type": "GPUTextureView",
"visibility": "public",
"rawText": "public get view(): GPUTextureView { return this.ctx.getCurrentTexture().createView(); }",
"get": true
},
{
"objectType": "property",
"name": "width",
"type": "number",
"visibility": "public",
"rawText": "public get width(): number { return this.domElement.width }",
"get": true
},
{
"objectType": "property",
"name": "height",
"type": "number",
"visibility": "public",
"rawText": "public get height(): number { return this.domElement.height }",
"get": true
},
{
"objectType": "property",
"name": "canvas",
"type": "HTMLCanvasElement",
"visibility": "public",
"rawText": "public get canvas(): HTMLCanvasElement { return this.domElement }",
"get": true
},
{
"objectType": "property",
"name": "nbPipeline",
"type": "number",
"visibility": "public",
"rawText": "public get nbPipeline(): number { return this.renderPipelines.length }",
"get": true
},
{
"objectType": "property",
"name": "useSinglePipeline",
"type": "boolean",
"visibility": "public",
"rawText": "public get useSinglePipeline(): boolean { return this.nbColorAttachment === 1 }",
"get": true
},
{
"objectType": "property",
"name": "commandEncoder",
"type": "GPUCommandEncoder",
"visibility": "public",
"rawText": "public commandEncoder: GPUCommandEncoder = null;"
}
],
"protected": [
{
"objectType": "property",
"name": "domElement",
"type": "HTMLCanvasElement",
"visibility": "protected",
"rawText": "protected domElement: HTMLCanvasElement;"
},
{
"objectType": "property",
"name": "canvasView",
"type": "GPUTextureView",
"visibility": "protected",
"rawText": "protected canvasView: GPUTextureView;"
},
{
"objectType": "property",
"name": "ctx",
"type": "GPUCanvasContext",
"visibility": "protected",
"rawText": "protected ctx: GPUCanvasContext;"
},
{
"objectType": "property",
"name": "currentWidth",
"type": "number",
"visibility": "protected",
"rawText": "protected currentWidth: number;"
},
{
"objectType": "property",
"name": "currentHeight",
"type": "number",
"visibility": "protected",
"rawText": "protected currentHeight: number;"
},
{
"objectType": "property",
"name": "dimensionChanged",
"type": "boolean",
"visibility": "protected",
"rawText": "protected dimensionChanged: boolean = false;"
},
{
"objectType": "property",
"name": "deviceId",
"type": "number",
"visibility": "protected",
"rawText": "protected deviceId: number;"
},
{
"objectType": "property",
"name": "nbColorAttachment",
"type": "number",
"visibility": "protected",
"rawText": "protected nbColorAttachment: number = 0;"
},
{
"objectType": "property",
"name": "gpuCtxConfiguration",
"type": "any",
"visibility": "protected",
"rawText": "protected gpuCtxConfiguration: any;"
}
]
},
"methods": {
"public": [
{
"objectType": "method",
"name": "resize",
"returnType": "void",
"params": [
{
"name": "w",
"type": "number"
},
{
"name": "h",
"type": "number"
}
],
"visibility": "public",
"rawText": "public resize(w: number, h: number) {\r\n this.domElement.width = w;\r\n this.domElement.height = h;\r\n this.dimensionChanged = true;\r\n\r\n }"
},
{
"objectType": "method",
"name": "destroy",
"returnType": "void",
"visibility": "public",
"rawText": "public destroy(): void {\r\n for (let i = 0; i < this.renderPipelines.length; i++) {\r\n this.renderPipelines[i].destroy();\r\n }\r\n this.renderPipelines = [];\r\n for (let z in this) {\r\n this[z] = null;\r\n }\r\n }"
},
{
"objectType": "method",
"name": "initCanvas",
"returnType": "Promise<HTMLCanvasElement>",
"params": [
{
"name": "canvas",
"type": "HTMLCanvasElement"
},
{
"name": "alphaMode",
"type": "\"opaque\" | \"premultiplied\""
}
],
"visibility": "public",
"rawText": "public initCanvas(canvas: HTMLCanvasElement, alphaMode: \"opaque\" | \"premultiplied\" = \"opaque\"): Promise<HTMLCanvasElement> {\r\n\r\n this.domElement = canvas;\r\n\r\n\r\n return new Promise(async (resolve: (e: HTMLCanvasElement) => void, error: (e: unknown) => void) => {\r\n await XGPU.init()\r\n this.deviceId = XGPU.deviceId;\r\n if (this.domElement == null) return\r\n\r\n this.currentWidth = this.domElement.width;\r\n this.currentHeight = this.domElement.height;\r\n\r\n try {\r\n this.gpuCtxConfiguration = {\r\n device: XGPU.device,\r\n format: XGPU.getPreferredCanvasFormat(),\r\n alphaMode: alphaMode,\r\n colorSpace: \"srgb\",\r\n usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC | GPUTextureUsage.TEXTURE_BINDING,\r\n };\r\n this.ctx = this.domElement.getContext(\"webgpu\");\r\n this.ctx.configure(this.gpuCtxConfiguration)\r\n\r\n resolve(canvas)\r\n } catch (e) {\r\n error(e)\r\n }\r\n\r\n })\r\n }"
},
{
"objectType": "method",
"name": "addPipeline",
"returnType": "RenderPipeline",
"params": [
{
"name": "pipeline",
"type": "RenderPipeline"
},
{
"name": "offset",
"type": "number"
}
],
"visibility": "public",
"rawText": "public addPipeline(pipeline: RenderPipeline, offset: number = null): RenderPipeline {\r\n\r\n pipeline.renderer = this;\r\n if (pipeline.renderPassDescriptor.colorAttachments[0]) this.nbColorAttachment++;\r\n\r\n if (offset === null) this.renderPipelines.push(pipeline);\r\n else this.renderPipelines.splice(offset, 0, pipeline)\r\n\r\n return pipeline;\r\n }"
},
{
"objectType": "method",
"name": "removePipeline",
"returnType": "RenderPipeline",
"params": [
{
"name": "pipeline",
"type": "RenderPipeline"
}
],
"visibility": "public",
"rawText": "public removePipeline(pipeline: RenderPipeline) {\r\n if (pipeline.renderPassDescriptor.colorAttachments[0]) this.nbColorAttachment--;\r\n const id = this.renderPipelines.indexOf(pipeline);\r\n if (id != -1) {\r\n this.renderPipelines.splice(id, 1);\r\n }\r\n pipeline.renderer = null;\r\n return pipeline;\r\n }"
},
{
"objectType": "method",
"name": "configure",
"returnType": "void",
"params": [
{
"name": "textureUsage",
"type": "GPUTextureUsageFlags"
},
{
"name": "alphaMode",
"type": "\"opaque\" | \"premultiplied\""
}
],
"visibility": "public",
"rawText": "public configure(textureUsage: GPUTextureUsageFlags = GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC | GPUTextureUsage.TEXTURE_BINDING, alphaMode: \"opaque\" | \"premultiplied\" = \"opaque\") {\r\n\r\n this.gpuCtxConfiguration = {\r\n device: XGPU.device,\r\n format: XGPU.getPreferredCanvasFormat(),\r\n alphaMode: alphaMode,\r\n colorSpace: \"srgb\",\r\n usage: textureUsage\r\n };\r\n\r\n this.ctx.configure(this.gpuCtxConfiguration)\r\n }"
},
{
"objectType": "method",
"name": "update",
"returnType": "Promise<void>",
"visibility": "public",
"rawText": "public async update() {\r\n if (!this.ctx) return;\r\n if (!XGPU.ready || this.renderPipelines.length === 0 || this.deviceId === undefined) return;\r\n\r\n\r\n if (XGPU.deviceId != this.deviceId) {\r\n this.ctx.configure({ ...this.gpuCtxConfiguration, device: XGPU.device })\r\n }\r\n\r\n if (this.canvas.width != this.currentWidth || this.canvas.height != this.currentHeight) {\r\n this.currentWidth = this.canvas.width;\r\n this.currentHeight = this.canvas.height;\r\n this.dimensionChanged = true;\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n let deviceChanged: boolean = XGPU.deviceId != this.deviceId;\r\n if (deviceChanged) {\r\n\r\n\r\n this.deviceId = XGPU.deviceId;\r\n for (let i = 0; i < this.renderPipelines.length; i++) {\r\n this.renderPipelines[i].clearAfterDeviceLostAndRebuild();\r\n }\r\n }\r\n\r\n this.commandEncoder = XGPU.device.createCommandEncoder();\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n let pipeline: RenderPipeline, renderPass:GPURenderPassEncoder;\r\n for (let i = 0; i < this.renderPipelines.length; i++) {\r\n pipeline = this.renderPipelines[i];\r\n\r\n pipeline.update();\r\n\r\n\r\n renderPass = pipeline.beginRenderPass(this.commandEncoder, this.view, 0);\r\n \r\n for (let j = 0; j < pipeline.pipelineCount; j++) {\r\n pipeline.dispatchEvent(RenderPipeline.ON_DRAW, j);\r\n pipeline.draw(renderPass);\r\n }\r\n\r\n pipeline.end(this.commandEncoder, renderPass);\r\n\r\n\r\n }\r\n\r\n const commandBuffer = this.commandEncoder.finish();\r\n this.commandEncoder = null;\r\n XGPU.device.queue.submit([commandBuffer]);\r\n\r\n this.dimensionChanged = false;\r\n\r\n\r\n this.dispatchEvent(GPURenderer.ON_DRAW_END);\r\n this.frameId++;\r\n\r\n }"
}
]
},
"statics": {
"properties": {
"public": [
{
"objectType": "property",
"name": "ON_DRAW_END",
"type": "string",
"visibility": "public",
"rawText": "public static ON_DRAW_END: string = \"ON_DRAW_END\";"
}
],
"private": [
{
"objectType": "property",
"name": "texturedQuadPipeline",
"type": "RenderPipeline",
"visibility": "private",
"rawText": "private static texturedQuadPipeline: RenderPipeline;"
}
]
}
},
"constructor": {
"objectType": "constructor",
"name": "constructor",
"rawText": "constructor() {\r\n super();\r\n\r\n if (!GPURenderer.texturedQuadPipeline) {\r\n GPURenderer.texturedQuadPipeline = new RenderPipeline()\r\n GPURenderer.texturedQuadPipeline.initFromObject({\r\n vertexCount: 6,\r\n vertexId: BuiltIns.vertexInputs.vertexIndex,\r\n image: new ImageTexture({ source: null }),\r\n imgSampler: new TextureSampler(),\r\n uv: BuiltIns.vertexOutputs.Vec2,\r\n vertexShader: {\r\n constants: `\r\n const pos = array<vec2<f32>([\r\n vec2(-0.5,-0.5),\r\n vec2(+0.5,-0.5),\r\n vec2(-0.5,+0.5),\r\n vec2(+0.5,-0.5),\r\n vec2(+0.5,+0.5),\r\n vec2(-0.5,+0.5),\r\n ]);\r\n `,\r\n main: `\r\n output.position = vec4(pos[vertexId],0.0,1.0);\r\n output.uv = 0.5 + output.position.xy;\r\n `\r\n },\r\n fragmentShader: `\r\n output.color = textureSample(image,imgSampler,uv);\r\n `,\r\n })\r\n }\r\n\r\n this.texturedQuadPipeline = GPURenderer.texturedQuadPipeline;\r\n\r\n\r\n\r\n\r\n }"
},
"rawText": "export class GPURenderer extends EventDispatcher implements IRenderer {\r\n\r\n\r\n public static ON_DRAW_END: string = \"ON_DRAW_END\";\r\n\r\n\r\n protected domElement: HTMLCanvasElement;\r\n protected canvasView: GPUTextureView;\r\n protected ctx: GPUCanvasContext;\r\n\r\n protected currentWidth: number;\r\n protected currentHeight: number;\r\n protected dimensionChanged: boolean = false;\r\n\r\n protected deviceId: number;\r\n public frameId: number = 0;\r\n protected nbColorAttachment: number = 0;\r\n public renderPipelines: RenderPipeline[] = [];\r\n\r\n\r\n private static texturedQuadPipeline: RenderPipeline;\r\n protected texturedQuadPipeline;\r\n constructor() {\r\n super();\r\n\r\n if (!GPURenderer.texturedQuadPipeline) {\r\n GPURenderer.texturedQuadPipeline = new RenderPipeline()\r\n GPURenderer.texturedQuadPipeline.initFromObject({\r\n vertexCount: 6,\r\n vertexId: BuiltIns.vertexInputs.vertexIndex,\r\n image: new ImageTexture({ source: null }),\r\n imgSampler: new TextureSampler(),\r\n uv: BuiltIns.vertexOutputs.Vec2,\r\n vertexShader: {\r\n constants: `\r\n const pos = array<vec2<f32>([\r\n vec2(-0.5,-0.5),\r\n vec2(+0.5,-0.5),\r\n vec2(-0.5,+0.5),\r\n vec2(+0.5,-0.5),\r\n vec2(+0.5,+0.5),\r\n vec2(-0.5,+0.5),\r\n ]);\r\n `,\r\n main: `\r\n output.position = vec4(pos[vertexId],0.0,1.0);\r\n output.uv = 0.5 + output.position.xy;\r\n `\r\n },\r\n fragmentShader: `\r\n output.color = textureSample(image,imgSampler,uv);\r\n `,\r\n })\r\n }\r\n\r\n this.texturedQuadPipeline = GPURenderer.texturedQuadPipeline;\r\n\r\n\r\n\r\n\r\n }\r\n\r\n public resize(w: number, h: number) {\r\n this.domElement.width = w;\r\n this.domElement.height = h;\r\n this.dimensionChanged = true;\r\n\r\n }\r\n\r\n public destroy(): void {\r\n for (let i = 0; i < this.renderPipelines.length; i++) {\r\n this.renderPipelines[i].destroy();\r\n }\r\n this.renderPipelines = [];\r\n for (let z in this) {\r\n this[z] = null;\r\n }\r\n }\r\n\r\n protected gpuCtxConfiguration: any;\r\n public initCanvas(canvas: HTMLCanvasElement, alphaMode: \"opaque\" | \"premultiplied\" = \"opaque\"): Promise<HTMLCanvasElement> {\r\n\r\n this.domElement = canvas;\r\n\r\n\r\n return new Promise(async (resolve: (e: HTMLCanvasElement) => void, error: (e: unknown) => void) => {\r\n await XGPU.init()\r\n this.deviceId = XGPU.deviceId;\r\n if (this.domElement == null) return\r\n\r\n this.currentWidth = this.domElement.width;\r\n this.currentHeight = this.domElement.height;\r\n\r\n try {\r\n this.gpuCtxConfiguration = {\r\n device: XGPU.device,\r\n format: XGPU.getPreferredCanvasFormat(),\r\n alphaMode: alphaMode,\r\n colorSpace: \"srgb\",\r\n usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC | GPUTextureUsage.TEXTURE_BINDING,\r\n };\r\n this.ctx = this.domElement.getContext(\"webgpu\");\r\n this.ctx.configure(this.gpuCtxConfiguration)\r\n\r\n resolve(canvas)\r\n } catch (e) {\r\n error(e)\r\n }\r\n\r\n })\r\n }\r\n\r\n\r\n\r\n public get resized(): boolean { return this.dimensionChanged; }\r\n public get firstPipeline(): RenderPipeline { return this.renderPipelines[0]; }\r\n public get texture(): GPUTexture { return this.ctx.getCurrentTexture() }\r\n public get view(): GPUTextureView { return this.ctx.getCurrentTexture().createView(); }\r\n\r\n public get width(): number { return this.domElement.width }\r\n public get height(): number { return this.domElement.height }\r\n public get canvas(): HTMLCanvasElement { return this.domElement }\r\n public addPipeline(pipeline: RenderPipeline, offset: number = null): RenderPipeline {\r\n\r\n pipeline.renderer = this;\r\n if (pipeline.renderPassDescriptor.colorAttachments[0]) this.nbColorAttachment++;\r\n\r\n if (offset === null) this.renderPipelines.push(pipeline);\r\n else this.renderPipelines.splice(offset, 0, pipeline)\r\n\r\n return pipeline;\r\n }\r\n\r\n public removePipeline(pipeline: RenderPipeline) {\r\n if (pipeline.renderPassDescriptor.colorAttachments[0]) this.nbColorAttachment--;\r\n const id = this.renderPipelines.indexOf(pipeline);\r\n if (id != -1) {\r\n this.renderPipelines.splice(id, 1);\r\n }\r\n pipeline.renderer = null;\r\n return pipeline;\r\n }\r\n public get nbPipeline(): number { return this.renderPipelines.length }\r\n public get useSinglePipeline(): boolean { return this.nbColorAttachment === 1 }\r\n\r\n public configure(textureUsage: GPUTextureUsageFlags = GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC | GPUTextureUsage.TEXTURE_BINDING, alphaMode: \"opaque\" | \"premultiplied\" = \"opaque\") {\r\n\r\n this.gpuCtxConfiguration = {\r\n device: XGPU.device,\r\n format: XGPU.getPreferredCanvasFormat(),\r\n alphaMode: alphaMode,\r\n colorSpace: \"srgb\",\r\n usage: textureUsage\r\n };\r\n\r\n this.ctx.configure(this.gpuCtxConfiguration)\r\n }\r\n\r\n\r\n\r\n public commandEncoder: GPUCommandEncoder = null;\r\n\r\n public async update() {\r\n if (!this.ctx) return;\r\n if (!XGPU.ready || this.renderPipelines.length === 0 || this.deviceId === undefined) return;\r\n\r\n\r\n if (XGPU.deviceId != this.deviceId) {\r\n this.ctx.configure({ ...this.gpuCtxConfiguration, device: XGPU.device })\r\n }\r\n\r\n if (this.canvas.width != this.currentWidth || this.canvas.height != this.currentHeight) {\r\n this.currentWidth = this.canvas.width;\r\n this.currentHeight = this.canvas.height;\r\n this.dimensionChanged = true;\r\n }\r\n\r\n\r\n\r\n\r\n\r\n\r\n let deviceChanged: boolean = XGPU.deviceId != this.deviceId;\r\n if (deviceChanged) {\r\n\r\n\r\n this.deviceId = XGPU.deviceId;\r\n for (let i = 0; i < this.renderPipelines.length; i++) {\r\n this.renderPipelines[i].clearAfterDeviceLostAndRebuild();\r\n }\r\n }\r\n\r\n this.commandEncoder = XGPU.device.createCommandEncoder();\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n let pipeline: RenderPipeline, renderPass:GPURenderPassEncoder;\r\n for (let i = 0; i < this.renderPipelines.length; i++) {\r\n pipeline = this.renderPipelines[i];\r\n\r\n pipeline.update();\r\n\r\n\r\n renderPass = pipeline.beginRenderPass(this.commandEncoder, this.view, 0);\r\n \r\n for (let j = 0; j < pipeline.pipelineCount; j++) {\r\n pipeline.dispatchEvent(RenderPipeline.ON_DRAW, j);\r\n pipeline.draw(renderPass);\r\n }\r\n\r\n pipeline.end(this.commandEncoder, renderPass);\r\n\r\n\r\n }\r\n\r\n const commandBuffer = this.commandEncoder.finish();\r\n this.commandEncoder = null;\r\n XGPU.device.queue.submit([commandBuffer]);\r\n\r\n this.dimensionChanged = false;\r\n\r\n\r\n this.dispatchEvent(GPURenderer.ON_DRAW_END);\r\n this.frameId++;\r\n\r\n }\r\n\r\n}"
}
],
"GPUType": [
{
"objectType": "class",
"name": "GPUType",
"filePath": "xGPU.GPUType",
"properties": {
"public": [
{
"objectType": "property",
"name": "isPrimitive",
"type": "boolean",
"visibility": "public",
"rawText": "public get isPrimitive(): boolean { return !this._isVector && !this._isArray && !this._isMatrix }",
"get": true
},
{
"objectType": "property",
"name": "isVector",
"type": "boolean",
"visibility": "public",
"rawText": "public get isVector(): boolean { return this._isVector && !this._isArray && !this._isMatrix }",
"get": true
},
{
"objectType": "property"