From: Cody Northrop Date: Thu, 30 Oct 2014 17:20:22 +0000 (-0600) Subject: Clean up: convert compiler_render_tests to all use BIL, remove redundant tests X-Git-Tag: khronos-master-20141209~124 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6217b82f7d3ca464d32a713b2d28d213aefbb82f;p=platform%2Fupstream%2FVulkan-LoaderAndValidationLayers.git Clean up: convert compiler_render_tests to all use BIL, remove redundant tests --- diff --git a/tests/compiler_render_tests.cpp b/tests/compiler_render_tests.cpp index 26e88ad..6c0bf0f 100644 --- a/tests/compiler_render_tests.cpp +++ b/tests/compiler_render_tests.cpp @@ -147,13 +147,9 @@ public: void InitMultipleSamplers(int samplerCount); void InitUniformBuffer(int constantCount, int constantSize, int constantIndex, const void* data); void DrawTriangleTest(const char *vertShaderText, const char *fragShaderText); - 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 DrawTriangleFSUniformBlock(const char *vertShaderText, const char *fragShaderText); void DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText); void DrawTriangleVSUniformBlock(const char *vertShaderText, const char *fragShaderText); - void DrawTriangleVSFSUniformBlock(const char *vertShaderText, const char *fragShaderText); void DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText); void DrawVSTexture(const char *vertShaderText, const char *fragShaderText); void DrawSamplerBindingsTriangle(const char *vertShaderText, const char *fragShaderText, int textureCount, int samplerCount); @@ -162,7 +158,6 @@ public: void CreatePipelineWithVertexFetch(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); void CreatePipelineFSUniformBlockBinding(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, int bufferCount); void CreatePipelineVSUniform(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); - void CreatePipelineVSFSUniformBlock(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); void CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps); void CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, int textureCount, int samplerCount); @@ -308,7 +303,7 @@ void XglRenderTest::InitTexture(int textureSlot, int* color) tex_colors[0][0] = *color; tex_colors[0][1] = *color; } else { - tex_colors[0][0] = 0xffff0000; + tex_colors[0][0] = 0xff0000ff; tex_colors[0][1] = 0xff00ff00; } @@ -608,101 +603,6 @@ void XglRenderTest::DrawTriangleTest(const char *vertShaderText, const char *fra } -void XglRenderTest::DrawTriangleTwoUniformsFS(const char *vertShaderText, const char *fragShaderText) -{ - 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(CreateDefaultPipeline(&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()); - - const int constantCount = 8; - const float constants[constantCount] = { 1.0, 0.0, 0.0, 1.0, - 0.0, 0.0, 1.0, 1.0 }; - - InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants); - - // Create descriptor set for a uniform resource - const int slotCount = 1; - 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 constant buffer view to the descriptor set - xglBeginDescriptorSetUpdate( m_rsrcDescSet ); - xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); - 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::DrawTexturedTriangle(const char *vertShaderText, const char *fragShaderText) { @@ -804,128 +704,6 @@ void XglRenderTest::DrawTexturedTriangle(const char *vertShaderText, const char } -void XglRenderTest::DrawTriangleVSUniform(const char *vertShaderText, const char *fragShaderText) -{ - XGL_PIPELINE pipeline; - XGL_SHADER vs, ps; - XGL_RESULT err; - glm::mat4 MVP; - int i; - - // Create identity matrix - glm::mat4 Model = glm::mat4(1.0f); - - 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(CreatePipelineVSUniform(&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()); - - const int matrixSize = 16; - MVP = Model; - - InitConstantBuffer(matrixSize, sizeof(MVP[0]), (const void*) &MVP[0][0]); - - // Create descriptor set for a uniform resource - const int slotCount = 1; - 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 constant buffer view to the descriptor set - xglBeginDescriptorSetUpdate( m_rsrcDescSet ); - xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); - 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); - - for (i = 0; i < 8; i++) { - XGL_UINT8 *pData; - err = xglMapMemory(m_constantBufferMem, 0, (XGL_VOID **) &pData); - ASSERT_XGL_SUCCESS(err); - - MVP = glm::rotate(MVP, glm::radians(22.5f), glm::vec3(0.0f, 1.0f, 0.0f)); - memcpy(pData, (const void*) &MVP[0][0], matrixSize); - - err = xglUnmapMemory(m_constantBufferMem); - ASSERT_XGL_SUCCESS(err); - - // 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::DrawTriangleVSUniformBlock(const char *vertShaderText, const char *fragShaderText) { // sourced from DrawTriangleVSUniform @@ -1345,52 +1123,66 @@ void XglRenderTest::CreatePipelineFSUniformBlockBinding(XGL_PIPELINE* pipeline, ASSERT_XGL_SUCCESS(err); } -void XglRenderTest::CreatePipelineVSFSUniformBlock(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) +void XglRenderTest::CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) { - // this is based on CreatePipelineVSUniform + // 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 vsSlots = 2; // One texture, one sampler - const int slots = 1; // Uniform buffer only - - // Create descriptor set for our one resource - XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; - descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; - descriptorInfo.slots = slots; - - // create a descriptor set with a single slot - err = xglCreateDescriptorSet( device(), &descriptorInfo, &m_rsrcDescSet ); + // Create descriptor set for single texture and sampler + XGL_DESCRIPTOR_SET_CREATE_INFO vsDescriptorInfo = {}; + vsDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; + vsDescriptorInfo.slots = vsSlots; + err = xglCreateDescriptorSet( device(), &vsDescriptorInfo, &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); - - XGL_DESCRIPTOR_SLOT_INFO *slotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( slots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); - slotInfo[0].shaderEntityIndex = 0; - slotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; + // Assign the slots, note that only t0 and s0 will work as of writing this test + XGL_DESCRIPTOR_SLOT_INFO *vsSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); + vsSlotInfo[0].shaderEntityIndex = 0; + vsSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; + vsSlotInfo[1].shaderEntityIndex = 0; + vsSlotInfo[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].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) slotInfo; - vs_stage.shader.descriptorSetMapping[0].descriptorCount = slots; + vs_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) vsSlotInfo; + vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots; 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; + const int psSlots = 2; // One texture, one sampler + + // Create descriptor set for single texture and sampler + XGL_DESCRIPTOR_SET_CREATE_INFO psDescriptorInfo = {}; + psDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; + psDescriptorInfo.slots = psSlots; + err = xglCreateDescriptorSet( device(), &psDescriptorInfo, &m_rsrcDescSet ); + ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; + err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); + + // Assign the slots, note that only t0 and s0 will work as of writing this test + XGL_DESCRIPTOR_SLOT_INFO *psSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); + psSlotInfo[0].shaderEntityIndex = 0; + psSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; + psSlotInfo[1].shaderEntityIndex = 0; + psSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER; + 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 = slots; + ps_stage.shader.descriptorSetMapping[0].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) psSlotInfo; + 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; @@ -1446,132 +1238,17 @@ void XglRenderTest::CreatePipelineVSFSUniformBlock(XGL_PIPELINE* pipeline, XGL_S ASSERT_XGL_SUCCESS(err); } -void XglRenderTest::CreatePipelineSingleTextureAndSampler(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps) +void XglRenderTest::CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, + int textureCount, int samplerCount) { - // based on CreatePipelineVSUniform + // based on CreatePipelineSingleTextureAndSampler 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 vsSlots = 2; // One texture, one sampler - - // Create descriptor set for single texture and sampler - XGL_DESCRIPTOR_SET_CREATE_INFO vsDescriptorInfo = {}; - vsDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; - vsDescriptorInfo.slots = vsSlots; - err = xglCreateDescriptorSet( device(), &vsDescriptorInfo, &m_rsrcDescSet ); - ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; - err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); - - // Assign the slots, note that only t0 and s0 will work as of writing this test - XGL_DESCRIPTOR_SLOT_INFO *vsSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( vsSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); - vsSlotInfo[0].shaderEntityIndex = 0; - vsSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; - vsSlotInfo[1].shaderEntityIndex = 0; - vsSlotInfo[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].pDescriptorInfo = (const XGL_DESCRIPTOR_SLOT_INFO*) vsSlotInfo; - vs_stage.shader.descriptorSetMapping[0].descriptorCount = vsSlots; - 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; - - const int psSlots = 2; // One texture, one sampler - - // Create descriptor set for single texture and sampler - XGL_DESCRIPTOR_SET_CREATE_INFO psDescriptorInfo = {}; - psDescriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO; - psDescriptorInfo.slots = psSlots; - err = xglCreateDescriptorSet( device(), &psDescriptorInfo, &m_rsrcDescSet ); - ASSERT_XGL_SUCCESS(err) << "xglCreateDescriptorSet failed"; - err = m_device->AllocAndBindGpuMemory(m_rsrcDescSet, "DescriptorSet", &m_descriptor_set_mem); - - // Assign the slots, note that only t0 and s0 will work as of writing this test - XGL_DESCRIPTOR_SLOT_INFO *psSlotInfo = (XGL_DESCRIPTOR_SLOT_INFO*) malloc( psSlots * sizeof(XGL_DESCRIPTOR_SLOT_INFO) ); - psSlotInfo[0].shaderEntityIndex = 0; - psSlotInfo[0].slotObjectType = XGL_SLOT_SHADER_RESOURCE; - psSlotInfo[1].shaderEntityIndex = 0; - psSlotInfo[1].slotObjectType = XGL_SLOT_SHADER_SAMPLER; - - 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*) psSlotInfo; - 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::CreatePipelineMultipleTexturesAndSamplers(XGL_PIPELINE* pipeline, XGL_SHADER vs, XGL_SHADER ps, - int textureCount, int samplerCount) -{ - // based on CreatePipelineSingleTextureAndSampler - - 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 = textureCount + samplerCount; + const int psSlots = textureCount + samplerCount; // Create descriptor set for single texture and sampler XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {}; @@ -1736,111 +1413,6 @@ void XglRenderTest::DrawTriangleWithVertexFetch(const char *vertShaderText, cons } -void XglRenderTest::DrawTriangleFSUniformBlock(const char *vertShaderText, const char *fragShaderText) -{ - // probably sourced from 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(CreateDefaultPipeline(&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()); - - - // Let's populate our buffer with the following: - // vec4 red; - // vec4 green; - // vec4 blue; - // vec4 white; - const int valCount = 4 * 4; - const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0, - 0.0, 1.0, 0.0, 1.0, - 0.0, 0.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0 }; - - InitConstantBuffer(valCount, sizeof(bufferVals[0]), (const void*) bufferVals); - - // Create descriptor set for a uniform resource - const int slotCount = 1; - 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 constant buffer view to the descriptor set - xglBeginDescriptorSetUpdate( m_rsrcDescSet ); - xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); - 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::DrawTriangleFSUniformBlockBinding(const char *vertShaderText, const char *fragShaderText) { // sourced from DrawTriangleFSUniformBlock @@ -2072,154 +1644,27 @@ void XglRenderTest::DrawSamplerBindingsTriangle(const char *vertShaderText, cons } -void XglRenderTest::DrawTriangleVSFSUniformBlock(const char *vertShaderText, const char *fragShaderText) +TEST_F(XglRenderTest, GreenTriangle) { - // this is sourced from DrawTriangleFSUniformBlock - - 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(CreatePipelineVSFSUniformBlock(&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)); + static const char *vertShaderText = + "#version 130\n" + "vec2 vertices[3];\n" + "void main() {\n" + " vertices[0] = vec2(-1.0, -1.0);\n" + " vertices[1] = vec2( 1.0, -1.0);\n" + " vertices[2] = vec2( 0.0, 1.0);\n" + " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" + "}\n"; - ASSERT_NO_FATAL_FAILURE(InitRenderTarget()); + static const char *fragShaderText = + "#version 130\n" + "void main() {\n" + " gl_FragColor = vec4(0,1,0,1);\n" + "}\n"; - - // Let's populate our buffer with the following: - // vec4 red; - // vec4 green; - // vec4 blue; - // vec4 white; - const int valCount = 4 * 4; - const float bufferVals[valCount] = { 1.0, 0.0, 0.0, 1.0, - 0.0, 1.0, 0.0, 1.0, - 0.0, 0.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0 }; - - InitConstantBuffer(valCount, sizeof(bufferVals[0]), (const void*) bufferVals); - - // Create descriptor set for a uniform resource - const int slotCount = 1; - 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 constant buffer view to the descriptor set - xglBeginDescriptorSetUpdate( m_rsrcDescSet ); - xglAttachMemoryViewDescriptors( m_rsrcDescSet, 0, 1, &m_constantBufferView ); - 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); - -} - -TEST_F(XglRenderTest, GreenTriangle) -{ - static const char *vertShaderText = - "#version 130\n" - "vec2 vertices[3];\n" - "void main() {\n" - " vertices[0] = vec2(-1.0, -1.0);\n" - " vertices[1] = vec2( 1.0, -1.0);\n" - " vertices[2] = vec2( 0.0, 1.0);\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; - - static const char *fragShaderText = - "#version 130\n" - "void main() {\n" - " gl_FragColor = vec4(0,1,0,1);\n" - "}\n"; - DrawTriangleTest(vertShaderText, fragShaderText); -} - -TEST_F(XglRenderTest, BIL_GreenTriangle) -{ - bool saved_use_bil = XglTestFramework::m_use_bil; - - static const char *vertShaderText = - "#version 130\n" - "vec2 vertices[3];\n" - "void main() {\n" - " vertices[0] = vec2(-1.0, -1.0);\n" - " vertices[1] = vec2( 1.0, -1.0);\n" - " vertices[2] = vec2( 0.0, 1.0);\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; - - static const char *fragShaderText = - "#version 130\n" - "void main() {\n" - " gl_FragColor = vec4(0,1,0,1);\n" - "}\n"; - XglTestFramework::m_use_bil = true; - DrawTriangleTest(vertShaderText, fragShaderText); - XglTestFramework::m_use_bil = saved_use_bil; -} + XglTestFramework::m_use_bil = true; + DrawTriangleTest(vertShaderText, fragShaderText); +} TEST_F(XglRenderTest, MixTriangle) { @@ -2249,244 +1694,166 @@ TEST_F(XglRenderTest, MixTriangle) "}\n"; static const char *fragShaderText = - "#version 140\n" - "#extension GL_ARB_separate_shader_objects : enable\n" - "#extension GL_ARB_shading_language_420pack : enable\n" - "layout (location=1) in vec4 bar;\n" - "layout (location=0) in vec4 foo;\n" - "layout (location=2) in vec4 scale;\n" - "void main() {\n" - " gl_FragColor = bar + foo * scale.x;\n" - "}\n"; + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 1) in vec4 bar;\n" + "layout (location = 0) in vec4 foo;\n" + "layout (location = 2) in vec4 scale;\n" + "void main() {\n" + " gl_FragColor = bar + foo * scale.x;\n" + "}\n"; + + XglTestFramework::m_use_bil = true; DrawTriangleTest(vertShaderText, fragShaderText); } -TEST_F(XglRenderTest, BIL_MixTriangle) +TEST_F(XglRenderTest, TriangleWithVertexFetch) { - bool saved_use_bil = XglTestFramework::m_use_bil; - - // This tests location applied to varyings. Notice that we have switched foo - // and bar in the FS. The triangle should be blended with red, green and blue - // corners. static const char *vertShaderText = "#version 140\n" "#extension GL_ARB_separate_shader_objects : enable\n" "#extension GL_ARB_shading_language_420pack : enable\n" - "layout (location=0) out vec4 bar;\n" - "layout (location=1) out vec4 foo;\n" - "layout (location=2) out vec4 scale;\n" - "vec2 vertices[3];\n" - "void main() {\n" - " vertices[0] = vec2(-1.0, -1.0);\n" - " vertices[1] = vec2( 1.0, -1.0);\n" - " vertices[2] = vec2( 0.0, 1.0);\n" - "vec4 colors[3];\n" - " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" - " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" - " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" - " foo = colors[gl_VertexID % 3];\n" - " bar = vec4(1.0, 1.0, 1.0, 1.0);\n" - " scale.x = 0.0;\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; - - static const char *fragShaderText = - "#version 140\n" - "#extension GL_ARB_separate_shader_objects : enable\n" - "#extension GL_ARB_shading_language_420pack : enable\n" - "layout (location=1) in vec4 bar;\n" - "layout (location=0) in vec4 foo;\n" - "layout (location=2) in vec4 scale;\n" - "void main() {\n" - " gl_FragColor = bar + foo * scale.x;\n" - "}\n"; - XglTestFramework::m_use_bil = true; - DrawTriangleTest(vertShaderText, fragShaderText); - XglTestFramework::m_use_bil = saved_use_bil; -} - -TEST_F(XglRenderTest, TriangleFragUniform) -{ - - static const char *vertShaderText = - "#version 130\n" - "out vec4 color;\n" - "out vec4 scale;\n" - "vec2 vertices[3];\n" - "void main() {\n" - "vec2 vertices[3];\n" - " vertices[0] = vec2(-0.5, -0.5);\n" - " vertices[1] = vec2( 0.5, -0.5);\n" - " vertices[2] = vec2( 0.5, 0.5);\n" - "vec4 colors[3];\n" - " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" - " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" - " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" - " color = colors[gl_VertexID % 3];\n" - " scale = vec4(1.0, 1.0, 1.0, 1.0);\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; - - static const char *fragShaderText = - "#version 130\n" - "in vec4 color;\n" - "in vec4 scale;\n" - "uniform vec4 foo;\n" + //XYZ1( -1, -1, -1 ) + "layout (location = 0) in vec4 pos;\n" + //XYZ1( 0.f, 0.f, 0.f ) + "layout (location = 1) in vec4 inColor;\n" + "layout (location = 0) out vec4 outColor;\n" "void main() {\n" - " gl_FragColor = color * scale + foo;\n" + " outColor = inColor;\n" + " gl_Position = pos;\n" "}\n"; - DrawTriangleTest(vertShaderText, fragShaderText); -} - -TEST_F(XglRenderTest, YellowTriangle) -{ - static const char *vertShaderText = - "#version 130\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" - " vec4 colors[3];\n" - " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" - " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" - " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; static const char *fragShaderText = - "#version 130\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) in vec4 color;\n" "void main() {\n" - " gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n" + " gl_FragColor = color;\n" "}\n"; - DrawTriangleTest(vertShaderText, fragShaderText); + XglTestFramework::m_use_bil = true; + DrawTriangleWithVertexFetch(vertShaderText, fragShaderText); } -TEST_F(XglRenderTest, TriangleTwoFSUniforms) +TEST_F(XglRenderTest, TexturedTriangle) { + // The expected result from this test is a red and green checkered triangle static const char *vertShaderText = - "#version 130\n" - "out vec4 color;\n" - "out vec4 scale;\n" - "out vec2 samplePos;\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) 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" - " vec4 colors[3];\n" - " colors[0] = vec4(1.0, 0.0, 0.0, 1.0);\n" - " colors[1] = vec4(0.0, 1.0, 0.0, 1.0);\n" - " colors[2] = vec4(0.0, 0.0, 1.0, 1.0);\n" - " color = colors[gl_VertexID % 3];\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" - " scale = vec4(0.0, 0.0, 0.0, 0.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 430\n" - "in vec4 color;\n" - "in vec4 scale;\n" - "uniform vec4 foo;\n" - "uniform vec4 bar;\n" - "void main() {\n" - // by default, with no location or blocks - // the compiler will read them from buffer - // in reverse order of first use in shader - // The buffer contains red, followed by blue, - // so foo should be blue, bar should be red - " gl_FragColor = color * scale * foo * bar + foo;\n" - "}\n"; - - DrawTriangleTwoUniformsFS(vertShaderText, fragShaderText); -} - -TEST_F(XglRenderTest, TriangleWithVertexFetch) -{ - static const char *vertShaderText = - "#version 130\n" - //XYZ1( -1, -1, -1 ) - "in vec4 pos;\n" - //XYZ1( 0.f, 0.f, 0.f ) - "in vec4 inColor;\n" - "out vec4 outColor;\n" - "void main() {\n" - " outColor = inColor;\n" - " gl_Position = pos;\n" - "}\n"; - - - static const char *fragShaderText = - "#version 430\n" - "in vec4 color;\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) in vec2 samplePos;\n" + "layout (binding = 0) uniform sampler2D surface;\n" "void main() {\n" - " gl_FragColor = color;\n" + " vec4 texColor = textureLod(surface, samplePos, 0.0);\n" + " gl_FragColor = texColor;\n" "}\n"; - DrawTriangleWithVertexFetch(vertShaderText, fragShaderText); + XglTestFramework::m_use_bil = true; + DrawTexturedTriangle(vertShaderText, fragShaderText); } -TEST_F(XglRenderTest, TriangleVSUniform) +TEST_F(XglRenderTest, VSTexture) { + // The expected result from this test is a green and red triangle; + // one red vertex on the left, two green vertices on the right. static const char *vertShaderText = - "#version 130\n" - "uniform mat4 mvp;\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) out vec4 texColor;\n" + "layout (binding = 0) uniform sampler2D surface;\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" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0) * mvp;\n" + " vec2 positions[3];" + " positions[0] = vec2( 0.0, 0.0);\n" + " positions[1] = vec2( 0.25, 0.1);\n" + " positions[2] = vec2( 0.1, 0.25);\n" + " vec2 samplePos = positions[gl_VertexID % 3];\n" + " texColor = textureLod(surface, samplePos, 0.0);\n" + " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" "}\n"; static const char *fragShaderText = - "#version 430\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) in vec4 texColor;\n" "void main() {\n" - " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" + " gl_FragColor = texColor;\n" "}\n"; - // Create identity matrix - glm::mat4 Model = glm::mat4(1.0f); - DrawTriangleVSUniform(vertShaderText, fragShaderText); - -// Model = glm::rotate(Model, glm::radians(45.0f), glm::vec3(0.0f, 0.0f, 1.0f)); -// DrawTriangleVSUniform(vertShaderText, fragShaderText, Model); + XglTestFramework::m_use_bil = true; + DrawTexturedTriangle(vertShaderText, fragShaderText); } -TEST_F(XglRenderTest, TriangleFSUniformBlock) +TEST_F(XglRenderTest, SamplerBindingsTriangle) { - // The expected result from this test is a blue triangle - + // This test sets bindings on the samplers + // For now we are asserting that sampler and texture pairs + // march in lock step, and are set via GLSL binding. This can + // and will probably change. + // The sampler bindings should match the sampler and texture slot + // number set up by the application. + // This test will result in a blue triangle static const char *vertShaderText = - "#version 130\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) out vec4 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 = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n" " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" "}\n"; - static const char *fragShaderText = - "#version 430\n" - "layout (std140) uniform bufferVals {\n" - " vec4 red;\n" - " vec4 green;\n" - " vec4 blue;\n" - " vec4 white;\n" - "} myBufferVals;\n" + static const char *fragShaderText = + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) in vec4 samplePos;\n" + "layout (binding = 0) uniform sampler2D surface0;\n" + "layout (binding = 1) uniform sampler2D surface1;\n" + "layout (binding = 2) uniform sampler2D surface2;\n" "void main() {\n" - " gl_FragColor = myBufferVals.blue;\n" + " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n" "}\n"; - DrawTriangleFSUniformBlock(vertShaderText, fragShaderText); + XglTestFramework::m_use_bil = true; + int textureCount = g_TextureCount; + int samplerCount = g_SamplerCount; + DrawSamplerBindingsTriangle(vertShaderText, fragShaderText, textureCount, samplerCount); } TEST_F(XglRenderTest, TriangleVSUniformBlock) @@ -2495,8 +1862,10 @@ TEST_F(XglRenderTest, TriangleVSUniformBlock) static const char *vertShaderText = "#version 140\n" - "out vec4 outColor;\n" - "layout (std140) uniform bufferVals {\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) out vec4 outColor;\n" + "layout (std140, binding = 0) uniform bufferVals {\n" " vec4 red;\n" " vec4 green;\n" " vec4 blue;\n" @@ -2512,142 +1881,32 @@ TEST_F(XglRenderTest, TriangleVSUniformBlock) "}\n"; static const char *fragShaderText = - "#version 430\n" - "in vec4 inColor;\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" + "layout (location = 0) in vec4 inColor;\n" "void main() {\n" " gl_FragColor = inColor;\n" "}\n"; + XglTestFramework::m_use_bil = true; DrawTriangleVSUniformBlock(vertShaderText, fragShaderText); } -TEST_F(XglRenderTest, TriangleVSFSUniformBlock) -{ - // The expected result from this test is a green triangle - // Note the buffer is shared between stages, idenitical layout - - static const char *vertShaderText = - "#version 140\n" - "out vec4 outRed;\n" - "out vec4 outGreen;\n" - "out vec4 outBlue;\n" - "out vec4 outWhite;\n" - "layout (std140) uniform bufferVals {\n" - " vec4 red;\n" - " vec4 green;\n" - " vec4 blue;\n" - " vec4 white;\n" - "} myBufferVals;\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" - " outRed = myBufferVals.red;\n" - " outGreen = myBufferVals.green;\n" - " outBlue = myBufferVals.blue;\n" - " outWhite = myBufferVals.white;\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; - - static const char *fragShaderText = - "#version 430\n" - "in vec4 inRed;\n" - "in vec4 inGreen;\n" - "in vec4 inBlue;\n" - "in vec4 inWhite;\n" - "layout (std140) uniform bufferVals {\n" - " vec4 red;\n" - " vec4 green;\n" - " vec4 blue;\n" - " vec4 white;\n" - "} myBufferVals;\n" - "void main() {\n" - " if (inRed == myBufferVals.red && \n" - " inGreen == myBufferVals.green && \n" - " inBlue == myBufferVals.blue && \n" - " inWhite == myBufferVals.white) \n" - " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" - " else\n" - " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" - "}\n"; - - DrawTriangleVSFSUniformBlock(vertShaderText, fragShaderText); - } - - -TEST_F(XglRenderTest, TexturedTriangle) -{ - // The expected result from this test is a red and green checkered triangle - 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); -} - -TEST_F(XglRenderTest, VSTexture) -{ - // The expected result from this test is a green and red triangle; - // one red vertex on the left, two green vertices on the right. - static const char *vertShaderText = - "#version 130\n" - "out vec4 texColor;\n" - "uniform sampler2D surface;\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( 0.25, 0.1);\n" - " positions[2] = vec2( 0.1, 0.25);\n" - " vec2 samplePos = positions[gl_VertexID % 3];\n" - " texColor = textureLod(surface, samplePos, 0.0);\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; - - static const char *fragShaderText = - "#version 130\n" - "in vec4 texColor;\n" - "void main() {\n" - " gl_FragColor = texColor;\n" - "}\n"; - - DrawTexturedTriangle(vertShaderText, fragShaderText); -} - TEST_F(XglRenderTest, TriangleFSUniformBlockBinding) { // This test allows the shader to select which buffer it is // pulling from using layout binding qualifier. // There are corresponding changes in the compiler stack that // will select the buffer using binding directly. + // The binding number should match the slot number set up by + // the application. // The expected result from this test is a purple triangle static const char *vertShaderText = - "#version 130\n" + "#version 140\n" + "#extension GL_ARB_separate_shader_objects : enable\n" + "#extension GL_ARB_shading_language_420pack : enable\n" "void main() {\n" " vec2 vertices[3];" " vertices[0] = vec2(-0.5, -0.5);\n" @@ -2669,48 +1928,10 @@ TEST_F(XglRenderTest, TriangleFSUniformBlockBinding) " gl_FragColor += myRedVal.color;\n" "}\n"; + XglTestFramework::m_use_bil = true; DrawTriangleFSUniformBlockBinding(vertShaderText, fragShaderText); } -TEST_F(XglRenderTest, SamplerBindingsTriangle) -{ - // This test sets bindings on the samplers - // For this implementation, we are asserting that sampler and texture pairs - // march in lock step, and are set via GLSL binding. - // This test will result in a blue triangle - static const char *vertShaderText = - "#version 140\n" - "out vec4 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 = vec4(positions[gl_VertexID % 3], 0.0, 0.0);\n" - " gl_Position = vec4(vertices[gl_VertexID % 3], 0.0, 1.0);\n" - "}\n"; - - static const char *fragShaderText = - "#version 140\n" - "#extension GL_ARB_separate_shader_objects : enable\n" - "#extension GL_ARB_shading_language_420pack : enable\n" - "in vec4 samplePos;\n" - "layout (binding = 0) uniform sampler2D surface0;\n" - "layout (binding = 1) uniform sampler2D surface1;\n" - "layout (binding = 2) uniform sampler2D surface2;\n" - "void main() {\n" - " gl_FragColor = textureLod(surface2, samplePos.xy, 0.0);\n" - "}\n"; - - int textureCount = g_TextureCount; - int samplerCount = g_SamplerCount; - DrawSamplerBindingsTriangle(vertShaderText, fragShaderText, textureCount, samplerCount); -} - int main(int argc, char **argv) { int result;