summaryrefslogtreecommitdiffstats
path: root/source/compiler-core
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-08-15 20:28:42 +0800
committerGitHub <noreply@github.com>2023-08-15 20:28:42 +0800
commit00bd481e001e8c0b8008eaff5a38fa37963e6f99 (patch)
treed068f0649167bff80b9cd3aa7d32d790540e9564 /source/compiler-core
parent113a257aafe4403c3ab905098d0560635ca94286 (diff)
SPIR-V WIP (#3064)
* Add type layout for structured buffer * Default to generating spirv directly * vk test for compute simple * Add spirv-dis as a downstream compiler * Emit Array types in SPIR-V * makevector for spirv * Dump whole spirv module on validation failure * register array types todo, use emitTypeInst * Neater formatting for unhandled inst printing * break out emitCompositeConstruct * Correct array type generation * neaten * Allow getElement for vector * Remove unused * Allow predicating target intrinsics on types * Consider functions with intrinsics to have definitions We need to specialize these if they are predicated on types * Correct array type generation * makeArray for spir-v * replace getElement with getElementPtr for spirv * Correct translation of field access for spirv * Push layouts to types for spirv * Spirv intrinsics * operator now makes a pointer * Add structured buffer of struct test * Preserve type layout in spirv structured buffer legalization * neaten * makeVectorFromScalar for SPIRV * placeholder for layouts on param groups * More type safe spirv op construction * Know that constants and types only go in one section * Remove emitTypeInst * Add todo for spirv sampling * Add links to spirv documentation on emit functions * OpTypeImage support for SPIR-V * Add simpler texture test for spirv * s/spirv_direct/spirv/g * Allow several string literals in target_intrinsic * Handle global params without a var layour for SPIR-V For example groupshared vars * uint spirv asm type * Add todo for isDefinition It is currently too broad * Some atomic op spirv intrinsics * Strip ConstantBuffer wrappers for spirv * Add todo for matrix annotations * Do not associate decorations insts with spirv counterparts * Correct entry point parameter generation * Spelling * Assert that fieldAddress is returning a pointer * Add error for existential type layout getting to spir-v emit * Add IRTupleTypeLayout Unused so far * Allow getElementPtr to work with vectors * Correct target name in test * Hide default spirv direct behind a premake option --default-spirv-direct=true * Do not insert space at start of intrinsic def * Correct asm rendering in tests * remove redundant option * Emit directly from direct test * Add source language options for spirv-dis * Add comments to spirv dis * Add dead debug print for before spirv module * Correct asm rendering in tests * s/spirv_direct/spirv/g * Only specialize intrinsic functions with predicates * regenerate vs projects * squash warnings * squash warnings * remove duplication * Silence warnings from msvc * squash warnings * Overload for zero sized array * More msvc warnings * warnings * Add spirv-tools to path for tests * Do not be specific about dxc version for diag test * Normalize line endings from spirv-dis * Correct filecheck matches * Temporarily disable two spirv tests Failing on CI, undebuggable hang :/ * Do not emit storage class more than once for spirv snippet * Do not pass spir-v to spirv-dis by stdin * Do not get spirv-dis output via stream, use file * normalize file endings in spirv-dis output
Diffstat (limited to 'source/compiler-core')
-rw-r--r--source/compiler-core/slang-spirv-dis-compiler.cpp42
1 files changed, 29 insertions, 13 deletions
diff --git a/source/compiler-core/slang-spirv-dis-compiler.cpp b/source/compiler-core/slang-spirv-dis-compiler.cpp
index 04e5c8e4a..0e484c7c5 100644
--- a/source/compiler-core/slang-spirv-dis-compiler.cpp
+++ b/source/compiler-core/slang-spirv-dis-compiler.cpp
@@ -1,8 +1,12 @@
#include "slang-spirv-dis-compiler.h"
#include "../core/slang-common.h"
+#include "../core/slang-string-util.h"
+#include "../core/slang-string.h"
+#include "slang-artifact-desc-util.h"
#include "slang-artifact-representation.h"
#include "slang-artifact-util.h"
+#include "slang-artifact-representation-impl.h"
namespace Slang
{
@@ -39,19 +43,23 @@ SlangResult SLANG_MCALL SPIRVDisDownstreamCompiler::convert(
ISlangBlob* fromBlob;
SLANG_RETURN_ON_FAIL(from->loadBlob(ArtifactKeep::No, &fromBlob));
+ ComPtr<IOSFileArtifactRepresentation> fromFile;
+ SLANG_RETURN_ON_FAIL(from->requireFile(ArtifactKeep::No, fromFile.writeRef()));
+
+ String toFile;
+ File::generateTemporary(UnownedStringSlice("spv-asm"), toFile);
+
// Set up our process
CommandLine commandLine;
commandLine.m_executableLocation.setName("spirv-dis");
+ commandLine.addArg("--comment");
+ commandLine.addArg(fromFile->getPath());
+ commandLine.addArg("-o");
+ commandLine.addArg(toFile);
RefPtr<Process> p;
SLANG_RETURN_ON_FAIL(Process::create(commandLine, 0, p));
- const auto in = p->getStream(StdStreamType::In);
- const auto out = p->getStream(StdStreamType::Out);
const auto err = p->getStream(StdStreamType::ErrorOut);
- // Write the assembly
- SLANG_RETURN_ON_FAIL(in->write(fromBlob->getBufferPointer(), fromBlob->getBufferSize()));
- in->close();
-
// Wait for it to finish
if(!p->waitForTermination(1000))
return SLANG_FAIL;
@@ -61,18 +69,26 @@ SlangResult SLANG_MCALL SPIRVDisDownstreamCompiler::convert(
SLANG_RETURN_ON_FAIL(StreamUtil::readAll(err, 0, errData));
fwrite(errData.getBuffer(), errData.getCount(), 1, stderr);
+ // If spirv-dis failed, we fail
const auto ret = p->getReturnValue();
if(ret != 0)
return SLANG_FAIL;
- // Read the disassembly
- List<Byte> outData;
- SLANG_RETURN_ON_FAIL(StreamUtil::readAll(out, 0, outData));
-
- // Wobble it into an artifact
- ComPtr<ISlangBlob> outBlob = RawBlob::create(outData.getBuffer(), outData.getCount());
+ // Normalize line endings
+ String outContents;
+ SLANG_RETURN_ON_FAIL(File::readAllText(toFile, outContents));
+ StringBuilder outBuilder;
+ StringUtil::appendStandardLines(outContents.getUnownedSlice(), outBuilder);
+ SLANG_RETURN_ON_FAIL(File::writeAllBytes(toFile, outBuilder.getBuffer(), outBuilder.getLength()));
+
+ // Return as a file artifact
+ auto fileRep = OSFileArtifactRepresentation::create(
+ IOSFileArtifactRepresentation::Kind::Owned,
+ toFile.getUnownedSlice(),
+ nullptr
+ );
auto artifact = ArtifactUtil::createArtifact(to);
- artifact->addRepresentationUnknown(outBlob.detach());
+ artifact->addRepresentation(fileRep.detach());
*outArtifact = artifact.detach();
return SLANG_OK;