Skip to content

Commit

Permalink
Allow writes to UAV textures (#416)
Browse files Browse the repository at this point in the history
Work on #415

This issue is already fixed in the `v0.10.*` line, but I'm back-porting the fix to `v0.9.*`.
The issue here was that the stdlib declarations for texture types were only including the `get` accessor for subscript operations, even if the texture was write-able.

I've also included the fixes for other subscript accessors in the stdlib (notably that `OutputPatch<T>` is readable, but not writable, despite what the name seems to imply).
  • Loading branch information
Tim Foley authored Feb 19, 2018
1 parent 172f3f0 commit 017c476
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
14 changes: 10 additions & 4 deletions source/slang/core.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,22 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt)

if(baseShape != TextureType::ShapeCube)
{
// TODO: In the case where `access` includes writeability,
// this should have both `get` and `set` accessors.

// subscript operator
sb << "__subscript(uint";
if(kBaseTextureTypes[tt].coordCount + isArray > 1)
{
sb << kBaseTextureTypes[tt].coordCount + isArray;
}
sb << " location) -> T;\n";
sb << " location) -> T";

if (access != SLANG_RESOURCE_ACCESS_READ)
{
sb << " { get; set; }\n";
}
else
{
sb << ";\n";
}
}

if( !isMultisample )
Expand Down
14 changes: 10 additions & 4 deletions source/slang/core.meta.slang.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,22 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt)

if(baseShape != TextureType::ShapeCube)
{
// TODO: In the case where `access` includes writeability,
// this should have both `get` and `set` accessors.

// subscript operator
sb << "__subscript(uint";
if(kBaseTextureTypes[tt].coordCount + isArray > 1)
{
sb << kBaseTextureTypes[tt].coordCount + isArray;
}
sb << " location) -> T;\n";
sb << " location) -> T";

if (access != SLANG_RESOURCE_ACCESS_READ)
{
sb << " { get; set; }\n";
}
else
{
sb << ";\n";
}
}

if( !isMultisample )
Expand Down
2 changes: 1 addition & 1 deletion source/slang/hlsl.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ __generic<T, let N : int> __magic_type(HLSLInputPatchType) struct InputPatch

__generic<T, let N : int> __magic_type(HLSLOutputPatchType) struct OutputPatch
{
__subscript(uint index) -> T { set; }
__subscript(uint index) -> T;
};

__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer
Expand Down
2 changes: 1 addition & 1 deletion source/slang/hlsl.meta.slang.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sb << "};\n";
sb << "\n";
sb << "__generic<T, let N : int> __magic_type(HLSLOutputPatchType) struct OutputPatch\n";
sb << "{\n";
sb << " __subscript(uint index) -> T { set; }\n";
sb << " __subscript(uint index) -> T;\n";
sb << "};\n";
sb << "\n";
sb << "__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer\n";
Expand Down
20 changes: 20 additions & 0 deletions tests/front-end/uav-write.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// uav-write.slang
//TEST:SIMPLE:

// Just confirming that code that writes to a UAV will type-check.

RWTexture2D<float4> gOutput;

float4 test(uint2 coord, float4 value)
{
// read
value = value + gOutput[coord];

// write
gOutput[coord] = value;

// read-modify-write
gOutput[coord] += value;

return value;
}

0 comments on commit 017c476

Please sign in to comment.