[4.0unstable] Gorilla is not rendered for Vulkan.

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


przemir
Halfling
Posts: 72
Joined: Sun May 11, 2014 7:55 pm
Location: Poland
x 21

[4.0unstable] Gorilla is not rendered for Vulkan.

Post by przemir »

It works for Direct3D11 and OpenGL, but Vulkan shows nothing (although RenderDoc have some data during Vertex input stage).

OpenGL
Image

Vulkan
Image

RenderDoc (Vulkan)
Image

To make this simpler to test I made sample https://github.com/przemir/Ogre_Sample_Gorilla
similar in style to ogre samples.

VertexShader:

Code: Select all

#version ogre_glsl_ver_330

vulkan_layout( OGRE_DIFFUSE ) in vec4 colour;
vulkan_layout( OGRE_POSITION ) in vec3 vertex;
vulkan_layout( OGRE_TEXCOORD0 ) in vec2 uv0;

out gl_PerVertex
{
    vec4 gl_Position;
};

/*
vulkan_layout( location = 0 ) out vec4 oUv;
vulkan_layout( location = 1 ) out vec4 oColor;
*/

vulkan_layout( location = 0 )
out block
{
    vec4 oUv;
    vec4 oColor;
} outVs;

void main()
{
    outVs.oUv = vec4(uv0, 1.0, 1.0);
    outVs.oColor = colour;
    gl_Position = vec4(vertex, 1.0);
}

PixelShader:

Code: Select all

#version ogre_glsl_ver_330

vulkan_layout( ogre_s0 ) uniform sampler2D atlas;

/*
vulkan_layout( location = 0 ) in vec4 oUv;
vulkan_layout( location = 1 ) in vec4 oColor;
*/

vulkan_layout( location = 0 )
in block
{
    vec4 oUv;
    vec4 oColor;
} inPs;

vulkan_layout( location = 0 )
out vec4 fragColour;

void main()
{
    fragColour = texture(atlas, inPs.oUv.xy) * inPs.oColor;
}

Material

Code: Select all

vertex_program gorilla2DVPHLSL hlsl
{
 	source gorilla2D.hlsl
	entry_point main_vp
	target vs_5_0 vs_4_0 vs_4_0_level_9_1 vs_4_0_level_9_3
} 

fragment_program gorilla2DFPHLSL hlsl
{
	source gorilla2D.hlsl
	entry_point main_fp
	target ps_5_0 ps_4_0 ps_4_0_level_9_1 ps_4_0_level_9_3
}

vertex_program gorilla2DVPGLSL glsl
{
 	source gorilla2DVP.glsl
} 

fragment_program gorilla2DFPGLSL glsl
{
	source gorilla2DFP.glsl
}

vertex_program gorilla2DVPGLSLES glsles
{
 	source gorilla2DVP.glsles
} 

fragment_program gorilla2DFPGLSLES glsles
{
	source gorilla2DFP.glsles
}

vertex_program gorilla2DVPVK glslvk
{
	source gorilla2DVP.glsl
}

fragment_program gorilla2DFPVK glslvk
{
	source gorilla2DFP.glsl
}

// Unified definition
vertex_program gorilla2DVP unified
{
	delegate gorilla2DVPGLSLES
	delegate gorilla2DVPHLSL
	delegate gorilla2DVPGLSL 
	delegate gorilla2DVPVK
}
fragment_program gorilla2DFP unified
{
	delegate gorilla2DFPGLSLES
	delegate gorilla2DFPHLSL
	delegate gorilla2DFPGLSL
	delegate gorilla2DFPVK
}

material Gorilla2D21
{
	technique
	{
		pass
		{
			depth_check off
			depth_write off
			diffuse vertexcolour
			scene_blend alpha_blend

		vertex_program_ref gorilla2DVP
		{
		}

		fragment_program_ref gorilla2DFP
		{
		}
	}
}
}

Prepare render system inside Gorilla:

Code: Select all

