diff options
Diffstat (limited to 'tools/render-test/shader-input-layout.h')
| -rw-r--r-- | tools/render-test/shader-input-layout.h | 190 |
1 files changed, 136 insertions, 54 deletions
diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h index 01ef5c443..60582aed8 100644 --- a/tools/render-test/shader-input-layout.h +++ b/tools/render-test/shader-input-layout.h @@ -14,8 +14,14 @@ using namespace gfx; enum class ShaderInputType { - Buffer, Texture, Sampler, CombinedTextureSampler, Array, Uniform, + Buffer, + Texture, + Sampler, + CombinedTextureSampler, + Array, + UniformData, Object, + Aggregate, }; enum class InputTextureContent @@ -40,13 +46,14 @@ struct InputTextureDesc enum class InputBufferType { - ConstantBuffer, StorageBuffer, - RootConstantBuffer, +// ConstantBuffer, + StorageBuffer, +// RootConstantBuffer, }; struct InputBufferDesc { - InputBufferType type = InputBufferType::ConstantBuffer; + InputBufferType type = InputBufferType::StorageBuffer; int stride = 0; // stride == 0 indicates an unstructured buffer. Format format = Format::Unknown; }; @@ -56,52 +63,6 @@ struct InputSamplerDesc bool isCompareSampler = false; }; -struct ArrayDesc -{ - int size = 0; -}; - -enum class RTTIDataEntryType -{ - RTTIObject, WitnessTable -}; -struct RTTIDataEntry -{ - RTTIDataEntryType type; - Slang::String typeName; - Slang::String interfaceName; - unsigned int offset; -}; - -struct BindlessHandleDataEntry -{ - unsigned int offset; - Slang::String name; -}; - -struct InputObjectDesc -{ - Slang::String typeName; -}; - -class ShaderInputLayoutEntry -{ -public: - ShaderInputType type; - Slang::List<unsigned int> bufferData; - Slang::List<RTTIDataEntry> rttiEntries; - Slang::List<BindlessHandleDataEntry> bindlessHandleEntry; - InputTextureDesc textureDesc; - InputBufferDesc bufferDesc; - InputSamplerDesc samplerDesc; - ArrayDesc arrayDesc; - InputObjectDesc objectDesc; - bool isOutput = false; - bool onlyCPULikeBinding = false; ///< If true, only use on targets that have 'uniform' or 'CPU like' binding, like CPU and CUDA - bool isBindlessObject = false; ///< If true, this is a bindless object with no associated binding point in the shader. - Slang::String name; ///< Optional name. Useful for binding through reflection. -}; - struct TextureData { Slang::List<Slang::List<unsigned int>> dataBuffer; @@ -113,19 +74,140 @@ struct TextureData class ShaderInputLayout { public: - Slang::List<ShaderInputLayoutEntry> entries; + class Val : public Slang::RefObject + { + public: + Val(ShaderInputType kind) + : kind(kind) + {} + + ShaderInputType kind; + bool isOutput = false; + }; + typedef Slang::RefPtr<Val> ValPtr; + + class TextureVal : public Val + { + public: + TextureVal() + : Val(ShaderInputType::Texture) + {} + + InputTextureDesc textureDesc; + }; + + class DataValBase : public Val + { + public: + DataValBase(ShaderInputType kind) + : Val(kind) + {} + + Slang::List<unsigned int> bufferData; + }; + + class BufferVal : public DataValBase + { + public: + BufferVal() + : DataValBase(ShaderInputType::Buffer) + {} + + InputBufferDesc bufferDesc; + }; + + class DataVal : public DataValBase + { + public: + DataVal() + : DataValBase(ShaderInputType::UniformData) + {} + }; + + class SamplerVal : public Val + { + public: + SamplerVal() + : Val(ShaderInputType::Sampler) + {} + + InputSamplerDesc samplerDesc; + }; + + class CombinedTextureSamplerVal : public Val + { + public: + CombinedTextureSamplerVal() + : Val(ShaderInputType::CombinedTextureSampler) + {} + + Slang::RefPtr<TextureVal> textureVal; + Slang::RefPtr<SamplerVal> samplerVal; + }; + + struct Field + { + Slang::String name; + ValPtr val; + }; + typedef Field Entry; + + class ParentVal : public Val + { + public: + ParentVal(ShaderInputType kind) + : Val(kind) + {} + + virtual void addField(Field const& field) = 0; + }; + + class AggVal : public ParentVal + { + public: + AggVal(ShaderInputType kind = ShaderInputType::Aggregate) + : ParentVal(kind) + {} + + Slang::List<Field> fields; + + virtual void addField(Field const& field) override; + }; + + class ObjectVal : public Val + { + public: + ObjectVal() + : Val(ShaderInputType::Object) + {} + + Slang::String typeName; + ValPtr contentVal; + }; + + class ArrayVal : public ParentVal + { + public: + ArrayVal() + : ParentVal(ShaderInputType::Array) + {} + + Slang::List<ValPtr> vals; + + virtual void addField(Field const& field) override; + }; + + Slang::RefPtr<AggVal> rootVal; Slang::List<Slang::String> globalSpecializationArgs; Slang::List<Slang::String> entryPointSpecializationArgs; int numRenderTargets = 1; Slang::Index findEntryIndexByName(const Slang::String& name) const; - void updateForTarget(SlangCompileTarget target); - void parse(Slang::RandomGenerator* rand, const char* source); /// Writes a binding, if bindRoot is set, will try to honor the underlying type when outputting. If not will dump as uint32_t hex. - static SlangResult writeBinding(const ShaderInputLayoutEntry& entry, slang::TypeLayoutReflection* typeLayout, const void* data, size_t sizeInBytes, Slang::WriterHelper writer); + static SlangResult writeBinding(slang::TypeLayoutReflection* typeLayout, const void* data, size_t sizeInBytes, Slang::WriterHelper writer); }; void generateTextureDataRGB8(TextureData& output, const InputTextureDesc& desc); |
