ShaderModuleVk.h#

The PVRVk ShaderModule class.

Includes#

  • PVRVk/DeviceVk.h

Included By#

Namespaces#

Classes#

Source Code#

#pragma once
#include "PVRVk/DeviceVk.h"

namespace pvrvk {
struct ShaderModuleCreateInfo
{
public:
    inline ShaderModuleCreateInfo(ShaderModuleCreateFlags flags = ShaderModuleCreateFlags::e_NONE) : _flags(flags) {}

    inline ShaderModuleCreateInfo(const std::vector<uint32_t>& shaderSources, ShaderModuleCreateFlags flags = ShaderModuleCreateFlags::e_NONE)
        : _flags(flags), _shaderSources(shaderSources)
    {
        if (_shaderSources.empty()) { throw ErrorValidationFailedEXT("Attempted to create ShaderModuleCreateInfo with empty shader source."); }
    }

    inline ShaderModuleCreateInfo(const uint32_t* shaderSources, uint32_t shaderSourcesSize, ShaderModuleCreateFlags flags = ShaderModuleCreateFlags::e_NONE)
        : _flags(flags), _shaderSources(shaderSources, shaderSources + shaderSourcesSize)
    {
        if (_shaderSources.empty()) { throw ErrorValidationFailedEXT("Attempted to create ShaderModuleCreateInfo with empty shader source."); }
    }

    inline ShaderModuleCreateFlags getFlags() const { return _flags; }
    inline void setFlags(ShaderModuleCreateFlags flags) { this->_flags = flags; }
    inline uint32_t getCodeSize() const { return static_cast<uint32_t>(_shaderSources.size() * 4.0); }
    inline const std::vector<uint32_t>& getShaderSources() const { return _shaderSources; }
    inline void setShaderSources(const std::vector<uint32_t>& shaderSources) { this->_shaderSources = shaderSources; }

private:
    ShaderModuleCreateFlags _flags;
    std::vector<uint32_t> _shaderSources;
};
namespace impl {
class ShaderModule_ : public PVRVkDeviceObjectBase<VkShaderModule, ObjectType::e_SHADER_MODULE>, public DeviceObjectDebugUtils<ShaderModule_>
{
private:
    friend class Device_;

    class make_shared_enabler
    {
    protected:
        make_shared_enabler() {}
        friend class ShaderModule_;
    };

    static ShaderModule constructShared(const DeviceWeakPtr& device, const ShaderModuleCreateInfo& createInfo)
    {
        return std::make_shared<ShaderModule_>(make_shared_enabler{}, device, createInfo);
    }

    ShaderModuleCreateInfo _createInfo;

public:
    DECLARE_NO_COPY_SEMANTICS(ShaderModule_)
    ShaderModule_(make_shared_enabler, const DeviceWeakPtr& device, const ShaderModuleCreateInfo& createInfo);

    ~ShaderModule_();

    inline ShaderModuleCreateFlags getFlags() const { return _createInfo.getFlags(); }
    inline uint32_t getCodeSize() const { return _createInfo.getCodeSize(); }
    inline const std::vector<uint32_t>& getShaderSources() const { return _createInfo.getShaderSources(); }
    ShaderModuleCreateInfo getCreateInfo() const { return _createInfo; }
};
} // namespace impl
} // namespace pvrvk