yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
5.9 KiB217 linesraw
1// cuda-command-encoder.cpp
2#include "cuda-command-encoder.h"
3
4#include "cuda-command-buffer.h"
5#include "cuda-device.h"
6
7namespace gfx
8{
9#ifdef GFX_ENABLE_CUDA
10using namespace Slang;
11
12namespace cuda
13{
14
15void ResourceCommandEncoderImpl::init(CommandBufferImpl* cmdBuffer)
16{
17    m_writer = cmdBuffer;
18}
19
20SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::copyBuffer(
21    IBufferResource* dst,
22    Offset dstOffset,
23    IBufferResource* src,
24    Offset srcOffset,
25    Size size)
26{
27    m_writer->copyBuffer(dst, dstOffset, src, srcOffset, size);
28}
29
30SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::uploadBufferData(
31    IBufferResource* dst,
32    Offset offset,
33    Size size,
34    void* data)
35{
36    m_writer->uploadBufferData(dst, offset, size, data);
37}
38
39SLANG_NO_THROW void SLANG_MCALL
40ResourceCommandEncoderImpl::writeTimestamp(IQueryPool* pool, GfxIndex index)
41{
42    m_writer->writeTimestamp(pool, index);
43}
44
45SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::copyTexture(
46    ITextureResource* dst,
47    ResourceState dstState,
48    SubresourceRange dstSubresource,
49    ITextureResource::Offset3D dstOffset,
50    ITextureResource* src,
51    ResourceState srcState,
52    SubresourceRange srcSubresource,
53    ITextureResource::Offset3D srcOffset,
54    ITextureResource::Extents extent)
55{
56    SLANG_UNUSED(dst);
57    SLANG_UNUSED(dstState);
58    SLANG_UNUSED(dstSubresource);
59    SLANG_UNUSED(dstOffset);
60    SLANG_UNUSED(src);
61    SLANG_UNUSED(srcState);
62    SLANG_UNUSED(srcSubresource);
63    SLANG_UNUSED(srcOffset);
64    SLANG_UNUSED(extent);
65    SLANG_UNIMPLEMENTED_X("copyTexture");
66}
67
68SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::uploadTextureData(
69    ITextureResource* dst,
70    SubresourceRange subResourceRange,
71    ITextureResource::Offset3D offset,
72    ITextureResource::Extents extent,
73    ITextureResource::SubresourceData* subResourceData,
74    GfxCount subResourceDataCount)
75{
76    SLANG_UNUSED(dst);
77    SLANG_UNUSED(subResourceRange);
78    SLANG_UNUSED(offset);
79    SLANG_UNUSED(extent);
80    SLANG_UNUSED(subResourceData);
81    SLANG_UNUSED(subResourceDataCount);
82    SLANG_UNIMPLEMENTED_X("uploadTextureData");
83}
84
85SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::clearResourceView(
86    IResourceView* view,
87    ClearValue* clearValue,
88    ClearResourceViewFlags::Enum flags)
89{
90    SLANG_UNUSED(view);
91    SLANG_UNUSED(clearValue);
92    SLANG_UNUSED(flags);
93    SLANG_UNIMPLEMENTED_X("clearResourceView");
94}
95
96SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::resolveResource(
97    ITextureResource* source,
98    ResourceState sourceState,
99    SubresourceRange sourceRange,
100    ITextureResource* dest,
101    ResourceState destState,
102    SubresourceRange destRange)
103{
104    SLANG_UNUSED(source);
105    SLANG_UNUSED(sourceState);
106    SLANG_UNUSED(sourceRange);
107    SLANG_UNUSED(dest);
108    SLANG_UNUSED(destState);
109    SLANG_UNUSED(destRange);
110    SLANG_UNIMPLEMENTED_X("resolveResource");
111}
112
113SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::resolveQuery(
114    IQueryPool* queryPool,
115    GfxIndex index,
116    GfxCount count,
117    IBufferResource* buffer,
118    Offset offset)
119{
120    SLANG_UNUSED(queryPool);
121    SLANG_UNUSED(index);
122    SLANG_UNUSED(count);
123    SLANG_UNUSED(buffer);
124    SLANG_UNUSED(offset);
125    SLANG_UNIMPLEMENTED_X("resolveQuery");
126}
127
128SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::copyTextureToBuffer(
129    IBufferResource* dst,
130    Offset dstOffset,
131    Size dstSize,
132    Size dstRowStride,
133    ITextureResource* src,
134    ResourceState srcState,
135    SubresourceRange srcSubresource,
136    ITextureResource::Offset3D srcOffset,
137    ITextureResource::Extents extent)
138{
139    SLANG_UNUSED(dst);
140    SLANG_UNUSED(dstOffset);
141    SLANG_UNUSED(dstSize);
142    SLANG_UNUSED(dstRowStride);
143    SLANG_UNUSED(src);
144    SLANG_UNUSED(srcState);
145    SLANG_UNUSED(srcSubresource);
146    SLANG_UNUSED(srcOffset);
147    SLANG_UNUSED(extent);
148    SLANG_UNIMPLEMENTED_X("copyTextureToBuffer");
149}
150
151SLANG_NO_THROW void SLANG_MCALL ResourceCommandEncoderImpl::textureSubresourceBarrier(
152    ITextureResource* texture,
153    SubresourceRange subresourceRange,
154    ResourceState src,
155    ResourceState dst)
156{
157    SLANG_UNUSED(texture);
158    SLANG_UNUSED(subresourceRange);
159    SLANG_UNUSED(src);
160    SLANG_UNUSED(dst);
161    SLANG_UNIMPLEMENTED_X("textureSubresourceBarrier");
162}
163
164SLANG_NO_THROW void SLANG_MCALL
165ResourceCommandEncoderImpl::beginDebugEvent(const char* name, float rgbColor[3])
166{
167    SLANG_UNUSED(name);
168    SLANG_UNUSED(rgbColor);
169}
170
171void ComputeCommandEncoderImpl::init(CommandBufferImpl* cmdBuffer)
172{
173    m_writer = cmdBuffer;
174    m_commandBuffer = cmdBuffer;
175}
176
177SLANG_NO_THROW Result SLANG_MCALL
178ComputeCommandEncoderImpl::bindPipeline(IPipelineState* state, IShaderObject** outRootObject)
179{
180    m_writer->setPipelineState(state);
181    PipelineStateBase* pipelineImpl = static_cast<PipelineStateBase*>(state);
182    SLANG_RETURN_ON_FAIL(m_commandBuffer->m_device->createRootShaderObject(
183        pipelineImpl->m_program,
184        m_rootObject.writeRef()));
185    returnComPtr(outRootObject, m_rootObject);
186    return SLANG_OK;
187}
188
189SLANG_NO_THROW Result SLANG_MCALL ComputeCommandEncoderImpl::bindPipelineWithRootObject(
190    IPipelineState* state,
191    IShaderObject* rootObject)
192{
193    m_writer->setPipelineState(state);
194    PipelineStateBase* pipelineImpl = static_cast<PipelineStateBase*>(state);
195    SLANG_RETURN_ON_FAIL(m_commandBuffer->m_device->createRootShaderObject(
196        pipelineImpl->m_program,
197        m_rootObject.writeRef()));
198    m_rootObject->copyFrom(rootObject, m_commandBuffer->m_transientHeap);
199    return SLANG_OK;
200}
201
202SLANG_NO_THROW Result SLANG_MCALL ComputeCommandEncoderImpl::dispatchCompute(int x, int y, int z)
203{
204    m_writer->bindRootShaderObject(m_rootObject);
205    m_writer->dispatchCompute(x, y, z);
206    return SLANG_OK;
207}
208
209SLANG_NO_THROW Result SLANG_MCALL
210ComputeCommandEncoderImpl::dispatchComputeIndirect(IBufferResource* argBuffer, Offset offset)
211{
212    SLANG_UNIMPLEMENTED_X("dispatchComputeIndirect");
213}
214
215} // namespace cuda
216#endif
217} // namespace gfx