diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-02-08 11:19:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-08 11:19:31 -0500 |
| commit | 0eed0125fa5e5f425d546efdc2b284b09ffc2785 (patch) | |
| tree | 4ded20c4966f05881a056fad8146e34ac595063e /source | |
| parent | 7de90c1e0b42b565a5f46e2f9f7580e1f577d414 (diff) | |
Fixes to make all CPU compute shaders work on CUDA (#1211)
* Launch CUDA test taking into account dispatch size.
* Enable isCPUOnly hack to work on CUDA.
* Rename 'isCPUOnly' hack to 'onlyCPULikeBinding'.
* Add $T special type.
Support SampleLevel on CUDA.
* Fix typo.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/core.meta.slang | 19 | ||||
| -rw-r--r-- | source/slang/core.meta.slang.h | 21 | ||||
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 16 |
3 files changed, 53 insertions, 3 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 85eb82576..14a8a0750 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -896,7 +896,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "D<$S0>($0"; + sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "D<$T0>($0"; if (kBaseTextureTypes[tt].coordCount == 1) { sb << ", $2"; @@ -1049,10 +1049,27 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // `SampleLevel` sb << "__target_intrinsic(glsl, \"$ctextureLod($p, $2, $3)$z\")\n"; + + // CUDA + if (!isArray) + { + sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "DLod<$T0>($0"; + for (int i = 0; i < kBaseTextureTypes[tt].coordCount; ++i) + { + sb << ", $2"; + if (kBaseTextureTypes[tt].coordCount > 1) + { + sb << '.' << char(i + 'x'); + } + } + sb << ", $3)\")\n"; + } + sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level);\n"; + if( baseShape != TextureFlavor::Shape::ShapeCube ) { sb << "__target_intrinsic(glsl, \"$ctextureLodOffset($p, $2, $3, $4)$z\")\n"; diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index b8d7d5d9c..c659d09ff 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -917,7 +917,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) if( baseShape != TextureFlavor::Shape::ShapeCube ) { - sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "D<$S0>($0"; + sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "D<$T0>($0"; if (kBaseTextureTypes[tt].coordCount == 1) { sb << ", $2"; @@ -1070,10 +1070,27 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) // `SampleLevel` sb << "__target_intrinsic(glsl, \"$ctextureLod($p, $2, $3)$z\")\n"; + + // CUDA + if (!isArray) + { + sb << "__target_intrinsic(cuda, \"tex" << kBaseTextureTypes[tt].coordCount << "DLod<$T0>($0"; + for (int i = 0; i < kBaseTextureTypes[tt].coordCount; ++i) + { + sb << ", $2"; + if (kBaseTextureTypes[tt].coordCount > 1) + { + sb << '.' << char(i + 'x'); + } + } + sb << ", $3)\")\n"; + } + sb << "T SampleLevel(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; sb << "float level);\n"; + if( baseShape != TextureFlavor::Shape::ShapeCube ) { sb << "__target_intrinsic(glsl, \"$ctextureLodOffset($p, $2, $3, $4)$z\")\n"; @@ -1282,7 +1299,7 @@ for (auto op : binaryOps) sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, " << rightType << " right);\n"; } } -SLANG_RAW("#line 1264 \"core.meta.slang\"") +SLANG_RAW("#line 1281 \"core.meta.slang\"") SLANG_RAW("\n") SLANG_RAW("\n") SLANG_RAW("// Specialized function\n") diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index a383caecf..2212cf9cc 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -1367,6 +1367,22 @@ void CLikeSourceEmitter::emitIntrinsicCallExprImpl( } break; + case 'T': + // Get the the 'element' type for the type of the param at the index + { + SLANG_RELEASE_ASSERT(*cursor >= '0' && *cursor <= '9'); + Index argIndex = (*cursor++) - '0'; + SLANG_RELEASE_ASSERT(argCount > argIndex); + + IRType* type = args[argIndex].get()->getDataType(); + if (auto baseTextureType = as<IRTextureType>(type)) + { + type = baseTextureType->getElementType(); + } + emitType(type); + } + break; + case 'S': // Get the scalar type of a generic at specified index { |
