diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/gfx/cuda/render-cuda.cpp | 77 | ||||
| -rw-r--r-- | tools/gfx/render-graphics-common.cpp | 2 |
2 files changed, 71 insertions, 8 deletions
diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp index 4f87bdfc9..906d553cb 100644 --- a/tools/gfx/cuda/render-cuda.cpp +++ b/tools/gfx/cuda/render-cuda.cpp @@ -250,6 +250,20 @@ public: slang::BindingType bindingType; Index count; Index baseIndex; // Flat index for sub-ojects + + // TODO: The `uniformOffset` field should be removed, + // since it cannot be supported by the Slang reflection + // API once we fix some design issues. + // + // It is only being used today for pre-allocation of sub-objects + // for constant buffers and parameter blocks (which should be + // deprecated/removed anyway). + // + // Note: We would need to bring this field back, plus + // a lot of other complexity, if we ever want to support + // setting of resources/buffers directly by a binding + // range index and array index. + // Index uniformOffset; // Uniform offset for a resource typed field. }; @@ -310,6 +324,14 @@ public: SlangInt rangeIndexInDescriptorSet = m_elementTypeLayout->getBindingRangeFirstDescriptorRangeIndex(r); + // TODO: This logic assumes that for any binding range that might consume + // multiple kinds of resources, the descriptor range for its uniform + // usage will be the first one in the range. + // + // We need to decide whether that assumption is one we intend to support + // applications making, or whether they should be forced to perform a + // linear search over the descriptor ranges for a specific binding range. + // auto uniformOffset = m_elementTypeLayout->getDescriptorSetDescriptorRangeIndexOffset( descriptorSetIndex, rangeIndexInDescriptorSet); @@ -464,6 +486,17 @@ public: return SLANG_OK; } virtual SLANG_NO_THROW Result SLANG_MCALL + setDeviceData(size_t offset, void* data, size_t size) + { + size = Math::Min(size, bufferResource->getDesc()->sizeInBytes - offset); + SLANG_CUDA_RETURN_ON_FAIL(cudaMemcpy( + (uint8_t*)bufferResource->m_cudaMemory + offset, + data, + size, + cudaMemcpyHostToDevice)); + return SLANG_OK; + } + virtual SLANG_NO_THROW Result SLANG_MCALL getObject(ShaderOffset const& offset, IShaderObject** object) { auto subObjectIndex = @@ -480,17 +513,34 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL setObject(ShaderOffset const& offset, IShaderObject* object) { - auto subObjectIndex = - getLayout()->m_bindingRanges[offset.bindingRangeIndex].baseIndex + offset.bindingArrayIndex; - SLANG_ASSERT( - offset.uniformOffset == - getLayout()->m_bindingRanges[offset.bindingRangeIndex].uniformOffset + - offset.bindingArrayIndex * sizeof(void*)); + auto layout = getLayout(); + SLANG_ASSERT(offset.bindingRangeIndex >= 0); + SLANG_ASSERT(offset.bindingRangeIndex < layout->m_bindingRanges.getCount()); + auto& bindingRange = layout->m_bindingRanges[offset.bindingRangeIndex]; + + auto subObjectIndex = bindingRange.baseIndex + offset.bindingArrayIndex; auto cudaObject = dynamic_cast<CUDAShaderObject*>(object); if (subObjectIndex >= objects.getCount()) objects.setCount(subObjectIndex + 1); objects[subObjectIndex] = cudaObject; - return setData(offset, &cudaObject->bufferResource->m_cudaMemory, sizeof(void*)); + + switch( bindingRange.bindingType ) + { + default: + SLANG_RETURN_ON_FAIL(setData(offset, &cudaObject->bufferResource->m_cudaMemory, sizeof(void*))); + break; + + case slang::BindingType::ExistentialValue: + // TODO: handle the "does it fit" logic + { + auto valueSize = cudaObject->m_layout->getElementTypeLayout()->getSize(); + auto valueOffset = 16; + SLANG_RETURN_ON_FAIL(setDeviceData(offset.uniformOffset + valueOffset, cudaObject->getBuffer(), valueSize)); + } + break; + } + + return SLANG_OK; } virtual SLANG_NO_THROW Result SLANG_MCALL setResource(ShaderOffset const& offset, IResourceView* resourceView) @@ -615,6 +665,19 @@ public: return SLANG_OK; } + virtual SLANG_NO_THROW Result SLANG_MCALL + setDeviceData(size_t offset, void* data, size_t size) + { + size = Math::Min(size, uniformBufferSize - offset); + SLANG_CUDA_RETURN_ON_FAIL(cudaMemcpy( + (uint8_t*)hostBuffer + offset, + data, + size, + cudaMemcpyDeviceToHost)); + return SLANG_OK; + } + + virtual SLANG_NO_THROW void* SLANG_MCALL getBuffer() override { return hostBuffer; diff --git a/tools/gfx/render-graphics-common.cpp b/tools/gfx/render-graphics-common.cpp index 5f083538d..9e95df95c 100644 --- a/tools/gfx/render-graphics-common.cpp +++ b/tools/gfx/render-graphics-common.cpp @@ -153,6 +153,7 @@ public: switch (slangBindingType) { case slang::BindingType::ExistentialValue: + case slang::BindingType::InlineUniformData: continue; default: break; @@ -172,7 +173,6 @@ public: auto category = typeLayout->getDescriptorSetDescriptorRangeCategory(s, r); descriptorRangeDesc.binding += varLayout->getOffset(category); } - descriptorSetInfo->slotRangeDescs.add(descriptorRangeDesc); } } |
