glslang/gtests/Hlsl.FromFile.cpp

515 lines
22 KiB
C++
Raw Normal View History

//
// Copyright (C) 2016 Google, Inc.
// Copyright (C) 2016 LunarG, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include <gtest/gtest.h>
#include "TestFixture.h"
namespace glslangtest {
namespace {
struct FileNameEntryPointPair {
const char* fileName;
const char* entryPoint;
};
// We are using FileNameEntryPointPair objects as parameters for instantiating
// the template, so the global FileNameAsCustomTestSuffix() won't work since
// it assumes std::string as parameters. Thus, an overriding one here.
std::string FileNameAsCustomTestSuffix(
const ::testing::TestParamInfo<FileNameEntryPointPair>& info) {
std::string name = info.param.fileName;
// A valid test case suffix cannot have '.' and '-' inside.
std::replace(name.begin(), name.end(), '.', '_');
std::replace(name.begin(), name.end(), '-', '_');
return name;
}
using HlslCompileTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
using HlslVulkan1_1CompileTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
using HlslCompileAndFlattenTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
using HlslLegalizeTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
using HlslDebugTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
using HlslDX9CompatibleTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
using HlslLegalDebugTest = GlslangTest<::testing::TestWithParam<FileNameEntryPointPair>>;
// Compiling HLSL to pre-legalized SPIR-V under Vulkan semantics. Expected
// to successfully generate both AST and SPIR-V.
TEST_P(HlslCompileTest, FromFile)
{
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
Target::BothASTAndSpv, true, GetParam().entryPoint);
}
TEST_P(HlslVulkan1_1CompileTest, FromFile)
{
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_1, glslang::EShTargetSpv_1_3,
Target::BothASTAndSpv, true, GetParam().entryPoint);
}
TEST_P(HlslCompileAndFlattenTest, FromFile)
{
loadFileCompileFlattenUniformsAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan,
Target::BothASTAndSpv, GetParam().entryPoint);
}
// Compiling HLSL to legal SPIR-V under Vulkan semantics. Expected to
// successfully generate SPIR-V.
TEST_P(HlslLegalizeTest, FromFile)
{
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
Target::Spv, true, GetParam().entryPoint,
"/baseLegalResults/", true);
}
// Compiling HLSL to pre-legalized SPIR-V. Expected to successfully generate
// SPIR-V with debug instructions, particularly line info.
TEST_P(HlslDebugTest, FromFile)
{
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
Target::Spv, true, GetParam().entryPoint,
"/baseResults/", false, true);
}
TEST_P(HlslDX9CompatibleTest, FromFile)
{
loadFileCompileAndCheckWithOptions(GlobalTestSettings.testRoot, GetParam().fileName, Source::HLSL,
Semantics::Vulkan, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
Target::BothASTAndSpv, true,
GetParam().entryPoint, "/baseResults/",
EShMessages::EShMsgHlslDX9Compatible);
}
// Compiling HLSL to legalized SPIR-V with debug instructions. Expected to
// successfully generate SPIR-V with debug instructions preserved through
// legalization, particularly line info.
TEST_P(HlslLegalDebugTest, FromFile)
{
loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName,
Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0, glslang::EShTargetSpv_1_0,
Target::Spv, true, GetParam().entryPoint,
"/baseResults/", true, true);
}
// clang-format off
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslCompileTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.amend.frag", "f1"},
{"hlsl.aliasOpaque.frag", "main"},
2016-06-19 17:50:34 +00:00
{"hlsl.array.frag", "PixelShaderFunction"},
{"hlsl.array.implicit-size.frag", "PixelShaderFunction"},
{"hlsl.array.multidim.frag", "main"},
{"hlsl.assoc.frag", "PixelShaderFunction"},
{"hlsl.attribute.frag", "PixelShaderFunction"},
{"hlsl.attribute.expression.comp", "main"},
{"hlsl.attributeC11.frag", "main"},
{"hlsl.attributeGlobalBuffer.frag", "main"},
{"hlsl.basic.comp", "main"},
{"hlsl.basic.geom", "main"},
{"hlsl.boolConv.vert", "main"},
{"hlsl.buffer.frag", "PixelShaderFunction"},
{"hlsl.calculatelod.dx10.frag", "main"},
{"hlsl.calculatelodunclamped.dx10.frag", "main"},
{"hlsl.cast.frag", "PixelShaderFunction"},
{"hlsl.cbuffer-identifier.vert", "main"},
{"hlsl.charLit.vert", "main"},
{"hlsl.clip.frag", "main"},
{"hlsl.clipdistance-1.frag", "main"},
{"hlsl.clipdistance-1.geom", "main"},
{"hlsl.clipdistance-1.vert", "main"},
{"hlsl.clipdistance-2.frag", "main"},
{"hlsl.clipdistance-2.geom", "main"},
{"hlsl.clipdistance-2.vert", "main"},
{"hlsl.clipdistance-3.frag", "main"},
{"hlsl.clipdistance-3.geom", "main"},
{"hlsl.clipdistance-3.vert", "main"},
{"hlsl.clipdistance-4.frag", "main"},
{"hlsl.clipdistance-4.geom", "main"},
{"hlsl.clipdistance-4.vert", "main"},
{"hlsl.clipdistance-5.frag", "main"},
{"hlsl.clipdistance-5.vert", "main"},
{"hlsl.clipdistance-6.frag", "main"},
{"hlsl.clipdistance-6.vert", "main"},
{"hlsl.clipdistance-7.frag", "main"},
{"hlsl.clipdistance-7.vert", "main"},
{"hlsl.clipdistance-8.frag", "main"},
{"hlsl.clipdistance-8.vert", "main"},
{"hlsl.clipdistance-9.frag", "main"},
{"hlsl.clipdistance-9.vert", "main"},
{"hlsl.color.hull.tesc", "main"},
2016-10-21 22:43:38 +00:00
{"hlsl.comparison.vec.frag", "main"},
{"hlsl.conditional.frag", "PixelShaderFunction"},
{"hlsl.constantbuffer.frag", "main"},
{"hlsl.constructArray.vert", "main"},
{"hlsl.constructexpr.frag", "main"},
{"hlsl.constructimat.frag", "main"},
{"hlsl.coverage.frag", "main"},
{"hlsl.depthGreater.frag", "PixelShaderFunction"},
{"hlsl.depthLess.frag", "PixelShaderFunction"},
{"hlsl.discard.frag", "PixelShaderFunction"},
{"hlsl.doLoop.frag", "PixelShaderFunction"},
{"hlsl.earlydepthstencil.frag", "main"},
{"hlsl.emptystructreturn.frag", "main"},
{"hlsl.emptystructreturn.vert", "main"},
{"hlsl.emptystruct.init.vert", "main"},
{"hlsl.entry-in.frag", "PixelShaderFunction"},
{"hlsl.entry-out.frag", "PixelShaderFunction"},
{"hlsl.fraggeom.frag", "main"},
{"hlsl.float1.frag", "PixelShaderFunction"},
{"hlsl.float4.frag", "PixelShaderFunction"},
{"hlsl.flatten.return.frag", "main"},
{"hlsl.flattenOpaque.frag", "main"},
{"hlsl.flattenOpaqueInit.vert", "main"},
{"hlsl.flattenOpaqueInitMix.vert", "main"},
{"hlsl.flattenSubset.frag", "main"},
{"hlsl.flattenSubset2.frag", "main"},
{"hlsl.forLoop.frag", "PixelShaderFunction"},
{"hlsl.gather.array.dx10.frag", "main"},
{"hlsl.gather.basic.dx10.frag", "main"},
{"hlsl.gather.basic.dx10.vert", "main"},
{"hlsl.gather.offset.dx10.frag", "main"},
{"hlsl.gather.offsetarray.dx10.frag", "main"},
{"hlsl.gathercmpRGBA.offset.dx10.frag", "main"},
{"hlsl.gatherRGBA.array.dx10.frag", "main"},
{"hlsl.gatherRGBA.basic.dx10.frag", "main"},
{"hlsl.gatherRGBA.offset.dx10.frag", "main"},
{"hlsl.gatherRGBA.offsetarray.dx10.frag", "main"},
{"hlsl.getdimensions.dx10.frag", "main"},
{"hlsl.getdimensions.rw.dx10.frag", "main"},
{"hlsl.getdimensions.dx10.vert", "main"},
{"hlsl.getsampleposition.dx10.frag", "main"},
{"hlsl.global-const-init.frag", "main"},
{"hlsl.gs-hs-mix.tesc", "HSMain"},
{"hlsl.domain.1.tese", "main"},
{"hlsl.domain.2.tese", "main"},
{"hlsl.domain.3.tese", "main"},
{"hlsl.function.frag", "main"},
Add basic HS/DS implementation. This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version here uses entry point wrapping. This is a limited implementation of tessellation shaders. In particular, the following are not functional, and will be added as separate stages to reduce the size of each PR. * patchconstantfunctions accepting per-control-point input values, such as const OutputPatch <hs_out_t, 3> cpv are not implemented. * patchconstantfunctions whose signature requires an aggregate input type such as a structure containing builtin variables. Code to synthesize such calls is not yet present. These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors. PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in the PCF but not the EP are also added to the linkage and synthesized as shader inputs. Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user variables in the PCF signature will result in an error. Overloaded PCF functions will also result in an error. [domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()] attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
{"hlsl.hull.1.tesc", "main"},
{"hlsl.hull.2.tesc", "main"},
2017-06-26 23:52:22 +00:00
{"hlsl.hull.3.tesc", "main"},
{"hlsl.hull.4.tesc", "main"},
{"hlsl.hull.5.tesc", "main"},
{"hlsl.hull.6.tesc", "main"},
Add basic HS/DS implementation. This obsoletes WIP PR #704, which was built on the pre entry point wrapping master. New version here uses entry point wrapping. This is a limited implementation of tessellation shaders. In particular, the following are not functional, and will be added as separate stages to reduce the size of each PR. * patchconstantfunctions accepting per-control-point input values, such as const OutputPatch <hs_out_t, 3> cpv are not implemented. * patchconstantfunctions whose signature requires an aggregate input type such as a structure containing builtin variables. Code to synthesize such calls is not yet present. These restrictions will be relaxed as soon as possible. Simple cases can compile now: see for example Test/hulsl.hull.1.tesc - e.g, writing to inner and outer tessellation factors. PCF invocation is synthesized as an entry point epilogue protected behind a barrier and a test on invocation ID == 0. If there is an existing invocation ID variable it will be used, otherwise one is added to the linkage. The PCF and the shader EP interfaces are unioned and builtins appearing in the PCF but not the EP are also added to the linkage and synthesized as shader inputs. Parameter matching to (eventually arbitrary) PCF signatures is by builtin variable type. Any user variables in the PCF signature will result in an error. Overloaded PCF functions will also result in an error. [domain()], [partitioning()], [outputtopology()], [outputcontrolpoints()], and [patchconstantfunction()] attributes to the shader entry point are in place, with the exception of the Pow2 partitioning mode.
2017-01-07 15:54:10 +00:00
{"hlsl.hull.void.tesc", "main"},
{"hlsl.hull.ctrlpt-1.tesc", "main"},
{"hlsl.hull.ctrlpt-2.tesc", "main"},
{"hlsl.format.rwtexture.frag", "main"},
{"hlsl.groupid.comp", "main"},
{"hlsl.identifier.sample.frag", "main"},
{"hlsl.if.frag", "PixelShaderFunction"},
{"hlsl.imageload-subvec4.comp", "main"},
{"hlsl.imagefetch-subvec4.comp", "main"},
{"hlsl.implicitBool.frag", "main"},
{"hlsl.inf.vert", "main"},
2016-07-13 02:44:32 +00:00
{"hlsl.inoutquals.frag", "main"},
{"hlsl.inoutquals.negative.frag", "main"},
{"hlsl.init.frag", "ShaderFunction"},
{"hlsl.init2.frag", "main"},
{"hlsl.isfinite.frag", "main"},
{"hlsl.intrinsics.barriers.comp", "ComputeShaderFunction"},
{"hlsl.intrinsics.comp", "ComputeShaderFunction"},
2017-01-03 21:42:18 +00:00
{"hlsl.intrinsics.d3dcolortoubyte4.frag", "main"},
{"hlsl.intrinsics.double.frag", "PixelShaderFunction"},
{"hlsl.intrinsics.f1632.frag", "main"},
{"hlsl.intrinsics.f3216.frag", "main"},
{"hlsl.intrinsics.frag", "main"},
{"hlsl.intrinsic.frexp.frag", "main"},
{"hlsl.intrinsics.lit.frag", "PixelShaderFunction"},
{"hlsl.intrinsics.negative.comp", "ComputeShaderFunction"},
2016-06-03 16:53:28 +00:00
{"hlsl.intrinsics.negative.frag", "PixelShaderFunction"},
{"hlsl.intrinsics.negative.vert", "VertexShaderFunction"},
HLSL: add intrinsic function implicit promotions This PR handles implicit promotions for intrinsics when there is no exact match, such as for example clamp(int, bool, float). In this case the int and bool will be promoted to a float, and the clamp(float, float, float) form used. These promotions can be mixed with shape conversions, e.g, clamp(int, bool2, float2). Output conversions are handled either via the existing addOutputArgumentConversion function, which this PR generalizes to handle either aggregates or unaries, or by intrinsic decomposition. If there are methods or intrinsics to be decomposed, then decomposition is responsible for any output conversions, which turns out to happen automatically in all current cases. This can be revisited once inout conversions are in place. Some cases of actual ambiguity were fixed in several tests, e.g, spv.register.autoassign.* Some intrinsics with only uint versions were expanded to signed ints natively, where the underlying AST and SPIR-V supports that. E.g, countbits. This avoids extraneous conversion nodes. A new function promoteAggregate is added, and used by findFunction. This is essentially a generalization of the "promote 1st or 2nd arg" algorithm in promoteBinary. The actual selection proceeds in three steps, as described in the comments in hlslParseContext::findFunction: 1. Attempt an exact match. If found, use it. 2. If not, obtain the operator from step 1, and promote arguments. 3. Re-select the intrinsic overload from the results of step 2.
2016-11-02 18:42:34 +00:00
{"hlsl.intrinsics.promote.frag", "main"},
{"hlsl.intrinsics.promote.down.frag", "main"},
{"hlsl.intrinsics.promote.outputs.frag", "main"},
{"hlsl.layout.frag", "main"},
{"hlsl.layoutOverride.vert", "main"},
{"hlsl.load.2dms.dx10.frag", "main"},
{"hlsl.load.array.dx10.frag", "main"},
{"hlsl.load.basic.dx10.frag", "main"},
{"hlsl.load.basic.dx10.vert", "main"},
{"hlsl.load.buffer.dx10.frag", "main"},
{"hlsl.load.buffer.float.dx10.frag", "main"},
{"hlsl.load.rwbuffer.dx10.frag", "main"},
{"hlsl.load.rwtexture.dx10.frag", "main"},
{"hlsl.load.rwtexture.array.dx10.frag", "main"},
{"hlsl.load.offset.dx10.frag", "main"},
{"hlsl.load.offsetarray.dx10.frag", "main"},
{"hlsl.localStructuredBuffer.comp", "main"},
{"hlsl.logical.binary.frag", "main"},
{"hlsl.logical.binary.vec.frag", "main"},
{"hlsl.logicalConvert.frag", "main"},
{"hlsl.logical.unary.frag", "main"},
{"hlsl.loopattr.frag", "main"},
{"hlsl.matpack-pragma.frag", "main"},
2020-06-25 03:27:28 +00:00
{"hlsl.matpack-pragma-global.frag", "main"},
{"hlsl.mip.operator.frag", "main"},
{"hlsl.mip.negative.frag", "main"},
{"hlsl.mip.negative2.frag", "main"},
{"hlsl.namespace.frag", "main"},
{"hlsl.nonint-index.frag", "main"},
{"hlsl.matNx1.frag", "main"},
{"hlsl.matpack-1.frag", "main"},
{"hlsl.matrixSwizzle.vert", "ShaderFunction"},
{"hlsl.memberFunCall.frag", "main"},
{"hlsl.mintypes.frag", "main"},
{"hlsl.mul-truncate.frag", "main"},
{"hlsl.multiEntry.vert", "RealEntrypoint"},
{"hlsl.multiReturn.frag", "main"},
{"hlsl.matrixindex.frag", "main"},
{"hlsl.nonstaticMemberFunction.frag", "main"},
{"hlsl.numericsuffixes.frag", "main"},
{"hlsl.numthreads.comp", "main_aux2"},
{"hlsl.overload.frag", "PixelShaderFunction"},
{"hlsl.opaque-type-bug.frag", "main"},
{"hlsl.params.default.frag", "main"},
{"hlsl.params.default.negative.frag", "main"},
{"hlsl.partialInit.frag", "PixelShaderFunction"},
{"hlsl.partialFlattenLocal.vert", "main"},
{"hlsl.PointSize.geom", "main"},
{"hlsl.PointSize.vert", "main"},
{"hlsl.pp.vert", "main"},
{"hlsl.pp.line.frag", "main"},
2016-08-25 05:49:36 +00:00
{"hlsl.precise.frag", "main"},
{"hlsl.printf.comp", "main"},
{"hlsl.promote.atomic.frag", "main"},
{"hlsl.promote.binary.frag", "main"},
{"hlsl.promote.vec1.frag", "main"},
{"hlsl.promotions.frag", "main"},
{"hlsl.round.dx10.frag", "main"},
{"hlsl.rw.atomics.frag", "main"},
{"hlsl.rw.bracket.frag", "main"},
{"hlsl.rw.register.frag", "main"},
{"hlsl.rw.scalar.bracket.frag", "main"},
{"hlsl.rw.swizzle.frag", "main"},
{"hlsl.rw.vec2.bracket.frag", "main"},
{"hlsl.sample.array.dx10.frag", "main"},
{"hlsl.sample.basic.dx10.frag", "main"},
{"hlsl.sample.offset.dx10.frag", "main"},
{"hlsl.sample.offsetarray.dx10.frag", "main"},
{"hlsl.samplebias.array.dx10.frag", "main"},
{"hlsl.samplebias.basic.dx10.frag", "main"},
{"hlsl.samplebias.offset.dx10.frag", "main"},
{"hlsl.samplebias.offsetarray.dx10.frag", "main"},
{"hlsl.samplecmp.array.dx10.frag", "main"},
{"hlsl.samplecmp.basic.dx10.frag", "main"},
{"hlsl.samplecmp.dualmode.frag", "main"},
{"hlsl.samplecmp.offset.dx10.frag", "main"},
{"hlsl.samplecmp.offsetarray.dx10.frag", "main"},
{"hlsl.samplecmp.negative.frag", "main"},
{"hlsl.samplecmp.negative2.frag", "main"},
{"hlsl.samplecmplevelzero.array.dx10.frag", "main"},
{"hlsl.samplecmplevelzero.basic.dx10.frag", "main"},
{"hlsl.samplecmplevelzero.offset.dx10.frag", "main"},
{"hlsl.samplecmplevelzero.offsetarray.dx10.frag", "main"},
{"hlsl.samplegrad.array.dx10.frag", "main"},
{"hlsl.samplegrad.basic.dx10.frag", "main"},
{"hlsl.samplegrad.basic.dx10.vert", "main"},
{"hlsl.samplegrad.offset.dx10.frag", "main"},
{"hlsl.samplegrad.offsetarray.dx10.frag", "main"},
2016-07-21 21:02:16 +00:00
{"hlsl.samplelevel.array.dx10.frag", "main"},
{"hlsl.samplelevel.basic.dx10.frag", "main"},
{"hlsl.samplelevel.basic.dx10.vert", "main"},
{"hlsl.samplelevel.offset.dx10.frag", "main"},
{"hlsl.samplelevel.offsetarray.dx10.frag", "main"},
{"hlsl.sample.sub-vec4.dx10.frag", "main"},
2017-03-24 16:12:53 +00:00
{"hlsl.scalar-length.frag", "main"},
{"hlsl.scalarCast.vert", "main"},
{"hlsl.semicolons.frag", "main"},
{"hlsl.shapeConv.frag", "main"},
{"hlsl.shapeConvRet.frag", "main"},
{"hlsl.singleArgIntPromo.vert", "main"},
{"hlsl.self_cast.frag", "main"},
{"hlsl.snorm.uav.comp", "main"},
{"hlsl.specConstant.frag", "main"},
{"hlsl.staticMemberFunction.frag", "main"},
{"hlsl.staticFuncInit.frag", "main"},
{"hlsl.store.rwbyteaddressbuffer.type.comp", "main"},
{"hlsl.stringtoken.frag", "main"},
{"hlsl.string.frag", "main"},
HLSL: inter-stage structure splitting. This adds structure splitting, which among other things will enable GS support where input structs are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case. The salient points of this PR are: * Structure splitting has been changed from "always between stages" to "only into the VS and out of the PS". It had previously happened between stages because it's not legal to pass a struct containing a builtin IO variable. * Structs passed between stages are now split into a struct containing ONLY user types, and a collection of loose builtin IO variables, if any. The user-part is passed as a normal struct between stages, which is valid SPIR-V now that the builtin IO is removed. * Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g, functions can work unmodified. * If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS, the array reference is moved to the split-off loose variable, which is given the array dimension itself. When passing things around inside the shader, such as over a function call, the the original type is used in a sanitized form that removes the builtIn qualifications and makes them temporaries. This means internal function calls do not have to change. However, the type when returned from the shader will be member-wise copied from the internal sanitized one to the external type. The sanitized type is used in variable declarations. When copying split types and unsplit, if a sub-struct contains only user variables, it is copied as a single entity to avoid more AST verbosity. Above strategy arrived at with talks with @johnkslang. This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to real world cases.
2016-12-14 22:22:25 +00:00
{"hlsl.struct.split-1.vert", "main"},
{"hlsl.struct.split.array.geom", "main"},
{"hlsl.struct.split.assign.frag", "main"},
HLSL: inter-stage structure splitting. This adds structure splitting, which among other things will enable GS support where input structs are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case. The salient points of this PR are: * Structure splitting has been changed from "always between stages" to "only into the VS and out of the PS". It had previously happened between stages because it's not legal to pass a struct containing a builtin IO variable. * Structs passed between stages are now split into a struct containing ONLY user types, and a collection of loose builtin IO variables, if any. The user-part is passed as a normal struct between stages, which is valid SPIR-V now that the builtin IO is removed. * Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g, functions can work unmodified. * If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS, the array reference is moved to the split-off loose variable, which is given the array dimension itself. When passing things around inside the shader, such as over a function call, the the original type is used in a sanitized form that removes the builtIn qualifications and makes them temporaries. This means internal function calls do not have to change. However, the type when returned from the shader will be member-wise copied from the internal sanitized one to the external type. The sanitized type is used in variable declarations. When copying split types and unsplit, if a sub-struct contains only user variables, it is copied as a single entity to avoid more AST verbosity. Above strategy arrived at with talks with @johnkslang. This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to real world cases.
2016-12-14 22:22:25 +00:00
{"hlsl.struct.split.call.vert", "main"},
{"hlsl.struct.split.nested.geom", "main"},
{"hlsl.struct.split.trivial.geom", "main"},
HLSL: inter-stage structure splitting. This adds structure splitting, which among other things will enable GS support where input structs are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case. The salient points of this PR are: * Structure splitting has been changed from "always between stages" to "only into the VS and out of the PS". It had previously happened between stages because it's not legal to pass a struct containing a builtin IO variable. * Structs passed between stages are now split into a struct containing ONLY user types, and a collection of loose builtin IO variables, if any. The user-part is passed as a normal struct between stages, which is valid SPIR-V now that the builtin IO is removed. * Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g, functions can work unmodified. * If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS, the array reference is moved to the split-off loose variable, which is given the array dimension itself. When passing things around inside the shader, such as over a function call, the the original type is used in a sanitized form that removes the builtIn qualifications and makes them temporaries. This means internal function calls do not have to change. However, the type when returned from the shader will be member-wise copied from the internal sanitized one to the external type. The sanitized type is used in variable declarations. When copying split types and unsplit, if a sub-struct contains only user variables, it is copied as a single entity to avoid more AST verbosity. Above strategy arrived at with talks with @johnkslang. This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to real world cases.
2016-12-14 22:22:25 +00:00
{"hlsl.struct.split.trivial.vert", "main"},
HLSL: Recursive composite flattening This PR implements recursive type flattening. For example, an array of structs of other structs can be flattened to individual member variables at the shader interface. This is sufficient for many purposes, e.g, uniforms containing opaque types, but is not sufficient for geometry shader arrayed inputs. That will be handled separately with structure splitting, which is not implemented by this PR. In the meantime, that case is detected and triggers an error. The recursive flattening extends the following three aspects of single-level flattening: - Flattening of structures to individual members with names such as "foo[0].samp[1]"; - Turning constant references to the nested composite type into a reference to a particular flattened member. - Shadow copies between arrays of flattened members and the nested composite type. Previous single-level flattening only flattened at the shader interface, and that is unchanged by this PR. Internally, shadow copies are, such as if the type is passed to a function. Also, the reasons for flattening are unchanged. Uniforms containing opaque types, and interface struct types are flattened. (The latter will change with structure splitting). One existing test changes: hlsl.structin.vert, which did in fact contain a nested composite type to be flattened. Two new tests are added: hlsl.structarray.flatten.frag, and hlsl.structarray.flatten.geom (currently issues an error until type splitting is online). The process of arriving at the individual member from chained postfix expressions is more complex than it was with one level. See large-ish comment above HlslParseContext::flatten() for details.
2016-11-29 00:09:54 +00:00
{"hlsl.structarray.flatten.frag", "main"},
{"hlsl.structarray.flatten.geom", "main"},
{"hlsl.structbuffer.frag", "main"},
{"hlsl.structbuffer.append.frag", "main"},
{"hlsl.structbuffer.append.fn.frag", "main"},
{"hlsl.structbuffer.atomics.frag", "main"},
{"hlsl.structbuffer.byte.frag", "main"},
{"hlsl.structbuffer.coherent.frag", "main"},
{"hlsl.structbuffer.floatidx.comp", "main"},
{"hlsl.structbuffer.incdec.frag", "main"},
{"hlsl.structbuffer.fn.frag", "main"},
{"hlsl.structbuffer.fn2.comp", "main"},
{"hlsl.structbuffer.rw.frag", "main"},
{"hlsl.structbuffer.rwbyte.frag", "main"},
{"hlsl.structin.vert", "main"},
{"hlsl.structIoFourWay.frag", "main"},
{"hlsl.structStructName.frag", "main"},
{"hlsl.subpass.frag", "main"},
{"hlsl.synthesizeInput.frag", "main"},
{"hlsl.texturebuffer.frag", "main"},
HLSL: add methods to track user structure in texture return type. Some languages allow a restricted set of user structure types returned from texture sampling operations. Restrictions include the total vector size of all components may not exceed 4, and the basic types of all members must be identical. This adds underpinnings for that ability. Because storing a whole TType or even a simple TTypeList in the TSampler would be expensive, the structure definition is held in a table outside the TType. The TSampler contains a small bitfield index, currently 4 bits to support up to 15 separate texture template structure types, but that can be adjusted up or down. Vector returns are handled as before. There are abstraction methods accepting and returning a TType (such as may have been parsed from a grammar). The new methods will accept a texture template type and set the sampler to the structure if possible, checking a range of error conditions such as whether the total structure vector components exceed 4, or whether their basic types differe, or whether the struct contains non-vector-or-scalar members. Another query returns the appropriate TType for the sampler. High level summary of design: In the TSampler, this holds an index into the texture structure return type table: unsigned int structReturnIndex : structReturnIndexBits; These are the methods to set or get the return type from the TSampler. They work for vector or structure returns, and potentially could be expanded to handle other things (small arrays?) if ever needed. bool setTextureReturnType(TSampler& sampler, const TType& retType, const TSourceLoc& loc); void getTextureReturnType(const TSampler& sampler, const TType& retType, const TSourceLoc& loc) const; The ``convertReturn`` lambda in ``HlslParseContext::decomposeSampleMethods`` is greatly expanded to know how to copy a vec4 sample return to whatever the structure type should be. This is a little awkward since it involves introducing a comma expression to return the proper aggregate value after a set of memberwise copies.
2017-07-31 19:41:42 +00:00
{"hlsl.texture.struct.frag", "main"},
{"hlsl.texture.subvec4.frag", "main"},
2017-03-22 17:38:22 +00:00
{"hlsl.this.frag", "main"},
2016-06-03 16:53:28 +00:00
{"hlsl.intrinsics.vert", "VertexShaderFunction"},
{"hlsl.intrinsic.frexp.vert", "VertexShaderFunction"},
{"hlsl.matType.frag", "PixelShaderFunction"},
{"hlsl.matType.bool.frag", "main"},
{"hlsl.matType.int.frag", "main"},
{"hlsl.max.frag", "PixelShaderFunction"},
{"hlsl.preprocessor.frag", "main"},
{"hlsl.precedence.frag", "PixelShaderFunction"},
{"hlsl.precedence2.frag", "PixelShaderFunction"},
{"hlsl.scalar2matrix.frag", "main"},
{"hlsl.semantic.geom", "main"},
{"hlsl.semantic.vert", "main"},
{"hlsl.semantic-1.vert", "main"},
{"hlsl.scope.frag", "PixelShaderFunction"},
{"hlsl.sin.frag", "PixelShaderFunction"},
{"hlsl.struct.frag", "PixelShaderFunction"},
2016-07-01 06:04:11 +00:00
{"hlsl.switch.frag", "PixelShaderFunction"},
{"hlsl.swizzle.frag", "PixelShaderFunction"},
{"hlsl.target.frag", "main"},
{"hlsl.targetStruct1.frag", "main"},
{"hlsl.targetStruct2.frag", "main"},
{"hlsl.templatetypes.frag", "PixelShaderFunction"},
{"hlsl.tristream-append.geom", "main"},
{"hlsl.tx.bracket.frag", "main"},
{"hlsl.tx.overload.frag", "main"},
{"hlsl.type.half.frag", "main"},
{"hlsl.type.identifier.frag", "main"},
{"hlsl.typeGraphCopy.vert", "main"},
{"hlsl.typedef.frag", "PixelShaderFunction"},
{"hlsl.whileLoop.frag", "PixelShaderFunction"},
{"hlsl.void.frag", "PixelShaderFunction"},
{"hlsl.type.type.conversion.all.frag", "main"}
}),
FileNameAsCustomTestSuffix
);
// clang-format on
// clang-format off
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslVulkan1_1CompileTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.wavebroadcast.comp", "CSMain"},
{"hlsl.waveprefix.comp", "CSMain"},
{"hlsl.wavequad.comp", "CSMain"},
{"hlsl.wavequery.comp", "CSMain"},
{"hlsl.wavequery.frag", "PixelShaderFunction"},
{"hlsl.wavereduction.comp", "CSMain"},
{"hlsl.wavevote.comp", "CSMain"},
{ "hlsl.type.type.conversion.valid.frag", "main" },
{"hlsl.int.dot.frag", "main"}
}),
FileNameAsCustomTestSuffix
);
// clang-format on
// clang-format off
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslCompileAndFlattenTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.array.flatten.frag", "main"},
{"hlsl.partialFlattenMixed.vert", "main"},
}),
FileNameAsCustomTestSuffix
);
// clang-format on
#if ENABLE_OPT
// clang-format off
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslLegalizeTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.aliasOpaque.frag", "main"},
{"hlsl.flattenOpaque.frag", "main"},
{"hlsl.flattenOpaqueInit.vert", "main"},
{"hlsl.flattenOpaqueInitMix.vert", "main"},
{"hlsl.flattenSubset.frag", "main"},
{"hlsl.flattenSubset2.frag", "main"},
{"hlsl.intrinsics.evalfns.frag", "main"},
{"hlsl.partialFlattenLocal.vert", "main"},
{"hlsl.partialFlattenMixed.vert", "main"}
}),
FileNameAsCustomTestSuffix
);
// clang-format on
#endif
// clang-format off
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslDebugTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.pp.line2.frag", "MainPs"}
}),
FileNameAsCustomTestSuffix
);
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslDX9CompatibleTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.round.dx9.frag", "main"},
{"hlsl.sample.dx9.frag", "main"},
{"hlsl.sample.dx9.vert", "main"},
}),
FileNameAsCustomTestSuffix
);
// clang-format off
INSTANTIATE_TEST_SUITE_P(
ToSpirv, HlslLegalDebugTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.pp.line4.frag", "MainPs"}
}),
FileNameAsCustomTestSuffix
);
// clang-format on
} // anonymous namespace
} // namespace glslangtest