summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2024-07-19 02:04:26 -0400
committerGitHub <noreply@github.com>2024-07-18 23:04:26 -0700
commit59dd133f1c52fb0a7a388f4a8f42234f4556a28a (patch)
tree02556f1660713ebc1272dec9e0e9766ee0999286 /source
parent6e7c726658c775e97578e7a9dd99d23b819870bd (diff)
Allow CPP/CUDA/Metal to lower/legalize buffer-elements to support column_major/row_major. (#4653)
* Allow CPP/CUDA/Metal to legalize their buffer-elements. Fixes: #4537 Changes: 1. Matrix inputs require legalization (pack/unpack) to ensure consistent row_major/column_major throughout entire shader, the following enabled legalization pass fixes this. 2. Added missing CUDA intrinsic so CUDA can run more tests. 3. Added a memory packing test since this still fails for cpp/cuda/metal (due to having no memory packing enforcement). * change memory packing tests to run for targets without packing --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
-rwxr-xr-xsource/slang/slang-compiler.h2
-rw-r--r--source/slang/slang-emit.cpp10
-rw-r--r--source/slang/slang-ir-lower-buffer-element-type.cpp4
3 files changed, 6 insertions, 10 deletions
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 2409cedfb..7fc43d778 100755
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -1769,6 +1769,8 @@ namespace Slang
/// Are we generating code for a CUDA API (CUDA / OptiX)?
bool isCUDATarget(TargetRequest* targetReq);
+ // Are we generating code for a CPU target
+ bool isCPUTarget(TargetRequest* targetReq);
/// A request to generate output in some target format.
class TargetRequest : public RefObject
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 679d8ce88..678b4137a 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -1267,15 +1267,7 @@ Result linkAndOptimizeIR(
if (requiredLoweringPassSet.meshOutput)
legalizeMeshOutputTypes(irModule);
- if (options.shouldLegalizeExistentialAndResourceTypes)
- {
- if (!isMetalTarget(targetRequest))
- {
- // We need to lower any types used in a buffer resource (e.g. ContantBuffer or StructuredBuffer) into
- // a simple storage type that has target independent layout based on the kind of buffer resource.
- lowerBufferElementTypeToStorageType(targetProgram, irModule);
- }
- }
+ lowerBufferElementTypeToStorageType(targetProgram, irModule);
// Rewrite functions that return arrays to return them via `out` parameter,
// since our target languages doesn't allow returning arrays.
diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp
index 981e29697..d042aae43 100644
--- a/source/slang/slang-ir-lower-buffer-element-type.cpp
+++ b/source/slang/slang-ir-lower-buffer-element-type.cpp
@@ -877,7 +877,9 @@ namespace Slang
void lowerBufferElementTypeToStorageType(TargetProgram* target, IRModule* module, bool lowerBufferPointer)
{
SlangMatrixLayoutMode defaultMatrixMode = (SlangMatrixLayoutMode)target->getOptionSet().getMatrixLayoutMode();
- if (defaultMatrixMode == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN)
+ if ((isCPUTarget(target->getTargetReq()) || isCUDATarget(target->getTargetReq()) || isMetalTarget(target->getTargetReq())))
+ defaultMatrixMode = SLANG_MATRIX_LAYOUT_ROW_MAJOR;
+ else if (defaultMatrixMode == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN)
defaultMatrixMode = SLANG_MATRIX_LAYOUT_ROW_MAJOR;
LoweredElementTypeContext context(target, lowerBufferPointer, defaultMatrixMode);
context.processModule(module);