triangle: Hook up a uniform read in fragment shader
Add a constant buffer and descriptor set to render_test
Read the uniform in fragment shader, add it to existing color
Triangle colors should remain, but be whiter
diff --git a/tests/render_tests.cpp b/tests/render_tests.cpp
index b872f8b..530d78b 100644
--- a/tests/render_tests.cpp
+++ b/tests/render_tests.cpp
@@ -234,7 +234,6 @@
XGL_SAMPLER m_sampler;
-
XGL_GPU_MEMORY m_vtxBufferMem;
XGL_GPU_MEMORY m_constantBufferMem;
XGL_UINT32 m_numMemRefs;
@@ -637,7 +636,6 @@
XGL_GRAPHICS_PIPELINE_CREATE_INFO info = {};
XGL_PIPELINE_SHADER_STAGE_CREATE_INFO vs_stage;
XGL_PIPELINE_SHADER_STAGE_CREATE_INFO ps_stage;
- //XGL_PIPELINE pipeline;
// create a raster state (solid, back-face culling)
XGL_RASTER_STATE_CREATE_INFO raster = {};
@@ -892,9 +890,11 @@
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::GenerateClearAndPrepareBufferCmds(XglImage *renderTarget)
@@ -963,11 +963,8 @@
XGL_SHADER vs, ps;
XGL_RESULT err;
int width = 256, height = 256;
- CreateDefaultPipeline(&pipeline, &vs, &ps, width, height);
- //ASSERT_XGL_SUCCESS(err);
- err = m_device->AllocAndBindGpuMemory(pipeline, "Pipeline", &m_pipe_mem);
- ASSERT_XGL_SUCCESS(err);
+ ASSERT_NO_FATAL_FAILURE(CreateDefaultPipeline(&pipeline, &vs, &ps, width, height));
/*
* Shaders are now part of the pipeline, don't need these anymore
@@ -989,6 +986,27 @@
XGL_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
&renderTarget));
+ const int constantCount = 4;
+ const float constants[constantCount] = { 0.5, 0.5, 0.5, 1.0 };
+ InitConstantBuffer(constantCount, sizeof(constants[0]), (const void*) constants);
+
+ // Create descriptor set for a uniform resource
+ XGL_DESCRIPTOR_SET_CREATE_INFO descriptorInfo = {};
+ descriptorInfo.sType = XGL_STRUCTURE_TYPE_DESCRIPTOR_SET_CREATE_INFO;
+ descriptorInfo.slots = 1;
+
+ // 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);