@@ -1567,6 +1567,8 @@ struct BatchMemoryState
15671567 void * user = nullptr ;
15681568};
15691569BatchMemoryState batchMemory;
1570+ // the rate control threshold of whichever frame finished last narrows the next search
1571+ std::atomic<uint16_t > batchMemorySlopeHint{0 };
15701572
15711573// the bound grk_compress uses for a compressed frame
15721574size_t codestreamBound (const BatchMemoryState& state)
@@ -1635,9 +1637,14 @@ static uint64_t batchMemoryEncodeCallback(gpup_compress_callback_info* info)
16351637 stream.buf = codestream.data ();
16361638 stream.buf_len = codestream.size ();
16371639 grk_cparameters parameters = batchMemory.t2Parameters ;
1640+ parameters.rate_control_slope_hint = batchMemorySlopeHint.load (std::memory_order_relaxed);
16381641 auto codec = grk_compress_init (&stream, ¶meters, &headerImage);
16391642 if (codec)
1643+ {
16401644 length = grk_compress (codec, wrapPluginTile (info->tile ));
1645+ batchMemorySlopeHint.store (grk_compress_get_slope_threshold (codec),
1646+ std::memory_order_relaxed);
1647+ }
16411648 grk_object_unref (codec);
16421649 }
16431650 batchMemory.callback (batchMemory.user , info->host_data , codestream.data (), length);
@@ -1673,6 +1680,7 @@ GRK_API int32_t GRK_CALLCONV grk_plugin_batch_memory_begin(grk_plugin_batch_memo
16731680 batchMemory.xyzOnDevice = false ;
16741681 batchMemory.rsiz = info.compress_parameters ->rsiz ;
16751682 batchMemory.t2Parameters = *info.compress_parameters ;
1683+ batchMemorySlopeHint.store (0 , std::memory_order_relaxed);
16761684 batchMemory.t2Parameters .apply_xyz_transform = false ;
16771685 batchMemory.t2Parameters .mct = gpupParameters.mct ;
16781686 batchMemory.callback = info.callback ;
0 commit comments