yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
3.0 KiB96 linesraw
1// cuda-shader-object.h
2#pragma once
3#include "cuda-base.h"
4#include "cuda-buffer.h"
5#include "cuda-resource-views.h"
6
7namespace gfx
8{
9#ifdef GFX_ENABLE_CUDA
10using namespace Slang;
11
12namespace cuda
13{
14
15class ShaderObjectData
16{
17public:
18    bool isHostOnly = false;
19    Slang::RefPtr<BufferResourceImpl> m_bufferResource;
20    Slang::RefPtr<ResourceViewImpl> m_bufferView;
21    Slang::List<uint8_t> m_cpuBuffer;
22
23    Result setCount(Index count);
24    Slang::Index getCount();
25    void* getBuffer();
26
27    /// Returns a resource view for GPU access into the buffer content.
28    ResourceViewBase* getResourceView(
29        RendererBase* device,
30        slang::TypeLayoutReflection* elementLayout,
31        slang::BindingType bindingType);
32};
33
34class ShaderObjectImpl
35    : public ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, ShaderObjectData>
36{
37    typedef ShaderObjectBaseImpl<ShaderObjectImpl, ShaderObjectLayoutImpl, ShaderObjectData> Super;
38
39public:
40    List<RefPtr<ResourceViewImpl>> resources;
41
42    virtual SLANG_NO_THROW Result SLANG_MCALL
43    init(IDevice* device, ShaderObjectLayoutImpl* typeLayout);
44
45    virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
46    virtual SLANG_NO_THROW Result SLANG_MCALL
47    getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
48
49    virtual SLANG_NO_THROW const void* SLANG_MCALL getRawData() override;
50
51    virtual SLANG_NO_THROW Size SLANG_MCALL getSize() override;
52
53    virtual SLANG_NO_THROW Result SLANG_MCALL
54    setData(ShaderOffset const& offset, void const* data, Size size) override;
55    virtual SLANG_NO_THROW Result SLANG_MCALL
56    setResource(ShaderOffset const& offset, IResourceView* resourceView) override;
57    virtual SLANG_NO_THROW Result SLANG_MCALL
58    setObject(ShaderOffset const& offset, IShaderObject* object) override;
59    virtual SLANG_NO_THROW Result SLANG_MCALL
60    setSampler(ShaderOffset const& offset, ISamplerState* sampler) override;
61    virtual SLANG_NO_THROW Result SLANG_MCALL setCombinedTextureSampler(
62        ShaderOffset const& offset,
63        IResourceView* textureView,
64        ISamplerState* sampler) override;
65};
66
67class MutableShaderObjectImpl
68    : public MutableShaderObject<MutableShaderObjectImpl, ShaderObjectLayoutImpl>
69{
70};
71
72class EntryPointShaderObjectImpl : public ShaderObjectImpl
73{
74public:
75    EntryPointShaderObjectImpl();
76};
77
78class RootShaderObjectImpl : public ShaderObjectImpl
79{
80public:
81    virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override;
82    virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override;
83
84public:
85    List<RefPtr<EntryPointShaderObjectImpl>> entryPointObjects;
86    virtual SLANG_NO_THROW Result SLANG_MCALL
87    init(IDevice* device, ShaderObjectLayoutImpl* typeLayout) override;
88    virtual SLANG_NO_THROW GfxCount SLANG_MCALL getEntryPointCount() override;
89    virtual SLANG_NO_THROW Result SLANG_MCALL
90    getEntryPoint(GfxIndex index, IShaderObject** outEntryPoint) override;
91    virtual Result collectSpecializationArgs(ExtendedShaderObjectTypeList& args) override;
92};
93
94} // namespace cuda
95#endif
96} // namespace gfx