diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-01-24 15:06:08 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-24 15:06:08 -0500 |
| commit | b8f294445b998eadb9b09e2b91eb462b881eaf2e (patch) | |
| tree | 8607e5d2f6c2c2b4b7545a721d6d58e6e557e5c0 /source/slang/slang-type-layout.cpp | |
| parent | 394983d61efa2bf99ba96aa68a47df8927a8a634 (diff) | |
Texture Sample available in CUDA (#1176)
* WIP: Trying to figure out how texturing will work with CUDA.
* WIP: Fixes for CUDA layout. Initial CUDA texture test.
* WIP: Outputs something compilable by CUDA for TextureND.Sample
* 2d texture working with CUDA.
* Fix how binding for SamplerState occurs in CUDA.
* Small tidy up of comments.
Diffstat (limited to 'source/slang/slang-type-layout.cpp')
| -rw-r--r-- | source/slang/slang-type-layout.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index 644f54a95..cf793b52d 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -735,25 +735,30 @@ struct CUDAObjectLayoutRulesImpl : CPUObjectLayoutRulesImpl { typedef CPUObjectLayoutRulesImpl Super; + // cuda.h defines a variety of handle types. We don't want to have to include cuda.h though - as it may not be available + // on a build target. So for we define this handle type, that matches cuda.h and is used for types that use this kind + // of opaque handle (as opposed to a pointer) such as CUsurfObject, CUtexObject + typedef unsigned long long ObjectHandle; + virtual SimpleLayoutInfo GetObjectLayout(ShaderParameterKind kind) override { switch (kind) { case ShaderParameterKind::ConstantBuffer: // It's a pointer to the actual uniform data - return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*)); + return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*)); case ShaderParameterKind::MutableTexture: case ShaderParameterKind::TextureUniformBuffer: case ShaderParameterKind::Texture: // It's a pointer to a texture interface - return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*)); + return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(ObjectHandle), SLANG_ALIGN_OF(ObjectHandle)); case ShaderParameterKind::StructuredBuffer: case ShaderParameterKind::MutableStructuredBuffer: // TODO(JS): We are just storing as a pointer for now // It's a ptr and a size of the amount of elements - return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*)); + return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*)); case ShaderParameterKind::RawBuffer: case ShaderParameterKind::Buffer: @@ -763,11 +768,16 @@ struct CUDAObjectLayoutRulesImpl : CPUObjectLayoutRulesImpl // TODO(JS): We are storing as a pointer for now // It's a pointer and a size in bytes - return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*)); + return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*)); case ShaderParameterKind::SamplerState: - // It's a pointer - return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), sizeof(void*)); + // In CUDA it seems that sampler states are combined into texture objects. + // So it's a binding issue to combine a sampler with a texture - and sampler are ignored + // For simplicity here though - we do create a variable and that variable takes up + // uniform binding space. + // TODO(JS): If we wanted to remove these variables we'd want to do it as a pass. The pass + // would presumably have to remove use of variables of this kind throughout IR. + return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(void*), SLANG_ALIGN_OF(void*)); case ShaderParameterKind::TextureSampler: case ShaderParameterKind::MutableTextureSampler: |
