//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// #pragma once #include "BsCorePrerequisites.h" #include "BsMaterial.h" #include "BsShader.h" #include "BsPass.h" namespace BansheeEngine { /** @addtogroup Implementation * @{ */ template struct TGpuParamsType { }; template<> struct TGpuParamsType { typedef GpuParams Type; }; template<> struct TGpuParamsType { typedef GpuParamsCore Type; }; /** Contains a set of GpuParams used for a single technique within a Material. */ template class BS_CORE_EXPORT TGpuParamsSet { typedef typename TGpuParamsType::Type GpuParamsType; typedef typename TMaterialParamsType::Type MaterialParamsType; typedef typename TGpuParamBlockBufferPtrType::Type ParamBlockPtrType; typedef typename TTechniqueType::Type TechniqueType; typedef typename TShaderType::Type ShaderType; typedef typename TPassType::Type PassType; typedef typename TGpuProgramType::Type GpuProgramPtrType; typedef typename TGpuParamBlockBufferType::Type ParamBlockType; typedef typename TGpuParamTextureType::Type TextureType; typedef typename TGpuBufferType::Type BufferType; typedef typename TGpuParamSamplerStateType::Type SamplerStateType; typedef typename TPassTypes::GraphicsPipelineStateType GraphicsPipelineStateType; typedef typename TPassTypes::ComputePipelineStateType ComputePipelineStateType; /** Information about a parameter block buffer. */ struct BlockInfo { BlockInfo(const String& name, const ParamBlockPtrType& buffer, bool shareable) :name(name), buffer(buffer), shareable(shareable), allowUpdate(true), isUsed(true) { } String name; ParamBlockPtrType buffer; bool shareable; bool allowUpdate; bool isUsed; }; /** Information about how a data parameter maps from a material parameter into a parameter block buffer. */ struct DataParamInfo { UINT32 paramIdx; UINT32 blockIdx; UINT32 offset; }; /** Information about how an object parameter maps from a material parameter to a GPU stage slot. */ struct ObjectParamInfo { UINT32 paramIdx; UINT32 slotIdx; UINT32 setIdx; }; /** Information about all object parameters for a specific GPU programmable stage. */ struct StageParamInfo { ObjectParamInfo* textures; UINT32 numTextures; ObjectParamInfo* loadStoreTextures; UINT32 numLoadStoreTextures; ObjectParamInfo* buffers; UINT32 numBuffers; ObjectParamInfo* samplerStates; UINT32 numSamplerStates; }; /** Information about all object parameters for a specific pass. */ struct PassParamInfo { StageParamInfo stages[6]; }; public: TGpuParamsSet() {} TGpuParamsSet(const SPtr& technique, const ShaderType& shader, const SPtr& params); ~TGpuParamsSet(); /** * Returns a set of GPU parameters for the specified pass. * * @param[in] passIdx Pass in which to look the GPU program for in. * @return GPU parameters object that can be used for setting parameters of all GPU programs * in a pass. Returns null if pass doesn't exist. */ SPtr getGpuParams(UINT32 passIdx = 0); /** * Assign a parameter block buffer with the specified name to all the relevant child GpuParams. * * @param[in] name Name of the buffer to set. * @param[in] paramBlock Parameter block to assign. * @param[in] ignoreInUpdate If true the buffer will not be updated during the update() call. This is useful * if the caller wishes to manually update the buffer contents externally, to prevent * overwriting manually written data during update. * * @note * Parameter block buffers can be used as quick way of setting multiple parameters on a material at once, or * potentially sharing parameters between multiple materials. This reduces driver overhead as the parameters * in the buffers need only be set once and then reused multiple times. */ void setParamBlockBuffer(const String& name, const ParamBlockPtrType& paramBlock, bool ignoreInUpdate = false); /** Returns the number of passes the set contains the parameters for. */ UINT32 getNumPasses() const { return (UINT32)mPassParams.size(); } /** * Updates internal GPU params for all passes and stages from the provided material parameters object. * * @param[in] params Object containing the parameter data to update from. Layout of the object must match the * object used for creating this object (be created for the same shader). * @param[in] dirtyBitIdx Index to use when checking if parameters are dirty. Must be in range [0, 31]. Allows * the same material params to record dirty state for multiple sets of GPU params * (each with their own index). * @param[in] updateAll By default the system will only update parameters marked as dirty in @p params. If this * is set to true, all parameters will be updated instead. */ void update(const SPtr& params, UINT32 dirtyBitIdx, bool updateAll = false); static const UINT32 NUM_STAGES; private: template friend class TMaterial; Vector> mPassParams; Vector mBlocks; Vector mDataParamInfos; PassParamInfo* mPassParamInfos; }; /** Sim thread version of TGpuParamsSet. */ class BS_CORE_EXPORT GpuParamsSet : public TGpuParamsSet { public: GpuParamsSet() { } GpuParamsSet(const SPtr& technique, const HShader& shader, const SPtr& params) :TGpuParamsSet(technique, shader, params) { } }; /** Core thread version of TGpuParamsSet. */ class BS_CORE_EXPORT GpuParamsSetCore : public TGpuParamsSet { public: GpuParamsSetCore() { } GpuParamsSetCore(const SPtr& technique, const SPtr& shader, const SPtr& params) :TGpuParamsSet(technique, shader, params) { } }; /** @} */ }