The content of the invention
The present invention provides a kind of determination methods and device of GPU task completion status, solves and striding course is difficult on GPU
The technical problem of content in another unfinished GPU task is read, has been reached and has been realized the shared unfinished GPU task content of striding course
Technique effect;
Typical case in GPU task is especially solved, when striding course shares same texture, a process is being drawn
Texture, and another process is in the technical problem for reading the texture.
In a first aspect, the application provides a kind of determination methods of GPU task completion status, the determination methods include:
The predeterminable event inquiry in the first process;Operation in first process has the GPU task;
After the GPU task, the event query is preset as into completion status;
Judge whether the event query is ready state;
If, it is determined that the GPU task is completed.
Preferably, the GPU task specially draws shared texture;
The inquiry of the predeterminable event in first process, also includes before:
The shared texture is preset in the first process, and the shared texture is set to into post-processing object, to be painted
System;
It is described to determine that the GPU task is completed, also include afterwards:
Second process reads the shared texture.
Preferably, the inquiry of the predeterminable event in the first process, specially:
By the CreateQuery methods of IDirect3DDevice9 interfaces, one is preset in first process
IDirect3DQuery9 interfaces, to preset an event query.
Preferably, it is described after GPU task instruction, the event query is preset as into completion status, specially:
After GPU task instruction, by the Issue methods of IDirect3DQuery9 interfaces by the event query
It is arranged to D3DISSUE_END states.
Preferably, it is described to judge whether the event query is ready state, specially:
By the GetData methods of IDirect3DDevice9 interfaces in first process, GetData methods are judged
Return value, if the return value be mistake S_FALSE, first process by GetData methods continue judgement;If institute
State return value for correct S_OK when, the event query be ready state.
Preferably, it is described that a shared texture is preset in the first process, specifically include:
D3D11_TEXTURE2D_DESC structures in initialization Direct3D11 equipment, by Direct3D11 device pointers
The default ID3D11Texture2D texture interfaces of the CreateTexture2D methods of interface ID3D11Device;
Shared texture pointer interface ID3D11Texture2D is obtained, by interface ID3D11Texture2D's
QueryInterface methods obtain IDXGIResource interfaces;
By the GetSharedHandle methods in the IDXGIResource interfaces that get, handle value is obtained
sharedHandle。
Preferably, the inquiry of the predeterminable event in first process, specifically includes:
When the second process needs to read the unfinished shared texture, by ID3D11Device interfaces
CreateQuery methods, preset an ID3D11Query interface in first process, to preset an event query.
Preferably, it is described after the GPU task, the event query is preset as into completion status, specially:
After the GPU task, the event query is set by the End methods of ID3D11DeviceContext interfaces
It is set to D3DISSUE_END states.
Preferably, it is described to judge whether the event query is ready state, specially:
By the GetData methods of ID3D11DeviceContext interfaces, the return value of GetData methods is judged, to sentence
Whether disconnected event query completes.
Second aspect, the application also provides a kind of judgment means of GPU task completion status, and the judgment means include:
The default unit of inquiry, inquires about for the predeterminable event in the first process;
State presets unit, for after the GPU task, the event query being preset as into completion status;
Condition adjudgement unit, for judging whether the event query is ready state;
Status determining unit, for when the condition adjudgement unit judges result is to be, it is determined that the GPU task is
Complete.
One or more technical schemes provided in the embodiment of the present invention, at least have the following technical effect that or advantage:
1st, the method and device that the embodiment of the present application is provided, is inquired about by the predeterminable event in first process;Institute
After stating GPU task, the event query is preset as into completion status, makes video driver take over the state control of inquiry;And lead to
Cross and judge that whether event query is ready state judging whether GPU task completes;If it is not, then first process continues to sentence
It is disconnected;If, it is determined that the GPU task is completed, realizes the GPU task content in the shared operation of striding course.
2nd, the method and device that the embodiment of the present application is provided, by passing through IDirect3DDevice9 in Direct3D9
The default texture of the CreateTexture interfaces of interface, arranges handle value for 0 to preset a shared texture, obtains return described
The read-write handle value e of shared texture, by arranging the shared handle value to open the first process in default shared texture, it is real
The read-write of striding course texture is showed.
3rd, the method and device that the embodiment of the present application is provided, the second process needs to read unfinished described shared texture
When, the predeterminable event inquiry in first process makes video driver take over the state control of inquiry;It is described by determining
Event query whether ready state determining whether shared texture part to be read has completed, the second process can if completing
Shared texture part to be read in read the first process, realizes and the process of the shared texture is read on GPU need not wait
The process that the texture is drawn to another is completed to draw operation on GPU and just can correctly read the picture material of texture.
Described above is only the general introduction of technical solution of the present invention, in order to better understand the technological means of the present invention,
And can be practiced according to the content of specification, and in order to allow the above and other objects of the present invention, feature and advantage can
Become apparent, below especially exemplified by the specific embodiment of the present invention.
Embodiment one
The application provides a kind of determination methods of GPU task completion status, refers to Fig. 1, and the determination methods include:
Step S110, the predeterminable event inquiry in the first process;Operation in first process has the GPU task.
Step S120, after the GPU task, by the event query completion status is preset as.
Step S130, judges whether the event query is ready state.
Step S140, if, it is determined that the GPU task is completed.
It should be noted that this method is suitable for all Windows systems, particularly Windows Vista systems and afterwards
Version.Can be in the version of Windows Vista, Windows 7, Windows 8 and Windows 10.
With reference to Fig. 1, the determination methods of the GPU task completion status provided the application describe in detail:
Wherein, the GPU task specially draws shared texture, and the predeterminable event in first process is inquired about,
Also include before:
Step S109, presets the shared texture in the first process, and the shared texture is set to into post-processing object,
To be drawn;
It is described to determine that the GPU task is completed, also include afterwards:
Step S150, the second process reads the shared texture.
The determination methods that the application is provided can apply to Direct3D9, be also applied to Direct3D11.
Example one
The determination methods that the application is provided are applied in Direct3D9, therefore, the specific embodiment of the determination methods
It is based on the interface or method in Direct3D11.The determination methods of the GPU task completion status that the application is provided, in detail such as
Under:
First, execution step S110, the predeterminable event inquiry in the first process;Operation in first process has described
GPU task.
In present application example, the inquiry of the predeterminable event in the first process;Operation in first process has described
GPU task, specifically includes:
By the CreateQuery methods of IDirect3DDevice9 interfaces, one is preset in first process
IDirect3DQuery9 interfaces, to preset an event query Query.
It should be noted that including three state by the default event query Query of step S110:
(1) ready state (Signaled State):It seem the state of a free time.Query object has been generated, and is judged
Application program is completing this time inquiry.Work as poll-final, when inquiry state is changed into ready state, it is possible to get inquiry knot
Fruit.
(2) preset state (Building State):It seem a staging area.In preset state, inquiry is sent out
Rise (by calling D3DISSUE_BEGIN), but without being transformed into completion status.When application program statement poll-final (passes through
Call D3DISSUE_END), inquiry has just been transformed into completion status.
(3) completion status (Issued State):The resource that expression is queried has taken over inquiry.When resource completes work
After work, state machine can be transformed into ready state.In the stage of completing, application program is it must be determined whether be converted to ready shape
State, if ready state, then what GetData was returned is exactly the Query Result for needing.
Next execution step S120, after the GPU task, by the event query completion status is preset as.
It is described after the GPU task in present application example, the event query is preset as into completion status, specifically
For:
After the GPU task, the event query is arranged by the Issue methods of IDirect3DQuery9 interfaces
Into D3DISSUE_END states.
The event query Query is arranged to into D3DISSUE_END states by performing, so that video driver becomes to connect
The state control of pipe inquiry.
Subsequently execution step S130, judges whether the event query is ready state.
In the step s 120 after the GPU task, the event query is preset as into completion status, afterwards described first
Process needs to judge whether query event completes, if completing, then the operation of GPU task is also completed, then the second process this
When can correctly read in first process share GPU task content.
Due in step S120 the event query being arranged to by the Issue methods of IDirect3DQuery9 interfaces
Video driver has taken over the state control of inquiry after D3DISSUE_END states, and after the completion of GPU task, the video driver will
The State Transferring of the query event is into ready state, so whether the state that only need to pass through to judge event query is ready state
To judge whether GPU task completes.
In present application example, if it is ready state not determine the event query, first process continues to sentence
It is disconnected, specifically include:
By the GetData methods of IDirect3DDevice9 interfaces in first process, GetData methods are judged
Return value be mistake S_FALSE when, first process by GetData methods continue judgement.
Last execution step S140, if, it is determined that the GPU task is completed.
In present application example, if described, it is determined that the GPU task is completed, is specifically included:
By the GetData methods of IDirect3DDevice9 interfaces in first process, GetData methods are judged
Return value be correct S_OK when, it is determined that goal task has been completed, and first process exits judgement.
A kind of determination methods of GPU task completion status that above-mentioned the application is also provided, the GPU task completion status
Determination methods solve and the technical problem that striding course reads content in another unfinished GPU task are difficult on GPU.
When the GPU task specially draws shared texture, then step S109 is first carried out before execution step S110,
The shared texture is preset in first process, and the shared texture is set to into post-processing object, to be drawn;Performing step
After rapid S140, execution step S150, the second process reads the shared texture.
Step S109, presets the shared texture in the first process, and the shared texture is set to render
Target, to be drawn, specifically includes:
In the first process, by the CreateTexture interfaces of IDirect3DDevice9 interfaces in Direct3D9
Preset a shared texture;By the SetRenderTarget methods of IDirect3DDevice9 interfaces, by the shared texture
It is arranged to a post-processing object.
It can be that method for drafting related in IDirect3DDevice9 interfaces is drawn to draw on the shared texture, can
Being to draw content on the shared texture by SetRenderTarget methods.
In the first process, by the CreateTexture interfaces of IDirect3DDevice9 interfaces in Direct3D9
A shared texture is preset, specifically can be pre- to realize when the handle for arranging is 0 by arranging handle (HANDLE) pointer
If texture be sharable texture;When the handle for arranging is not 0, then it represents that open a shared texture.
In the shared texture of striding course operation, by arranging handle value in the first process for 0 a shared line is preset
Reason, obtains returning the read-write handle value sharedHandle of the shared texture, and other processes can be described shared by arranging
Handle value sharedHandle to open the first process in default shared texture, realize the read-write of striding course texture, i.e., in fact
Having showed the second process can share the content of shared texture of the first process.But when in the first process in drafting texture still not
The picture material of the shared texture can be correctly obtained, will further explain how to solve the problem below.
Step S150, the second process reads the shared texture, specifically includes:
Second process by arranging the shared handle value sharedHandle to open the first process in it is default
Shared texture, and read the shared texture, by the shared texture display in first process second process window
On mouth.
It is determined that the shared texture rendering after the completion of, second process can read being total in first process
Texture is enjoyed, even if the drafting to sharing texture has not been completed in certain process of moment first using after the reading/writing method of the application,
Second process still can synchronously read the content of the shared texture.
In the present embodiment, it is described to read the shared texture particular by IDirect3DDevice9's
SetTexture methods, so as to realize reading the shared texture.
Example two
The determination methods that the application is provided are applied in Direct3D11, the concrete reality of the determination methods that the application is provided
The mode of applying is based on the interface or method in Direct3D11.The determination methods of the GPU task completion status that the application is provided, in detail
It is thin as follows:
First, execution step S110, the predeterminable event inquiry in the first process;Operation in first process has described
GPU task.
In present application example, the inquiry of the predeterminable event in the first process;Operation in first process has described
GPU task, specifically includes:
By the CreateQuery methods of ID3D11Device interfaces, one is preset in first process
ID3D11Query interfaces, to preset an event query.
Specifically, the type that will be inquired about by the CreateQuery methods of ID3D11Device interfaces in the first process
It is set to D3D11_QUERY_EVENT to preset an ID3D11Query interface, to preset an event query.
It should be noted that including three state by the default event query Query of step S110:
(1) ready state (Signaled State):It seem the state of a free time.Query object has been generated, and is judged
Application program is completing this time inquiry.Work as poll-final, when inquiry state is changed into ready state, it is possible to get inquiry knot
Fruit.
(2) preset state (Building State):It seem a staging area.In preset state, inquiry is sent out
Rise (by calling D3DISSUE_BEGIN), but without being transformed into completion status.When application program statement poll-final (passes through
Call D3DISSUE_END), inquiry has just been transformed into completion status.
(3) completion status (Issued State):The resource that expression is queried has taken over inquiry.When resource completes work
After work, state machine can be transformed into ready state.In the stage of completing, application program is it must be determined whether be converted to ready shape
State, if ready state, then what GetData was returned is exactly the Query Result for needing.
Next execution step S120, after the GPU task, by the event query completion status is preset as.
It is described after the GPU task in present application example, the event query is preset as into completion status, specifically
For:
After the GPU task, the event query is set by the End methods of ID3D11DeviceContext interfaces
It is set to D3DISSUE_END states.By the way that event query is preset as into completion status so that video driver becomes the shape for taking over inquiry
State is controlled.
Subsequently execution step S130, judges whether the event query is ready state.
In the step s 120 after the GPU task, the event query is preset as into completion status, afterwards described first
Process needs to judge whether query event completes, if completing, then the operation of GPU task is also completed, then the second process this
When can correctly read in first process share GPU task content.
Due in step S120 the event query being arranged by the End methods of ID3D11DeviceContext interfaces
Into D3DISSUE_END states.By the way that event query is preset as into completion status so that video driver becomes the state for taking over inquiry
Control, after the completion of GPU task, the video driver by the State Transferring of the query event into ready state, so only needing
By judging that whether the state of event query is ready state judging whether GPU task completes.
In present application example, judge whether the event query is ready state, specifically include:
By the GetData methods of ID3D11DeviceContext interfaces, the return value of GetData methods is judged, to sentence
Whether disconnected event query completes.
When GetData methods return value be S_FALSE, represent the query event have not been completed GPU task also in
In drawing process, the first process still needs to continue waiting for and call again GetData methods;If the return value of GetData methods
For S_OK, represent that the query event is completed and the drafting operation of GPU task has also been completed, the first process then can be exited
Treat, the second process can read the content of GPU task.
Last execution step S140, if, it is determined that the GPU task is completed.
In present application example, if described, it is determined that the GPU task is completed, is specifically included:
When the return value of the GetData methods of ID3D11DeviceContext interfaces is S_OK, represent that the query event is complete
Into and GPU task drafting operation also completed, it is determined that the GPU task is completed.
A kind of determination methods of GPU task completion status that above-mentioned the application is also provided, the GPU task completion status
Determination methods solve and the technical problem that striding course reads content in another unfinished GPU task are difficult on GPU.
When the GPU task specially draws shared texture, then step S109 is first carried out before execution step S110,
The shared texture is preset in first process, and the shared texture is set to into post-processing object, to be drawn;Performing step
After rapid S140, execution step S150, the second process reads the shared texture.
Step S109, presets the shared texture in the first process, and the shared texture is set to render
Target, to be drawn, specifically includes:
When needing texture read-write synchronous, D3D11_TEXTURE2D_DESC structures in initialization Direct3D11 equipment,
Preset by the CreateTexture2D methods of Direct3D11 device pointer interface ID3D11Device
ID3D11Texture2D texture interfaces;
Shared texture pointer interface ID3D11Texture2D is obtained, by interface ID3D11Texture2D's
QueryInterface methods obtain IDXGIResource interfaces;
By the OMSetRenderTargets methods of ID3D11DeviceContext interfaces, the shared texture is set
A post-processing object is set to, then using related method for drafting, the drawing image on the shared texture;
By the OMSetRenderTargets methods of ID3D11DeviceContext interfaces, the shared texture is set
A post-processing object is set to, then using related method for drafting, the drawing image on the shared texture.First process can be with
Content is drawn on the shared texture by OMSetRenderTargets methods.
By the GetSharedHandle methods in the IDXGIResource interfaces that get, handle value is obtained
SharedHandle, obtains a shared Direct3D11 texture so in the first process.Can lead in other processes
Cross setting handle value sharedHandle to open the shared texture.
Wherein, D3D11_TEXTURE2D_DESC structures in Direct3D11 equipment are initialized, is specially set by preset value
The association attributes in D3D11_TEXTURE2D_DESC structures is put, and D3D11_RESOURCE_MISC_SHARED values are assigned to
The MiscFlags attributes of the structure.
Step S150, the second process reads the shared texture, specifically includes:
Step S151, the handle value sharedHandle is set to not for 0, to open first process in institute
State shared texture.
Step S151, the handle value sharedHandle is set to not for 0, to open first process in
Described shared texture, specially:
By the OpenSharedHandle methods of ID3D11Device interfaces, and handle value sharedHandle, obtain
One ID3D11Texture2D interface, to share to the described shared texture in the first process in the second process.
Step S152, reads the shared texture.It is described to read the shared texture, specifically include:
By the PSSetShaderResource methods of ID3D11DeviceContext interfaces, so as to realize that reading this is total to
Enjoy the function of texture.Due to now described in the first process share texture have determined complete draw, so second process
The content of the shared texture can accurately be read.
Embodiment two
Based on same inventive concept, the application also provides a kind of judgment means of GPU task completion status, refers to figure
2, the judgment means include:
The default unit 210 of inquiry, inquires about for the predeterminable event in the first process;
State presets unit 220, for after the GPU task, the event query being preset as into completion status;
Condition adjudgement unit 230, for judging whether the event query is ready state;
Status determining unit 240, for when the condition adjudgement unit judges result is to be, it is determined that the GPU appoints
Business is completed.
The judgment means that the application is provided can apply to Direct3D9, be also applied to Direct3D11.
The judgment means that the present embodiment two is introduced are a kind of judgement side of GPU task completion status of the embodiment of the present application one
The device that method is adopted, so the method introduced based on the embodiment of the present invention one, the affiliated personnel in this area will appreciate that the dress
The concrete structure put and deformation, so will not be described here.The device that the method for every embodiment of the present invention one is adopted all belongs to
In the scope to be protected of the invention.
The technical scheme provided in the embodiment of the present application, at least has the following technical effect that or advantage:
1st, the method and device that the embodiment of the present application is provided, is inquired about by the predeterminable event in first process;Institute
After stating GPU task, the event query is preset as into completion status, makes video driver take over the state control of inquiry;And lead to
Cross and judge that whether event query is ready state judging whether GPU task completes;If it is not, then first process continues to sentence
It is disconnected;If, it is determined that the GPU task is completed, realizes that striding course shares unfinished GPU task content.
2nd, the method and device that the embodiment of the present application is provided, by passing through IDirect3DDevice9 in Direct3D9
The default texture of the CreateTexture interfaces of interface, arranges handle value for 0 to preset a shared texture, obtains return described
The read-write handle value e of shared texture, by arranging the shared handle value to open the first process in default shared texture, it is real
The read-write of striding course texture is showed.
3rd, the method and device that the embodiment of the present application is provided, the second process needs to read the described shared texture in drawing
When, the predeterminable event inquiry in first process makes video driver take over the state control of inquiry;It is described by determining
Event query whether ready state determining whether shared texture part to be read has completed, the second process can if completing
Shared texture part to be read in read the first process, realizes and the process of the shared texture is read on GPU need not wait
The process that the texture is drawn to another is completed to draw operation on GPU and just can correctly read the picture material of texture.
Those skilled in the art are it should be appreciated that embodiments of the invention can be provided as method, system or computer program
Product.Therefore, the present invention can be using complete hardware embodiment, complete software embodiment or with reference to the reality in terms of software and hardware
Apply the form of example.And, the present invention can be adopted and wherein include the computer of computer usable program code at one or more
The computer program implemented in usable storage medium (including but not limited to magnetic disc store, CD-ROM, optical memory etc.) is produced
The form of product.
The present invention is the flow process with reference to method according to embodiments of the present invention, equipment (system) and computer program
Figure and/or block diagram are describing.It should be understood that can be by computer program instructions flowchart and/or each stream in block diagram
The combination of journey and/or square frame and flow chart and/or the flow process in block diagram and/or square frame.These computer programs can be provided
The processor of all-purpose computer, special-purpose computer, Embedded Processor or other programmable data processing devices is instructed to produce
A raw machine so that produced for reality by the instruction of computer or the computing device of other programmable data processing devices
The device of the function of specifying in present one flow process of flow chart or one square frame of multiple flow processs and/or block diagram or multiple square frames.
These computer program instructions may be alternatively stored in can guide computer or other programmable data processing devices with spy
In determining the computer-readable memory that mode works so that the instruction being stored in the computer-readable memory is produced to be included referring to
Make the manufacture of device, the command device realize in one flow process of flow chart or one square frame of multiple flow processs and/or block diagram or
The function of specifying in multiple square frames.
These computer program instructions also can be loaded in computer or other programmable data processing devices so that in meter
Series of operation steps is performed on calculation machine or other programmable devices to produce computer implemented process, so as in computer or
The instruction performed on other programmable devices is provided for realizing in one flow process of flow chart or multiple flow processs and/or block diagram one
The step of function of specifying in individual square frame or multiple square frames.
, but those skilled in the art once know basic creation although preferred embodiments of the present invention have been described
Property concept, then can make other change and modification to these embodiments.So, claims are intended to be construed to include excellent
Select embodiment and fall into having altered and changing for the scope of the invention.
Obviously, those skilled in the art can carry out various changes and modification without deviating from this to the embodiment of the present invention
The spirit and scope of bright embodiment.So, if these modifications of the embodiment of the present invention and modification belong to the claims in the present invention
And its within the scope of equivalent technologies, then the present invention is also intended to comprising these changes and modification.