This repository was archived by the owner on Aug 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathNative.cpp
More file actions
123 lines (107 loc) · 4.68 KB
/
Native.cpp
File metadata and controls
123 lines (107 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* ShaderConductor
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
* to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "Native.h"
#include <ShaderConductor/ShaderConductor.hpp>
#include <cstring>
#include <iostream>
using namespace ShaderConductor;
void Compile(SourceDescription* source, OptionsDescription* optionsDesc, TargetDescription* target, ResultDescription* result)
{
Compiler::SourceDesc sourceDesc;
sourceDesc.entryPoint = source->entryPoint;
sourceDesc.source = source->source;
sourceDesc.stage = source->stage;
sourceDesc.fileName = nullptr;
sourceDesc.defines = nullptr;
sourceDesc.numDefines = 0;
Compiler::Options options;
options.packMatricesInRowMajor = optionsDesc->packMatricesInRowMajor;
options.enable16bitTypes = optionsDesc->enable16bitTypes;
options.enableDebugInfo = optionsDesc->enableDebugInfo;
options.disableOptimizations = optionsDesc->disableOptimizations;
options.optimizationLevel = optionsDesc->optimizationLevel;
options.shaderModel = { static_cast<uint8_t>(optionsDesc->shaderModel.major), static_cast<uint8_t>(optionsDesc->shaderModel.minor) };
options.shiftAllTexturesBindings = optionsDesc->shiftAllTexturesBindings;
options.shiftAllSamplersBindings = optionsDesc->shiftAllSamplersBindings;
options.shiftAllCBuffersBindings = optionsDesc->shiftAllCBuffersBindings;
options.shiftAllUABuffersBindings = optionsDesc->shiftAllUABuffersBindings;
Compiler::TargetDesc targetDesc;
targetDesc.language = target->shadingLanguage;
targetDesc.version = target->version;
try
{
const auto translation = Compiler::Compile(sourceDesc, options, targetDesc);
if (translation.errorWarningMsg != nullptr)
{
result->errorWarningMsg = reinterpret_cast<ShaderConductorBlob*>(translation.errorWarningMsg);
}
if (translation.target != nullptr)
{
result->target = reinterpret_cast<ShaderConductorBlob*>(translation.target);
}
result->hasError = translation.hasError;
result->isText = translation.isText;
}
catch (std::exception& ex)
{
const char* exception = ex.what();
result->errorWarningMsg = CreateShaderConductorBlob(exception, static_cast<uint32_t>(strlen(exception)));
result->hasError = true;
}
}
void Disassemble(DisassembleDescription* source, ResultDescription* result)
{
Compiler::DisassembleDesc disassembleSource;
disassembleSource.language = source->language;
disassembleSource.binary = reinterpret_cast<uint8_t*>(source->binary);
disassembleSource.binarySize = source->binarySize;
const auto disassembleResult = Compiler::Disassemble(disassembleSource);
if (disassembleResult.errorWarningMsg != nullptr)
{
result->errorWarningMsg = reinterpret_cast<ShaderConductorBlob*>(disassembleResult.errorWarningMsg);
}
if (disassembleResult.target != nullptr)
{
result->target = reinterpret_cast<ShaderConductorBlob*>(disassembleResult.target);
}
result->hasError = disassembleResult.hasError;
result->isText = disassembleResult.isText;
}
ShaderConductorBlob* CreateShaderConductorBlob(const void* data, int size)
{
return reinterpret_cast<ShaderConductorBlob*>(ShaderConductor::CreateBlob(data, size));
}
void DestroyShaderConductorBlob(ShaderConductorBlob* blob)
{
DestroyBlob(reinterpret_cast<Blob*>(blob));
}
const void* GetShaderConductorBlobData(ShaderConductorBlob* blob)
{
return reinterpret_cast<Blob*>(blob)->Data();
}
int GetShaderConductorBlobSize(ShaderConductorBlob* blob)
{
return reinterpret_cast<Blob*>(blob)->Size();
}