Skip to content

processors/processing_processor.hpp

Namespaces

Name
sgns
sgns::sgprocessing
Artifact and manifest binary serialization.

Classes

Name
struct sgns::sgprocessing::ProcessingError
struct sgns::sgprocessing::ProcessingResult
class sgns::sgprocessing::ProcessingProcessor

Types

Name
enum class ProcessingErrorStage

Types Documentation

enum ProcessingErrorStage

Enumerator Value Description
UNSPECIFIED 0
CONTEXT_INIT_FAILED
RESOURCE_RESOLUTION
BUFFER_ALLOCATION
IMAGE_ALLOCATION
FORMAT_UNSUPPORTED
SHADER_MODULE_CREATION
PIPELINE_CREATION
RENDER_PASS_CREATION
DRAW_SUBMISSION
READBACK
DATA_TRANSFORM_UNSUPPORTED
CANCELLED 12 Processor cancelled via CancellationToken (D-05: distinct error code)
TIMED_OUT 13 Per-pass deadline expired (D-02, D-05)
BUDGET_EXCEEDED 14 Output artifact size exceeded max_output_artifact_bytes (EXEC-03)

Per-stage failure classification for structured processor errors (D-25/D-26). Plain, non-outcome::result enum – StartProcessing()'s return type stays the concrete ProcessingResult, so the OUTCOME_HPP_DECLARE_ERROR_2 machinery is unnecessary here.

Source code

#ifndef PROCESSING_PROCESSOR_HPP
#define PROCESSING_PROCESSOR_HPP

#include <cmath>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include <SGNSProcMain.hpp>
#include <util/sgprocmgr-logger.hpp>
#include <execution/execution_context.hpp>

namespace sgns::sgprocessing
{
    enum class ProcessingErrorStage
    {
        UNSPECIFIED = 0,
        CONTEXT_INIT_FAILED,
        RESOURCE_RESOLUTION,
        BUFFER_ALLOCATION,
        IMAGE_ALLOCATION,
        FORMAT_UNSUPPORTED,
        SHADER_MODULE_CREATION,
        PIPELINE_CREATION,
        RENDER_PASS_CREATION,
        DRAW_SUBMISSION,
        READBACK,
        DATA_TRANSFORM_UNSUPPORTED,
        CANCELLED       = 12,  
        TIMED_OUT       = 13,  
        BUDGET_EXCEEDED = 14   
    };

    struct ProcessingError
    {
        ProcessingErrorStage stage = ProcessingErrorStage::UNSPECIFIED;
        std::string          message;
    };

    struct ProcessingResult
    {
        std::vector<uint8_t> hash;
        std::shared_ptr<std::pair<std::vector<std::string>, std::vector<std::vector<char>>>> output_buffers;
        std::vector<std::string> output_locations;
        std::optional<ProcessingError> error;

        static ProcessingResult FromProcessOutput( const struct ProcessOutput &output );
    };

    class ProcessingProcessor
    {
    public:
        virtual ~ProcessingProcessor() = default;

        virtual ProcessingResult StartProcessing( std::vector<std::vector<uint8_t>> &chunkhashes,
                               const sgns::IoDeclaration         &proc,
                               std::vector<char>                 &imageData,
                               std::vector<char>                 &modelFile,
                               const std::vector<sgns::Parameter> *parameters,
                               const ExecutionContext            &execCtx ) = 0;

        //virtual void SetData(std::shared_ptr<std::pair<std::vector<std::string>, std::vector<std::vector<char>>>> buffers) = 0;

        virtual float GetProgress() const { return m_progress; }

        void RunTeardown()
        {
            for ( auto it = m_teardownFns.rbegin(); it != m_teardownFns.rend(); ++it )
            {
                try
                {
                    ( *it )();
                }
                catch ( ... )
                {
                    // D-17: Teardown functions must be noexcept-safe since
                    // stack unwinding may leave Vulkan objects in unknown
                    // state. Log failure and continue.
                }
            }
            m_teardownFns.clear();
        }

    protected:
        void PushTeardown( std::function<void()> fn )
        {
            m_teardownFns.push_back( std::move( fn ) );
        }

        std::atomic<float> m_progress{0.0f}; // Progress percentage
        sgns::sgprocmanager::Logger m_logger = sgns::sgprocmanager::createLogger( "SGProcessor" );

    private:
        std::vector<std::function<void()>> m_teardownFns; 
    };
}

#endif 

Updated on 2026-10-06 at 13:34:21 +0000