Discussion:
calling IDirect3DDevice9::StretchRect failed
(too old to reply)
wpiyong
2007-06-14 15:34:51 UTC
Permalink
Calling IDirect3DDevice9::StretchRect failed with return value
D3DERR_INVALIDCALL. In the project, I am using VMR9 custom allocator
presenter based on the sample code VMR9Allocator. The project required
to do some image processing in pixel shader, and so before pixel
shader processing, I need first to manipulate the pixel data in video
texture. In VMR9Allocator, there are two ways to create the video
texture, one is to create VMR9AllocFlag_TextureSurface by calling
AllocateSurfaceHelper, and in PresentImage, calling GetContainer to
get the video texture. I tried this method, but I could not call
IDirect3DTexture9::LockRect. I do not know how VMR9 create the video
texture, I mean USAGE and POOL of the texture. So I tried the second
method create private texture by calling CreateTexture with parameters
USAGE: D3DUSAGE_DYNAMIC, POOL: D3DPOOL_DEFAULT. I do not know how to
create the surface, so I just use AllocateSurfaceHelper with
information of lpAllocInfo->dwFlags |= VMR9AllocFlag_TextureSurface.
In PresentImage, GetSurfaceLevel is called to get the private texture
surface, but the call to StretchRect failed. I also tried to change
the setting in AllocateSurfaceHelper dwFlags to
VMR9AllocFlag_OffScreenSurface, video frames are played in another
window, but this time PresentImage never been called (looks like using
default allocator presenter). Can anyone help me with this problem? I
read DX document and searched on line for more than one week, but no
results. I also found some sample codes creating private video
texture, but they are not using VMR9. Thanks for your help.
Jan Bruns
2007-06-14 17:16:15 UTC
Permalink
Post by wpiyong
Calling IDirect3DDevice9::StretchRect failed with return value
D3DERR_INVALIDCALL.
StrechtRect normally isn't the way to go to get a texture filled
with image data. It is mainly used to copy data between vidmem
surfaces that can be rendered to.

I don't know anything about VMR9, even not what it is (google says
it has s.th. to do with TV/video). Whatever it is, it should either
generate/accept a texture compatible to your d3d-device and copy
data to it directly (using methods probably unavailable from
user-land), or it should provide it's data in form of a SYSMEM
(Offscreenplain) D3D-surface, compatible to your d3d-device,
so you could use d3ddev.UpdateTexture()/d3ddev.UpdateSurface().

After searching msdn for VMR9, it seems to me that IVMRSurface9
isn't meant to be used by applications, and the surfaces are
lockable. In D3D, lockable surfaces normally can't be rendered
to, so that StretchRect() may fail.

I'd try to put UpdateSurface() to the error-handling part
where your try to StretchRect() fails, and I'd use a
RT-trexture (if possible) as destination.

Gruss

Jan Bruns
legalize+ (Richard [Microsoft Direct3D MVP])
2007-06-14 18:32:01 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by wpiyong
Calling IDirect3DDevice9::StretchRect failed with return value
D3DERR_INVALIDCALL. [...]
Standard questions apply:

- debug runtime installed?
- debug runtime selected?
- any relevant messages in the debug output stream?

The debug runtime always announces in the debug output stream the
reason for an invalid call error.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
wpiyong
2007-06-14 18:59:59 UTC
Permalink
Post by legalize+ (Richard [Microsoft Direct3D MVP])
[Please do not mail me a copy of your followup]
Post by wpiyong
Calling IDirect3DDevice9::StretchRect failed with return value
D3DERR_INVALIDCALL. [...]
- debug runtime installed?
- debug runtime selected?
- any relevant messages in the debug output stream?
The debug runtime always announces in the debug output stream the
reason for an invalid call error.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>
Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Thanks for your information. I checked the debug output, it had the
message "Direct3D9: (ERROR) :Destination textures passed to
StretchRect or ColorFill must have D3DUSAGE_RENDERTARGET set". It
looks like that I should create the private video texture with the
parameter of D3DUSAGE_RENDERTARGET not D3DUSAGE_DYNAMIC. But I need to
access to the pixels in video texture. If I set to
D3DUSAGE_RENDERTARGET, the call to LockRect will fail. So is there any
way to solve this problem? Thank you.
Yong
legalize+ (Richard [Microsoft Direct3D MVP])
2007-06-14 19:15:13 UTC
Permalink
[Please do not mail me a copy of your followup]
Post by wpiyong
Thanks for your information. I checked the debug output, it had the
message "Direct3D9: (ERROR) :Destination textures passed to
StretchRect or ColorFill must have D3DUSAGE_RENDERTARGET set". It
looks like that I should create the private video texture with the
parameter of D3DUSAGE_RENDERTARGET not D3DUSAGE_DYNAMIC. But I need to
access to the pixels in video texture. If I set to
D3DUSAGE_RENDERTARGET, the call to LockRect will fail. So is there any
way to solve this problem? Thank you.
Do you need access to the pixels for reading or for writing?

I'm guessing only for writing, in which case you should create a
system memory texture, write to that and use UpdateTexture to copy
from system to device memory.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>
Jan Bruns
2007-06-14 19:27:07 UTC
Permalink
Post by wpiyong
Thanks for your information. I checked the debug output, it had the
message "Direct3D9: (ERROR) :Destination textures passed to
StretchRect or ColorFill must have D3DUSAGE_RENDERTARGET set". It
looks like that I should create the private video texture with the
parameter of D3DUSAGE_RENDERTARGET not D3DUSAGE_DYNAMIC. But I need to
access to the pixels in video texture. If I set to
D3DUSAGE_RENDERTARGET, the call to LockRect will fail. So is there any
way to solve this problem? Thank you.
I don't get what you're trying to do.

