summaryrefslogtreecommitdiff
path: root/tools/render-test
diff options
context:
space:
mode:
Diffstat (limited to 'tools/render-test')
-rw-r--r--tools/render-test/main.cpp117
-rw-r--r--tools/render-test/options.h2
-rw-r--r--tools/render-test/png-serialize-util.h2
-rw-r--r--tools/render-test/render-test.vcxproj10
-rw-r--r--tools/render-test/shader-input-layout.h2
-rw-r--r--tools/render-test/shader-renderer-util.cpp251
-rw-r--r--tools/render-test/shader-renderer-util.h56
-rw-r--r--tools/render-test/slang-support.cpp4
-rw-r--r--tools/render-test/slang-support.h4
9 files changed, 353 insertions, 95 deletions
diff --git a/tools/render-test/main.cpp b/tools/render-test/main.cpp
index 935b9bc98..4734c2c8f 100644
--- a/tools/render-test/main.cpp
+++ b/tools/render-test/main.cpp
@@ -29,6 +29,8 @@
namespace renderer_test {
+using Slang::Result;
+
int gWindowWidth = 1024;
int gWindowHeight = 768;
@@ -45,7 +47,7 @@ struct Vertex
float uv[2];
};
-static const Vertex kVertexData[] =
+static const Vertex kVertexData[] =
{
{ { 0, 0, 0.5 }, {1, 0, 0} , {0, 0} },
{ { 0, 1, 0.5 }, {0, 0, 1} , {1, 0} },
@@ -61,15 +63,15 @@ class RenderTestApp
// At initialization time, we are going to load and compile our Slang shader
// code, and then create the API objects we need for rendering.
- Result initialize(Renderer* renderer, ShaderCompiler* shaderCompiler);
+ Result initialize(Renderer* renderer, ShaderCompiler* shaderCompiler);
void runCompute();
void renderFrame();
void finalize();
- BindingState* getBindingState() const { return m_bindingState; }
+ BindingStateImpl* getBindingState() const { return m_bindingState; }
Result writeBindingOutput(const char* fileName);
-
+
Result writeScreen(const char* filename);
protected:
@@ -85,7 +87,8 @@ class RenderTestApp
RefPtr<InputLayout> m_inputLayout;
RefPtr<BufferResource> m_vertexBuffer;
RefPtr<ShaderProgram> m_shaderProgram;
- RefPtr<BindingState> m_bindingState;
+ RefPtr<PipelineState> m_pipelineState;
+ RefPtr<BindingStateImpl> m_bindingState;
ShaderInputLayout m_shaderInputLayout; ///< The binding layout
int m_numAddedConstantBuffers; ///< Constant buffers can be added to the binding directly. Will be added at the end.
@@ -117,22 +120,26 @@ SlangResult RenderTestApp::initialize(Renderer* renderer, ShaderCompiler* shader
}
{
- BindingState::Desc bindingStateDesc;
- SLANG_RETURN_ON_FAIL(ShaderRendererUtil::createBindingStateDesc(m_shaderInputLayout, m_renderer, bindingStateDesc));
-
- //! Hack -> if bindings are specified, just set up the constant buffer binding
- // Should probably be more sophisticated than this - with 'dynamic' constant buffer/s binding always being specified
- // in the test file
-
- if ((gOptions.shaderType == Options::ShaderProgramType::Graphics || gOptions.shaderType == Options::ShaderProgramType::GraphicsCompute)
- && bindingStateDesc.findBindingIndex(Resource::BindFlag::ConstantBuffer, 0) < 0)
+ //! Hack -> if doing a graphics test, add an extra binding for our dynamic constant buffer
+ //
+ // TODO: Should probably be more sophisticated than this - with 'dynamic' constant buffer/s binding always being specified
+ // in the test file
+ RefPtr<BufferResource> addedConstantBuffer;
+ switch(gOptions.shaderType)
{
- bindingStateDesc.addResource(BindingType::Buffer, m_constantBuffer, BindingState::RegisterRange::makeSingle(0) );
+ default:
+ break;
+ case Options::ShaderProgramType::Graphics:
+ case Options::ShaderProgramType::GraphicsCompute:
+ addedConstantBuffer = m_constantBuffer;
m_numAddedConstantBuffers++;
+ break;
}
- m_bindingState = m_renderer->createBindingState(bindingStateDesc);
+ BindingStateImpl* bindingState = nullptr;
+ SLANG_RETURN_ON_FAIL(ShaderRendererUtil::createBindingState(m_shaderInputLayout, m_renderer, addedConstantBuffer, &bindingState));
+ m_bindingState = bindingState;
}
// Do other initialization that doesn't depend on the source language.
@@ -156,6 +163,38 @@ SlangResult RenderTestApp::initialize(Renderer* renderer, ShaderCompiler* shader
if(!m_vertexBuffer)
return SLANG_FAIL;
+ {
+ switch(gOptions.shaderType)
+ {
+ default:
+ assert(!"unexpected test shader type");
+ return SLANG_FAIL;
+
+ case Options::ShaderProgramType::Compute:
+ {
+ ComputePipelineStateDesc desc;
+ desc.pipelineLayout = m_bindingState->pipelineLayout;
+ desc.program = m_shaderProgram;
+
+ m_pipelineState = renderer->createComputePipelineState(desc);
+ }
+ break;
+
+ case Options::ShaderProgramType::Graphics:
+ case Options::ShaderProgramType::GraphicsCompute:
+ {
+ GraphicsPipelineStateDesc desc;
+ desc.pipelineLayout = m_bindingState->pipelineLayout;
+ desc.program = m_shaderProgram;
+ desc.inputLayout = m_inputLayout;
+ desc.renderTargetCount = m_bindingState->m_numRenderTargets;
+
+ m_pipelineState = renderer->createGraphicsPipelineState(desc);
+ }
+ break;
+ }
+ }
+
return SLANG_OK;
}
@@ -182,6 +221,16 @@ Result RenderTestApp::initializeShaders(ShaderCompiler* shaderCompiler)
fclose(sourceFile);
sourceText[sourceSize] = 0;
+ switch( gOptions.shaderType )
+ {
+ default:
+ m_shaderInputLayout.numRenderTargets = 1;
+ break;
+
+ case Options::ShaderProgramType::Compute:
+ m_shaderInputLayout.numRenderTargets = 0;
+ break;
+ }
m_shaderInputLayout.Parse(sourceText);
ShaderCompileRequest::SourceInfo sourceInfo;
@@ -220,31 +269,27 @@ void RenderTestApp::renderFrame()
{
const ProjectionStyle projectionStyle = RendererUtil::getProjectionStyle(m_renderer->getRendererType());
RendererUtil::getIdentityProjection(projectionStyle, (float*)mappedData);
-
+
m_renderer->unmap(m_constantBuffer);
}
- // Input Assembler (IA)
+ auto pipelineType = PipelineType::Graphics;
- m_renderer->setInputLayout(m_inputLayout);
- m_renderer->setPrimitiveTopology(PrimitiveTopology::TriangleList);
+ m_renderer->setPipelineState(pipelineType, m_pipelineState);
+ m_renderer->setPrimitiveTopology(PrimitiveTopology::TriangleList);
m_renderer->setVertexBuffer(0, m_vertexBuffer, sizeof(Vertex));
- // Vertex Shader (VS)
- // Pixel Shader (PS)
-
- m_renderer->setShaderProgram(m_shaderProgram);
- m_renderer->setBindingState(m_bindingState);
- //
+ m_bindingState->apply(m_renderer, pipelineType);
m_renderer->draw(3);
}
void RenderTestApp::runCompute()
{
- m_renderer->setShaderProgram(m_shaderProgram);
- m_renderer->setBindingState(m_bindingState);
+ auto pipelineType = PipelineType::Compute;
+ m_renderer->setPipelineState(pipelineType, m_pipelineState);
+ m_bindingState->apply(m_renderer, pipelineType);
m_renderer->dispatchCompute(1, 1, 1);
}
@@ -265,18 +310,12 @@ Result RenderTestApp::writeBindingOutput(const char* fileName)
return SLANG_FAIL;
}
- const BindingState::Desc& bindingStateDesc = m_bindingState->getDesc();
- // Must be the same amount of entries
- assert(bindingStateDesc.m_bindings.Count() == m_shaderInputLayout.entries.Count() + m_numAddedConstantBuffers);
-
- const int numBindings = int(m_shaderInputLayout.entries.Count());
-
- for (int i = 0; i < numBindings; ++i)
+ for(auto binding : m_bindingState->outputBindings)
{
+ auto i = binding.entryIndex;
const auto& layoutBinding = m_shaderInputLayout.entries[i];
- const auto& binding = bindingStateDesc.m_bindings[i];
- if (layoutBinding.isOutput)
+ assert(layoutBinding.isOutput);
{
if (binding.resource && binding.resource->isBuffer())
{
@@ -524,11 +563,11 @@ SlangResult innerMain(int argc, char** argv)
else
{
Result res = app.writeScreen(gOptions.outputPath);
-
+
if (SLANG_FAILED(res))
{
fprintf(stderr, "ERROR: failed to write screen capture to file\n");
- return res;
+ return res;
}
}
return SLANG_OK;
diff --git a/tools/render-test/options.h b/tools/render-test/options.h
index 82c018f66..78f673796 100644
--- a/tools/render-test/options.h
+++ b/tools/render-test/options.h
@@ -9,7 +9,7 @@
namespace renderer_test {
-using namespace slang_graphics;
+using namespace gfx;
struct Options
{
diff --git a/tools/render-test/png-serialize-util.h b/tools/render-test/png-serialize-util.h
index dad17ae74..1ec5204f7 100644
--- a/tools/render-test/png-serialize-util.h
+++ b/tools/render-test/png-serialize-util.h
@@ -5,7 +5,7 @@
namespace renderer_test {
-using namespace slang_graphics;
+using namespace gfx;
struct PngSerializeUtil
{
diff --git a/tools/render-test/render-test.vcxproj b/tools/render-test/render-test.vcxproj
index 66ad9e7ed..91c8bd997 100644
--- a/tools/render-test/render-test.vcxproj
+++ b/tools/render-test/render-test.vcxproj
@@ -99,7 +99,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@@ -117,7 +117,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@@ -135,7 +135,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -157,7 +157,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\slang-graphics;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -196,7 +196,7 @@
<ProjectReference Include="..\..\source\slang\slang.vcxproj">
<Project>{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}</Project>
</ProjectReference>
- <ProjectReference Include="..\slang-graphics\slang-graphics.vcxproj">
+ <ProjectReference Include="..\gfx\gfx.vcxproj">
<Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project>
</ProjectReference>
</ItemGroup>
diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h
index 19a7e59d0..92dd516a7 100644
--- a/tools/render-test/shader-input-layout.h
+++ b/tools/render-test/shader-input-layout.h
@@ -7,7 +7,7 @@
namespace renderer_test {
-using namespace slang_graphics;
+using namespace gfx;
enum class ShaderInputType
{
diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp
index e46c725bc..f6c0366bb 100644
--- a/tools/render-test/shader-renderer-util.cpp
+++ b/tools/render-test/shader-renderer-util.cpp
@@ -5,6 +5,16 @@
namespace renderer_test {
using namespace Slang;
+using Slang::Result;
+
+void BindingStateImpl::apply(Renderer* renderer, PipelineType pipelineType)
+{
+ renderer->setDescriptorSet(
+ pipelineType,
+ pipelineLayout,
+ 0,
+ descriptorSet);
+}
/* static */Result ShaderRendererUtil::generateTextureResource(const InputTextureDesc& inputDesc, int bindFlags, Renderer* renderer, RefPtr<TextureResource>& textureOut)
{
@@ -125,16 +135,27 @@ using namespace Slang;
return SLANG_OK;
}
-static BindingState::SamplerDesc _calcSamplerDesc(const InputSamplerDesc& srcDesc)
+static SamplerState::Desc _calcSamplerDesc(const InputSamplerDesc& srcDesc)
{
- BindingState::SamplerDesc dstDesc;
- dstDesc.isCompareSampler = srcDesc.isCompareSampler;
+ SamplerState::Desc dstDesc;
+ if (srcDesc.isCompareSampler)
+ {
+ dstDesc.reductionOp = TextureReductionOp::Comparison;
+ dstDesc.comparisonFunc = ComparisonFunc::Less;
+ }
return dstDesc;
}
-/* static */BindingState::RegisterRange ShaderRendererUtil::calcRegisterRange(Renderer* renderer, const ShaderInputLayoutEntry& entry)
+static RefPtr<SamplerState> _createSamplerState(
+ Renderer* renderer,
+ const InputSamplerDesc& srcDesc)
{
- typedef BindingState::RegisterRange RegisterRange;
+ return renderer->createSamplerState(_calcSamplerDesc(srcDesc));
+}
+
+/* static */BindingStateImpl::RegisterRange ShaderRendererUtil::calcRegisterRange(Renderer* renderer, const ShaderInputLayoutEntry& entry)
+{
+ typedef BindingStateImpl::RegisterRange RegisterRange;
BindingStyle bindingStyle = RendererUtil::getBindingStyle(renderer->getRendererType());
@@ -179,71 +200,227 @@ static BindingState::SamplerDesc _calcSamplerDesc(const InputSamplerDesc& srcDes
return RegisterRange::makeInvalid();
}
-/* static */Result ShaderRendererUtil::createBindingStateDesc(ShaderInputLayoutEntry* srcEntries, int numEntries, Renderer* renderer, BindingState::Desc& descOut)
+/* static */Result ShaderRendererUtil::createBindingState(const ShaderInputLayout& layout, Renderer* renderer, BufferResource* addedConstantBuffer, BindingStateImpl** outBindingState)
{
+ auto srcEntries = layout.entries.Buffer();
+ auto numEntries = int(layout.entries.Count());
+
const int textureBindFlags = Resource::BindFlag::NonPixelShaderResource | Resource::BindFlag::PixelShaderResource;
- descOut.clear();
+ List<DescriptorSetLayout::SlotRangeDesc> slotRangeDescs;
+
+ if(addedConstantBuffer)
+ {
+ DescriptorSetLayout::SlotRangeDesc slotRangeDesc;
+ slotRangeDesc.type = DescriptorSlotType::UniformBuffer;
+
+ slotRangeDescs.Add(slotRangeDesc);
+ }
+
for (int i = 0; i < numEntries; i++)
{
const ShaderInputLayoutEntry& srcEntry = srcEntries[i];
- const BindingState::RegisterRange registerSet = calcRegisterRange(renderer, srcEntry);
+ const BindingStateImpl::RegisterRange registerSet = calcRegisterRange(renderer, srcEntry);
if (!registerSet.isValid())
{
assert(!"Couldn't find a binding");
return SLANG_FAIL;
}
+ DescriptorSetLayout::SlotRangeDesc slotRangeDesc;
+
switch (srcEntry.type)
{
case ShaderInputType::Buffer:
- {
- const InputBufferDesc& srcBuffer = srcEntry.bufferDesc;
+ {
+ const InputBufferDesc& srcBuffer = srcEntry.bufferDesc;
+
+ switch (srcBuffer.type)
+ {
+ case InputBufferType::ConstantBuffer:
+ slotRangeDesc.type = DescriptorSlotType::UniformBuffer;
+ break;
+
+ case InputBufferType::StorageBuffer:
+ slotRangeDesc.type = DescriptorSlotType::StorageBuffer;
+ break;
+ }
+ }
+ break;
- const size_t bufferSize = srcEntry.bufferData.Count() * sizeof(uint32_t);
+ case ShaderInputType::CombinedTextureSampler:
+ {
+ slotRangeDesc.type = DescriptorSlotType::CombinedImageSampler;
+ }
+ break;
- RefPtr<BufferResource> bufferResource;
- SLANG_RETURN_ON_FAIL(createBufferResource(srcEntry.bufferDesc, srcEntry.isOutput, bufferSize, srcEntry.bufferData.Buffer(), renderer, bufferResource));
+ case ShaderInputType::Texture:
+ {
+ if (srcEntry.textureDesc.isRWTexture)
+ {
+ slotRangeDesc.type = DescriptorSlotType::StorageImage;
+ }
+ else
+ {
+ slotRangeDesc.type = DescriptorSlotType::SampledImage;
+ }
+ }
+ break;
- descOut.addBufferResource(bufferResource, registerSet);
+ case ShaderInputType::Sampler:
+ slotRangeDesc.type = DescriptorSlotType::Sampler;
break;
- }
+
+ default:
+ assert(!"Unhandled type");
+ return SLANG_FAIL;
+ }
+ slotRangeDescs.Add(slotRangeDesc);
+ }
+
+ DescriptorSetLayout::Desc descriptorSetLayoutDesc;
+ descriptorSetLayoutDesc.slotRangeCount = slotRangeDescs.Count();
+ descriptorSetLayoutDesc.slotRanges = slotRangeDescs.Buffer();
+
+ auto descriptorSetLayout = renderer->createDescriptorSetLayout(descriptorSetLayoutDesc);
+ if(!descriptorSetLayout) return SLANG_FAIL;
+
+ List<PipelineLayout::DescriptorSetDesc> pipelineDescriptorSets;
+ pipelineDescriptorSets.Add(PipelineLayout::DescriptorSetDesc(descriptorSetLayout));
+
+ PipelineLayout::Desc pipelineLayoutDesc;
+ pipelineLayoutDesc.renderTargetCount = layout.numRenderTargets;
+ pipelineLayoutDesc.descriptorSetCount = pipelineDescriptorSets.Count();
+ pipelineLayoutDesc.descriptorSets = pipelineDescriptorSets.Buffer();
+
+ auto pipelineLayout = renderer->createPipelineLayout(pipelineLayoutDesc);
+ if(!pipelineLayout) return SLANG_FAIL;
+
+ auto descriptorSet = renderer->createDescriptorSet(descriptorSetLayout);
+ if(!descriptorSet) return SLANG_FAIL;
+
+ List<BindingStateImpl::OutputBinding> outputBindings;
+
+ if(addedConstantBuffer)
+ {
+ descriptorSet->setConstantBuffer(0, 0, addedConstantBuffer);
+ }
+ for (int i = 0; i < numEntries; i++)
+ {
+ const ShaderInputLayoutEntry& srcEntry = srcEntries[i];
+
+ auto rangeIndex = i + (addedConstantBuffer ? 1 : 0);
+
+ switch (srcEntry.type)
+ {
+ case ShaderInputType::Buffer:
+ {
+ const InputBufferDesc& srcBuffer = srcEntry.bufferDesc;
+ const size_t bufferSize = srcEntry.bufferData.Count() * sizeof(uint32_t);
+
+ RefPtr<BufferResource> bufferResource;
+ SLANG_RETURN_ON_FAIL(createBufferResource(srcEntry.bufferDesc, srcEntry.isOutput, bufferSize, srcEntry.bufferData.Buffer(), renderer, bufferResource));
+
+ switch(srcBuffer.type)
+ {
+ case InputBufferType::ConstantBuffer:
+ descriptorSet->setConstantBuffer(rangeIndex, 0, bufferResource);
+ break;
+
+ case InputBufferType::StorageBuffer:
+ {
+ ResourceView::Desc viewDesc;
+ viewDesc.type = ResourceView::Type::UnorderedAccess;
+ viewDesc.format = srcBuffer.format;
+ auto bufferView = renderer->createBufferView(
+ bufferResource,
+ viewDesc);
+ descriptorSet->setResource(rangeIndex, 0, bufferView);
+ }
+ break;
+ }
+
+ if(srcEntry.isOutput)
+ {
+ BindingStateImpl::OutputBinding binding;
+ binding.entryIndex = i;
+ binding.resource = bufferResource;
+ outputBindings.Add(binding);
+ }
+ }
+ break;
+
case ShaderInputType::CombinedTextureSampler:
- {
- RefPtr<TextureResource> texture;
- SLANG_RETURN_ON_FAIL(generateTextureResource(srcEntry.textureDesc, textureBindFlags, renderer, texture));
- descOut.addCombinedTextureSampler(texture, _calcSamplerDesc(srcEntry.samplerDesc), registerSet);
+ {
+ RefPtr<TextureResource> texture;
+ SLANG_RETURN_ON_FAIL(generateTextureResource(srcEntry.textureDesc, textureBindFlags, renderer, texture));
+
+ auto sampler = _createSamplerState(renderer, srcEntry.samplerDesc);
+
+ ResourceView::Desc viewDesc;
+ viewDesc.type = ResourceView::Type::ShaderResource;
+ auto textureView = renderer->createTextureView(
+ texture,
+ viewDesc);
+
+ descriptorSet->setCombinedTextureSampler(rangeIndex, 0, textureView, sampler);
+
+ if(srcEntry.isOutput)
+ {
+ BindingStateImpl::OutputBinding binding;
+ binding.entryIndex = i;
+ binding.resource = texture;
+ outputBindings.Add(binding);
+ }
+ }
break;
- }
- case ShaderInputType::Texture:
- {
- RefPtr<TextureResource> texture;
- SLANG_RETURN_ON_FAIL(generateTextureResource(srcEntry.textureDesc, textureBindFlags, renderer, texture));
- descOut.addTextureResource(texture, registerSet);
+ case ShaderInputType::Texture:
+ {
+ RefPtr<TextureResource> texture;
+ SLANG_RETURN_ON_FAIL(generateTextureResource(srcEntry.textureDesc, textureBindFlags, renderer, texture));
+
+ // TODO: support UAV textures...
+
+ ResourceView::Desc viewDesc;
+ viewDesc.type = ResourceView::Type::ShaderResource;
+ auto textureView = renderer->createTextureView(
+ texture,
+ viewDesc);
+
+ descriptorSet->setResource(rangeIndex, 0, textureView);
+
+ if(srcEntry.isOutput)
+ {
+ BindingStateImpl::OutputBinding binding;
+ binding.entryIndex = i;
+ binding.resource = texture;
+ outputBindings.Add(binding);
+ }
+ }
break;
- }
+
case ShaderInputType::Sampler:
- {
- descOut.addSampler(_calcSamplerDesc(srcEntry.samplerDesc), registerSet);
+ {
+ auto sampler = _createSamplerState(renderer, srcEntry.samplerDesc);
+ descriptorSet->setSampler(rangeIndex, 0, sampler);
+ }
break;
- }
+
default:
- {
assert(!"Unhandled type");
return SLANG_FAIL;
- }
}
}
- return SLANG_OK;
-}
+ BindingStateImpl* bindingState = new BindingStateImpl();
+ bindingState->descriptorSet = descriptorSet;
+ bindingState->pipelineLayout = pipelineLayout;
+ bindingState->outputBindings = outputBindings;
+ bindingState->m_numRenderTargets = layout.numRenderTargets;
-/* static */Result ShaderRendererUtil::createBindingStateDesc(const ShaderInputLayout& layout, Renderer* renderer, BindingState::Desc& descOut)
-{
- SLANG_RETURN_ON_FAIL(createBindingStateDesc(layout.entries.Buffer(), int(layout.entries.Count()), renderer, descOut));
- descOut.m_numRenderTargets = layout.numRenderTargets;
+ *outBindingState = bindingState;
return SLANG_OK;
}
diff --git a/tools/render-test/shader-renderer-util.h b/tools/render-test/shader-renderer-util.h
index 849e68754..bbdea2af6 100644
--- a/tools/render-test/shader-renderer-util.h
+++ b/tools/render-test/shader-renderer-util.h
@@ -6,26 +6,68 @@
namespace renderer_test {
-/// Utility class containing functions that construct items on the renderer using the ShaderInputLayout representation
-struct ShaderRendererUtil
+using namespace Slang;
+
+struct BindingStateImpl : public Slang::RefObject
+{
+ /// A register set consists of one or more contiguous indices.
+ /// To be valid index >= 0 and size >= 1
+ struct RegisterRange
+ {
+ /// True if contains valid contents
+ bool isValid() const { return size > 0; }
+ /// True if valid single value
+ bool isSingle() const { return size == 1; }
+ /// Get as a single index (must be at least one index)
+ int getSingleIndex() const { return (size == 1) ? index : -1; }
+ /// Return the first index
+ int getFirstIndex() const { return (size > 0) ? index : -1; }
+ /// True if contains register index
+ bool hasRegister(int registerIndex) const { return registerIndex >= index && registerIndex < index + size; }
+
+ static RegisterRange makeInvalid() { return RegisterRange{ -1, 0 }; }
+ static RegisterRange makeSingle(int index) { return RegisterRange{ int16_t(index), 1 }; }
+ static RegisterRange makeRange(int index, int size) { return RegisterRange{ int16_t(index), uint16_t(size) }; }
+
+ int16_t index; ///< The base index
+ uint16_t size; ///< The amount of register indices
+ };
+
+ void apply(Renderer* renderer, PipelineType pipelineType);
+
+ struct OutputBinding
+ {
+ RefPtr<Resource> resource;
+ Slang::UInt entryIndex;
+ };
+ List<OutputBinding> outputBindings;
+
+ RefPtr<PipelineLayout> pipelineLayout;
+ RefPtr<DescriptorSet> descriptorSet;
+ int m_numRenderTargets = 1;
+};
+
+/// Utility class containing functions that construct items on the renderer using the ShaderInputLayout representation
+struct ShaderRendererUtil
{
/// Generate a texture using the InputTextureDesc and construct a TextureResource using the Renderer with the contents
static Slang::Result generateTextureResource(const InputTextureDesc& inputDesc, int bindFlags, Renderer* renderer, Slang::RefPtr<TextureResource>& textureOut);
/// Create texture resource using inputDesc, and texData to describe format, and contents
static Slang::Result createTextureResource(const InputTextureDesc& inputDesc, const TextureData& texData, int bindFlags, Renderer* renderer, Slang::RefPtr<TextureResource>& textureOut);
-
+
/// Create the BufferResource using the renderer from the contents of inputDesc
static Slang::Result createBufferResource(const InputBufferDesc& inputDesc, bool isOutput, size_t bufferSize, const void* initData, Renderer* renderer, Slang::RefPtr<BufferResource>& bufferOut);
/// Create BindingState::Desc from the contents of layout
- static Slang::Result createBindingStateDesc(const ShaderInputLayout& layout, Renderer* renderer, BindingState::Desc& descOut);
- /// Create BindingState::Desc from a list of ShaderInputLayout entries
- static Slang::Result createBindingStateDesc(ShaderInputLayoutEntry* srcEntries, int numEntries, Renderer* renderer, BindingState::Desc& descOut);
+ static Slang::Result createBindingState(const ShaderInputLayout& layout, Renderer* renderer, BufferResource* addedConstantBuffer, BindingStateImpl** outBindingState);
/// Get the binding register associated with this binding (or -1 if none defined)
- static BindingState::RegisterRange calcRegisterRange(Renderer* renderer, const ShaderInputLayoutEntry& entry);
+ static BindingStateImpl::RegisterRange calcRegisterRange(Renderer* renderer, const ShaderInputLayoutEntry& entry);
+private:
+ /// Create BindingState::Desc from a list of ShaderInputLayout entries
+ static Slang::Result _createBindingState(ShaderInputLayoutEntry* srcEntries, int numEntries, Renderer* renderer, BufferResource* addedConstantBuffer, BindingStateImpl** outBindingState);
};
} // renderer_test
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index a6c252843..26e856295 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -11,7 +11,7 @@
namespace renderer_test {
-ShaderProgram* ShaderCompiler::compileProgram(
+RefPtr<ShaderProgram> ShaderCompiler::compileProgram(
ShaderCompileRequest const& request)
{
SlangSession* slangSession = spCreateSession(NULL);
@@ -92,7 +92,7 @@ ShaderProgram* ShaderCompiler::compileProgram(
}
- ShaderProgram * shaderProgram = nullptr;
+ RefPtr<ShaderProgram> shaderProgram;
Slang::List<const char*> rawTypeNames;
for (auto typeName : request.entryPointTypeArguments)
rawTypeNames.Add(typeName.Buffer());
diff --git a/tools/render-test/slang-support.h b/tools/render-test/slang-support.h
index 8697abcb8..03de062d1 100644
--- a/tools/render-test/slang-support.h
+++ b/tools/render-test/slang-support.h
@@ -11,13 +11,13 @@ namespace renderer_test {
struct ShaderCompiler
{
- Renderer* renderer;
+ RefPtr<Renderer> renderer;
SlangCompileTarget target;
SlangSourceLanguage sourceLanguage;
SlangPassThrough passThrough;
char const* profile;
- ShaderProgram* compileProgram(
+ RefPtr<ShaderProgram> compileProgram(
ShaderCompileRequest const& request);
};