6#include <unordered_set>
11#include "shader/general/resource/binding/ShaderResourceBinding.h"
12#include "render/directx/descriptors/DirectXDescriptorHeap.h"
13#include "render/general/pipeline/PipelineShaderConstantsManager.hpp"
14#include "render/directx/resource/DirectXResource.h"
43 Error error(std::format(
44 "shader resource \"{}\" was requested to set its root constant "
45 "index but this shader resource does not reference the specified pipeline",
54 unsigned int iRootConstantValue = 0;
58 const auto pDirectXTexture =
62 const auto pSrvDescriptor = pDirectXTexture->
getDescriptor(DirectXDescriptorType::SRV);
63 if (pSrvDescriptor ==
nullptr) [[unlikely]] {
64 Error error(std::format(
65 "shader resource \"{}\" was requested to set its root constant "
66 "index but used texture \"{}\" does not seem to have an SRV bound",
68 pDirectXTexture->getResourceName()));
76 auto result = pSrvDescriptor->getOffsetFromRangeStartOnCurrentFrame();
77 if (std::holds_alternative<Error>(result)) [[unlikely]] {
78 auto error = std::get<Error>(std::move(result));
79 error.addCurrentLocationToErrorStack();
81 throw std::runtime_error(error.getFullErrorMessage());
84 iRootConstantValue = std::get<unsigned int>(result);
102 [[nodiscard]]
virtual std::optional<Error>
103 useNewTexture(std::unique_ptr<TextureHandle> pTextureToUse)
override;
121 [[nodiscard]]
virtual std::optional<Error>
137 const std::string& sResourceName,
138 std::unique_ptr<TextureHandle> pTextureToUse,
139 std::unordered_map<DirectXPso*, size_t>&& shaderConstantOffsetPerPipeline);
163 static std::variant<std::unique_ptr<ShaderTextureResourceBinding>,
Error>
create(
165 const std::unordered_set<Pipeline*>& pipelinesToUse,
166 std::unique_ptr<TextureHandle> pTextureToUse);
177 static std::variant<std::shared_ptr<ContinuousDirectXDescriptorRange>,
Error>
184 std::pair<std::recursive_mutex, std::unordered_map<DirectXPso*, size_t>>
Definition: DirectXPso.h:22
Definition: DirectXResource.h:32
DirectXDescriptor * getDescriptor(DirectXDescriptorType descriptorType)
Definition: DirectXResource.cpp:182
std::string getFullErrorMessage() const
Definition: Error.cpp:84
void showError() const
Definition: Error.cpp:102
Definition: HlslShaderTextureResourceBinding.h:22
void copyResourceIndexToRootConstants(PipelineShaderConstantsManager *pShaderConstantsManager, DirectXPso *pUsedPipeline)
Definition: HlslShaderTextureResourceBinding.h:35
std::pair< std::recursive_mutex, std::unordered_map< DirectXPso *, size_t > > mtxShaderConstantOffsetPerPipeline
Definition: HlslShaderTextureResourceBinding.h:185
static std::variant< std::shared_ptr< ContinuousDirectXDescriptorRange >, Error > getSrvDescriptorRange(DirectXPso *pPipeline, const std::string &sShaderResourceName)
Definition: HlslShaderTextureResourceBinding.cpp:17
virtual std::optional< Error > changeUsedPipelines(const std::unordered_set< Pipeline * > &pipelinesToUse) override
Definition: HlslShaderTextureResourceBinding.cpp:232
static std::variant< std::unique_ptr< ShaderTextureResourceBinding >, Error > create(const std::string &sShaderResourceName, const std::unordered_set< Pipeline * > &pipelinesToUse, std::unique_ptr< TextureHandle > pTextureToUse)
Definition: HlslShaderTextureResourceBinding.cpp:76
std::pair< std::mutex, std::unique_ptr< TextureHandle > > mtxUsedTexture
Definition: HlslShaderTextureResourceBinding.h:181
virtual std::optional< Error > useNewTexture(std::unique_ptr< TextureHandle > pTextureToUse) override
Definition: HlslShaderTextureResourceBinding.cpp:186
static constexpr bool bBindSrvToCubemapFaces
Definition: HlslShaderTextureResourceBinding.h:191
virtual std::optional< Error > onAfterAllPipelinesRefreshedResources() override
Definition: HlslShaderTextureResourceBinding.cpp:166
Definition: PipelineShaderConstantsManager.hpp:14
void copyValueToShaderConstant(size_t iShaderConstantIndex, unsigned int iValueToCopy)
Definition: PipelineShaderConstantsManager.hpp:75
std::string getShaderResourceName() const
Definition: ShaderResourceBinding.cpp:11
const std::string sShaderResourceName
Definition: ShaderResourceBinding.h:82
Definition: ShaderTextureResourceBindingManager.h:27
Definition: ShaderResourceBinding.h:86