Mutable Variables #291
-
Hey! I'm trying to understand the differences between the three variable types for shader resources:
I seem to be using mutable for all of my variables up to this point, but I'm not clear on what the internal differences are. Are there any performance considerations between them? Or do they just permit varying levels of access/etc.? I have a situation where I'm filling an immutable shader-view buffer with data, and that data remains constant until that entire area is exited and a new area loaded. So it is essentially static. When a new area is loaded, I create a new immutable buffer, fill it with new data, change the SRB variable to point to the new buffer, then delete the old one. First, would there be a better way to handle this situation? For example, should I be creating an entire new SRB to represent the new area? Or is there perhaps a way to update data in an immutable buffer? I assumed it was a one and done type thing. Would any such changes have an impact on general runtime performance? Second, when I attempt to change my immutable buffer through its mutable variable, I get the following error:
Since what I'm doing is a rare event that occurs between different areas, I'm not sure what the best approach would be. Should I use the ALLOW_OVERWRITE flag, or switch to using a dynamic variable? I wasn't able to find much information about downsides to using a dynamic variable. Thanks, I appreciate any advice! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This is a reasonable approach.
You may be confusing immutability of a buffer content with immutability of variable binding. They are orthogonal. The variable type only defines how frequent you can change the variable, it is not related to the content of e.g. a buffer that is bound to that variable. If you need to update the buffer content, don't use
This flag requires manual synchronization with fence, you probably don't need it here.
It adds a minor overhead. If you don't bind SRB thousands of times a frame, you will unlikely to see any difference. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I appreciate the information. In my case, I use a single, global SRB with a global resource signature, so I'm assuming that means the overhead of dynamic variables won't have any effect. Even though I don't technically change the buffer at "runtime", I switched all static buffers to use dynamic variables, to allow swapping them out between areas. As for confusing the dynamic-ness of buffer content and buffer variables, I have certainly done it in the past, but was able to keep it straight this time. Thanks again! |
Beta Was this translation helpful? Give feedback.
STATIC
andMUTABLE
variables are internally pretty much the same.STATIC
are simply for convenience of defining a variable through the pipeline state (or resource signature) that can be shared between all SRBs.DYNAMIC
variables are handled differently. They can be changed arbitrary for the cost of introducing a minor overhead each time an SRB is committed.This is a reasonable approach.
You may be confusing immu…