Program Listing for File shader.h

Return to documentation for file (include\playback\experiments\shader.h)

/******************************************************************************
© Intel Corporation.

This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.


 This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.

******************************************************************************/

#pragma once

#include "igpa-config.h"
#include "playback/metadata-extraction/metadata-types.h"

#include <string>
#include <vector>

namespace gpa {
namespace playback {

class Shader final
{
public:
    class Compiler;

    enum class Stage {
        kInvalid,
        kVertex,
        kHull,
        kTesselationControl = kHull,
        kDomain,
        kTesselationEvaluation = kDomain,
        kGeometry,
        kAmplification,
        kMesh,
        kFragment,
        kCompute,
        kLibrary,
        kCount,
    };

    class CompileInfo final
    {
    public:
        Stage stage{Stage::kInvalid};
        api_types::ManagedShaderSource sourceCode;
        std::vector<uint8_t> byteCode;
        std::string shaderProfile;
        void* shaderData{nullptr};
    };

    bool operator==(Shader const& other) const;

    bool operator!=(Shader const& other) const;

    bool operator<(Shader const& other) const;

    Shader::Stage GetStage() const;

    api_types::ShaderLanguage GetLanguage() const;

    void GetSourceCode(size_t* pSizeBytes, char* pSourceCode) const;

    void GetEntryPoint(size_t* pSizeBytes, char* pEntryPoint) const;

    void GetByteCode(size_t* pSizeBytes, uint8_t* pByteCode) const;

    uint32_t GetHash() const;

private:
    Shader::Stage mStage{Shader::Stage::kInvalid};
    api_types::ShaderLanguage mLanguage{api_types::GPA_SHADER_LANGUAGE_UNKNOWN};
    std::string mSourceCode;
    std::string mEntryPoint;
    std::vector<uint8_t> mByteCode;
    uint32_t mHash{0};
};

}  // namespace playback
}  // namespace gpa

namespace std {

template<>
struct hash<gpa::playback::Shader>
{
    inline size_t operator()(gpa::playback::Shader const& shader) const
    {
        return (size_t)shader.GetHash();
    }
};

}  // namespace std