Quellcode durchsuchen

[BUGFIX] Texture views GL fixes

Panagiotis Christopoulos Charitos vor 8 Jahren
Ursprung
Commit
e79db6b7de

+ 1 - 0
src/anki/gr/gl/Buffer.cpp

@@ -44,6 +44,7 @@ Buffer* Buffer::newInstance(GrManager* manager, const BufferInitInfo& inf)
 	};
 
 	BufferImpl* impl = manager->getAllocator().newInstance<BufferImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
 	static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<BufferCreateCommand>(

+ 1 - 0
src/anki/gr/gl/Framebuffer.cpp

@@ -40,6 +40,7 @@ Framebuffer* Framebuffer::newInstance(GrManager* manager, const FramebufferInitI
 	};
 
 	FramebufferImpl* impl = manager->getAllocator().newInstance<FramebufferImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
 	static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<CreateFramebufferCommand>(impl, init);

+ 3 - 3
src/anki/gr/gl/FramebufferImpl.cpp

@@ -142,18 +142,18 @@ void FramebufferImpl::attachTextureInternal(
 		glFramebufferTexture2D(target,
 			attachment,
 			GL_TEXTURE_CUBE_MAP_POSITIVE_X + view.getBaseFace(),
-			view.getGlName(),
+			tex.getGlName(),
 			view.getBaseMipmap());
 		break;
 	case GL_TEXTURE_2D_ARRAY:
-		glFramebufferTextureLayer(target, attachment, view.getGlName(), view.getBaseMipmap(), view.getBaseLayer());
+		glFramebufferTextureLayer(target, attachment, tex.getGlName(), view.getBaseMipmap(), view.getBaseLayer());
 		break;
 	case GL_TEXTURE_3D:
 		ANKI_ASSERT(!"TODO");
 		break;
 	case GL_TEXTURE_CUBE_MAP_ARRAY:
 		glFramebufferTextureLayer(
-			target, attachment, view.getGlName(), view.getBaseMipmap(), view.getBaseLayer() * 6 + view.getBaseFace());
+			target, attachment, tex.getGlName(), view.getBaseMipmap(), view.getBaseLayer() * 6 + view.getBaseFace());
 		break;
 	default:
 		ANKI_ASSERT(0);

+ 19 - 8
src/anki/gr/gl/GrManager.cpp

@@ -81,34 +81,40 @@ void GrManager::finish()
 	self.getRenderingThread().syncClientServer();
 }
 
+#define ANKI_SAFE_CONSTRUCT(class_)                \
+	class_* out = class_::newInstance(this, init); \
+	class_##Ptr ptr(out);                          \
+	out->getRefcount().fetchSub(1);                \
+	return ptr
+
 BufferPtr GrManager::newBuffer(const BufferInitInfo& init)
 {
-	return BufferPtr(Buffer::newInstance(this, init));
+	ANKI_SAFE_CONSTRUCT(Buffer);
 }
 
 TexturePtr GrManager::newTexture(const TextureInitInfo& init)
 {
-	return TexturePtr(Texture::newInstance(this, init));
+	ANKI_SAFE_CONSTRUCT(Texture);
 }
 
 TextureViewPtr GrManager::newTextureView(const TextureViewInitInfo& init)
 {
-	return TextureViewPtr(TextureView::newInstance(this, init));
+	ANKI_SAFE_CONSTRUCT(TextureView);
 }
 
 SamplerPtr GrManager::newSampler(const SamplerInitInfo& init)
 {
-	return SamplerPtr(Sampler::newInstance(this, init));
+	ANKI_SAFE_CONSTRUCT(Sampler);
 }
 
 ShaderPtr GrManager::newShader(const ShaderInitInfo& init)
 {
-	return ShaderPtr(Shader::newInstance(this, init));
+	ANKI_SAFE_CONSTRUCT(Shader);
 }
 
 ShaderProgramPtr GrManager::newShaderProgram(const ShaderProgramInitInfo& init)
 {
-	return ShaderProgramPtr(ShaderProgram::newInstance(this, init));
+	ANKI_SAFE_CONSTRUCT(ShaderProgram);
 }
 
 CommandBufferPtr GrManager::newCommandBuffer(const CommandBufferInitInfo& init)
@@ -118,12 +124,15 @@ CommandBufferPtr GrManager::newCommandBuffer(const CommandBufferInitInfo& init)
 
 FramebufferPtr GrManager::newFramebuffer(const FramebufferInitInfo& init)
 {
-	return FramebufferPtr(Framebuffer::newInstance(this, init));
+	ANKI_SAFE_CONSTRUCT(Framebuffer);
 }
 
 OcclusionQueryPtr GrManager::newOcclusionQuery()
 {
-	return OcclusionQueryPtr(OcclusionQuery::newInstance(this));
+	OcclusionQuery* out = OcclusionQuery::newInstance(this);
+	OcclusionQueryPtr ptr(out);
+	out->getRefcount().fetchSub(1);
+	return ptr;
 }
 
 RenderGraphPtr GrManager::newRenderGraph()
