diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-08-31 12:47:39 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-09-06 13:52:04 -0700 |
| commit | 5900f32fff9970b4221ce7fb7e94133e387ff9de (patch) | |
| tree | fd83b7e861dbc6a0d442d5a913a1bcd9df547408 /source/slang/slang-stdlib.cpp | |
| parent | e59a1b39317c10815baaed3b70c4a6580dbe1e63 (diff) | |
Continue work on IR-based codegen
This gets us far enough that we can convert a single test case to use the IR, under the new `-use-ir` flag.
Getting this merged into mainline will at least ensure that we keep the IR path working in a minimal fashion, even when we have to add functionality the existing AST-based path
There is definitely some clutter here from keeping both IR-based and AST-based translation around, but I don't want to have a long-lived branch for the IR that gets further and further away from the `master` branch that is actually getting used and tested.
Summary of changes:
- Add pointer types and basic `load` operation to be able to handle variable declarations
- Add basic `call` instruction type
- Add simple address math for field reference in l-value
- Always add IR for referenced decls to global scope
- Add notion of "intrinsic" type modifier, which maps a type declaration directly to an IR opcode (plus optional literal operands to handle things like texture/sampler flavor)
- Improve printing of IR instructions, types, operands
- Add constant-buffer type to IR
- Allow any instruction to be detected as "should be folded into use sites" and use this to tag things of constant-buffer type
- Also add logic for implicit base on member expressions, to handle references to `cbuffer` members
- Add connection back to original decl to IR variables (including global shader parameters...)
- Use reflection name instead of true name when emitting HLSL from IR (so that we can match HLSL output)
- Make IR include decorations for type layout
- Re-use existing emit logic for HLSL semantics to output `register` semantics for IR-based code
- Make IR-based codegen be an option we can enable from the command line
- It still isn't on by default (it can barely manage a trivial shader), but it seems better to enable it always instead of putting it under an `#ifdef`
- Fix up how we check for intrinsic operations suring AST-based cross compilation so that adding new intrinsic ops for the IR won't break codegen.
Diffstat (limited to 'source/slang/slang-stdlib.cpp')
| -rw-r--r-- | source/slang/slang-stdlib.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp index 89fcd0800..afcca4d7f 100644 --- a/source/slang/slang-stdlib.cpp +++ b/source/slang/slang-stdlib.cpp @@ -1,6 +1,7 @@ // slang-stdlib.cpp #include "compiler.h" +#include "ir.h" #include "syntax.h" #define STRINGIZE(x) STRINGIZE2(x) @@ -1393,8 +1394,15 @@ namespace Slang // Declare additional built-in generic types // EMIT_LINE_DIRECTIVE(); - sb << "__generic<T> __magic_type(ConstantBuffer) struct ConstantBuffer {};\n"; - sb << "__generic<T> __magic_type(TextureBuffer) struct TextureBuffer {};\n"; + + + sb << "__generic<T>\n"; + sb << "__intrinsic_type(" << kIROp_ConstantBufferType << ")\n"; + sb << "__magic_type(ConstantBuffer) struct ConstantBuffer {};\n"; + + sb << "__generic<T>\n"; + sb << "__intrinsic_type(" << kIROp_TextureBufferType << ")\n"; + sb << "__magic_type(TextureBuffer) struct TextureBuffer {};\n"; static const char* kComponentNames[]{ "x", "y", "z", "w" }; @@ -1527,8 +1535,15 @@ namespace Slang // Declare built-in texture and sampler types - sb << "__magic_type(SamplerState," << int(SamplerStateType::Flavor::SamplerState) << ") struct SamplerState {};"; - sb << "__magic_type(SamplerState," << int(SamplerStateType::Flavor::SamplerComparisonState) << ") struct SamplerComparisonState {};"; + + + sb << "__magic_type(SamplerState," << int(SamplerStateType::Flavor::SamplerState) << ")\n"; + sb << "__intrinsic_type(" << kIROp_SamplerType << ", " << int(SamplerStateType::Flavor::SamplerState) << ")\n"; + sb << "struct SamplerState {};"; + + sb << "__magic_type(SamplerState," << int(SamplerStateType::Flavor::SamplerComparisonState) << ")\n"; + sb << "__intrinsic_type(" << kIROp_SamplerType << ", " << int(SamplerStateType::Flavor::SamplerComparisonState) << ")\n"; + sb << "struct SamplerComparisonState {};"; // TODO(tfoley): Need to handle `RW*` variants of texture types as well... static const struct { @@ -1582,7 +1597,9 @@ namespace Slang // TODO: allow for multisample count to come in as well... sb << "__generic<T = float4> "; - sb << "__magic_type(Texture," << int(flavor) << ") struct "; + sb << "__magic_type(Texture," << int(flavor) << ")\n"; + sb << "__intrinsic_type(" << kIROp_TextureType << ", " << flavor << ")\n"; + sb << "struct "; sb << kBaseTextureAccessLevels[accessLevel].name; sb << name; if (isMultisample) sb << "MS"; @@ -1787,6 +1804,10 @@ namespace Slang // `Sample()` sb << "__intrinsic(glsl, \"texture($p, $1)\")\n"; + + // TODO: only enable if IR is being used? + sb << "__intrinsic_op(sample_t_s_u)\n"; + sb << "__intrinsic\n"; sb << "T Sample(SamplerState s, "; sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location);\n"; |
