mirror of
https://gitee.com/openharmony/third_party_vulkan-loader
synced 2024-12-25 08:26:23 +00:00
compiler_render_tests: Turn on textured triangle test, with just t0 and s0
This commit is contained in:
parent
000208953e
commit
5b86122036
@ -142,9 +142,11 @@ public:
|
||||
void DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText);
|
||||
void DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText);
|
||||
void DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText);
|
||||
void DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText);
|
||||
|
||||
void CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
|
||||
void CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
|
||||
void CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps);
|
||||
void DrawRotatedTriangleTest();
|
||||
|
||||
|
||||
@ -618,6 +620,106 @@ void XglRenderTest::DrawTriangleTwoUniformsFS(const char *vertShaderText, const
|
||||
|
||||
}
|
||||
|
||||
void XglRenderTest::DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText)
|
||||
{
|
||||
|
||||
// based on DrawTriangleTwoUniformsFS
|
||||
|
||||
XGL_PIPELINE pipeline;
|
||||
XGL_SHADER vs, ps;
|
||||
XGL_RESULT err;
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(InitState());
|
||||
ASSERT_NO_FATAL_FAILURE(InitViewport());
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_VERTEX,
|
||||
vertShaderText, &vs));
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(CreateShader(XGL_SHADER_STAGE_FRAGMENT,
|
||||
fragShaderText, &ps));
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(CreatePipelineSingleTextureAndSampler(&pipeline, vs, ps));
|
||||
|
||||
/*
|
||||
* Shaders are now part of the pipeline, don't need these anymore
|
||||
*/
|
||||
ASSERT_XGL_SUCCESS(xglDestroyObject(ps));
|
||||
ASSERT_XGL_SUCCESS(xglDestroyObject(vs));
|
||||
|
||||
ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
|
||||
|
||||
|
||||
// Enable our single sampler
|
||||
ASSERT_NO_FATAL_FAILURE(InitSampler());
|
||||
|
||||
// Enable our single texture
|
||||
ASSERT_NO_FATAL_FAILURE(InitTexture());
|
||||
|
||||
// Create descriptor set for a texture and sampler resources
|
||||
const int slotCount = 3;
|
||||
XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
|
||||
descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
|
||||
descriptorInfo.slots = slotCount;
|
||||
|
||||
// create a descriptor set with a single slot
|
||||
err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
|
||||
ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
|
||||
|
||||
// bind memory to the descriptor set
|
||||
err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
|
||||
|
||||
// write the sampler and image views to the descriptor set
|
||||
// ensure this matches order set in CreatePipelineSingleTextureAndSampler
|
||||
xglBeginDescriptorSetUpdate( m_rsrcDescSet );
|
||||
xglAttachImageViewDescriptors( m_rsrcDescSet, 0, 1, &m_textureViewInfo );
|
||||
xglAttachSamplerDescriptors(m_rsrcDescSet, 1, 1, &m_sampler);
|
||||
xglEndDescriptorSetUpdate( m_rsrcDescSet );
|
||||
|
||||
// Build command buffer
|
||||
err = xglBeginCommandBuffer(m_cmdBuffer, 0);
|
||||
ASSERT_XGL_SUCCESS(err);
|
||||
|
||||
GenerateClearAndPrepareBufferCmds();
|
||||
GenerateBindRenderTargetCmd();
|
||||
GenerateBindStateAndPipelineCmds(&pipeline);
|
||||
|
||||
// xglCmdBindDescriptorSet(m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, 0, m_rsrcDescSet, 0 );
|
||||
// xglCmdBindDynamicMemoryView( m_cmdBuffer, XGL_PIPELINE_BIND_POINT_GRAPHICS, &m_constantBufferView );
|
||||
|
||||
// render the cube
|
||||
xglCmdDraw( m_cmdBuffer, 0, 3, 0, 1 );
|
||||
|
||||
// prepare the back buffer for present
|
||||
// XGL_IMAGE_STATE_TRANSITION transitionToPresent = {};
|
||||
// transitionToPresent.image = m_image;
|
||||
// transitionToPresent.oldState = m_image_state;
|
||||
// transitionToPresent.newState = m_display.fullscreen ? XGL_WSI_WIN_PRESENT_SOURCE_FLIP : XGL_WSI_WIN_PRESENT_SOURCE_BLT;
|
||||
// transitionToPresent.subresourceRange = srRange;
|
||||
// xglCmdPrepareImages( m_cmdBuffer, 1, &transitionToPresent );
|
||||
// m_image_state = ( XGL_IMAGE_STATE ) transitionToPresent.newState;
|
||||
|
||||
// finalize recording of the command buffer
|
||||
err = xglEndCommandBuffer( m_cmdBuffer );
|
||||
ASSERT_XGL_SUCCESS( err );
|
||||
|
||||
// this command buffer only uses the vertex buffer memory
|
||||
m_numMemRefs = 0;
|
||||
// m_memRefs[0].flags = 0;
|
||||
// m_memRefs[0].mem = m_vtxBufferMemory;
|
||||
|
||||
// submit the command buffer to the universal queue
|
||||
err = xglQueueSubmit( m_device->m_queue, 1, &m_cmdBuffer, m_numMemRefs, m_memRefs, NULL );
|
||||
ASSERT_XGL_SUCCESS( err );
|
||||
|
||||
err = xglQueueWaitIdle( m_device->m_queue );
|
||||
ASSERT_XGL_SUCCESS( err );
|
||||
|
||||
// Wait for work to finish before cleaning up.
|
||||
xglDeviceWaitIdle(m_device->device());
|
||||
|
||||
RecordImage(m_renderTarget);
|
||||
|
||||
}
|
||||
|
||||
void XglRenderTest::DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText)
|
||||
{
|
||||
@ -965,6 +1067,107 @@ void XglRenderTest::CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER v
|
||||
ASSERT_XGL_SUCCESS(err);
|
||||
}
|
||||
|
||||
void XglRenderTest::CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps)
|
||||
{
|
||||
// based on CreatePipelineVSUniform
|
||||
|
||||
XGL_RESULT err;
|
||||
XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
|
||||
XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
|
||||
XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
|
||||
|
||||
const int psSlots = 2; // One texture, one sampler
|
||||
|
||||
// Create descriptor set for single texture and sampler
|
||||
XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
|
||||
descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
|
||||
descriptorInfo.slots = psSlots;
|
||||
err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet );
|
||||
ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed";
|
||||
err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem);
|
||||
|
||||
//XXXXXX
|
||||
// Texture must be first, followed by sampler (VALIDATED THIS BEFORE SUBMITTING COMMENT)
|
||||
//XXXXXX
|
||||
|
||||
// Assign the slots, note that only t0 and s0 will work as of writing this test
|
||||
XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) );
|
||||
slotInfo[0].shaderEntityIndex = 0;
|
||||
slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE;
|
||||
slotInfo[1].shaderEntityIndex = 0;
|
||||
slotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER;
|
||||
|
||||
vs_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
vs_stage.pNext = XGL_NULL_HANDLE;
|
||||
vs_stage.shader.stage = XGL_SHADER_STAGE_VERTEX;
|
||||
vs_stage.shader.shader = vs;
|
||||
vs_stage.shader.descriptorSetMapping[0].descriptorCount = 0;
|
||||
vs_stage.shader.linkConstBufferCount = 0;
|
||||
vs_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
|
||||
vs_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
|
||||
vs_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
|
||||
|
||||
ps_stage.sType = XGL_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||
ps_stage.pNext = &vs_stage;
|
||||
ps_stage.shader.stage = XGL_SHADER_STAGE_FRAGMENT;
|
||||
ps_stage.shader.shader = ps;
|
||||
ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo;
|
||||
ps_stage.shader.descriptorSetMapping[0].descriptorCount = psSlots;
|
||||
ps_stage.shader.linkConstBufferCount = 0;
|
||||
ps_stage.shader.pLinkConstBufferInfo = XGL_NULL_HANDLE;
|
||||
ps_stage.shader.dynamicMemoryViewMapping.slotObjectType = XGL_SLOT_UNUSED;
|
||||
ps_stage.shader.dynamicMemoryViewMapping.shaderEntityIndex = 0;
|
||||
|
||||
XGL_PIPELINE_IA_STATE_CREATE_INFO ia_state = {
|
||||
XGL_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO, // sType
|
||||
&ps_stage, // pNext
|
||||
XGL_TOPOLOGY_TRIANGLE_LIST, // XGL_PRIMITIVE_TOPOLOGY
|
||||
XGL_FALSE, // disableVertexReuse
|
||||
XGL_PROVOKING_VERTEX_LAST, // XGL_PROVOKING_VERTEX_CONVENTION
|
||||
XGL_FALSE, // primitiveRestartEnable
|
||||
0 // primitiveRestartIndex
|
||||
};
|
||||
|
||||
XGL_PIPELINE_RS_STATE_CREATE_INFO rs_state = {
|
||||
XGL_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO,
|
||||
&ia_state,
|
||||
XGL_FALSE, // depthClipEnable
|
||||
XGL_FALSE, // rasterizerDiscardEnable
|
||||
1.0 // pointSize
|
||||
};
|
||||
|
||||
XGL_PIPELINE_CB_STATE cb_state = {
|
||||
XGL_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO,
|
||||
&rs_state,
|
||||
XGL_FALSE, // alphaToCoverageEnable
|
||||
XGL_FALSE, // dualSourceBlendEnable
|
||||
XGL_LOGIC_OP_COPY, // XGL_LOGIC_OP
|
||||
{ // XGL_PIPELINE_CB_ATTACHMENT_STATE
|
||||
{
|
||||
XGL_FALSE, // blendEnable
|
||||
m_render_target_fmt, // XGL_FORMAT
|
||||
0xF // channelWriteMask
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Should take depth buffer format from queried formats
|
||||
XGL_PIPELINE_DB_STATE_CREATE_INFO db_state = {
|
||||
XGL_STRUCTURE_TYPE_PIPELINE_DB_STATE_CREATE_INFO,
|
||||
&cb_state,
|
||||
{XGL_CH_FMT_R32, XGL_NUM_FMT_DS} // XGL_FORMAT
|
||||
};
|
||||
|
||||
info.sType = XGL_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
info.pNext = &db_state;
|
||||
info.flags = 0;
|
||||
err = xglCreateGraphicsPipeline(device(), &info, pipeline);
|
||||
ASSERT_XGL_SUCCESS(err);
|
||||
|
||||
err = m_device->AllocAndBindGpuMemory(*pipeline, "Pipeline", &m_pipe_mem);
|
||||
ASSERT_XGL_SUCCESS(err);
|
||||
}
|
||||
|
||||
void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, const char *fragShaderText)
|
||||
{
|
||||
XGL_PIPELINE pipeline;
|
||||
@ -1240,6 +1443,35 @@ TEST_F(XglRenderTest, TriangleVSUniform)
|
||||
// DrawTriangleVSUniform(vertShaderText, fragShaderText, Model);
|
||||
}
|
||||
|
||||
TEST_F(XglRenderTest, TexturedTriangle)
|
||||
{
|
||||
static const char *vertShaderText =
|
||||
"#version 130\n"
|
||||
"out vec2 samplePos;\n"
|
||||
"void main() {\n"
|
||||
" vec2 vertices[3];"
|
||||
" vertices[0] = vec2(-0.5, -0.5);\n"
|
||||
" vertices[1] = vec2( 0.5, -0.5);\n"
|
||||
" vertices[2] = vec2( 0.5, 0.5);\n"
|
||||
" vec2 positions[3];"
|
||||
" positions[0] = vec2( 0.0, 0.0);\n"
|
||||
" positions[1] = vec2( 1.0, 0.0);\n"
|
||||
" positions[2] = vec2( 1.0, 1.0);\n"
|
||||
" samplePos = positions[gl_VertexID % 3];\n"
|
||||
" gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char *fragShaderText =
|
||||
"#version 130\n"
|
||||
"in vec2 samplePos;\n"
|
||||
"uniform sampler2D surface;\n"
|
||||
"void main() {\n"
|
||||
" vec4 texColor = textureLod(surface, samplePos, 0.0);\n"
|
||||
" gl_FragColor = texColor;\n"
|
||||
"}\n";
|
||||
DrawTexturedTriangle(vertShaderText, fragShaderText);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int result;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user