Skip to content

Commit

Permalink
SPIR-V: Allow generation of OpSource NZSL
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLynix committed Nov 16, 2024
1 parent 3bec332 commit 297169a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
5 changes: 0 additions & 5 deletions src/NZSL/SpirV/SpirvConstantCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,6 @@ namespace nzsl

void SpirvConstantCache::RegisterSource(SpirvSourceLanguage sourceLang, std::uint32_t version, std::uint32_t fileNameId, std::string source)
{
//FIXME: NZSL has been registered to Khronos but tools are not up-to-date (libspirv won't validate a source code using NZSL as a source language)
// Keep unknown for now
if (sourceLang == SpirvSourceLanguage::NZSL)
sourceLang = SpirvSourceLanguage::Unknown;

auto& sourceData = m_internal->debugSources.emplace_back();
sourceData.file = fileNameId;
sourceData.fileSource = std::move(source);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Tests/ComputeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn main(input: Input)
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
OpEntryPoint ExecutionModel(GLCompute) %26 "main" %15
OpExecutionMode %26 ExecutionMode(LocalSize) 32 32 1
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %8 "Data"
OpMemberName %8 0 "tex_size"
OpName %19 "Input"
Expand Down
18 changes: 9 additions & 9 deletions tests/src/Tests/DebugInfoTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void main()
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
OpEntryPoint ExecutionModel(Fragment) %27 "main" %21
OpExecutionMode %27 ExecutionMode(OriginUpperLeft)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %12 "Data"
OpMemberName %12 0 "color"
OpName %22 "Output"
Expand Down Expand Up @@ -411,19 +411,19 @@ void main()
%28 = OpString "../resources/Shader.nzsl"
%29 = OpString "../resources/modules/Color.nzsl"
%30 = OpString "../resources/modules/Data/OutputStruct.nzsl"
OpSource SourceLanguage(Unknown) 100 %28
OpSource SourceLanguage(NZSL) 100 %28
OpSourceExtension "ModuleName: Shader"
OpSourceExtension "Author: SirLynix"
OpSourceExtension "Description: Test module"
OpSourceExtension "License: MIT"
OpSource SourceLanguage(Unknown) 100 %29
OpSource SourceLanguage(NZSL) 100 %29
OpSourceExtension "ModuleName: Color"
OpSourceExtension "Author: SirLynix"
OpSourceExtension "Description: Test color module"
OpSourceExtension "License: MIT"
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpSourceExtension "ModuleName: DataStruct"
OpSource SourceLanguage(Unknown) 100 %30
OpSource SourceLanguage(NZSL) 100 %30
OpSourceExtension "ModuleName: OutputStruct"
OpName %12 "Data"
OpMemberName %12 0 "color"
Expand Down Expand Up @@ -722,7 +722,7 @@ void main()
%28 = OpString "../resources/Shader.nzsl"
%29 = OpString "../resources/modules/Color.nzsl"
%30 = OpString "../resources/modules/Data/OutputStruct.nzsl"
OpSource SourceLanguage(Unknown) 100 %28 "[nzsl_version("1.0")]
OpSource SourceLanguage(NZSL) 100 %28 "[nzsl_version("1.0")]
[author("SirLynix")]
[desc("Test module")]
[license("MIT")]
Expand All @@ -748,7 +748,7 @@ fn main() -> Output
OpSourceExtension "Author: SirLynix"
OpSourceExtension "Description: Test module"
OpSourceExtension "License: MIT"
OpSource SourceLanguage(Unknown) 100 %29 "[nzsl_version("1.0")]
OpSource SourceLanguage(NZSL) 100 %29 "[nzsl_version("1.0")]
[author("SirLynix")]
[desc("Test color module")]
[license("MIT")]
Expand Down Expand Up @@ -794,9 +794,9 @@ fn GetAnotherColor() -> vec4[f32]
OpSourceExtension "Author: SirLynix"
OpSourceExtension "Description: Test color module"
OpSourceExtension "License: MIT"
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpSourceExtension "ModuleName: DataStruct"
OpSource SourceLanguage(Unknown) 100 %30 "[nzsl_version("1.0")]
OpSource SourceLanguage(NZSL) 100 %30 "[nzsl_version("1.0")]
module OutputStruct;
import * from DataStruct;
Expand Down
12 changes: 6 additions & 6 deletions tests/src/Tests/EntryFunctionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() -> FragOut
OpExecutionMode %11 ExecutionMode(OriginUpperLeft)
OpExecutionMode %11 ExecutionMode(DepthReplacing)
OpExecutionMode %11 ExecutionMode(DepthGreater)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %6 "FragOut"
OpMemberName %6 0 "depth"
OpName %5 "frag_depth"
Expand Down Expand Up @@ -182,7 +182,7 @@ fn main() -> FragOut
OpExecutionMode %11 ExecutionMode(OriginUpperLeft)
OpExecutionMode %11 ExecutionMode(DepthReplacing)
OpExecutionMode %11 ExecutionMode(DepthLess)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %6 "FragOut"
OpMemberName %6 0 "depth"
OpName %5 "frag_depth"
Expand Down Expand Up @@ -288,7 +288,7 @@ fn main() -> FragOut
OpEntryPoint ExecutionModel(Fragment) %11 "main" %5
OpExecutionMode %11 ExecutionMode(OriginUpperLeft)
OpExecutionMode %11 ExecutionMode(DepthReplacing)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %6 "FragOut"
OpMemberName %6 0 "depth"
OpName %5 "frag_depth"
Expand Down Expand Up @@ -398,7 +398,7 @@ fn main(input: FragIn) -> FragOut
OpExecutionMode %17 ExecutionMode(OriginUpperLeft)
OpExecutionMode %17 ExecutionMode(DepthReplacing)
OpExecutionMode %17 ExecutionMode(DepthUnchanged)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %10 "FragIn"
OpMemberName %10 0 "fragCoord"
OpName %14 "FragOut"
Expand Down Expand Up @@ -577,7 +577,7 @@ fn main()
OpEntryPoint ExecutionModel(Fragment) %3 "main"
OpExecutionMode %3 ExecutionMode(OriginUpperLeft)
OpExecutionMode %3 ExecutionMode(EarlyFragmentTests)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %3 "main"
%1 = OpTypeVoid
%2 = OpTypeFunction %1
Expand Down Expand Up @@ -631,7 +631,7 @@ fn main()
ExpectSPIRV(*shaderModule, R"(
OpEntryPoint ExecutionModel(Fragment) %3 "main"
OpExecutionMode %3 ExecutionMode(OriginUpperLeft)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %3 "main"
%1 = OpTypeVoid
%2 = OpTypeFunction %1
Expand Down
12 changes: 6 additions & 6 deletions tests/src/Tests/ExternalTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn main()
})");

