Skip to content

Commit b5e9eda

Browse files
committed
feat(architecture): add UpdatePassCPJobEntity
pass unit test;
1 parent c57d30f commit b5e9eda

File tree

4 files changed

+120
-5
lines changed

4 files changed

+120
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
let create = () => JobEntity.create("update_pass");
2+
3+
let _updateCommonBufferData = ((commonBuffer, commonBufferData)) => {
4+
let sampleCount = PassCPRepo.getSampleCount();
5+
6+
TypeArrayCPRepoUtils.setUint32_1(0, sampleCount, commonBufferData)
7+
->Result.tap(() => {
8+
WebGPUCoreDpRunAPI.unsafeGet().buffer.setSubUint32Data(
9+
0,
10+
commonBufferData,
11+
commonBuffer->UniformBufferVO.value,
12+
);
13+
14+
PassCPRepo.setCommonBufferData((commonBuffer, commonBufferData));
15+
});
16+
};
17+
18+
let _updateAllBufferData = ((commonBuffer, commonBufferData)) => {
19+
_updateCommonBufferData((commonBuffer, commonBufferData));
20+
};
21+
22+
let exec = () => {
23+
PassCPRepo.getCommonBufferData()
24+
->OptionSt.get
25+
->Result.bind(((commonBuffer, commonBufferData)) => {
26+
_updateAllBufferData((commonBuffer, commonBufferData))
27+
})
28+
->WonderBsMost.Most.just;
29+
};

src/run/domain_layer/domain/pipeline/pipeline/service/JobCPDoService.re

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let _getUpdatePipelineJobs = () => [
1414
UpdateTextureArrayCPJobEntity.exec,
1515
),
1616
(UpdatePathTracingCPJobEntity.create(), UpdatePathTracingCPJobEntity.exec),
17-
// (UpdatePassCPJobEntity.create(), UpdatePassCPJobEntity.exec),
17+
(UpdatePassCPJobEntity.create(), UpdatePassCPJobEntity.exec),
1818
];
1919

2020
// let _getRenderPipelineJobs = () => [

src/run/domain_layer/repo/CreateCPRepo.re

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ let create = () => {
1616
{name: "start_time", type_: Job},
1717
{name: "init_webgpu", type_: Job},
1818
{name: "init_camera", type_: Job},
19-
// {name: "init_pass", type_: Job},
20-
// {name: "init_pathTracing", type_: Job},
21-
// {name: "init_accumulation", type_: Job},
19+
{name: "init_pass", type_: Job},
20+
{name: "init_pathTracing", type_: Job},
21+
{name: "init_accumulation", type_: Job},
2222
],
2323
},
2424
],
@@ -34,7 +34,7 @@ let create = () => {
3434
{name: "update_camera", type_: Job},
3535
{name: "update_textureArray", type_: Job},
3636
{name: "update_pathTracing", type_: Job},
37-
// {name: "update_pass", type_: Job},
37+
{name: "update_pass", type_: Job},
3838
],
3939
},
4040
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
open Wonder_jest;
2+
3+
let _ =
4+
describe("test update_pass job", () => {
5+
open Expect;
6+
open Expect.Operators;
7+
open Sinon;
8+
9+
let sandbox = getSandboxDefaultVal();
10+
11+
beforeEach(() => {
12+
sandbox := createSandbox();
13+
TestCPTool.init(
14+
~sandbox,
15+
~updatePipelineData={
16+
name: "update",
17+
firstGroup: "frame",
18+
groups: [
19+
{
20+
name: "frame",
21+
link: Concat,
22+
elements: [{name: "update_pass", type_: Job}],
23+
},
24+
],
25+
},
26+
(),
27+
);
28+
});
29+
afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));
30+
31+
describe("update common buffer data", () => {
32+
let _prepare = () => {
33+
let device = WebGPUDependencyTool.createDeviceObject();
34+
WebGPUCPTool.setDevice(device);
35+
let window = WebGPUDependencyTool.createWindowObject();
36+
WebGPUCPTool.setWindow(window);
37+
38+
PassCPTool.buildAndSetAllBufferData(window, device);
39+
};
40+
41+
testPromise("set sample count to buffer data", () => {
42+
let _ = _prepare();
43+
let sampleCount = 2;
44+
DirectorCPTool.prepare(~sampleCount, ());
45+
46+
DirectorCPTool.initAndUpdate(
47+
~handleSuccessFunc=
48+
() => {
49+
let (_, typeArr) = PassCPTool.getCommonBufferData();
50+
51+
typeArr->Js.Typed_array.Uint32Array.unsafe_get(0)->expect
52+
== sampleCount;
53+
},
54+
(),
55+
);
56+
});
57+
testPromise("set buffer's data", () => {
58+
let _ = _prepare();
59+
let setSubUint32DataStubData =
60+
createEmptyStub(refJsObjToSandbox(sandbox^))
61+
->SinonTool.createThreeArgsEmptyStubData;
62+
WebGPUDependencyTool.build(
63+
~sandbox,
64+
~setSubUint32Data=setSubUint32DataStubData->SinonTool.getDpFunc,
65+
(),
66+
)
67+
->WebGPUDependencyTool.set;
68+
DirectorCPTool.initAndUpdate(
69+
~handleSuccessFunc=
70+
() => {
71+
let (buffer, typeArr) = PassCPTool.getCommonBufferData();
72+
73+
setSubUint32DataStubData
74+
->SinonTool.getStub
75+
->expect
76+
->SinonTool.toCalledWith((
77+
0,
78+
typeArr,
79+
buffer->UniformBufferVO.value,
80+
));
81+
},
82+
(),
83+
);
84+
});
85+
});
86+
});

0 commit comments

Comments
 (0)