@@ -131,6 +140,8 @@ RenderGraphPtr GrManager::newRenderGraph()
 	return RenderGraphPtr(RenderGraph::newInstance(this));
 }
 
+#undef ANKI_SAFE_CONSTRUCT
+
 void GrManager::getTextureSurfaceUploadInfo(TexturePtr tex, const TextureSurfaceInfo& surf, PtrSize& allocationSize)
 {
 	const TextureImpl& impl = static_cast<const TextureImpl&>(*tex);

+ 1 - 0
src/anki/gr/gl/OcclusionQuery.cpp

@@ -39,6 +39,7 @@ OcclusionQuery* OcclusionQuery::newInstance(GrManager* manager)
 	};
 
 	OcclusionQueryImpl* impl = manager->getAllocator().newInstance<OcclusionQueryImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
 	static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<CreateOqCommand>(impl);

+ 1 - 0
src/anki/gr/gl/Sampler.cpp

@@ -40,6 +40,7 @@ Sampler* Sampler::newInstance(GrManager* manager, const SamplerInitInfo& init)
 	};
 
 	SamplerImpl* impl = manager->getAllocator().newInstance<SamplerImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
 	static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<CreateSamplerCommand>(impl, init);

+ 1 - 0
src/anki/gr/gl/Shader.cpp

@@ -46,6 +46,7 @@ Shader* Shader::newInstance(GrManager* manager, const ShaderInitInfo& init)
 	ANKI_ASSERT(!init.m_source.isEmpty() && init.m_source.getLength() > 0);
 
 	ShaderImpl* impl = manager->getAllocator().newInstance<ShaderImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	// Copy source to the command buffer
 	CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());

+ 1 - 0
src/anki/gr/gl/ShaderProgram.cpp

@@ -56,6 +56,7 @@ ShaderProgram* ShaderProgram::newInstance(GrManager* manager, const ShaderProgra
 	};
 
 	ShaderProgramImpl* impl = manager->getAllocator().newInstance<ShaderProgramImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	CommandBufferPtr cmdb = manager->newCommandBuffer(CommandBufferInitInfo());
 	static_cast<CommandBufferImpl&>(*cmdb).pushBackNewCommand<CreateCommand>(impl,

+ 1 - 0
src/anki/gr/gl/Texture.cpp

@@ -40,6 +40,7 @@ Texture* Texture::newInstance(GrManager* manager, const TextureInitInfo& init)
 	};
 
 	TextureImpl* impl = manager->getAllocator().newInstance<TextureImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	// Need to pre-init because some funcs ask for members and we don't want to serialize
 	impl->preInit(init);

+ 1 - 1
src/anki/gr/gl/TextureImpl.cpp

@@ -393,7 +393,7 @@ MicroTextureView TextureImpl::getOrCreateView(const TextureSubresourceInfo& subr
 			0,
 			subresource.m_baseFace + subresource.m_faceCount - 1,
 			subresource.m_baseLayer + subresource.m_layerCount - 1));
-		ANKI_ASSERT(firstSurf < lastSurf);
+		ANKI_ASSERT(firstSurf <= lastSurf);
 
 		MicroTextureView view;
 		view.m_aspect = subresource.m_depthStencilAspect;

+ 1 - 0
src/anki/gr/gl/TextureView.cpp

@@ -38,6 +38,7 @@ TextureView* TextureView::newInstance(GrManager* manager, const TextureViewInitI
 	};
 
 	TextureViewImpl* impl = manager->getAllocator().newInstance<TextureViewImpl>(manager);
+	impl->getRefcount().fetchAdd(1); // Hold a reference in case the command finishes and deletes quickly
 
 	// Need to pre-init because some funcs ask for members and we don't want to serialize
 	impl->preInit(init);

+ 2 - 0
src/anki/gr/gl/TextureViewImpl.h

@@ -29,6 +29,7 @@ public:
 
 	~TextureViewImpl()
 	{
+		m_glName = 0;
 	}
 
 	void preInit(const TextureViewInitInfo& inf);
@@ -36,6 +37,7 @@ public:
 	void init()
 	{
 		m_view = static_cast<const TextureImpl&>(*m_tex).getOrCreateView(getSubresource());
+		m_glName = m_view.m_glName;
 	}
 
 	TextureSubresourceInfo getSubresource() const