Skip to content

Commit

Permalink
feat(architecture): add UpdateAccumulationCPJobEntity, RenderAccumula…
Browse files Browse the repository at this point in the history
…tionCPJobEntity, RenderPathTracingCPJobEntity, EndRenderCPJobEntity

pass unit test;
  • Loading branch information
yyc-git committed Nov 6, 2020
1 parent b5e9eda commit 8a213f5
Show file tree
Hide file tree
Showing 19 changed files with 932 additions and 90 deletions.
6 changes: 3 additions & 3 deletions src/run/application_layer/DirectorCPApService.re
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ let update = () => {
PipelineCPDoService.getUpdatePipelineData()->_parseAndSetPipelineStream;
};

// let render = () => {
// PipelineCPDoService.getRenderPipelineData()->_parseAndSetPipelineStream;
// };
let render = () => {
PipelineCPDoService.getRenderPipelineData()->_parseAndSetPipelineStream;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let create = () => JobEntity.create("end_render");

let exec = () => {
Tuple2.collectOption(WebGPUCPRepo.getWindow(), WebGPUCPRepo.getSwapChain())
->Result.mapSuccess(((window, swapChain)) => {
WebGPUCoreDpRunAPI.unsafeGet().swapChain.present(swapChain);

WebGPUCoreDpRunAPI.unsafeGet().window.pollEvents(window);
})
->WonderBsMost.Most.just;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
let create = () => JobEntity.create("render_accumulation");

let exec = () => {
Tuple6.collectOption(
WebGPUCPRepo.getDevice(),
WebGPUCPRepo.getQueue(),
WebGPUCPRepo.getWindow(),
WebGPUCPRepo.getSwapChain(),
AccumulationPassCPRepo.getStaticBindGroupData(),
AccumulationPassCPRepo.getPipeline(),
)
->Result.mapSuccess(
(
(
device,
queue,
window,
swapChain,
{setSlot, bindGroup}: PassCPPOType.staticBindGroupData,
pipeline,
),
) => {
let backBufferView =
WebGPUCoreDpRunAPI.unsafeGet().swapChain.getCurrentTextureView(
(),
swapChain,
);

let commandEncoder =
WebGPUCoreDpRunAPI.unsafeGet().device.createCommandEncoder(
IWebGPUCoreDp.commandEncoderDescriptor(),
device,
);
let renderPass =
WebGPUCoreDpRunAPI.unsafeGet().commandEncoder.beginRenderPass(
IWebGPUCoreDp.passEncoderRenderDescriptor(
~colorAttachments=[|
{
"clearColor": {
"r": 0.0,
"g": 0.0,
"b": 0.0,
"a": 1.0,
},
"loadOp": "clear",
"storeOp": "store",
"attachment": backBufferView,
},
|],
(),
),
commandEncoder,
);

WebGPUCoreDpRunAPI.unsafeGet().passEncoder.render.setPipeline(
pipeline,
renderPass,
);

WebGPUCoreDpRunAPI.unsafeGet().passEncoder.render.setBindGroup(
setSlot,
bindGroup,
renderPass,
);

WebGPUCoreDpRunAPI.unsafeGet().passEncoder.render.draw(
3,
1,
0,
0,
renderPass,
);

WebGPUCoreDpRunAPI.unsafeGet().passEncoder.render.endPass(
renderPass,
);

WebGPUCoreDpRunAPI.unsafeGet().queue.submit(
[|
WebGPUCoreDpRunAPI.unsafeGet().commandEncoder.finish(
commandEncoder,
),
|],
queue,
);
})
->WonderBsMost.Most.just;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
let create = () => JobEntity.create("render_pathTracing");

let exec = () => {
Tuple4.collectOption(
WebGPUCPRepo.getDevice(),
WebGPUCPRepo.getQueue(),
WebGPUCPRepo.getWindow(),
PathTracingPassCPRepo.getPipeline(),
)
->Result.mapSuccess(((device, queue, window, pipeline)) => {
let commandEncoder =
WebGPUCoreDpRunAPI.unsafeGet().device.createCommandEncoder(
IWebGPUCoreDp.commandEncoderDescriptor(),
device,
);
let rtPass =
WebGPURayTracingDpRunAPI.unsafeGet().commandEncoder.
beginRayTracingPass(
IWebGPURayTracingDp.passEncoderRayTracingDescriptor(),
commandEncoder,
);

WebGPURayTracingDpRunAPI.unsafeGet().passEncoder.
setPipeline(
pipeline,
rtPass,
);

PathTracingPassCPRepo.getAllStaticBindGroupData()
->ListSt.forEach(
({setSlot, bindGroup}: PassCPPOType.staticBindGroupData) => {
WebGPURayTracingDpRunAPI.unsafeGet().passEncoder.
setBindGroup(
setSlot,
bindGroup,
rtPass,
)
});

WebGPURayTracingDpRunAPI.unsafeGet().passEncoder.traceRays(
0, // sbt ray_generation offset
1, // sbt ray-hit offset
2, // sbt ray_miss offset
WebGPUCoreDpRunAPI.unsafeGet().window.getWidth(window),
WebGPUCoreDpRunAPI.unsafeGet().window.getHeight(window),
1, // query depth dimension
rtPass,
);

WebGPURayTracingDpRunAPI.unsafeGet().passEncoder.endPass(
rtPass,
);

WebGPUCoreDpRunAPI.unsafeGet().queue.submit(
[|
WebGPUCoreDpRunAPI.unsafeGet().commandEncoder.finish(
commandEncoder,
),
|],
queue,
);
})
->WonderBsMost.Most.just;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let create = () => JobEntity.create("update_accumulation");

let exec = () => {
AccumulationPassCPDoService.increaseSampleAccumulation()
->Result.succeed
->WonderBsMost.Most.just;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let create = () => JobEntity.create("update_pass_for_render");

let _updateCommonBufferData = ((commonBuffer, commonBufferData)) => {
let totalSampleCount = PassCPRepo.getTotalSampleCount();

TypeArrayCPRepoUtils.setUint32_1(1, totalSampleCount, commonBufferData)
->Result.tap(() => {
WebGPUCoreDpRunAPI.unsafeGet().buffer.setSubUint32Data(
0,
commonBufferData,
commonBuffer->UniformBufferVO.value,
);

PassCPRepo.setCommonBufferData((commonBuffer, commonBufferData));
});
};

let exec = () => {
PassCPRepo.getCommonBufferData()
->OptionSt.get
->Result.bind(((commonBuffer, commonBufferData)) => {
_updateCommonBufferData((commonBuffer, commonBufferData))
})
->WonderBsMost.Most.just;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let increaseSampleAccumulation = () => {
PassCPRepo.setTotalSampleCount(
PassCPRepo.getTotalSampleCount() + PassCPRepo.getSampleCount(),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ let _getUpdatePipelineJobs = () => [
(UpdatePassCPJobEntity.create(), UpdatePassCPJobEntity.exec),
];

// let _getRenderPipelineJobs = () => [
// (RenderPathTracingCPJobEntity.create(), RenderPathTracingCPJobEntity.exec),
// (
// UpdateAccumulationCPJobEntity.create(),
// UpdateAccumulationCPJobEntity.exec,
// ),
// (
// UpdatePassForRenderCPJobEntity.create(),
// UpdatePassForRenderCPJobEntity.exec,
// ),
// (
// RenderAccumulationCPJobEntity.create(),
// RenderAccumulationCPJobEntity.exec,
// ),
// (EndRenderCPJobEntity.create(), EndRenderCPJobEntity.exec),
// ];
let _getRenderPipelineJobs = () => [
(RenderPathTracingCPJobEntity.create(), RenderPathTracingCPJobEntity.exec),
(
UpdateAccumulationCPJobEntity.create(),
UpdateAccumulationCPJobEntity.exec,
),
(
UpdatePassForRenderCPJobEntity.create(),
UpdatePassForRenderCPJobEntity.exec,
),
(
RenderAccumulationCPJobEntity.create(),
RenderAccumulationCPJobEntity.exec,
),
(EndRenderCPJobEntity.create(), EndRenderCPJobEntity.exec),
];

let _register = (pipeline, jobs) => {
jobs->ListSt.forEach(((job, execFunc)) => {
Expand All @@ -43,5 +43,5 @@ let _register = (pipeline, jobs) => {
let registerAllJobs = () => {
_register(PipelineCPRepo.getInitPipeline(), _getInitPipelineJobs());
_register(PipelineCPRepo.getUpdatePipeline(), _getUpdatePipelineJobs());
// _register(PipelineCPRepo.getRenderPipeline(), _getRenderPipelineJobs());
_register(PipelineCPRepo.getRenderPipeline(), _getRenderPipelineJobs());
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ let getUpdatePipeline = () => {
PipelineCPRepo.getUpdatePipeline();
};

// let getRenderPipeline = () => {
// PipelineCPRepo.getRenderPipeline();
// };
let getRenderPipeline = () => {
PipelineCPRepo.getRenderPipeline();
};

let getInitPipelineData = () => {
PipelineCPRepo.getInitPipelineData();
Expand All @@ -26,13 +26,13 @@ let setUpdatePipelineData = pipelineData => {
PipelineCPRepo.setUpdatePipelineData(pipelineData);
};

// let getRenderPipelineData = () => {
// PipelineCPRepo.getRenderPipelineData();
// };
let getRenderPipelineData = () => {
PipelineCPRepo.getRenderPipelineData();
};

// let setRenderPipelineData = pipelineData => {
// PipelineCPRepo.setRenderPipelineData(pipelineData);
// };
let setRenderPipelineData = pipelineData => {
PipelineCPRepo.setRenderPipelineData(pipelineData);
};

let getPipelineStream = pipeline => {
PipelineCPRepo.getPipelineStream(pipeline);
Expand Down
36 changes: 18 additions & 18 deletions src/run/domain_layer/repo/CreateCPRepo.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let create = () => {
pipeline: {
initPipeline: "init",
updatePipeline: "update",
// renderPipeline: "render",
renderPipeline: "render",
initPipelineData: {
name: "init",
firstGroup: "frame",
Expand Down Expand Up @@ -39,23 +39,23 @@ let create = () => {
},
],
},
// renderPipelineData: {
// name: "render",
// firstGroup: "frame",
// groups: [
// {
// name: "frame",
// link: Concat,
// elements: [
// {name: "render_pathTracing", type_: Job},
// {name: "update_accumulation", type_: Job},
// {name: "update_pass_for_render", type_: Job},
// {name: "render_accumulation", type_: Job},
// {name: "end_render", type_: Job},
// ],
// },
// ],
// },
renderPipelineData: {
name: "render",
firstGroup: "frame",
groups: [
{
name: "frame",
link: Concat,
elements: [
{name: "render_pathTracing", type_: Job},
{name: "update_accumulation", type_: Job},
{name: "update_pass_for_render", type_: Job},
{name: "render_accumulation", type_: Job},
{name: "end_render", type_: Job},
],
},
],
},
pipelineStreamMap: ImmutableHashMap.createEmpty(),
jobExecFuncMap: ImmutableHashMap.createEmpty(),
},
Expand Down
23 changes: 10 additions & 13 deletions src/run/domain_layer/repo/pipeline/PipelineCPRepo.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ let getUpdatePipeline = () => {
CPRepo.getPipeline().updatePipeline->PipelineEntity.create;
};

// let getRenderPipeline = () => {
// CPRepo.getPipeline().renderPipeline->PipelineEntity.create;
// };
let getRenderPipeline = () => {
CPRepo.getPipeline().renderPipeline->PipelineEntity.create;
};

let getInitPipelineData = () => {
CPRepo.getPipeline().initPipelineData;
Expand All @@ -26,19 +26,16 @@ let setUpdatePipelineData = updatePipelineData => {
CPRepo.setPipeline({...CPRepo.getPipeline(), updatePipelineData});
};

// let getRenderPipelineData = () => {
// CPRepo.getPipeline().renderPipelineData;
// };
let getRenderPipelineData = () => {
CPRepo.getPipeline().renderPipelineData;
};

// let setRenderPipelineData = renderPipelineData => {
// CPRepo.setPipeline({...CPRepo.getPipeline(), renderPipelineData});
// };
let setRenderPipelineData = renderPipelineData => {
CPRepo.setPipeline({...CPRepo.getPipeline(), renderPipelineData});
};

let getPipelineStream = pipeline => {
pipeline
->PipelineEntity.value
->PipelineCPRepoDp.getPipelineStream

pipeline->PipelineEntity.value->PipelineCPRepoDp.getPipelineStream;
};

let setPipelineStream = (pipeline, stream) => {
Expand Down
Loading

0 comments on commit 8a213f5

Please sign in to comment.