You want some video-data to be streamed to d3d, then modify it
per CPU using lock, and finally use it as a texture-map?

Can't the modification be done per gpu?

Gruss

Jan Bruns
wpiyong
2007-06-14 20:50:32 UTC
Permalink
Post by Jan Bruns
Post by wpiyong
Thanks for your information. I checked the debug output, it had the
message "Direct3D9: (ERROR) :Destination textures passed to
StretchRect or ColorFill must have D3DUSAGE_RENDERTARGET set". It
looks like that I should create the private video texture with the
parameter of D3DUSAGE_RENDERTARGET not D3DUSAGE_DYNAMIC. But I need to
access to the pixels in video texture. If I set to
D3DUSAGE_RENDERTARGET, the call to LockRect will fail. So is there any
way to solve this problem? Thank you.
I don't get what you're trying to do.
You want some video-data to be streamed to d3d, then modify it
per CPU using lock, and finally use it as a texture-map?
Can't the modification be done per gpu?
Gruss
Jan Bruns
Thank you very much for all your replys. Actually, this image
processing is to double size the video frame in both hight and width.
At first, I thought to enlarge the image in GPU, but to my knowledge,
I could not find way to do that in pixel shader. So I first want to
create a double sized video texture first on CPU, then do other
processings in pixel shader. Therefore, to enlarge the private video
texture in CPU, I want to add extra pixels with some kind characters
so that pixel shader can recognize them. Those extra pixels are
inserted in between of original pixels along hight and width. So, the
pirvate video texture will be read and written. Another thing is that
I am using VMR9. I do not know if there are some restrictions for VMR9
on surface allocation. I could not find any useful documents about
vmr9 except DXsdk. In vmr9, video frames are decoded to surface, I
tried LockRect on the surface, but failed. Also, I only found two ways
to create the video texture which I described in last poster. Do you
have any ideas of access pixel in video texture or the whole work
being dong on pixel shader (GPU) Thank you.
Yong
Jan Bruns
2007-06-14 21:05:52 UTC
Permalink
Post by wpiyong
Post by Jan Bruns
I don't get what you're trying to do.
You want some video-data to be streamed to d3d, then modify it
per CPU using lock, and finally use it as a texture-map?
Can't the modification be done per gpu?
Thank you very much for all your replys. Actually, this image
processing is to double size the video frame in both hight and width.
At first, I thought to enlarge the image in GPU, but to my knowledge,
I could not find way to do that in pixel shader. So I first want to
create a double sized video texture first on CPU, then do other
processings in pixel shader. Therefore, to enlarge the private video
texture in CPU, I want to add extra pixels with some kind characters
so that pixel shader can recognize them. Those extra pixels are
inserted in between of original pixels along hight and width. So, the
pirvate video texture will be read and written. Another thing is that
I am using VMR9. I do not know if there are some restrictions for VMR9
on surface allocation. I could not find any useful documents about
vmr9 except DXsdk. In vmr9, video frames are decoded to surface, I
tried LockRect on the surface, but failed. Also, I only found two ways
to create the video texture which I described in last poster. Do you
have any ideas of access pixel in video texture or the whole work
being dong on pixel shader (GPU) Thank you.
Sounds like you don't want to simply scale the image (whis wouldn't
make much sense with textures), but merely want to add some extra data
to the image? Why not pass this extra data in another texture to the
shader, or even generate it on the fly in the shader?

Gruss

Jan Bruns
wpiyong
2007-06-14 21:13:41 UTC
Permalink
Post by Jan Bruns
Post by wpiyong
Post by Jan Bruns
I don't get what you're trying to do.
You want some video-data to be streamed to d3d, then modify it
per CPU using lock, and finally use it as a texture-map?
Can't the modification be done per gpu?
Thank you very much for all your replys. Actually, this image
processing is to double size the video frame in both hight and width.
At first, I thought to enlarge the image in GPU, but to my knowledge,
I could not find way to do that in pixel shader. So I first want to
create a double sized video texture first on CPU, then do other
processings in pixel shader. Therefore, to enlarge the private video
texture in CPU, I want to add extra pixels with some kind characters
so that pixel shader can recognize them. Those extra pixels are
inserted in between of original pixels along hight and width. So, the
pirvate video texture will be read and written. Another thing is that
I am using VMR9. I do not know if there are some restrictions for VMR9
on surface allocation. I could not find any useful documents about
vmr9 except DXsdk. In vmr9, video frames are decoded to surface, I
tried LockRect on the surface, but failed. Also, I only found two ways
to create the video texture which I described in last poster. Do you
have any ideas of access pixel in video texture or the whole work
being dong on pixel shader (GPU) Thank you.
Sounds like you don't want to simply scale the image (whis wouldn't
make much sense with textures), but merely want to add some extra data
to the image? Why not pass this extra data in another texture to the
shader, or even generate it on the fly in the shader?
Gruss
Jan Bruns- Hide quoted text -
- Show quoted text -
Good point. That is what I am thinking. It seems that there is no way
to access pixels in video texture in VMR9 :(

Loading...