GameMaker Drawing texture page instead of application surface

A

AttaBoy

Guest
I'm drawing a part of the application surface for a shader, but keep getting an error message: "Trying to set texture that is also bound as depth buffer - bailing..."

I've tried removing the shader, and this reveals weird behavior, which is that if I try to draw the application surface it just draws the first texture page. I've tried this with draw_surface_part and draw_surface, same result either way. I'm drawing this in the Draw End event, does anyone know what this could be?
 
A

AttaBoy

Guest
Quick update (and title change to more accurately reflect the symptoms of my problem): I've run the debugger on this section, and I can confirm that the application_surface is what it should be, and that its related texture is also correct. GMS2 seems to simply be drawing the wrong texture (the main texture page instead of the application_surface). Here's the actual draw code:
Code:
draw_surface_part(application_surface, 0, 0, 2 * radius, 2 * radius, x - radius, y - radius);
and here's the resulting draw:
Annoying Bug.png

I've got no idea what this could be, coupled with not knowing what the error in the first post is. Thanks for reading!
 

CMAllen

Member
Yes. Is this normally not supported?
I'm not 100% sure on that. I know that when it comes to GPUs, reading from and writing to the same surface at the same time has spotty stability and support -- which is what you'd have to do to draw a surface to itself (which includes the application surface). What you could do is make a copy of the application surface just before hand and draw the copy instead.
 
A

AttaBoy

Guest
I'm not 100% sure on that. I know that when it comes to GPUs, reading from and writing to the same surface at the same time has spotty stability and support -- which is what you'd have to do to draw a surface to itself (which includes the application surface). What you could do is make a copy of the application surface just before hand and draw the copy instead.
Using another surface works perfectly! I'm still confused, I guess this might just be undefined behavior to avoid? In GMS:1 I would sometimes draw a surface over itself to a apply a shader, which worked without a hiccup. Hmm, maybe I was just getting lucky then. Thanks!
 

CMAllen

Member
It's not related to GMS, but the system hardware itself, hence why I said it had spotty support and stability, regardless of what software package or development environment you're using. It might work fine for one video card and driver combination and not work at all with another. Or it could work off and on, crashing occasionally when it throws an access violation error. Which is part of why the support is spotty -- it's trying to read from and write to the same memory addresses at the same time. That's something that's not typically done. You either read from an address or you write to it. In a strictly single-threaded environment, it doesn't much matter. But GPUs process multiple pixels in parallel. If one thread is trying to read from memory addresses while another thread is trying to write to those same addresses, you get an access violation (or not, depending on if those addresses were locked at the time).

This was something I delved into when trying to develop a shader with easy access to both the source and destination pixel channels.
 
A

AttaBoy

Guest
Okay, good to know. It's easy enough to try and avoid this behavior in the future. I do generally try to create effects using the minimal amount of surfaces, so this might mess with that, but if it's the right way to do it then I'll change my method. Thanks for your help again!
 

Son-Benji

Member
I know this is an old post, but could you please tell me how I create a copy of the aplication surface?

I’m getting the same message while trying to use colorswap shaders that used to work perfectly in 1.4

Some of the shaders don’t work the same at all and I’ve noticed that my shaders also affect the black bars around my game now, they didn’t before
 
Top