1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
3  <head>
4    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5    <meta http-equiv="Content-Style-Type" content="text/css" />
6    <link rel="stylesheet" href="../css/document.css" type="text/css" />
7    <title>Notes About Creating GPU Commands and Using Them With DMPGL</title>
8  </head>
9  <body>
10    <h1>Using GPU Commands and GL Together</h1>
11
12<a href="#introduction">Introduction</a><BR> <a href="#inner_state">Maintaining Consistency of Internal States When DMPGL API Mixed with Directly Generated Commands</a><BR> <a href="#change_state" >Moving Between DMPGL API Calls and Directly Generated Commands</a><BR> <a href="#note">Notes</a><BR>
13
14<h2><a name="introduction">Introduction</a></h2>
15
16    <p>This document is a collection of notes regarding the methods of generating commands that can be directly interpreted by the GPU and the use of those commands together with DMPGL.</p>
17
18    <p>If you need more information about the direct generation of commands, see the following documentation:</p>
19
20    <ul>
21    <li>DMPGL2.0 System API Specifications, Chapter 5 (DMPGL20_system_API_specification.pdf).</li>
22    </ul>
23
24<h2><a name="inner_state">Maintaining Consistency of Internal States When DMPGL API Mixed with Directly Generated Commands</a></h2>
25
26    <h3>Assumptions:</h3>
27    <ul>
28    <li>The <I>internal states</I> are mirrors of the GPU register settings, maintained by the DMPGL driver as local data (as a collection of structures). Providing that you are only using the DMPGL API, the internal states and the states of the GPU registers are essentially the same.</li>
29    <li>The internal states are not changed by directly generated commands (they cannot be changed this way).</li>
30    </ul>
31
32    <h3>Command Issuance by the DMPGL Driver</h3>
33    <ul>
34    <li>Command Issuance by <B>Validate</B></li>
35      <ul>
36      <li>Command issued when <CODE>glDrawArrays</CODE>, <CODE>glDrawElements </CODE>or <CODE>nngxValidateState </CODE>is called.</li>
37      <li>The DMPGL divides the internal states into a number of categories, and flags are used to manage whether each has been updated (See Specification: State Flags).</li>
38      <li>When the update flag is standing for a given category, an overwrite command is issued to update those GPU registers.</li>
39      <li>Almost all commands are issued this way.</li>
40      </ul>
41    </ul>
42
43    <ul>
44    <li>Command Issuance by Call to DMPGL API Itself</li>
45      <ul>
46      <li>Inside the DMPGL API , there are functions for which commands are issued immediately upon calling. (See Table 5-3 in the System API Specifications) These belong to the <CODE>NN_GX_STATE_OTHERS </CODE> state.  This is a special state (explained below).</li>
47      </ul>
48    </ul>
49
50    <h3>The Timing of Internal State Updating</h3>
51
52    <p>Basically speaking, when a DMPGL API function is called that requires state updating, if it is possible to compare and confirm the updating of the current internal state, then the actual process of updating the internal state is carried out and the state update flag is raised.</p>
53    <p  style="padding-left:2em">→ In other words, when commands are directly generated without using the DMPGL API, they must not issue an update the internal state.</p>
54
55    <p>For the DMPGL API functions belonging to <CODE>NN_GX_STATE_OTHERS</CODE>, if there is an update to the internal state a command is issued and afterward the internal state is updated.  (The exception is <CODE>glViewport</CODE>, where the command is issued without making the comparison with the internal state.)</p>
56    <p>For the API functions listed below, the update flag stands for the dependent state (<CODE>NN_GX_STATE_FACES)</CODE>.</p>
57
58    <ul>
59    <li>glEnable, glDisable</li>
60      <ul>
61      <li><CODE>param</CODE> is GL_COLOR_LOGIC, GL_BLEND、GL_DEPTH_TEST, GL_EARLY_DEPTH_TEST_DMP, GL_STENCIL_TEST</li>
62      </ul>
63    <li><CODE>glDepthFunc</CODE></li>
64    <li><CODE>glEarlyDepthFuncDMP</CODE></li>
65    <li><CODE>glColorMask</CODE></li>
66    <li><CODE>glDepthMask</CODE></li>
67    <li><CODE>glStencilMask</CODE></li>
68    </ul>
69
70<h2><a name="change_state">Moving Between DMPGL API Calls and Directly Generated Commands</a></h2>
71
72    <h3>How to Safely Move From Calls to DMPGL API Functions to Direct Generation of Commands</h3>
73    <ul>
74    <li>Validate all states.</li>
75      <ul>
76      <li>Validation is done by calling <CODE>nngxValidateState(NN_GX_STATE_ALL, *)</CODE> or executed internally by <CODE>glDrawArrays, glDrawElements</CODE>. </li>
77      <li>You must perform this validation if, for simplicity, you want to directly generate commands with the assumption that the settings as configured by the DMPGL API are applied to the GPU.</li>
78      <li>Regardless of whether you are moving from calls to the DMPGL API, you can prevent the occurrence of unforeseen problems by first validating and making sure the state flags are all down before you generate direct commands.</li>
79      </ul>
80    </ul>
81
82    <h3>How to Safely Move From Direct Generation of Commands to Calls to DMPGL API Functions</h3>
83
84    <p>Due to the direct generation of commands, the register settings in the GPU and the internal states maintained in the DMPG driver layer may not be exactly the same.</p>
85
86    <p>In order for the GPU to correctly process the results of calls to the DMPGL API, the two must be made to match.</p>
87
88    <p>Broadly speaking, there are two ways of doing this before moving to the call of DMPGL API functions.</p>
89
90    <ol>
91    <li>Issue commands to force the updating of all states. In other words, specify <CODE>nngxUpdateState(NN_GX_STATE_ALL)</CODE> and validate.  This is the surest way, but you also end up issuing unnecessary commands (for registers that have already been overwritten).</li>
92
93    <li>If the directly generated commands have been already clearly divided out, forcedly raise the update flag for just the states that pertain to those commands, and then validate. This method minimizes the issuance of commands, but the application needs to manage which states pertain to which directly generated commands and whether there are any dependent states.</li>
94    </ol>
95
96    <p>You can modify method (2) to suppress the redundant issuance of commands. By defining <CODE>nngxSetCommandGenerationMode(NN_GX_CMDGEN_MODE_UNCONDITIONAL)</CODE>, commands will be issued regardless of the result of the comparison with the internal state.  However, the influence of this mode is limited to the following settings. (For details, see section 4.10 in the specifications.)</p>
97
98    <ul>
99    <li>Uniform settings for the reserved fragment shader.</li>
100    <li>Integer uniform settings for the vertex shader.</li>
101    <li>LUT data settings</li>
102    <li>DMPGL API belonging to the <CODE>NN_GX_STATE_OTHERS</CODE> state.</li>
103    </ul>
104
105    <p>To update the state flags relating to these settings, it is no longer necessary to use <CODE>nngxUpdateState</CODE>.</p>
106
107<h2><a name="note">Notes</a></h2>
108    <p>Other notes regarding the <CODE>NN_GX_STATE_OTHERS</CODE> state.</p>
109
110    <h3>When Creating Command Cache</h3>
111    <ul>
112    <li>For API functions that result in command issuance when they themselves are called, there is a problem if the generated command is simply saved for use.</li>
113      <ul>
114      <li>The API functions that were referred to in <I>The Timing of Internal State Updating</I> earlier in this document have <CODE>NN_GX_STATE_FBACCESS</CODE> raised, so they must be validated by <CODE>nngxValidateState(*)</CODE> and saved to cache including the command being issued.</li>
115      <li>You can  made do by passing <CODE>NN_GX_STATE_ALL</CODE> as the argument to <CODE>nngxValidateState</CODE>, or if there are no other targets to validate you can just pass <CODE>NN_GX_STATE_FBACCESS</CODE>.</li>
116      </ul>
117    </ul>
118
119    <h3>About Command Output Mode</h3>
120
121    <p>By specifying <CODE>NN_GX_CMDGEN_MODE_UNCONDITIONAL</CODE> with <CODE>nngxSetCommandGenerationMode</CODE> before calling the pertinent API function, the command will be issued regardless of the result of the comparison with the internal state. </p>
122
123    <h3>The Behavior of <CODE>nngxUseSavedCmdlist</CODE> and <CODE>nngxUpdateState(NN_GX_STATE_OTHERS)</CODE></h3>
124
125    <p>If <CODE>NN_GX_STATE_OTHERS</CODE> has been specified for the <CODE>statemask</CODE> argument, the commands will be issued all at once at validation time for all API functions that result in command issuance when they themselves are called. In addition, the update bit will raise automatically for the dependent state  <CODE>NN_GX_STATE_FBACCESS</CODE>.</p>
126
127  <hr><p>CONFIDENTIAL</p></body>
128</html>
129
130