-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metal: Texture write fix #4952
base: master
Are you sure you want to change the base?
Metal: Texture write fix #4952
Conversation
@@ -1797,6 +1797,21 @@ namespace Slang | |||
} | |||
} | |||
} | |||
for(auto inst : block->getChildren()) | |||
{ | |||
if(auto write = as<IRImageStore>(inst)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this if statement to the loop above, instead of doing a fresh loop?
for now i implemented a split between ImageStore and ImageStoreArray, because i cant split the array component from the coordinate in hlsl.meta.slang, but also i dont know when to split it off in the legalize because i dont know if the target texture is an array texture or not. this way if the swizzle does work in the future the entire ImageStoreArray can be deleted and the array coordinate passed the aux coord in ImageStore |
You should be able to check the type of the image operand to get its shape and arrayness.
|
Now a much better solution, not needing the ImageStoreArray anymore, but IMO it would be a bit better to swizzle the location in the hlsl.meta.slang instead if doing it in the legalize step |
source/slang/hlsl.meta.slang
Outdated
break; | ||
} | ||
// last arg will be replaced with the split off array index | ||
__metalImageStore(this, location, newValue, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be able to do this completely in stdlib without implementing any logic for kIROp_ImageStore in the compiler backend.
[require(metal, texture_sm_4_1)]
static void __metalImageStore(This val, vector<uint, Shape.dimensions> location, T value, uint arrayIndex)
{
__intrinsic_asm "...";
}
//...
case metal:
__metalImageStore(this, __vectorReshape<Shape.dimensions>(location), newValue, location[Shape.dimensions+isArray-1]);
return;
@@ -1740,6 +1740,46 @@ namespace Slang | |||
} | |||
}; | |||
|
|||
// metal textures only support writing 4-component values, even if the texture is only 1, 2, or 3-component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use vectorReshape<>
on the value to write into in stdlib as well? That should remove the need for this leglaization step, right?
@Dynamitos Do you plan to clean up the image store inst with |
In Metal, there is no overload for different component counts of textures, only 4-component writes are allowed. For textures that do not have four components the unused components get discarded, as far as I can gather from the specs.