SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 Okay I've solved it. If I use a 4096x4096 texture the crash occurs. Using a 1024x1024 works perfectly. @Josh any ideas why this would happen? EDIT : Something is being set when loading the texture before assigning it to the array. If I don't load the texture and set my own, any size works. But if I load an image before making my own to assign to the array and the two sizes don't match, it crashes. Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 Do you know for sure that bluegrid.tex is GL_RGBA format? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 With no compression it is, yes. Even if i didn't use the texture that I loaded, and set the pixels for the array manually after loading the texture, the two different sizes would cause the crash. Obviously it's something that's easily avoided now, I'm just more curious as to why it happened. Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 8 minutes ago, SpiderPig said: With no compression it is, yes. Even if i didn't use the texture that I loaded, and set the pixels for the array manually after loading the texture, the two different sizes would cause the crash. Obviously it's something that's easily avoided now, I'm just more curious as to why it happened. Until you determine the cause I would not consider it solved. You either have random memory overwrite or a failure to allocate memory. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 This code shows a yellow texture; int _width = 512; int _height = 512; char* buf = new char[ _width * _height * 3]; int index = 0; for (int x = 0; x < _width; x++) { for (int y = 0; y < _height; y++) { buf[index] = 255; buf[index + 1] = 255; buf[index + 2] = 0; index+=3; } } OpenGLShader* shader = (OpenGLShader*)mat->GetShader(); glUseProgram(shader->program); GLuint _buffer; glGenTextures(1, &_buffer); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, _buffer); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB8, _width, _height, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); GLenum e5 = glGetError(); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _width, _height, 1, GL_RGB, GL_UNSIGNED_BYTE, buf); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); However loading a texture with a different size at the beginning (1024 x 1024) causes the crash. Texture* texture = Texture::Load("Materials\\bluegrid.tex");//1024x1024 int _width = 512;//works if these are made 1024 as well int _height = 512; char* buf = new char[ _width * _height * 3]; int index = 0; for (int x = 0; x < _width; x++) { for (int y = 0; y < _height; y++) { buf[index] = 255; buf[index + 1] = 255; buf[index + 2] = 0; index+=3; } } OpenGLShader* shader = (OpenGLShader*)mat->GetShader(); glUseProgram(shader->program); GLuint _buffer; glGenTextures(1, &_buffer); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, _buffer); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0); glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB8, _width, _height, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); GLenum e5 = glGetError(); glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _width, _height, 1, GL_RGB, GL_UNSIGNED_BYTE, buf); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR); Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 In the code I sent you there is a block of four lines of code. Above this block is a comment: //Don't forget these commands or you will have random crashes that are very hard to track down! I think this will fix your problem. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 That did the trick, thanks Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 The arrays don't like working with z-sort off... with z sort off everything is black. With it on I get the sky seeping around the edges of buildings. Same problem as here; https://www.leadwerks.com/community/topic/17428-background-seeps-around-edges/#comment-113247 I can't turn Z-Sort on everything because the tree models don't like it on... EDIT : This happens with multi-sampling on at any level. Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 AMD GPU? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 No Nvidia. GTX 980 Ti Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 What is MSAA set to? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 It was set to 2x. Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 And if disabled, the problem disappears? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 Yeah. It's worse at higher levels too. I've tried up to 16x. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 When changing it from off to 2x it looks like the buildings actually move slightly.. Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 So it does not occur when MSAA is disabled. This issue actually has nothing to do with texture arrays. This is happening because the depth texture is twice (or more) the resolution of the context. There is not a single correct depth value at each pixel, but the sorted objects are being drawn directly on the context after the MSAA rendering has been all filtered into a non-multisampled display. You could render these buildings in a second world by themselves, making sure the camera has color buffer clearing disabled. What is it that you are trying to do with this? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 24, 2018 Author Share Posted September 24, 2018 Quote So it does not occur when MSAA is disabled. Correct. What I noticed with texture arrays is, the material had to have z-sort enabled in order for the textures to show. With z-sort enabled on my terrain, and MSAA enabled I get this issue. Can the resolution of the depth texture be changed to match the context or is this impractical? Quote Link to comment Share on other sites More sharing options...
Josh Posted September 24, 2018 Share Posted September 24, 2018 38 minutes ago, SpiderPig said: Correct. What I noticed with texture arrays is, the material had to have z-sort enabled in order for the textures to show. With z-sort enabled on my terrain, and MSAA enabled I get this issue. Can the resolution of the depth texture be changed to match the context or is this impractical? Sure. Disable MSAA ? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 26, 2018 Author Share Posted September 26, 2018 I guess I'll have to leave texture arrays alone then. Don't want to not use MSAA ? Will turbo be different regarding the depth texture? Can we also have the option to use texture arrays? Quote Link to comment Share on other sites More sharing options...
Josh Posted September 26, 2018 Share Posted September 26, 2018 Turbo uses a forward tenderer. So basically yes. i don’t understand why sorting is needed. You should solve that problem instead of making things more complicated. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted September 26, 2018 Author Share Posted September 26, 2018 I'm not sure why it's needed either. I will be looking into it more as i dont think its just the texture array shader. I have a shader that uses a storage object and it dosnt work with zsort on. I'll see if I can track the problem down. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.