diff --git a/src/construct/domain_layer/dependency/container/DpContainer.re b/src/construct/domain_layer/dependency/container/DpContainer.re index 8abd3fef70..e8d98bb70c 100644 --- a/src/construct/domain_layer/dependency/container/DpContainer.re +++ b/src/construct/domain_layer/dependency/container/DpContainer.re @@ -3,9 +3,21 @@ type t = { mutable poConfig: option(IConfigDp.poConfig), mutable repo: option(IRepoDp.repo), mutable time: option(ITimeDp.time), + mutable webgpuCore: option(IWebGPUCoreDp.webgpuCore), + mutable webgpuRayTracing: option(IWebGPURayTracingDp.webgpuRayTracing), + // mutable network: option(INetworkDp.network), }; -let dpContainer = {otherConfig: None, poConfig: None, repo: None, time: None}; +let dpContainer = { + otherConfig: None, + poConfig: None, + repo: None, + time: None, + + webgpuCore: None, + webgpuRayTracing: None, + // network: None, +}; let unsafeGetOtherConfigDp = () => { dpContainer.otherConfig->OptionSt.unsafeGet; @@ -90,3 +102,33 @@ let setTimeDp = dp => { (); }; + +let unsafeGetWebGPUCoreDp = () => { + dpContainer.webgpuCore->OptionSt.unsafeGet; +}; + +let setWebGPUCoreDp = dp => { + dpContainer.webgpuCore = dp->Some; + + (); +}; + +let unsafeGetWebGPURayTracingDp = () => { + dpContainer.webgpuRayTracing->OptionSt.unsafeGet; +}; + +let setWebGPURayTracingDp = dp => { + dpContainer.webgpuRayTracing = dp->Some; + + (); +}; + +// let unsafeGetNetworkDp = () => { +// dpContainer.network->OptionSt.unsafeGet; +// }; + +// let setNetworkDp = dp => { +// dpContainer.network = dp->Some; + +// (); +// }; diff --git a/src/construct/domain_layer/dependency/interface/IWebGPUCoreDp.re b/src/construct/domain_layer/dependency/interface/IWebGPUCoreDp.re new file mode 100644 index 0000000000..e8e98b6c69 --- /dev/null +++ b/src/construct/domain_layer/dependency/interface/IWebGPUCoreDp.re @@ -0,0 +1,499 @@ +type gpuObject; + +type adapterObject; + +type windowObject; + +type deviceObject; + +type contextObject; + +type swapChainObject; + +type queueObject; + +type shaderModuleObject; + +type renderPipelineObject; + +type computePipelineObject; + +type bindGroupLayoutObject; + +type pipelineLayoutObject; + +type bufferUsageObject = int; + +type bufferObject; + +type shaderStageObject = int; + +type bindGroupObject; + +// type accelerationContainerObject; + +type samplerObject; + +type textureViewObject; + +type pipelineRenderObject; + +type pipelineComputeObject; + +type commandEncoderObject; + +type textureUsageObject = int; + +type textureObject; + +type commandBufferObject; + +type textureFormat = string; + +[@bs.deriving abstract] +type adapterDescriptor = { + window: windowObject, + [@bs.optional] + preferredBackend: string, +}; + +type windowDescriptor = { + . + "width": int, + "height": int, + "title": string, + "resizable": bool, +}; + +type swapChainConfig = { + . + "device": deviceObject, + "format": textureFormat, +}; + +type shaderModuleDescriptor = {. "code": string}; + +type pipelineLayoutConfig = { + . + "bindGroupLayouts": array(bindGroupLayoutObject), +}; + +type bufferDescriptor = { + . + "size": int, + "usage": bufferUsageObject, +}; + +type bindingPoint = int; + +[@bs.deriving abstract] +type layoutBinding = { + binding: bindingPoint, + visibility: shaderStageObject, + [@bs.as "type"] + type_: string, + [@bs.optional] + hasDynamicOffset: bool, +}; + +type bindGroupLayoutDescriptor = {. "entries": array(layoutBinding)}; + +[@bs.deriving abstract] +type binding = { + binding: bindingPoint, + [@bs.optional] + buffer: bufferObject, + [@bs.optional] + sampler: samplerObject, + [@bs.optional] + textureView: textureViewObject, + [@bs.optional] + offset: int, + size: int, +}; + +type bindGroupDescriptor = { + . + "layout": bindGroupLayoutObject, + "entries": array(binding), +}; + +[@bs.deriving abstract] +type vertexStage = { + [@bs.as "module"] + module_: shaderModuleObject, + entryPoint: string, +}; + +[@bs.deriving abstract] +type fragmentStage = { + [@bs.as "module"] + module_: shaderModuleObject, + entryPoint: string, +}; + +[@bs.deriving abstract] +type vertexAttribute = { + shaderLocation: int, + offset: int, + format: string, +}; + +[@bs.deriving abstract] +type vertexBuffer = { + arrayStride: int, + [@bs.optional] + stepMode: string, + attributes: array(vertexAttribute), +}; + +[@bs.deriving abstract] +type vertexState = { + indexFormat: string, + [@bs.optional] + vertexBuffers: array(vertexBuffer), +}; + +[@bs.deriving abstract] +type rasterizationState = { + [@bs.optional] + frontFace: string, + [@bs.optional] + cullMode: string, +}; + +[@bs.deriving abstract] +type blendDescriptor = { + [@bs.optional] + srcFactor: string, + [@bs.optional] + dstFactor: string, + [@bs.optional] + operation: string, +}; + +[@bs.deriving abstract] +type colorState = { + format: textureFormat, + alphaBlend: blendDescriptor, + colorBlend: blendDescriptor, +}; + +[@bs.deriving abstract] +type stencilStateFaceDescriptor = { + [@bs.optional] + compare: string, + [@bs.optional] + failOp: string, + [@bs.optional] + depthFailOp: string, + [@bs.optional] + passOp: string, +}; + +[@bs.deriving abstract] +type depthStencilState = { + depthWriteEnabled: bool, + depthCompare: string, + format: string, + stencilFront: stencilStateFaceDescriptor, + stencilBack: stencilStateFaceDescriptor, +}; + +type pipelineLayout; + +[@bs.deriving abstract] +type pipelineRenderDescriptor = { + layout: pipelineLayout, + [@bs.optional] + sampleCount: int, + vertexStage, + fragmentStage, + primitiveTopology: string, + vertexState, + rasterizationState, + colorStates: array(colorState), + [@bs.optional] + depthStencilState, +}; + +[@bs.deriving abstract] +type computeStage = { + [@bs.as "module"] + module_: shaderModuleObject, + entryPoint: string, +}; + +[@bs.deriving abstract] +type pipelineComputeDescriptor = { + layout: pipelineLayout, + computeStage, +}; + +[@bs.deriving abstract] +type commandEncoderDescriptor = { + [@bs.optional] + label: string, +}; + +[@bs.deriving abstract] +type samplerDescriptor = { + magFilter: string, + minFilter: string, + addressModeU: string, + addressModeV: string, + addressModeW: string, +}; + +type extend3D = { + . + "width": int, + "height": int, + "depth": int, +}; + +[@bs.deriving abstract] +type textureDescriptor = { + size: extend3D, + arrayLayerCount: int, + mipLevelCount: int, + sampleCount: int, + dimension: string, + format: textureFormat, + usage: textureUsageObject, +}; + +type passEncoderRenderObject; + +type clearColor = { + . + "r": float, + "g": float, + "b": float, + "a": float, +}; + +type colorAttachment = { + . + "clearColor": clearColor, + "loadOp": string, + "storeOp": string, + "attachment": textureViewObject, +}; + +type depthStencilAttachment = { + . + "clearDepth": float, + "depthLoadOp": string, + "depthStoreOp": string, + "clearStencil": int, + "stencilLoadOp": string, + "stencilStoreOp": string, + "attachment": textureViewObject, +}; + +[@bs.deriving abstract] +type passEncoderRenderDescriptor = { + colorAttachments: array(colorAttachment), + [@bs.optional] + depthStencilAttachment, +}; + +type vertexCount = int; +type indexCount = int; +type instanceCount = int; +type firstVertex = int; +type firstIndex = int; +type firstInstance = int; +type baseVertex = firstVertex; + +type passEncoderComputeObject; + +[@bs.deriving abstract] +type passEncoderComputeDescriptor = { + [@bs.optional] + label: string, +}; + +type x = int; +type y = int; +type z = int; + +// type textureUsage = { +// copy_src: textureUsageObject, +// copy_dst: textureUsageObject, +// sampled: textureUsageObject, +// storage: textureUsageObject, +// output_attachment: textureUsageObject, +// }; + +type swapChain = { + getCurrentTextureView: (unit, swapChainObject) => textureViewObject, + present: swapChainObject, + unit, +}; + +type queue = {submit: (array(commandBufferObject), queueObject) => unit}; + +// type shaderStage = { +// compute: shaderStageObject, +// fragment: shaderStageObject, +// vertex: shaderStageObject, +// }; + +// type bufferUsage = { +// storage: bufferUsageObject, +// uniform: bufferUsageObject, +// indirect: bufferUsageObject, +// vertex: bufferUsageObject, +// index: bufferUsageObject, +// map_read: bufferUsageObject, +// map_write: bufferUsageObject, +// copy_src: bufferUsageObject, +// copy_dst: bufferUsageObject, +// }; + +type buffer = { + setSubFloat32Data: + (int, Js.Typed_array.Float32Array.t, bufferObject) => unit, + setSubUint8Data: (int, Js.Typed_array.Uint8Array.t, bufferObject) => unit, + setSubUint32Data: (int, Js.Typed_array.Uint32Array.t, bufferObject) => unit, +}; + +[@bs.deriving abstract] +type textureViewDescriptor = { + format: textureFormat, + [@bs.optional] + dimension: string, + [@bs.optional] + aspect: string, + [@bs.optional] + baseMipLevel: int, + [@bs.optional] + mipLevelCount: int, + [@bs.optional] + baseArrayLayer: int, + [@bs.optional] + arrayLayerCount: int, +}; + +type texture = { + createView: (textureViewDescriptor, textureObject) => textureViewObject, +}; + +type passEncoderRender = { + setPipeline: (pipelineRenderObject, passEncoderRenderObject) => unit, + setBindGroup: + (bindingPoint, bindGroupObject, passEncoderRenderObject) => unit, + setDynamicBindGroup: + (bindingPoint, bindGroupObject, array(int), passEncoderRenderObject) => + unit, + setVertexBuffer: (int, bufferObject, passEncoderRenderObject) => unit, + setIndexBuffer: (bufferObject, passEncoderRenderObject) => unit, + draw: + ( + vertexCount, + instanceCount, + firstVertex, + firstInstance, + passEncoderRenderObject + ) => + unit, + drawIndexed: + ( + indexCount, + instanceCount, + firstIndex, + baseVertex, + firstInstance, + passEncoderRenderObject + ) => + unit, + endPass: passEncoderRenderObject => unit, +}; + +type passEncoderCompute = { + setPipeline: (pipelineComputeObject, passEncoderComputeObject) => unit, + setBindGroup: + (bindingPoint, bindGroupObject, passEncoderComputeObject) => unit, + setDynamicBindGroup: + (bindingPoint, bindGroupObject, array(int), passEncoderRenderObject) => + unit, + dispatchX: (x, passEncoderComputeObject) => unit, + endPass: passEncoderComputeObject => unit, +}; + +type passEncoder = { + render: passEncoderRender, + compute: passEncoderCompute, +}; + +type commandEncoder = { + beginRenderPass: + (passEncoderRenderDescriptor, commandEncoderObject) => + passEncoderRenderObject, + beginComputePass: + (passEncoderComputeDescriptor, commandEncoderObject) => + passEncoderComputeObject, + finish: commandEncoderObject => commandBufferObject, +}; + +type device = { + getQueue: deviceObject => queueObject, + createShaderModule: shaderModuleDescriptor => shaderModuleObject, + createPipelineLayout: + (pipelineLayoutConfig, deviceObject) => pipelineLayoutObject, + createBuffer: (bufferDescriptor, deviceObject) => bufferObject, + createBindGroupLayout: + (bindGroupLayoutDescriptor, deviceObject) => bindGroupLayoutObject, + createBindGroup: (bindGroupDescriptor, deviceObject) => bindGroupObject, + createRenderPipeline: + (pipelineRenderDescriptor, deviceObject) => pipelineRenderObject, + createComputePipeline: + (pipelineComputeDescriptor, deviceObject) => pipelineComputeObject, + createCommandEncoder: + (commandEncoderDescriptor, deviceObject) => commandEncoderObject, + createSampler: (samplerDescriptor, deviceObject) => samplerObject, + createTexture: (textureDescriptor, deviceObject) => textureObject, +}; + +type context = { + getSwapChainPreferredFormat: deviceObject => Js.Promise.t(textureFormat), + configureSwapChain: (swapChainConfig, contextObject) => swapChainObject, +}; + +type window = { + make: windowDescriptor => windowObject, + getContext: (string, windowObject) => contextObject, + pollEvents: (unit, windowObject) => unit, + shouldClose: windowObject => bool, + getWidth: windowObject => int, + getHeight: windowObject => int, +}; + +type adapter = { + requestDevice: + ({. "extensions": array(string)}, adapterObject) => + Js.Promise.t(deviceObject), +}; + +type gpu = { + requestAdapter: adapterDescriptor => Js.Promise.t(adapterObject), +}; + +type webgpuCore = { + // textureUsage, + texture, + swapChain, + queue, + // shaderStage, + // bufferUsage, + buffer, + passEncoder, + commandEncoder, + device, + context, + window, + adapter, + gpu, +}; diff --git a/src/construct/domain_layer/dependency/interface/IWebGPURayTracingDp.re b/src/construct/domain_layer/dependency/interface/IWebGPURayTracingDp.re new file mode 100644 index 0000000000..afb9b39834 --- /dev/null +++ b/src/construct/domain_layer/dependency/interface/IWebGPURayTracingDp.re @@ -0,0 +1,229 @@ +open IWebGPUCoreDp; + +type shaderBindingTableObject; + +type pipelineRayTracingObject; + +type accelerationContainerObject; + +type accelerationGeometryUsageObject = int; + +type accelerationInstanceUsageObject = int; + +type accelerationContainerUsageObject = int; + +type stage = { + . + "module": shaderModuleObject, + "stage": shaderStageObject, +}; + +[@bs.deriving abstract] +type group = { + [@bs.as "type"] + type_: string, + [@bs.optional] + generalIndex: int, + [@bs.optional] + anyHitIndex: int, + [@bs.optional] + closestHitIndex: int, + [@bs.optional] + intersectionIndex: int, +}; + +type shaderBindingTableDescriptor = { + . + "stages": array(stage), + "groups": array(group), +}; + +[@bs.deriving abstract] +type rayTracingState = { + shaderBindingTable: shaderBindingTableObject, + maxRecursionDepth: int, + maxPayloadSize: int, +}; + +[@bs.deriving abstract] +type pipelineRayTracingDescriptor = { + layout: pipelineLayoutObject, + rayTracingState, +}; + +type geometryVertex = { + . + "buffer": bufferObject, + "format": string, + "stride": int, + "count": int, +}; + +type geometryIndex = { + . + "buffer": bufferObject, + "format": string, + "count": int, +}; + +type geometry = { + . + "usage": accelerationGeometryUsageObject, + "type": string, + "vertex": geometryVertex, + "index": geometryIndex, +}; + +type transform3D = { + . + "x": float, + "y": float, + "z": float, +}; + +type transform = { + . + "translation": transform3D, + "rotation": transform3D, + "scale": transform3D, +}; + +type instanceId = int; + +[@bs.deriving abstract] +type instance = { + usage: accelerationInstanceUsageObject, + mask: int, + instanceId, + instanceOffset: int, + geometryContainer: accelerationContainerObject, + [@bs.optional] + transform, + [@bs.optional] + transformMatrix: Js.Typed_array.Float32Array.t, +}; + +let getInstanceId = instance => { + instance->instanceIdGet; +}; + +[@bs.deriving abstract] +type accelerationContainerDescriptor = { + level: string, + usage: accelerationContainerUsageObject, + [@bs.optional] + geometries: array(geometry), + [@bs.optional] + instances: array(instance), +}; + +// type accelerationContainerUsage ={ +// none: accelerationContainerUsageObject, +// allow_update: accelerationContainerUsageObject, +// prefer_fast_trace: accelerationContainerUsageObject, +// prefer_fast_build: accelerationContainerUsageObject, +// low_memory: accelerationContainerUsageObject, +// }; + +// type accelerationGeometryUsage ={ +// none: accelerationGeometryUsageObject, +// opaque: accelerationGeometryUsageObject, +// allow_any_hit: accelerationGeometryUsageObject, +// }; + +// type accelerationInstanceUsage ={ +// none: accelerationInstanceUsageObject, +// triangle_cull_disable: accelerationInstanceUsageObject, +// triangle_front_counterclockwise: accelerationInstanceUsageObject, +// force_opaque: accelerationInstanceUsageObject, +// force_no_opaque: accelerationInstanceUsageObject, +// }; + +type accelerationContainer = { + updateInstance: (instanceId, instance, accelerationContainerObject) => unit, + setSubFloat32Data: + (int, Js.Typed_array.Float32Array.t, accelerationContainerObject) => unit, +}; + +type passEncoderRayTracingObject; + +[@bs.deriving abstract] +type passEncoderRayTracingDescriptor = { + [@bs.optional] + label: string, +}; + +type sbtRayGenerationOffset = int; +type sbtRayHitOffset = int; +type sbtRayMissOffset = int; +type queryWidthDimension = int; +type queryHeightDimension = int; +type queryDepthDimension = int; + +type passEncoderRayTracing = { + setPipeline: (pipelineRayTracingObject, passEncoderRayTracingObject) => unit, + setBindGroup: + (bindingPoint, bindGroupObject, passEncoderRayTracingObject) => unit, + traceRays: + ( + sbtRayGenerationOffset, + sbtRayHitOffset, + sbtRayMissOffset, + queryWidthDimension, + queryHeightDimension, + queryDepthDimension, + passEncoderRayTracingObject + ) => + unit, + endPass: passEncoderRayTracingObject => unit, +}; + +type commandEncoder = { + beginRayTracingPass: + (passEncoderRayTracingDescriptor, commandEncoderObject) => + passEncoderRayTracingObject, + buildRayTracingAccelerationContainer: + (accelerationContainerObject, commandEncoderObject) => unit, + updateRayTracingAccelerationContainer: + (accelerationContainerObject, commandEncoderObject) => unit, +}; + +[@bs.deriving abstract] +type binding = { + accelerationContainer: accelerationContainerObject, + binding: bindingPoint, + [@bs.optional] + buffer: bufferObject, + [@bs.optional] + sampler: samplerObject, + [@bs.optional] + textureView: textureViewObject, + [@bs.optional] + offset: int, + size: int, +}; + +type bindGroupDescriptor = { + . + "layout": bindGroupLayoutObject, + "entries": array(binding), +}; + +type device = { + createRayTracingPipeline: + (pipelineRayTracingDescriptor, deviceObject) => pipelineRayTracingObject, + createRayTracingShaderBindingTable: + (shaderBindingTableDescriptor, deviceObject) => shaderBindingTableObject, + createRayTracingAccelerationContainer: + accelerationContainerDescriptor => accelerationContainerObject, + /*! add this to avoid IWebGPUCoreDp->binding dependent on IWebGPURayTracingDP! */ + createRayTracingBindGroup: + (bindGroupDescriptor, deviceObject) => bindGroupObject, +}; + +type webgpuRayTracing = { + accelerationContainer, + passEncoderRayTracing, + commandEncoder, + device, +};