Skip to content

Commit

Permalink
feat(dispose): fix "dispose basic source texture/array buffer view so…
Browse files Browse the repository at this point in the history
…urce texture->bindTextureUnitCacheMap"

update wonder-commonlib version
  • Loading branch information
yyc-git committed May 23, 2019
1 parent d5c6e77 commit c56411f
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 228 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"bs-fetch": "^0.3.0",
"wonder-bs-json": "^0.0.1",
"wonder-bs-most": "^0.0.3",
"wonder-commonlib": "^0.2.31",
"wonder-commonlib": "^0.2.32",
"wonder-imgui": "^0.0.34",
"wonder-log": "^0.2.11",
"wonder-most-animation-frame": "0.0.3",
Expand All @@ -80,7 +80,7 @@
"resolutions": {
"wonder-log": "^0.2.11",
"wonder-webgl": "^0.0.10",
"wonder-commonlib": "0.2.31",
"wonder-commonlib": "0.2.32",
"wonder-bs-jest": "0.3.0",
"wonder-bs-puppeteer": "^0.1.6"
}
Expand Down
19 changes: 14 additions & 5 deletions src/service/primitive/texture/CacheTextureService.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
let isCached = (unit, texture, bindTextureUnitCacheMap) =>
switch (bindTextureUnitCacheMap |> WonderCommonlib.MutableSparseMapService.get(unit)) {
switch (
bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.get(unit)
) {
| None => false
| Some(bindedTexture) => bindedTexture === texture
};
Expand All @@ -11,13 +14,19 @@ let addActiveTexture = (unit, texture, bindTextureUnitCacheMap) => {
Contract.(
Operators.(
test(
Log.buildAssertMessage(~expect={j|not cached|j}, ~actual={j||j}),
() => isCached(unit, texture, bindTextureUnitCacheMap) |> assertFalse
Log.buildAssertMessage(
~expect={j|not cached|j},
~actual={j||j},
),
() =>
isCached(unit, texture, bindTextureUnitCacheMap) |> assertFalse
)
)
)
),
IsDebugMainService.getIsDebug(StateDataMain.stateData)
IsDebugMainService.getIsDebug(StateDataMain.stateData),
);
bindTextureUnitCacheMap |> WonderCommonlib.MutableSparseMapService.set(unit, texture)

bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.set(unit, texture);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ type arrayBufferViewSourceTextureRecord = {
flipYs: Js.Typed_array.Uint8Array.t,
widths: Js.Typed_array.Uint16Array.t,
heights: Js.Typed_array.Uint16Array.t,
sourceMap: WonderCommonlib.MutableSparseMapService.t(Js.Typed_array.Uint8Array.t),
glTextureMap: WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
sourceMap:
WonderCommonlib.MutableSparseMapService.t(Js.Typed_array.Uint8Array.t),
glTextureMap:
WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
bindTextureUnitCacheMap: WonderCommonlib.MutableSparseMapService.t(int),
setFlipYFunc: (WonderWebgl.GlType.webgl1Context, bool, BrowserDetectType.browserDetectRecord) => unit,
textureIndexOffset: int
setFlipYFunc:
(
WonderWebgl.GlType.webgl1Context,
bool,
BrowserDetectType.browserDetectRecord
) =>
unit,
textureIndexOffset: int,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ type basicSourceTextureRecord = {
types: Js.Typed_array.Uint8Array.t,
isNeedUpdates: Js.Typed_array.Uint8Array.t,
flipYs: Js.Typed_array.Uint8Array.t,
sourceMap: WonderCommonlib.MutableSparseMapService.t(WonderWebgl.DomExtendType.imageElement),
glTextureMap: WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
sourceMap:
WonderCommonlib.MutableSparseMapService.t(
WonderWebgl.DomExtendType.imageElement,
),
glTextureMap:
WonderCommonlib.MutableSparseMapService.t(WonderWebgl.GlType.texture),
bindTextureUnitCacheMap: WonderCommonlib.MutableSparseMapService.t(int),
setFlipYFunc: (WonderWebgl.GlType.webgl1Context, bool, BrowserDetectType.browserDetectRecord) => unit
setFlipYFunc:
(
WonderWebgl.GlType.webgl1Context,
bool,
BrowserDetectType.browserDetectRecord
) =>
unit,
};
19 changes: 18 additions & 1 deletion src/service/state/main/texture/DisposeTextureMainService.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,21 @@ let clearNeedDisposedTextureIndexArray = state => {
...RecordArrayBufferViewSourceTextureMainService.getRecord(state),
needDisposedTextureIndexArray: [||],
}),
};
};

