castle/repeat: fix a number of bugs

- Add fits_in_len_bytes assertions for packed stores.
  Corrects the assertion formerly on line 888.

- In exclusive mode, don't overwrite packedCtrlSize with the max of the
  group; each repeat should know how many bytes it is using, even if
  they share the same stream state.

- Ensure that exclusive mode stream state is sized correctly.
This commit is contained in:
Justin Viiret
2016-03-14 09:28:17 +11:00
committed by Matthew Barr
parent e10d2eb269
commit d0aa138ada
2 changed files with 22 additions and 15 deletions

View File

@@ -361,25 +361,22 @@ void buildSubcastles(const CastleProto &proto, vector<SubCastle> &subs,
DEBUG_PRINTF("sub %u: selected %s model for %s repeat\n", i,
repeatTypeName(rtype), pr.bounds.str().c_str());
u32 subScratchStateSize;
u32 subStreamStateSize;
SubCastle &sub = subs[i];
RepeatInfo &info = infos[i];
// handle exclusive case differently
info.packedCtrlSize = rsi.packedCtrlSize;
u32 subStreamStateSize = verify_u32(rsi.packedCtrlSize + rsi.stateSize);
// Handle stream/scratch space alloc for exclusive case differently.
if (contains(groupId, i)) {
u32 id = groupId.at(i);
maxStreamSize[id] = MAX(maxStreamSize[id], rsi.packedCtrlSize);
maxStreamSize[id] = max(maxStreamSize[id], subStreamStateSize);
// SubCastle full/stream state offsets are written in for the group
// below.
} else {
subScratchStateSize = verify_u32(sizeof(RepeatControl));
subStreamStateSize = verify_u32(rsi.packedCtrlSize + rsi.stateSize);
info.packedCtrlSize = rsi.packedCtrlSize;
sub.fullStateOffset = scratchStateSize;
sub.streamStateOffset = streamStateSize;
scratchStateSize += subScratchStateSize;
scratchStateSize += verify_u32(sizeof(RepeatControl));
streamStateSize += subStreamStateSize;
}
@@ -420,8 +417,6 @@ void buildSubcastles(const CastleProto &proto, vector<SubCastle> &subs,
u32 top = j.first;
u32 id = j.second;
SubCastle &sub = subs[top];
RepeatInfo &info = infos[top];
info.packedCtrlSize = maxStreamSize[id];
if (!scratchOffset[id]) {
sub.fullStateOffset = scratchStateSize;
sub.streamStateOffset = streamStateSize;