4545
4646using namespace std ;
4747
48+ enum ThunderscopeDataType_e {
49+ DATATYPE_I8 = 2 ,
50+ DATATYPE_I16 = 4
51+ };
52+
4853// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4954// Construction / destruction
5055
@@ -164,8 +169,11 @@ ThunderScopeOscilloscope::ThunderScopeOscilloscope(SCPITransport* transport)
164169 bufname.c_str ()));
165170 }
166171
167- m_conversionPipeline = make_unique<ComputePipeline>(
172+ m_conversion8BitPipeline = make_unique<ComputePipeline>(
168173 " shaders/Convert8BitSamples.spv" , 2 , sizeof (ConvertRawSamplesShaderArgs) );
174+
175+ m_conversion16BitPipeline = make_unique<ComputePipeline>(
176+ " shaders/Convert16BitSamples.spv" , 2 , sizeof (ConvertRawSamplesShaderArgs) );
169177
170178 m_clippingBuffer.resize (1 );
171179}
@@ -315,9 +323,14 @@ Oscilloscope::TriggerMode ThunderScopeOscilloscope::PollTrigger()
315323
316324bool ThunderScopeOscilloscope::AcquireData ()
317325{
318- const uint8_t r = ' K ' ;
326+ const uint8_t r = ' S ' ;
319327 m_transport->SendRawData (1 , &r);
320328
329+ // Read Version No.
330+ uint8_t version;
331+ if (!m_transport->ReadRawData (sizeof (version), (uint8_t *)&version))
332+ return false ;
333+
321334 // Read the sequence number of the current waveform
322335 uint32_t seqnum;
323336 if (!m_transport->ReadRawData (sizeof (seqnum), (uint8_t *)&seqnum))
@@ -357,6 +370,7 @@ bool ThunderScopeOscilloscope::AcquireData()
357370
358371 // Acquire data for each channel
359372 uint8_t chnum;
373+ uint8_t dataType;
360374 uint64_t memdepth;
361375 float config[3 ];
362376 SequenceSet s;
@@ -400,10 +414,15 @@ bool ThunderScopeOscilloscope::AcquireData()
400414 bool clipping;
401415 if (!m_transport->ReadRawData (sizeof (clipping), (uint8_t *)&clipping))
402416 return false ;
417+
418+ if (!m_transport->ReadRawData (sizeof (dataType), (uint8_t *)&dataType))
419+ return false ;
403420
404421 // TODO: stream timestamp from the server
405-
406- if (!m_transport->ReadRawData (memdepth * sizeof (int8_t ), (uint8_t *)buf))
422+ uint32_t depth = memdepth * sizeof (int8_t );
423+ if (dataType == DATATYPE_I16)
424+ depth = memdepth * sizeof (int16_t );
425+ if (!m_transport->ReadRawData (depth, (uint8_t *)buf))
407426 return false ;
408427 abuf->MarkModifiedFromCpu ();
409428
@@ -430,26 +449,56 @@ bool ThunderScopeOscilloscope::AcquireData()
430449 }
431450
432451 // Prefer GPU path
433- if (g_hasShaderInt8 && g_hasPushDescriptor)
452+ if (g_hasShaderInt8 && g_hasPushDescriptor && (dataType == DATATYPE_I8))
453+ {
454+ m_cmdBuf->begin ({});
455+
456+ m_conversion8BitPipeline->Bind (*m_cmdBuf);
457+
458+ for (size_t i=0 ; i<awfms.size (); i++)
459+ {
460+ auto cap = awfms[i];
461+
462+ m_conversion8BitPipeline->BindBufferNonblocking (0 , cap->m_samples , *m_cmdBuf, true );
463+ m_conversion8BitPipeline->BindBufferNonblocking (1 , *m_analogRawWaveformBuffers[achans[i]], *m_cmdBuf);
464+
465+ ConvertRawSamplesShaderArgs args;
466+ args.size = cap->size ();
467+ args.gain = scales[i];
468+ args.offset = -offsets[i];
469+
470+ const uint32_t compute_block_count = GetComputeBlockCount (cap->size (), 64 );
471+ m_conversion8BitPipeline->DispatchNoRebind (
472+ *m_cmdBuf, args,
473+ min (compute_block_count, 32768u ),
474+ compute_block_count / 32768 + 1 );
475+
476+ cap->MarkModifiedFromGpu ();
477+ }
478+
479+ m_cmdBuf->end ();
480+ m_queue->SubmitAndBlock (*m_cmdBuf);
481+ }
482+ else if (g_hasShaderInt16 && g_hasPushDescriptor && (dataType == DATATYPE_I16))
434483 {
435484 m_cmdBuf->begin ({});
436485
437- m_conversionPipeline ->Bind (*m_cmdBuf);
486+ m_conversion16BitPipeline ->Bind (*m_cmdBuf);
438487
439488 for (size_t i=0 ; i<awfms.size (); i++)
440489 {
441490 auto cap = awfms[i];
442491
443- m_conversionPipeline ->BindBufferNonblocking (0 , cap->m_samples , *m_cmdBuf, true );
444- m_conversionPipeline ->BindBufferNonblocking (1 , *m_analogRawWaveformBuffers[achans[i]], *m_cmdBuf);
492+ m_conversion16BitPipeline ->BindBufferNonblocking (0 , cap->m_samples , *m_cmdBuf, true );
493+ m_conversion16BitPipeline ->BindBufferNonblocking (1 , *m_analogRawWaveformBuffers[achans[i]], *m_cmdBuf);
445494
446495 ConvertRawSamplesShaderArgs args;
447496 args.size = cap->size ();
448497 args.gain = scales[i];
449498 args.offset = -offsets[i];
450499
451500 const uint32_t compute_block_count = GetComputeBlockCount (cap->size (), 64 );
452- m_conversionPipeline ->DispatchNoRebind (
501+ m_conversion16BitPipeline ->DispatchNoRebind (
453502 *m_cmdBuf, args,
454503 min (compute_block_count, 32768u ),
455504 compute_block_count / 32768 + 1 );
@@ -470,12 +519,24 @@ bool ThunderScopeOscilloscope::AcquireData()
470519 {
471520 auto cap = awfms[i];
472521 cap->PrepareForCpuAccess ();
473- Convert8BitSamples (
474- (float *)&cap->m_samples [0 ],
475- (int8_t *)m_analogRawWaveformBuffers[achans[i]]->GetCpuPointer (),
476- scales[i],
477- offsets[i],
478- cap->m_samples .size ());
522+ if (dataType == DATATYPE_I8)
523+ {
524+ Convert8BitSamples (
525+ (float *)&cap->m_samples [0 ],
526+ (int8_t *)m_analogRawWaveformBuffers[achans[i]]->GetCpuPointer (),
527+ scales[i],
528+ offsets[i],
529+ cap->m_samples .size ());
530+ }
531+ else if (dataType == DATATYPE_I16)
532+ {
533+ Convert16BitSamples (
534+ (float *)&cap->m_samples [0 ],
535+ (int16_t *)m_analogRawWaveformBuffers[achans[i]]->GetCpuPointer (),
536+ scales[i],
537+ offsets[i],
538+ cap->m_samples .size ());
539+ }
479540 cap->MarkModifiedFromCpu ();
480541 }
481542 }
0 commit comments