summaryrefslogtreecommitdiffstats
path: root/tools/render-test/render-gl.cpp
diff options
context:
space:
mode:
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)