let disposeBindTextureUnitCacheMap = (texture, bindTextureUnitCacheMap) =>
switch (
bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.getValidDataArr
|> Js.Array.filter(((unit, bindedTexture)) => bindedTexture === texture)
) {
| arr when Js.Array.length(arr) > 0 =>
arr
|> WonderCommonlib.ArrayService.reduceOneParam(
(. bindTextureUnitCacheMap, (unit, texture)) =>
bindTextureUnitCacheMap
|> DisposeComponentService.disposeSparseMapData(unit),
bindTextureUnitCacheMap,
)
| _ => bindTextureUnitCacheMap
};
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ let _disposeData = (texture, textureIndexInTypeArr, state) => {
),
sourceMap: sourceMap |> disposeSparseMapData(texture),
bindTextureUnitCacheMap:
bindTextureUnitCacheMap |> disposeSparseMapData(texture),
DisposeTextureMainService.disposeBindTextureUnitCacheMap(
texture,
bindTextureUnitCacheMap,
),
needAddedSourceArray:
DisposeTextureMainService.disposeNeedAddedSourceArray(
texture,
Expand All @@ -131,14 +134,6 @@ let _disposeData = (texture, textureIndexInTypeArr, state) => {

let handleDispose = (materialData, textureArr, state) =>
textureArr
/* |> Js.Array.map(texture =>
IndexSourceTextureService.getArrayBufferViewSourceTextureIndexInTypeArray(
texture,
IndexSourceTextureMainService.getArrayBufferViewSourceTextureIndexOffset(
state,
),
)
) */
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, texture) => {
let arrayBufferViewSourceTextureRecord =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ let _disposeData = (texture, state) => {
),
sourceMap: sourceMap |> disposeSparseMapData(texture),
bindTextureUnitCacheMap:
bindTextureUnitCacheMap |> disposeSparseMapData(texture),
DisposeTextureMainService.disposeBindTextureUnitCacheMap(
texture,
bindTextureUnitCacheMap,
),
needAddedSourceArray:
DisposeTextureMainService.disposeNeedAddedSourceArray(
texture,
Expand Down
8 changes: 4 additions & 4 deletions test/tool/service/texture/ArrayBufferViewSourceTextureTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ let getMaterialDataArr = (texture, state) =>
materialsMap,
);

let getBindTextureUnitCacheMap = (texture, state) => {
/* let getBindTextureUnitCacheMap = (texture, state) => {
let arrayBufferViewSourceTextureRecord =
RecordArrayBufferViewSourceTextureMainService.getRecord(state);
arrayBufferViewSourceTextureRecord.bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.get(texture);
};
}; */

let setBindTextureUnitCacheMap = (texture, unit, state) => {
/* let setBindTextureUnitCacheMap = (texture, unit, state) => {
let arrayBufferViewSourceTextureRecord =
RecordArrayBufferViewSourceTextureMainService.getRecord(state);
Expand All @@ -92,7 +92,7 @@ let setBindTextureUnitCacheMap = (texture, unit, state) => {
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
}),
};
};
}; */

let unsafeGetMaterialDataArr = (texture, state) =>
getMaterialDataArr(texture, state) |> OptionService.unsafeGet;
Expand Down
24 changes: 20 additions & 4 deletions test/tool/service/texture/BasicSourceTextureTool.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ let getMaterialDataArr = (texture, state) =>
let unsafeGetMaterialDataArr = (texture, state) =>
getMaterialDataArr(texture, state) |> OptionService.unsafeGet;

let getBindTextureUnitCacheMap = (texture, state) => {
let getBindTextureUnitCacheMap = (unit, state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);

basicSourceTextureRecord.bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.get(texture);
|> WonderCommonlib.MutableSparseMapService.get(unit);
};

let setBindTextureUnitCacheMap = (texture, unit, state) => {
let setBindTextureUnitCacheMap = (unit, bindedTexture, state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);

Expand All @@ -123,11 +123,27 @@ let setBindTextureUnitCacheMap = (texture, unit, state) => {
...basicSourceTextureRecord,
bindTextureUnitCacheMap:
basicSourceTextureRecord.bindTextureUnitCacheMap
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
|> WonderCommonlib.MutableSparseMapService.set(unit, bindedTexture),
}),
};
};

/* let setBindTextureUnitMap = (texture, unit, state) => {
let basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);
{
...state,
basicSourceTextureRecord:
Some({
...basicSourceTextureRecord,
bindTextureUnitMap:
basicSourceTextureRecord.bindTextureUnitMap
|> WonderCommonlib.MutableSparseMapService.set(texture, unit),
}),
};
}; */

let getBasicSourceTextureSource = (texture, state: StateDataMainType.state) => {
let {sourceMap} = RecordBasicSourceTextureMainService.getRecord(state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,47 +263,6 @@ let _ =
});

describe("else", () => {
test("remove from sourceMap, bindTextureUnitCacheMap, nameMap", () => {
let (
state,
material1,
(diffuseMap, specularMap, source1, source2),
) =
LightMaterialTool.createMaterialWithArrayBufferViewMap(state^);
let state =
state
|> ArrayBufferViewSourceTextureAPI.setArrayBufferViewSourceTextureName(
diffuseMap,
"name",
)
|> ArrayBufferViewSourceTextureTool.setBindTextureUnitCacheMap(
diffuseMap,
1,
);

let state =
LightMaterialAPI.batchDisposeLightMaterial(
[|material1|],
state,
);

(
ArrayBufferViewSourceTextureTool.getArrayBufferViewSourceTextureName(
diffuseMap,
state,
),
ArrayBufferViewSourceTextureTool.getArrayBufferViewSourceTextureSource(
diffuseMap,
state,
),
ArrayBufferViewSourceTextureTool.getBindTextureUnitCacheMap(
diffuseMap,
state,
),
)
|> expect == (None, None, None);
});

describe("test remove from type array", () => {
let _testRemoveFromTypeArr =
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ let _ =
});

describe("else", () => {
test("remove from sourceMap, bindTextureUnitCacheMap, nameMap", () => {
test("remove from sourceMap, nameMap", () => {
let (
state,
material1,
Expand Down Expand Up @@ -321,12 +321,50 @@ let _ =
diffuseMap,
state,
),
BasicSourceTextureTool.getBindTextureUnitCacheMap(
diffuseMap,
)
|> expect == (None, None);
});
test("remove from bindTextureUnitCacheMap", () => {
let (
state,
material1,
(diffuseMap1, specularMap1, source1_1, source1_2),
) =
LightMaterialTool.createMaterialWithMap(state^);
let (
state,
material2,
(diffuseMap2, specularMap2, source2_1, source2_2),
) =
LightMaterialTool.createMaterialWithMap(state);

let unit0 = 0;
let unit1 = 1;

let state =
state
|> BasicSourceTextureTool.setBindTextureUnitCacheMap(
unit1,
diffuseMap1,
)
|> BasicSourceTextureTool.setBindTextureUnitCacheMap(
unit0,
diffuseMap2,
);

let state =
LightMaterialAPI.batchDisposeLightMaterial(
[|material1|],
state,
),
);

(
BasicSourceTextureTool.getBindTextureUnitCacheMap(unit1, state)
|> Js.Option.isNone,
BasicSourceTextureTool.getBindTextureUnitCacheMap(unit0, state)
|> Js.Option.isNone,
)
|> expect == (None, None, None);
|> expect == (true, false);
});

describe("test remove from type array", () => {
Expand Down
Loading

0 comments on commit c56411f

Please sign in to comment.