void Screen::_prepareRenderSystem(Ogre::v1::RenderOperation &renderOp)
{
        mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
        mRenderSystem->_setProjectionMatrix(Ogre::Matrix4::IDENTITY);
        mRenderSystem->_setViewMatrix(Ogre::Matrix4::IDENTITY);

    Ogre::TextureGpu* texture = mAtlas->get2DPass()->getTextureUnitState(0)->_getTexturePtr();
    mRenderSystem->_setTexture(0, texture, false);

    Ogre::HlmsManager* hlmsManager = Ogre::Root::getSingleton().getHlmsManager();

    Ogre::HlmsSamplerblock sampler;
    sampler.setAddressingMode(Ogre::TextureAddressingMode::TAM_CLAMP);
    sampler.setFiltering(Ogre::TextureFilterOptions::TFO_TRILINEAR);

    mRenderSystem->_setHlmsSamplerblock(0, hlmsManager->getSamplerblock(sampler));

    // Destroy the last pso created before making a new one.
    if (hasPSO){
        mRenderSystem->_hlmsPipelineStateObjectDestroyed(&pso);
    }

    // Create the PSO for the current render of the GUI
    pso.initialize();
    pso.operationType = Ogre::OT_TRIANGLE_LIST;
    pso.vertexShader = mAtlas->get2DPass()->getVertexProgram();
    pso.pixelShader = mAtlas->get2DPass()->getFragmentProgram();
    pso.macroblock = mAtlas->get2DPass()->getMacroblock();
    pso.blendblock = mAtlas->get2DPass()->getBlendblock();
    pso.vertexElements = renderOp.vertexData->vertexDeclaration->convertToV2(); // Required by DX11 or it will crash! :D

    // Create & Set the PSO to the render system
    mRenderSystem->_hlmsPipelineStateObjectCreated(&pso);
    mRenderSystem->_setPipelineStateObject(&pso);

    // Send the render through. Ogre::v1::CbRenderOp cmd is needed for DX11.
    // A straight renderOperation passed in _render will work in OpenGL.
    Ogre::v1::CbRenderOp cmd = Ogre::v1::CbRenderOp(renderOp);
    mRenderSystem->_setRenderOperation(&cmd);

    hasPSO = true;
}

Gorilla CompositorPass:

Code: Select all

    class GorillaPass : public Ogre::CompositorPass
    {
    public:
        GorillaPass(const Ogre::CompositorPassDef* definition, Ogre::CompositorNode* parentNode, Ogre::Camera* camera, const Ogre::RenderTargetViewDef *rtvDef, Ogre::SceneManager* sceneManager)
            : Ogre::CompositorPass(definition, parentNode)
            , mSceneManager(sceneManager)
            , mCamera(camera)
        {
        }

    virtual void execute(const Ogre::Camera* lodCameraconst)
    {
        profilingBegin();
        Screen* screen = Ogre::any_cast<Screen*>(mCamera->getUserAny());
        screen->renderOnce();
        profilingEnd();
    }

protected:
    Ogre::SceneManager* mSceneManager;
    Ogre::Camera* mCamera;
};

Thanks!

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5533
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1391

Re: [4.0unstable] Gorilla is not rendered for Vulkan.

Post by dark_sylinc »

Hi!

There are two problems with this Gorilla implementation that stood out:

Separate shader samplers

In Vulkan we are using separate sampler and texture objects. Therefore gorilla2DFP.glsl needs to be changed into:

Code: Select all

#version ogre_glsl_ver_330

vulkan_layout( ogre_t0 ) uniform texture2D atlas;
vulkan( layout( ogre_s0 ) uniform sampler texSampler );

/*
vulkan_layout( location = 0 ) in vec4 oUv;
vulkan_layout( location = 1 ) in vec4 oColor;
*/

vulkan_layout( location = 0 )
in block
{
    vec4 oUv;
    vec4 oColor;
} inPs;

vulkan_layout( location = 0 )
out vec4 fragColour;

void main()
{
    fragColour = texture(vkSampler2D(atlas, texSampler), inPs.oUv.xy) * inPs.oColor;
}

Incomplete PSO setup

In Gorilla.cpp Screen::_prepareRenderSystem, pso.pass is never setup. This is required. If enabling Vulkan Validation Layers they will complain about the invalid settings right at mRenderSystem->_hlmsPipelineStateObjectCreated(&pso);.