summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-stdlib.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-17 15:13:37 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-17 15:13:37 -0700
commitff4621460a98f34d74e4275841c313400cbda0dd (patch)
treea8f6a2334397ade3981f35d1ee764a4c325e0927 /source/slang/slang-stdlib.cpp
parent0059ccb3997c2af87bc3f76524d8cd4787c20b7e (diff)
Handle `Buffer` types more like textures
Fixes #94 We'd been handling HLSL `Buffer` and `RWBuffer` in a one-off fashion, and that led to a lot of code duplication, and also to the issue that we weren't handling `RasterizerOrderedBuffer` at all. This change basically folds `Buffer` in so that it is conceptually a texture type (just with a unique shape). Hopefully all the other logic still works.
Diffstat (limited to 'source/slang/slang-stdlib.cpp')
-rw-r--r--source/slang/slang-stdlib.cpp70
1 files changed, 42 insertions, 28 deletions
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp
index 3de33f554..5800a5deb 100644
--- a/source/slang/slang-stdlib.cpp
+++ b/source/slang/slang-stdlib.cpp
@@ -50,17 +50,6 @@ __generic<T> __magic_type(HLSLAppendStructuredBufferType) struct AppendStructure
out uint stride);
};
-__generic<T> __magic_type(HLSLBufferType) struct Buffer
-{
- __intrinsic void GetDimensions(
- out uint dim);
-
- __intrinsic T Load(int location);
- __intrinsic T Load(int location, out uint status);
-
- __intrinsic __subscript(uint index) -> T;
-};
-
__magic_type(HLSLByteAddressBufferType) struct ByteAddressBuffer
{
__intrinsic void GetDimensions(
@@ -110,19 +99,6 @@ __generic<T, let N : int> __magic_type(HLSLOutputPatchType) struct OutputPatch
__intrinsic __subscript(uint index) -> T { set; }
};
-__generic<T> __magic_type(HLSLRWBufferType) struct RWBuffer
-{
- // Note(tfoley): duplication with declaration of `Buffer`
-
- __intrinsic void GetDimensions(
- out uint dim);
-
- __intrinsic T Load(int location);
- __intrinsic T Load(int location, out uint status);
-
- __intrinsic __subscript(uint index) -> T { get; set; }
-};
-
__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer
{
// Note(tfoley): supports alll operations from `ByteAddressBuffer`
@@ -1985,10 +1961,6 @@ namespace Slang
StringBuilder sb;
-// sb << "__generic<T> __magic_type(PackedBuffer) struct PackedBuffer {};\n";
-// sb << "__generic<T> __magic_type(Uniform) struct Uniform {};\n";
-// sb << "__generic<T> __magic_type(Patch) struct Patch {};\n";
-
// Component-wise multiplication ops
for(auto op : binaryOps)
{
@@ -2019,6 +1991,48 @@ namespace Slang
}
}
+ //
+
+ // Buffer types
+
+ static const struct {
+ char const* name;
+ SlangResourceAccess access;
+ } kBaseBufferAccessLevels[] = {
+ { "", SLANG_RESOURCE_ACCESS_READ },
+ { "RW", SLANG_RESOURCE_ACCESS_READ_WRITE },
+ { "RasterizerOrdered", SLANG_RESOURCE_ACCESS_RASTER_ORDERED },
+ };
+ static const int kBaseBufferAccessLevelCount = sizeof(kBaseBufferAccessLevels) / sizeof(kBaseBufferAccessLevels[0]);
+
+ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa)
+ {
+
+ sb << "__generic<T> __magic_type(Texture, ";
+ sb << ResourceType::makeFlavor(ResourceType::Shape::ShapeBuffer, kBaseBufferAccessLevels[aa].access);
+ sb << ") struct ";
+ sb << kBaseBufferAccessLevels[aa].name;
+ sb << "Buffer {\n";
+
+ sb << "__intrinsic void GetDimensions(out uint dim);\n";
+
+ sb << "__intrinsic T Load(int location);\n";
+ sb << "__intrinsic T Load(int location, out uint status);\n";
+
+ sb << "__intrinsic __subscript(uint index) -> T";
+
+ if (kBaseBufferAccessLevels[aa].access != SLANG_RESOURCE_ACCESS_READ)
+ {
+ sb << " { get; set; }\n";
+ }
+ else
+ {
+ sb << ";\n";
+ }
+
+ sb << "};\n";
+ }
+
// Output a suitable `#line` directive to point at our raw stdlib code above
sb << "\n#line " << kHLSLLibIncludeStringLine << " \"" << getStdlibPath() << "\"\n";