summaryrefslogtreecommitdiffstats
path: root/tools/render-test/render-gl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-10-19 19:38:07 -0400
committerGitHub <noreply@github.com>2017-10-19 19:38:07 -0400
commit7ba937faa3f72b0f319150c3dde041d8a353c007 (patch)
tree4e4ac0f96ca2d9a7647f64e108498ea0d69c5acf /tools/render-test/render-gl.cpp
parent88023aea669f258d66e53eab10215337a7f72853 (diff)
parent5a18dc704a2f5eecebcbdd77682a40ba8316d253 (diff)
Merge pull request #225 from csyonghe/master
Support running compute shaders in testing framework
Diffstat (limited to 'tools/render-test/render-gl.cpp')
-rw-r--r--tools/render-test/render-gl.cpp68
1 files changed, 51 insertions, 17 deletions
diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp
index f02ac36c4..55647fb25 100644
--- a/tools/render-test/render-gl.cpp
+++ b/tools/render-test/render-gl.cpp
@@ -58,6 +58,7 @@
F(glEnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC) \
F(glDisableVertexAttribArray, PFNGLDISABLEVERTEXATTRIBARRAYPROC) \
F(glDebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC) \
+ F(glDispatchCompute, PFNGLDISPATCHCOMPUTEPROC) \
/* end */
namespace renderer_test {
@@ -311,8 +312,12 @@ public:
switch (flavor)
{
case MapFlavor::WriteDiscard:
+ case MapFlavor::HostWrite:
access = GL_WRITE_ONLY;
break;
+ case MapFlavor::HostRead:
+ access = GL_READ_ONLY;
+ break;
}
auto bufferID = (GLuint)(uintptr_t)buffer;
@@ -377,21 +382,32 @@ public:
glUseProgram(programID);
}
- virtual void setConstantBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) override
- {
- for (UInt ii = 0; ii < slotCount; ++ii)
- {
- UInt slot = startSlot + ii;
+ void bindBufferImpl(int target, UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets)
+ {
+ for (UInt ii = 0; ii < slotCount; ++ii)
+ {
+ UInt slot = startSlot + ii;
- Buffer* buffer = buffers[ii];
- GLuint bufferID = (GLuint)(uintptr_t)buffer;
+ Buffer* buffer = buffers[ii];
+ GLuint bufferID = (GLuint)(uintptr_t)buffer;
- assert(!offsets || !offsets[ii]);
+ assert(!offsets || !offsets[ii]);
- glBindBufferBase(GL_UNIFORM_BUFFER, (GLuint) slot, bufferID);
- }
+ glBindBufferBase(target, (GLuint)slot, bufferID);
+ }
+ }
+
+ virtual void setConstantBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) override
+ {
+ bindBufferImpl(GL_UNIFORM_BUFFER, startSlot, slotCount, buffers, offsets);
}
+
+ virtual void setStorageBuffers(UInt startSlot, UInt slotCount, Buffer* const* buffers, UInt const* offsets) override
+ {
+ bindBufferImpl(GL_SHADER_STORAGE_BUFFER, startSlot, slotCount, buffers, offsets);
+ }
+
void flushStateForDraw()
{
auto layout = this->boundInputLayout;
@@ -432,18 +448,31 @@ public:
virtual ShaderProgram* compileProgram(ShaderCompileRequest const& request) override
{
auto programID = glCreateProgram();
+ if (request.computeShader.name)
+ {
+ auto computeShaderID = loadShader(GL_COMPUTE_SHADER, request.computeShader.source.text);
- auto vertexShaderID = loadShader(GL_VERTEX_SHADER, request.vertexShader .source.text);
- auto fragmentShaderID = loadShader(GL_FRAGMENT_SHADER, request.fragmentShader.source.text);
+ glAttachShader(programID, computeShaderID);
- glAttachShader(programID, vertexShaderID);
- glAttachShader(programID, fragmentShaderID);
- glLinkProgram(programID);
+ glLinkProgram(programID);
- glDeleteShader(vertexShaderID);
- glDeleteShader(fragmentShaderID);
+ glDeleteShader(computeShaderID);
+ }
+ else
+ {
+ auto vertexShaderID = loadShader(GL_VERTEX_SHADER, request.vertexShader.source.text);
+ auto fragmentShaderID = loadShader(GL_FRAGMENT_SHADER, request.fragmentShader.source.text);
+ glAttachShader(programID, vertexShaderID);
+ glAttachShader(programID, fragmentShaderID);
+
+
+ glLinkProgram(programID);
+
+ glDeleteShader(vertexShaderID);
+ glDeleteShader(fragmentShaderID);
+ }
GLint success = GL_FALSE;
glGetProgramiv(programID, GL_LINK_STATUS, &success);
if( !success )
@@ -579,6 +608,11 @@ public:
return shaderID;
}
+
+ virtual void dispatchCompute(int x, int y, int z) override
+ {
+ glDispatchCompute(x, y, z);
+ }
};