Loading...
Searching...
No Matches
extCompGpuComputationResource.h
1//
2// Copyright 2017 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
25#define PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hd/bufferSource.h"
30#include "pxr/imaging/hdSt/resourceBinder.h"
31#include "pxr/imaging/hdSt/extCompComputeShader.h"
32#include "pxr/imaging/hdSt/resourceRegistry.h"
33
34#include <vector>
35
36PXR_NAMESPACE_OPEN_SCOPE
37
38using HdStExtCompGpuComputationResourceSharedPtr =
39 std::shared_ptr<class HdStExtCompGpuComputationResource>;
40using HdStGLSLProgramSharedPtr= std::shared_ptr<class HdStGLSLProgram>;
41using HdBufferArrayRangeSharedPtrVector =
42 std::vector<HdBufferArrayRangeSharedPtr>;
43
54public:
74 HdBufferSpecVector const &outputBufferSpecs,
75 HdSt_ExtCompComputeShaderSharedPtr const &kernel,
76 HdBufferArrayRangeSharedPtrVector const &inputs,
77 HdStResourceRegistrySharedPtr const &registry
78 );
79
80 virtual ~HdStExtCompGpuComputationResource() = default;
81
84 HdBufferArrayRangeSharedPtrVector const &GetInputs() const {
85 return _inputs;
86 }
87
92 HdStGLSLProgramSharedPtr const &GetProgram() {
93 if (!_computeProgram) {
94 _Resolve();
95 }
96 return _computeProgram;
97 }
98
102 HdSt_ResourceBinder const &GetResourceBinder() {
103 if (!_computeProgram) {
104 _Resolve();
105 }
106 return _resourceBinder;
107 }
108
109private:
113 bool _Resolve();
114
115 HdBufferSpecVector _outputBufferSpecs;
116 HdSt_ExtCompComputeShaderSharedPtr _kernel;
117 HdStResourceRegistrySharedPtr _registry;
118
119 size_t _shaderSourceHash;
120 HdBufferArrayRangeSharedPtrVector _inputs;
121 HdStGLSLProgramSharedPtr _computeProgram;
122 HdSt_ResourceBinder _resourceBinder;
123
126 const HdStExtCompGpuComputationResource &) = delete;
128 const HdStExtCompGpuComputationResource &) = delete;
129};
130
131PXR_NAMESPACE_CLOSE_SCOPE
132
133#endif // PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
134
A resource that represents the persistent GPU resources of an ExtComputation.
HdStGLSLProgramSharedPtr const & GetProgram()
Gets the GPU HdStGLSLProgram to run to execute the computation.
HdStExtCompGpuComputationResource(HdBufferSpecVector const &outputBufferSpecs, HdSt_ExtCompComputeShaderSharedPtr const &kernel, HdBufferArrayRangeSharedPtrVector const &inputs, HdStResourceRegistrySharedPtr const &registry)
Creates a GPU computation resource that can bind resources matching the layout of the compute kernel.
HdBufferArrayRangeSharedPtrVector const & GetInputs() const
Gets the HdBufferArrayRange that inputs should be loaded into using the resource binder.
HdSt_ResourceBinder const & GetResourceBinder()
Gets the resource binder that matches the layout of the compute program.