git.s-ol.nu forks/DiligentCore / 7cc1c47
Fixed Buffer, BufferView, Texture, TextureView interfaces; added C interface tests assiduous 3 years ago
18 changed file(s) with 584 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
231231
232232 struct IBuffer;
233233
234 struct IBufferVtbl
234 struct IBufferMethods
235235 {
236236 void (*CreateView) (struct IBuffer*, const struct BufferViewDesc* ViewDesc, class IBufferView** ppView);
237237 class IBufferView* (*GetDefaultView) (struct IBuffer*, BUFFER_VIEW_TYPE ViewType);
242242
243243 // clang-format on
244244
245 struct IBufferVtbl
246 {
247 struct IObjectMethods Object;
248 struct IDeviceObjectMethods DeviceObject;
249 struct IBufferMethods Buffer;
250 };
251
245252 struct IBuffer
246253 {
247 struct IObjectVtbl* pObjectVtbl;
248 struct IDeviceObjectVtbl* pDeviceObjectVtbl;
249 struct IBufferVtbl* pBufferVtbl;
254 struct IBufferVtbl* pVtbl;
250255 };
251256
252257 // clang-format off
253258
254259 # define IBuffer_GetDesc(This) (const struct BufferDesc*)IDeviceObject_GetDesc(This)
255260
256 # define IBuffer_CreateView(This, ...) (This)->pBufferVtbl->CreateView ((struct IBuffer*)(This), __VA_ARGS__)
257 # define IBuffer_GetDefaultView(This, ...) (This)->pBufferVtbl->GetDefaultView ((struct IBuffer*)(This), __VA_ARGS__)
258 # define IBuffer_GetNativeHandle(This) (This)->pBufferVtbl->GetNativeHandle((struct IBuffer*)(This))
259 # define IBuffer_SetState(This, ...) (This)->pBufferVtbl->SetState ((struct IBuffer*)(This), __VA_ARGS__)
260 # define IBuffer_GetState(This) (This)->pBufferVtbl->GetState ((struct IBuffer*)(This))
261 # define IBuffer_CreateView(This, ...) (This)->pVtbl->Buffer.CreateView ((struct IBuffer*)(This), __VA_ARGS__)
262 # define IBuffer_GetDefaultView(This, ...) (This)->pVtbl->Buffer.GetDefaultView ((struct IBuffer*)(This), __VA_ARGS__)
263 # define IBuffer_GetNativeHandle(This) (This)->pVtbl->Buffer.GetNativeHandle((struct IBuffer*)(This))
264 # define IBuffer_SetState(This, ...) (This)->pVtbl->Buffer.SetState ((struct IBuffer*)(This), __VA_ARGS__)
265 # define IBuffer_GetState(This) (This)->pVtbl->Buffer.GetState ((struct IBuffer*)(This))
261266
262267 // clang-format on
263268
163163 class IBufferView;
164164 class IBuffer;
165165
166 struct IBufferViewVtbl
166 struct IBufferViewMethods
167167 {
168168 class IBuffer* (*GetBuffer)(struct IBufferView*);
169169 };
170170
171 struct IBufferViewVtbl
172 {
173 struct IObjectMethods Object;
174 struct IDeviceObjectMethods DeviceObject;
175 struct IBufferViewMethods BufferView;
176 };
177
171178 struct IBufferView
172179 {
173 struct IObjectVtbl* pObjectVtbl;
174 struct IDeviceObjectVtbl* pDeviceObjectVtbl;
175 struct IBufferViewVtbl* pBufferVtbl;
180 struct IBufferViewVtbl* pVtbl;
176181 };
177182
178183 # define IBufferView_GetDesc(This) (const struct BufferViewDesc*)IDeviceObject_GetDesc(This)
179184
180 # define IBufferView_GetBuffer(This) (This)->pBufferVtbl->GetBuffer((struct IBufferView*)(This))
185 # define IBufferView_GetBuffer(This) (This)->pVtbl->BufferView.GetBuffer((struct IBufferView*)(This))
181186
182187 #endif
183188
221221
222222 /// The type of elements in the index buffer.
223223 /// Allowed values: VT_UINT16 and VT_UINT32.
224 enum VALUE_TYPE IndexType DEFAULT_INITIALIZER(VT_UNDEFINED);
224 VALUE_TYPE IndexType DEFAULT_INITIALIZER(VT_UNDEFINED);
225225
226226 /// Additional flags, see Diligent::DRAW_FLAGS.
227 enum DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
227 DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
228228
229229 /// Number of instances to draw. If more than one instance is specified,
230230 /// instanced draw call will be performed.
283283 struct DrawIndirectAttribs
284284 {
285285 /// Additional flags, see Diligent::DRAW_FLAGS.
286 enum DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
286 DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
287287
288288 /// State transition mode for indirect draw arguments buffer.
289 enum RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
289 RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
290290
291291 /// Offset from the beginning of the buffer to the location of draw command attributes.
292 Uint32 IndirectDrawArgsOffset DEFAULT_INITIALIZER(0);
292 Uint32 IndirectDrawArgsOffset DEFAULT_INITIALIZER(0);
293293
294294
295295 #if DILIGENT_CPP_INTERFACE
322322 {
323323 /// The type of the elements in the index buffer.
324324 /// Allowed values: VT_UINT16 and VT_UINT32. Ignored if DrawAttribs::IsIndexed is False.
325 enum VALUE_TYPE IndexType DEFAULT_INITIALIZER(VT_UNDEFINED);
325 VALUE_TYPE IndexType DEFAULT_INITIALIZER(VT_UNDEFINED);
326326
327327 /// Additional flags, see Diligent::DRAW_FLAGS.
328 enum DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
328 DRAW_FLAGS Flags DEFAULT_INITIALIZER(DRAW_FLAG_NONE);
329329
330330 /// State transition mode for indirect draw arguments buffer.
331 enum RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
331 RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
332332
333333 /// Offset from the beginning of the buffer to the location of draw command attributes.
334334 Uint32 IndirectDrawArgsOffset DEFAULT_INITIALIZER(0);
404404 struct DispatchComputeIndirectAttribs
405405 {
406406 /// State transition mode for indirect dispatch attributes buffer.
407 enum RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
407 RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
408408
409409 /// The offset from the beginning of the buffer to the dispatch command arguments.
410410 Uint32 DispatchArgsByteOffset DEFAULT_INITIALIZER(0);
435435 Uint32 SrcSlice DEFAULT_INITIALIZER(0);
436436
437437 /// Source texture state transition mode, see Diligent::RESOURCE_STATE_TRANSITION_MODE.
438 enum RESOURCE_STATE_TRANSITION_MODE SrcTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
438 RESOURCE_STATE_TRANSITION_MODE SrcTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
439439
440440 /// Mip level of the destination non-multi-sampled texture.
441441 Uint32 DstMipLevel DEFAULT_INITIALIZER(0);
444444 Uint32 DstSlice DEFAULT_INITIALIZER(0);
445445
446446 /// Destination texture state transition mode, see Diligent::RESOURCE_STATE_TRANSITION_MODE.
447 enum RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
447 RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
448448
449449 /// If one or both textures are typeless, specifies the type of the typeless texture.
450450 /// If both texture formats are not typeless, in which case they must be identical, this member must be
451451 /// either TEX_FORMAT_UNKNOWN, or match this format.
452 enum TEXTURE_FORMAT Format DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
452 TEXTURE_FORMAT Format DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
453453 };
454454
455455 /// Defines allowed flags for IDeviceContext::SetVertexBuffers() function.
580580 Uint32 DstZ DEFAULT_INITIALIZER(0);
581581
582582 /// Destination texture state transition mode (see Diligent::RESOURCE_STATE_TRANSITION_MODE).
583 enum RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
583 RESOURCE_STATE_TRANSITION_MODE DstTextureTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
584584
585585
586586 #if DILIGENT_CPP_INTERFACE
7474
7575 // clang-format off
7676
77 struct IDeviceObjectVtbl
77 struct IDeviceObjectMethods
7878 {
7979 const struct DeviceObjectAttribs* (*GetDesc) (struct IDeviceObject*);
8080 Int32 (*GetUniqueID)(struct IDeviceObject*);
8282
8383 // clang-format on
8484
85 struct IDeviceObjectVtbl
86 {
87 struct IObjectMethods Object;
88 struct IDeviceObjectMethods DeviceObject;
89 };
90
8591 struct IDeviceObject
8692 {
87 struct IObjectVtbl* pObjectVtbl;
88 struct IDeviceObjectVtbl* pDeviceObjectVtbl;
93 struct IDeviceObjectVtbl* pVtbl;
8994 };
9095
9196 // clang-format off
9297
93 # define IDeviceObject_GetDesc(This) (This)->pDeviceObjectVtbl->GetDesc ((struct IDeviceObject*)(This))
94 # define IDeviceObject_GetUniqueID(This) (This)->pDeviceObjectVtbl->GetUniqueID((struct IDeviceObject*)(This))
98 # define IDeviceObject_GetDesc(This) (This)->pVtbl->DeviceObject.GetDesc ((struct IDeviceObject*)(This))
99 # define IDeviceObject_GetUniqueID(This) (This)->pVtbl->DeviceObject.GetUniqueID((struct IDeviceObject*)(This))
95100
96101 // clang-format on
97102
7272 struct ShaderResourceVariableDesc
7373 {
7474 /// Shader stages this resources variable applies to. More than one shader stage can be specified.
75 enum SHADER_TYPE ShaderStages DEFAULT_INITIALIZER(SHADER_TYPE_UNKNOWN);
75 SHADER_TYPE ShaderStages DEFAULT_INITIALIZER(SHADER_TYPE_UNKNOWN);
7676
7777 /// Shader variable name
7878 const Char* Name DEFAULT_INITIALIZER(nullptr);
9696 struct StaticSamplerDesc
9797 {
9898 /// Shader stages that this static sampler applies to. More than one shader stage can be specified.
99 enum SHADER_TYPE ShaderStages DEFAULT_INITIALIZER(SHADER_TYPE_UNKNOWN);
99 SHADER_TYPE ShaderStages DEFAULT_INITIALIZER(SHADER_TYPE_UNKNOWN);
100100
101101 /// The name of the sampler itself or the name of the texture variable that
102102 /// this static sampler is assigned to if combined texture samplers are used.
125125 /// Default shader resource variable type. This type will be used if shader
126126 /// variable description is not found in the Variables array
127127 /// or if Variables == nullptr
128 enum SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType DEFAULT_INITIALIZER(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
128 SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType DEFAULT_INITIALIZER(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
129129
130130 /// Number of elements in Variables array
131131 Uint32 NumVariables DEFAULT_INITIALIZER(0);
183183 //D3D12_INDEX_BUFFER_STRIP_CUT_VALUE IBStripCutValue;
184184
185185 /// Primitive topology type
186 enum PRIMITIVE_TOPOLOGY PrimitiveTopology DEFAULT_INITIALIZER(PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
186 PRIMITIVE_TOPOLOGY PrimitiveTopology DEFAULT_INITIALIZER(PRIMITIVE_TOPOLOGY_TRIANGLE_LIST);
187187
188188 /// Number of viewports used by this pipeline
189 Uint8 NumViewports DEFAULT_INITIALIZER(1);
189 Uint8 NumViewports DEFAULT_INITIALIZER(1);
190190
191191 /// Number of render targets in the RTVFormats member
192 Uint8 NumRenderTargets DEFAULT_INITIALIZER(0);
192 Uint8 NumRenderTargets DEFAULT_INITIALIZER(0);
193193
194194 /// Render target formats
195 enum TEXTURE_FORMAT RTVFormats[8] DEFAULT_INITIALIZER({});
195 TEXTURE_FORMAT RTVFormats[8] DEFAULT_INITIALIZER({});
196196
197197 /// Depth-stencil format
198 enum TEXTURE_FORMAT DSVFormat DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
198 TEXTURE_FORMAT DSVFormat DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN);
199199
200200 /// Multisampling parameters
201201 struct SampleDesc SmplDesc;
9696 {
9797 /// Determines traingle fill mode, see Diligent::FILL_MODE for details.
9898 /// Default value: Diligent::FILL_MODE_SOLID.
99 enum FILL_MODE FillMode DEFAULT_INITIALIZER(FILL_MODE_SOLID);
99 FILL_MODE FillMode DEFAULT_INITIALIZER(FILL_MODE_SOLID);
100100
101101 /// Determines traingle cull mode, see Diligent::CULL_MODE for details.
102102 /// Default value: Diligent::CULL_MODE_BACK.
103 enum CULL_MODE CullMode DEFAULT_INITIALIZER(CULL_MODE_BACK);
103 CULL_MODE CullMode DEFAULT_INITIALIZER(CULL_MODE_BACK);
104104
105105 /// Determines if a triangle is front- or back-facing. If this parameter is True,
106106 /// a triangle will be considered front-facing if its vertices are counter-clockwise
367367 struct ITexture;
368368 struct ITextureView;
369369
370 struct ITextureVtbl
370 struct ITextureMethods
371371 {
372372 void (*CreateView) (struct ITexture*, const struct TextureViewDesc* ViewDesc, class ITextureView** ppView);
373373 class ITextureView* (*GetDefaultView) (struct ITexture*, TEXTURE_VIEW_TYPE ViewType);
378378
379379 // clang-format on
380380
381 struct ITextureVtbl
382 {
383 struct IObjectMethods Object;
384 struct IDeviceObjectMethods DeviceObject;
385 struct ITextureMethods Texture;
386 };
387
381388 struct ITexture
382389 {
383 struct IObjectVtbl* pObjectVtbl;
384 struct IDeviceObjectVtbl* pDeviceObjectVtbl;
385 struct ITextureVtbl* pTextureVtbl;
390 struct ITextureVtbl* pVtbl;
386391 };
387392
388393 // clang-format off
389394
390395 # define ITexture_GetDesc(This) (const struct TextureDesc*)IDeviceObject_GetDesc(This)
391396
392 # define ITexture_CreateView(This, ...) (This)->pTextureVtbl->CreateView ((struct ITexture*)(This), __VA_ARGS__)
393 # define ITexture_GetDefaultView(This, ...) (This)->pTextureVtbl->GetDefaultView ((struct ITexture*)(This), __VA_ARGS__)
394 # define ITexture_GetNativeHandle(This) (This)->pTextureVtbl->GetNativeHandle((struct ITexture*)(This))
395 # define ITexture_SetState(This, ...) (This)->pTextureVtbl->SetState ((struct ITexture*)(This), __VA_ARGS__)
396 # define ITexture_GetState(This) (This)->pTextureVtbl->GetState ((struct ITexture*)(This))
397 # define ITexture_CreateView(This, ...) (This)->pVtbl->Texture.CreateView ((struct ITexture*)(This), __VA_ARGS__)
398 # define ITexture_GetDefaultView(This, ...) (This)->pVtbl->Texture.GetDefaultView ((struct ITexture*)(This), __VA_ARGS__)
399 # define ITexture_GetNativeHandle(This) (This)->pVtbl->Texture.GetNativeHandle((struct ITexture*)(This))
400 # define ITexture_SetState(This, ...) (This)->pVtbl->Texture.SetState ((struct ITexture*)(This), __VA_ARGS__)
401 # define ITexture_GetState(This) (This)->pVtbl->Texture.GetState ((struct ITexture*)(This))
397402
398403 // clang-format on
399404
225225
226226 // clang-format off
227227
228 struct ITextureViewVtbl
228 struct ITextureViewMethods
229229 {
230230 void (*SetSampler)(struct ITextureView*, class ISampler* pSampler);
231231 class ISampler* (*GetSampler)(struct ITextureView*);
234234
235235 // clang-format on
236236
237 struct ITextureViewVtbl
238 {
239 struct IObjectMethods Object;
240 struct IDeviceObjectMethods DeviceObject;
241 struct ITextureViewMethods TextureView;
242 };
243
237244 struct ITextureView
238245 {
239 struct IObjectVtbl* pObjectVtbl;
240 struct IDeviceObjectVtbl* pDeviceObjectVtbl;
241 struct ITextureViewVtbl* pTextureViewVtbl;
246 struct ITextureViewVtbl* pVtbl;
242247 };
243248
244249 # define ITextureView_GetDesc(This) (const struct TextureViewDesc*)IDeviceObject_GetDesc(This)
245250
246251 // clang-format off
247252
248 # define ITextureView_SetSampler(This, ...) (This)->pTextureViewVtbl->SetSampler((struct ITextureView*)(This), __VA_ARGS__)
249 # define ITextureView_GetSampler(This) (This)->pTextureViewVtbl->GetSampler((struct ITextureView*)(This))
250 # define ITextureView_GetTexture(This) (This)->pTextureViewVtbl->GetTexture((struct ITextureView*)(This))
253 # define ITextureView_SetSampler(This, ...) (This)->pVtbl->TextureView.SetSampler((struct ITextureView*)(This), __VA_ARGS__)
254 # define ITextureView_GetSampler(This) (This)->pVtbl->TextureView.GetSampler((struct ITextureView*)(This))
255 # define ITextureView_GetTexture(This) (This)->pVtbl->TextureView.GetTexture((struct ITextureView*)(This))
251256
252257 // clang-format on
253258
8585
8686 // clang-format off
8787
88 struct IObjectVtbl
88 struct IObjectMethods
8989 {
9090 void (*QueryInterface) (struct IObject*, const struct INTERFACE_ID* IID, struct IObject** ppInterface);
9191 ReferenceCounterValueType (*AddRef) (struct IObject*);
9393 class IReferenceCounters* (*GetReferenceCounters)(struct IObject*);
9494 };
9595
96 struct IObjectVtbl
97 {
98 struct IObjectMethods Object;
99 };
100
96101 // clang-format on
97102
98103 struct IObject
99104 {
100 struct IObjectVtbl* pObjectVtbl;
105 struct IObjectVtbl* pVtbl;
101106 };
102107
103108 // clang-format off
104109
105 # define IObject_QueryInterface(This, ...) (This)->pObjectVtbl->QueryInterface((struct IObject*)(This), __VA_ARGS__)
106 # define IObject_AddRef(This, ...) (This)->pObjectVtbl->AddRef ((struct IObject*)(This), __VA_ARGS__)
107 # define IObject_Release(This) (This)->pObjectVtbl->Release ((struct IObject*)(This))
110 # define IObject_QueryInterface(This, ...) (This)->pVtbl->Object.QueryInterface((struct IObject*)(This), __VA_ARGS__)
111 # define IObject_AddRef(This, ...) (This)->pVtbl->Object.AddRef ((struct IObject*)(This), __VA_ARGS__)
112 # define IObject_Release(This) (This)->pVtbl->Object.Release ((struct IObject*)(This))
108113
109114 // clang-format on
110115
55 file(GLOB COMMON_INCLUDE LIST_DIRECTORIES false include/*)
66 file(GLOB INLINE_SHADERS LIST_DIRECTORIES false include/InlineShaders/*)
77 file(GLOB_RECURSE SHADERS LIST_DIRECTORIES false assets/shaders/*.*)
8 file(GLOB C_INTERFACE_SOURCE LIST_DIRECTORIES false src/c_interface/*)
89
910 set_source_files_properties(${SHADERS} PROPERTIES VS_TOOL_OVERRIDE "None")
1011
11 set(SOURCE ${COMMON_SOURCE})
12 set(SOURCE ${COMMON_SOURCE} ${C_INTERFACE_SOURCE})
1213 set(INCLUDE ${COMMON_INCLUDE})
1314
1415 if(NOT GL_SUPPORTED AND NOT GLES_SUPPORTED)
4646
4747 #include "gtest/gtest.h"
4848
49 extern "C"
50 {
51 int TestBufferCInterface(void* pBuffer);
52 int TestBufferViewCInterface(void* pView);
53 }
54
4955 using namespace Diligent;
5056 using namespace Diligent::Testing;
5157
176182 pBuffer->CreateView(ViewDesc, &pBufferSRV);
177183 EXPECT_NE(pBufferSRV, nullptr) << GetObjectDescString(BuffDesc);
178184
185 EXPECT_EQ(TestBufferViewCInterface(pBufferSRV.RawPtr()), 0);
186
179187 ViewDesc.ViewType = BUFFER_VIEW_UNORDERED_ACCESS;
180188 RefCntAutoPtr<IBufferView> pBufferUAV;
181189 pBuffer->CreateView(ViewDesc, &pBufferUAV);
182190 EXPECT_NE(pBufferUAV, nullptr) << GetObjectDescString(BuffDesc);
183191
184192 pCreateObjFromNativeRes->CreateBuffer(pBuffer);
193
194 EXPECT_EQ(TestBufferCInterface(pBuffer.RawPtr()), 0);
185195 }
186196
187197 TEST_F(BufferCreationTest, CreateStructuedBuffer)
5252 using namespace Diligent;
5353 using namespace Diligent::Testing;
5454
55 extern "C"
56 {
57 int TestTextureCInterface(void* pTexture);
58 int TestTextureViewCInterface(void* pView, void* pSampler);
59 }
60
5561 namespace
5662 {
5763
102108
103109 default: UNEXPECTED("Unexpected device type");
104110 }
111
112 pDevice->CreateSampler(SamplerDesc{}, &pSampler);
105113 }
106114
107115 static void TearDownTestSuite()
108116 {
109117 pCreateObjFromNativeRes.reset();
118 pSampler.Release();
110119 TestingEnvironment::GetInstance()->Reset();
111120 }
112121
295304 RefCntAutoPtr<ITextureView> pSRV;
296305 pTestTex->CreateView(ViewDesc, &pSRV);
297306 EXPECT_NE(pSRV, nullptr) << GetObjectDescString(TexDesc);
307
308 EXPECT_EQ(TestTextureCInterface(pTestTex), 0);
309 EXPECT_EQ(TestTextureViewCInterface(pSRV.RawPtr(), pSampler.RawPtr()), 0);
298310 }
299311
300312 // RTV, DSV & UAV can reference only one mip level
518530 }
519531
520532 static std::unique_ptr<CreateObjFromNativeResTestBase> pCreateObjFromNativeRes;
533 static RefCntAutoPtr<ISampler> pSampler;
521534 };
522535
523536 std::unique_ptr<CreateObjFromNativeResTestBase> TextureCreationTest::pCreateObjFromNativeRes;
537 RefCntAutoPtr<ISampler> TextureCreationTest::pSampler;
524538
525539 TEST_P(TextureCreationTest, CreateTexture)
526540 {
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include "BufferView.h"
28
29 int TestObjectCInterface(struct IObject* pObject);
30 int TestDeviceObjectCInterface(struct IDeviceObject* pDeviceObject);
31
32 int TestBufferViewCInterface(struct IBufferView* pView)
33 {
34 struct IObject* pObject = NULL;
35 ReferenceCounterValueType RefCnt1 = 0, RefCnt2 = 0;
36
37 struct DeviceObjectAttribs Desc;
38 Int32 UniqueId = 0;
39
40 struct BufferViewDesc ViewDesc;
41 class IBuffer* pBuffer = NULL;
42
43 int num_errors =
44 TestObjectCInterface((struct IObject*)pView) +
45 TestDeviceObjectCInterface((struct IDeviceObject*)pView);
46
47 IObject_QueryInterface(pView, &IID_Unknown, &pObject);
48 if (pObject != NULL)
49 IObject_Release(pObject);
50 else
51 ++num_errors;
52
53 RefCnt1 = IObject_AddRef(pView);
54 if (RefCnt1 <= 0)
55 ++num_errors;
56 RefCnt2 = IObject_Release(pView);
57 if (RefCnt2 <= 0)
58 ++num_errors;
59 if (RefCnt2 != RefCnt1 - 1)
60 ++num_errors;
61
62 Desc = *IDeviceObject_GetDesc(pView);
63 if (Desc.Name == NULL)
64 ++num_errors;
65
66 UniqueId = IDeviceObject_GetUniqueID(pView);
67 if (UniqueId == 0)
68 ++num_errors;
69
70
71 pBuffer = IBufferView_GetBuffer(pView);
72 if (pBuffer == NULL)
73 ++num_errors;
74
75 ViewDesc = *IBufferView_GetDesc(pView);
76 if (ViewDesc.ByteWidth == 0)
77 ++num_errors;
78
79 return num_errors;
80 }
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include "Buffer.h"
28
29 int TestObjectCInterface(struct IObject* pObject);
30 int TestDeviceObjectCInterface(struct IDeviceObject* pDeviceObject);
31
32 int TestBufferCInterface(struct IBuffer* pBuffer)
33 {
34 struct IObject* pObject = NULL;
35 ReferenceCounterValueType RefCnt1 = 0, RefCnt2 = 0;
36
37 struct DeviceObjectAttribs Desc;
38 Int32 UniqueId = 0;
39
40 struct BufferDesc BuffDesc;
41 struct IBufferView * pView0 = NULL, *pView1 = NULL;
42 struct BufferViewDesc ViewDesc;
43 void* NativeHanlde;
44 RESOURCE_STATE State = RESOURCE_STATE_CONSTANT_BUFFER;
45
46 int num_errors =
47 TestObjectCInterface((struct IObject*)pBuffer) +
48 TestDeviceObjectCInterface((struct IDeviceObject*)pBuffer);
49
50 IObject_QueryInterface(pBuffer, &IID_Unknown, &pObject);
51 if (pObject != NULL)
52 IObject_Release(pObject);
53 else
54 ++num_errors;
55
56 RefCnt1 = IObject_AddRef(pBuffer);
57 if (RefCnt1 <= 0)
58 ++num_errors;
59 RefCnt2 = IObject_Release(pBuffer);
60 if (RefCnt2 <= 0)
61 ++num_errors;
62 if (RefCnt2 != RefCnt1 - 1)
63 ++num_errors;
64
65 Desc = *IDeviceObject_GetDesc(pBuffer);
66 if (Desc.Name == NULL)
67 ++num_errors;
68
69 UniqueId = IDeviceObject_GetUniqueID(pBuffer);
70 if (UniqueId == 0)
71 ++num_errors;
72
73 BuffDesc = *IBuffer_GetDesc(pBuffer);
74 if (BuffDesc._DeviceObjectAttribs.Name == NULL)
75 ++num_errors;
76
77 ViewDesc._DeviceObjectAttribs.Name = "Test SRV";
78 ViewDesc.ViewType = BUFFER_VIEW_SHADER_RESOURCE;
79 ViewDesc.ByteOffset = 32;
80 ViewDesc.ByteWidth = 0;
81 ViewDesc.Format.NumComponents = 4;
82 ViewDesc.Format.ValueType = VT_FLOAT32;
83 ViewDesc.Format.IsNormalized = false;
84 IBuffer_CreateView(pBuffer, &ViewDesc, &pView0);
85 if (pView0 != NULL)
86 IObject_Release(pView0);
87 else
88 ++num_errors;
89
90 pView1 = IBuffer_GetDefaultView(pBuffer, BUFFER_VIEW_SHADER_RESOURCE);
91
92 NativeHanlde = IBuffer_GetNativeHandle(pBuffer);
93 if (NativeHanlde == NULL)
94 ++num_errors;
95
96 State = IBuffer_GetState(pBuffer);
97 IBuffer_SetState(pBuffer, State);
98
99 return num_errors;
100 }
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include "DeviceObject.h"
28
29 int TestDeviceObjectCInterface(struct IDeviceObject* pDeviceObject)
30 {
31 struct DeviceObjectAttribs Desc;
32 Int32 UniqueId = 0;
33
34 int num_errors = 0;
35
36 Desc = *IDeviceObject_GetDesc(pDeviceObject);
37 if (Desc.Name == NULL)
38 ++num_errors;
39
40 UniqueId = IDeviceObject_GetUniqueID(pDeviceObject);
41 if (UniqueId == 0)
42 ++num_errors;
43
44 return num_errors;
45 }
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include "Object.h"
28
29 int TestObjectCInterface(struct IObject* pObject)
30 {
31 struct IObject* pObject1 = NULL;
32 ReferenceCounterValueType RefCnt1 = 0, RefCnt2 = 0;
33
34 int num_errors = 0;
35
36 IObject_QueryInterface(pObject, &IID_Unknown, &pObject1);
37 if (pObject1 != NULL)
38 IObject_Release(pObject1);
39 else
40 ++num_errors;
41
42 RefCnt1 = IObject_AddRef(pObject);
43 if (RefCnt1 <= 0)
44 ++num_errors;
45 RefCnt2 = IObject_Release(pObject);
46 if (RefCnt2 <= 0)
47 ++num_errors;
48 if (RefCnt2 != RefCnt1 - 1)
49 ++num_errors;
50
51 return num_errors;
52 }
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include "TextureView.h"
28
29 int TestObjectCInterface(struct IObject* pObject);
30 int TestDeviceObjectCInterface(struct IDeviceObject* pDeviceObject);
31
32 int TestTextureViewCInterface(struct ITextureView* pView, struct ISampler* pSampler)
33 {
34 struct IObject* pObject = NULL;
35 ReferenceCounterValueType RefCnt1 = 0, RefCnt2 = 0;
36
37 struct DeviceObjectAttribs Desc;
38 Int32 UniqueId = 0;
39
40 struct TextureViewDesc ViewDesc;
41 class ITexture* pTexture = NULL;
42
43 int num_errors =
44 TestObjectCInterface((struct IObject*)pView) +
45 TestDeviceObjectCInterface((struct IDeviceObject*)pView);
46
47 IObject_QueryInterface(pView, &IID_Unknown, &pObject);
48 if (pObject != NULL)
49 IObject_Release(pObject);
50 else
51 ++num_errors;
52
53 RefCnt1 = IObject_AddRef(pView);
54 if (RefCnt1 <= 0)
55 ++num_errors;
56 RefCnt2 = IObject_Release(pView);
57 if (RefCnt2 <= 0)
58 ++num_errors;
59 if (RefCnt2 != RefCnt1 - 1)
60 ++num_errors;
61
62 Desc = *IDeviceObject_GetDesc(pView);
63 if (Desc.Name == NULL)
64 ++num_errors;
65
66 UniqueId = IDeviceObject_GetUniqueID(pView);
67 if (UniqueId == 0)
68 ++num_errors;
69
70
71 pTexture = ITextureView_GetTexture(pView);
72 if (pTexture == NULL)
73 ++num_errors;
74
75 ViewDesc = *ITextureView_GetDesc(pView);
76 if (ViewDesc.ViewType != TEXTURE_VIEW_SHADER_RESOURCE)
77 ++num_errors;
78
79 ITextureView_SetSampler(pView, pSampler);
80
81 return num_errors;
82 }
0 /*
1 * Copyright 2019-2020 Diligent Graphics LLC
2 * Copyright 2015-2019 Egor Yusov
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * In no event and under no legal theory, whether in tort (including negligence),
17 * contract, or otherwise, unless required by applicable law (such as deliberate
18 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
19 * liable for any damages, including any direct, indirect, special, incidental,
20 * or consequential damages of any character arising as a result of this License or
21 * out of the use or inability to use the software (including but not limited to damages
22 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23 * all other commercial damages or losses), even if such Contributor has been advised
24 * of the possibility of such damages.
25 */
26
27 #include "Texture.h"
28
29 int TestObjectCInterface(struct IObject* pObject);
30 int TestDeviceObjectCInterface(struct IDeviceObject* pDeviceObject);
31
32 struct ISampler;
33
34 int TestTextureCInterface(struct ITexture* pTexture)
35 {
36 struct IObject* pObject = NULL;
37 ReferenceCounterValueType RefCnt1 = 0, RefCnt2 = 0;
38
39 struct DeviceObjectAttribs Desc;
40 Int32 UniqueId = 0;
41
42 struct TextureDesc TexDesc;
43 struct ITextureView * pView0 = NULL, *pView1 = NULL;
44 struct TextureViewDesc ViewDesc;
45 void* NativeHanlde;
46 RESOURCE_STATE State = RESOURCE_STATE_SHADER_RESOURCE;
47
48 int num_errors =
49 TestObjectCInterface((struct IObject*)pTexture) +
50 TestDeviceObjectCInterface((struct IDeviceObject*)pTexture);
51
52 IObject_QueryInterface(pTexture, &IID_Unknown, &pObject);
53 if (pObject != NULL)
54 IObject_Release(pObject);
55 else
56 ++num_errors;
57
58 RefCnt1 = IObject_AddRef(pTexture);
59 if (RefCnt1 <= 0)
60 ++num_errors;
61 RefCnt2 = IObject_Release(pTexture);
62 if (RefCnt2 <= 0)
63 ++num_errors;
64 if (RefCnt2 != RefCnt1 - 1)
65 ++num_errors;
66
67 Desc = *IDeviceObject_GetDesc(pTexture);
68 if (Desc.Name == NULL)
69 ++num_errors;
70
71 UniqueId = IDeviceObject_GetUniqueID(pTexture);
72 if (UniqueId == 0)
73 ++num_errors;
74
75 TexDesc = *ITexture_GetDesc(pTexture);
76 if (TexDesc._DeviceObjectAttribs.Name == NULL)
77 ++num_errors;
78
79 memset(&ViewDesc, 0, sizeof(ViewDesc));
80 ViewDesc._DeviceObjectAttribs.Name = "Test SRV";
81 ViewDesc.ViewType = TEXTURE_VIEW_SHADER_RESOURCE;
82 ITexture_CreateView(pTexture, &ViewDesc, &pView0);
83 if (pView0 != NULL)
84 IObject_Release(pView0);
85 else
86 ++num_errors;
87
88 pView1 = ITexture_GetDefaultView(pTexture, TEXTURE_VIEW_SHADER_RESOURCE);
89 if (pView1 == NULL)
90 ++num_errors;
91
92 NativeHanlde = ITexture_GetNativeHandle(pTexture);
93 if (NativeHanlde == NULL)
94 ++num_errors;
95
96 State = ITexture_GetState(pTexture);
97 ITexture_SetState(pTexture, State);
98
99 return num_errors;
100 }