ExpectSPIRV(*shaderModule, R"(
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %9 "Data"
OpMemberName %9 0 "values"
OpMemberName %9 1 "matrices"
Expand Down Expand Up @@ -351,7 +351,7 @@ fn main()
{
nzsl::SpirvWriter::Environment spirvEnv;
ExpectSPIRV(*shaderModule, R"(
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %5 "Data"
OpMemberName %5 0 "values"
OpName %7 "data"
Expand Down Expand Up @@ -393,7 +393,7 @@ fn main()
spirvEnv.spvMinorVersion = 3;

ExpectSPIRV(*shaderModule, R"(
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %5 "Data"
OpMemberName %5 0 "values"
OpName %7 "data"
Expand Down Expand Up @@ -501,7 +501,7 @@ fn main()
nzsl::SpirvWriter::Environment spirvEnv;

ExpectSPIRV(*shaderModule, R"(
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %4 "Data"
OpMemberName %4 0 "data"
OpMemberName %4 1 "values"
Expand Down Expand Up @@ -548,7 +548,7 @@ fn main()
spirvEnv.spvMinorVersion = 3;

ExpectSPIRV(*shaderModule, R"(
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %4 "Data"
OpMemberName %4 0 "data"
OpMemberName %4 1 "values"
Expand Down Expand Up @@ -923,7 +923,7 @@ fn main()
})");

ExpectSPIRV(*shaderModule, R"(
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %2 "Data"
OpMemberName %2 0 "index"
OpName %4 "data"
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Tests/InputOutputTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn main(input: VertIn) -> VertOut
OpEntryPoint ExecutionModel(Fragment) %37 "main" %11 %15 %18 %23
OpEntryPoint ExecutionModel(Vertex) %38 "main" %27 %28 %29 %33 %35 %36
OpExecutionMode %37 ExecutionMode(OriginUpperLeft)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %4 "ColorData"
OpMemberName %4 0 "colors"
OpName %20 "VertOut"
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Tests/IntrinsicTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ fn main()
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
OpEntryPoint ExecutionModel(Fragment) %59 "main"
OpExecutionMode %59 ExecutionMode(OriginUpperLeft)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %5 "tex1D"
OpName %9 "tex1DArray"
OpName %13 "tex2D"
Expand Down Expand Up @@ -1149,7 +1149,7 @@ fn main()
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
OpEntryPoint ExecutionModel(Fragment) %44 "main"
OpExecutionMode %44 ExecutionMode(OriginUpperLeft)
OpSource SourceLanguage(Unknown) 100
OpSource SourceLanguage(NZSL) 100
OpName %44 "main"
%1 = OpTypeVoid
%2 = OpTypeFunction %1
Expand Down

0 comments on commit 297169a

Please sign in to comment.