diff options
Diffstat (limited to 'tools/render-test/shader-input-layout.cpp')
| -rw-r--r-- | tools/render-test/shader-input-layout.cpp | 357 |
1 files changed, 183 insertions, 174 deletions
diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp index ef78fe3d5..01328eabd 100644 --- a/tools/render-test/shader-input-layout.cpp +++ b/tools/render-test/shader-input-layout.cpp @@ -7,6 +7,7 @@ namespace renderer_test void ShaderInputLayout::Parse(const char * source) { entries.Clear(); + globalTypeArguments.Clear(); auto lines = Split(source, '\n'); for (auto & line : lines) { @@ -16,200 +17,208 @@ namespace renderer_test TokenReader parser(lineContent); try { - ShaderInputLayoutEntry entry; - - if (parser.LookAhead("cbuffer")) - { - entry.type = ShaderInputType::Buffer; - entry.bufferDesc.type = InputBufferType::ConstantBuffer; - } - else if (parser.LookAhead("ubuffer")) - { - entry.type = ShaderInputType::Buffer; - entry.bufferDesc.type = InputBufferType::StorageBuffer; - } - else if (parser.LookAhead("Texture1D")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 1; - } - else if (parser.LookAhead("Texture2D")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 2; - } - else if (parser.LookAhead("Texture3D")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 3; - } - else if (parser.LookAhead("TextureCube")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 2; - entry.textureDesc.isCube = true; - } - else if (parser.LookAhead("RWTexture1D")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 1; - entry.textureDesc.isRWTexture = true; - } - else if (parser.LookAhead("RWTexture2D")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 2; - entry.textureDesc.isRWTexture = true; - } - else if (parser.LookAhead("RWTexture3D")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 3; - entry.textureDesc.isRWTexture = true; - } - else if (parser.LookAhead("RWTextureCube")) - { - entry.type = ShaderInputType::Texture; - entry.textureDesc.dimension = 2; - entry.textureDesc.isCube = true; - entry.textureDesc.isRWTexture = true; - } - else if (parser.LookAhead("Sampler")) - { - entry.type = ShaderInputType::Sampler; - } - else if (parser.LookAhead("Sampler1D")) - { - entry.type = ShaderInputType::CombinedTextureSampler; - entry.textureDesc.dimension = 1; - } - else if (parser.LookAhead("Sampler2D")) - { - entry.type = ShaderInputType::CombinedTextureSampler; - entry.textureDesc.dimension = 2; - } - else if (parser.LookAhead("Sampler3D")) - { - entry.type = ShaderInputType::CombinedTextureSampler; - entry.textureDesc.dimension = 3; - } - else if (parser.LookAhead("SamplerCube")) + if (parser.LookAhead("type")) { - entry.type = ShaderInputType::CombinedTextureSampler; - entry.textureDesc.dimension = 2; - entry.textureDesc.isCube = true; + parser.ReadToken(); + globalTypeArguments.Add(parser.ReadWord()); } - else if (parser.LookAhead("render_targets")) + else { - numRenderTargets = parser.ReadInt(); - continue; - } - parser.ReadToken(); - // parse options - if (parser.LookAhead("(")) - { - parser.Read("("); - while (!parser.IsEnd() && !parser.LookAhead(")")) + ShaderInputLayoutEntry entry; + + if (parser.LookAhead("cbuffer")) { - auto word = parser.ReadWord(); - if (word == "depth") - { - entry.textureDesc.isDepthTexture = true; - } - else if (word == "depthCompare") - { - entry.samplerDesc.isCompareSampler = true; - } - else if (word == "arrayLength") - { - parser.Read("="); - entry.textureDesc.arrayLength = parser.ReadInt(); - } - else if (word == "stride") - { - parser.Read("="); - entry.bufferDesc.stride = parser.ReadInt(); - } - else if (word == "size") - { - parser.Read("="); - entry.textureDesc.size = parser.ReadInt(); - } - else if (word == "data") + entry.type = ShaderInputType::Buffer; + entry.bufferDesc.type = InputBufferType::ConstantBuffer; + } + else if (parser.LookAhead("ubuffer")) + { + entry.type = ShaderInputType::Buffer; + entry.bufferDesc.type = InputBufferType::StorageBuffer; + } + else if (parser.LookAhead("Texture1D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 1; + } + else if (parser.LookAhead("Texture2D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 2; + } + else if (parser.LookAhead("Texture3D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 3; + } + else if (parser.LookAhead("TextureCube")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 2; + entry.textureDesc.isCube = true; + } + else if (parser.LookAhead("RWTexture1D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 1; + entry.textureDesc.isRWTexture = true; + } + else if (parser.LookAhead("RWTexture2D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 2; + entry.textureDesc.isRWTexture = true; + } + else if (parser.LookAhead("RWTexture3D")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 3; + entry.textureDesc.isRWTexture = true; + } + else if (parser.LookAhead("RWTextureCube")) + { + entry.type = ShaderInputType::Texture; + entry.textureDesc.dimension = 2; + entry.textureDesc.isCube = true; + entry.textureDesc.isRWTexture = true; + } + else if (parser.LookAhead("Sampler")) + { + entry.type = ShaderInputType::Sampler; + } + else if (parser.LookAhead("Sampler1D")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 1; + } + else if (parser.LookAhead("Sampler2D")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 2; + } + else if (parser.LookAhead("Sampler3D")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 3; + } + else if (parser.LookAhead("SamplerCube")) + { + entry.type = ShaderInputType::CombinedTextureSampler; + entry.textureDesc.dimension = 2; + entry.textureDesc.isCube = true; + } + else if (parser.LookAhead("render_targets")) + { + numRenderTargets = parser.ReadInt(); + continue; + } + parser.ReadToken(); + // parse options + if (parser.LookAhead("(")) + { + parser.Read("("); + while (!parser.IsEnd() && !parser.LookAhead(")")) { - parser.Read("="); - parser.Read("["); - while (!parser.IsEnd() && !parser.LookAhead("]")) + auto word = parser.ReadWord(); + if (word == "depth") + { + entry.textureDesc.isDepthTexture = true; + } + else if (word == "depthCompare") + { + entry.samplerDesc.isCompareSampler = true; + } + else if (word == "arrayLength") { - if (parser.NextToken().Type == TokenType::IntLiteral) + parser.Read("="); + entry.textureDesc.arrayLength = parser.ReadInt(); + } + else if (word == "stride") + { + parser.Read("="); + entry.bufferDesc.stride = parser.ReadInt(); + } + else if (word == "size") + { + parser.Read("="); + entry.textureDesc.size = parser.ReadInt(); + } + else if (word == "data") + { + parser.Read("="); + parser.Read("["); + while (!parser.IsEnd() && !parser.LookAhead("]")) { - entry.bufferData.Add(parser.ReadUInt()); + if (parser.NextToken().Type == TokenType::IntLiteral) + { + entry.bufferData.Add(parser.ReadUInt()); + } + else + { + auto floatNum = parser.ReadFloat(); + entry.bufferData.Add(*(unsigned int*)&floatNum); + } } + parser.Read("]"); + } + else if (word == "content") + { + parser.Read("="); + auto contentWord = parser.ReadWord(); + if (contentWord == "zero") + entry.textureDesc.content = InputTextureContent::Zero; + else if (contentWord == "one") + entry.textureDesc.content = InputTextureContent::One; + else if (contentWord == "chessboard") + entry.textureDesc.content = InputTextureContent::ChessBoard; else - { - auto floatNum = parser.ReadFloat(); - entry.bufferData.Add(*(unsigned int*)&floatNum); - } + entry.textureDesc.content = InputTextureContent::Gradient; } - parser.Read("]"); - } - else if (word == "content") - { - parser.Read("="); - auto contentWord = parser.ReadWord(); - if (contentWord == "zero") - entry.textureDesc.content = InputTextureContent::Zero; - else if (contentWord == "one") - entry.textureDesc.content = InputTextureContent::One; - else if (contentWord == "chessboard") - entry.textureDesc.content = InputTextureContent::ChessBoard; + if (parser.LookAhead(",")) + parser.Read(","); else - entry.textureDesc.content = InputTextureContent::Gradient; + break; } - if (parser.LookAhead(",")) - parser.Read(","); - else - break; + parser.Read(")"); } - parser.Read(")"); - } - // parse bindings - if (parser.LookAhead(":")) - { - parser.Read(":"); - while (!parser.IsEnd()) + // parse bindings + if (parser.LookAhead(":")) { - if (parser.LookAhead("dxbinding")) - { - parser.ReadToken(); - parser.Read("("); - entry.hlslBinding = parser.ReadInt(); - parser.Read(")"); - } - else if (parser.LookAhead("glbinding")) + parser.Read(":"); + while (!parser.IsEnd()) { - parser.ReadToken(); - parser.Read("("); - while (!parser.IsEnd() && !parser.LookAhead(")")) + if (parser.LookAhead("dxbinding")) { - entry.glslBinding.Add(parser.ReadInt()); - if (parser.LookAhead(",")) - parser.Read(","); - else - break; + parser.ReadToken(); + parser.Read("("); + entry.hlslBinding = parser.ReadInt(); + parser.Read(")"); } - parser.Read(")"); - } - else if (parser.LookAhead("out")) - { - parser.ReadToken(); - entry.isOutput = true; + else if (parser.LookAhead("glbinding")) + { + parser.ReadToken(); + parser.Read("("); + while (!parser.IsEnd() && !parser.LookAhead(")")) + { + entry.glslBinding.Add(parser.ReadInt()); + if (parser.LookAhead(",")) + parser.Read(","); + else + break; + } + parser.Read(")"); + } + else if (parser.LookAhead("out")) + { + parser.ReadToken(); + entry.isOutput = true; + } + if (parser.LookAhead(",")) + parser.Read(","); } - if (parser.LookAhead(",")) - parser.Read(","); } + entries.Add(entry); } - entries.Add(entry); } catch (TextFormatException) { |
