summaryrefslogtreecommitdiff
path: root/tools/render-test/render-gl.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-04-19 17:47:04 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2018-04-19 14:47:04 -0700
commit4c751df1680c30fac0369171a9b8dd4bb5bb5b9f (patch)
treeafde05a4cefd2b203add6b6ea8b94722d9734e11 /tools/render-test/render-gl.cpp
parentcbedf01cc53b848dfcc086f04098ef438121a7c7 (diff)
Separation of Binding/Resource construction on Renderer interface (#508)
* Dx12 rendering works in test framework. * Turn on dx12 render tests. * First pass at Resource and TextureResource/BufferResource types. * Fix bug in Dx11 impl for BufferResource. * Dx12 supports TextureResource and binds using TextureResource type, and all tests pass. * Added TextureBuffer::Size type to make handling mips a little simpler. * Small improvements to Dx12 constant buffer binding Removed k prefix on an enum * First pass impl of dx11 createTextureResource Added setDefaults to TextureResource::Desc and BufferResource::Desc to simplify setup accessFlags -> cpuAccessFlags desc -> srcDesc * Split out generateTextureResource - can produce the texture using createTextureResource on the Renderer. * Added support for read mapping to Dx11 accessFlags -> cpuAccessFlags First pass at using TextureResource/BufferResource on Dx11 Some tests fail with this checkin * TextureResource working on all tests on dx11. * Construct ResourceBuffers on Dx11 and Dx12 using utility function createInputBufferResource. * First pass at OpenGl TextureResource * Small fixes to dx12 and dx11 setup. Gl working working using BufferResource and TextureResource * Tidy up around the compareSampler - looks like the previous test was incorrect. * Small documentation /naming improvements. * Fix some more small documentation issues. * First pass testing out construction of binding resources external to Renderer implementation. * Moved some BindingState::Desc types to BindingState to make easier to use. * First pass of binding using BindingState::Desc for Dx11. * First pass at binding with dx12. * Fixed issues around separating dx12 binding from ShaderInputLayout * First pass at OpenGl state binding. * BindingState::Desc::Binding::Type -> BindingType * Use Buffer to manage life of vk resources. Construction of buffers handled by createBufferResource (BindingState doesn't have specialized logic) * Remove InputLayout types from binding so can create a binding independent of it. * Added upload buffer to BufferResource - could be used for write mapping. * m_samplers -> m_samplerDescs. First pass at Vk binding with BindingState::Desc. Small tidy/doc improvements. * First pass with binding all taking place through BindingState::Desc. All tests pass. * Removed support for creating BindingState from ShaderInputLayout * Remove serializeOutput from Renderer interface and all implementations. Implement map/unmap on vulkan Implement serializeBindingOutput which uses map/unmap and BindingState::Desc to write result. * Make implementation of BindingState use the BindingState::Desc for much of state - only hold api specific in BindingDetail per implementation. * Use Glsl binding on vulkan (was using hlsl). * BindingState::Desc::Binding -> BindingState::Binding. Made possible by impls using 'BindingDetail' for their specific needs. * Fix compile problems on win32. * Fix a typo in name createBindingSetDesc -> createBindingStateDesc
Diffstat (limited to 'tools/render-test/render-gl.cpp')
-rw-r--r--tools/render-test/render-gl.cpp208
1 files changed, 95 insertions, 113 deletions
diff --git a/tools/render-test/render-gl.cpp b/tools/render-test/render-gl.cpp
index 27c3cdab4..8db963014 100644
--- a/tools/render-test/render-gl.cpp
+++ b/tools/render-test/render-gl.cpp
@@ -11,8 +11,6 @@
#include "core/secure-crt.h"
#include "external/stb/stb_image_write.h"
-#include "slang-support.h"
-
// TODO(tfoley): eventually we should be able to run these
// tests on non-Windows targets to confirm that cross-compilation
// at least *works* on those platforms...
@@ -87,9 +85,8 @@ public:
virtual TextureResource* createTextureResource(Resource::Type type, Resource::Usage initialUsage, const TextureResource::Desc& desc, const TextureResource::Data* initData) override;
virtual BufferResource* createBufferResource(Resource::Usage initialUsage, const BufferResource::Desc& descIn, const void* initData) override;
virtual SlangResult captureScreenShot(char const* outputPath) override;
- virtual void serializeOutput(BindingState* state, const char* fileName) override;
virtual InputLayout* createInputLayout(const InputElementDesc* inputElements, UInt inputElementCount) override;
- virtual BindingState * createBindingState(const ShaderInputLayout& layout) override;
+ virtual BindingState* createBindingState(const BindingState::Desc& bindingStateDesc) override;
virtual ShaderCompiler* getShaderCompiler() override;
virtual void* map(BufferResource* buffer, MapFlavor flavor) override;
virtual void unmap(BufferResource* buffer) override;
@@ -188,19 +185,20 @@ public:
GLuint m_handle;
};
- struct BindingEntry
+ struct BindingDetail
{
- ShaderInputType type;
- RefPtr<Resource> resource;
- GLuint samplerHandle = 0;
- List<int> binding;
- bool isOutput = false;
+ GLuint m_samplerHandle = 0;
+ int m_firstBinding; //< Holds binding index if not sampler (which has multiple, and can be read from the BindingState::Desc)
};
class BindingStateImpl: public BindingState
{
public:
- BindingStateImpl(GLRenderer* renderer):
+ typedef BindingState Parent;
+
+ /// Ctor
+ BindingStateImpl(const Desc& desc, GLRenderer* renderer):
+ Parent(desc),
m_renderer(renderer)
{
}
@@ -209,12 +207,12 @@ public:
{
if (m_renderer)
{
- m_renderer->destroyBindingEntries(m_entries.Buffer(), int(m_entries.Count()));
+ m_renderer->destroyBindingEntries(getDesc(), m_bindingDetails.Buffer());
}
}
GLRenderer* m_renderer;
- List<BindingEntry> m_entries;
+ List<BindingDetail> m_bindingDetails;
};
class ShaderProgramImpl : public ShaderProgram
@@ -251,14 +249,13 @@ public:
GLenum formatType; // such as GL_UNSIGNED_BYTE
};
- void destroyBindingEntries(const BindingEntry* entries, int numEntries);
+ void destroyBindingEntries(const BindingState::Desc& desc, const BindingDetail* details);
void bindBufferImpl(int target, UInt startSlot, UInt slotCount, BufferResource*const* buffers, const UInt* offsets);
void flushStateForDraw();
GLuint loadShader(GLenum stage, char const* source);
void debugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message);
- void createInputSampler(BindingEntry& rs, InputSamplerDesc samplerDesc);
-
+
/// Returns GlPixelFormat::Unknown if not an equivalent
static GlPixelFormat _getGlPixelFormat(Format format);
@@ -497,44 +494,22 @@ GLuint GLRenderer::loadShader(GLenum stage, const char* source)
return shaderID;
}
-void GLRenderer::destroyBindingEntries(const BindingEntry* entries, int numEntries)
+void GLRenderer::destroyBindingEntries(const BindingState::Desc& desc, const BindingDetail* details)
{
- for (int i = 0; i < numEntries; ++i)
+ const auto& bindings = desc.m_bindings;
+ const int numBindings = int(bindings.Count());
+ for (int i = 0; i < numBindings; ++i)
{
- const BindingEntry& entry = entries[i];
- if (entry.type == ShaderInputType::Sampler && entry.samplerHandle != 0)
+ const auto& binding = bindings[i];
+ const auto& detail = details[i];
+
+ if (binding.bindingType == BindingType::Sampler && detail.m_samplerHandle != 0)
{
- glDeleteSamplers(1, &entry.samplerHandle);
+ glDeleteSamplers(1, &detail.m_samplerHandle);
}
}
}
-void GLRenderer::createInputSampler(BindingEntry& entry, InputSamplerDesc samplerDesc)
-{
- GLuint handle;
-
- glCreateSamplers(1, &handle);
- glSamplerParameteri(handle, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glSamplerParameteri(handle, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glSamplerParameteri(handle, GL_TEXTURE_WRAP_R, GL_REPEAT);
-
- if (samplerDesc.isCompareSampler)
- {
- glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glSamplerParameteri(handle, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
- glSamplerParameteri(handle, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
- }
- else
- {
- glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glSamplerParameteri(handle, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8);
- }
-
- entry.samplerHandle = handle;
-}
-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!! Renderer interface !!!!!!!!!!!!!!!!!!!!!!!!!!
SlangResult GLRenderer::initialize(void* inWindowHandle)
@@ -937,37 +912,39 @@ void GLRenderer::dispatchCompute(int x, int y, int z)
glDispatchCompute(x, y, z);
}
-BindingState* GLRenderer::createBindingState(const ShaderInputLayout& layout)
+BindingState* GLRenderer::createBindingState(const BindingState::Desc& bindingStateDesc)
{
- BindingStateImpl* state = new BindingStateImpl(this);
- for (auto & srcEntry : layout.entries)
+ RefPtr<BindingStateImpl> bindingState(new BindingStateImpl(bindingStateDesc, this));
+
+ const auto& srcBindings = bindingStateDesc.m_bindings;
+ const int numBindings = int(srcBindings.Count());
+
+ auto& dstDetails = bindingState->m_bindingDetails;
+ dstDetails.SetSize(numBindings);
+
+ for (int i = 0; i < numBindings; ++i)
{
- BindingEntry dstEntry;
- dstEntry.isOutput = srcEntry.isOutput;
- dstEntry.binding = srcEntry.glslBinding;
- dstEntry.type = srcEntry.type;
+ auto& dstDetail = dstDetails[i];
+ const auto& srcBinding = srcBindings[i];
- switch (srcEntry.type)
+ // Copy over the bindings
+ dstDetail.m_firstBinding = bindingStateDesc.getFirst(BindingState::ShaderStyle::Glsl, srcBinding.registerDesc);
+
+ switch (srcBinding.bindingType)
{
- case ShaderInputType::Buffer:
+ case BindingType::Texture:
+ case BindingType::Buffer:
{
- RefPtr<BufferResource> bufferResource;
- SLANG_RETURN_NULL_ON_FAIL(createInputBufferResource(srcEntry.bufferDesc, srcEntry.isOutput, srcEntry.bufferData.Count() * sizeof(uint32_t), srcEntry.bufferData.Buffer(), this, bufferResource));
- dstEntry.resource = bufferResource;
break;
}
- case ShaderInputType::Texture:
- case ShaderInputType::CombinedTextureSampler:
+ case BindingType::CombinedTextureSampler:
{
- RefPtr<TextureResource> textureResource;
+ assert(srcBinding.resource && srcBinding.resource->isTexture());
+ TextureResourceImpl* texture = static_cast<TextureResourceImpl*>(srcBinding.resource.Ptr());
+ const BindingState::SamplerDesc& samplerDesc = bindingStateDesc.m_samplerDescs[srcBinding.descIndex];
- int bindFlags = 0;
- SLANG_RETURN_NULL_ON_FAIL(generateTextureResource(srcEntry.textureDesc, bindFlags, this, textureResource));
-
- // Handle if combined
- if (srcEntry.type == ShaderInputType::CombinedTextureSampler && srcEntry.samplerDesc.isCompareSampler)
+ if (samplerDesc.isCompareSampler)
{
- TextureResourceImpl* texture = static_cast<TextureResourceImpl*>(textureResource.Ptr());
auto target = texture->m_target;
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -975,47 +952,80 @@ BindingState* GLRenderer::createBindingState(const ShaderInputLayout& layout)
glTexParameteri(target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(target, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
}
-
break;
}
- case ShaderInputType::Sampler:
+ case BindingType::Sampler:
{
- createInputSampler(dstEntry, srcEntry.samplerDesc);
+ const BindingState::SamplerDesc& samplerDesc = bindingStateDesc.m_samplerDescs[srcBinding.descIndex];
+
+ GLuint handle;
+
+ glCreateSamplers(1, &handle);
+ glSamplerParameteri(handle, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glSamplerParameteri(handle, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glSamplerParameteri(handle, GL_TEXTURE_WRAP_R, GL_REPEAT);
+
+ if (samplerDesc.isCompareSampler)
+ {
+ glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glSamplerParameteri(handle, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
+ glSamplerParameteri(handle, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
+ }
+ else
+ {
+ glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glSamplerParameteri(handle, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8);
+ }
+
+ dstDetail.m_samplerHandle = handle;
break;
}
}
- state->m_entries.Add(dstEntry);
}
- return state;
+
+ return bindingState.detach();
}
void GLRenderer::setBindingState(BindingState* stateIn)
{
BindingStateImpl* state = static_cast<BindingStateImpl*>(stateIn);
- for (auto & entry : state->m_entries)
+
+ const auto& bindingDesc = state->getDesc();
+
+ const auto& details = state->m_bindingDetails;
+ const auto& bindings = bindingDesc.m_bindings;
+ const int numBindings = int(bindings.Count());
+
+ for (int i = 0; i < numBindings; ++i)
{
- switch (entry.type)
+ const auto& binding = bindings[i];
+ const auto& detail = details[i];
+
+ switch (binding.bindingType)
{
- case ShaderInputType::Buffer:
+ case BindingType::Buffer:
{
- BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(entry.resource.Ptr());
- glBindBufferBase(buffer->m_target, entry.binding[0], buffer->m_handle);
+ BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(binding.resource.Ptr());
+ glBindBufferBase(buffer->m_target, detail.m_firstBinding, buffer->m_handle);
break;
}
- case ShaderInputType::Sampler:
+ case BindingType::Sampler:
{
- for (auto b : entry.binding)
+ auto bindings = bindingDesc.asRegisterList(BindingState::ShaderStyle::Glsl, binding.registerDesc);
+ for (auto b : bindings)
{
- glBindSampler(b, entry.samplerHandle);
+ glBindSampler(b, detail.m_samplerHandle);
}
break;
}
- case ShaderInputType::Texture:
- case ShaderInputType::CombinedTextureSampler:
+ case BindingType::Texture:
+ case BindingType::CombinedTextureSampler:
{
- BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(entry.resource.Ptr());
+ BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(binding.resource.Ptr());
- glActiveTexture(GL_TEXTURE0 + entry.binding[0]);
+ glActiveTexture(GL_TEXTURE0 + detail.m_firstBinding);
glBindTexture(buffer->m_target, buffer->m_handle);
break;
}
@@ -1023,34 +1033,6 @@ void GLRenderer::setBindingState(BindingState* stateIn)
}
}
-void GLRenderer::serializeOutput(BindingState* stateIn, const char* fileName)
-{
- BindingStateImpl * state = (BindingStateImpl*)stateIn;
- FILE * f;
- fopen_s(&f, fileName, "wt");
- for (auto & entry : state->m_entries)
- {
- if (entry.isOutput)
- {
- if (entry.resource && entry.resource->isBuffer())
- {
- BufferResource* bufferResource = static_cast<BufferResource*>(entry.resource.Ptr());
- size_t bufferSize = bufferResource->getDesc().sizeInBytes;
-
- unsigned int* ptr = (unsigned int*)map(bufferResource, MapFlavor::HostRead);
-
- for (auto i = 0u; i < bufferSize / sizeof(unsigned int); i++)
- {
- fprintf(f, "%X\n", ptr[i]);
- }
- unmap(bufferResource);
- }
- }
- }
- fclose(f);
-}
-
-
// ShaderCompiler interface
ShaderProgram* GLRenderer::compileProgram(const ShaderCompileRequest& request)