@@ -100,6 +100,7 @@ typedef struct {
100
100
HapCodecTaskGroupRef taskGroup ;
101
101
102
102
unsigned int sliceCount ;
103
+ unsigned int sliceHeight ;
103
104
#ifdef DEBUG
104
105
unsigned int debugFrameCount ;
105
106
uint64_t debugStartTime ;
@@ -229,6 +230,7 @@ Hap_COpen(
229
230
glob -> dxtFormat = 0 ;
230
231
glob -> taskGroup = NULL ;
231
232
glob -> sliceCount = 1 ;
233
+ glob -> sliceHeight = 4 ;
232
234
233
235
bail :
234
236
debug_print_err (glob , err );
@@ -664,13 +666,26 @@ Hap_CPrepareToCompressFrames(
664
666
665
667
glob -> taskGroup = HapCodecTasksCreateGroup (Background_Encode , maxTasks );
666
668
667
- glob -> sliceCount = roundUpToMultipleOf4 (glob -> height ) / 4 ;
668
- if (glob -> sliceCount > 32 )
669
- glob -> sliceCount = 32 ;
670
-
671
- // decrease slice count until it yeilds whole DXT rows
672
- while ((roundUpToMultipleOf4 (glob -> height ) / 4 ) % glob -> sliceCount != 0 )
673
- glob -> sliceCount -- ;
669
+ {
670
+ // Slice on DXT row boundaries
671
+ unsigned int totalDXTRows = roundUpToMultipleOf4 (glob -> height ) / 4 ;
672
+ unsigned int remainder ;
673
+ glob -> sliceCount = totalDXTRows < 30 ? totalDXTRows : 30 ;
674
+ glob -> sliceHeight = (totalDXTRows / glob -> sliceCount ) * 4 ;
675
+ remainder = (totalDXTRows % glob -> sliceCount ) * 4 ;
676
+ while (remainder > 0 )
677
+ {
678
+ glob -> sliceCount ++ ;
679
+ if (remainder > glob -> sliceHeight )
680
+ {
681
+ remainder -= glob -> sliceHeight ;
682
+ }
683
+ else
684
+ {
685
+ remainder = 0 ;
686
+ }
687
+ }
688
+ }
674
689
675
690
#ifdef DEBUG
676
691
glob -> debugStartTime = CVGetCurrentHostTime ();
@@ -860,7 +875,7 @@ dxtEncode(HapCompressorGlobals glob, CVPixelBufferRef sourcePixelBuffer, HapCode
860
875
dxtTask .width = glob -> width ;
861
876
dxtTask .height = glob -> height ;
862
877
dxtTask .encoder = encoder ;
863
- dxtTask .sliceHeight = roundUpToMultipleOf4 ( glob -> height ) / glob -> sliceCount ;
878
+ dxtTask .sliceHeight = glob -> sliceHeight ;
864
879
dxtTask .sourceBytesPerRow = CVPixelBufferGetBytesPerRow (sourcePixelBuffer );
865
880
dxtTask .sourcePixelFormat = sourceFormat ;
866
881
dxtTask .source = CVPixelBufferGetBaseAddress (sourcePixelBuffer );
0 commit comments