yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
5.2 KiB162 linesraw
1// cuda-command-encoder.h
2#pragma once
3#include "cuda-base.h"
4
5namespace gfx
6{
7#ifdef GFX_ENABLE_CUDA
8using namespace Slang;
9
10namespace cuda
11{
12
13class ResourceCommandEncoderImpl : public IResourceCommandEncoder
14{
15public:
16    CommandWriter* m_writer;
17
18    virtual void* getInterface(SlangUUID const& uuid)
19    {
20        if (uuid == GfxGUID::IID_IResourceCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
21            return this;
22        return nullptr;
23    }
24    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
25    queryInterface(SlangUUID const& uuid, void** outObject) override
26    {
27        if (auto ptr = getInterface(uuid))
28        {
29            *outObject = ptr;
30            return SLANG_OK;
31        }
32        return SLANG_E_NO_INTERFACE;
33    }
34    virtual SLANG_NO_THROW uint32_t SLANG_MCALL addRef() override { return 1; }
35    virtual SLANG_NO_THROW uint32_t SLANG_MCALL release() override { return 1; }
36
37    void init(CommandBufferImpl* cmdBuffer);
38
39    virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override {}
40    virtual SLANG_NO_THROW void SLANG_MCALL copyBuffer(
41        IBufferResource* dst,
42        Offset dstOffset,
43        IBufferResource* src,
44        Offset srcOffset,
45        Size size) override;
46
47    virtual SLANG_NO_THROW void SLANG_MCALL textureBarrier(
48        GfxCount count,
49        ITextureResource* const* textures,
50        ResourceState src,
51        ResourceState dst) override
52    {
53    }
54
55    virtual SLANG_NO_THROW void SLANG_MCALL bufferBarrier(
56        GfxCount count,
57        IBufferResource* const* buffers,
58        ResourceState src,
59        ResourceState dst) override
60    {
61    }
62
63    virtual SLANG_NO_THROW void SLANG_MCALL
64    uploadBufferData(IBufferResource* dst, Offset offset, Size size, void* data) override;
65
66    virtual SLANG_NO_THROW void SLANG_MCALL
67    writeTimestamp(IQueryPool* pool, GfxIndex index) override;
68
69    virtual SLANG_NO_THROW void SLANG_MCALL copyTexture(
70        ITextureResource* dst,
71        ResourceState dstState,
72        SubresourceRange dstSubresource,
73        ITextureResource::Offset3D dstOffset,
74        ITextureResource* src,
75        ResourceState srcState,
76        SubresourceRange srcSubresource,
77        ITextureResource::Offset3D srcOffset,
78        ITextureResource::Extents extent) override;
79
80    virtual SLANG_NO_THROW void SLANG_MCALL uploadTextureData(
81        ITextureResource* dst,
82        SubresourceRange subResourceRange,
83        ITextureResource::Offset3D offset,
84        ITextureResource::Extents extent,
85        ITextureResource::SubresourceData* subResourceData,
86        GfxCount subResourceDataCount) override;
87
88    virtual SLANG_NO_THROW void SLANG_MCALL clearResourceView(
89        IResourceView* view,
90        ClearValue* clearValue,
91        ClearResourceViewFlags::Enum flags) override;
92
93    virtual SLANG_NO_THROW void SLANG_MCALL resolveResource(
94        ITextureResource* source,
95        ResourceState sourceState,
96        SubresourceRange sourceRange,
97        ITextureResource* dest,
98        ResourceState destState,
99        SubresourceRange destRange) override;
100
101    virtual SLANG_NO_THROW void SLANG_MCALL resolveQuery(
102        IQueryPool* queryPool,
103        GfxIndex index,
104        GfxCount count,
105        IBufferResource* buffer,
106        Offset offset) override;
107
108    virtual SLANG_NO_THROW void SLANG_MCALL copyTextureToBuffer(
109        IBufferResource* dst,
110        Offset dstOffset,
111        Size dstSize,
112        Size dstRowStride,
113        ITextureResource* src,
114        ResourceState srcState,
115        SubresourceRange srcSubresource,
116        ITextureResource::Offset3D srcOffset,
117        ITextureResource::Extents extent) override;
118
119    virtual SLANG_NO_THROW void SLANG_MCALL textureSubresourceBarrier(
120        ITextureResource* texture,
121        SubresourceRange subresourceRange,
122        ResourceState src,
123        ResourceState dst) override;
124    virtual SLANG_NO_THROW void SLANG_MCALL
125    beginDebugEvent(const char* name, float rgbColor[3]) override;
126    virtual SLANG_NO_THROW void SLANG_MCALL endDebugEvent() override {}
127};
128
129class ComputeCommandEncoderImpl : public IComputeCommandEncoder, public ResourceCommandEncoderImpl
130{
131public:
132    SLANG_GFX_FORWARD_RESOURCE_COMMAND_ENCODER_IMPL(ResourceCommandEncoderImpl)
133    virtual void* getInterface(SlangUUID const& uuid) override
134    {
135        if (uuid == GfxGUID::IID_IResourceCommandEncoder ||
136            uuid == GfxGUID::IID_IComputeCommandEncoder || uuid == ISlangUnknown::getTypeGuid())
137            return this;
138        return nullptr;
139    }
140
141public:
142    CommandWriter* m_writer;
143    CommandBufferImpl* m_commandBuffer;
144    RefPtr<ShaderObjectBase> m_rootObject;
145    virtual SLANG_NO_THROW void SLANG_MCALL endEncoding() override {}
146    void init(CommandBufferImpl* cmdBuffer);
147
148    virtual SLANG_NO_THROW Result SLANG_MCALL
149    bindPipeline(IPipelineState* state, IShaderObject** outRootObject) override;
150
151    virtual SLANG_NO_THROW Result SLANG_MCALL
152    bindPipelineWithRootObject(IPipelineState* state, IShaderObject* rootObject) override;
153
154    virtual SLANG_NO_THROW Result SLANG_MCALL dispatchCompute(int x, int y, int z) override;
155
156    virtual SLANG_NO_THROW Result SLANG_MCALL
157    dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset) override;
158};
159
160} // namespace cuda
161#endif
162} // namespace gfx