RavEngine
Loading...
Searching...
No Matches
NvFlowTextureVariable.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2014-2022 NVIDIA Corporation. All rights reserved.
26
27#pragma once
28
29#include "NvFlowContext.h"
30
32{
33 NvFlowContextInterface* contextInterface = nullptr;
34 NvFlowTextureTransient* transientTexture = nullptr;
35 NvFlowUint64 transientFrame = ~0llu;
36 NvFlowFormat transientFormat = eNvFlowFormat_unknown;
37 NvFlowTexture* texture = nullptr;
39 NvFlowTextureDesc hintTexDesc = {};
40};
41
42NV_FLOW_INLINE void NvFlowTextureVariable_init(NvFlowContextInterface* contextInterface, NvFlowTextureVariable* ptr)
43{
44 ptr->contextInterface = contextInterface;
45}
46
47NV_FLOW_INLINE void NvFlowTextureVariable_flush(NvFlowContext* context, NvFlowTextureVariable* ptr)
48{
49 // process acquire queue
50 NvFlowUint acquireWriteIdx = 0u;
51 for (NvFlowUint acquireReadIdx = 0u; acquireReadIdx < ptr->acquires.size; acquireReadIdx++)
52 {
53 NvFlowTexture* acquiredTexture = nullptr;
54 if (ptr->contextInterface->getAcquiredTexture(context, ptr->acquires[acquireReadIdx], &acquiredTexture))
55 {
56 if (ptr->texture)
57 {
58 ptr->contextInterface->destroyTexture(context, ptr->texture);
59 ptr->texture = nullptr;
60 }
61 ptr->texture = acquiredTexture;
62 }
63 else
64 {
65 ptr->acquires[acquireWriteIdx++] = ptr->acquires[acquireReadIdx];
66 }
67 }
68 ptr->acquires.size = acquireWriteIdx;
69}
70
71NV_FLOW_INLINE NvFlowTextureTransient* NvFlowTextureVariable_get(NvFlowContext* context, NvFlowTextureVariable* ptr, NvFlowFormat* pFormat)
72{
73 if (ptr->transientFrame == ptr->contextInterface->getCurrentFrame(context))
74 {
75 if (pFormat)
76 {
77 *pFormat = ptr->transientFormat;
78 }
79 return ptr->transientTexture;
80 }
81
82 NvFlowTextureVariable_flush(context, ptr);
83
84 if (ptr->texture)
85 {
86 ptr->transientTexture = ptr->contextInterface->registerTextureAsTransient(context, ptr->texture);
87 ptr->transientFrame = ptr->contextInterface->getCurrentFrame(context);
88 }
89 else
90 {
91 ptr->transientTexture = nullptr;
92 ptr->transientFrame = ~0llu;
93 ptr->transientFormat = eNvFlowFormat_unknown;
94 }
95 if (pFormat)
96 {
97 *pFormat = ptr->transientFormat;
98 }
99 return ptr->transientTexture;
100}
101
102NV_FLOW_INLINE void NvFlowTextureVariable_set(NvFlowContext* context, NvFlowTextureVariable* ptr, NvFlowTextureTransient* transientTexture, NvFlowFormat transientFormat)
103{
104 NvFlowTextureVariable_flush(context, ptr);
105 if (ptr->texture)
106 {
107 ptr->contextInterface->destroyTexture(context, ptr->texture);
108 ptr->texture = nullptr;
109 }
110 ptr->transientTexture = nullptr;
111 ptr->transientFrame = ~0llu;
112 ptr->transientFormat = eNvFlowFormat_unknown;
113 if (transientTexture)
114 {
115 ptr->transientTexture = transientTexture;
116 ptr->transientFrame = ptr->contextInterface->getCurrentFrame(context);
117 ptr->transientFormat = transientFormat;
118 // push acquire
119 ptr->acquires.pushBack(ptr->contextInterface->enqueueAcquireTexture(context, transientTexture));
120 }
121}
122
123NV_FLOW_INLINE void NvFlowTextureVariable_destroy(NvFlowContext* context, NvFlowTextureVariable* ptr)
124{
125 NvFlowTextureVariable_set(context, ptr, nullptr, eNvFlowFormat_unknown);
126}
Definition base.h:1940
Definition NvFlowArray.h:36
Definition NvFlowContext.h:362
Definition NvFlowContext.h:137
Definition NvFlowTextureVariable.h:32