Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pierre NARVOR
rtac_base
Commits
146bf9d9
Commit
146bf9d9
authored
Oct 20, 2021
by
Pierre NARVOR
Browse files
[cuda] Added helpers methods to Texture2D
parent
e1f83f0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
cuda/include/rtac_base/cuda/Texture2D.h
View file @
146bf9d9
...
...
@@ -63,12 +63,14 @@ class Texture2D
void
allocate_data
(
size_t
width
,
size_t
height
);
void
set_image
(
size_t
width
,
size_t
height
,
const
T
*
data
);
void
set_image
(
size_t
width
,
size_t
height
,
const
DeviceVector
<
T
>&
data
);
void
set_subimage
(
size_t
width
,
size_t
height
,
size_t
wOffset
,
size_t
hOffset
,
const
T
*
data
);
size_t
width
()
const
;
size_t
height
()
const
;
size_t
size
()
const
;
cudaTextureDesc
description
()
const
;
...
...
@@ -243,6 +245,35 @@ void Texture2D<T>::set_image(size_t width, size_t height, const T* data)
this
->
update_texture_handle
();
}
template
<
typename
T
>
void
Texture2D
<
T
>::
set_image
(
size_t
width
,
size_t
height
,
const
DeviceVector
<
T
>&
data
)
{
if
(
data
.
size
()
<
width
*
height
)
{
std
::
ostringstream
oss
;
oss
<<
"error Texture2D::set_image : not enough input data for "
<<
"requested size (expected "
<<
width
*
height
<<
", got "
<<
data
.
size
()
<<
")"
;
throw
std
::
runtime_error
(
oss
.
str
());
}
this
->
allocate_data
(
width
,
height
);
//CUDA_CHECK( cudaMemcpyToArray(data_, 0, 0, data,
// sizeof(T)*width_*height_,
// cudaMemcpyHostToDevice) );
CUDA_CHECK
(
cudaMemcpy2DToArray
(
data_
,
0
,
0
,
data
.
data
(),
sizeof
(
T
)
*
width_
,
sizeof
(
T
)
*
width_
,
height_
,
cudaMemcpyDeviceToDevice
)
);
// A new texture handle creation seems to be necessary when data is changed.
this
->
update_texture_handle
();
}
template
<
typename
T
>
void
Texture2D
<
T
>::
set_subimage
(
size_t
width
,
size_t
height
,
size_t
wOffset
,
size_t
hOffset
,
...
...
@@ -281,6 +312,12 @@ size_t Texture2D<T>::height() const
return
height_
;
}
template
<
typename
T
>
size_t
Texture2D
<
T
>::
size
()
const
{
return
this
->
width
()
*
this
->
height
();
}
template
<
typename
T
>
struct
cudaTextureDesc
Texture2D
<
T
>::
description
()
const
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment