LCOV - code coverage report
Current view: top level - xenolith/utils/shadernn/src/backend/vk - XLSnnVkInputLayer.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 14 42.9 %
Date: 2024-05-06 04:51:23 Functions: 7 17 41.2 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef SRC_BACKEND_VK_XLSNNVKINPUTLAYER_H_
      24             : #define SRC_BACKEND_VK_XLSNNVKINPUTLAYER_H_
      25             : 
      26             : #include "XLVkRenderPass.h"
      27             : #include "XLVkQueuePass.h"
      28             : #include "XLVkAttachment.h"
      29             : #include "XLSnnInputLayer.h"
      30             : 
      31             : namespace stappler::xenolith::vk::shadernn {
      32             : 
      33             : struct NormData {
      34             :         Vec4 mean = Vec4::ZERO;
      35             :         Vec4 norm = Vec4::ONE;
      36             : };
      37             : 
      38             : struct InputDataInput : core::AttachmentInputData {
      39             :         NormData norm;
      40             :         core::ImageData image;
      41             : };
      42             : 
      43             : struct InputBufferDataInput : core::AttachmentInputData {
      44             :         core::BufferData buffer;
      45             : };
      46             : 
      47             : struct InputCsvInput : core::AttachmentInputData {
      48             :         SpanView<Value> data;
      49             : };
      50             : class InputLayer : public vk::QueuePass {
      51             : public:
      52             :         virtual ~InputLayer();
      53             : 
      54             :         virtual bool init(Queue::Builder &queueBuilder, QueuePassBuilder &, const AttachmentData *input, const AttachmentData *output);
      55             : 
      56           0 :         const AttachmentData *getInputAttachment() const { return _inputAttachment; }
      57           0 :         const AttachmentData *getOutputAttachment() const { return _outputAttachment; }
      58           2 :         const AttachmentData *getDataAttachment() const { return _dataAttachment; }
      59             : 
      60             :         class LayerHandle : public vk::QueuePassHandle {
      61             :         public:
      62           0 :                 virtual ~LayerHandle() = default;
      63             : 
      64             :                 virtual bool prepare(FrameQueue &q, Function<void(bool)> &&cb) override;
      65             : 
      66             :         protected:
      67             :                 void doTransferInput(vk::CommandBuffer &buf, DeviceFrameHandle &handle, InputDataInput *);
      68             : 
      69             :                 virtual Vector<const vk::CommandBuffer *> doPrepareCommands(FrameHandle &) override;
      70             : 
      71             :                 const vk::ImageAttachmentHandle *_inputImage = nullptr;
      72             :                 const vk::ImageAttachmentHandle *_outputImage = nullptr;
      73             :                 const core::AttachmentHandle *_dataHandle = nullptr;
      74             :         };
      75             : 
      76             : protected:
      77             :         using QueuePass::init;
      78             : 
      79             :         const AttachmentData *_inputAttachment = nullptr;
      80             :         const AttachmentData *_outputAttachment = nullptr;
      81             :         const AttachmentData *_dataAttachment = nullptr;
      82             : };
      83             : 
      84             : class InputBufferLayer : public vk::QueuePass {
      85             : public:
      86             :         using Front = xenolith::shadernn::InputBufferLayer;
      87             : 
      88             :         virtual ~InputBufferLayer();
      89             : 
      90             :         virtual bool init(Queue::Builder &queueBuilder, QueuePassBuilder &, Front *,
      91             :                         const AttachmentData *input, const AttachmentData *output);
      92             : 
      93        2400 :         const AttachmentData *getInputAttachment() const { return _inputAttachment; }
      94        2400 :         const AttachmentData *getOutputAttachment() const { return _outputAttachment; }
      95        2400 :         const AttachmentData *getDataAttachment() const { return _dataAttachment; }
      96             : 
      97        2400 :         const Front *getFront() const { return _front; }
      98             : 
      99             :         class LayerHandle : public vk::QueuePassHandle {
     100             :         public:
     101        4800 :                 virtual ~LayerHandle() = default;
     102             : 
     103             :                 virtual bool prepare(FrameQueue &q, Function<void(bool)> &&cb) override;
     104             : 
     105             :         protected:
     106             :                 virtual Vector<const vk::CommandBuffer *> doPrepareCommands(FrameHandle &) override;
     107             : 
     108             :                 vk::BufferAttachmentHandle *_inputBuffer = nullptr;
     109             :                 vk::BufferAttachmentHandle *_outputBuffer = nullptr;
     110             :                 vk::BufferAttachmentHandle *_dataHandle = nullptr;
     111             :                 const Front *_front = nullptr;
     112             :         };
     113             : 
     114             : protected:
     115             :         using QueuePass::init;
     116             : 
     117             :         const AttachmentData *_inputAttachment = nullptr;
     118             :         const AttachmentData *_outputAttachment = nullptr;
     119             :         const AttachmentData *_dataAttachment = nullptr;
     120             : 
     121             :         Rc<Front> _front;
     122             : };
     123             : 
     124             : class InputCsvIntLayer : public vk::QueuePass {
     125             : public:
     126             :         using Front = xenolith::shadernn::InputCsvIntLayer;
     127             : 
     128             :         virtual ~InputCsvIntLayer();
     129             : 
     130             :         virtual bool init(Queue::Builder &queueBuilder, QueuePassBuilder &, Front *,
     131             :                         const AttachmentData *input, const AttachmentData *output);
     132             : 
     133           0 :         const AttachmentData *getInputAttachment() const { return _inputAttachment; }
     134           0 :         const AttachmentData *getOutputAttachment() const { return _outputAttachment; }
     135           0 :         const AttachmentData *getDataAttachment() const { return _dataAttachment; }
     136             : 
     137           0 :         const Front *getFront() const { return _front; }
     138             : 
     139             :         class LayerHandle : public vk::QueuePassHandle {
     140             :         public:
     141           0 :                 virtual ~LayerHandle() = default;
     142             : 
     143             :                 virtual bool prepare(FrameQueue &q, Function<void(bool)> &&cb) override;
     144             : 
     145             :         protected:
     146             :                 virtual Vector<const vk::CommandBuffer *> doPrepareCommands(FrameHandle &) override;
     147             : 
     148             :                 vk::BufferAttachmentHandle *_inputBuffer = nullptr;
     149             :                 vk::BufferAttachmentHandle *_outputBuffer = nullptr;
     150             :                 vk::BufferAttachmentHandle *_dataHandle = nullptr;
     151             :                 const Front *_front = nullptr;
     152             :         };
     153             : 
     154             : protected:
     155             :         using QueuePass::init;
     156             : 
     157             :         const AttachmentData *_inputAttachment = nullptr;
     158             :         const AttachmentData *_outputAttachment = nullptr;
     159             :         const AttachmentData *_dataAttachment = nullptr;
     160             : 
     161             :         Rc<Front> _front;
     162             : };
     163             : 
     164             : }
     165             : 
     166             : #endif /* SRC_BACKEND_VK_XLSNNVKINPUTLAYER_H_ */

Generated by: LCOV version 1.14