-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTextureSetMetadata.h
More file actions
152 lines (115 loc) · 5.49 KB
/
TextureSetMetadata.h
File metadata and controls
152 lines (115 loc) · 5.49 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#pragma once
#include "StdTypes.h"
#include "FeatureGridMath.h"
#include <array>
struct NtcDecompressConstants;
namespace ntc
{
class Context;
class TextureMetadata;
class GraphicsResources;
struct MlpDesc;
namespace json
{
struct Document;
struct LatentImage;
struct MLP;
}
struct LatentImageDesc
{
Vector<BufferFootprint> footprintsPerLayer;
int width = 0;
int height = 0;
LatentImageDesc(IAllocator* allocator)
: footprintsPerLayer(allocator)
{ }
};
struct ColorMipDesc
{
int neuralLod = -1;
float positionLod = 0.f;
float positionScale = 0.f;
};
class TextureSetMetadata : virtual public ITextureSetMetadata
{
public:
TextureSetMetadata(IAllocator* allocator, Context const* context, TextureSetDesc const& desc,
LatentShape const& latentShape);
TextureSetDesc const& GetDesc() const override { return m_desc; }
LatentShape const& GetLatentShape() const override { return m_latentShape; }
ITextureMetadata* AddTexture() override;
Status RemoveTexture(ITextureMetadata* texture) override;
void ClearTextureMetadata() override;
int GetTextureCount() const override;
ITextureMetadata* GetTexture(int textureIndex) override;
ITextureMetadata const* GetTexture(int textureIndex) const override;
ColorSpace GetChannelStorageColorSpace(int channel) const override;
LatentTextureDesc GetLatentTextureDesc() const override;
Status GetLatentTextureFootprint(int latentMipLevel, int arrayLayer, LatentTextureFootprint& outFootprint) const override;
Status GetFusedMipLevels(int mipLevel, int* pOutFirstFusedMip, int* pOutLastFusedMip) const override;
int GetNumLatentImages() const override;
Status GetMipLevelsForLatentImage(int latentImageIndex, int* pOutFirstColorMip, int* pOutLastColorMip) const override;
InferenceWeightType GetBestSupportedWeightType() const override;
Status GetInferenceWeights(InferenceWeightType weightType, void const** pOutData, size_t* pOutSize,
size_t* pOutConvertedSize) override;
Status ConvertInferenceWeights(InferenceWeightType weightType, void* commandList,
void* srcBuffer, uint64_t srcOffset, void* dstBuffer, uint64_t dstOffset) override;
bool IsInferenceWeightTypeSupported(InferenceWeightType weightType) const override;
Status ShuffleInferenceOutputs(ShuffleSource mapping[NTC_MAX_CHANNELS]) override;
Status LoadMetadataFromStream(json::Document const& document, uint64_t binaryChunkOffset,
uint64_t binaryChunkSize, LatentShape const& latentShape, IStream* inputStream);
Status LoadWeightsFromStream(json::Document const& document, IStream* inputStream);
void GetWeightOffsets(InferenceWeightType weightType,
int weightOffsets[NTC_MLP_LAYERS],
int biasOffsets[NTC_MLP_LAYERS],
int scaleOffsets[NTC_MLP_LAYERS]) const;
uint64_t GetSourceStreamSize() const { return m_sourceStreamSize; }
uint32_t GetValidChannelMask() const override;
uint32_t GetPackedColorSpaces() const;
void FillColorMipConstants(NtcColorMipConstants& colorMip, int mipLevel, int firstLatentMipInTexture);
void FillDecompressionConstants(
NtcDecompressConstants& output,
MakeDecompressionComputePassParameters const& params,
Rect srcRect,
Point dstOffset);
bool ValidateBufferView(uint32_t view, uint64_t minSize, json::Document const& document);
bool ValidateMLP(json::Document const& document, json::MLP const& mlp);
bool ReadViewFromStream(IStream* stream, json::Document const& document, uint32_t view, void* pData, uint64_t size);
LatentImageDesc const* GetLatentImageDesc(int neuralLod) const;
int ColorMipToNeuralLod(int colorMip) const;
bool ConvertWeightsForCoopVec(Vector<uint8_t> const& src, Vector<uint8_t>& dst,
bool useFP8, size_t& outWeightSize, int outWeightOffsets[4]);
static Status ValidateLatentShape(LatentShape const& latentShape);
static Status ValidateTextureSetDesc(TextureSetDesc const& desc);
static Status DeserializeTextureSetDesc(json::Document const& document,
TextureSetDesc& desc, LatentShape& latentShape);
static Status LoadFileHeadersFromStream(IAllocator* allocator, IStream* inputStream, json::Document& outDocument,
uint64_t& outBinaryChunkOffset, uint64_t& outBinaryChunkSize);
protected:
IAllocator* m_allocator;
Context const* m_context;
TextureSetDesc m_desc{ };
LatentShape m_latentShape = LatentShape::Empty();
Vector<UniquePtr<TextureMetadata>> m_textureInfos;
uint64_t m_binaryChunkOffset = 0;
uint64_t m_binaryChunkSize = 0;
uint64_t m_sourceStreamSize = 0;
Vector<uint8_t> m_rowMajorWeightDataInt8;
Vector<uint8_t> m_rowMajorWeightDataFP8;
std::array<ColorSpace, NTC_MAX_CHANNELS> m_channelColorSpaces;
std::array<ShuffleSource, NTC_MAX_CHANNELS> m_channelShuffleMapping;
Vector<LatentImageDesc> m_latentImages;
std::array<ColorMipDesc, NTC_MAX_MIPS> m_colorMips;
};
}